Simbody  3.4
 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-13 Stanford University and the Authors. *
13  * Authors: Michael Sherman *
14  * Contributors: Jack Middleton, Peter Eastman, Ayman Habib *
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:
89 DecorativeGeometry() : rep(0) { }
96 DecorativeGeometry& operator=(const DecorativeGeometry& source);
97 
100  DrawPoints = 1,
101  DrawWireframe = 2,
102  DrawSurface = 3,
103 
104  DrawDefault = -1
105 };
106 
117 DecorativeGeometry& setBodyId(int bodyId);
118 
125 DecorativeGeometry& setIndexOnBody(int index);
126 
140 DecorativeGeometry& setUserRef(void* userRef);
141 
147 DecorativeGeometry& setTransform(const Transform& X_BG);
148 
157 DecorativeGeometry& setResolution(Real);
158 
166 DecorativeGeometry& setScaleFactors(const Vec3& scale);
167 
169 DecorativeGeometry& setScale(Real scale) {return setScaleFactors(Vec3(scale));}
170 
176 int getBodyId() const;
177 
182 int getIndexOnBody() const;
183 
188 void* getUserRef() const;
189 
192 Real getResolution() const;
193 
197 const Transform& getTransform() const;
198 
202 const Vec3& getScaleFactors() const;
203 
209 DecorativeGeometry& setColor(const Vec3& rgb); // 0-1 for each color
210 
214 DecorativeGeometry& setOpacity(Real); // 0-1; default is 1 (opaque)
215 
220 DecorativeGeometry& setLineThickness(Real);
221 
224 const Vec3& getColor() const;
226 Real getOpacity() const;
229 Real getLineThickness() const;
230 
235 DecorativeGeometry& setFaceCamera(int shouldFace);
238 int getFaceCamera() const;
239 
243 DecorativeGeometry& setRepresentation(const Representation&);
244 
246 Representation getRepresentation() const;
247 
248 void implementGeometry(DecorativeGeometryImplementation&) const;
249 
250 // Bookkeeping below here -- internal use only. Don't look below or you will
251 // turn into a pillar of salt.
252 bool isOwnerHandle() const;
253 bool isEmptyHandle() const;
254 explicit DecorativeGeometry(class DecorativeGeometryRep* r) : rep(r) { }
255 bool hasRep() const {return rep!=0;}
256 const DecorativeGeometryRep& getRep() const {assert(rep); return *rep;}
257 DecorativeGeometryRep& updRep() {assert(rep); return *rep;}
258 protected:
259 DecorativeGeometryRep* rep;
260 };
261 
262 
268 public:
269  explicit DecorativePoint(const Vec3& p=Vec3(0));
270 
271  // These are specific to DecorativePoint.
272 
273  DecorativePoint& setPoint(const Vec3& p);
274  const Vec3& getPoint() const;
275 
276  // Retain the derived type when setting generic geometry options.
283  DecorativePoint& setColor(const Vec3& rgb) {DecorativeGeometry::setColor(rgb); return *this;}
286  DecorativePoint& setRepresentation(const Representation& r)
287  { DecorativeGeometry::setRepresentation(r); return *this; }
288 
290 private:
291  class DecorativePointRep& updRep();
292  const DecorativePointRep& getRep() const;
293 };
294 
305 public:
306  explicit DecorativeLine(const Vec3& p1=Vec3(0), const Vec3& p2=Vec3(1)); // line between p1 and p2
307 
308  // These are specific to lines.
309  DecorativeLine& setPoint1(const Vec3& p1);
310  DecorativeLine& setPoint2(const Vec3& p2);
311  DecorativeLine& setEndpoints(const Vec3& p1, const Vec3& p2);
312 
313  // Retain the derived type when setting generic geometry options.
320  DecorativeLine& setColor(const Vec3& rgb) {DecorativeGeometry::setColor(rgb); return *this;}
323  DecorativeLine& setRepresentation(const Representation& r)
324  { DecorativeGeometry::setRepresentation(r); return *this; }
325 
326  const Vec3& getPoint1() const;
327  const Vec3& getPoint2() const;
328 
330 private:
331  class DecorativeLineRep& updRep();
332  const DecorativeLineRep& getRep() const;
333 };
334 
338 public:
339  explicit DecorativeCircle(Real radius=0.5);
340 
341  DecorativeCircle& setRadius(Real);
342  Real getRadius() const;
343 
344  // Retain the derived type when setting generic geometry options.
351  DecorativeCircle& setColor(const Vec3& rgb) {DecorativeGeometry::setColor(rgb); return *this;}
354  DecorativeCircle& setRepresentation(const Representation& r)
355  { DecorativeGeometry::setRepresentation(r); return *this; }
356 
358 private:
359  class DecorativeCircleRep& updRep();
360  const DecorativeCircleRep& getRep() const;
361 };
362 
366 public:
367  explicit DecorativeSphere(Real radius=0.5);
368 
369  DecorativeSphere& setRadius(Real);
370  Real getRadius() const;
371 
372  // Retain the derived type when setting generic geometry options.
379  DecorativeSphere& setColor(const Vec3& rgb) {DecorativeGeometry::setColor(rgb); return *this;}
382  DecorativeSphere& setRepresentation(const Representation& r)
383  { DecorativeGeometry::setRepresentation(r); return *this; }
384 
386 private:
387  class DecorativeSphereRep& updRep();
388  const DecorativeSphereRep& getRep() const;
389 };
390 
395 public:
396  explicit DecorativeEllipsoid(const Vec3& radii =
397  Vec3(Real(0.5),Real(1/3.),Real(0.25)));
398 
399  DecorativeEllipsoid& setRadii(const Vec3&);
400  const Vec3& getRadii() const;
401 
402  // Retain the derived type when setting generic geometry options.
412  DecorativeEllipsoid& setRepresentation(const Representation& r)
413  { DecorativeGeometry::setRepresentation(r); return *this; }
414 
416 private:
417  class DecorativeEllipsoidRep& updRep();
418  const DecorativeEllipsoidRep& getRep() const;
419 };
420 
425 public:
426  explicit DecorativeBrick(const Vec3& halfLengths = Vec3(Real(0.5)));
427 
428  DecorativeBrick& setHalfLengths(const Vec3&);
429  const Vec3& getHalfLengths() const;
430 
431  // Retain the derived type when setting generic geometry options.
438  DecorativeBrick& setColor(const Vec3& rgb) {DecorativeGeometry::setColor(rgb); return *this;}
441  DecorativeBrick& setRepresentation(const Representation& r)
442  { DecorativeGeometry::setRepresentation(r); return *this; }
443 
445 private:
446  class DecorativeBrickRep& updRep();
447  const DecorativeBrickRep& getRep() const;
448 };
449 
454 public:
455  explicit DecorativeCylinder(Real radius=0.5, Real halfHeight=0.5);
456 
457  DecorativeCylinder& setRadius(Real);
458  DecorativeCylinder& setHalfHeight(Real);
459  Real getRadius() const;
460  Real getHalfHeight() const;
461 
462  // Retain the derived type when setting generic geometry options.
472  DecorativeCylinder& setRepresentation(const Representation& r)
473  { DecorativeGeometry::setRepresentation(r); return *this; }
474 
476 private:
477  class DecorativeCylinderRep& updRep();
478  const DecorativeCylinderRep& getRep() const;
479 };
480 
485 public:
486  explicit DecorativeFrame(Real axisLength=1);
487 
488  DecorativeFrame& setAxisLength(Real);
489  Real getAxisLength() const;
490 
491  // Retain the derived type when setting generic geometry options.
498  DecorativeFrame& setColor(const Vec3& rgb) {DecorativeGeometry::setColor(rgb); return *this;}
501  DecorativeFrame& setRepresentation(const Representation& r)
502  { DecorativeGeometry::setRepresentation(r); return *this; }
503 
505 private:
506  class DecorativeFrameRep& updRep();
507  const DecorativeFrameRep& getRep() const;
508 };
509 
513 public:
514  explicit DecorativeText(const std::string& label="");
515 
516  DecorativeText& setText(const std::string& label);
517  const std::string& getText() const;
518 
521  DecorativeText& setIsScreenText(bool isScreen);
522  bool getIsScreenText() const;
523 
524  // Retain the derived type when setting generic geometry options.
531  DecorativeText& setColor(const Vec3& rgb) {DecorativeGeometry::setColor(rgb); return *this;}
534  DecorativeText& setRepresentation(const Representation& r)
535  { DecorativeGeometry::setRepresentation(r); return *this; }
536 
538 private:
539  class DecorativeTextRep& updRep();
540  const DecorativeTextRep& getRep() const;
541 };
542 
546 public:
547  explicit DecorativeMesh(const PolygonalMesh& mesh);
548  const PolygonalMesh& getMesh() const;
549 
550  // Retain the derived type when setting generic geometry options.
557  DecorativeMesh& setColor(const Vec3& rgb) {DecorativeGeometry::setColor(rgb); return *this;}
560  DecorativeMesh& setRepresentation(const Representation& r)
561  { DecorativeGeometry::setRepresentation(r); return *this; }
562 
564 private:
565  class DecorativeMeshRep& updRep();
566  const DecorativeMeshRep& getRep() const;
567 };
568 
569 
573 public:
574  explicit DecorativeMeshFile(const std::string& meshFileName);
575  const std::string& getMeshFile() const;
576 
577  // Retain the derived type when setting generic geometry options.
587  DecorativeMeshFile& setRepresentation(const Representation& r)
588  { DecorativeGeometry::setRepresentation(r); return *this; }
589 
591 private:
592  class DecorativeMeshFileRep& updRep();
593  const DecorativeMeshFileRep& getRep() const;
594 };
595 
596 
607 public:
609  Decorations();
612  explicit Decorations(const DecorativeGeometry& decoration);
614  Decorations& addDecoration(const DecorativeGeometry& decoration);
617  Decorations& addDecoration(const Transform& placement,
618  const DecorativeGeometry& decoration);
621  int getNumDecorations() const;
624  const DecorativeGeometry& getDecoration(int i) const;
625 
626  // Retain the derived type when setting generic geometry options.
633  Decorations& setColor(const Vec3& rgb) {DecorativeGeometry::setColor(rgb); return *this;}
636  Decorations& setRepresentation(const Representation& r)
637  { DecorativeGeometry::setRepresentation(r); return *this; }
638 
639 
641 private:
642  class DecorationsRep& updRep();
643  const DecorationsRep& getRep() const;
644 };
645 
649 public:
651  virtual void implementPointGeometry( const DecorativePoint&) = 0;
652  virtual void implementLineGeometry( const DecorativeLine&) = 0;
653  virtual void implementBrickGeometry( const DecorativeBrick&) = 0;
654  virtual void implementCylinderGeometry( const DecorativeCylinder&) = 0;
655  virtual void implementCircleGeometry( const DecorativeCircle&) = 0;
656  virtual void implementSphereGeometry( const DecorativeSphere&) = 0;
657  virtual void implementEllipsoidGeometry(const DecorativeEllipsoid&)= 0;
658  virtual void implementFrameGeometry( const DecorativeFrame&) = 0;
659  virtual void implementTextGeometry( const DecorativeText&) = 0;
660  virtual void implementMeshGeometry( const DecorativeMesh&) = 0;
661  virtual void implementMeshFileGeometry( const DecorativeMeshFile&) =0;
662 };
663 
664 } // namespace SimTK
665 
666 #endif // SimTK_SimTKCOMMON_DECORATIVE_GEOMETRY_H_