24#include <nlohmann/json.hpp>
36 Seg_t(
Int_t i1=-1,
Int_t i2=-1) : fV1(i1), fV2(i2) {}
39 typedef std::list<Seg_t> LSeg_t;
54REvePolygonSetProjected::REvePolygonSetProjected(
const std::string &
n,
const std::string &t) :
76 j[
"fNPnts"] =
fPnts.size();
95 fRenderData = std::make_unique<REveRenderData>(
"makePolygonSetProjected", 3 *
fPnts.size());
98 Int_t n_poly_info = 0;
99 for (
auto &
p :
fPols) n_poly_info += 1 +
p.NPoints();
101 std::vector<Double_t> verts;
102 verts.reserve(3 *
fPnts.size());
103 std::vector<UInt_t> polys;
104 polys.reserve(n_poly_info);
108 polys.emplace_back(
p.NPoints());
109 polys.insert(polys.end(),
p.fPnts.begin(),
p.fPnts.end());
112 for (
unsigned i = 0; i <
fPnts.size(); ++i)
114 verts.push_back(
fPnts[i].fX);
115 verts.push_back(
fPnts[i].fY);
116 verts.push_back(
fPnts[i].fZ);
131 Int_t n_idxbuff = 2 + 3 * n_trings + n_pols + n_poly_info;
134 assert(n_trings * 4 == (
int)polys.size());
139 for (
int i = 0; i < n_trings; ++i)
163 for (
unsigned pi = 0; pi <
fPnts.size(); ++pi)
187 for (
unsigned i = 0; i <
fPnts.size(); ++i)
226 std::vector<REveVector> pnts; pnts.resize(buffN);
227 for (
Int_t i = 0; i < buffN; ++i)
232 pnts[i].Set(
p[0],
p[1],
p[2]);
233 projection->
ProjectPoint(pnts[i].fX, pnts[i].fY, pnts[i].fZ, 0,
238 std::vector<UInt_t> idxMap;
239 idxMap.resize(buffN);
246 for (
Int_t k = 0; k < npoints; ++k)
265 fPnts.resize(npoints);
266 for (
Int_t idx = 0; idx < npoints; ++idx)
271 fPnts[idx].Set(pnts[i]);
284 if (pp.size() <= 2)
return 0;
286 Float_t bbox[4] = { 1e6, -1e6, 1e6, -1e6 };
289 if (
fPnts[idx].fX < bbox[0]) bbox[0] =
fPnts[idx].fX;
290 if (
fPnts[idx].fX > bbox[1]) bbox[1] =
fPnts[idx].fX;
292 if (
fPnts[idx].fY < bbox[2]) bbox[2] =
fPnts[idx].fY;
293 if (
fPnts[idx].fY > bbox[3]) bbox[3] =
fPnts[idx].fY;
296 if ((bbox[1]-bbox[0]) < eps || (bbox[3]-bbox[2]) < eps)
return 0;
299 for (
auto &&refP : pols)
301 if ((
Int_t) pp.size() != refP.NPoints())
304 int start_idx = refP.FindPoint(pp.front());
307 if (++start_idx >= refP.NPoints()) start_idx = 0;
311 auto u = ++pp.begin();
312 Int_t pidx = start_idx;
313 while (u != pp.end())
315 if ((*u) != refP.fPnts[pidx])
318 if (++pidx >= refP.NPoints()) pidx = 0;
320 if (u == pp.end())
return 0;
325 Int_t pidx = start_idx;
326 while (u != pp.begin())
328 if ((*u) != refP.fPnts[pidx])
331 if (++pidx >= refP.NPoints()) pidx = 0;
333 if (u == pp.begin())
return 0;
337 std::vector<UInt_t> pv(pp.size(), 0);
339 for (
auto &&u : pp) {
343 pols.emplace_back(std::move(pv));
345 return (bbox[1]-bbox[0]) * (bbox[3]-bbox[2]);
358 std::list<UInt_t> pp;
360 Int_t *seg = &bpols[2];
365 head = idxMap[
fBuff->fSegs[3*seg[0] + 1]];
366 tail = idxMap[
fBuff->fSegs[3*seg[0] + 2]];
370 head = idxMap[
fBuff->fSegs[3*seg[0] + 2]];
371 tail = idxMap[
fBuff->fSegs[3*seg[0] + 1]];
373 pp.emplace_back(head);
376 for (
UInt_t s = 1; s < segN; ++s)
377 segs.emplace_back(
fBuff->fSegs[3*seg[s] + 1],
fBuff->fSegs[3*seg[s] + 2]);
381 UInt_t mv1 = idxMap[it.fV1];
382 UInt_t mv2 = idxMap[it.fV2];
389 if (tail != pp.back()) pp.push_back(tail);
390 tail = (mv1 == tail) ? mv2 : mv1;
396 if (pp.front() == pp.back()) pp.pop_front();
419 vo1 =
fBuff->fSegs[3*s + 1];
420 vo2 =
fBuff->fSegs[3*s + 2];
423 if (vor1 == vor2)
continue;
425 for (
auto &seg: segs)
429 if((vv1 == vor1 && vv2 == vor2) || (vv1 == vor2 && vv2 == vor1))
436 segs.emplace_back(vor1, vor2);
439 while (!segs.empty())
441 std::list<UInt_t> pp;
442 pp.push_back(segs.front().fV1);
443 UInt_t tail = segs.front().fV2;
446 while (match && ! segs.empty())
448 for (
auto k = segs.begin(); k != segs.end(); ++k)
452 if (cv1 == tail || cv2 == tail)
454 pp.emplace_back(tail);
455 tail = (cv1 == tail) ? cv2 : cv1;
465 if (tail == pp.front())
497 if (surfBS < surfBP) {
518 Int_t nPnts =
p.NPoints();
519 for (
Int_t i = 0; i < nPnts - 1; ++i)
533 printf(
"REvePolygonSetProjected %d polygons\n", (
Int_t)
fPols.size());
535 for (
auto &pol :
fPols)
537 Int_t nPnts = pol.NPoints();
538 printf(
"Points of polygon %d [Np = %d]:\n", ++cnt, nPnts);
539 for (
Int_t vi = 0; vi<nPnts; ++vi) {
540 Int_t pi = pol.fPnts[vi];
557 printf(
"%d polygon of %d has %d segments \n", pi,
fBuff->NbPols(), segN);
559 Int_t* seg = &bpols[2];
564 printf(
"(%d, %d) \n", a1, a2);
565 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.
void BBoxCheckPoint(const REveVector &v)
std::unique_ptr< REveRenderData > fRenderData
! Vertex / normal / triangle index information for rendering.
void BBoxInit()
Start filling the bounding box with BBoxCheckPoint(): min at +infinity, max at -infinity,...
virtual std::unique_ptr< TBuffer3D > MakeBuffer3D()
Create a TBuffer3D suitable for presentation of the shape, in the shape's own frame.
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
Fill the bounding box (virtual from REveElement).
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)
Set the depth and stamp el for a rebuild.
REveProjectable * fProjectable
REveProjectionManager * fManager
REveProjectionManager Manager class for steering of projections and managing projected objects.
REveProjection * GetProjection()
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.
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 MultiplyIP(TVector3 &v, Double_t w=1) const
Multiply vector in-place.
Namespace for ROOT features in testing.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.