Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

TridPageSlice.cxx

Go to the documentation of this file.
00001 #include <TGeoManager.h>
00002 
00003 #include "TridPageSlice.h"
00004 #include "TridModelSlice.h"
00005 #include "TridModelMaker.h"
00006 #include "TridControl.h"
00007 #include "TridGLFrame.h"
00008 #include "TridFlatGLFrame.h"
00009 
00010 #include "Midad/Base/PageProxy.h"
00011 #include "Midad/Base/Mint.h"
00012 
00013 #include "JobControl/JobC.h"
00014 #include "MessageService/MsgService.h"
00015 
00016 using namespace std;
00017 using namespace SigC;
00018 
00019 CVSID("$Id: TridPageSlice.cxx,v 1.4 2006/06/04 20:37:40 tagg Exp $");
00020 
00021 static PageProxy<TridPageSlice> gsTridPageSliceProxy("TridSlice");
00022 
00023 const double kWidth = 10;
00024 const double kHeight = 3;
00025 
00026 
00027 TridPageSlice::TridPageSlice() : TridPage()
00028 {
00029   // Default view.
00030   fViewModesSupported = kView2D | kView3D;
00031   fViewMode = kView2D;
00032   fWindowName = "TridSlice";
00033   fFullPOV.Set(kWidth*0.5, 0, -kHeight*0.5, 9, 90, 0 );  
00034   fAutoPOV.Set(kWidth*0.5, 0, -kHeight*0.5, 9, 90, 0 );  
00035 }
00036 
00037 TridPageSlice::~TridPageSlice()
00038 {
00039 }
00040 
00041 
00042 TObject* TridPageSlice::Init(Mint* mint, PageDisplay* pageDisplay, GuiBox& box)
00043 {
00044   MSG("TriD",Msg::kDebug) << "TridPageSlice: Init()\n";
00045   return TridPage::Init(mint, pageDisplay, box);
00046 }
00047 
00048 TridGLFrame* TridPageSlice::CreateNewGLFrame( TridPage::ViewMode_t mode )
00049 {
00050   TridPOV min(-kWidth   ,0, -kHeight,        0, 0,-180);
00051   TridPOV max(kWidth*2  ,0, +kHeight*2,   1000,90, 180);
00052   
00053   if(mode==kView2D) {
00054     MSG("TriD",Msg::kDebug) << "Changing to 2D" << endl;
00055     return new TridFlatGLFrame(this,*fGuiBox,fTridControl,min,max,1.5);
00056   };
00057 
00058   MSG("TriD",Msg::kDebug) << "Changing to 3D" << endl;
00059   return new TridGLFrame(this,*fGuiBox,fTridControl,min,max);
00060 }
00061 
00062 
00063 void TridPageSlice::CreateModels() 
00064 {
00065   fModels.Clear();
00066   fTridControl->ClearPicked();
00067   fTridControl->ClearSelected();
00068 
00069   TridModelMaker maker;
00070   maker.Prepare(&(fMint->GetJobC().Mom));
00071   maker.CreateSliceModels(&(fMint->GetJobC().Mom),fModels);
00072 }
00073 
00074 TVector3 TridPageSlice::SliceColor(int c)
00075 {
00076   // what color should slice c of n be?
00077   float f = (c%5)/4.;
00078   return GetColor(f);
00079 }
00080 
00081 void TridPageSlice::CreateSketches()
00082 {  
00083   fModels.ClearAssociations();
00084 
00085   TridModel* basemodel;
00086 
00087   // First, loop through to get the start/stop times.
00088   double tlow = 1e19;
00089   double thigh = -1e19;
00090   Int_t  nslices = 0;
00091 
00092   TridModelItr itr1 = fModels.GetIterator();
00093   while( (basemodel = itr1.Next()) ) {    
00094     // Make a new sketch for this model.
00095     TridModelSlice* slice = dynamic_cast<TridModelSlice*>(basemodel);
00096     if(slice) {
00097       nslices++;
00098       cout << nslices << " " << slice->GetEarliestTime() << " " << slice->GetLatestTime() << endl;
00099       if(slice->GetEarliestTime()<tlow) tlow = slice->GetEarliestTime();
00100       if(slice->GetLatestTime()>thigh)  thigh = slice->GetLatestTime();     
00101     }
00102   }
00103 
00104   if(nslices==0) return;
00105   if(tlow>1) {
00106     MSG("TriD",Msg::kWarning) << "Strange slice times. tlow=" << tlow << " thigh=" << thigh << std::endl;
00107   }
00108 
00109   thigh = tlow + 10.0e-6; // 10 us.
00110 
00111   // Set Z limits
00112   double zlow=0;
00113   double zhigh=120; // plane 120 
00114   if(fContext.GetDetector()==Detector::kFar) {
00115     zhigh = 294;
00116   }
00117 
00118   int icolor = 0;
00119 
00120   // Now loop through again to draw.
00121   TridModelItr itr2 = fModels.GetIterator();
00122   while( (basemodel = itr2.Next()) ) {    
00123     // Make a new sketch for this model.
00124     TridModelSlice* slice = dynamic_cast<TridModelSlice*>(basemodel);
00125 
00126     if(slice) {
00127       //       cout << "Drawing slice " << slice->GetSlice() << endl;
00128       //       cout << "  Hits: " << slice->fHits.size() << endl; 
00129       //       cout << "  Time start: " << slice->GetEarliestTime()-tlow << endl;
00130       //       cout << "  Time start: " << slice->GetLatestTime()  -tlow << endl;
00131       //       cout << "  Color: " << icolor << endl;
00132       
00133       for(UInt_t i=0; i< slice->fHits.size(); i++) {
00134         double z = slice->fHits[i].fPlane - zlow;
00135         double t = slice->fHits[i].fTime - tlow;
00136         double x = (t) /(thigh-tlow) * kWidth;
00137         double y = (z) /(zhigh-zlow) * kHeight;
00138         double w = (50e-9) /(thigh-tlow) * kWidth;   // duration of a hit
00139         double h = (2)      /(zhigh-zlow) * kHeight;
00140 
00141         cout << "   Hit: " << z << "\t" << t 
00142           << "\t" << x << "\t" << y << endl;
00143         double depth = 0.1;
00144         
00145         TVector3 pos(x+w*0.5,0,-(y+h*0.5));
00146         TridSketch* sk = new TridSketchBox(pos,
00147                                            kv_x, w*0.5,
00148                                            kv_z, h*0.5,
00149                                            kv_y, depth/2.);
00150         sk->SetTime(t);
00151         sk->SetColor(SliceColor(icolor));
00152         fGLFrame->AddSketch(sk);
00153         fModels.AssociateModel(slice,sk->GetId());
00154       }
00155       
00156     }
00157     icolor++;
00158   }
00159 }
00160 
00161 void TridPageSlice::CreateScenery()
00162 {  
00163   TridSketch::SetDefaultColor(fTridControl->GetForegroundColor());
00164   TridSketch::StartScenery();
00165       // Put a black quad behind everything so mouse movement works better.
00166 
00167   
00168   TridSketch* backplane = new TridSketchPlane
00169     ( TVector3(kWidth* 0.5, -1.0, kHeight*0.5),
00170       kv_x, kWidth  * 4,
00171       kv_z, kHeight * 4 
00172       );
00173   backplane->SetColor(fTridControl->GetBackgroundColor());
00174   fGLFrame->AddSketch(backplane);
00175   
00176 
00177   TridSketch* l;
00178 
00179   l = new TridSketchLine( TVector3(0, -0.1, 0),
00180                           TVector3(0, -0.1, -kHeight) );
00181   fGLFrame->AddSketch(l);
00182 
00183   l = new TridSketchLine( TVector3(0,      -0.1, 0),
00184                           TVector3(kWidth, -0.1, 0) );
00185   fGLFrame->AddSketch(l);
00186 
00187   TridSketchText* txt;
00188   for(int i=0;i<=10;i+=2) {
00189     l = new TridSketchLine( TVector3((double)i,      -0.1, 0),
00190                             TVector3((double)i,      -0.1, 0.1)
00191                             );
00192     fGLFrame->AddSketch(l);
00193 
00194     txt = new TridSketchText( TVector3((double)i, -0.1, 0.5), -kv_z, kv_y, 
00195                               Form("%d us",i) );
00196     txt->SetScale(0.2);
00197     txt->SetThickness(0.005);
00198     fGLFrame->AddSketch(txt);
00199   }
00200   
00201   l = new TridSketchLine( TVector3(   0, -0.1, 0 ),
00202                           TVector3(-0.2, -0.1, 0 ) );
00203   fGLFrame->AddSketch(l);
00204 
00205   txt = new TridSketchText( TVector3(-0.5, -0.1, 0), -kv_z, kv_y, "Plane 0");
00206   txt->SetScale(0.2);
00207   txt->SetThickness(0.005);
00208   fGLFrame->AddSketch(txt);
00209 
00210   l = new TridSketchLine( TVector3(   0, -0.1, -kHeight ),
00211                           TVector3(-0.2, -0.1, -kHeight ) );
00212   fGLFrame->AddSketch(l);
00213 
00214   txt = new TridSketchText( TVector3(-1.0, -0.1, -kHeight), -kv_z, kv_y, 
00215                             (fContext.GetDetector()==Detector::kFar)?("Plane 295"):("Plane 120"));
00216   txt->SetScale(0.2);
00217   txt->SetThickness(0.005);
00218   fGLFrame->AddSketch(txt);
00219   
00220 
00221   TridSketch::StopScenery();
00222 }
00223 
00224 
00225 void TridPageSlice::ModifySketches()
00226 {
00227   // Go through all models. Modify their sketches to match the current
00228   // transparency and color maps.
00229 
00230   fColorHistogram->Reset();
00231   fTransHistogram->Reset();
00232 
00233   int nsketches =0;
00234 
00235   TridSketchListItr itr = fGLFrame->GetIterator();
00236   while( TridSketch* sketch = itr.Next() ) {
00237     int sketchnum = sketch->GetId();
00238     TridModel* model = fModels.GetModelFromSketch(sketchnum);
00239 
00240     if((sketch)&&(model)) {
00241       nsketches++;
00242  
00243       Double_t trans_x = fTridControl->GetRangedModelTrans(model);
00244       Double_t color_x = fTridControl->GetRangedModelColor(model);
00245       fColorHistogram->Fill(color_x);
00246       fTransHistogram->Fill(trans_x);
00247       sketch->SetTransparency(trans_x);
00248 
00249       // set color by number:
00250       sketch->SetColor(SliceColor(model->GetSlice()));
00251 
00252      // If picked, shine as white.
00253      if(fTridControl->IsPicked(model))
00254        sketch->SetColor(1,1,1);
00255      
00256      // Ditto selected.
00257      if(fTridControl->IsSelected(model))
00258        sketch->SetColor(1,1,1);
00259          
00260 
00261     } else {
00262       if(!(sketch->IsScenery())) {
00263         MSG("TriD",Msg::kError) << "Cannot find sketch or model "
00264                                 << " ModelAdd:"     << model 
00265                                 << " Model ID:"     << ((model) ? (model->GetId()) : 0)
00266                                 << " ModelKey:"     << ((model) ? (model->GetSortKey()) : 0)
00267                                 << " SketchNumber:" << sketchnum
00268                                 << " SketchAddr: " << sketch << endl;
00269         //if(model) model->Print();
00270       }
00271     }
00272   }
00273 }
00274 

Generated on Thu Nov 1 11:53:31 2007 for loon by  doxygen 1.3.9.1