23#include <nlohmann/json.hpp>
35 Seg_t(
Int_t i1=-1,
Int_t i2=-1) : fV1(i1), fV2(i2) {}
38 typedef std::list<Seg_t> LSeg_t;
53REvePolygonSetProjected::REvePolygonSetProjected(
const std::string &
n,
const std::string &t) :
75 j[
"fNPnts"] =
fPnts.size();
94 fRenderData = std::make_unique<REveRenderData>(
"makePolygonSetProjected", 3 *
fPnts.size());
97 Int_t n_poly_info = 0;
98 for (
auto &
p :
fPols) n_poly_info += 1 +
p.NPoints();
100 std::vector<Double_t> verts;
101 verts.reserve(3 *
fPnts.size());
102 std::vector<UInt_t> polys;
103 polys.reserve(n_poly_info);
107 polys.emplace_back(
p.NPoints());
108 polys.insert(polys.end(),
p.fPnts.begin(),
p.fPnts.end());
111 for (
unsigned i = 0; i <
fPnts.size(); ++i)
113 verts.push_back(
fPnts[i].fX);
114 verts.push_back(
fPnts[i].fY);
115 verts.push_back(
fPnts[i].fZ);
130 Int_t n_idxbuff = 2 + 3 * n_trings + n_pols + n_poly_info;
133 assert(n_trings * 4 == (
int)polys.size());
138 for (
int i = 0; i < n_trings; ++i)
161 if (!
fPnts.empty()) {
163 for (
unsigned pi = 0; pi <
fPnts.size(); ++pi)
190 for (
unsigned i = 0; i <
fPnts.size(); ++i)
225 std::vector<REveVector> pnts; pnts.resize(buffN);
226 for (
Int_t i = 0; i < buffN; ++i)
228 pnts[i].Set(
fBuff->fPnts[3*i],
fBuff->fPnts[3*i+1],
fBuff->fPnts[3*i+2]);
229 projection->
ProjectPoint(pnts[i].fX, pnts[i].fY, pnts[i].fZ, 0,
234 std::vector<UInt_t> idxMap;
235 idxMap.resize(buffN);
242 for (
Int_t k = 0; k < npoints; ++k)
261 fPnts.resize(npoints);
262 for (
Int_t idx = 0; idx < npoints; ++idx)
267 fPnts[idx].Set(pnts[i]);
280 if (pp.size() <= 2)
return 0;
282 Float_t bbox[4] = { 1e6, -1e6, 1e6, -1e6 };
285 if (
fPnts[idx].fX < bbox[0]) bbox[0] =
fPnts[idx].fX;
286 if (
fPnts[idx].fX > bbox[1]) bbox[1] =
fPnts[idx].fX;
288 if (
fPnts[idx].fY < bbox[2]) bbox[2] =
fPnts[idx].fY;
289 if (
fPnts[idx].fY > bbox[3]) bbox[3] =
fPnts[idx].fY;
292 if ((bbox[1]-bbox[0]) < eps || (bbox[3]-bbox[2]) < eps)
return 0;
295 for (
auto &&refP : pols)
297 if ((
Int_t) pp.size() != refP.NPoints())
300 int start_idx = refP.FindPoint(pp.front());
303 if (++start_idx >= refP.NPoints()) start_idx = 0;
307 auto u = ++pp.begin();
308 Int_t pidx = start_idx;
309 while (u != pp.end())
311 if ((*u) != refP.fPnts[pidx])
314 if (++pidx >= refP.NPoints()) pidx = 0;
316 if (u == pp.end())
return 0;
321 Int_t pidx = start_idx;
322 while (u != pp.begin())
324 if ((*u) != refP.fPnts[pidx])
327 if (++pidx >= refP.NPoints()) pidx = 0;
329 if (u == pp.begin())
return 0;
333 std::vector<UInt_t> pv(pp.size(), 0);
335 for (
auto &&u : pp) {
339 pols.emplace_back(std::move(pv));
341 return (bbox[1]-bbox[0]) * (bbox[3]-bbox[2]);
354 std::list<UInt_t> pp;
356 Int_t *seg = &bpols[2];
361 head = idxMap[
fBuff->fSegs[3*seg[0] + 1]];
362 tail = idxMap[
fBuff->fSegs[3*seg[0] + 2]];
366 head = idxMap[
fBuff->fSegs[3*seg[0] + 2]];
367 tail = idxMap[
fBuff->fSegs[3*seg[0] + 1]];
369 pp.emplace_back(head);
372 for (
UInt_t s = 1; s < segN; ++s)
373 segs.emplace_back(
fBuff->fSegs[3*seg[s] + 1],
fBuff->fSegs[3*seg[s] + 2]);
377 UInt_t mv1 = idxMap[it.fV1];
378 UInt_t mv2 = idxMap[it.fV2];
385 if (tail != pp.back()) pp.push_back(tail);
386 tail = (mv1 == tail) ? mv2 : mv1;
392 if (pp.front() == pp.back()) pp.pop_front();
415 vo1 =
fBuff->fSegs[3*s + 1];
416 vo2 =
fBuff->fSegs[3*s + 2];
419 if (vor1 == vor2)
continue;
421 for (
auto &seg: segs)
425 if((vv1 == vor1 && vv2 == vor2) || (vv1 == vor2 && vv2 == vor1))
432 segs.emplace_back(vor1, vor2);
435 while (!segs.empty())
437 std::list<UInt_t> pp;
438 pp.push_back(segs.front().fV1);
439 UInt_t tail = segs.front().fV2;
442 while (match && ! segs.empty())
444 for (
auto k = segs.begin(); k != segs.end(); ++k)
448 if (cv1 == tail || cv2 == tail)
450 pp.emplace_back(tail);
451 tail = (cv1 == tail) ? cv2 : cv1;
461 if (tail == pp.front())
493 if (surfBS < surfBP) {
514 Int_t nPnts =
p.NPoints();
515 for (
Int_t i = 0; i < nPnts - 1; ++i)
529 printf(
"REvePolygonSetProjected %d polygons\n", (
Int_t)
fPols.size());
531 for (
auto &pol :
fPols)
533 Int_t nPnts = pol.NPoints();
534 printf(
"Points of polygon %d [Np = %d]:\n", ++cnt, nPnts);
535 for (
Int_t vi = 0; vi<nPnts; ++vi) {
536 Int_t pi = pol.fPnts[vi];
553 printf(
"%d polygon of %d has %d segments \n", pi,
fBuff->NbPols(), segN);
555 Int_t* seg = &bpols[2];
560 printf(
"(%d, %d) \n", a1, a2);
561 printf(
"ORIG points :(%f, %f, %f) (%f, %f, %f)\n",
int Int_t
Signed integer 4 bytes (int)
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char mode
std::vector< UInt_t > & RefPolyDesc()
void ProcessData(const std::vector< Double_t > &verts, const std::vector< UInt_t > &polys, const Int_t n_polys)
ProcessData.
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
std::unique_ptr< REveRenderData > fRenderData
! Vertex / normal / triangle index information for rendering.
virtual std::unique_ptr< TBuffer3D > MakeBuffer3D()
Create a TBuffer3D suitable for presentation of the shape.
void SetProjection(REveProjectionManager *mng, REveProjectable *model) override
This is virtual method from base-class REveProjected.
virtual void DumpPolys() const
Dump information about built polygons.
Bool_t IsFirstIdxHead(Int_t s0, Int_t s1)
Compare the two segments and check if the first index of first segment is starting.
vpPolygon_t fPolsBS
! polygons build from TBuffer3D segments
void BuildRenderData() override
Crates representation for rendering.
void DumpBuffer3D()
Dump information about currently projected buffer.
void UpdateProjection() override
This is virtual method from base-class REveProjected.
std::list< Polygon_t > vpPolygon_t
vpPolygon_t fPolsBP
! polygons build from TBuffer3D polygons
std::vector< UInt_t > ProjectAndReducePoints()
Project and reduce buffer points.
vpPolygon_t fPols
! polygons
std::vector< REveVector > fPnts
! reduced and projected points
void ProjectBuffer3D()
Project current buffer.
Float_t PolygonSurfaceXY(const Polygon_t &poly) const
Calculate XY surface of a polygon.
void ComputeBBox() override
Override of virtual method from TAttBBox.
Float_t MakePolygonsFromBS(std::vector< UInt_t > &idxMap)
Build polygons from the set of buffer segments.
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
void SetDepthLocal(Float_t d) override
Set depth (z-coordinate) of the projected points.
Float_t MakePolygonsFromBP(std::vector< UInt_t > &idxMap)
Build polygons from list of buffer polygons.
std::unique_ptr< TBuffer3D > fBuff
~REvePolygonSetProjected() override
Destructor.
Float_t AddPolygon(std::list< UInt_t > &pp, std::list< Polygon_t > &p)
Check if polygon has dimensions above REveProjection::fgEps and add it to a list if it is not a dupli...
virtual void SetProjection(REveProjectionManager *mng, REveProjectable *model)
Sets projection manager and reference in the projectable object.
void SetDepthCommon(Float_t d, REveElement *el, Float_t *bbox)
Utility function to update the z-values of the bounding-box.
REveProjectionManager * fManager
REveProjectionManager Manager class for steering of projections and managing projected objects.
REveProjection * GetProjection()
REveProjection Base for specific classes that implement non-linear projections.
virtual void ProjectPoint(Float_t &x, Float_t &y, Float_t &z, Float_t d, EPProc_e p=kPP_Full)=0
EGeoMode_e GetGeoMode() const
virtual Bool_t AcceptSegment(REveVector &, REveVector &, Float_t) const
void CopyVizParams(const REveElement *el) override
Copy visualization parameters from element el.
void BBoxCheckPoint(Float_t x, Float_t y, Float_t z)
void BBoxZero(Float_t epsilon=0, Float_t x=0, Float_t y=0, Float_t z=0)
Create cube of volume (2*epsilon)^3 at (x,y,z).
void BBoxInit(Float_t infinity=1e6)
Allocate and prepare for incremental filling.
Float_t * fBBox
! Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
Namespace for ROOT features in testing.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.