CMS 3D CMS Logo

IgSoJet.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "Iguana/Inventor/interface/IgSoJet.h"
00004 #include <Inventor/nodes/SoSeparator.h>
00005 #include <Inventor/nodes/SoCone.h>
00006 #include <Inventor/nodes/SoTransform.h>
00007 
00008 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00009 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00010 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00011 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00012 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00013 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00014 
00015 SO_KIT_SOURCE (IgSoJet);
00016 
00017 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00018 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00019 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00020 
00021 void
00022 IgSoJet::initClass (void)
00023 { SO_KIT_INIT_CLASS (IgSoJet, IgSoShapeKit, "IgSoShapeKit"); }
00024 
00025 IgSoJet::IgSoJet (void)
00026 {
00027     SO_KIT_CONSTRUCTOR (IgSoJet);
00028     SO_KIT_ADD_FIELD (energy,    (0.0));
00029     SO_KIT_ADD_FIELD (theta,     (0.0));
00030     SO_KIT_ADD_FIELD (phi,       (0.0));
00031     SO_KIT_ADD_FIELD (thrust,    (1.0));
00032     SO_KIT_ADD_FIELD (maxZ,      (4.0)) ;               // set these to something more sensible ...
00033     SO_KIT_ADD_FIELD (maxR,      (2.0)) ;
00034     SO_KIT_ADD_FIELD (maxEnergy, (100.0)) ;
00035     SO_KIT_ADD_CATALOG_ENTRY (body,      SoSeparator, FALSE, separator,\x0, TRUE);
00036     SO_KIT_ADD_CATALOG_ENTRY (bodyTrans, SoTransform, FALSE, body,\x0, TRUE);
00037     SO_KIT_ADD_CATALOG_ENTRY (bodyCone,  SoCone,      FALSE, body,\x0, TRUE);
00038     SO_KIT_ADD_CATALOG_ENTRY (hat,       SoSeparator, FALSE, separator,\x0, TRUE);
00039     SO_KIT_ADD_CATALOG_ENTRY (hatTrans,  SoTransform, FALSE, hat,\x0, TRUE);
00040     SO_KIT_ADD_CATALOG_ENTRY (hatCone,   SoCone,      FALSE, hat,\x0, TRUE);
00041     SO_KIT_INIT_INSTANCE ();
00042     setUpConnections (true, true);
00043 }
00044 
00045 void
00046 IgSoJet::refresh (void)
00047 {
00048     SoTransform *bodyTrans = new SoTransform;
00049     SoCone      *bodyCone = new SoCone;
00050     SoTransform *hatTrans = new SoTransform;
00051     SoCone      *hatCone = new SoCone;
00052 
00053     // private data members
00054     float       theta = this->theta.getValue ();
00055     float       phi = this->phi.getValue ();
00056     double      ct = cos (theta);
00057     double      st = sin (theta);
00058     double      cp = cos (phi);
00059     double      sp = sin (phi);
00060 
00061     // Define cone rotations and translations; rotVec is the normal of
00062     // the thrust-y plane and alpha the angle between the y and thrust
00063     // axes.
00064     SbVec3f     rotVec (ct, 0.0, -st * cp);
00065     float       alpha = acos (st * sp);
00066 
00067     // The body cone of the jet (FIXME: Set radius to something
00068     // meaningful; first attempt to make bodyRadius somehow related to
00069     // thrust.)  Move cone on its head (M_PI rotation) and vertex at
00070     // the origin
00071     float       length1 = ct ? maxZ.getValue () / fabs (ct) : maxZ.getValue ();
00072     float       length2 = st ? maxR.getValue () / fabs (st) : maxR.getValue ();
00073     float       bodyHeight = length1 < length2 ? length1 : length2;
00074     float       bodyRadius = 0.3 * (1.0 / (thrust.getValue () + 0.001));
00075 
00076     bodyCone->bottomRadius = bodyRadius;
00077     bodyCone->height = bodyHeight;
00078     bodyTrans->rotation.setValue (rotVec, alpha + M_PI);
00079     bodyTrans->translation = SbVec3f (bodyHeight * st * cp / 2.0,
00080                                       bodyHeight * st * sp / 2.0,
00081                                       bodyHeight * ct / 2.0);
00082 
00083     // The pointy "hat" on top of the jet.  (FIXME: Set height to
00084     // something meaningful; first attempt to relate hat height to
00085     // energy.  For now, hat height varies from 0 up to maxR,
00086     // depending on what max energy is set to.)
00087     float       hatRadius = 1.4 * bodyRadius;
00088     float       hatHeight = maxR.getValue () * energy.getValue ()
00089                             / maxEnergy.getValue ();
00090 
00091     hatCone->bottomRadius = hatRadius;
00092     hatCone->height = hatHeight;
00093     hatTrans->rotation.setValue (rotVec, alpha);
00094     hatTrans->translation = SbVec3f ((bodyHeight + hatHeight / 2.0) * st * cp,
00095                                      (bodyHeight + hatHeight / 2.0) * st * sp,
00096                                      (bodyHeight + hatHeight / 2.0) * ct);
00097 
00098     setPart ("bodyTrans", bodyTrans);
00099     setPart ("bodyCone",  bodyCone);
00100     setPart ("hatTrans",  hatTrans);
00101     setPart ("hatCone",   hatCone);
00102 }

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