ROOT  6.06/09
Reference Guide
TEveShape.cxx
Go to the documentation of this file.
1 // @(#)root/eve:$Id$
2 // Author: Matevz Tadel, 2010
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TEveShape.h"
13 #include "Riostream.h"
14 
15 /** \class TEveShape
16 \ingroup TEve
17 Abstract base-class for 2D/3D shapes.
18 
19 It provides:
20  - fill color / transparency, accessible via Get/SetMainColor/Transparency;
21  - frame line color / width;
22  - flag if frame should be drawn;
23  - flag specifying whether frame or whole shape should be emphasised for
24  highlight.
25 */
26 
28 
29 ////////////////////////////////////////////////////////////////////////////////
30 /// Constructor.
31 
32 TEveShape::TEveShape(const char* n, const char* t) :
33  TEveElementList(n, t),
34  fFillColor(5),
35  fLineColor(5),
36  fLineWidth(1),
37  fDrawFrame(kTRUE),
38  fHighlightFrame(kFALSE),
39  fMiniFrame(kTRUE)
40 {
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Destructor.
48 
50 {
51 }
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Set main color.
55 /// Override so that line-color can also be changed if it is equal
56 /// to fill color (which is treated as main color).
57 
59 {
60  if (fFillColor == fLineColor) {
61  fLineColor = color;
62  StampObjProps();
63  }
65 }
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 /// Copy visualization parameters from element el.
69 
71 {
72  const TEveShape* m = dynamic_cast<const TEveShape*>(el);
73  if (m)
74  {
81  }
82 
84 }
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 /// Write visualization parameters.
88 
89 void TEveShape::WriteVizParams(std::ostream& out, const TString& var)
90 {
92 
93  TString t = " " + var + "->";
94  out << t << "SetFillColor(" << fFillColor << ");\n";
95  out << t << "SetLineColor(" << fLineColor << ");\n";
96  out << t << "SetLineWidth(" << fLineWidth << ");\n";
97  out << t << "SetDrawFrame(" << ToString(fDrawFrame) << ");\n";
98  out << t << "SetHighlightFrame(" << ToString(fHighlightFrame) << ");\n";
99 }
100 
101 ////////////////////////////////////////////////////////////////////////////////
102 /// Paint this object. Only direct rendering is supported.
103 
105 {
106  PaintStandard(this);
107 }
108 
109 ////////////////////////////////////////////////////////////////////////////////
110 /// Determines the convex-hull of points in pin.
111 ///
112 /// Adds the hull points to pout and returns the number of added points.
113 /// If size of pout is less then 3 then either the number of input points
114 /// was too low or they were degenerate so that the hull is actually a line
115 /// segment or even a point.
116 
118 {
119  Int_t N = pin.size();
120 
121  // Find the minimum (bottom-left) point.
122  Int_t min_point = 0;
123  for (Int_t i = 1; i < N; ++i)
124  {
125  if (pin[i].fY < pin[min_point].fY || (pin[i].fY == pin[min_point].fY && pin[i].fX < pin[min_point].fX))
126  min_point = i;
127  }
128 
129  // Calculate angles and sort.
130  std::vector<Float_t> angles(N);
131  for (Int_t i = 0; i < N; ++i)
132  {
133  angles[i] = (pin[i] - pin[min_point]).Phi();
134  }
135  std::vector<Int_t> idcs(N);
136  TMath::Sort(N, &angles[0], &idcs[0], kFALSE);
137 
138  // Weed out points with the same angle -- keep the furthest only.
139  // The first point must stay.
140  if (N > 2)
141  {
142  std::vector<Int_t> new_idcs;
143  new_idcs.push_back(idcs[0]);
144  std::vector<Int_t>::iterator a, b;
145  a = idcs.begin(); ++a;
146  b = a; ++b;
147  while (b != idcs.end())
148  {
149  if (TMath::Abs(angles[*a] - angles[*b]) < 1e-5f)
150  {
151  if (pin[idcs[0]].SquareDistance(pin[*a]) < pin[idcs[0]].SquareDistance(pin[*b]))
152  a = b;
153  }
154  else
155  {
156  new_idcs.push_back(*a);
157  a = b;
158  }
159  ++b;
160  }
161  new_idcs.push_back(*a);
162  idcs.swap(new_idcs);
163  }
164 
165  N = idcs.size();
166 
167  // Find hull.
168  std::vector<Int_t> hull;
169  if (N > 2)
170  {
171  hull.push_back(idcs[0]);
172  hull.push_back(idcs[1]);
173  hull.push_back(idcs[2]);
174  {
175  Int_t i = 3;
176  while (i < N)
177  {
178  Int_t n = hull.size() - 1;
179  if ((pin[hull[n]] - pin[hull[n-1]]).Cross(pin[idcs[i]] - pin[hull[n]]) > 0)
180  {
181  hull.push_back(idcs[i]);
182  ++i;
183  }
184  else
185  {
186  hull.pop_back();
187  }
188  }
189  }
190  }
191  else
192  {
193  ::Warning("TEveShape::FindConvexHull()", "Polygon reduced to %d points. for '%s'.",
194  N, caller ? caller->GetElementName() : "unknown");
195  hull.swap(idcs);
196  }
197 
198  // Add hull points into the output vector.
199  N = hull.size();
200  Int_t Nold = pout.size();
201  pout.resize(Nold + N);
202  for (Int_t i = 0; i < N; ++i)
203  {
204  pout[Nold + i] = pin[hull[i]];
205  }
206 
207  // Print the hull.
208  // for (Int_t i = 0; i < N; ++i)
209  // {
210  // const TEveVector2 &p = pin[hull[i]];
211  // printf("%d [%d] (%5.1f, %5.1f) %f\n", i, hull[i], p.fX, p.fY, angles[hull[i]]);
212  // }
213 
214  return N;
215 }
216 
217 ////////////////////////////////////////////////////////////////////////////////
218 /// Checks if the first face normal is pointing into the other
219 /// direction as the vector pointing towards the opposite face.
220 /// This assumes standard box vertex arrangement.
221 
223 {
224  TEveVector f1 = box[1] - box[0];
225  TEveVector f2 = box[3] - box[0];
226  TEveVector up = box[4] - box[0];
227 
228  return up.Dot(f1.Cross(f2)) < 0;
229 }
230 
231 ////////////////////////////////////////////////////////////////////////////////
232 /// Checks if the first face normal is pointing into the other
233 /// direction as the vector pointing towards the opposite face.
234 /// This assumes standard box vertex arrangement.
235 
237 {
238  TEveVector b0(box[0]);
239  TEveVector f1(box[1]); f1 -= b0;
240  TEveVector f2(box[3]); f2 -= b0;
241  TEveVector up(box[4]); up -= b0;
242 
243  return up.Dot(f1.Cross(f2)) < 0;
244 }
245 
246 ////////////////////////////////////////////////////////////////////////////////
247 /// Make sure box orientation is consistent with standard arrangement.
248 
250 {
251  if ( ! IsBoxOrientationConsistentEv(box))
252  {
253  std::swap(box[1], box[3]);
254  std::swap(box[5], box[7]);
255  }
256 }
257 
258 ////////////////////////////////////////////////////////////////////////////////
259 /// Make sure box orientation is consistent with standard arrangement.
260 
262 {
263  if ( ! IsBoxOrientationConsistentFv(box))
264  {
265  std::swap(box[1][0], box[3][0]);
266  std::swap(box[1][1], box[3][1]);
267  std::swap(box[1][2], box[3][2]);
268  std::swap(box[5][0], box[7][0]);
269  std::swap(box[5][1], box[7][1]);
270  std::swap(box[5][2], box[7][2]);
271  }
272 }
Abstract base-class for 2D/3D shapes.
Definition: TEveShape.h:22
std::vector< TEveVector2 > vVector2_t
Definition: TEveShape.h:33
float Float_t
Definition: RtypesCore.h:53
const char Option_t
Definition: RtypesCore.h:62
Bool_t fCanEditMainColor
Definition: TEveElement.h:92
Color_t fFillColor
Definition: TEveShape.h:37
void swap(ROOT::THist< DIMENSIONS, PRECISION > &a, ROOT::THist< DIMENSIONS, PRECISION > &b) noexcept
Swap two histograms.
Definition: THist.h:196
#define N
TT Dot(const TEveVectorT &a) const
Definition: TEveVector.h:138
virtual void PaintStandard(TObject *id)
Paint object – a generic implementation for EVE elements.
virtual void CopyVizParams(const TEveElement *el)
Copy visualization parameters from element el.
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
Bool_t fHighlightFrame
Definition: TEveShape.h:42
virtual const char * GetElementName() const
Virtual function for retrieving name of the element.
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
static const char * ToString(Bool_t b)
Convert Bool_t to string - kTRUE or kFALSE.
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
Float_t fLineWidth
Definition: TEveShape.h:39
void SetMainColorPtr(Color_t *color)
Definition: TEveElement.h:267
A list of TEveElements.
Definition: TEveElement.h:459
static void CheckAndFixBoxOrientationFv(Float_t box[8][3])
Make sure box orientation is consistent with standard arrangement.
Definition: TEveShape.cxx:261
Bool_t fCanEditMainTransparency
Definition: TEveElement.h:93
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Definition: TMath.h:1002
virtual void WriteVizParams(std::ostream &out, const TString &var)
Write visualization parameters.
Definition: TEveShape.cxx:89
virtual void SetMainColor(Color_t color)
Set main color.
Definition: TEveShape.cxx:58
TEveVectorT Cross(const TEveVectorT &a) const
Definition: TEveVector.h:145
virtual ~TEveShape()
Destructor.
Definition: TEveShape.cxx:49
char * out
Definition: TBase64.cxx:29
short Color_t
Definition: RtypesCore.h:79
virtual void Paint(Option_t *option="")
Paint this object. Only direct rendering is supported.
Definition: TEveShape.cxx:104
TMarker * m
Definition: textangle.C:8
void StampObjProps()
Definition: TEveElement.h:397
static Bool_t IsBoxOrientationConsistentFv(const Float_t box[8][3])
Checks if the first face normal is pointing into the other direction as the vector pointing towards t...
Definition: TEveShape.cxx:236
virtual void SetMainColor(Color_t color)
Set main color of the element.
TEveShape(const TEveShape &)
Bool_t fDrawFrame
Definition: TEveShape.h:41
double f(double x)
virtual void CopyVizParams(const TEveElement *el)
Copy visualization parameters from element el.
Definition: TEveShape.cxx:70
double f2(const double *x)
virtual void WriteVizParams(std::ostream &out, const TString &var)
Write-out visual parameters for this object.
TF1 * f1
Definition: legend1.C:11
ClassImp(TEveShape)
Bool_t fMiniFrame
Definition: TEveShape.h:43
Color_t fLineColor
Definition: TEveShape.h:38
TGLVector3 Cross(const TGLVector3 &v1, const TGLVector3 &v2)
Definition: TGLUtil.h:328
static Int_t FindConvexHull(const vVector2_t &pin, vVector2_t &pout, TEveElement *caller=0)
Determines the convex-hull of points in pin.
Definition: TEveShape.cxx:117
const Bool_t kTRUE
Definition: Rtypes.h:91
static Bool_t IsBoxOrientationConsistentEv(const TEveVector box[8])
Checks if the first face normal is pointing into the other direction as the vector pointing towards t...
Definition: TEveShape.cxx:222
static void CheckAndFixBoxOrientationEv(TEveVector box[8])
Make sure box orientation is consistent with standard arrangement.
Definition: TEveShape.cxx:249
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition: TEveElement.h:33
const Int_t n
Definition: legend1.C:16
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904