00001
00002 #include "VisReco/VisTracker/interface/VisTkRecTracksTwig.h"
00003 #include "VisFramework/VisFrameworkBase/interface/VisTwigFactroyService.h"
00004 #include "VisFramework/VisFrameworkBase/interface/VisEventSelector.h"
00005 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00006 #include "VisFramework/VisConfigService/interface/VisConfigurationService.h"
00007 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00008 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00009 #include "DataFormats/GeometryVector/interface/LocalVector.h"
00010 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00011 #include "DataFormats/TrackReco/interface/Track.h"
00012 #include "DataFormats/TrackReco/interface/TrackBase.h"
00013 #include "DataFormats/TrackReco/interface/TrackExtra.h"
00014 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00015 #include "FWCore/Framework/interface/Event.h"
00016 #include "FWCore/Framework/interface/EventSetup.h"
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00019 #include "FWCore/Utilities/interface/Exception.h"
00020 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00021 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00022 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00023 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00024 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00025 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00026 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00027 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00028 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00029 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
00030 #include "TrackingTools/TrackRefitter/interface/TrackTransformer.h"
00031
00032 #include "Iguana/Inventor/interface/IgSbColorMap.h"
00033 #include "Iguana/Inventor/interface/IgSoSimpleTrajectory.h"
00034 #include "Iguana/Inventor/interface/IgSoSplineTrack.h"
00035 #include "Iguana/Models/interface/IgTextRep.h"
00036 #include "Iguana/GLModels/interface/Ig3DRep.h"
00037 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00038 #include "Iguana/GLModels/interface/IgRZRep.h"
00039 #include "Iguana/GLModels/interface/IgLegoRep.h"
00040 #include "Iguana/Framework/interface/IgRepSet.h"
00041 #include "Iguana/Studio/interface/IgDocumentData.h"
00042 #include "Iguana/Studio/interface/IgQtLock.h"
00043
00044 #include "VisReco/VisTracker/interface/VisTrackerRechit2DTwig.h"
00045
00046 #include <Inventor/nodes/SoMaterial.h>
00047 #include <Inventor/nodes/SoSeparator.h>
00048 #include <Inventor/nodes/SoDrawStyle.h>
00049 #include <qmessagebox.h>
00050 #include <qstring.h>
00051 #include <classlib/utils/Error.h>
00052 #include <sstream>
00053 #include <iomanip>
00054 #include <iterator>
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 namespace
00067 {
00068 VisQueuedTwig *
00069 createThisTwig (IgState *state, IgTwig *parent,
00070 const std::string &name,
00071 const std::string &friendlyName,
00072 const std::string &modLabel,
00073 const std::string &instanceName,
00074 const std::string &processName)
00075 {
00076 IgTwig *rootTwig = IgDocumentData::get (state)->root ();
00077 IgTwig *eventTwig = 0;
00078 eventTwig = rootTwig->lookup ("/Objects/CMS Event and Detector/Tracker Event/Reconstructed Tracks");
00079
00080 if (! eventTwig)
00081 eventTwig = parent;
00082
00083 return new VisTkRecTracksTwig (state, eventTwig, "[N/A] Track (" + name + ")",
00084 friendlyName, modLabel, instanceName, processName);
00085 }
00086 }
00087
00088
00089
00090
00091 VisTkRecTracksTwig::VisTkRecTracksTwig (IgState *state, IgTwig *parent,
00092 const std::string &name ,
00093 const std::string &friendlyName ,
00094 const std::string &moduleLabel ,
00095 const std::string &instanceName ,
00096 const std::string &processName )
00097 : VisQueuedTwig (state, parent, name),
00098 m_text ("no info"),
00099 m_friendlyName (friendlyName),
00100 m_moduleLabel (moduleLabel),
00101 m_instanceName (instanceName),
00102 m_processName (processName),
00103 m_selectedTrack(state, lat::CreateCallback (this, &VisTkRecTracksTwig::configChanged))
00104 {
00105 VisTwigFactroyService *tfService = VisTwigFactroyService::get (state);
00106 if (! tfService)
00107 {
00108 tfService = new VisTwigFactroyService (state);
00109 }
00110 edm::TypeID trackID (typeid (reco::TrackCollection));
00111 tfService->registerTwig (trackID.friendlyClassName (), &createThisTwig);
00112 m_pset = VisConfigurationService::pSet ();
00113 if (! m_pset)
00114 {
00115 edm::ParameterSet p;
00116 VisConfigurationService *visService = new VisConfigurationService (p);
00117 m_pset = visService->pSet ();
00118 delete visService;
00119 }
00120
00121 m_haloFlag = m_pset->getUntrackedParameter<bool>("VisHaloTracks", false);
00122 m_trackThickness = m_pset->getUntrackedParameter<double> ("trackLineThickness", 2.0);
00123
00124 std::vector<std::string> notSpecified;
00125 m_trackCollectionNames = m_pset->getUntrackedParameter<std::vector<std::string> > ("trackCollectionNames", notSpecified);
00126
00127 init ();
00128 }
00129
00130 void
00131 VisTkRecTracksTwig::init (void)
00132 {
00133 edm::ParameterSet config;
00134
00135 config.addParameter<std::string> ("Fitter", "KFFitterForRefitInsideOut");
00136 config.addParameter<std::string> ("Smoother", "KFSmootherForRefitInsideOut");
00137 config.addParameter<std::string> ("Propagator", "SmartPropagatorAny");
00138 config.addParameter<std::string> ("TrackerRecHitBuilder", "WithTrackAngle");
00139 config.addParameter<std::string> ("MuonRecHitBuilder", "MuonRecHitBuilder");
00140 config.addParameter<std::string> ("RefitDirection", "insideOut");
00141 config.addParameter<bool> ("RefitRPCHits", true);
00142
00143 m_transformer = new TrackTransformer (config);
00144 }
00145
00146 void
00147 VisTkRecTracksTwig::onNewEvent (const edm::Event &event,
00148 const edm::EventSetup &eventSetup)
00149 {
00150 LOG (1, trace, LFfwvis, "VisTkRecTracksTwig[" << name ()
00151 << "]::onNewEvent()\n");
00152
00153 VisQueuedTwig::onBaseInvalidate ();
00154 m_tracks.clear ();
00155 m_trackPoints.clear ();
00156
00157 m_trajectoryPositions.clear ();
00158 m_trajectoryDirections.clear ();
00159
00160 m_text = (QString ("Run %1, Event %2, LS %3, Orbit %4, BX %5")
00161 .arg (event.id ().run ())
00162 .arg (event.id ().event ())
00163 .arg (event.luminosityBlock ())
00164 .arg (event.orbitNumber ())
00165 .arg (event.bunchCrossing ())
00166 .latin1 ());
00167
00168 std::vector<edm::Handle<reco::TrackCollection> > trackCollections;
00169
00170 try
00171 {
00172 if ((! m_friendlyName.empty ()) || (! m_moduleLabel.empty ()) || (! m_instanceName.empty ()) || (! m_processName.empty ()))
00173 {
00174 VisEventSelector visSel (m_friendlyName, m_moduleLabel, m_instanceName, m_processName);
00175 event.getMany (visSel, trackCollections);
00176 }
00177 }
00178 catch (lat::Error& e)
00179 {
00180 IgQtLock ();
00181
00182 delete m_transformer;
00183 init ();
00184
00185 if (this->m_onError)
00186 this->m_onError (&e);
00187 }
00188 catch (cms::Exception& e)
00189 {
00190 IgQtLock ();
00191
00192 delete m_transformer;
00193 init ();
00194
00195 if (this->m_onCmsException)
00196 this->m_onCmsException (&e);
00197 }
00198 catch (std::exception& e)
00199 {
00200 IgQtLock ();
00201
00202 delete m_transformer;
00203 init ();
00204
00205 if (this->m_onException)
00206 this->m_onException (&e);
00207 }
00208 catch (...)
00209 {
00210 IgQtLock ();
00211
00212 delete m_transformer;
00213 init ();
00214
00215 if (this->m_onUnhandledException)
00216 this->m_onUnhandledException ();
00217 }
00218
00219 if (! trackCollections.empty ())
00220 {
00221 try
00222 {
00223 eventSetup.get<GlobalTrackingGeometryRecord> ().get (m_trackerGeometry);
00224 }
00225 catch (cms::Exception& e)
00226 {
00227 if (this->m_onCmsException)
00228 this->m_onCmsException (&e);
00229 }
00230 catch (lat::Error &e)
00231 {
00232 if (this->m_onError)
00233 this->m_onError (&e);
00234 }
00235 catch (std::exception &e)
00236 {
00237 if (this->m_onException)
00238 this->m_onException (&e);
00239 }
00240 catch (...)
00241 {
00242 if (this->m_onUnhandledException)
00243 this->m_onUnhandledException ();
00244 }
00245
00246 if (m_trackerGeometry.isValid ())
00247 {
00248 LOG (2, trace, LFfwvis, "OK: trackCollections is not empty and TrackingGeometry is valid===>>>\n");
00249
00250 m_transformer->setServices (eventSetup);
00251 std::vector<Trajectory> trajectories;
00252
00253 std::vector<edm::Handle<reco::TrackCollection> >::iterator i;
00254 std::vector<edm::Handle<reco::TrackCollection> >::iterator iEnd;
00255
00256 LOG (2, trace, LFfwvis, "There are " << trackCollections.size () << " track collections.\n");
00257
00258 for (i = trackCollections.begin (), iEnd = trackCollections.end (); i != iEnd; ++i)
00259 {
00260 try
00261 {
00262 const reco::TrackCollection c = *(*i).product ();
00263 QString sizeStr = (QString ("%1").arg (c.size ()));
00264 QString nameStr = QString (this->name ());
00265 int ib = nameStr.find ("[");
00266 int ie = nameStr.find ("]");
00267 nameStr.replace (ib + 1, ie - 1, sizeStr);
00268 this->name (nameStr);
00269
00270 LOG (3, trace, LFfwvis, ": track collection has " << c.size () << " tracks\n");
00271 for (reco::TrackCollection::const_iterator track = c.begin (), trackEnd = c.end (); track != trackEnd; ++track)
00272 {
00273 m_tracks.push_back (*track);
00274 LOG (4, trace, LFfwvis, "\nTrack with rechitsize = " << (*track).recHitsSize () << "\n"
00275 << "Check the validity of the RecHits:" << "\n");
00276
00277 bool valid = true;
00278 for (trackingRecHit_iterator it = track->recHitsBegin (); it != track->recHitsEnd (); it++)
00279 {
00280 if ((*it)->geographicalId ().null ())
00281 {
00282 LOG (5, trace, LFfwvis, "\nWARNING: RecHit is not valid." << "\n");
00283 valid = false;
00284 }
00285 else
00286 {
00287 LOG (5, trace, LFfwvis, "\nRecHit is OK." << "\n");
00288 }
00289 }
00290
00291 std::vector<Trajectory> traj;
00292 if (valid && (*track).recHitsSize () > 3)
00293
00294 {
00295 LOG (1, trace, LFfwvis, "Try to convert Track to Trajectory..." << "\n");
00296 traj = m_transformer->transform (*track);
00297 LOG (2, trace, LFfwvis, "\nconverted " << traj.size () << " tracks to trajectories" << "\n"
00298 << "convertion of the Track to Trajectory finished." << "\n");
00299 }
00300
00301 int nRecHit = 0;
00302
00303 std::vector<SbVec3f> myTrack;
00304 for (trackingRecHit_iterator it = track->recHitsBegin (); it != track->recHitsEnd (); it++)
00305 {
00306 if ((*it)->isValid () && !(*it)->geographicalId ().null ())
00307 {
00308 LocalPoint point = VisTrackerRechit2DTwig::localPosition( &(**it) , m_trackerGeometry.product());
00309 float x = m_trackerGeometry->idToDet ((*it)->geographicalId ())->surface ().toGlobal (point).x () / 100.0;
00310 float y = m_trackerGeometry->idToDet ((*it)->geographicalId ())->surface ().toGlobal (point).y () / 100.0;
00311 float z = m_trackerGeometry->idToDet ((*it)->geographicalId ())->surface ().toGlobal (point).z () / 100.0;
00312 LOG (2, trace, LFfwvis, "#" << nRecHit++ << ": " << "(" << x << ", " << y << ", " << z << ")"
00313 << " on module =" << (*it)->geographicalId ().rawId () << "\n");
00314 myTrack.push_back (SbVec3f (x, y, z));
00315 }
00316 }
00317 m_trackPoints.push_back (myTrack);
00318
00319 if (traj.empty () && valid)
00320
00321 {
00322 LOG (2, trace, LFfwvis, "\nConvert failed, use Inner and Onter States\n");
00323
00324 std::vector<SbVec3f> myTraPos;
00325 std::vector<SbVec3f> myTraDir;
00326
00327 if ((*track).innerOk () && (*track).outerOk ())
00328 {
00329 float x = (*track).innerPosition ().x () / 100.0;
00330 float y = (*track).innerPosition ().y () / 100.0;
00331 float z = (*track).innerPosition ().z () / 100.0;
00332 SbVec3f posi (x, y, z);
00333
00334 float dirx = (*track).innerMomentum ().x ();
00335 float diry = (*track).innerMomentum ().y ();
00336 float dirz = (*track).innerMomentum ().z ();
00337 SbVec3f diri (dirx, diry, dirz);
00338 diri.normalize ();
00339
00340
00341
00342
00343 x = (*track).outerPosition ().x () / 100.0;
00344 y = (*track).outerPosition ().y () / 100.0;
00345 z = (*track).outerPosition ().z () / 100.0;
00346 SbVec3f poso (x, y, z);
00347
00348 dirx = (*track).outerMomentum ().x ();
00349 diry = (*track).outerMomentum ().y ();
00350 dirz = (*track).outerMomentum ().z ();
00351 SbVec3f diro (dirx, diry, dirz);
00352 diro.normalize ();
00353 if (m_haloFlag)
00354 {
00355 if ((poso-posi).dot (diri) < 0.F) diri = -1.F * diri;
00356 if ((poso-posi).dot (diro) < 0.F) diro = -1.F * diro;
00357 }
00358 myTraPos.push_back (posi);
00359 myTraDir.push_back (diri);
00360 myTraPos.push_back (poso);
00361
00362 myTraDir.push_back (diro);
00363 }
00364
00365 m_trajectoryPositions.push_back (myTraPos);
00366 m_trajectoryDirections.push_back (myTraDir);
00367 }
00368 else
00369 {
00370 LOG (2, trace, LFfwvis, "\nConvert successed, use Measurements\n");
00371 int nMeas = 0;
00372 std::vector<SbVec3f> myTraPos;
00373 std::vector<SbVec3f> myTraDir;
00374
00375 std::vector<TrajectoryMeasurement> meas = traj.front ().measurements ();
00376 LOG (2, trace, LFfwvis, "\n There're " << meas.size () << " Measurements in Trajectory\n");
00377
00378 for (std::vector<TrajectoryMeasurement>::const_iterator it = meas.begin (); it != meas.end (); ++it)
00379 {
00380 TrajectoryStateOnSurface updatedState = (*it).updatedState ();
00381
00382 if (updatedState.isValid ())
00383 {
00384 float x = updatedState.globalPosition ().x () / 100.0;
00385 float y = updatedState.globalPosition ().y () / 100.0;
00386 float z = updatedState.globalPosition ().z () / 100.0;
00387
00388 float dirx = updatedState.globalDirection ().x ();
00389 float diry = updatedState.globalDirection ().y ();
00390 float dirz = updatedState.globalDirection ().z ();
00391
00392 LOG (2, trace, LFfwvis, "#" << nMeas++ << "Pos: (" << x << ", " << y << ", " << z
00393 << "),\n Dir: (" << dirx << ", " << diry << ", " << dirz << ") "
00394 << " on module =" << (*it).recHit()->geographicalId ().rawId () << "\n");
00395
00396 myTraPos.push_back (SbVec3f (x, y, z));
00397 myTraDir.push_back (SbVec3f (dirx, diry, dirz));
00398
00399 }
00400 }
00401
00402 m_trajectoryPositions.push_back (myTraPos);
00403 m_trajectoryDirections.push_back (myTraDir);
00404 }
00405 }
00406 }
00407 catch (cms::Exception& e)
00408 {
00409 if (this->m_onCmsException)
00410 this->m_onCmsException (&e);
00411 }
00412 catch (lat::Error &e)
00413 {
00414 if (this->m_onError)
00415 this->m_onError (&e);
00416 }
00417 catch (std::exception &e)
00418 {
00419 if (this->m_onException)
00420 this->m_onException (&e);
00421 }
00422 catch (...)
00423 {
00424 if (this->m_onUnhandledException)
00425 this->m_onUnhandledException ();
00426 }
00427 }
00428 }
00429 }
00430
00431 IgRepSet::invalidate (this, IgTwig::SELF_MASK | IgTwig::STRUCTURE_MASK);
00432 }
00433
00434 void
00435 VisTkRecTracksTwig::configChanged (void)
00436 { IgRepSet::invalidate (this, SELF_MASK); }
00437
00438 void
00439 VisTkRecTracksTwig::update (IgTextRep *rep)
00440 {
00441
00442 VisQueuedTwig::update (rep);
00443
00444
00445 std::ostringstream text;
00446
00447 text << setiosflags (std::ios::showpoint | std::ios::fixed);
00448 text.setf (std::ios::right, std::ios::adjustfield);
00449
00450 text << m_text << "<br>";
00451
00452 try
00453 {
00454 unsigned int tracks_size = m_tracks.size ();
00455 text << tracks_size << " Reconstructed Tracks in collection defined by " << m_friendlyName << ":" << m_moduleLabel << ":" << m_instanceName << ":" << m_processName;
00456
00457 if (tracks_size == 0)
00458 {
00459 text << "" << std::endl;
00460 }
00461 else
00462 {
00463 for (unsigned int nt = 0; nt < tracks_size; nt++)
00464 {
00465 if (m_selectedTrack.value () == -1 || m_selectedTrack.value () == (int) nt)
00466 {
00467 std::ostringstream out_pt;
00468 out_pt << m_tracks [nt].pt ();
00469 text << "<table width='100%' border=1>"
00470 << "<TR align = center>"
00471 << "<TD COLSPAN = 5>Track number = " << nt
00472 << " track pt = " << out_pt.str ()
00473 << " and charge = " << m_tracks [nt].charge ()
00474 << "</TD></TR><TR align = center>"
00475 << "<TH>Reference Point (vx, vy, vz)</TH>"
00476 << "<TH>px, py, pz</TH>"
00477 << "<TH>Phi</TH>"
00478 << "<TH>Eta</TH>"
00479 << "<TH>RecHits (x, y, z)</TH>"
00480 << "</TR>";
00481
00482 text << "<TR><TD>" << std::setw (3) << std::setprecision (3)
00483 << m_tracks [nt].vx () / 100. << ", "
00484 << m_tracks [nt].vy () / 100. << ", "
00485 << m_tracks [nt].vz () / 100. << "</TD>"
00486 << "<TD>" << std::setw (3) << std::setprecision (3)
00487 << m_tracks [nt].px () << ", "
00488 << m_tracks [nt].py () << ", "
00489 << m_tracks [nt].pz () << "</TD>"
00490 << "<TD>" << std::setw (3) << std::setprecision (3) << m_tracks [nt].phi () << "</TD>"
00491 << "<TD>" << std::setw (3) << std::setprecision (3) << m_tracks [nt].eta () << "</TD>";
00492
00493 int n_rechit = 0;
00494 text << "<TD>";
00495
00496 if (nt < m_trackPoints.size ())
00497 for (std::vector<SbVec3f>::const_iterator ir = m_trackPoints[nt].begin (); ir != m_trackPoints[nt].end (); ++ir)
00498 {
00499 SbVec3f xyzPoint = (*ir);
00500 float x = xyzPoint [0];
00501 float y = xyzPoint [1];
00502 float z = xyzPoint [2];
00503
00504 text << std::setw (3) << n_rechit++ << ":("
00505 << std::setprecision (3) << x << "," << y << "," << z << "), ";
00506
00507 }
00508 text << "</TD></TR>";
00509 text << "</table>";
00510 }
00511 }
00512 }
00513 }
00514 catch (cms::Exception& e)
00515 {
00516 e.append (" from VisTkRecTracksTwig::update(IgTextRep*) ");
00517 e.append (this->name ());
00518
00519 if (this->m_onCmsException)
00520 this->m_onCmsException (&e);
00521 }
00522 catch (lat::Error &e)
00523 {
00524 if (this->m_onError)
00525 this->m_onError (&e);
00526 }
00527 catch (std::exception &e)
00528 {
00529 if (this->m_onException)
00530 this->m_onException (&e);
00531 }
00532 catch (...)
00533 {
00534 if (this->m_onUnhandledException)
00535 this->m_onUnhandledException ();
00536 }
00537
00538 IgQtLock ();
00539 rep->setText (text.str ());
00540 }
00541
00542 void
00543 VisTkRecTracksTwig::update (Ig3DRep *rep)
00544 {
00545
00546 VisQueuedTwig::update (rep);
00547
00548 IgQtLock ();
00549 rep->clear ();
00550
00551 SoSeparator *sep = new SoSeparator;
00552
00553 SoMaterial *mat = new SoMaterial;
00554 float rgbcomponents [4];
00555 IgSbColorMap::unpack (0x99ccff, rgbcomponents);
00556 mat->diffuseColor.setValue (SbColor (rgbcomponents));
00557 sep->addChild (mat);
00558
00559
00560 SoDrawStyle *sty = new SoDrawStyle;
00561 sty->style = SoDrawStyle::LINES;
00562 sty->lineWidth.setValue (m_trackThickness);
00563 sep->addChild (sty);
00564
00565 if (!m_trajectoryPositions.empty () && !m_trajectoryDirections.empty ())
00566 {
00567 std::vector<std::vector<SbVec3f> >::const_iterator ipos = m_trajectoryPositions.begin ();
00568 std::vector<std::vector<SbVec3f> >::const_iterator idir = m_trajectoryDirections.begin ();
00569 for (unsigned int itrack = 0; itrack != m_trajectoryPositions.size (); ++itrack)
00570 {
00571 if(m_selectedTrack.value()==-1 || m_selectedTrack.value()==(int)itrack){
00572 IgSoSplineTrack* myTraj = new IgSoSplineTrack;
00573 SoMFVec3f tangents;
00574 SoMFVec3f points;
00575 int nState = 0;
00576 std::vector<SbVec3f>::const_iterator idd = (*idir).begin ();
00577 for (std::vector<SbVec3f>::const_iterator ipp = (*ipos).begin (); ipp != (*ipos).end (); ++ipp)
00578 {
00579 points.set1Value (nState, (*ipp));
00580 tangents.set1Value (nState, (*idd));
00581
00582 nState++;
00583 idd++;
00584 }
00585 myTraj->points = points;
00586 myTraj->tangents = tangents;
00587
00588 sep->addChild (myTraj);
00589 }
00590 ipos++;
00591 idir++;
00592 }
00593 }
00594 rep->node ()->addChild (sep);
00595 }
00596
00597 void
00598 VisTkRecTracksTwig::update (IgRPhiRep *rep)
00599 {
00600
00601 VisQueuedTwig::update (rep);
00602
00603 IgQtLock ();
00604 rep->clear ();
00605
00606 if ((! m_tracks.empty ()) && m_trackerGeometry.isValid ())
00607 {
00608 SoSeparator *sep = new SoSeparator;
00609
00610 SoMaterial *mat = new SoMaterial;
00611 float rgbcomponents [4];
00612 IgSbColorMap::unpack (0x99ccff, rgbcomponents);
00613 mat->diffuseColor.setValue (SbColor (rgbcomponents));
00614 sep->addChild (mat);
00615
00616
00617 SoDrawStyle *sty = new SoDrawStyle;
00618 sty->style = SoDrawStyle::LINES;
00619 sty->lineWidth.setValue (m_trackThickness);
00620 sep->addChild (sty);
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638 if (!m_trajectoryPositions.empty () && !m_trajectoryDirections.empty ())
00639 {
00640 std::vector<std::vector<SbVec3f> >::const_iterator ipos = m_trajectoryPositions.begin ();
00641 std::vector<std::vector<SbVec3f> >::const_iterator idir = m_trajectoryDirections.begin ();
00642 for (unsigned int itrack = 0; itrack != m_trajectoryPositions.size (); ++itrack)
00643 {
00644 if(m_selectedTrack.value()==-1 || m_selectedTrack.value()==(int)itrack){
00645 IgSoSplineTrack* myTraj = new IgSoSplineTrack;
00646 SoMFVec3f tangents;
00647 SoMFVec3f points;
00648 int nState = 0;
00649 std::vector<SbVec3f>::const_iterator idd = (*idir).begin ();
00650 for (std::vector<SbVec3f>::const_iterator ipp = (*ipos).begin (); ipp != (*ipos).end (); ++ipp)
00651 {
00652 points.set1Value (nState, (*ipp));
00653 tangents.set1Value (nState, (*idd));
00654 nState++;
00655 idd++;
00656 }
00657 myTraj->points = points;
00658 myTraj->tangents = tangents;
00659
00660 sep->addChild (myTraj);
00661 }
00662 ipos++;
00663 idir++;
00664 }
00665 }
00666 rep->node ()->addChild (sep);
00667 }
00668 }
00669
00670
00671 void
00672 VisTkRecTracksTwig::update (IgRZRep *rep)
00673 {
00674
00675 VisQueuedTwig::update (rep);
00676
00677 IgQtLock ();
00678 rep->clear ();
00679
00680 if ((! m_tracks.empty ()) && m_trackerGeometry.isValid ())
00681 {
00682 SoSeparator *sep = new SoSeparator;
00683
00684 SoMaterial *mat = new SoMaterial;
00685 float rgbcomponents [4];
00686 IgSbColorMap::unpack (0x99ccff, rgbcomponents);
00687 mat->diffuseColor.setValue (SbColor (rgbcomponents));
00688 sep->addChild (mat);
00689
00690
00691 SoDrawStyle *sty = new SoDrawStyle;
00692 sty->style = SoDrawStyle::LINES;
00693 sty->lineWidth.setValue (m_trackThickness);
00694 sep->addChild (sty);
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711 if (!m_trajectoryPositions.empty () && !m_trajectoryDirections.empty ())
00712 {
00713 std::vector<std::vector<SbVec3f> >::const_iterator ipos = m_trajectoryPositions.begin ();
00714 std::vector<std::vector<SbVec3f> >::const_iterator idir = m_trajectoryDirections.begin ();
00715 for (unsigned int itrack = 0; itrack != m_trajectoryPositions.size(); ++itrack)
00716 {
00717 if (m_selectedTrack.value()==-1 || m_selectedTrack.value()==(int)itrack)
00718 {
00719 IgSoSplineTrack* myTraj = new IgSoSplineTrack;
00720 SoMFVec3f tangents;
00721 SoMFVec3f points;
00722 int nState = 0;
00723 std::vector<SbVec3f>::const_iterator idd = (*idir).begin ();
00724 bool projectInSameHalf = (((*idir).front()[1] * (*idir).back()[1] < 0 ) || ( fabs((*idir).front()[1]) < 0.3 ));
00725
00726 bool projectLower = ((*ipos).back()[1] < 0);
00727
00728 for (std::vector<SbVec3f>::const_iterator ipp = (*ipos).begin (); ipp != (*ipos).end (); ++ipp)
00729 {
00730 float posy = sqrt((*ipp)[0]*(*ipp)[0]+(*ipp)[1]*(*ipp)[1]);
00731 float diry = sqrt((*idd)[0]*(*idd)[0]+(*idd)[1]*(*idd)[1]);
00732
00733 if (projectInSameHalf)
00734 {
00735 if (projectLower)
00736 {
00737 posy = -posy;
00738 diry = -diry;
00739 }
00740 }
00741 else
00742 {
00743 if ((*ipp)[1] < 0) posy = -posy;
00744 if ((*idd)[1] < 0) diry = -diry;
00745 }
00746
00747 SbVec3f rzpos (0, posy, (*ipp)[2]);
00748 SbVec3f rzdir (0, diry, (*idd)[2]);
00749
00750 points.set1Value (nState, rzpos);
00751 tangents.set1Value (nState, rzdir);
00752 nState++;
00753 idd++;
00754 }
00755 myTraj->points = points;
00756 myTraj->tangents = tangents;
00757 sep->addChild (myTraj);
00758 }
00759 ipos++;
00760 idir++;
00761 }
00762 }
00763 rep->node ()->addChild (sep);
00764 }
00765 }
00766
00767 void
00768 VisTkRecTracksTwig::update (IgLegoRep *rep)
00769 {
00770
00771
00772 VisQueuedTwig::update (rep);
00773
00774 IgQtLock ();
00775 rep->clear ();
00776
00777
00778 }
00779