CMS 3D CMS Logo

IgSoTower.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "Iguana/Inventor/interface/IgSoTower.h"
00004 #include "Inventor/nodes/SoCoordinate3.h"
00005 #include "Inventor/nodes/SoIndexedFaceSet.h"
00006 #include "Inventor/nodes/SoMaterialBinding.h"
00007 #include "Inventor/nodes/SoShapeHints.h"
00008 #include "Inventor/nodes/SoVertexProperty.h"
00009 #include "Inventor/SbColor.h"
00010 #include <vector>
00011 
00012 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00013 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00014 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00015 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00016 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00017 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00018 
00019 SO_KIT_SOURCE (IgSoTower);
00020 
00021 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00022 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00023 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00024 
00025 void
00026 IgSoTower::initClass (void)
00027 { SO_KIT_INIT_CLASS (IgSoTower, IgSoShapeKit, "IgSoShapeKit"); }
00028 
00029 IgSoTower::IgSoTower (void)
00030 {
00031     SO_KIT_CONSTRUCTOR (IgSoTower);
00032 
00033     SO_KIT_ADD_FIELD (position,         (0.0f,0.0f));
00034     SO_KIT_ADD_FIELD (energy,           (0.0f));
00035     SO_KIT_ADD_FIELD (emFraction,       (0.0f));
00036     SO_KIT_ADD_FIELD (scaleFactor,      (1.0f));
00037     SO_KIT_ADD_FIELD (minimumEnergy,    (0.0f));
00038     SO_KIT_ADD_FIELD (etaWidth,         (0.087f));
00039     SO_KIT_ADD_FIELD (phiWidth,         (0.087f));
00040     SO_KIT_ADD_FIELD (orderedRGBA,      (0));
00041 
00042     orderedRGBA.set1Value (0, SbColor (0.622, 0.0, 0.622).getPackedValue ());
00043     orderedRGBA.set1Value (1, orderedRGBA [0]);
00044     orderedRGBA.set1Value (2, orderedRGBA [0]);
00045     orderedRGBA.set1Value (3, orderedRGBA [0]);
00046     orderedRGBA.set1Value (4, orderedRGBA [0]);
00047     orderedRGBA.set1Value (5, orderedRGBA [0]);
00048     orderedRGBA.set1Value (6, SbColor (0.0, 0.0, 1.0).getPackedValue ());
00049     orderedRGBA.set1Value (7, orderedRGBA [6]);
00050     orderedRGBA.set1Value (8, orderedRGBA [6]);
00051     orderedRGBA.set1Value (9, orderedRGBA [6]);
00052     orderedRGBA.set1Value (10, orderedRGBA [6]);
00053     orderedRGBA.set1Value (11, orderedRGBA [6]);
00054    
00055     SO_KIT_ADD_CATALOG_ENTRY (shapeHints, SoShapeHints, FALSE, separator,\x0, TRUE);
00056     SO_KIT_ADD_CATALOG_ENTRY (faces, SoIndexedFaceSet, FALSE, separator,\x0, TRUE);
00057     SO_KIT_INIT_INSTANCE ();
00058     setUpConnections (true, true);
00059 }
00060 
00061 void
00062 IgSoTower::cleanParts (void)
00063 {
00064     setPart ("shapeHints", NULL);
00065     setPart ("faces", NULL);
00066 }
00067 
00068 void
00069 IgSoTower::refresh (void)
00070 {
00071     if ((energy.getValue () == 0.0) || (fabs (energy.getValue ()) < fabs (minimumEnergy.getValue ())))
00072     {
00073         cleanParts ();
00074         return;
00075     }
00076 
00077     SoShapeHints *shapeHints = new SoShapeHints;
00078     SoIndexedFaceSet *faces = new SoIndexedFaceSet;
00079     SoVertexProperty *vtx = new SoVertexProperty;
00080  
00081     int faceIndices [] = 
00082         {0, 1, 5, 4, SO_END_FACE_INDEX,
00083          3, 7, 6, 2, SO_END_FACE_INDEX,
00084          1, 2, 6, 5, SO_END_FACE_INDEX,
00085          5, 6, 7, 4, SO_END_FACE_INDEX,
00086          4, 7, 3, 0, SO_END_FACE_INDEX,
00087          0, 3, 2, 1, SO_END_FACE_INDEX,
00088 
00089          8,  9, 13, 12, SO_END_FACE_INDEX,
00090         11, 15, 14, 10, SO_END_FACE_INDEX,
00091          9, 10, 14, 13, SO_END_FACE_INDEX,
00092         13, 14, 15, 12, SO_END_FACE_INDEX,
00093         12, 15, 11,  8, SO_END_FACE_INDEX,
00094          8, 11, 10,  9, SO_END_FACE_INDEX
00095         };
00096     
00097     float       cx, cz;
00098     float       dx = etaWidth.getValue () / 2.0F;
00099     float       dz = phiWidth.getValue () / 2.0F;
00100     float       cMax = energy.getValue () / scaleFactor.getValue ();
00101     float       cMin = cMax * emFraction.getValue ();
00102     bool        noEm;
00103     bool        noHm;
00104     bool        top = false;
00105     bool        bottom = false;
00106     
00107     (emFraction.getValue () == 0.0) ? noEm = true : noEm = false;
00108     (emFraction.getValue () == 1.0) ? noHm = true : noHm = false;
00109     
00110     position.getValue ().getValue (cx, cz);
00111 
00112     if (cMax < 0.0)
00113     {
00114         shapeHints->vertexOrdering = SoShapeHints::CLOCKWISE;
00115 
00116         orderedRGBA.set1Value (0, orderedRGBA [0] xor 0xffffff00);
00117         orderedRGBA.set1Value (1, orderedRGBA [0]);
00118         orderedRGBA.set1Value (2, orderedRGBA [0]);
00119         orderedRGBA.set1Value (3, orderedRGBA [0]);
00120         orderedRGBA.set1Value (4, orderedRGBA [0]);
00121         orderedRGBA.set1Value (5, orderedRGBA [0]);
00122         orderedRGBA.set1Value (6, orderedRGBA [6] xor 0xffffff00);
00123         orderedRGBA.set1Value (7, orderedRGBA [6]);
00124         orderedRGBA.set1Value (8, orderedRGBA [6]);
00125         orderedRGBA.set1Value (9, orderedRGBA [6]);
00126         orderedRGBA.set1Value (10, orderedRGBA [6]);
00127         orderedRGBA.set1Value (11, orderedRGBA [6]);
00128     }
00129     else
00130     {
00131         shapeHints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
00132     }
00133     
00134     shapeHints->shapeType = SoShapeHints::SOLID;
00135     shapeHints->faceType = SoShapeHints::CONVEX;
00136     
00137     int nverts = 16;
00138     std::vector<SbVec3f> vertexData (nverts);
00139 
00140     if (! noEm) 
00141     {           
00142         vertexData [0][0] = cx - dx;
00143         vertexData [0][1] = cMin;
00144         vertexData [0][2] = cz - dz;
00145     
00146         vertexData [1][0] = cx + dx;
00147         vertexData [1][1] = cMin;
00148         vertexData [1][2] = cz - dz;
00149 
00150         vertexData [2][0] = cx + dx;
00151         vertexData [2][1] = cMin;
00152         vertexData [2][2] = cz + dz;
00153     
00154         vertexData [3][0] = cx - dx;
00155         vertexData [3][1] = cMin;
00156         vertexData [3][2] = cz + dz;
00157 
00158         vertexData [4][0] = cx - dx;
00159         vertexData [4][1] = 0;
00160         vertexData [4][2] = cz - dz;
00161 
00162         vertexData [5][0] = cx + dx;
00163         vertexData [5][1] = 0;
00164         vertexData [5][2] = cz - dz;
00165 
00166         vertexData [6][0] = cx + dx;
00167         vertexData [6][1] = 0;
00168         vertexData [6][2] = cz + dz;
00169 
00170         vertexData [7][0] = cx - dx;
00171         vertexData [7][1] = 0;
00172         vertexData [7][2] = cz + dz;
00173   
00174         bottom = true;
00175     } 
00176     
00177     if (! noHm) 
00178     {
00179         vertexData [8][0] = cx - dx;
00180         vertexData [8][1] = cMax;
00181         vertexData [8][2] = cz - dz;
00182     
00183         vertexData [9][0] = cx + dx;
00184         vertexData [9][1] = cMax;
00185         vertexData [9][2] = cz - dz;
00186 
00187         vertexData [10][0] = cx + dx;
00188         vertexData [10][1] = cMax;
00189         vertexData [10][2] = cz + dz;
00190     
00191         vertexData [11][0] = cx - dx;
00192         vertexData [11][1] = cMax;
00193         vertexData [11][2] = cz + dz;
00194 
00195         vertexData [12][0] = cx - dx;
00196         vertexData [12][1] = cMin;
00197         vertexData [12][2] = cz - dz;
00198 
00199         vertexData [13][0] = cx + dx;
00200         vertexData [13][1] = cMin;
00201         vertexData [13][2] = cz - dz;
00202 
00203         vertexData [14][0] = cx + dx;
00204         vertexData [14][1] = cMin;
00205         vertexData [14][2] = cz + dz;
00206 
00207         vertexData [15][0] = cx - dx;
00208         vertexData [15][1] = cMin;
00209         vertexData [15][2] = cz + dz;
00210         
00211         top = true;
00212     }
00213     
00214     vtx->materialBinding = SoMaterialBinding::PER_FACE;
00215 
00216     if (top && bottom)
00217     {
00218         vtx->vertex.setValues (0, 16, &vertexData [0]);
00219         vtx->orderedRGBA = orderedRGBA;
00220 
00221         faces->vertexProperty = vtx;
00222         faces->coordIndex.setValues (0, sizeof (faceIndices) / sizeof (int), faceIndices);
00223         setPart ("shapeHints",  shapeHints);
00224         setPart ("faces",       faces);
00225     }
00226     else if (top && (! bottom))
00227     {
00228         orderedRGBA.set1Value (0, orderedRGBA [6]);
00229         orderedRGBA.set1Value (1, orderedRGBA [6]);
00230         orderedRGBA.set1Value (2, orderedRGBA [6]);
00231         orderedRGBA.set1Value (3, orderedRGBA [6]);
00232         orderedRGBA.set1Value (4, orderedRGBA [6]);
00233         orderedRGBA.set1Value (5, orderedRGBA [6]);
00234         vtx->orderedRGBA = orderedRGBA;
00235         
00236         vtx->vertex.setValues (0, 8, &vertexData [8]);
00237         faces->vertexProperty = vtx;
00238         faces->coordIndex.setValues (0, 6 * 5, faceIndices);
00239         setPart ("shapeHints",  shapeHints);
00240         setPart ("faces",       faces);
00241     }
00242     else if ((! top) && bottom)
00243     {
00244         orderedRGBA.set1Value (6, orderedRGBA [0]);
00245         orderedRGBA.set1Value (7, orderedRGBA [0]);
00246         orderedRGBA.set1Value (8, orderedRGBA [0]);
00247         orderedRGBA.set1Value (9, orderedRGBA [0]);
00248         orderedRGBA.set1Value (10, orderedRGBA [0]);
00249         orderedRGBA.set1Value (11, orderedRGBA [0]);
00250         vtx->orderedRGBA = orderedRGBA;
00251 
00252         vtx->vertex.setValues (0, 8, &vertexData [0]);
00253         faces->vertexProperty = vtx;
00254         faces->coordIndex.setValues (0, 6 * 5, faceIndices);
00255         setPart ("shapeHints",  shapeHints);
00256         setPart ("faces",       faces);
00257     }
00258     else 
00259     {
00260         vtx->orderedRGBA = orderedRGBA;
00261         faces->vertexProperty = vtx;
00262         shapeHints->ref(); shapeHints->unref();
00263         faces->ref(); faces->unref();
00264         setPart ("shapeHints",  NULL);
00265         setPart ("faces",       NULL);
00266     }
00267 }

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