Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveBox.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 <ROOT/REveBox.hxx>
15#include <ROOT/REveTrans.hxx>
16
17#include "TClass.h"
18
19#include <nlohmann/json.hpp>
20
21using namespace ROOT::Experimental;
22
23/** \class REveBox
24\ingroup REve
253D box with arbitrary vertices (cuboid).
26Vertices 0-3 specify the "bottom" rectangle in clockwise direction and
27vertices 4-7 the "top" rectangle so that 4 is above 0, 5 above 1 and so on.
28
29If vertices are provided some local coordinates the transformation matrix
30of the element should also be set (but then the memory usage is increased
31by the size of the REveTrans object).
32
33Currently only supports 3D -> 2D projections.
34
35The render data is one entry, `pos`, f32 x 3, the eight vertices in the
36order above, primitive triangles: the client draws the faces with a fixed list
37of indices into the eight, and the frame as the edges of those triangles.
38*/
39
40////////////////////////////////////////////////////////////////////////////////
41/// Constructor.
42
43REveBox::REveBox(const char* n, const char* t) :
44 REveShape(n, t)
45{
46}
47
48////////////////////////////////////////////////////////////////////////////////
49/// Destructor.
50
54
55////////////////////////////////////////////////////////////////////////////////
56/// Set vertex 'i'.
57
59{
60 fVertices[i][0] = x;
61 fVertices[i][1] = y;
62 fVertices[i][2] = z;
63 ResetBBox();
64}
65
66////////////////////////////////////////////////////////////////////////////////
67/// Set vertex 'i'.
68
70{
71 fVertices[i][0] = v[0];
72 fVertices[i][1] = v[1];
73 fVertices[i][2] = v[2];
74 ResetBBox();
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// Set vertices.
79
81{
82 memcpy(fVertices, vs, sizeof(fVertices));
83 ResetBBox();
84}
85
86
87////////////////////////////////////////////////////////////////////////////////
88/// Compute bounding-box of the data.
89
91{
93
94 BBoxInit();
95 for (Int_t i=0; i<8; ++i)
96 {
98 }
99}
100
101
102////////////////////////////////////////////////////////////////////////////////
103/// Fill core part of JSON representation.
104
105Int_t REveBox::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
106{
107 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
108
109 j["fMainColor"] = GetFillColor();
110 j["fLineColor"] = GetLineColor();
111
112 return ret;
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Write the render data entry `pos`, see the class description.
117
119{
120 using RD = REveRenderData;
121 fRenderData = std::make_unique<RD>("makeBox");
122 fRenderData->NewEntry("pos", RD::EType::kF32, 3)
123 .Role(RD::ERole::kVertex)
124 .Prim(RD::EPrim::kTriangles)
125 .Push(&fVertices[0][0], 8 * 3);
126}
127
128
129////////////////////////////////////////////////////////////////////////////////
130/// Virtual from REveProjectable, return REveBoxProjected class.
131
133{
134 return TClass::GetClass<REveBoxProjected>();
135}
136
137/** \class REveBoxProjected
138\ingroup REve
139Projection of REveBox.
140
141The projected box is the convex hull of the projected vertices, or, when the
142projection splits the space in two (RhoZ), one hull per sub-space; fBreakIdx is
143the index of the first point of the second hull, zero when there is one.
144
145The render data is one entry, `pos`, f32 x 3, the hull points (x, y, depth) in
146order, primitive triangles: the client fans each hull into triangles, splitting
147the points at fBreakIdx, which the core JSON carries.
148*/
149
150////////////////////////////////////////////////////////////////////////////////
151/// Constructor.
152
153REveBoxProjected::REveBoxProjected(const char* n, const char* t) :
154 REveShape(n, t),
155 fBreakIdx(0),
156 fDebugCornerPoints(false)
157{
158}
159
160////////////////////////////////////////////////////////////////////////////////
161/// Destructor.
162
166
167////////////////////////////////////////////////////////////////////////////////
168/// Fill the bounding box (virtual from REveElement).
169
171{
172 BBoxInit();
173 for (auto &pnt: fPoints)
174 BBoxCheckPoint(pnt.fX, pnt.fY, fDepth);
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// This is virtual method from base-class REveProjected.
179
184
185////////////////////////////////////////////////////////////////////////////////
186/// This is virtual method from base-class REveProjected.
187
193
194////////////////////////////////////////////////////////////////////////////////
195/// Re-project the box. Projects all points and finds 2D convex-hull.
196///
197/// The only issue is with making sure that initial conditions for
198/// hull-search are reasonable -- that is, there are no overlaps with the
199/// first point.
200
202{
203 REveBox *box = dynamic_cast<REveBox*>(fProjectable);
204
205 fDebugPoints.clear();
206
207 // Project points in global CS, remove overlaps.
208 vVector2_t pp[2];
209 {
210 REveProjection *projection = fManager->GetProjection();
211 REveTrans mt;
212 const REveTrans *trans = fManager->GetModelTrans(box, mt);
213
214 REveVector pbuf;
215 for (Int_t i = 0; i < 8; ++i)
216 {
217 projection->ProjectPointfv(trans, box->GetVertex(i), pbuf, fDepth);
218 vVector2_t& ppv = pp[projection->SubSpaceId(pbuf)];
219
220 REveVector2 p(pbuf);
221 Bool_t overlap = kFALSE;
222 for (auto &j: ppv)
223 {
224 if (p.SquareDistance(j) < REveProjection::fgEpsSqr)
225 {
226 overlap = kTRUE;
227 break;
228 }
229 }
230 if (! overlap)
231 {
232 ppv.push_back(p);
234 fDebugPoints.push_back(p);
235 }
236 }
237 }
238
239 fPoints.clear();
240 fBreakIdx = 0;
241
242 if ( ! pp[0].empty())
243 {
244 FindConvexHull(pp[0], fPoints, this);
245 }
246 if ( ! pp[1].empty())
247 {
248 fBreakIdx = fPoints.size();
249 FindConvexHull(pp[1], fPoints, this);
250 }
251}
252
253////////////////////////////////////////////////////////////////////////////////
254/// Get state of fgDebugCornerPoints static.
255
260
261////////////////////////////////////////////////////////////////////////////////
262/// Set state of fgDebugCornerPoints static.
263/// When this is true, points will be drawn at the corners of
264/// computed convex hull.
265
270
271////////////////////////////////////////////////////////////////////////////////
272/// Write the render data entry `pos`, see the class description. A projected
273/// box of fewer than three points has no area and no render data.
274
276{
277 const int N = fPoints.size();
278 if (N < 3)
279 return;
280
281 using RD = REveRenderData;
282 fRenderData = std::make_unique<RD>("makeBoxProjected");
283 auto &pos =
284 fRenderData->NewEntry("pos", RD::EType::kF32, 3).Role(RD::ERole::kVertex).Prim(RD::EPrim::kTriangles).Reserve(N);
285 for (auto &v : fPoints)
286 pos.Push(v.fX, v.fY, fDepth);
287}
288
289////////////////////////////////////////////////////////////////////////////////
290/// Fill core part of JSON representation. fBreakIdx is an index into the
291/// render data entry `pos`.
292
293Int_t REveBoxProjected::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
294{
295 Int_t ret = REveShape::WriteCoreJson(j, rnr_offset);
296
297 j["fBreakIdx"] = fBreakIdx;
298
299 return ret;
300}
#define d(i)
Definition RSha256.hxx:102
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
#define N
winID h TVirtualViewer3D TVirtualGLPainter p
void BuildRenderData() override
Write the render data entry pos, see the class description.
Definition REveBox.cxx:275
Bool_t GetDebugCornerPoints()
Get state of fgDebugCornerPoints static.
Definition REveBox.cxx:256
~REveBoxProjected() override
Destructor.
Definition REveBox.cxx:163
void SetDepthLocal(Float_t d) override
This is virtual method from base-class REveProjected.
Definition REveBox.cxx:180
void UpdateProjection() override
Re-project the box.
Definition REveBox.cxx:201
void SetDebugCornerPoints(Bool_t d)
Set state of fgDebugCornerPoints static.
Definition REveBox.cxx:266
void ComputeBBox() override
Fill the bounding box (virtual from REveElement).
Definition REveBox.cxx:170
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
Definition REveBox.cxx:293
void SetProjection(REveProjectionManager *mng, REveProjectable *model) override
This is virtual method from base-class REveProjected.
Definition REveBox.cxx:188
REveBoxProjected(const REveBoxProjected &)=delete
~REveBox() override
Destructor.
Definition REveBox.cxx:51
void SetVertex(Int_t i, Float_t x, Float_t y, Float_t z)
Set vertex 'i'.
Definition REveBox.cxx:58
TClass * ProjectedClass(const REveProjection *p) const override
Virtual from REveProjectable, return REveBoxProjected class.
Definition REveBox.cxx:132
void ComputeBBox() override
Compute bounding-box of the data.
Definition REveBox.cxx:90
void BuildRenderData() override
Write the render data entry pos, see the class description.
Definition REveBox.cxx:118
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
Definition REveBox.cxx:105
void SetVertices(const Float_t *vs)
Set vertices.
Definition REveBox.cxx:80
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
void BBoxCheckPoint(const REveVector &v)
std::unique_ptr< REveRenderData > fRenderData
! Render data entries for the client's maker, see REveRenderData.
void BBoxInit()
Start filling the bounding box with BBoxCheckPoint(): min at +infinity, max at -infinity,...
virtual void SetProjection(REveProjectionManager *mng, REveProjectable *model)
Sets projection manager and reference in the projectable object.
void SetDepthCommon(Float_t d, REveElement *el)
Set the depth and stamp el for a rebuild.
REveProjectionManager Manager class for steering of projections and managing projected objects.
const REveTrans * GetModelTrans(REveElement *model, REveTrans &t)
Return the matrix that takes the coordinates of model into the frame of this manager,...
REveProjection Base for specific classes that implement non-linear projections.
void ProjectPointfv(Float_t *v, Float_t d)
Project float array.
virtual Int_t SubSpaceId(const REveVector &) const
Render data of an element: a client maker name and a list of tagged entries, each a typed array with ...
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:82
std::vector< REveVector2 > vVector2_t
Definition REveShape.hxx:34
static void CheckAndFixBoxOrientationFv(Float_t box[8][3])
Make sure box orientation is consistent with standard arrangement.
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
Definition REveShape.cxx:51
REveVector2T A two-vector template without TObject inheritance and virtual functions.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Namespace for ROOT features in testing.
Definition TROOT.h:100