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 
00101 #include <cassert>
00102 
00103 
00104 namespace SimTK {
00105 
00106 class AnalyticGeometry;
00107 
00108 
00109 // Some common RGB values;
00110 static const Vec3 Black   = Vec3( 0, 0, 0);
00111 static const Vec3 Gray    = Vec3(.5,.5,.5);
00112 static const Vec3 Red     = Vec3( 1, 0, 0);
00113 static const Vec3 Green   = Vec3( 0, 1, 0);
00114 static const Vec3 Blue    = Vec3( 0, 0, 1);
00115 static const Vec3 Yellow  = Vec3( 1, 1, 0);
00116 static const Vec3 Orange  = Vec3( 1,.5, 0);
00117 static const Vec3 Magenta = Vec3( 1, 0, 1);
00118 static const Vec3 Purple  = Vec3(.5, 0,.5);
00119 static const Vec3 Cyan    = Vec3( 0, 1, 1);
00120 static const Vec3 White   = Vec3( 1, 1, 1);
00121 
00122 // Drawing representations
00123 
00124 class DecorativeGeometryImplementation;
00125 
00131 class SimTK_SimTKCOMMON_EXPORT DecorativeGeometry {
00132 public:
00133     DecorativeGeometry() : rep(0) { }
00134     ~DecorativeGeometry();
00135     DecorativeGeometry(const DecorativeGeometry&);
00136     DecorativeGeometry& operator=(const DecorativeGeometry&);
00137 
00138     // Drawing modes.
00139     enum Representation {
00140         DrawPoints    =  1,
00141         DrawWireframe =  2,
00142         DrawSurface   =  3,
00143 
00144         DrawDefault   = -1
00145     };
00146 
00148     DecorativeGeometry(const AnalyticGeometry&);
00149 
00154     DecorativeGeometry& setBodyId(int);
00155 
00161     DecorativeGeometry& setTransform(const Transform& X_BG);
00162 
00168     DecorativeGeometry& setResolution(Real);
00169 
00177     DecorativeGeometry& setScale(Real);
00178 
00181     int getBodyId() const;
00182 
00185     Real getResolution() const;
00186 
00190     const Transform& getTransform() const;
00191 
00194     Real getScale() const;
00195 
00199     DecorativeGeometry& setColor(const Vec3& rgb); // 0-1 for each color
00200 
00204     DecorativeGeometry& setOpacity(Real);          // 0-1; default is 1 (opaque)
00205 
00210     DecorativeGeometry& setLineThickness(Real);
00211 
00212     const Vec3& getColor()      const;
00213     Real        getOpacity()    const;
00214     Real        getLineThickness() const;
00215     
00217     DecorativeGeometry& setFaceCamera(bool face);
00219     bool getFaceCamera() const;
00220 
00223     DecorativeGeometry& setRepresentation(const Representation&);
00224 
00226     Representation getRepresentation() const;
00227 
00228     void implementGeometry(DecorativeGeometryImplementation&) const;
00229 
00230     // Bookkeeping below here -- internal use only. Don't look below or you will
00231     // turn into a pillar of salt.
00232     bool isOwnerHandle() const;
00233     bool isEmptyHandle() const;
00234     explicit DecorativeGeometry(class DecorativeGeometryRep* r) : rep(r) { }
00235     bool hasRep() const {return rep!=0;}
00236     const DecorativeGeometryRep& getRep() const {assert(rep); return *rep;}
00237     DecorativeGeometryRep&       updRep()       {assert(rep); return *rep;}
00238 protected:
00239     DecorativeGeometryRep* rep;
00240 };
00241 
00253 class SimTK_SimTKCOMMON_EXPORT DecorativeLine : public DecorativeGeometry {
00254 public:
00255     explicit DecorativeLine(const Vec3& p1=Vec3(0), const Vec3& p2=Vec3(1)); // line between p1 and p2
00256 
00257     // Retain the derived type when setting generic geometry options.
00258     DecorativeLine& setBodyId(int b)          {DecorativeGeometry::setBodyId(b);        return *this;}
00259     DecorativeLine& setTransform(const Transform& X_BD) {DecorativeGeometry::setTransform(X_BD); return *this;}
00260     DecorativeLine& setResolution(Real r)     {DecorativeGeometry::setResolution(r);    return *this;}
00261     DecorativeLine& setScale(Real s)          {DecorativeGeometry::setScale(s);         return *this;}
00262     DecorativeLine& setColor(const Vec3& rgb) {DecorativeGeometry::setColor(rgb);       return *this;}
00263     DecorativeLine& setOpacity(Real o)        {DecorativeGeometry::setOpacity(o);       return *this;}
00264     DecorativeLine& setLineThickness(Real t)  {DecorativeGeometry::setLineThickness(t); return *this;}
00265     DecorativeLine& setRepresentation(const Representation& r) {
00266         DecorativeGeometry::setRepresentation(r); return *this;
00267     }
00268 
00269     // These are specific to lines.
00270     DecorativeLine& setPoint1(const Vec3& p1);
00271     DecorativeLine& setPoint2(const Vec3& p2);
00272     DecorativeLine& setEndpoints(const Vec3& p1, const Vec3& p2);
00273 
00274     const Vec3& getPoint1() const;
00275     const Vec3& getPoint2() const;
00276 
00277     SimTK_PIMPL_DOWNCAST(DecorativeLine, DecorativeGeometry);
00278 private:
00279     class DecorativeLineRep& updRep();
00280     const DecorativeLineRep& getRep() const;
00281 };
00282 
00287 class SimTK_SimTKCOMMON_EXPORT DecorativeCircle : public DecorativeGeometry {
00288 public:
00289     explicit DecorativeCircle(Real radius=0.5);
00290 
00291     void setRadius(Real);
00292     Real getRadius() const;
00293 
00294     SimTK_PIMPL_DOWNCAST(DecorativeCircle, DecorativeGeometry);
00295 private:
00296     class DecorativeCircleRep& updRep();
00297     const DecorativeCircleRep& getRep() const;
00298 };
00299 
00304 class SimTK_SimTKCOMMON_EXPORT DecorativeSphere : public DecorativeGeometry {
00305 public:
00306     explicit DecorativeSphere(Real radius=0.5);
00307 
00308     void setRadius(Real);
00309     Real getRadius() const;
00310 
00311     SimTK_PIMPL_DOWNCAST(DecorativeSphere, DecorativeGeometry);
00312 private:
00313     class DecorativeSphereRep& updRep();
00314     const DecorativeSphereRep& getRep() const;
00315 };
00316 
00322 class SimTK_SimTKCOMMON_EXPORT DecorativeEllipsoid : public DecorativeGeometry {
00323 public:
00324     explicit DecorativeEllipsoid(const Vec3& radii = Vec3(0.5,1/3.,0.25));
00325 
00326     void setRadii(const Vec3&);
00327     const Vec3& getRadii() const;
00328 
00329     SimTK_PIMPL_DOWNCAST(DecorativeEllipsoid, DecorativeGeometry);
00330 private:
00331     class DecorativeEllipsoidRep& updRep();
00332     const DecorativeEllipsoidRep& getRep() const;
00333 };
00334 
00340 class SimTK_SimTKCOMMON_EXPORT DecorativeBrick : public DecorativeGeometry {
00341 public:
00342     explicit DecorativeBrick(const Vec3& halfLengths = Vec3(0.5));
00343 
00344     void setHalfLengths(const Vec3&);
00345     const Vec3& getHalfLengths() const;
00346 
00347     SimTK_PIMPL_DOWNCAST(DecorativeBrick, DecorativeGeometry);
00348 private:
00349     class DecorativeBrickRep& updRep();
00350     const DecorativeBrickRep& getRep() const;
00351 };
00352 
00358 class SimTK_SimTKCOMMON_EXPORT DecorativeCylinder : public DecorativeGeometry {
00359 public:
00360     explicit DecorativeCylinder(Real radius=0.5, Real halfHeight=0.5);
00361 
00362     void setRadius(Real);
00363     void setHalfHeight(Real);
00364     Real getRadius() const;
00365     Real getHalfHeight() const;
00366 
00367     SimTK_PIMPL_DOWNCAST(DecorativeCylinder, DecorativeGeometry);
00368 private:
00369     class DecorativeCylinderRep& updRep();
00370     const DecorativeCylinderRep& getRep() const;
00371 };
00372 
00378 class SimTK_SimTKCOMMON_EXPORT DecorativeFrame : public DecorativeGeometry {
00379 public:
00380     explicit DecorativeFrame(Real axisLength=1);
00381 
00382     void setAxisLength(Real);
00383     Real getAxisLength() const;
00384 
00385     SimTK_PIMPL_DOWNCAST(DecorativeFrame, DecorativeGeometry);
00386 private:
00387     class DecorativeFrameRep& updRep();
00388     const DecorativeFrameRep& getRep() const;
00389 };
00390 
00395 class SimTK_SimTKCOMMON_EXPORT DecorativeText : public DecorativeGeometry {
00396 public:
00397     explicit DecorativeText(const std::string& label="");
00398 
00399     void setText(const std::string& label);
00400     const std::string& getText() const;
00401 
00402     SimTK_PIMPL_DOWNCAST(DecorativeText, DecorativeGeometry);
00403 private:
00404     class DecorativeTextRep& updRep();
00405     const DecorativeTextRep& getRep() const;
00406 };
00407 
00408 
00413 class SimTK_SimTKCOMMON_EXPORT DecorativeGeometryImplementation {
00414 public:
00415     virtual ~DecorativeGeometryImplementation() { }
00416     virtual void implementLineGeometry(     const DecorativeLine&)     = 0;
00417     virtual void implementBrickGeometry(    const DecorativeBrick&)    = 0;
00418     virtual void implementCylinderGeometry( const DecorativeCylinder&) = 0;
00419     virtual void implementCircleGeometry(   const DecorativeCircle&)   = 0; 
00420     virtual void implementSphereGeometry(   const DecorativeSphere&)   = 0;
00421     virtual void implementEllipsoidGeometry(const DecorativeEllipsoid&)= 0;
00422     virtual void implementFrameGeometry(    const DecorativeFrame&)    = 0;
00423     virtual void implementTextGeometry(     const DecorativeText&)     = 0;
00424 
00425     // TODO: wrappers for binary compatibility
00426 };
00427 
00428 } // namespace SimTK
00429 
00430 #endif // SimTK_SimTKCOMMON_DECORATIVE_GEOMETRY_H_

Generated on Thu Feb 28 01:34:28 2008 for SimTKcommon by  doxygen 1.4.7