CMS 3D CMS Logo

IgSoCalHit Class Reference

Represents an energy deposition by an extruded shape proportional to the energy. This is a cheap copy of IgSoCrystalHits. All parts are currently drawn despite the settings of the flags. More...

#include <Iguana/Inventor/interface/IgSoCalHit.h>

Inheritance diagram for IgSoCalHit:

IgSoShapeKit

List of all members.

Public Member Functions

 IgSoCalHit (void)

Static Public Member Functions

static void initClass (void)

Public Attributes

SoSFBool drawHit
SoSFBool drawShape
SoSFFloat emFraction
SoSFFloat energy
SoSFFloat minimumEnergy
SoMFUInt32 orderedRGBA
SoSFFloat relativeWidth
SoSFFloat scaleFactor
SoSFBool twoColor
SoMFVec3f vertices

Protected Member Functions

virtual void refresh (void)

Private Member Functions

 SO_KIT_CATALOG_ENTRY_HEADER (faces)
 SO_KIT_HEADER (IgSoCalHit)


Detailed Description

Represents an energy deposition by an extruded shape proportional to the energy. This is a cheap copy of IgSoCrystalHits. All parts are currently drawn despite the settings of the flags.

At present, all the flags must be initialised first,and then the vertices must be supplied.

The different colors for EM/Had are accessible as follows:

std::vector<SbVec3f> pts(8); pts [0] = SbVec3f (0, 0, 0); pts [4] = SbVec3f (0, 0, 1); pts [1] = SbVec3f (1, 0, 0); pts [5] = SbVec3f (1, 0, 1); pts [2] = SbVec3f (1, 1, 0); pts [6] = SbVec3f (1, 1, 1); pts [3] = SbVec3f (0, 1, 0); pts [7] = SbVec3f (0, 1, 1);

IgSoCalHit *obj = new IgSoCalHit; obj->energy = 10; obj->vertices.setValues (0, 8, &pts[0]); obj->orderedRGBA.set1Value (0, SbColor (0.5,0.5,0.5).getPackedValue ()); obj->orderedRGBA.set1Value (1, SbColor (0.5,1.0,0.5).getPackedValue ()); obj->orderedRGBA.set1Value (2, SbColor (0.5,0.5,1.0).getPackedValue ()); obj->minimumEnergy = 0.2; obj->drawShape = false;

Author:
G. Alverson, Northeastern University/CMS Software
Date:
20 June 2002

Definition at line 51 of file IgSoCalHit.h.


Constructor & Destructor Documentation

IgSoCalHit::IgSoCalHit ( void   ) 

Definition at line 27 of file IgSoCalHit.cc.

References drawHit, drawShape, emFraction, energy, f, FALSE, minimumEnergy, orderedRGBA, relativeWidth, scaleFactor, IgSoShapeKit::setUpConnections(), TRUE, twoColor, and vertices.

00028 {
00029     SO_KIT_CONSTRUCTOR (IgSoCalHit);
00030 
00031     SO_KIT_ADD_FIELD (vertices,         (0, 0, 0));
00032     SO_KIT_ADD_FIELD (energy,           (0.1f));
00033     SO_KIT_ADD_FIELD (emFraction,       (0.5f));
00034     SO_KIT_ADD_FIELD (scaleFactor,      (1.0f));
00035     SO_KIT_ADD_FIELD (minimumEnergy,    (0.001f));
00036     SO_KIT_ADD_FIELD (relativeWidth,    (.85f));
00037     SO_KIT_ADD_FIELD (drawShape,        (TRUE));
00038     SO_KIT_ADD_FIELD (drawHit,          (TRUE));
00039     SO_KIT_ADD_FIELD (twoColor,         (TRUE));
00040     SO_KIT_ADD_FIELD (orderedRGBA,      (0));
00041 
00042     orderedRGBA.set1Value (0, SbColor (0.5,0.5,0.5).getPackedValue ());
00043     orderedRGBA.set1Value (1, SbColor (0.5,1.0,0.5).getPackedValue ());
00044     orderedRGBA.set1Value (2, SbColor (0.5,0.5,1.0).getPackedValue ());
00045 
00046     SO_KIT_ADD_CATALOG_ENTRY (faces, SoIndexedFaceSet, FALSE, separator,\x0, TRUE);
00047     SO_KIT_INIT_INSTANCE ();
00048     setUpConnections (true, true);
00049 }


