DecorativeGeometry.h

Go to the documentation of this file.
00001 #ifndef SimTK_SimTKCOMMON_DECORATIVE_GEOMETRY_H_
00002 #define SimTK_SimTKCOMMON_DECORATIVE_GEOMETRY_H_
00003 
00004 /* -------------------------------------------------------------------------- *
00005  *                      SimTK Core: SimTKcommon                               *
00006  * -------------------------------------------------------------------------- *
00007  * This is part of the SimTK Core biosimulation toolkit originating from      *
00008  * Simbios, the NIH National Center for Physics-Based Simulation of           *
00009  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
00010  * Medical Research, grant U54 GM072970. See https://simtk.org.               *
00011  *                                                                            *
00012  * Portions copyright (c) 2005-7 Stanford University and the Authors.         *
00013  * Authors: Michael Sherman                                                   *
00014  * Contributors: Jack Middleton                                               *
00015  *                                                                            *
00016  * Permission is hereby granted, free of charge, to any person obtaining a    *
00017  * copy of this software and associated documentation files (the "Software"), *
00018  * to deal in the Software without restriction, including without limitation  *
00019  * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
00020  * and/or sell copies of the Software, and to permit persons to whom the      *
00021  * Software is furnished to do so, subject to the following conditions:       *
00022  *                                                                            *
00023  * The above copyright notice and this permission notice shall be included in *
00024  * all copies or substantial portions of the Software.                        *
00025  *                                                                            *
00026  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
00027  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
00028  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
00029  * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
00030  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
00031  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
00032  * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
00033  * -------------------------------------------------------------------------- */
00034 
00067 /* TODO: NEW TEXT -- NOT IMPLEMENTED YET (just thinking out loud)
00068  *
00069  * Each kind of Decoration defines a parameterized object, whose appearance
00070  * is specified once its parameters are known. Parameters will be scalars,
00071  * points, direction vectors, and transforms. These involve dependencies on
00072  * a fixed set of reference frames: the ground body frame, the moving body frames,
00073  * and the screen or viewing frame. The body frames are defined by the System;
00074  * while the viewing frame is defined by whatever application is communicating
00075  * to a user. The World frame of the viewer and the Ground frame of the System
00076  * are the same. At run time a System can always report the configuration of its
00077  * moving bodies with respect to Ground, and hence these can be placed in the
00078  * scene with respect to the World frame. A text label, for example, could be tethered
00079  * to a point on a moving body while defined to remain parallel to the viewing plane.
00080  *
00081  * In addition to their geometric representations, Decorations defined here can 
00082  * state preferences, if any, for a variety of viewing options such as color,
00083  * drawing style, and transparency. If left unspecified, the viewer will have to
00084  * determine how to set these options; if specified the viewer may want to use
00085  * the specified options but can override them if it has good reason to do so.
00086  * Many different implementations of Decorations are possible. The generic 
00087  * implementation is defined below as an abstract class; each viewer will use
00088  * a particular implementation that defines a concrete implementation for each of the virtual
00089  * methods of the abstraction.
00090  *
00091  * There are two Stages associated with a Decoration. When is the Decoration
00092  * known to exist (including its parameterization), and when are values for its 
00093  * parameters calculatable. For example, a permanent body-fixed sphere is known
00094  * to exist a the Topological stage (i.e., as soon as the body exists). Its 
00095  * configuration in the World frame, however, cannot be computed until we
00096  * know the body's configuration, that is, Stage::Position.
00097  */
00098 
00099 #include "SimTKcommon/Simmatrix.h"
00100 #include "SimTKcommon/internal/PolygonalMesh.h"
00101 
00102 #include <cassert>
00103 
00104 
00105 namespace SimTK {
00106 
00107 class AnalyticGeometry;
00108 
00109 
00110 // Some common RGB values;
00111 static const Vec3 Black   = Vec3( 0, 0, 0);
00112 static const Vec3 Gray    = Vec3(.5,.5,.5);
00113 static const Vec3 Red     = Vec3( 1, 0, 0);
00114 static const Vec3 Green   = Vec3( 0, 1, 0);
00115 static const Vec3 Blue    = Vec3( 0, 0, 1);
00116 static const Vec3 Yellow  = Vec3( 1, 1, 0);
00117 static const Vec3 Orange  = Vec3( 1,.5, 0);
00118 static const Vec3 Magenta = Vec3( 1, 0, 1);
00119 static const Vec3 Purple  = Vec3(.5, 0,.5);
00120 static const Vec3 Cyan    = Vec3( 0, 1, 1);
00121 static const Vec3 White   = Vec3( 1, 1, 1);
00122 
00123 // Drawing representations
00124 
00125 class DecorativeGeometryImplementation;
00126 
00132 class SimTK_SimTKCOMMON_EXPORT DecorativeGeometry {
00133 public:
00134     DecorativeGeometry() : rep(0) { }
00135     ~DecorativeGeometry();
00136     DecorativeGeometry(const DecorativeGeometry&);
00137     DecorativeGeometry& operator=(const DecorativeGeometry&);
00138 
00139     // Drawing modes.
00140     enum Representation {
00141         DrawPoints    =  1,
00142         DrawWireframe =  2,
00143         DrawSurface   =  3,
00144 
00145         DrawDefault   = -1
00146     };
00147 
00149     DecorativeGeometry(const AnalyticGeometry&);
00150 
00155     DecorativeGeometry& setBodyId(int);
00156 
00162     DecorativeGeometry& setTransform(const Transform& X_BG);
00163 
00169     DecorativeGeometry& setResolution(Real);
00170 
00178     DecorativeGeometry& setScale(Real);
00179 
00182     int getBodyId() const;
00183 
00186     Real getResolution() const;
00187 
00191     const Transform& getTransform() const;
00192 
00195     Real getScale() const;
00196 
00200     DecorativeGeometry& setColor(const Vec3& rgb); // 0-1 for each color
00201 
00205     DecorativeGeometry& setOpacity(Real);          // 0-1; default is 1 (opaque)
00206 
00211     DecorativeGeometry& setLineThickness(Real);
00212 
00213     const Vec3& getColor()      const;
00214     Real        getOpacity()    const;
00215     Real        getLineThickness() const;
00216     
00218     DecorativeGeometry& setFaceCamera(bool face);
00220     bool getFaceCamera() const;
00221 
00224     DecorativeGeometry& setRepresentation(const Representation&);
00225 
00227     Representation getRepresentation() const;
00228 
00229     void implementGeometry(DecorativeGeometryImplementation&) const;
00230 
00231     // Bookkeeping below here -- internal use only. Don't look below or you will
00232     // turn into a pillar of salt.
00233     bool isOwnerHandle() const;
00234     bool isEmptyHandle() const;
00235     explicit DecorativeGeometry(class DecorativeGeometryRep* r) : rep(r) { }
00236     bool hasRep() const {return rep!=0;}
00237     const DecorativeGeometryRep& getRep() const {assert(rep); return *rep;}
00238     DecorativeGeometryRep&       updRep()       {assert(rep); return *rep;}
00239 protected:
00240     DecorativeGeometryRep* rep;
00241 };
00242 
00254 class SimTK_SimTKCOMMON_EXPORT DecorativeLine : public DecorativeGeometry {
00255 public:
00256     explicit DecorativeLine(const Vec3& p1=Vec3(0), const Vec3& p2=Vec3(1)); // line between p1 and p2
00257 
00258     // Retain the derived type when setting generic geometry options.
00259     DecorativeLine& setBodyId(int b)          {DecorativeGeometry::setBodyId(b);        return *this;}
00260     DecorativeLine& setTransform(const Transform& X_BD) {DecorativeGeometry::setTransform(X_BD); return *this;}
00261     DecorativeLine& setResolution(Real r)     {DecorativeGeometry::setResolution(r);    return *this;}
00262     DecorativeLine& setScale(Real s)          {DecorativeGeometry::setScale(s);         return *this;}
00263     DecorativeLine& setColor(const Vec3& rgb) {DecorativeGeometry::setColor(rgb);       return *this;}
00264     DecorativeLine& setOpacity(Real o)        {DecorativeGeometry::setOpacity(o);       return *this;}
00265     DecorativeLine& setLineThickness(Real t)  {DecorativeGeometry::setLineThickness(t); return *this;}
00266     DecorativeLine& setRepresentation(const Representation& r) {
00267         DecorativeGeometry::setRepresentation(r); return *this;
00268     }
00269 
00270     // These are specific to lines.
00271     DecorativeLine& setPoint1(const Vec3& p1);
00272     DecorativeLine& setPoint2(const Vec3& p2);
00273     DecorativeLine& setEndpoints(const Vec3& p1, const Vec3& p2);
00274 
00275     const Vec3& getPoint1() const;
00276     const Vec3& getPoint2() const;
00277 
00278     SimTK_PIMPL_DOWNCAST(DecorativeLine, DecorativeGeometry);
00279 private:
00280     class DecorativeLineRep& updRep();
00281     const DecorativeLineRep& getRep() const;
00282 };
00283 
00288 class SimTK_SimTKCOMMON_EXPORT DecorativeCircle : public DecorativeGeometry {
00289 public:
00290     explicit DecorativeCircle(Real radius=0.5);
00291 
00292     void setRadius(Real);
00293     Real getRadius() const;
00294 
00295     SimTK_PIMPL_DOWNCAST(DecorativeCircle, DecorativeGeometry);
00296 private:
00297     class DecorativeCircleRep& updRep();
00298     const DecorativeCircleRep& getRep() const;
00299 };
00300 
00305 class SimTK_SimTKCOMMON_EXPORT DecorativeSphere : public DecorativeGeometry {
00306 public:
00307     explicit DecorativeSphere(Real radius=0.5);
00308 
00309     void setRadius(Real);
00310     Real getRadius() const;
00311 
00312     SimTK_PIMPL_DOWNCAST(DecorativeSphere, DecorativeGeometry);
00313 private:
00314     class DecorativeSphereRep& updRep();
00315     const DecorativeSphereRep& getRep() const;
00316 };
00317 
00323 class SimTK_SimTKCOMMON_EXPORT DecorativeEllipsoid : public DecorativeGeometry {
00324 public:
00325     explicit DecorativeEllipsoid(const Vec3& radii = Vec3(0.5,1/3.,0.25));
00326 
00327     void setRadii(const Vec3&);
00328     const Vec3& getRadii() const;
00329 
00330     SimTK_PIMPL_DOWNCAST(DecorativeEllipsoid, DecorativeGeometry);
00331 private:
00332     class DecorativeEllipsoidRep& updRep();
00333     const DecorativeEllipsoidRep& getRep() const;
00334 };
00335 
00341 class SimTK_SimTKCOMMON_EXPORT DecorativeBrick : public DecorativeGeometry {
00342 public:
00343     explicit DecorativeBrick(const Vec3& halfLengths = Vec3(0.5));
00344 
00345     void setHalfLengths(const Vec3&);
00346     const Vec3& getHalfLengths() const;
00347 
00348     SimTK_PIMPL_DOWNCAST(DecorativeBrick, DecorativeGeometry);
00349 private:
00350     class DecorativeBrickRep& updRep();
00351     const DecorativeBrickRep& getRep() const;
00352 };
00353 
00359 class SimTK_SimTKCOMMON_EXPORT DecorativeCylinder : public DecorativeGeometry {
00360 public:
00361     explicit DecorativeCylinder(Real radius=0.5, Real halfHeight=0.5);
00362 
00363     void setRadius(Real);
00364     void setHalfHeight(Real);
00365     Real getRadius() const;
00366     Real getHalfHeight() const;
00367 
00368     SimTK_PIMPL_DOWNCAST(DecorativeCylinder, DecorativeGeometry);
00369 private:
00370     class DecorativeCylinderRep& updRep();
00371     const DecorativeCylinderRep& getRep() const;
00372 };
00373 
00379 class SimTK_SimTKCOMMON_EXPORT DecorativeFrame : public DecorativeGeometry {
00380 public:
00381     explicit DecorativeFrame(Real axisLength=1);
00382 
00383     void setAxisLength(Real);
00384     Real getAxisLength() const;
00385 
00386     SimTK_PIMPL_DOWNCAST(DecorativeFrame, DecorativeGeometry);
00387 private:
00388     class DecorativeFrameRep& updRep();
00389     const DecorativeFrameRep& getRep() const;
00390 };
00391 
00396 class SimTK_SimTKCOMMON_EXPORT DecorativeText : public DecorativeGeometry {
00397 public:
00398     explicit DecorativeText(const std::string& label="");
00399 
00400     void setText(const std::string& label);
00401     const std::string& getText() const;
00402 
00403     SimTK_PIMPL_DOWNCAST(DecorativeText, DecorativeGeometry);
00404 private:
00405     class DecorativeTextRep& updRep();
00406     const DecorativeTextRep& getRep() const;
00407 };
00408 
00412 class SimTK_SimTKCOMMON_EXPORT DecorativeMesh : public DecorativeGeometry {
00413 public:
00414     explicit DecorativeMesh(const PolygonalMesh& mesh);
00415     const PolygonalMesh& getMesh() const;
00416 
00417     SimTK_PIMPL_DOWNCAST(DecorativeMesh, DecorativeGeometry);
00418 private:
00419     class DecorativeMeshRep& updRep();
00420     const DecorativeMeshRep& getRep() const;
00421 };
00422 
00427 class SimTK_SimTKCOMMON_EXPORT DecorativeGeometryImplementation {
00428 public:
00429     virtual ~DecorativeGeometryImplementation() { }
00430     virtual void implementLineGeometry(     const DecorativeLine&)     = 0;
00431     virtual void implementBrickGeometry(    const DecorativeBrick&)    = 0;
00432     virtual void implementCylinderGeometry( const DecorativeCylinder&) = 0;
00433     virtual void implementCircleGeometry(   const DecorativeCircle&)   = 0; 
00434     virtual void implementSphereGeometry(   const DecorativeSphere&)   = 0;
00435     virtual void implementEllipsoidGeometry(const DecorativeEllipsoid&)= 0;
00436     virtual void implementFrameGeometry(    const DecorativeFrame&)    = 0;
00437     virtual void implementTextGeometry(     const DecorativeText&)     = 0;
00438     virtual void implementMeshGeometry(     const DecorativeMesh&)     = 0;
00439 };
00440 
00441 } // namespace SimTK
00442 
00443 #endif // SimTK_SimTKCOMMON_DECORATIVE_GEOMETRY_H_

Generated on Wed Dec 30 11:04:33 2009 for SimTKcore by  doxygen 1.6.1