CMS 3D CMS Logo

IgSoPolyVol.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "Iguana/Inventor/interface/IgSoPolyVol.h"
00004 #include <Inventor/nodes/SoVertexProperty.h>
00005 #include <Inventor/nodes/SoShapeHints.h>
00006 #include <Inventor/nodes/SoIndexedFaceSet.h>
00007 #include <Inventor/nodes/SoTranslation.h>
00008 
00009 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00010 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00011 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00012 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00013 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00014 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00015 
00016 SO_KIT_SOURCE (IgSoPolyVol);
00017 
00018 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00019 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00020 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00021 
00022 void
00023 IgSoPolyVol::initClass (void)
00024 { SO_KIT_INIT_CLASS (IgSoPolyVol, IgSoShapeKit, "IgSoShapeKit"); }
00025 
00026 IgSoPolyVol::IgSoPolyVol (void)
00027 {
00028     SO_KIT_CONSTRUCTOR (IgSoPolyVol);
00029     SO_KIT_ADD_FIELD (vtxPts, (SbVec3f (0,0,0)));
00030     SO_KIT_ADD_FIELD (center, (SbVec3f (0,0,0)));
00031     SO_KIT_ADD_FIELD (dZ, (1.0));
00032     SO_KIT_ADD_CATALOG_ENTRY (hints, SoShapeHints, FALSE, separator,\x0, TRUE);
00033     SO_KIT_ADD_CATALOG_ENTRY (trans, SoTranslation, FALSE, separator,\x0, TRUE);
00034     SO_KIT_ADD_CATALOG_ENTRY (face, SoIndexedFaceSet, FALSE, separator,\x0, TRUE);
00035     SO_KIT_INIT_INSTANCE ();
00036     setUpConnections (true, true);
00037 
00038     const SbVec3f defPolyVol[10] = {
00039         SbVec3f (0.0,0.0,-0.5), SbVec3f (1.0,0.0,-0.5), SbVec3f (1.5,1.0,-0.5),
00040         SbVec3f (0.2,1.2,-0.5), SbVec3f (-0.2,1.0,-0.5),
00041         SbVec3f (0.0,0.0,0.5), SbVec3f (1.0,0.0,0.5), SbVec3f (1.5,1.0,0.5),
00042         SbVec3f (0.2,1.2,0.5), SbVec3f (-0.2,1.0,0.5)   
00043     };
00044     vtxPts.setValues (0,10,defPolyVol);
00045 }
00046 
00047 void
00048 IgSoPolyVol::refresh (void)
00049 {
00050     if (vtxPts.getNum () < 2) 
00051     {
00052         // set parts
00053         setPart ("hints", NULL);
00054         setPart ("trans", NULL);
00055         setPart ("face",  NULL);
00056 
00057         return;
00058     }
00059     
00060     SoTranslation       *trans = new SoTranslation;
00061     SoShapeHints        *hints = new SoShapeHints;
00062     SoVertexProperty    *vtx = new SoVertexProperty;
00063     SoIndexedFaceSet    *face = new SoIndexedFaceSet;
00064 
00065     hints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
00066     hints->faceType = SoShapeHints::UNKNOWN_FACE_TYPE;
00067     hints->shapeType = SoShapeHints::SOLID;
00068     hints->creaseAngle = 0;
00069 
00070     trans->translation = center;
00071 
00072     //  Create the face set
00073     vtx->vertex = vtxPts;
00074     face->vertexProperty = vtx;
00075 
00076     int nsides = vtxPts.getNum ()/2; // number of sides of front polygon
00077     face->coordIndex.setNum (7 * nsides + 2); //5*nsides for side polys+ 2* (nsides+1) for front and back
00078 
00079     int *indx = face->coordIndex.startEditing ();
00080     int i; 
00081 
00082     //  sides
00083     for (i = 0; i < nsides-1; i++)
00084     {
00085         *indx++ = i;
00086         *indx++ = i+1;
00087         *indx++ = i+nsides+1;
00088         *indx++ = i+nsides;
00089         *indx++ = SO_END_FACE_INDEX;
00090     } 
00091     *indx++ = i;  *indx++ = 0;  *indx++ = nsides; *indx++ = i+nsides;
00092     *indx++ = SO_END_FACE_INDEX;
00093 
00094     //  front & back faces; back face counts down
00095     for (i = nsides-1; i > -1; i--)
00096     {
00097         *indx = i;
00098         *((indx++) + nsides + 1) = 2*nsides-1-i; // bump past n vertices+end_face
00099     }
00100     *indx++ = SO_END_FACE_INDEX;
00101     *(indx+nsides) = SO_END_FACE_INDEX;
00102     face->coordIndex.finishEditing ();
00103 
00104     // set parts
00105     setPart ("hints", hints);
00106     setPart ("trans", trans);
00107     setPart ("face",  face);
00108 }
00109 
00111 void
00112 IgSoPolyVol::initialise (const int sides, const float dZHalf, 
00113                          const float *angles, const float *sideHalf)
00114 {
00115     assert (sides > 2);
00116 
00117     //  Stuff the points into the vtxPts
00118     vtxPts.setNum (2*sides);
00119 
00120     SbVec3f     *pt = vtxPts.startEditing ();
00121     float       x = 0;
00122     float       y = 0;
00123     float       z = 0;
00124 
00125     for (int i = 0; i < sides; i++, pt++)
00126     {
00127         *pt = SbVec3f (x,y,z-dZHalf);
00128         *(pt+sides) = SbVec3f (x,y,z+dZHalf);
00129         x += 2 * (*sideHalf) * cos (*angles);
00130         y += 2 * (*sideHalf++) * sin (*angles++);
00131     }
00132 
00133     vtxPts.finishEditing ();
00134 }

Generated on Tue Jun 9 17:38:47 2009 for CMSSW by  doxygen 1.5.4