Member Function Documentation

void IgSoCalHit::initClass ( void   )  [static]

Reimplemented from IgSoShapeKit.

Definition at line 24 of file IgSoCalHit.cc.

Referenced by initNodes(), and initShapes().

00025 { SO_KIT_INIT_CLASS (IgSoCalHit, IgSoShapeKit, "IgSoShapeKit"); }

void IgSoCalHit::refresh ( void   )  [protected, virtual]

Reimplemented from IgSoShapeKit.

Definition at line 52 of file IgSoCalHit.cc.

References edmNew::copy(), drawHit, drawShape, emFraction, energy, edm::pset::fill(), i, j, k, orderedRGBA, relativeWidth, scaleFactor, twoColor, and vertices.

00053 {
00054     /*    Vertex layout  
00055      *       |             |            |        |         |         |             
00056      *       |     np      |  np        |    np  |    np   |    np   |   : total 5*np vertices
00057      *       |             |            |        |         |         |             
00058      *            bottom     shape top    xition    EM top   had top               
00059      *
00060      *   co-ordinate index layout (np = nper) 
00061      *       |             |             |        |        |        |       | 
00062      *       | (np + 1)    | (np + 1)    |  5*np  |  5*np  |  5*np  |  5*np |   : total 22*np+2 coord entries
00063      *       |             |             |        |        |        |       | 
00064      *            bottom        top        shape    xition    EM       had
00065      *     
00066      *   face layout
00067      *       |             |             |        |        |        |       |
00068      *       |    bottom   |    top      |  np    |  np    |   np   |   np  |  : total 4*np+2  
00069      *            bottom        top        shape    xition    EM       had
00070      */
00071 
00072     if (vertices.getNum () % 2)
00073         return;
00074 
00075     SoIndexedFaceSet    *faces = new SoIndexedFaceSet;
00076     SoVertexProperty    *vp = new SoVertexProperty;
00077     int                 nper = vertices.getNum () / 2;
00078     int                 nfaces = 2 + 3*nper; // top & bottom + two extruded sections
00079     int                 nverts = 4*nper; // as above
00080 
00081     if (twoColor.getValue ())
00082     {
00083         nfaces += nper; // get extra extruded section
00084         nverts += nper;  
00085     }
00086 
00087     // follow IgSoCrystalHit... assumes symmetry & even number of sides
00088     std::vector<SbVec3f>        tmpv (2*nper);
00089     std::vector<SbVec3f>        verts (nverts);
00090     const float                 eps = 0.0001F; // offset between hit & shape
00091 
00092     std::copy (vertices.getValues (0),
00093                vertices.getValues (0) + vertices.getNum (),
00094                &verts[0]);
00095 
00096     // generate a scaled shape
00097     for (int i = 0; i < 2*nper; i += nper)
00098         for (int j = 0, k = i; j < nper; j++, k++)
00099             tmpv[k] = verts[k] * (1 + relativeWidth.getValue ())/2
00100                       + verts[i + (k+nper/2)%nper] * (1 - relativeWidth.getValue ())/2;
00101 
00102     // front (bottom) face of hit
00103     for (int i = 0; i < nper; i++)
00104         verts[2*nper+i] = tmpv[nper+i] + (tmpv[nper+i]-tmpv[i])*eps;
00105 
00106     // mid face of hit
00107     int backPt = 3 * nper;
00108     if (twoColor.getValue ())
00109     {
00110         backPt = 4 * nper;
00111         for (int i = 0; i < nper; i++)
00112             verts[3*nper+i] = verts[2*nper+i]
00113                               + ((tmpv[nper+i]-tmpv[i])
00114                                  * scaleFactor.getValue ()
00115                                  * energy.getValue ()
00116                                  * emFraction.getValue ());
00117     }
00118 
00119     // back (top) face of hit
00120     for (int i = 0; i < nper; i++)
00121         verts [backPt+i] = verts[2*nper+i]
00122                            + ((tmpv[nper+i]-tmpv[i])
00123                               * scaleFactor.getValue ()
00124                               * energy.getValue ());
00125 
00126     // generate required items for each face
00127     int                 numIndices = 5*(nfaces-2) + 2*(nper+1); // all but top/bottom faces have 4 vertexes plus stop
00128     std::vector<int>    indices (numIndices); // indices for vertices/face
00129     std::vector<int>    mindices (nfaces,1); // indices for material/face
00130     std::vector<int>    nindices (nfaces); // indices for the normals
00131     std::vector<SbVec3f> normals (nfaces); // inormals/face
00132 
00133     // bottom (for outward normal, walk backwards)
00134     for (int i = 0; i < nper; i++)
00135         indices[nper - 1 -i] = i;
00136     indices[nper] = SO_END_FACE_INDEX;
00137     mindices[0] = 0;
00138 
00139     // top
00140     for (int i = 0; i < nper; i++)
00141         indices[nper + 1 + i] = nverts - nper + i;
00142     indices[2*nper+1] = SO_END_FACE_INDEX;
00143 
00144     // all others
00145     int ip = 2*nper+2;
00146     int iv = 0;
00147     int iface = 2; 
00148     while (iv < nverts - nper)
00149     {
00150         for (int i = 0; i < nper -1; i++)
00151         {
00152             indices[ip++] = iv;
00153             indices[ip++] = iv + 1;
00154             indices[ip++] = iv + 1 + nper;
00155             indices[ip++] = iv + nper;
00156             indices[ip++] = SO_END_FACE_INDEX;  
00157             normals[iface++] = (verts[iv+1] - verts[iv])
00158                                .cross (verts[iv+nper]-verts[iv]);
00159             iv++;
00160         }
00161         // last face wraps vertices back to start
00162         indices[ip++] = iv;
00163         indices[ip++] = iv + 1 - nper;
00164         indices[ip++] = iv + 1;
00165         indices[ip++] = iv + nper;
00166         indices[ip++] = SO_END_FACE_INDEX;
00167         normals[iface++] = (verts[iv+1-nper] - verts[iv])
00168                            .cross (verts[iv+nper]-verts[iv]);
00169         iv++;
00170     }
00171     normals[0] = (verts[nper-1] - verts[0])
00172                  .cross (verts[1]-verts[0]); // reverse the order
00173     normals[1] = (verts[nverts - nper + 1] - verts[nverts - nper])
00174                  .cross (verts[nverts-1]-verts[nverts - nper]);
00175 
00176     for (int i = 2; i < 2*nper+2; i++)
00177         mindices[i] = 0;
00178 
00179     if (twoColor.getValue ())
00180     {
00181         mindices[1] = 2; 
00182         std::fill (mindices.begin ()+3*nper+2,mindices.end (),2);
00183     }
00184 
00185     for (int i = 0; i < nfaces; i++)
00186         nindices[i] = i;
00187 
00188     // adjust for options
00189     if (! drawHit.getValue ())
00190     {
00191         // readjust down to just the cal cell
00192         nverts = 2*nper;
00193         nfaces = 2+nper;
00194         numIndices = 5* (nfaces-2) + 2* (nper+1); // all but top/bottom faces have 4 vertexes plus stop
00195         verts.resize (nverts);
00196         for (int i = 0; i < nper; i++)
00197             indices[nper + 1 + i] = nverts - nper + i;
00198         indices[2*nper+1] = SO_END_FACE_INDEX;
00199         normals[1] = (verts[nverts - nper + 1] - verts[nverts - nper])
00200                      .cross (verts[nverts-1]-verts[nverts - nper]);
00201         mindices[1] = 0;
00202     }
00203 
00204     int findexStart = 0;
00205     int indexStart = 0;
00206     if (!drawShape.getValue ())
00207     {
00208         // cut off/transfer first section
00209         std::copy (indices.begin ()+ (nper+1),
00210                    indices.begin ()+2* (nper+1),
00211                    indices.begin ()+11*nper+1); // back face
00212 
00213         // front (bottom) face
00214         for (int i = 2*nper; i < 3*nper; i++)
00215             indices[13*nper -i -1] = i;
00216 
00217         indices[11*nper] = SO_END_FACE_INDEX;
00218         mindices[2*nper] = 1;
00219         mindices[2*nper+1] = 2;
00220         normals[2*nper+1] = normals[1];
00221         normals[2*nper] = (verts[3*nper-1] - verts[2*nper])
00222                           .cross (verts[2*nper+1]-verts[2*nper]); // reverse the order
00223         findexStart = 2*nper;
00224         indexStart = 10*nper;
00225         nfaces -= 2*nper;
00226         numIndices -= 10*nper;
00227     }
00228     else if (energy.getValue () <= 0)
00229     {
00230         // remove the extrusion
00231         //   over-write the top hit face with the original shape top face
00232         for (int i = 0; i < nper; i++)
00233             indices[nper + 1 + i] = nper + i;
00234 
00235         mindices[1] = 0;
00236         normals[1] = (verts[nper + 1] - verts[nper])
00237                      .cross (verts[2*nper-1]-verts[nper]);
00238         nfaces = nper+2;
00239         numIndices = 7 * nper +2;
00240     }
00241 
00242     vp->materialBinding = SoMaterialBinding::PER_FACE_INDEXED;
00243     vp->normalBinding = SoMaterialBinding::PER_FACE_INDEXED;
00244     vp->orderedRGBA = orderedRGBA;
00245     vp->vertex.setValues (0,verts.size (),&verts[0]);
00246     vp->normal.setValues (0,nfaces,&normals[findexStart]);
00247     faces->coordIndex.setValues (0,numIndices,&indices[indexStart]);
00248     faces->materialIndex.setValues (0,nfaces,&mindices[findexStart]);
00249     faces->normalIndex.setValues (0,nfaces,&nindices[0]);
00250     faces->vertexProperty = vp;
00251 
00252     setPart ("faces", faces);
00253 }

