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();
90 fRenderData = std::make_unique<REveRenderData>(
"makePolygonSetProjected", 3 *
fPnts.size());
93 Int_t n_poly_info = 0;
94 for (
auto &p :
fPols) n_poly_info += 1 + p.NPoints();
96 std::vector<Double_t> verts;
97 verts.reserve(3 *
fPnts.size());
98 std::vector<UInt_t>
polys;
99 polys.reserve(n_poly_info);
101 for (
auto &p :
fPols)
103 polys.emplace_back(p.NPoints());
104 polys.insert(
polys.end(), p.fPnts.begin(), p.fPnts.end());
107 for (
unsigned i = 0; i <
fPnts.size(); ++i)
109 verts.push_back(
fPnts[i].fX);
110 verts.push_back(
fPnts[i].fY);
111 verts.push_back(
fPnts[i].fZ);
126 Int_t n_idxbuff = 2 + 3 * n_trings + n_pols + n_poly_info;
129 assert(n_trings * 4 == (
int)
polys.size());
134 for (
int i = 0; i < n_trings; ++i)
142 for (
auto &p :
fPols)
157 if (
fPnts.size() > 0) {
159 for (
unsigned pi = 0; pi <
fPnts.size(); ++pi)
186 for (
unsigned i = 0; i <
fPnts.size(); ++i)
221 std::vector<REveVector> pnts; pnts.resize(buffN);
222 for (
Int_t i = 0; i < buffN; ++i)
224 pnts[i].Set(
fBuff->fPnts[3*i],
fBuff->fPnts[3*i+1],
fBuff->fPnts[3*i+2]);
225 projection->
ProjectPoint(pnts[i].fX, pnts[i].fY, pnts[i].fZ, 0,
230 std::vector<UInt_t> idxMap;
231 idxMap.resize(buffN);
238 for (
Int_t k = 0; k < npoints; ++k)
257 fPnts.resize(npoints);
258 for (
Int_t idx = 0; idx < npoints; ++idx)
263 fPnts[idx].Set(pnts[i]);
276 if (pp.size() <= 2)
return 0;
278 Float_t bbox[4] = { 1e6, -1e6, 1e6, -1e6 };
281 if (
fPnts[idx].fX < bbox[0]) bbox[0] =
fPnts[idx].fX;
282 if (
fPnts[idx].fX > bbox[1]) bbox[1] =
fPnts[idx].fX;
284 if (
fPnts[idx].fY < bbox[2]) bbox[2] =
fPnts[idx].fY;
285 if (
fPnts[idx].fY > bbox[3]) bbox[3] =
fPnts[idx].fY;
288 if ((bbox[1]-bbox[0]) < eps || (bbox[3]-bbox[2]) < eps)
return 0;
291 for (
auto &&refP : pols)
293 if ((
Int_t) pp.size() != refP.NPoints())
296 int start_idx = refP.FindPoint(pp.front());
299 if (++start_idx >= refP.NPoints()) start_idx = 0;
303 auto u = ++pp.begin();
304 Int_t pidx = start_idx;
305 while (u != pp.end())
307 if ((*u) != refP.fPnts[pidx])
310 if (++pidx >= refP.NPoints()) pidx = 0;
312 if (u == pp.end())
return 0;
317 Int_t pidx = start_idx;
318 while (u != pp.begin())
320 if ((*u) != refP.fPnts[pidx])
323 if (++pidx >= refP.NPoints()) pidx = 0;
325 if (u == pp.begin())
return 0;
329 std::vector<UInt_t> pv(pp.size(), 0);
331 for (
auto &&u : pp) {
335 pols.emplace_back(std::move(pv));
337 return (bbox[1]-bbox[0]) * (bbox[3]-bbox[2]);
350 std::list<UInt_t> pp;
352 Int_t *seg = &bpols[2];
357 head = idxMap[
fBuff->fSegs[3*seg[0] + 1]];
358 tail = idxMap[
fBuff->fSegs[3*seg[0] + 2]];
362 head = idxMap[
fBuff->fSegs[3*seg[0] + 2]];
363 tail = idxMap[
fBuff->fSegs[3*seg[0] + 1]];
365 pp.emplace_back(head);
368 for (
UInt_t s = 1; s < segN; ++s)
369 segs.emplace_back(
fBuff->fSegs[3*seg[s] + 1],
fBuff->fSegs[3*seg[s] + 2]);
373 UInt_t mv1 = idxMap[it.fV1];
374 UInt_t mv2 = idxMap[it.fV2];
381 if (tail != pp.back()) pp.push_back(tail);
382 tail = (mv1 == tail) ? mv2 : mv1;
388 if (pp.front() == pp.back()) pp.pop_front();
411 vo1 =
fBuff->fSegs[3*s + 1];
412 vo2 =
fBuff->fSegs[3*s + 2];
415 if (vor1 == vor2)
continue;
417 for (
auto &seg:
segs)
421 if((vv1 == vor1 && vv2 == vor2) || (vv1 == vor2 && vv2 == vor1))
428 segs.emplace_back(vor1, vor2);
431 while (!
segs.empty())
433 std::list<UInt_t> pp;
434 pp.push_back(
segs.front().fV1);
438 while (match && !
segs.empty())
440 for (
auto k =
segs.begin(); k !=
segs.end(); ++k)
444 if (cv1 == tail || cv2 == tail)
446 pp.emplace_back(tail);
447 tail = (cv1 == tail) ? cv2 : cv1;
457 if (tail == pp.front())
489 if (surfBS < surfBP) {
511 for (
Int_t i = 0; i < nPnts - 1; ++i)
525 printf(
"REvePolygonSetProjected %d polygons\n", (
Int_t)
fPols.size());
527 for (
auto &pol :
fPols)
529 Int_t nPnts = pol.NPoints();
530 printf(
"Points of polygon %d [Np = %d]:\n", ++cnt, nPnts);
531 for (
Int_t vi = 0; vi<nPnts; ++vi) {
532 Int_t pi = pol.fPnts[vi];
549 printf(
"%d polygon of %d has %d segments \n", pi,
fBuff->NbPols(), segN);
551 Int_t* seg = &bpols[2];
556 printf(
"(%d, %d) \n", a1, a2);
557 printf(
"ORIG points :(%f, %f, %f) (%f, %f, %f)\n",
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
Externally assigned and controlled user data.
virtual std::unique_ptr< TBuffer3D > MakeBuffer3D()
Create a TBuffer3D suitable for presentation of the shape.
virtual ~REvePolygonSetProjected()
Destructor.
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
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)
Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
basic_json< std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator, adl_serializer, std::vector< std::uint8_t > > json
std::vector< UInt_t > fPnts