Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveShape.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Author: Matevz Tadel, 2010
3
4/*************************************************************************
5 * Copyright (C) 1995-2019, 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 <ROOT/REveShape.hxx>
13
14using namespace ROOT::Experimental;
15
16/** \class REveShape
17\ingroup REve
18Abstract base-class for 2D/3D shapes.
19
20It provides:
21 - fill color / transparency, accessible via Get/SetMainColor/Transparency;
22 - frame line color / width;
23 - flag if frame should be drawn;
24 - flag specifying whether frame or whole shape should be emphasised for
25 highlight.
26*/
27
28////////////////////////////////////////////////////////////////////////////////
29/// Constructor.
30
31REveShape::REveShape(const std::string &n, const std::string &t) :
32 REveElement(n, 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
49{
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Fill core part of JSON representation.
54
55Int_t REveShape::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
56{
57 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
58
59 j["fFillColor"] = fFillColor;
60 j["fLineColor"] = fLineColor;
61 j["fLineWidth"] = fLineWidth;
62 j["fDrawFrame"] = fDrawFrame;
63
64 return ret;
65}
66
67////////////////////////////////////////////////////////////////////////////////
68/// Set main color.
69/// Override so that line-color can also be changed if it is equal
70/// to fill color (which is treated as main color).
71
73{
74 if (fFillColor == fLineColor) {
75 fLineColor = color;
77 }
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Copy visualization parameters from element el.
83
85{
86 const REveShape* m = dynamic_cast<const REveShape*>(el);
87 if (m)
88 {
90 fLineColor = m->fLineColor;
91 fLineWidth = m->fLineWidth;
92 fDrawFrame = m->fDrawFrame;
93 fHighlightFrame = m->fHighlightFrame;
94 fMiniFrame = m->fMiniFrame;
95 }
96
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Write visualization parameters.
102
103void REveShape::WriteVizParams(std::ostream& out, const TString& var)
104{
106
107 TString t = " " + var + "->";
108 out << t << "SetFillColor(" << fFillColor << ");\n";
109 out << t << "SetLineColor(" << fLineColor << ");\n";
110 out << t << "SetLineWidth(" << fLineWidth << ");\n";
111 out << t << "SetDrawFrame(" << ToString(fDrawFrame) << ");\n";
112 out << t << "SetHighlightFrame(" << ToString(fHighlightFrame) << ");\n";
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Determines the convex-hull of points in pin.
117///
118/// Adds the hull points to pout and returns the number of added points.
119/// If size of pout is less then 3 then either the number of input points
120/// was too low or they were degenerate so that the hull is actually a line
121/// segment or even a point.
122
124{
125 Int_t N = pin.size();
126
127 // Find the minimum (bottom-left) point.
128 Int_t min_point = 0;
129 for (Int_t i = 1; i < N; ++i)
130 {
131 if (pin[i].fY < pin[min_point].fY || (pin[i].fY == pin[min_point].fY && pin[i].fX < pin[min_point].fX))
132 min_point = i;
133 }
134
135 // Calculate angles and sort.
136 std::vector<Float_t> angles(N);
137 for (Int_t i = 0; i < N; ++i)
138 {
139 angles[i] = (pin[i] - pin[min_point]).Phi();
140 }
141 std::vector<Int_t> idcs(N);
142 TMath::Sort(N, &angles[0], &idcs[0], kFALSE);
143
144 // Weed out points with the same angle -- keep the furthest only.
145 // The first point must stay.
146 if (N > 2)
147 {
148 std::vector<Int_t> new_idcs;
149 new_idcs.push_back(idcs[0]);
150 auto a = idcs.begin(); ++a;
151 auto b = a; ++b;
152 while (b != idcs.end())
153 {
154 if (TMath::Abs(angles[*a] - angles[*b]) < 1e-5f)
155 {
156 if (pin[idcs[0]].SquareDistance(pin[*a]) < pin[idcs[0]].SquareDistance(pin[*b]))
157 a = b;
158 }
159 else
160 {
161 new_idcs.push_back(*a);
162 a = b;
163 }
164 ++b;
165 }
166 new_idcs.push_back(*a);
167 idcs.swap(new_idcs);
168 }
169
170 N = idcs.size();
171
172 // Find hull.
173 std::vector<Int_t> hull;
174 if (N > 2)
175 {
176 hull.push_back(idcs[0]);
177 hull.push_back(idcs[1]);
178 hull.push_back(idcs[2]);
179 {
180 Int_t i = 3;
181 while (i < N)
182 {
183 Int_t n = hull.size() - 1;
184 if ((pin[hull[n]] - pin[hull[n-1]]).Cross(pin[idcs[i]] - pin[hull[n]]) > 0)
185 {
186 hull.push_back(idcs[i]);
187 ++i;
188 }
189 else
190 {
191 hull.pop_back();
192 }
193 }
194 }
195 }
196 else
197 {
198 ::Warning("REveShape::FindConvexHull()", "Polygon reduced to %d points. for '%s'.",
199 N, caller ? caller->GetCName() : "unknown");
200 hull.swap(idcs);
201 }
202
203 // Add hull points into the output vector.
204 N = hull.size();
205 Int_t Nold = pout.size();
206 pout.resize(Nold + N);
207 for (Int_t i = 0; i < N; ++i)
208 {
209 pout[Nold + i] = pin[hull[i]];
210 }
211
212 // Print the hull.
213 // for (Int_t i = 0; i < N; ++i)
214 // {
215 // const REveVector2 &p = pin[hull[i]];
216 // printf("%d [%d] (%5.1f, %5.1f) %f\n", i, hull[i], p.fX, p.fY, angles[hull[i]]);
217 // }
218
219 return N;
220}
221
222////////////////////////////////////////////////////////////////////////////////
223/// Checks if the first face normal is pointing into the other
224/// direction as the vector pointing towards the opposite face.
225/// This assumes standard box vertex arrangement.
226
228{
229 REveVector f1 = box[1] - box[0];
230 REveVector f2 = box[3] - box[0];
231 REveVector up = box[4] - box[0];
232
233 return up.Dot(f1.Cross(f2)) < 0;
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// Checks if the first face normal is pointing into the other
238/// direction as the vector pointing towards the opposite face.
239/// This assumes standard box vertex arrangement.
240
242{
243 REveVector b0(box[0]);
244 REveVector f1(box[1]); f1 -= b0;
245 REveVector f2(box[3]); f2 -= b0;
246 REveVector up(box[4]); up -= b0;
247
248 return up.Dot(f1.Cross(f2)) < 0;
249}
250
251////////////////////////////////////////////////////////////////////////////////
252/// Make sure box orientation is consistent with standard arrangement.
253
255{
257 {
258 std::swap(box[1], box[3]);
259 std::swap(box[5], box[7]);
260 }
261}
262
263////////////////////////////////////////////////////////////////////////////////
264/// Make sure box orientation is consistent with standard arrangement.
265
267{
269 {
270 std::swap(box[1][0], box[3][0]);
271 std::swap(box[1][1], box[3][1]);
272 std::swap(box[1][2], box[3][2]);
273 std::swap(box[5][0], box[7][0]);
274 std::swap(box[5][1], box[7][1]);
275 std::swap(box[5][2], box[7][2]);
276 }
277}
#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
const Bool_t kTRUE
Definition RtypesCore.h:91
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:231
#define N
TGLVector3 Cross(const TGLVector3 &v1, const TGLVector3 &v2)
Definition TGLUtil.h:323
void SetMainColorPtr(Color_t *colptr)
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
const char * GetCName() const
virtual void WriteVizParams(std::ostream &out, const TString &var)
Write-out visual parameters for this object.
static const std::string & ToString(Bool_t b)
Convert Bool_t to string - kTRUE or kFALSE.
virtual void CopyVizParams(const REveElement *el)
Copy visualization parameters from element el.
virtual void SetMainColor(Color_t color)
Set main color of the element.
void WriteVizParams(std::ostream &out, const TString &var) override
Write visualization parameters.
static Int_t FindConvexHull(const vVector2_t &pin, vVector2_t &pout, REveElement *caller=nullptr)
Determines the convex-hull of points in pin.
void CopyVizParams(const REveElement *el) override
Copy visualization parameters from element el.
Definition REveShape.cxx:84
std::vector< REveVector2 > vVector2_t
Definition REveShape.hxx:37
static void CheckAndFixBoxOrientationFv(Float_t box[8][3])
Make sure box orientation is consistent with standard arrangement.
virtual ~REveShape()
Destructor.
Definition REveShape.cxx:48
static Bool_t IsBoxOrientationConsistentEv(const REveVector 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...
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
Definition REveShape.cxx:55
static void CheckAndFixBoxOrientationEv(REveVector box[8])
Make sure box orientation is consistent with standard arrangement.
void SetMainColor(Color_t color) override
Set main color.
Definition REveShape.cxx:72
TT Dot(const REveVectorT &a) const
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