IgSoCalHit::SO_KIT_CATALOG_ENTRY_HEADER ( faces   )  [private]

IgSoCalHit::SO_KIT_HEADER ( IgSoCalHit   )  [private]


Member Data Documentation

SoSFBool IgSoCalHit::drawHit

Definition at line 67 of file IgSoCalHit.h.

Referenced by IgSoCalHit(), and refresh().

SoSFBool IgSoCalHit::drawShape

Definition at line 66 of file IgSoCalHit.h.

Referenced by IgSoCalHit(), refresh(), and VisCaloTowerTwig::update().

SoSFFloat IgSoCalHit::emFraction

Definition at line 62 of file IgSoCalHit.h.

Referenced by IgSoCalHit(), refresh(), and VisCaloTowerTwig::update().

SoSFFloat IgSoCalHit::energy

Definition at line 61 of file IgSoCalHit.h.

Referenced by IgSoCalHit(), refresh(), and VisCaloTowerTwig::update().

SoSFFloat IgSoCalHit::minimumEnergy

Definition at line 64 of file IgSoCalHit.h.

Referenced by IgSoCalHit().

SoMFUInt32 IgSoCalHit::orderedRGBA

Definition at line 69 of file IgSoCalHit.h.

Referenced by IgSoCalHit(), refresh(), and VisCaloTowerTwig::update().

SoSFFloat IgSoCalHit::relativeWidth

Definition at line 65 of file IgSoCalHit.h.

Referenced by IgSoCalHit(), and refresh().

SoSFFloat IgSoCalHit::scaleFactor

Definition at line 63 of file IgSoCalHit.h.

Referenced by IgSoCalHit(), refresh(), and VisCaloTowerTwig::update().

SoSFBool IgSoCalHit::twoColor

Definition at line 68 of file IgSoCalHit.h.

Referenced by IgSoCalHit(), and refresh().

SoMFVec3f IgSoCalHit::vertices

Definition at line 60 of file IgSoCalHit.h.

Referenced by IgSoCalHit(), refresh(), and VisCaloTowerTwig::update().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:25:40 2009 for CMSSW by  doxygen 1.5.4