Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <iostream>
14
15/** \class TEveShape
16\ingroup TEve
17Abstract base-class for 2D/3D shapes.
18
19It 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
32TEveShape::TEveShape(const char* n, const char* 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;
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 {
76 fLineColor = m->fLineColor;
77 fLineWidth = m->fLineWidth;
78 fDrawFrame = m->fDrawFrame;
79 fHighlightFrame = m->fHighlightFrame;
80 fMiniFrame = m->fMiniFrame;
81 }
82
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Write visualization parameters.
88
89void 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{
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{
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}
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
const Bool_t kFALSE
Definition RtypesCore.h:92
short Color_t
Definition RtypesCore.h:83
float Float_t
Definition RtypesCore.h:57
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
#define N
TGLVector3 Cross(const TGLVector3 &v1, const TGLVector3 &v2)
Definition TGLUtil.h:323
A list of TEveElements.
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition TEveElement.h:36
void StampObjProps()
Bool_t fCanEditMainTransparency
Definition TEveElement.h:95
virtual void SetMainColor(Color_t color)
Set main color of the element.
void SetMainColorPtr(Color_t *color)
virtual const char * GetElementName() const
Virtual function for retrieving name of the element.
virtual void CopyVizParams(const TEveElement *el)
Copy visualization parameters from element el.
static const char * ToString(Bool_t b)
Convert Bool_t to string - kTRUE or kFALSE.
Bool_t fCanEditMainColor
Definition TEveElement.h:94
virtual void WriteVizParams(std::ostream &out, const TString &var)
Write-out visual parameters for this object.
virtual void PaintStandard(TObject *id)
Paint object – a generic implementation for EVE elements.
Abstract base-class for 2D/3D shapes.
Definition TEveShape.h:26
static Int_t FindConvexHull(const vVector2_t &pin, vVector2_t &pout, TEveElement *caller=0)
Determines the convex-hull of points in pin.
TEveShape(const TEveShape &)=delete
virtual void CopyVizParams(const TEveElement *el)
Copy visualization parameters from element el.
Definition TEveShape.cxx:70
Color_t fFillColor
Definition TEveShape.h:38
Bool_t fDrawFrame
Definition TEveShape.h:42
Bool_t fHighlightFrame
Definition TEveShape.h:43
virtual void WriteVizParams(std::ostream &out, const TString &var)
Write visualization parameters.
Definition TEveShape.cxx:89
static void CheckAndFixBoxOrientationFv(Float_t box[8][3])
Make sure box orientation is consistent with standard arrangement.
virtual ~TEveShape()
Destructor.
Definition TEveShape.cxx:49
static void CheckAndFixBoxOrientationEv(TEveVector box[8])
Make sure box orientation is consistent with standard arrangement.
virtual void SetMainColor(Color_t color)
Set main color.
Definition TEveShape.cxx:58
std::vector< TEveVector2 > vVector2_t
Definition TEveShape.h:34
Float_t fLineWidth
Definition TEveShape.h:40
Color_t fLineColor
Definition TEveShape.h:39
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...
virtual void Paint(Option_t *option="")
Paint this object. Only direct rendering is supported.
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...
Bool_t fMiniFrame
Definition TEveShape.h:44
TT Dot(const TEveVectorT &a) const
Definition TEveVector.h:168
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:879
Basic string class.
Definition TString.h:136
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
const Int_t n
Definition legend1.C:16
TF1 * f1
Definition legend1.C:11
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Definition TMathBase.h:362
Short_t Abs(Short_t d)
Definition TMathBase.h:120
auto * m
Definition textangle.C:8