]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPainterContour.cxx
Updated documentation
[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 = area.Position().X();
68   Double_t y = area.Position().Y();
69   Double_t dx = area.Dimensions().X();
70   Double_t dy = area.Dimensions().Y();
71   line->SetPoint(0,x-dx,y-dy);
72   line->SetPoint(1,x-dx,y+dy);
73   line->SetPoint(2,x+dx,y+dy);
74   line->SetPoint(3,x+dx,y-dy);
75   line->SetPoint(4,x-dx,y-dy);
76   
77   fPolyLines->AddLast(line);
78 }
79
80 //______________________________________________________________________________
81 AliMUONPainterContour::AliMUONPainterContour(const AliMUONPainterContour& rhs) 
82 : TNamed(rhs), 
83 fPolyLines(0x0),
84 fXmin(FLT_MAX),
85 fXmax(-FLT_MAX),
86 fYmin(FLT_MAX),
87 fYmax(-FLT_MAX)
88 {
89   /// Copy constructor.
90   
91   ((AliMUONPainterContour&)rhs).Copy(*this);
92 }
93
94 //______________________________________________________________________________
95 AliMUONPainterContour&
96 AliMUONPainterContour::operator=(const AliMUONPainterContour& rhs)
97 {
98   /// Assignment operator
99   if ( this != &rhs ) 
100   {
101     delete fPolyLines;
102     fPolyLines = 0;
103     rhs.Copy(*this);
104   }
105   return *this;
106 }
107
108 //_____________________________________________________________________________
109 AliMUONPainterContour::~AliMUONPainterContour()
110 {
111   /// dtor
112   delete fPolyLines;
113 }
114
115 //_____________________________________________________________________________
116 void 
117 AliMUONPainterContour::AdoptPolyLine(TPolyLine* line)
118 {
119   /// Adopt one polyline into our array of polylines
120   fPolyLines->AddLast(line);
121   for ( Int_t i = 0; i <= line->GetLastPoint(); ++i ) 
122   {
123     Double_t x = line->GetX()[i];
124     Double_t y = line->GetY()[i];
125     fXmin = TMath::Min(fXmin,x);
126     fXmax = TMath::Max(fXmax,x);
127     fYmin = TMath::Min(fYmin,y);
128     fYmax = TMath::Max(fYmax,y);
129   }
130 }
131
132 //_____________________________________________________________________________
133 AliMpArea
134 AliMUONPainterContour::Area() const
135 {
136   /// Return the area covered by this contour (i.e. the area that
137   /// contains all the poylines)
138   
139   return AliMpArea( TVector2( (fXmax+fXmin)/2.0, (fYmax+fYmin)/2.0 ),
140                     TVector2( TMath::Abs(fXmax-fXmin)/2.0, TMath::Abs(fYmax-fYmin)/2.0 ) );
141 }
142
143 //______________________________________________________________________________
144 void AliMUONPainterContour::Copy(TObject& obj) const
145 {
146   /// Copy this to obj
147   
148   AliMUONPainterContour& rhs = static_cast<AliMUONPainterContour&>(obj);
149   TNamed::Copy(rhs);
150   rhs.fPolyLines = new TObjArray;
151   rhs.fPolyLines->SetOwner(kTRUE);
152   TIter next(fPolyLines);
153   TPolyLine* line;
154   while ( ( line = static_cast<TPolyLine*>(next()) ) )
155   {
156     rhs.fPolyLines->AddLast(line->Clone());
157   }
158   rhs.fXmin = fXmin;
159   rhs.fXmax = fXmax;
160   rhs.fYmin = fYmin;
161   rhs.fYmax = fYmax;
162 }
163
164 //_____________________________________________________________________________
165 Bool_t 
166 AliMUONPainterContour::IsInside(Double_t x, Double_t y) const
167 {
168   /// Whether the point (x,y) is inside one of ours polylines
169 //  if ( x >= fXmin && x <= fXmax && y >= fYmin && y <= fYmax ) 
170   {
171     TIter next(fPolyLines);
172     TPolyLine* line;
173     while ( ( line = static_cast<TPolyLine*>(next()) ) )
174     {
175       if ( TMath::IsInside(x,y,line->Size(),line->GetX(),line->GetY() ) )
176       {
177         return kTRUE;
178       }
179     }
180   }
181   return kFALSE;
182 }
183
184 //_____________________________________________________________________________
185 void 
186 AliMUONPainterContour::Offset(const TVector2& offset)
187 {
188   /// Offset all lines by a given offset
189   
190   TIter next(fPolyLines);
191   TPolyLine* line;
192   
193   while ( ( line = static_cast<TPolyLine*>(next()) ) )
194   {
195     for ( Int_t i = 0; i <= line->GetLastPoint(); ++i ) 
196     {
197       Double_t x = line->GetX()[i];
198       Double_t y = line->GetY()[i];
199       x += offset.X();
200       y += offset.Y();
201       line->SetPoint(i,x,y);
202     }
203   }
204
205   fXmin += offset.X();
206   fXmax += offset.X();
207   fYmin += offset.Y();
208   fYmax += offset.Y();
209 }
210
211 //_____________________________________________________________________________
212 void 
213 AliMUONPainterContour::PaintArea(Int_t fillColor, Int_t fillStyle)
214 {
215   /// Paint a filled contour
216   
217   Int_t fc = gVirtualX->GetFillColor();
218   Int_t fs = gVirtualX->GetFillStyle();
219   
220   TIter next(fPolyLines);
221   TPolyLine* line;
222   
223   while ( ( line = static_cast<TPolyLine*>(next()) ) )
224   {
225     line->SetFillColor(fillColor);
226     line->SetFillStyle(fillStyle);
227     line->Paint("F");
228   }
229   
230   gVirtualX->SetFillColor(fc);
231   gVirtualX->SetFillStyle(fs);
232 }
233
234 //_____________________________________________________________________________
235 void 
236 AliMUONPainterContour::PaintOutline(Int_t lineColor, Int_t lineWidth)
237 {
238   /// Paint the outline of this contour
239   
240   Int_t lc = gVirtualX->GetLineColor();
241   Int_t lw = gVirtualX->GetLineWidth();
242   
243   TIter next(fPolyLines);
244   TPolyLine* line;
245   
246   while ( ( line = static_cast<TPolyLine*>(next()) ) )
247   {
248     line->SetLineColor(lineColor);
249     line->SetLineWidth(lineWidth);
250     line->Paint();
251   }
252   
253   gVirtualX->SetLineColor(lc);
254   gVirtualX->SetLineWidth(lw);
255 }
256
257 //_____________________________________________________________________________
258 void 
259 AliMUONPainterContour::Print(Option_t* opt) const
260 {
261   /// Printout
262   
263   cout << GetName() << " Ngroups=" << fPolyLines->GetLast()+1;
264   TString sopt(opt);
265   sopt.ToUpper();
266
267   TIter next(fPolyLines);
268   TPolyLine* line;
269   while ( ( line = static_cast<TPolyLine*>(next()) ) )
270   {
271     cout << " (" << line->Size() << ")";
272     if ( sopt.Contains("FULL") )
273     {
274       cout << endl;
275       for ( Int_t i = 0; i < line->Size(); ++i ) 
276       {
277         Double_t x = line->GetX()[i];
278         Double_t y = line->GetY()[i];
279         cout << Form("Point %3d = %7.3f %7.3f",i,x,y) << endl;
280       }
281     }
282   }
283   cout << endl;
284 }  
285
286 //_____________________________________________________________________________
287 void 
288 AliMUONPainterContour::Transform(const TGeoHMatrix& matrix)
289 {
290   /// Transform the polylines using the given transformation
291   
292   TIter next(fPolyLines);
293   TPolyLine* line;
294   while ( ( line = static_cast<TPolyLine*>(next()) ) )
295   {
296     for ( Int_t i = 0; i < line->Size(); ++i ) 
297     {
298       Double_t pl[3] = { line->GetX()[i], line->GetY()[i], 0 };
299       Double_t pg[3] = { 0., 0., 0. };
300       matrix.LocalToMaster(pl, pg);
301       line->SetPoint(i,pg[0],pg[1]);
302     }
303   }
304   
305
306   Double_t pl[3] = { fXmin,fYmin, 0 };
307   Double_t pg[3] = { 0., 0., 0. };
308   matrix.LocalToMaster(pl, pg);
309   
310   fXmin = pg[0];
311   fYmin = pg[1];
312   
313   pl[0] = fXmax;
314   pl[1] = fYmax;
315
316   matrix.LocalToMaster(pl, pg);
317   fXmax = pg[0];
318   fYmax= pg[1];
319 }