]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPainterContour.cxx
Replacement of TVector2 object with two doubles
[u/mrichter/AliRoot.git] / MUON / AliMUONPainterContour.cxx
1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 *                                                                        *
4 * Author: The ALICE Off-line Project.                                    *
5 * Contributors are mentioned in the code where appropriate.              *
6 *                                                                        *
7 * Permission to use, copy, modify and distribute this software and its   *
8 * documentation strictly for non-commercial purposes is hereby granted   *
9 * without fee, provided that the above copyright notice appears in all   *
10 * copies and that both the copyright notice and this permission notice   *
11 * appear in the supporting documentation. The authors make no claims     *
12 * about the suitability of this software for any purpose. It is          *
13 * provided "as is" without express or implied warranty.                  *
14 **************************************************************************/
15
16 // $Id$
17
18 #include "AliMUONPainterContour.h"
19
20 #include "AliMpArea.h"
21 #include "AliLog.h"
22 #include <Riostream.h>
23 #include <TGeoMatrix.h>
24 #include <TMath.h>
25 #include <TObjArray.h>
26 #include <TPolyLine.h>
27 #include <TString.h>
28 #include <TVector2.h>
29 #include <TVirtualX.h>
30 #include <float.h>
31
32 ///\class AliMUONPainterContour
33 ///
34 /// Contour for one painter. A contour is a set of TPolyLine (one polyline
35 /// per closed shape).
36 ///
37 ///\author Laurent Aphecetche, Subatech
38
39 ///\cond CLASSIMP
40 ClassImp(AliMUONPainterContour)
41 ///\endcond
42
43 //_____________________________________________________________________________
44 AliMUONPainterContour::AliMUONPainterContour(const char* name) : TNamed(name,""), 
45 fPolyLines(new TObjArray),
46 fXmin(FLT_MAX),
47 fXmax(-FLT_MAX),
48 fYmin(FLT_MAX),
49 fYmax(-FLT_MAX)
50 {
51   /// ctor
52   fPolyLines->SetOwner(kTRUE);
53 }
54
55 //_____________________________________________________________________________
56 AliMUONPainterContour::AliMUONPainterContour(const char* name, const AliMpArea& area) 
57 : TNamed(name,""), 
58 fPolyLines(new TObjArray),
59 fXmin(area.LeftBorder()),
60 fXmax(area.RightBorder()),
61 fYmin(area.DownBorder()),
62 fYmax(area.UpBorder())
63 {
64   /// ctor
65   fPolyLines->SetOwner(kTRUE);
66   TPolyLine* line = new TPolyLine(5);
67   Double_t x, y, dx, dy;
68   area.GetParameters(x, y, dx, dy);
69   line->SetPoint(0,x-dx,y-dy);
70   line->SetPoint(1,x-dx,y+dy);
71   line->SetPoint(2,x+dx,y+dy);
72   line->SetPoint(3,x+dx,y-dy);
73   line->SetPoint(4,x-dx,y-dy);
74   
75   fPolyLines->AddLast(line);
76 }
77
78 //______________________________________________________________________________
79 AliMUONPainterContour::AliMUONPainterContour(const AliMUONPainterContour& rhs) 
80 : TNamed(rhs), 
81 fPolyLines(0x0),
82 fXmin(FLT_MAX),
83 fXmax(-FLT_MAX),
84 fYmin(FLT_MAX),
85 fYmax(-FLT_MAX)
86 {
87   /// Copy constructor.
88   
89   ((AliMUONPainterContour&)rhs).Copy(*this);
90 }
91
92 //______________________________________________________________________________
93 AliMUONPainterContour&
94 AliMUONPainterContour::operator=(const AliMUONPainterContour& rhs)
95 {
96   /// Assignment operator
97   if ( this != &rhs ) 
98   {
99     delete fPolyLines;
100     fPolyLines = 0;
101     rhs.Copy(*this);
102   }
103   return *this;
104 }
105
106 //_____________________________________________________________________________
107 AliMUONPainterContour::~AliMUONPainterContour()
108 {
109   /// dtor
110   delete fPolyLines;
111 }
112
113 //_____________________________________________________________________________
114 void 
115 AliMUONPainterContour::AdoptPolyLine(TPolyLine* line)
116 {
117   /// Adopt one polyline into our array of polylines
118   fPolyLines->AddLast(line);
119   for ( Int_t i = 0; i <= line->GetLastPoint(); ++i ) 
120   {
121     Double_t x = line->GetX()[i];
122     Double_t y = line->GetY()[i];
123     fXmin = TMath::Min(fXmin,x);
124     fXmax = TMath::Max(fXmax,x);
125     fYmin = TMath::Min(fYmin,y);
126     fYmax = TMath::Max(fYmax,y);
127   }
128 }
129
130 //_____________________________________________________________________________
131 AliMpArea
132 AliMUONPainterContour::Area() const
133 {
134   /// Return the area covered by this contour (i.e. the area that
135   /// contains all the poylines)
136   
137   return AliMpArea( ( fXmax+fXmin)/2.0, (fYmax+fYmin)/2.0 ,
138                     TMath::Abs(fXmax-fXmin)/2.0, TMath::Abs(fYmax-fYmin)/2.0 );
139 }
140
141 //______________________________________________________________________________
142 void AliMUONPainterContour::Copy(TObject& obj) const
143 {
144   /// Copy this to obj
145   
146   AliMUONPainterContour& rhs = static_cast<AliMUONPainterContour&>(obj);
147   TNamed::Copy(rhs);
148   rhs.fPolyLines = new TObjArray;
149   rhs.fPolyLines->SetOwner(kTRUE);
150   TIter next(fPolyLines);
151   TPolyLine* line;
152   while ( ( line = static_cast<TPolyLine*>(next()) ) )
153   {
154     rhs.fPolyLines->AddLast(line->Clone());
155   }
156   rhs.fXmin = fXmin;
157   rhs.fXmax = fXmax;
158   rhs.fYmin = fYmin;
159   rhs.fYmax = fYmax;
160 }
161
162 //_____________________________________________________________________________
163 Bool_t 
164 AliMUONPainterContour::IsInside(Double_t x, Double_t y) const
165 {
166   /// Whether the point (x,y) is inside one of ours polylines
167 //  if ( x >= fXmin && x <= fXmax && y >= fYmin && y <= fYmax ) 
168   {
169     TIter next(fPolyLines);
170     TPolyLine* line;
171     while ( ( line = static_cast<TPolyLine*>(next()) ) )
172     {
173       if ( TMath::IsInside(x,y,line->Size(),line->GetX(),line->GetY() ) )
174       {
175         return kTRUE;
176       }
177     }
178   }
179   return kFALSE;
180 }
181
182 //_____________________________________________________________________________
183 void 
184 AliMUONPainterContour::Offset(const TVector2& offset)
185 {
186   /// Offset all lines by a given offset
187   
188   TIter next(fPolyLines);
189   TPolyLine* line;
190   
191   while ( ( line = static_cast<TPolyLine*>(next()) ) )
192   {
193     for ( Int_t i = 0; i <= line->GetLastPoint(); ++i ) 
194     {
195       Double_t x = line->GetX()[i];
196       Double_t y = line->GetY()[i];
197       x += offset.X();
198       y += offset.Y();
199       line->SetPoint(i,x,y);
200     }
201   }
202
203   fXmin += offset.X();
204   fXmax += offset.X();
205   fYmin += offset.Y();
206   fYmax += offset.Y();
207 }
208
209 //_____________________________________________________________________________
210 void 
211 AliMUONPainterContour::PaintArea(Int_t fillColor, Int_t fillStyle)
212 {
213   /// Paint a filled contour
214   
215   Int_t fc = gVirtualX->GetFillColor();
216   Int_t fs = gVirtualX->GetFillStyle();
217   
218   TIter next(fPolyLines);
219   TPolyLine* line;
220   
221   while ( ( line = static_cast<TPolyLine*>(next()) ) )
222   {
223     line->SetFillColor(fillColor);
224     line->SetFillStyle(fillStyle);
225     line->Paint("F");
226   }
227   
228   gVirtualX->SetFillColor(fc);
229   gVirtualX->SetFillStyle(fs);
230 }
231
232 //_____________________________________________________________________________
233 void 
234 AliMUONPainterContour::PaintOutline(Int_t lineColor, Int_t lineWidth)
235 {
236   /// Paint the outline of this contour
237   
238   Int_t lc = gVirtualX->GetLineColor();
239   Int_t lw = gVirtualX->GetLineWidth();
240   
241   TIter next(fPolyLines);
242   TPolyLine* line;
243   
244   while ( ( line = static_cast<TPolyLine*>(next()) ) )
245   {
246     line->SetLineColor(lineColor);
247     line->SetLineWidth(lineWidth);
248     line->Paint();
249   }
250   
251   gVirtualX->SetLineColor(lc);
252   gVirtualX->SetLineWidth(lw);
253 }
254
255 //_____________________________________________________________________________
256 void 
257 AliMUONPainterContour::Print(Option_t* opt) const
258 {
259   /// Printout
260   
261   cout << GetName() << " Ngroups=" << fPolyLines->GetLast()+1;
262   TString sopt(opt);
263   sopt.ToUpper();
264
265   TIter next(fPolyLines);
266   TPolyLine* line;
267   while ( ( line = static_cast<TPolyLine*>(next()) ) )
268   {
269     cout << " (" << line->Size() << ")";
270     if ( sopt.Contains("FULL") )
271     {
272       cout << endl;
273       for ( Int_t i = 0; i < line->Size(); ++i ) 
274       {
275         Double_t x = line->GetX()[i];
276         Double_t y = line->GetY()[i];
277         cout << Form("Point %3d = %7.3f %7.3f",i,x,y) << endl;
278       }
279     }
280   }
281   cout << endl;
282 }  
283
284 //_____________________________________________________________________________
285 void 
286 AliMUONPainterContour::Transform(const TGeoHMatrix& matrix)
287 {
288   /// Transform the polylines using the given transformation
289   
290   TIter next(fPolyLines);
291   TPolyLine* line;
292   while ( ( line = static_cast<TPolyLine*>(next()) ) )
293   {
294     for ( Int_t i = 0; i < line->Size(); ++i ) 
295     {
296       Double_t pl[3] = { line->GetX()[i], line->GetY()[i], 0 };
297       Double_t pg[3] = { 0., 0., 0. };
298       matrix.LocalToMaster(pl, pg);
299       line->SetPoint(i,pg[0],pg[1]);
300     }
301   }
302   
303
304   Double_t pl[3] = { fXmin,fYmin, 0 };
305   Double_t pg[3] = { 0., 0., 0. };
306   matrix.LocalToMaster(pl, pg);
307   
308   fXmin = pg[0];
309   fYmin = pg[1];
310   
311   pl[0] = fXmax;
312   pl[1] = fYmax;
313
314   matrix.LocalToMaster(pl, pg);
315   fXmax = pg[0];
316   fYmax= pg[1];
317 }