VrmlNodes.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * National Institute of Advanced Industrial Science and Technology (AIST)
00008  * General Robotix Inc. 
00009  */
00010 
00017 #ifndef OPENHRP_UTIL_VRMLNODES_H_INCLUDED
00018 #define OPENHRP_UTIL_VRMLNODES_H_INCLUDED
00019 
00020 #include "config.h"
00021 
00022 #include <vector>
00023 #include <string>
00024 #include <map>
00025 #include <bitset>
00026 #include <typeinfo>
00027 #include <boost/intrusive_ptr.hpp>
00028 #include <boost/array.hpp>
00029 
00030 
00031 namespace hrp {
00032 
00033     enum VrmlFieldTypeId {
00034         UNDETERMINED_FIELD_TYPE = 0,
00035         SFBOOL,
00036         SFINT32, MFINT32,
00037         SFFLOAT, MFFLOAT,
00038         SFVEC2F, MFVEC2F,
00039         SFVEC3F, MFVEC3F,
00040         SFROTATION, MFROTATION,
00041         SFTIME, MFTIME,
00042         SFCOLOR, MFCOLOR,
00043         SFSTRING, MFSTRING,
00044         SFNODE, MFNODE,
00045         SFIMAGE,
00046     };
00047 
00048     typedef bool        SFBool;
00049     typedef int         SFInt32;
00050     typedef double      SFFloat;
00051     typedef SFFloat     SFTime;
00052     typedef std::string SFString;
00053 
00054     typedef boost::array<SFFloat, 2> SFVec2f;
00055     typedef boost::array<SFFloat, 3> SFVec3f;
00056     typedef boost::array<SFFloat, 4> SFVec4f;
00057 
00058     typedef SFVec3f SFColor;
00059     typedef SFVec4f SFRotation;
00060 
00061     typedef struct {
00062         int                             width;
00063         int                             height;
00064         int                             numComponents;
00065         std::vector<unsigned char> pixels;
00066     } SFImage;
00067 
00068 
00069     typedef std::vector<SFInt32>    MFInt32;
00070     typedef std::vector<SFFloat>    MFFloat;
00071     typedef std::vector<SFVec2f>    MFVec2f;
00072     typedef std::vector<SFVec3f>    MFVec3f;
00073     typedef std::vector<SFVec4f>    MFVec4f;
00074     typedef std::vector<SFRotation> MFRotation;
00075     typedef std::vector<SFTime>     MFTime;
00076     typedef std::vector<SFColor>    MFColor;
00077     typedef std::vector<SFString>   MFString;
00078 
00079 
00080     // see 4.6.3 - 4.6.10 of the VRML97 specification
00081     enum VrmlNodeCategory {
00082 
00083         ANY_NODE = -1,
00084 
00085         PROTO_DEF_NODE = 0,
00086         PROTO_INSTANCE_NODE,
00087 
00088         TOP_NODE,
00089         BINDABLE_NODE,
00090         GROUPING_NODE,
00091         CHILD_NODE,
00092 
00093         APPEARANCE_NODE,
00094         MATERIAL_NODE,
00095         TEXTURE_NODE,
00096         TEXTURE_TRANSFORM_NODE,
00097 
00098         SHAPE_NODE,
00099         GEOMETRY_NODE,
00100         COORDINATE_NODE,
00101         COLOR_NODE,
00102         NORMAL_NODE,
00103         TEXTURE_COORDINATE_NODE,
00104 
00105         FONT_STYLE_NODE,
00106 
00107         SENSOR_NODE,
00108         INLINE_NODE,
00109 
00110         LIGHT_NODE,
00111 
00112         NUM_VRML_NODE_CATEGORIES
00113     };
00114 
00115     class VrmlNode;
00116 
00117     inline void intrusive_ptr_add_ref(VrmlNode* obj);
00118     inline void intrusive_ptr_release(VrmlNode* obj);
00119 
00121     class HRP_UTIL_EXPORT VrmlNode
00122     {
00123       public:
00124 
00125         VrmlNode();
00126         virtual ~VrmlNode();
00127 
00128         static const char* getLabelOfFieldType(int type);
00129         
00130         std::string defName;
00131 
00132         bool isCategoryOf(VrmlNodeCategory category);
00133 
00134       protected:
00135         std::bitset<NUM_VRML_NODE_CATEGORIES> categorySet;
00136 
00137       private:
00138         int refCounter;
00139 
00140         friend void intrusive_ptr_add_ref(VrmlNode* obj);
00141         friend void intrusive_ptr_release(VrmlNode* obj);
00142     };
00143 
00144     inline void intrusive_ptr_add_ref(VrmlNode* obj){
00145         obj->refCounter++;
00146     }
00147     
00148     inline void intrusive_ptr_release(VrmlNode* obj){
00149         obj->refCounter--;
00150         if(obj->refCounter <= 0){
00151             delete obj;
00152         }
00153     }
00154 
00155     typedef boost::intrusive_ptr<VrmlNode> VrmlNodePtr;
00156 
00157     typedef VrmlNodePtr SFNode;
00158     typedef std::vector<SFNode> MFNode;
00159 
00160 
00161     class HRP_UTIL_EXPORT  VrmlUnsupportedNode : public VrmlNode
00162     {
00163       public:
00164         VrmlUnsupportedNode(const std::string& nodeTypeName);
00165         std::string nodeTypeName;
00166     };
00167     typedef boost::intrusive_ptr<VrmlUnsupportedNode> VrmlUnsupportedNodePtr;
00168 
00169 
00171     class HRP_UTIL_EXPORT  VrmlViewpoint : public VrmlNode
00172     {
00173       public:
00174         VrmlViewpoint();
00175 
00176         SFFloat fieldOfView;
00177         SFBool jump;
00178         SFRotation orientation;
00179         SFVec3f position;
00180         SFString description;
00181     };
00182     typedef boost::intrusive_ptr<VrmlViewpoint> VrmlViewpointPtr;
00183 
00184 
00186     class HRP_UTIL_EXPORT  VrmlNavigationInfo : public VrmlNode
00187     {
00188       public:
00189         VrmlNavigationInfo();
00190 
00191         MFFloat avatarSize;
00192         SFBool headlight;
00193         SFFloat speed;
00194         MFString type;
00195         SFFloat visibilityLimit;
00196     };
00197     typedef boost::intrusive_ptr<VrmlNavigationInfo> VrmlNavigationInfoPtr;
00198 
00199 
00201     class HRP_UTIL_EXPORT  VrmlBackground : public VrmlNode
00202     {
00203       public:
00204         VrmlBackground();
00205       
00206         MFFloat groundAngle;
00207         MFColor groundColor;
00208         MFFloat skyAngle;
00209         MFColor skyColor;
00210         MFString backUrl;
00211         MFString bottomUrl;
00212         MFString frontUrl;
00213         MFString leftUrl;
00214         MFString rightUrl;
00215         MFString topUrl;
00216     };
00217     typedef boost::intrusive_ptr<VrmlBackground> VrmlBackgroundPtr;
00218 
00219 
00220     class HRP_UTIL_EXPORT  AbstractVrmlGroup : public VrmlNode
00221     {
00222       public:
00223         AbstractVrmlGroup();
00224         
00225         virtual MFNode& getChildren() = 0;
00226         virtual int countChildren() = 0;
00227         virtual VrmlNode* getChild(int index) = 0;
00228         virtual void replaceChild(int childIndex, VrmlNode* childNode) = 0;
00229         
00230         void removeChild(int childIndex);
00231     };
00232     typedef boost::intrusive_ptr<AbstractVrmlGroup> AbstractVrmlGroupPtr;
00233     
00234     
00236     class HRP_UTIL_EXPORT VrmlGroup : public AbstractVrmlGroup
00237     {
00238       public:
00239         VrmlGroup();
00240 
00241         virtual MFNode& getChildren();
00242         virtual int countChildren();
00243         virtual VrmlNode* getChild(int index);
00244         virtual void replaceChild(int childIndex, VrmlNode* childNode);
00245 
00246         SFVec3f bboxCenter;    
00247         SFVec3f bboxSize;  
00248         MFNode children;
00249     };
00250     typedef boost::intrusive_ptr<VrmlGroup> VrmlGroupPtr;
00251 
00252 
00254     class HRP_UTIL_EXPORT  VrmlTransform : public VrmlGroup
00255     {
00256       public:
00257         VrmlTransform();
00258 
00259         SFVec3f center;
00260         SFRotation rotation;
00261         SFVec3f scale;
00262         SFRotation scaleOrientation;
00263         SFVec3f translation;
00264     };
00265     typedef boost::intrusive_ptr<VrmlTransform> VrmlTransformPtr;
00266 
00268     class HRP_UTIL_EXPORT  VrmlInline : public VrmlGroup
00269     {
00270       public:
00271         VrmlInline();
00272         MFString urls;
00273     };
00274     typedef boost::intrusive_ptr<VrmlInline> VrmlInlinePtr;
00275 
00276 
00277     class VrmlAppearance;
00278     typedef boost::intrusive_ptr<VrmlAppearance> VrmlAppearancePtr;
00279 
00280     class VrmlGeometry;
00281     typedef boost::intrusive_ptr<VrmlGeometry> VrmlGeometryPtr;
00282 
00283 
00285     class HRP_UTIL_EXPORT  VrmlShape : public VrmlNode
00286     {
00287       public:
00288         VrmlShape();
00289         VrmlAppearancePtr appearance;
00290         SFNode geometry;
00291     };
00292     typedef boost::intrusive_ptr<VrmlShape> VrmlShapePtr;
00293 
00294 
00295     class VrmlMaterial;
00296     typedef boost::intrusive_ptr<VrmlMaterial> VrmlMaterialPtr;
00297 
00298     class VrmlTexture;
00299     typedef boost::intrusive_ptr<VrmlTexture> VrmlTexturePtr;
00300 
00301     class VrmlTextureTransform;
00302     typedef boost::intrusive_ptr<VrmlTextureTransform> VrmlTextureTransformPtr;
00303 
00304 
00306     class HRP_UTIL_EXPORT  VrmlAppearance : public VrmlNode
00307     {
00308       public:
00309         VrmlAppearance();
00310       
00311         VrmlMaterialPtr material;
00312         VrmlTexturePtr texture;
00313         VrmlTextureTransformPtr textureTransform;
00314     };
00315 
00316 
00318     class HRP_UTIL_EXPORT  VrmlMaterial : public VrmlNode
00319     {
00320       public:
00321         VrmlMaterial();
00322 
00323         SFFloat ambientIntensity;
00324         SFColor diffuseColor;
00325         SFColor emissiveColor;
00326         SFFloat shininess;
00327         SFColor specularColor;
00328         SFFloat transparency;
00329     };
00330 
00331 
00333     class HRP_UTIL_EXPORT  VrmlTexture : public VrmlNode
00334     {
00335       public:
00336         VrmlTexture();
00337     };
00338 
00339     
00341     class HRP_UTIL_EXPORT  VrmlImageTexture : public VrmlTexture
00342     {
00343       public:
00344         VrmlImageTexture();
00345 
00346         MFString url;
00347         SFBool   repeatS;
00348         SFBool   repeatT;
00349     };
00350     typedef boost::intrusive_ptr<VrmlImageTexture> VrmlImageTexturePtr;
00351 
00352 
00354     class HRP_UTIL_EXPORT  VrmlTextureTransform : public VrmlNode
00355     {
00356       public:
00357         VrmlTextureTransform();
00358 
00359         SFVec2f center;
00360         SFFloat rotation;
00361         SFVec2f scale;
00362         SFVec2f translation;
00363     };
00364 
00366     class HRP_UTIL_EXPORT  VrmlGeometry : public VrmlNode
00367     {
00368       public:
00369         VrmlGeometry();
00370     };
00371 
00373     class HRP_UTIL_EXPORT  VrmlBox : public VrmlGeometry
00374     {
00375       public:
00376         VrmlBox();
00377         SFVec3f size;
00378     };
00379     typedef boost::intrusive_ptr<VrmlBox> VrmlBoxPtr;
00380 
00381 
00383     class HRP_UTIL_EXPORT  VrmlCone : public VrmlGeometry
00384     {
00385       public:
00386         VrmlCone();
00387 
00388         SFBool bottom;
00389         SFFloat bottomRadius;
00390         SFFloat height;
00391         SFBool side;
00392     };
00393     typedef boost::intrusive_ptr<VrmlCone> VrmlConePtr;
00394 
00395 
00397     class HRP_UTIL_EXPORT  VrmlCylinder : public VrmlGeometry
00398     {
00399       public:
00400         VrmlCylinder();
00401 
00402         SFBool bottom;
00403         SFFloat height;
00404         SFFloat radius;
00405         SFBool side;
00406         SFBool top;
00407     };
00408     typedef boost::intrusive_ptr<VrmlCylinder> VrmlCylinderPtr;
00409 
00410 
00412     class HRP_UTIL_EXPORT  VrmlSphere : public VrmlGeometry
00413     {
00414       public:
00415         VrmlSphere();
00416         SFFloat radius;
00417     };
00418     typedef boost::intrusive_ptr<VrmlSphere> VrmlSpherePtr;
00419 
00420 
00422     class HRP_UTIL_EXPORT  VrmlFontStyle : public VrmlNode
00423     {
00424       public:
00425         VrmlFontStyle();
00426 
00427         MFString family;       
00428         SFBool   horizontal;
00429         MFString justify;
00430         SFString language;
00431         SFBool   leftToRight;
00432         SFFloat  size;
00433         SFFloat  spacing;
00434         SFString style;
00435         SFBool   topToBottom;
00436     };
00437     typedef boost::intrusive_ptr<VrmlFontStyle> VrmlFontStylePtr;
00438 
00439 
00441     class HRP_UTIL_EXPORT  VrmlText : public VrmlGeometry
00442     {
00443       public:
00444         VrmlText();
00445 
00446         MFString fstring;
00447         VrmlFontStylePtr fontStyle;
00448         MFFloat length;
00449         SFFloat maxExtent;
00450     };
00451     typedef boost::intrusive_ptr<VrmlText> VrmlTextPtr;
00452 
00453 
00454     class VrmlColor;
00455     typedef boost::intrusive_ptr<VrmlColor> VrmlColorPtr;
00456 
00457     class VrmlCoordinate;
00458     typedef boost::intrusive_ptr<VrmlCoordinate> VrmlCoordinatePtr;
00459 
00461     class HRP_UTIL_EXPORT  VrmlIndexedLineSet : public VrmlGeometry
00462     {
00463       public: 
00464         VrmlIndexedLineSet();
00465 
00466         VrmlColorPtr color;
00467         VrmlCoordinatePtr coord;
00468         MFInt32 colorIndex;
00469         SFBool colorPerVertex;
00470         MFInt32 coordIndex;
00471     };
00472     typedef boost::intrusive_ptr<VrmlIndexedLineSet> VrmlIndexedLineSetPtr;
00473 
00474 
00475     class VrmlNormal;
00476     typedef boost::intrusive_ptr<VrmlNormal> VrmlNormalPtr;
00477 
00478     class VrmlTextureCoordinate;
00479     typedef boost::intrusive_ptr<VrmlTextureCoordinate> VrmlTextureCoordinatePtr;
00480 
00481 
00483     class HRP_UTIL_EXPORT  VrmlIndexedFaceSet : public VrmlIndexedLineSet
00484     {
00485       public:
00486         VrmlIndexedFaceSet();
00487 
00488         VrmlNormalPtr normal;
00489         VrmlTextureCoordinatePtr texCoord;
00490         SFBool ccw;
00491         SFBool convex;
00492         SFFloat creaseAngle;
00493         MFInt32 normalIndex;
00494         SFBool normalPerVertex;  
00495         SFBool solid;
00496         MFInt32 texCoordIndex;
00497     };
00498     typedef boost::intrusive_ptr<VrmlIndexedFaceSet> VrmlIndexedFaceSetPtr;
00499 
00500 
00502     class HRP_UTIL_EXPORT  VrmlColor : public VrmlNode
00503     {
00504       public:
00505         VrmlColor();
00506       
00507         MFColor color;
00508     };
00509 
00510 
00512     class HRP_UTIL_EXPORT  VrmlCoordinate : public VrmlNode
00513     {
00514       public:
00515         VrmlCoordinate();
00516         MFVec3f point;
00517     };
00518 
00519 
00521     class HRP_UTIL_EXPORT  VrmlTextureCoordinate : public VrmlNode
00522     {
00523       public:
00524         VrmlTextureCoordinate();
00525         MFVec2f point;
00526     };
00527 
00528 
00530     class HRP_UTIL_EXPORT  VrmlNormal : public VrmlNode
00531     {
00532       public:
00533         VrmlNormal();
00534         MFVec3f vector;
00535     };
00536 
00537 
00539     class HRP_UTIL_EXPORT  VrmlCylinderSensor : public VrmlNode
00540     {
00541       public:
00542         VrmlCylinderSensor();
00543 
00544         SFBool  autoOffset;
00545         SFFloat diskAngle;
00546         SFBool  enabled;
00547         SFFloat maxAngle;
00548         SFFloat minAngle;
00549         SFFloat offset;
00550     };
00551     typedef boost::intrusive_ptr<VrmlCylinderSensor> VrmlCylinderSensorPtr;
00552 
00553 
00554 
00555     // #####
00557     class HRP_UTIL_EXPORT  VrmlPointSet : public VrmlGeometry
00558     {
00559       public:
00560         VrmlPointSet();
00561 
00562         VrmlCoordinatePtr       coord;
00563         VrmlColorPtr            color;
00564     };
00565 
00566     typedef boost::intrusive_ptr<VrmlPointSet> VrmlPointSetPtr;
00567 
00568 
00569 
00570     // #####
00572     class HRP_UTIL_EXPORT  VrmlPixelTexture : public VrmlTexture
00573     {
00574       public:
00575         VrmlPixelTexture();
00576 
00577         SFImage                 image;
00578         SFBool                  repeatS;
00579         SFBool                  repeatT;
00580     };
00581 
00582     typedef boost::intrusive_ptr<VrmlPixelTexture> VrmlPixelTexturePtr;
00583 
00584 
00585 
00586     // #####
00588     class HRP_UTIL_EXPORT  VrmlMovieTexture : public VrmlTexture
00589     {
00590       public:
00591         VrmlMovieTexture();
00592 
00593         MFString                url;
00594         SFBool                  loop;
00595         SFFloat                 speed;
00596         SFTime                  startTime;
00597         SFTime                  stopTime;
00598         SFBool                  repeatS;
00599         SFBool                  repeatT;
00600     };
00601 
00602     typedef boost::intrusive_ptr<VrmlMovieTexture> VrmlMovieTexturePtr;
00603 
00604 
00605 
00606     // #####
00608     class HRP_UTIL_EXPORT  VrmlElevationGrid : public VrmlGeometry
00609     {
00610       public:
00611         VrmlElevationGrid();
00612 
00613         SFInt32                 xDimension;
00614         SFInt32                 zDimension;
00615         SFFloat                 xSpacing;
00616         SFFloat                 zSpacing;
00617         MFFloat                 height;
00618         SFBool                  ccw;
00619         SFBool                  colorPerVertex;
00620         SFFloat                 creaseAngle;
00621         SFBool                  normalPerVertex;
00622         SFBool                  solid;
00623         VrmlColorPtr    color;
00624         VrmlNormalPtr   normal;
00625         VrmlTextureCoordinatePtr        texCoord;
00626     };
00627 
00628     typedef boost::intrusive_ptr<VrmlElevationGrid> VrmlElevationGridPtr;
00629 
00630 
00631 
00632     // #####
00634     class HRP_UTIL_EXPORT  VrmlExtrusion : public VrmlGeometry
00635     {
00636       public:
00637         VrmlExtrusion();
00638 
00639         MFVec2f                 crossSection;
00640         MFVec3f                 spine;
00641         MFVec2f                 scale;
00642         MFRotation              orientation;
00643         SFBool                  beginCap;
00644         SFBool                  endCap;
00645         SFBool                  solid;
00646         SFBool                  ccw;
00647         SFBool                  convex;
00648         SFFloat                 creaseAngle;
00649     };
00650 
00651     typedef boost::intrusive_ptr<VrmlExtrusion> VrmlExtrusionPtr;
00652 
00653 
00654 
00655     class HRP_UTIL_EXPORT  VrmlSwitch : public AbstractVrmlGroup
00656     {
00657       public:
00658         VrmlSwitch();
00659 
00660         virtual MFNode& getChildren();
00661         virtual int countChildren();
00662         virtual VrmlNode* getChild(int index);
00663         virtual void replaceChild(int childIndex, VrmlNode* childNode);
00664 
00665         MFNode  choice;
00666         SFInt32 whichChoice;
00667     };
00668 
00669     typedef boost::intrusive_ptr<VrmlSwitch> VrmlSwitchPtr;
00670 
00671 
00672     class HRP_UTIL_EXPORT  VrmlLOD : public AbstractVrmlGroup
00673     {
00674       public:
00675         VrmlLOD();
00676 
00677         virtual MFNode& getChildren();
00678         virtual int countChildren();
00679         virtual VrmlNode* getChild(int index);
00680         virtual void replaceChild(int childIndex, VrmlNode* childNode);
00681 
00682         MFFloat range;
00683         SFVec3f center;
00684         MFNode  level;
00685     };
00686 
00687     typedef boost::intrusive_ptr<VrmlLOD> VrmlLODPtr;
00688 
00689 
00690     class HRP_UTIL_EXPORT VrmlCollision : public VrmlGroup
00691     {
00692       public:
00693         VrmlCollision();
00694         SFBool collide;
00695         SFNode proxy;
00696     };
00697 
00698     typedef boost::intrusive_ptr<VrmlCollision> VrmlCollisionPtr;
00699 
00700 
00701     class HRP_UTIL_EXPORT VrmlAnchor : public VrmlGroup
00702     {
00703       public:
00704         VrmlAnchor();
00705         SFString description;
00706         MFString parameter;
00707         MFString url;
00708     };
00709 
00710     typedef boost::intrusive_ptr<VrmlAnchor> VrmlAnchorPtr;
00711 
00712 
00713     class HRP_UTIL_EXPORT VrmlBillboard : public VrmlGroup
00714     {
00715       public:
00716         VrmlBillboard();
00717         SFVec3f axisOfRotation;
00718     };
00719 
00720     typedef boost::intrusive_ptr<VrmlBillboard> VrmlBillboardPtr;
00721 
00722 
00723     class HRP_UTIL_EXPORT VrmlFog : public VrmlNode
00724     {
00725       public:
00726         VrmlFog();
00727         SFColor  color;
00728         SFFloat  visibilityRange;
00729         SFString fogType;
00730     };
00731 
00732     typedef boost::intrusive_ptr<VrmlFog> VrmlFogPtr;
00733 
00734 
00735     class HRP_UTIL_EXPORT  VrmlWorldInfo : public VrmlNode
00736     {
00737       public:
00738         VrmlWorldInfo();
00739         SFString title;
00740         MFString info;
00741     };
00742 
00743     typedef boost::intrusive_ptr<VrmlWorldInfo> VrmlWorldInfoPtr;
00744 
00745 
00746     class HRP_UTIL_EXPORT VrmlPointLight : public VrmlNode
00747     {
00748       public:
00749         VrmlPointLight();
00750         SFVec3f location;
00751         SFBool  on;
00752         SFFloat intensity;
00753         SFColor color;
00754         SFFloat radius;
00755         SFFloat ambientIntensity;
00756         SFVec3f attenuation;
00757     };
00758 
00759     typedef boost::intrusive_ptr<VrmlPointLight> VrmlPointLightPtr;
00760 
00761 
00762     class HRP_UTIL_EXPORT VrmlDirectionalLight : public VrmlNode
00763     {
00764       public:
00765         VrmlDirectionalLight();
00766         SFFloat ambientIntensity;
00767         SFColor color;
00768         SFVec3f direction;
00769         SFFloat intensity;
00770         SFBool  on;
00771     };
00772 
00773     typedef boost::intrusive_ptr<VrmlDirectionalLight> VrmlDirectionalLightPtr;
00774 
00775 
00776     class HRP_UTIL_EXPORT  VrmlSpotLight : public VrmlNode
00777     {
00778       public:
00779         VrmlSpotLight();
00780         SFVec3f location;
00781         SFVec3f direction;
00782         SFBool  on;
00783         SFColor color;
00784         SFFloat intensity;
00785         SFFloat radius;
00786         SFFloat ambientIntensity;
00787         SFVec3f attenuation;
00788         SFFloat beamWidth;
00789         SFFloat cutOffAngle;
00790     };
00791 
00792     typedef boost::intrusive_ptr<VrmlSpotLight> VrmlSpotLightPtr;
00793 
00794 
00795 
00796     class HRP_UTIL_EXPORT  VrmlVariantField
00797     {
00798       private:
00799 
00800         union {
00801             SFInt32    sfInt32;
00802             SFFloat    sfFloat;
00803             SFVec2f    sfVec2f;
00804             SFVec3f    sfVec3f;
00805             SFRotation sfRotation;
00806             SFColor    sfColor;
00807             SFBool     sfBool;
00808             SFTime     sfTime;
00809 //              SFImage    sfImage;             // #####
00810         } v;
00811 
00812         void* valueObj; // multi-type field object
00813 
00814         VrmlFieldTypeId typeId_;
00815 
00816         void copy(const VrmlVariantField& org);
00817         void deleteObj();  
00818 
00819       public:
00820   
00821         VrmlVariantField();
00822         VrmlVariantField(VrmlFieldTypeId typeId);
00823         VrmlVariantField(const VrmlVariantField& org);
00824         VrmlVariantField& operator=(const VrmlVariantField& org);
00825 
00826         ~VrmlVariantField();
00827 
00828         inline VrmlFieldTypeId typeId() { return typeId_; }
00829         void setType(VrmlFieldTypeId typeId0);
00830 
00831         inline SFInt32&    sfInt32()    { return v.sfInt32; }
00832         inline MFInt32&    mfInt32()    { return *((MFInt32*)valueObj); }
00833         inline SFFloat&    sfFloat()    { return v.sfFloat; }
00834         inline MFFloat&    mfFloat()    { return *((MFFloat*)valueObj); }
00835         inline SFTime&     sfTime()     { return v.sfFloat; }
00836         inline MFTime&     mfTime()     { return *((MFTime*)valueObj); }
00837         inline SFBool&     sfBool()     { return v.sfBool; }
00838         inline SFVec2f&    sfVec2f()    { return v.sfVec2f; }
00839         inline MFVec2f&    mfVec2f()    { return *((MFVec2f*)valueObj); }
00840         inline SFVec3f&    sfVec3f()    { return v.sfVec3f; }
00841         inline MFVec3f&    mfVec3f()    { return *((MFVec3f*)valueObj); }
00842         inline SFRotation& sfRotation() { return v.sfRotation; }
00843         inline MFRotation& mfRotation() { return *((MFRotation*)valueObj); }
00844         inline SFString&   sfString()   { return *((SFString*)valueObj); }
00845         inline MFString&   mfString()   { return *((MFString*)valueObj); }
00846         inline SFColor&    sfColor()    { return v.sfColor; }
00847         inline MFColor&    mfColor()    { return *((MFColor*)valueObj); }
00848         inline SFNode&     sfNode()     { return *((SFNode*)valueObj); }
00849         inline MFNode&     mfNode()     { return *((MFNode*)valueObj); }
00850         inline SFImage&    sfImage()    { return *((SFImage*)valueObj); }       // #####
00851 
00852     };
00853 
00854     typedef std::map <std::string, VrmlVariantField> TProtoFieldMap;
00855     typedef std::pair<std::string, VrmlVariantField> TProtoFieldPair;
00856 
00857     
00859     class HRP_UTIL_EXPORT  VrmlProto : public VrmlNode
00860     {
00861       public:
00862         std::string protoName;
00863         TProtoFieldMap fields;
00864 
00865         VrmlProto(const std::string& n);
00866 
00867         inline VrmlVariantField* getField(const std::string& fieldName) {
00868             TProtoFieldMap::iterator p = fields.find(fieldName);
00869             return (p != fields.end()) ? &p->second : 0;
00870         }
00871 
00872         inline VrmlVariantField* addField(const std::string& fieldName, VrmlFieldTypeId typeId){
00873             VrmlVariantField* field = &(fields[fieldName]);
00874             field->setType(typeId);
00875             return field;
00876         }
00877 
00878     };
00879     typedef boost::intrusive_ptr<VrmlProto> VrmlProtoPtr;
00880 
00881 
00883     class HRP_UTIL_EXPORT VrmlProtoInstance : public VrmlNode
00884     {
00885       public:
00886         VrmlProtoPtr proto;
00887         TProtoFieldMap fields;
00888         VrmlNodePtr actualNode;
00889 
00890         VrmlProtoInstance(VrmlProtoPtr proto0);
00891 
00892         inline VrmlVariantField* getField(const std::string& fieldName) {
00893             TProtoFieldMap::iterator p = fields.find(fieldName);
00894             return (p != fields.end()) ? &p->second : 0;
00895         } 
00896                 
00897     };
00898     typedef boost::intrusive_ptr<VrmlProtoInstance> VrmlProtoInstancePtr;
00899 
00900 
00906     template<class VrmlNodeType>
00907     boost::intrusive_ptr<VrmlNodeType> dynamic_node_cast(VrmlNodePtr node) {
00908         VrmlProtoInstancePtr protoInstance = boost::dynamic_pointer_cast<VrmlProtoInstance>(node);
00909         if(protoInstance){
00910             return boost::dynamic_pointer_cast<VrmlNodeType>(protoInstance->actualNode);
00911         } else {
00912             return boost::dynamic_pointer_cast<VrmlNodeType>(node);
00913         }
00914     }
00915 
00916 };
00917 
00918 #endif


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:57