CMS 3D CMS Logo

VisQueuedTwig.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "VisFramework/VisFrameworkBase/interface/VisQueuedTwig.h"
00004 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00005 #include "VisFramework/VisConfigService/interface/VisConfigurationService.h"
00006 #include "Iguana/GLModels/interface/IgCommon3DReps.h"
00007 #include "Iguana/GLModels/interface/Ig2DModel.h"
00008 #include "Iguana/GLModels/interface/Ig2DRep.h"
00009 #include "Iguana/Inventor/interface/IgSurfaceOperation.h"
00010 #include "Iguana/Studio/interface/IgQtLock.h"
00011 #include "Iguana/Framework/interface/IgRepSet.h"
00012 #include <Inventor/actions/SoGetBoundingBoxAction.h>
00013 #include <Inventor/actions/SoSearchAction.h>
00014 #include <Inventor/nodes/SoMaterial.h>
00015 #include <Inventor/nodes/SoSeparator.h>
00016 #include <qregexp.h>
00017 
00018 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00019 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00020 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00021 
00022 class VisQueuedTwig::ExactMatch
00023 {
00024     std::string m_name;
00025 
00026 public:
00027     ExactMatch (std::string name) : m_name (name) {}
00028 
00029     bool operator() (const std::string twig)
00030         { 
00031             QRegExp rx (twig);
00032             rx.setWildcard (true);
00033             rx.setCaseSensitive (false);
00034             return rx.exactMatch (m_name);
00035         }
00036 };
00037 
00038 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00039 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00040 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00041 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00042 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00043 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00044 
00045 VisQueuedTwig::VisQueuedTwig (IgState *state, IgTwig *parent,
00046                               const std::string &name /* = "" */)
00047     : IgSimpleTwig (parent, name, true, false, true),
00048       VisEventObserver (state),
00049       m_state (state)
00050 { 
00051     ASSERT (m_state); 
00052     const edm::ParameterSet *pset = VisConfigurationService::pSet ();
00053     if (pset)
00054     {
00055         std::vector<std::string> twigs;
00056         twigs = pset->getUntrackedParameter<std::vector<std::string> > ("EnabledTwigs", twigs);
00057         
00058         if (std::find_if (twigs.begin (), twigs.end (), ExactMatch (fullName ())) != twigs.end ())
00059             selfVisible (true);
00060     }
00061 }
00062 
00063 void
00064 VisQueuedTwig::onNewEvent (const edm::Event &, const edm::EventSetup &) 
00065 { LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00066        << "]::onNewEvent(edm::Event,edm::EventSetup)\n");}
00067 
00068 void
00069 VisQueuedTwig::onBaseInvalidate (void)
00070 {
00071     LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00072          << "]::onBaseInvalidate()\n");
00073     
00074     // Lock the main thread while we walk the ancestors of this twig
00075     // and (possibly) create a burst of requests to update my reps.
00076     // Note that this does not yet actually update the reps, we only
00077     // invoke VisQueue::push() to queue calls.  We are executing
00078     // in the event consumer thread so the main thread is the only one
00079     // we need to block.  Note that always have to update the object
00080     // even if this is not visible.  Otherwise the object may get
00081     // hidden, get a notification (ignored here) and then made visible
00082     // again -- with the old, wrong contents.
00083     IgQtLock ();
00084     
00085     IgRepSet::invalidate (this, SELF_MASK);
00086 }
00087 
00088 void
00089 VisQueuedTwig::onException (lat::Callback1<std::exception *> callback)
00090 {
00091     LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00092          << "]::onException()\n");
00093 
00094     m_onException = callback;
00095 }
00096 
00097 void
00098 VisQueuedTwig::onUnhandledException (lat::Callback callback)
00099 {
00100     LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00101          << "]::onUnhandledException()\n");
00102 
00103     m_onUnhandledException = callback;    
00104 }
00105 
00106 void
00107 VisQueuedTwig::onError (lat::Callback1<lat::Error *> callback)
00108 {
00109     LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00110          << "]::onError()\n");
00111 
00112     m_onError = callback;
00113 }
00114 
00115 void
00116 VisQueuedTwig::onCmsException (lat::Callback1<cms::Exception *> callback)
00117 {
00118     LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00119          << "]::onCmsException()\n");
00120 
00121     m_onCmsException = callback;
00122 }
00123 
00125 void
00126 VisQueuedTwig::update (Ig3DRep *)
00127 { LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00128        << "]::update(Ig3DRep)\n"); }
00129 
00130 void
00131 VisQueuedTwig::update (Ig2DRep *rep)
00132 { 
00133     // We do the actual clipping in here.
00134     LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00135          << "]::update(Ig2DRep)\n"); 
00136 
00137     Ig2DModel *model = dynamic_cast <Ig2DModel *> (rep->model ());
00138     ASSERT (model);        
00139     ASSERT (model->sourceModel ());
00140     
00141     // Get the original 3D rep. No need to create it as this has
00142     // already taken care by the multimethod, moreover it is always
00143     // scheduled to be upgraded before this 2D one.
00144     Ig3DBaseRep *sourceRep
00145         = static_cast<Ig3DBaseRep *>
00146         (IgRepSet::lookup (this, model->sourceModel ()));
00147 
00148     rep->clear ();
00149     
00150     if (sourceRep)
00151     {
00152         static SbViewportRegion viewportRegion (640, 480);          
00153         static SoGetBoundingBoxAction bbAction(viewportRegion);
00154         
00155         // Gets the material for the twig
00156         SoSearchAction getMaterialAction;
00157         getMaterialAction.setType (SoMaterial::getClassTypeId ());
00158         getMaterialAction.apply (sourceRep->node ());   
00159         if (getMaterialAction.getPath () != 0)
00160             rep->node ()->addChild
00161                 (getMaterialAction.getPath ()->getTail ());
00162         
00163         // Cut the original rep with a plane 
00164         
00165         // First we rotate the object so that we are cutting it
00166         // with the correct orientation.
00167         SoSeparator *sep = new SoSeparator;
00168         sep->addChild (model->cutTransform ());     
00169         sep->addChild (sourceRep->node ());
00170         sep->ref ();
00171         
00172         // Then we calculate its 2D projected bounding box, so
00173         // that the plane we are using to cut it is actually
00174         // rescaled to better match the position and size of the
00175         // object.
00176         bbAction.apply (sep);
00177         SbBox3f sourceBox = bbAction.getBoundingBox ();
00178         
00179         SbVec3f sourceCenter = sourceBox.getCenter ();
00180         SbVec3f dimensions = sourceBox.getMax () - sourceCenter;
00181         float sourceSizeWidth = fabs (dimensions [0]);
00182         float sourceSizeHeight = fabs (dimensions [1]);
00183         
00184         model->setCutPlanePosition (sourceCenter[0], sourceCenter[1]);
00185         model->setCutPlaneSize (sourceSizeWidth*2,
00186                                 sourceSizeHeight*2);
00187         
00188         // Then we perform the cut operation and add the result to
00189         // the rep.
00190         IgSurfaceOperation cutOperation (IgSurfaceOperation::SURFACE_1_IN_2);
00191         SoNode *result = cutOperation.apply (model->cutPlane (), sep);
00192         result->ref ();
00193         
00194         SoSeparator *resultSep = new SoSeparator;
00195         resultSep->addChild (result);
00196         rep->node ()->addChild (resultSep);     
00197     }
00198 }
00199 
00200 void
00201 VisQueuedTwig::update (IgLegoRep *)
00202 { LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00203        << "]::update(IgLegoRep)\n"); }
00204 
00205 void
00206 VisQueuedTwig::update (IgTextRep *)
00207 { LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00208        << "]::update(IgTextRep)\n"); }
00209 
00210 void
00211 VisQueuedTwig::update (IgRPhiRep *)
00212 { LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00213        << "]::update(IgRPhiRep)\n"); }
00214 
00215 
00216 void
00217 VisQueuedTwig::update (IgRZRep *)
00218 { LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00219        << "]::update(IgRZRep)\n"); }
00220 void
00221 VisQueuedTwig::update (IgSpareRep *)
00222 { LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00223        << "]::update(IgSpareRep)\n"); }
00224 

Generated on Tue Jun 9 17:50:04 2009 for CMSSW by  doxygen 1.5.4