Simbody  3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DecorativeGeometry.h
Go to the documentation of this file.
1 #ifndef SimTK_SimTKCOMMON_DECORATIVE_GEOMETRY_H_
2 #define SimTK_SimTKCOMMON_DECORATIVE_GEOMETRY_H_
3 
4 /* -------------------------------------------------------------------------- *
5  * Simbody(tm): SimTKcommon *
6  * -------------------------------------------------------------------------- *
7  * This is part of the SimTK biosimulation toolkit originating from *
8  * Simbios, the NIH National Center for Physics-Based Simulation of *
9  * Biological Structures at Stanford, funded under the NIH Roadmap for *
10  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
11  * *
12  * Portions copyright (c) 2005-12 Stanford University and the Authors. *
13  * Authors: Michael Sherman *
14  * Contributors: Jack Middleton, Peter Eastman *
15  * *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may *
17  * not use this file except in compliance with the License. You may obtain a *
18  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19  * *
20  * Unless required by applicable law or agreed to in writing, software *
21  * distributed under the License is distributed on an "AS IS" BASIS, *
22  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23  * See the License for the specific language governing permissions and *
24  * limitations under the License. *
25  * -------------------------------------------------------------------------- */
26 
30 #include "SimTKcommon/Simmatrix.h"
32 
33 #include <cassert>
34 
35 
36 namespace SimTK {
37 
38 // Some common RGB values;
39 extern SimTK_SimTKCOMMON_EXPORT const Vec3 Black;
40 extern SimTK_SimTKCOMMON_EXPORT const Vec3 Gray;
41 extern SimTK_SimTKCOMMON_EXPORT const Vec3 Red;
42 extern SimTK_SimTKCOMMON_EXPORT const Vec3 Green;
43 extern SimTK_SimTKCOMMON_EXPORT const Vec3 Blue;
48 extern SimTK_SimTKCOMMON_EXPORT const Vec3 Cyan;
49 extern SimTK_SimTKCOMMON_EXPORT const Vec3 White;
50 
51 // Drawing representations
52 
53 class DecorativeGeometryImplementation;
54 
87 public:
88 DecorativeGeometry() : rep(0) { }
91 DecorativeGeometry& operator=(const DecorativeGeometry&);
92 
93 // Drawing modes.
95  DrawPoints = 1,
96  DrawWireframe = 2,
97  DrawSurface = 3,
98 
99  DrawDefault = -1
100 };
101 
106 DecorativeGeometry& setBodyId(int);
107 
113 DecorativeGeometry& setTransform(const Transform& X_BG);
114 
123 DecorativeGeometry& setResolution(Real);
124 
132 DecorativeGeometry& setScaleFactors(const Vec3& scale);
133 
135 DecorativeGeometry& setScale(Real scale) {return setScaleFactors(Vec3(scale));}
136 
139 int getBodyId() const;
140 
143 Real getResolution() const;
144 
148 const Transform& getTransform() const;
149 
153 const Vec3& getScaleFactors() const;
154 
160 DecorativeGeometry& setColor(const Vec3& rgb); // 0-1 for each color
161 
165 DecorativeGeometry& setOpacity(Real); // 0-1; default is 1 (opaque)
166 
171 DecorativeGeometry& setLineThickness(Real);
172 
175 const Vec3& getColor() const;
177 Real getOpacity() const;
180 Real getLineThickness() const;
181 
186 DecorativeGeometry& setFaceCamera(int shouldFace);
189 int getFaceCamera() const;
190 
194 DecorativeGeometry& setRepresentation(const Representation&);
195 
197 Representation getRepresentation() const;
198 
199 void implementGeometry(DecorativeGeometryImplementation&) const;
200 
201 // Bookkeeping below here -- internal use only. Don't look below or you will
202 // turn into a pillar of salt.
203 bool isOwnerHandle() const;
204 bool isEmptyHandle() const;
205 explicit DecorativeGeometry(class DecorativeGeometryRep* r) : rep(r) { }
206 bool hasRep() const {return rep!=0;}
207 const DecorativeGeometryRep& getRep() const {assert(rep); return *rep;}
208 DecorativeGeometryRep& updRep() {assert(rep); return *rep;}
209 protected:
210 DecorativeGeometryRep* rep;
211 };
212 
213 
219 public:
220  explicit DecorativePoint(const Vec3& p=Vec3(0));
221 
222  // These are specific to DecorativePoint.
223 
224  DecorativePoint& setPoint(const Vec3& p);
225  const Vec3& getPoint() const;
226 
227  // Retain the derived type when setting generic geometry options.
228 
233  DecorativePoint& setColor(const Vec3& rgb) {DecorativeGeometry::setColor(rgb); return *this;}
237  { DecorativeGeometry::setRepresentation(r); return *this; }
238 
239  SimTK_PIMPL_DOWNCAST(DecorativePoint, DecorativeGeometry);
240 private:
241  class DecorativePointRep& updRep();
242  const DecorativePointRep& getRep() const;
243 };
244 
255 public:
256  explicit DecorativeLine(const Vec3& p1=Vec3(0), const Vec3& p2=Vec3(1)); // line between p1 and p2
257 
258  // Retain the derived type when setting generic geometry options.
263  DecorativeLine& setColor(const Vec3& rgb) {DecorativeGeometry::setColor(rgb); return *this;}
267  DecorativeGeometry::setRepresentation(r); return *this;
268  }
269 
270  // These are specific to lines.
271  DecorativeLine& setPoint1(const Vec3& p1);
272  DecorativeLine& setPoint2(const Vec3& p2);
273  DecorativeLine& setEndpoints(const Vec3& p1, const Vec3& p2);
274 
275  const Vec3& getPoint1() const;
276  const Vec3& getPoint2() const;
277 
278  SimTK_PIMPL_DOWNCAST(DecorativeLine, DecorativeGeometry);
279 private:
280  class DecorativeLineRep& updRep();
281  const DecorativeLineRep& getRep() const;
282 };
283 
287 public:
288  explicit DecorativeCircle(Real radius=0.5);
289 
290  DecorativeCircle& setRadius(Real);
291  Real getRadius() const;
292 
293  SimTK_PIMPL_DOWNCAST(DecorativeCircle, DecorativeGeometry);
294 private:
295  class DecorativeCircleRep& updRep();
296  const DecorativeCircleRep& getRep() const;
297 };
298 
302 public:
303  explicit DecorativeSphere(Real radius=0.5);
304 
305  DecorativeSphere& setRadius(Real);
306  Real getRadius() const;
307 
308  SimTK_PIMPL_DOWNCAST(DecorativeSphere, DecorativeGeometry);
309 private:
310  class DecorativeSphereRep& updRep();
311  const DecorativeSphereRep& getRep() const;
312 };
313 
318 public:
319  explicit DecorativeEllipsoid(const Vec3& radii =
320  Vec3(Real(0.5),Real(1/3.),Real(0.25)));
321 
322  DecorativeEllipsoid& setRadii(const Vec3&);
323  const Vec3& getRadii() const;
324 
325  SimTK_PIMPL_DOWNCAST(DecorativeEllipsoid, DecorativeGeometry);
326 private:
327  class DecorativeEllipsoidRep& updRep();
328  const DecorativeEllipsoidRep& getRep() const;
329 };
330 
335 public:
336  explicit DecorativeBrick(const Vec3& halfLengths = Vec3(Real(0.5)));
337 
338  DecorativeBrick& setHalfLengths(const Vec3&);
339  const Vec3& getHalfLengths() const;
340 
341  SimTK_PIMPL_DOWNCAST(DecorativeBrick, DecorativeGeometry);
342 private:
343  class DecorativeBrickRep& updRep();
344  const DecorativeBrickRep& getRep() const;
345 };
346 
351 public:
352  explicit DecorativeCylinder(Real radius=0.5, Real halfHeight=0.5);
353 
354  DecorativeCylinder& setRadius(Real);
355  DecorativeCylinder& setHalfHeight(Real);
356  Real getRadius() const;
357  Real getHalfHeight() const;
358 
359  SimTK_PIMPL_DOWNCAST(DecorativeCylinder, DecorativeGeometry);
360 private:
361  class DecorativeCylinderRep& updRep();
362  const DecorativeCylinderRep& getRep() const;
363 };
364 
369 public:
370  explicit DecorativeFrame(Real axisLength=1);
371 
372  DecorativeFrame& setAxisLength(Real);
373  Real getAxisLength() const;
374 
375  SimTK_PIMPL_DOWNCAST(DecorativeFrame, DecorativeGeometry);
376 private:
377  class DecorativeFrameRep& updRep();
378  const DecorativeFrameRep& getRep() const;
379 };
380 
384 public:
385  explicit DecorativeText(const std::string& label="");
386 
387  DecorativeText& setText(const std::string& label);
388  const std::string& getText() const;
389 
392  DecorativeText& setIsScreenText(bool isScreen);
393  bool getIsScreenText() const;
394 
395  SimTK_PIMPL_DOWNCAST(DecorativeText, DecorativeGeometry);
396 private:
397  class DecorativeTextRep& updRep();
398  const DecorativeTextRep& getRep() const;
399 };
400 
404 public:
405  explicit DecorativeMesh(const PolygonalMesh& mesh);
406  const PolygonalMesh& getMesh() const;
407 
408  SimTK_PIMPL_DOWNCAST(DecorativeMesh, DecorativeGeometry);
409 private:
410  class DecorativeMeshRep& updRep();
411  const DecorativeMeshRep& getRep() const;
412 };
413 
414 
420 public:
422  Decorations();
425  explicit Decorations(const DecorativeGeometry& decoration);
427  Decorations& addDecoration(const DecorativeGeometry& decoration);
430  Decorations& addDecoration(const Transform& placement,
431  const DecorativeGeometry& decoration);
434  int getNumDecorations() const;
437  const DecorativeGeometry& getDecoration(int i) const;
438 
439  // Retain the derived type when setting generic geometry options.
440 
445  Decorations& setColor(const Vec3& rgb) {DecorativeGeometry::setColor(rgb); return *this;}
449  { DecorativeGeometry::setRepresentation(r); return *this; }
450 
451 
452  SimTK_PIMPL_DOWNCAST(Decorations, DecorativeGeometry);
453 private:
454  class DecorationsRep& updRep();
455  const DecorationsRep& getRep() const;
456 };
457 
461 public:
463  virtual void implementPointGeometry( const DecorativePoint&) = 0;
464  virtual void implementLineGeometry( const DecorativeLine&) = 0;
465  virtual void implementBrickGeometry( const DecorativeBrick&) = 0;
466  virtual void implementCylinderGeometry( const DecorativeCylinder&) = 0;
467  virtual void implementCircleGeometry( const DecorativeCircle&) = 0;
468  virtual void implementSphereGeometry( const DecorativeSphere&) = 0;
469  virtual void implementEllipsoidGeometry(const DecorativeEllipsoid&)= 0;
470  virtual void implementFrameGeometry( const DecorativeFrame&) = 0;
471  virtual void implementTextGeometry( const DecorativeText&) = 0;
472  virtual void implementMeshGeometry( const DecorativeMesh&) = 0;
473 };
474 
475 } // namespace SimTK
476 
477 #endif // SimTK_SimTKCOMMON_DECORATIVE_GEOMETRY_H_
const Vec3 Orange
RGB=( 1,.5, 0)
const Vec3 Yellow
RGB=( 1, 1, 0)
#define SimTK_SimTKCOMMON_EXPORT
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:202
DecorativePoint & setTransform(const Transform &X_BD)
Definition: DecorativeGeometry.h:230
This defines a rectangular solid centered at the origin and aligned with the local frame axes...
Definition: DecorativeGeometry.h:334
DecorativeLine & setScaleFactors(const Vec3 &s)
Definition: DecorativeGeometry.h:262
const DecorativeGeometryRep & getRep() const
Definition: DecorativeGeometry.h:207
DecorativeGeometry & setResolution(Real)
Each concrete DecorativeGeometry object is expected to have a default resolution that gets the point ...
This defines a text label with its base at the origin.
Definition: DecorativeGeometry.h:383
This defines geometry to represent a coordinate frame.
Definition: DecorativeGeometry.h:368
const Vec3 Gray
RGB=(.5,.5,.5)
Decorations & setTransform(const Transform &X_BD)
Definition: DecorativeGeometry.h:442
Decorations & setScaleFactors(const Vec3 &s)
Definition: DecorativeGeometry.h:444
Decorations & setBodyId(int b)
Definition: DecorativeGeometry.h:441
This defines an ellipsoidal solid centered at the origin and aligned with the local frame axes...
Definition: DecorativeGeometry.h:317
DecorativeGeometryRep & updRep()
Definition: DecorativeGeometry.h:208
const Vec3 Red
RGB=( 1, 0, 0)
Representation
Definition: DecorativeGeometry.h:94
DecorativeGeometry & setColor(const Vec3 &rgb)
Request a specific color for this DecorativeGeometry object.
DecorativePoint & setLineThickness(Real t)
Definition: DecorativeGeometry.h:235
Decorations & setOpacity(Real o)
Definition: DecorativeGeometry.h:446
DecorativeGeometry & setScale(Real scale)
Convenience method to set all three scale factors to the same value.
Definition: DecorativeGeometry.h:135
Decorations & setResolution(Real r)
Definition: DecorativeGeometry.h:443
const Vec3 Cyan
RGB=( 0, 1, 1)
DecorativeGeometryRep * rep
Definition: DecorativeGeometry.h:210
Decorations & setLineThickness(Real t)
Definition: DecorativeGeometry.h:447
DecorativeGeometry & setRepresentation(const Representation &)
Request a particular rendering representation of this DecorativeGeometry object.
DecorativePoint & setRepresentation(const Representation &r)
Definition: DecorativeGeometry.h:236
Decorations & setRepresentation(const Representation &r)
Definition: DecorativeGeometry.h:448
DecorativeLine & setBodyId(int b)
Definition: DecorativeGeometry.h:259
DecorativeGeometry & setScaleFactors(const Vec3 &scale)
Each concrete DecorativeGeometry object is expected to have a default size around "1"...
This defines a circle in the x-y plane, centered at the origin.
Definition: DecorativeGeometry.h:286
DecorativeGeometry & setLineThickness(Real)
Request an adjustment to the default rendering of lines and curves.
DecorativeGeometry & setOpacity(Real)
Request a level of transparency for this DecorativeGeometry.
const Vec3 Blue
RGB=( 0, 0, 1)
DecorativeGeometry()
Definition: DecorativeGeometry.h:88
DecorativePoint & setBodyId(int b)
Definition: DecorativeGeometry.h:229
DecorativeLine & setRepresentation(const Representation &r)
Definition: DecorativeGeometry.h:266
This class provides a description of a mesh made of polygonal faces (not limited to triangles)...
Definition: PolygonalMesh.h:71
const Vec3 Magenta
RGB=( 1, 0, 1)
This is the client-side interface to an implementation-independent representation of "Decorations" su...
Definition: DecorativeGeometry.h:86
This defines a sphere centered at the origin.
Definition: DecorativeGeometry.h:301
A point of interest.
Definition: DecorativeGeometry.h:218
DecorativeLine & setResolution(Real r)
Definition: DecorativeGeometry.h:261
DecorativeGeometry(class DecorativeGeometryRep *r)
Definition: DecorativeGeometry.h:205
DecorativeLine & setLineThickness(Real t)
Definition: DecorativeGeometry.h:265
virtual ~DecorativeGeometryImplementation()
Definition: DecorativeGeometry.h:462
DecorativeLine & setTransform(const Transform &X_BD)
Definition: DecorativeGeometry.h:260
bool hasRep() const
Definition: DecorativeGeometry.h:206
DecorativeGeometry & setTransform(const Transform &X_BG)
This transform shifts the generated polygons with respect to this object's local frame.
const Vec3 White
RGB=( 1, 1, 1)
DecorativePoint & setResolution(Real r)
Definition: DecorativeGeometry.h:231
Vec< 3 > Vec3
Definition: SmallMatrix.h:104
DecorativeLine & setOpacity(Real o)
Definition: DecorativeGeometry.h:264
const Vec3 Purple
RGB=(.5, 0,.5)
DecorativePoint & setColor(const Vec3 &rgb)
Definition: DecorativeGeometry.h:233
This defines a single DecorativeGeometry object that is composed of a collection of other DecorativeG...
Definition: DecorativeGeometry.h:419
const Vec3 Green
RGB=( 0, 1, 0)
DecorativeGeometry & setBodyId(int)
By default the geometry will be placed on ground.
A line between two points.
Definition: DecorativeGeometry.h:254
This is the header which should be included in user programs that would like to make use of all the S...
Use this abstract class to connect your implementation of decorative geometry to the implementation-i...
Definition: DecorativeGeometry.h:460
DecorativePoint & setScaleFactors(const Vec3 &s)
Definition: DecorativeGeometry.h:232
Decorations & setColor(const Vec3 &rgb)
Definition: DecorativeGeometry.h:445
DecorativePoint & setOpacity(Real o)
Definition: DecorativeGeometry.h:234
This defines a cylinder centered on the origin and aligned in the y direction.
Definition: DecorativeGeometry.h:350
This defines a displayable mesh by referencing an already-existing PolygonalMesh object.
Definition: DecorativeGeometry.h:403
DecorativeLine & setColor(const Vec3 &rgb)
Definition: DecorativeGeometry.h:263
const Vec3 Black
RGB=( 0, 0, 0)