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
27
28////////////////////////////////////////////////////////////////////////////////
29/// Constructor.
30
31TEveShape::TEveShape(const char* n, const char* t) :
33 fFillColor(5),
34 fLineColor(5),
35 fLineWidth(1),
36 fDrawFrame(kTRUE),
37 fHighlightFrame(kFALSE),
38 fMiniFrame(kTRUE)
39{
43}
44
45////////////////////////////////////////////////////////////////////////////////
46/// Destructor.
47
51
52////////////////////////////////////////////////////////////////////////////////
53/// Set main color.
54/// Override so that line-color can also be changed if it is equal
55/// to fill color (which is treated as main color).
56
58{
59 if (fFillColor == fLineColor) {
60 fLineColor = color;
62 }
64}
65
66////////////////////////////////////////////////////////////////////////////////
67/// Copy visualization parameters from element el.
68
70{
71 const TEveShape* m = dynamic_cast<const TEveShape*>(el);
72 if (m)
73 {
74 fFillColor = m->fFillColor;
75 fLineColor = m->fLineColor;
76 fLineWidth = m->fLineWidth;
77 fDrawFrame = m->fDrawFrame;
78 fHighlightFrame = m->fHighlightFrame;
79 fMiniFrame = m->fMiniFrame;
80 }
81
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// Write visualization parameters.
87
88void TEveShape::WriteVizParams(std::ostream& out, const TString& var)
89{
91
92 TString t = " " + var + "->";
93 out << t << "SetFillColor(" << fFillColor << ");\n";
94 out << t << "SetLineColor(" << fLineColor << ");\n";
95 out << t << "SetLineWidth(" << fLineWidth << ");\n";
96 out << t << "SetDrawFrame(" << ToString(fDrawFrame) << ");\n";
97 out << t << "SetHighlightFrame(" << ToString(fHighlightFrame) << ");\n";
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Paint this object. Only direct rendering is supported.
102
104{
105 PaintStandard(this);
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Determines the convex-hull of points in pin.
110///
111/// Adds the hull points to pout and returns the number of added points.
112/// If size of pout is less then 3 then either the number of input points
113/// was too low or they were degenerate so that the hull is actually a line
114/// segment or even a point.
115
117{
118 Int_t N = pin.size();
119
120 // Find the minimum (bottom-left) point.
121 Int_t min_point = 0;
122 for (Int_t i = 1; i < N; ++i)
123 {
124 if (pin[i].fY < pin[min_point].fY || (pin[i].fY == pin[min_point].fY && pin[i].fX < pin[min_point].fX))
125 min_point = i;
126 }
127
128 // Calculate angles and sort.
129 std::vector<Float_t> angles(N);
130 for (Int_t i = 0; i < N; ++i)
131 {
132 angles[i] = (pin[i] - pin[min_point]).Phi();
133 }
134 std::vector<Int_t> idcs(N);
135 TMath::Sort(N, &angles[0], &idcs[0], kFALSE);
136
137 // Weed out points with the same angle -- keep the furthest only.
138 // The first point must stay.
139 if (N > 2)
140 {
141 std::vector<Int_t> new_idcs;
142 new_idcs.push_back(idcs[0]);
143 std::vector<Int_t>::iterator a, b;
144 a = idcs.begin(); ++a;
145 b = a; ++b;
146 while (b != idcs.end())
147 {
148 if (TMath::Abs(angles[*a] - angles[*b]) < 1e-5f)
149 {
150 if (pin[idcs[0]].SquareDistance(pin[*a]) < pin[idcs[0]].SquareDistance(pin[*b]))
151 a = b;
152 }
153 else
154 {
155 new_idcs.push_back(*a);
156 a = b;
157 }
158 ++b;
159 }
160 new_idcs.push_back(*a);
161 idcs.swap(new_idcs);
162 }
163
164 N = idcs.size();
165
166 // Find hull.
167 std::vector<Int_t> hull;
168 if (N > 2)
169 {
170 hull.push_back(idcs[0]);
171 hull.push_back(idcs[1]);
172 hull.push_back(idcs[2]);
173 {
174 Int_t i = 3;
175 while (i < N)
176 {
177 Int_t n = hull.size() - 1;
178 if ((pin[hull[n]] - pin[hull[n-1]]).Cross(pin[idcs[i]] - pin[hull[n]]) > 0)
179 {
180 hull.push_back(idcs[i]);
181 ++i;
182 }
183 else
184 {
185 hull.pop_back();
186 }
187 }
188 }
189 }
190 else
191 {
192 ::Warning("TEveShape::FindConvexHull()", "Polygon reduced to %d points. for '%s'.",
193 N, caller ? caller->GetElementName() : "unknown");
194 hull.swap(idcs);
195 }
196
197 // Add hull points into the output vector.
198 N = hull.size();
199 Int_t Nold = pout.size();
200 pout.resize(Nold + N);
201 for (Int_t i = 0; i < N; ++i)
202 {
203 pout[Nold + i] = pin[hull[i]];
204 }
205
206 // Print the hull.
207 // for (Int_t i = 0; i < N; ++i)
208 // {
209 // const TEveVector2 &p = pin[hull[i]];
210 // printf("%d [%d] (%5.1f, %5.1f) %f\n", i, hull[i], p.fX, p.fY, angles[hull[i]]);
211 // }
212
213 return N;
214}
215
216////////////////////////////////////////////////////////////////////////////////
217/// Checks if the first face normal is pointing into the other
218/// direction as the vector pointing towards the opposite face.
219/// This assumes standard box vertex arrangement.
220
222{
223 TEveVector f1 = box[1] - box[0];
224 TEveVector f2 = box[3] - box[0];
225 TEveVector up = box[4] - box[0];
226
227 return up.Dot(f1.Cross(f2)) < 0;
228}
229
230////////////////////////////////////////////////////////////////////////////////
231/// Checks if the first face normal is pointing into the other
232/// direction as the vector pointing towards the opposite face.
233/// This assumes standard box vertex arrangement.
234
236{
237 TEveVector b0(box[0]);
238 TEveVector f1(box[1]); f1 -= b0;
239 TEveVector f2(box[3]); f2 -= b0;
240 TEveVector up(box[4]); up -= b0;
241
242 return up.Dot(f1.Cross(f2)) < 0;
243}
244
245////////////////////////////////////////////////////////////////////////////////
246/// Make sure box orientation is consistent with standard arrangement.
247
249{
251 {
252 std::swap(box[1], box[3]);
253 std::swap(box[5], box[7]);
254 }
255}
256
257////////////////////////////////////////////////////////////////////////////////
258/// Make sure box orientation is consistent with standard arrangement.
259
261{
263 {
264 std::swap(box[1][0], box[3][0]);
265 std::swap(box[1][1], box[3][1]);
266 std::swap(box[1][2], box[3][2]);
267 std::swap(box[5][0], box[7][0]);
268 std::swap(box[5][1], box[7][1]);
269 std::swap(box[5][2], box[7][2]);
270 }
271}
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
short Color_t
Color number (short)
Definition RtypesCore.h:99
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define N
TGLVector3 Cross(const TGLVector3 &v1, const TGLVector3 &v2)
Definition TGLUtil.h:323
const_iterator begin() const
const_iterator end() const
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 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
~TEveShape() override
Destructor.
Definition TEveShape.cxx:48
void SetMainColor(Color_t color) override
Set main color.
Definition TEveShape.cxx:57
void WriteVizParams(std::ostream &out, const TString &var) override
Write visualization parameters.
Definition TEveShape.cxx:88
TEveShape(const TEveShape &)=delete
Color_t fFillColor
Definition TEveShape.h:38
Bool_t fDrawFrame
Definition TEveShape.h:42
Bool_t fHighlightFrame
Definition TEveShape.h:43
static void CheckAndFixBoxOrientationFv(Float_t box[8][3])
Make sure box orientation is consistent with standard arrangement.
static void CheckAndFixBoxOrientationEv(TEveVector box[8])
Make sure box orientation is consistent with standard arrangement.
std::vector< TEveVector2 > vVector2_t
Definition TEveShape.h:34
Float_t fLineWidth
Definition TEveShape.h:40
void CopyVizParams(const TEveElement *el) override
Copy visualization parameters from element el.
Definition TEveShape.cxx:69
static Int_t FindConvexHull(const vVector2_t &pin, vVector2_t &pout, TEveElement *caller=nullptr)
Determines the convex-hull of points in pin.
void Paint(Option_t *option="") override
Paint this object. Only direct rendering is supported.
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...
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
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
Basic string class.
Definition TString.h:138
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)
Sort the n elements of the array a of generic templated type Element.
Definition TMathBase.h:432
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:124
TMarker m
Definition textangle.C:8