Choreonoid  1.1
VrmlNodes.h
説明を見る。
1 
6 #ifndef CNOID_UTIL_VRMLNODES_H_INCLUDED
7 #define CNOID_UTIL_VRMLNODES_H_INCLUDED
8 
9 #include <map>
10 #include <string>
11 #include <bitset>
12 #include <boost/variant.hpp>
13 #include <boost/intrusive_ptr.hpp>
14 #include <Eigen/Core>
15 #include <Eigen/Geometry>
16 #include <Eigen/StdVector>
17 #include "exportdecl.h"
18 
19 namespace cnoid {
20 
21  typedef bool SFBool;
22  typedef int SFInt32;
23  typedef double SFFloat;
24  typedef std::string SFString;
25 
26  // Define SFTime as struct to clearly distinguish its type from SFFloat
27  struct SFTime {
28  double value;
29  inline SFTime() { value = 0.0; }
30  inline SFTime(double time) { value = time; }
31  inline double operator=(double time) { return (value = time); }
32  };
33 
34  typedef Eigen::Vector2d SFVec2f;
35  typedef Eigen::Vector3d SFVec3f;
36  typedef Eigen::Array3f SFColor;
37  typedef Eigen::AngleAxisd SFRotation;
38 
39  typedef struct {
40  int width;
41  int height;
43  std::vector<unsigned char> pixels;
44  } SFImage;
45 
46  typedef std::vector<SFInt32> MFInt32;
47  typedef std::vector<SFFloat> MFFloat;
48  typedef std::vector<SFVec2f, Eigen::aligned_allocator<SFVec2f> > MFVec2f;
49  typedef std::vector<SFVec3f> MFVec3f;
50  typedef std::vector<SFRotation> MFRotation;
51  typedef std::vector<SFTime> MFTime;
52  typedef std::vector<SFColor> MFColor;
53  typedef std::vector<SFString> MFString;
54 
55  // see 4.6.3 - 4.6.10 of the VRML97 specification
57 
58  ANY_NODE = -1,
59 
62 
67 
72 
79 
81 
84 
86  };
87 
88  class VrmlNode;
89 
90  inline void intrusive_ptr_add_ref(VrmlNode* obj);
91  inline void intrusive_ptr_release(VrmlNode* obj);
92 
95  {
96  public:
97 
98  VrmlNode();
99  virtual ~VrmlNode();
100 
101  std::string defName;
102 
103  bool isCategoryOf(VrmlNodeCategory category);
104 
105  protected:
106  std::bitset<NUM_VRML_NODE_CATEGORIES> categorySet;
107 
108  private:
109  int refCounter;
110 
111  friend void intrusive_ptr_add_ref(VrmlNode* obj);
112  friend void intrusive_ptr_release(VrmlNode* obj);
113  };
114 
115  inline void intrusive_ptr_add_ref(VrmlNode* obj){
116  obj->refCounter++;
117  }
118 
119  inline void intrusive_ptr_release(VrmlNode* obj){
120  obj->refCounter--;
121  if(obj->refCounter <= 0){
122  delete obj;
123  }
124  }
125 
126  typedef boost::intrusive_ptr<VrmlNode> VrmlNodePtr;
127 
129  typedef std::vector<SFNode> MFNode;
130 
131 
133  {
134  public:
135  VrmlUnsupportedNode(const std::string& nodeTypeName);
136  std::string nodeTypeName;
137  };
138  typedef boost::intrusive_ptr<VrmlUnsupportedNode> VrmlUnsupportedNodePtr;
139 
140 
143  {
144  public:
145  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
146 
147  VrmlViewpoint();
148 
154  };
155  typedef boost::intrusive_ptr<VrmlViewpoint> VrmlViewpointPtr;
156 
157 
160  {
161  public:
163 
169  };
170  typedef boost::intrusive_ptr<VrmlNavigationInfo> VrmlNavigationInfoPtr;
171 
172 
175  {
176  public:
177  VrmlBackground();
178 
189  };
190  typedef boost::intrusive_ptr<VrmlBackground> VrmlBackgroundPtr;
191 
192 
194  {
195  public:
197 
198  virtual MFNode& getChildren() = 0;
199  virtual int countChildren() = 0;
200  virtual VrmlNode* getChild(int index) = 0;
201  virtual void replaceChild(int childIndex, VrmlNode* childNode) = 0;
202 
203  void removeChild(int childIndex);
204  };
205  typedef boost::intrusive_ptr<AbstractVrmlGroup> AbstractVrmlGroupPtr;
206 
207 
210  {
211  public:
212  VrmlGroup();
213 
214  virtual MFNode& getChildren();
215  virtual int countChildren();
216  virtual VrmlNode* getChild(int index);
217  virtual void replaceChild(int childIndex, VrmlNode* childNode);
218 
222  };
223  typedef boost::intrusive_ptr<VrmlGroup> VrmlGroupPtr;
224 
225 
228  {
229  public:
230  VrmlTransform();
231 
232  Eigen::Affine3d toAffine3d();
233 
239  };
240  typedef boost::intrusive_ptr<VrmlTransform> VrmlTransformPtr;
241 
244  {
245  public:
246  VrmlInline();
248  };
249  typedef boost::intrusive_ptr<VrmlInline> VrmlInlinePtr;
250 
251 
253  typedef boost::intrusive_ptr<VrmlAppearance> VrmlAppearancePtr;
254 
256  typedef boost::intrusive_ptr<VrmlGeometry> VrmlGeometryPtr;
257 
258 
261  {
262  public:
263  VrmlShape();
266  };
267  typedef boost::intrusive_ptr<VrmlShape> VrmlShapePtr;
268 
269 
271  typedef boost::intrusive_ptr<VrmlMaterial> VrmlMaterialPtr;
272 
273  class VrmlTexture;
274  typedef boost::intrusive_ptr<VrmlTexture> VrmlTexturePtr;
275 
277  typedef boost::intrusive_ptr<VrmlTextureTransform> VrmlTextureTransformPtr;
278 
281  {
282  public:
283  VrmlAppearance();
284 
288  };
289 
290 
293  {
294  public:
295  VrmlMaterial();
296 
303  };
304 
305 
308  {
309  public:
310  VrmlTexture();
311  };
312 
313 
316  {
317  public:
319 
323  };
324  typedef boost::intrusive_ptr<VrmlImageTexture> VrmlImageTexturePtr;
325 
326 
329  {
330  public:
331  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
332 
334 
339  };
340 
343  {
344  public:
345  VrmlGeometry();
346  };
347 
350  {
351  public:
352  VrmlBox();
354  };
355  typedef boost::intrusive_ptr<VrmlBox> VrmlBoxPtr;
356 
357 
360  {
361  public:
362  VrmlCone();
363 
368  };
369  typedef boost::intrusive_ptr<VrmlCone> VrmlConePtr;
370 
371 
374  {
375  public:
376  VrmlCylinder();
377 
383  };
384  typedef boost::intrusive_ptr<VrmlCylinder> VrmlCylinderPtr;
385 
386 
389  {
390  public:
391  VrmlSphere();
393  };
394  typedef boost::intrusive_ptr<VrmlSphere> VrmlSpherePtr;
395 
396 
399  {
400  public:
401  VrmlFontStyle();
402 
412  };
413  typedef boost::intrusive_ptr<VrmlFontStyle> VrmlFontStylePtr;
414 
415 
418  {
419  public:
420  VrmlText();
421 
426  };
427  typedef boost::intrusive_ptr<VrmlText> VrmlTextPtr;
428 
429 
430  class VrmlColor;
431  typedef boost::intrusive_ptr<VrmlColor> VrmlColorPtr;
432 
434  typedef boost::intrusive_ptr<VrmlCoordinate> VrmlCoordinatePtr;
435 
438  {
439  public:
441 
447  };
448  typedef boost::intrusive_ptr<VrmlIndexedLineSet> VrmlIndexedLineSetPtr;
449 
450 
451  class VrmlNormal;
452  typedef boost::intrusive_ptr<VrmlNormal> VrmlNormalPtr;
453 
455  typedef boost::intrusive_ptr<VrmlTextureCoordinate> VrmlTextureCoordinatePtr;
456 
457 
460  {
461  public:
463 
473  };
474  typedef boost::intrusive_ptr<VrmlIndexedFaceSet> VrmlIndexedFaceSetPtr;
475 
476 
479  {
480  public:
481  VrmlColor();
482 
484  };
485 
486 
489  {
490  public:
491  VrmlCoordinate();
493  };
494 
495 
498  {
499  public:
502  };
503 
504 
507  {
508  public:
509  VrmlNormal();
511  };
512 
513 
516  {
517  public:
519 
526  };
527  typedef boost::intrusive_ptr<VrmlCylinderSensor> VrmlCylinderSensorPtr;
528 
529 
532  {
533  public:
534  VrmlPointSet();
535 
538  };
539 
540  typedef boost::intrusive_ptr<VrmlPointSet> VrmlPointSetPtr;
541 
542 
545  {
546  public:
548 
552  };
553 
554  typedef boost::intrusive_ptr<VrmlPixelTexture> VrmlPixelTexturePtr;
555 
556 
559  {
560  public:
562 
570  };
571 
572  typedef boost::intrusive_ptr<VrmlMovieTexture> VrmlMovieTexturePtr;
573 
574 
577  {
578  public:
580 
594  };
595 
596  typedef boost::intrusive_ptr<VrmlElevationGrid> VrmlElevationGridPtr;
597 
598 
601  {
602  public:
603  VrmlExtrusion();
604 
615  };
616 
617  typedef boost::intrusive_ptr<VrmlExtrusion> VrmlExtrusionPtr;
618 
619 
621  {
622  public:
623  VrmlSwitch();
624 
625  virtual MFNode& getChildren();
626  virtual int countChildren();
627  virtual VrmlNode* getChild(int index);
628  virtual void replaceChild(int childIndex, VrmlNode* childNode);
629 
632  };
633 
634  typedef boost::intrusive_ptr<VrmlSwitch> VrmlSwitchPtr;
635 
636 
638  {
639  public:
640  VrmlLOD();
641 
642  virtual MFNode& getChildren();
643  virtual int countChildren();
644  virtual VrmlNode* getChild(int index);
645  virtual void replaceChild(int childIndex, VrmlNode* childNode);
646 
650  };
651 
652  typedef boost::intrusive_ptr<VrmlLOD> VrmlLODPtr;
653 
654 
656  {
657  public:
658  VrmlCollision();
661  };
662 
663  typedef boost::intrusive_ptr<VrmlCollision> VrmlCollisionPtr;
664 
665 
667  {
668  public:
669  VrmlAnchor();
673  };
674 
675  typedef boost::intrusive_ptr<VrmlAnchor> VrmlAnchorPtr;
676 
677 
679  {
680  public:
681  VrmlBillboard();
683  };
684 
685  typedef boost::intrusive_ptr<VrmlBillboard> VrmlBillboardPtr;
686 
687 
689  {
690  public:
691  VrmlFog();
695  };
696 
697  typedef boost::intrusive_ptr<VrmlFog> VrmlFogPtr;
698 
699 
701  {
702  public:
703  VrmlWorldInfo();
706  };
707 
708  typedef boost::intrusive_ptr<VrmlWorldInfo> VrmlWorldInfoPtr;
709 
710 
712  {
713  public:
714  VrmlPointLight();
722  };
723 
724  typedef boost::intrusive_ptr<VrmlPointLight> VrmlPointLightPtr;
725 
726 
728  {
729  public:
736  };
737 
738  typedef boost::intrusive_ptr<VrmlDirectionalLight> VrmlDirectionalLightPtr;
739 
740 
742  {
743  public:
744  VrmlSpotLight();
755  };
756 
757  typedef boost::intrusive_ptr<VrmlSpotLight> VrmlSpotLightPtr;
758 
759  typedef boost::variant<SFBool,
762 
768  };
769 
770  typedef std::map <std::string, VrmlVariantField> TProtoFieldMap;
771  typedef std::pair<std::string, VrmlVariantField> TProtoFieldPair;
772 
773  template<typename TValue> int vrmlFieldTypeId() { return UNKNOWN_VRML_FIELD_TYPE; }
774  template<> inline int vrmlFieldTypeId<SFInt32>() { return SFINT32; }
775  template<> inline int vrmlFieldTypeId<MFInt32>() { return MFINT32; }
776  template<> inline int vrmlFieldTypeId<SFFloat>() { return SFFLOAT; }
777  template<> inline int vrmlFieldTypeId<MFFloat>() { return MFFLOAT; }
778  template<> inline int vrmlFieldTypeId<SFVec3f>() { return SFVEC3F; }
779  template<> inline int vrmlFieldTypeId<MFVec3f>() { return MFVEC3F; }
780  template<> inline int vrmlFieldTypeId<SFRotation>() { return SFROTATION; }
781  template<> inline int vrmlFieldTypeId<MFRotation>() { return MFROTATION; }
782  template<> inline int vrmlFieldTypeId<SFTime>() { return SFTIME; }
783  template<> inline int vrmlFieldTypeId<MFTime>() { return MFTIME; }
784  template<> inline int vrmlFieldTypeId<SFColor>() { return SFCOLOR; }
785  template<> inline int vrmlFieldTypeId<MFColor>() { return MFCOLOR; }
786  template<> inline int vrmlFieldTypeId<SFString>() { return SFSTRING; }
787  template<> inline int vrmlFieldTypeId<MFString>() { return MFSTRING; }
788  template<> inline int vrmlFieldTypeId<SFNode>() { return SFNODE; }
789  template<> inline int vrmlFieldTypeId<MFNode>() { return MFNODE; }
790  template<> inline int vrmlFieldTypeId<SFImage>() { return SFIMAGE; }
791 
792  CNOID_EXPORT const char* labelOfVrmlFieldTypeId(int type);
793 
794  template<typename TValue> inline const char* labelOfVrmlFieldType() {
795  return labelOfVrmlFieldTypeId(vrmlFieldTypeId<TValue>());
796  }
797 
800  {
801  public:
802  std::string protoName;
804 
805  VrmlProto(const std::string& n);
806 
807  inline VrmlVariantField* findField(const std::string& fieldName) {
808  TProtoFieldMap::iterator p = fields.find(fieldName);
809  return (p != fields.end()) ? &p->second : 0;
810  }
811 
812  inline VrmlVariantField& field(const std::string& fieldName){
813  return fields[fieldName];
814  }
815 
816  /*
817  inline VrmlVariantField& addField(const std::string& fieldName, VrmlFieldTypeId typeId){
818  VrmlVariantField* field = &(fields[fieldName]);
819  field->setType(typeId);
820  return field;
821  }
822  */
823 
824  };
825  typedef boost::intrusive_ptr<VrmlProto> VrmlProtoPtr;
826 
827 
830  {
831  public:
835 
837 
838  inline VrmlVariantField* findField(const std::string& fieldName) {
839  TProtoFieldMap::iterator p = fields.find(fieldName);
840  return (p != fields.end()) ? &p->second : 0;
841  }
842 
843  };
844  typedef boost::intrusive_ptr<VrmlProtoInstance> VrmlProtoInstancePtr;
845 
851  template<class VrmlNodeType>
852  inline boost::intrusive_ptr<VrmlNodeType> dynamic_node_cast(VrmlNodePtr node) {
853  VrmlProtoInstancePtr protoInstance = boost::dynamic_pointer_cast<VrmlProtoInstance>(node);
854  if(protoInstance){
855  return boost::dynamic_pointer_cast<VrmlNodeType>(protoInstance->actualNode);
856  } else {
857  return boost::dynamic_pointer_cast<VrmlNodeType>(node);
858  }
859  }
860 
861 };
862 
863 #endif