CMS 3D CMS Logo

IgSoSlicer.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "Iguana/Inventor/interface/IgSoSlicer.h"
00004 #include "Iguana/Inventor/interface/IgSoSlicerEngine.h"
00005 #include "Iguana/Inventor/interface/IgSoClipPlane.h"
00006 #include "Iguana/Inventor/interface/IgSoPlaneManip.h"
00007 #include <Inventor/sensors/SoFieldSensor.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_NODE_SOURCE (IgSoSlicer);
00017 
00018 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00019 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00020 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00021 
00022 void
00023 IgSoSlicer::initClass (void)
00024 {
00025     SO_NODE_INIT_CLASS (IgSoSlicer, SoNode, "Node");
00026 }
00027 
00028 IgSoSlicer::IgSoSlicer (void)
00029     : m_front        (new IgSoClipPlane),
00030       m_back         (new IgSoClipPlane),
00031       m_manipPlane   (new IgSoPlaneManip),
00032       m_engine       (new IgSoSlicerEngine),
00033       m_planeSensor  (0),
00034       m_mplaneSensor (0)
00035 {
00036     // Construct two clip planes, front, back and a Plane manipulator
00037 
00038     SO_NODE_CONSTRUCTOR (IgSoSlicer);
00039     SO_NODE_ADD_FIELD (on, (TRUE));
00040     SO_NODE_ADD_FIELD (manip, (FALSE));
00041     SO_NODE_ADD_FIELD (thickness, (.5f));
00042     SO_NODE_ADD_FIELD (plane, (SbPlane (SbVec3f (0, 0, -1), 0)));
00043 
00044     //add clip planes
00045     m_manipPlane->ref ();
00046     m_front->ref ();
00047     m_back->ref ();
00048     addChild (m_manipPlane);
00049     addChild (m_front);
00050     addChild (m_back);
00051 
00052     //set the manipplane same as the plane
00053     m_manipPlane->plane = plane;
00054     
00055     //connect "on" field to the front and back clip plane's 
00056     m_front->on.connectFrom (&on);
00057     m_back->on.connectFrom (&on);
00058     
00059     //connect engine's outputs to the front and back 
00060     //clip plane's "plane" feild
00061     m_front->plane.connectFrom (&m_engine->frontPlane);
00062     m_back->plane.connectFrom (&m_engine->backPlane);
00063 
00064     //connect the engine's inputs
00065     m_engine->thickness.connectFrom (&thickness);
00066     m_engine->plane.connectFrom (&plane);
00067     m_engine->ref();
00068 
00069     m_manipPlane->manip.connectFrom (&manip);
00070         
00071     m_planeSensor = new SoFieldSensor (&planeSensorCB, this);
00072     m_planeSensor->attach (&plane);
00073     
00074     m_mplaneSensor = new SoFieldSensor (&mplaneSensorCB, this);
00075     m_mplaneSensor->attach (&m_manipPlane->plane);
00076 }
00077 
00078 IgSoSlicer::~IgSoSlicer (void)
00079 {
00080     removeChild (m_manipPlane);
00081     removeChild (m_front);
00082     removeChild (m_back);
00083     m_manipPlane->unref ();
00084     m_front->unref ();
00085     m_back->unref ();
00086     m_engine->unref();
00087     delete m_planeSensor;
00088     delete m_mplaneSensor;
00089 }
00090 
00093 void
00094 IgSoSlicer::mplaneSensorCB (void *me, SoSensor *)
00095 {
00096     IgSoSlicer *self = static_cast<IgSoSlicer *> (me);
00097     self->m_planeSensor->detach ();
00098     self->plane = self->m_manipPlane->plane;
00099     self->m_planeSensor->attach (&self->plane);
00100 }
00101 
00104 void
00105 IgSoSlicer::planeSensorCB (void *me, SoSensor *)
00106 {
00107     IgSoSlicer *self = static_cast<IgSoSlicer *> (me);
00108     self->m_mplaneSensor->detach ();
00109     self->m_manipPlane->plane = self->plane;
00110     self->m_mplaneSensor->attach (&self->m_manipPlane->plane);
00111 }
00112 
00113 void
00114 IgSoSlicer::write (SoWriteAction *action)
00115 { SoNode::write (action); }

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