18#include <TGeoTessellated.h>
32std::vector<int> BuildVertexLoop(
const TBuffer3D&
buf,
33 const std::vector<int>& segs)
36 std::unordered_map<int, std::vector<int>> adj;
39 int a =
buf.fSegs[3 *
s + 1];
40 int b =
buf.fSegs[3 *
s + 2];
46 int start = adj.begin()->first;
50 std::vector<int> loop;
55 const auto& nbrs = adj[curr];
65 if (next == -1 || next ==
start) {
75std::vector<std::vector<int>> ExtractPolygons(
const TBuffer3D&
buf)
77 std::vector<std::vector<int>> polys;
80 for (Int_t ip = 0; ip <
buf.NbPols(); ++ip) {
83 Int_t nseg =
buf.fPols[
idx++];
85 std::vector<int> segs(nseg);
86 for (Int_t
i = 0;
i < nseg; ++
i) {
90 auto verts = BuildVertexLoop(
buf, segs);
91 if (verts.size() >= 3) {
92 polys.push_back(std::move(verts));
99std::vector<std::array<int, 3>>
100 Triangulate(
const std::vector<std::vector<int>>& polys)
102 std::vector<std::array<int, 3>> tris;
103 for (
const auto& poly : polys) {
104 int nv = poly.size();
110 for (
int i = 1;
i < nv - 1; ++
i) {
111 tris.push_back({{
v0, poly[
i], poly[
i + 1]}});
117TGeoTessellated* MakeTessellated(
const TBuffer3D&
buf)
119 auto polys = ExtractPolygons(
buf);
120 auto tris = Triangulate(polys);
122 auto* tess =
new TGeoTessellated(
"tess");
123 const Double_t*
p =
buf.fPnts;
124 for (
auto& t : tris) {
126 TGeoTessellated::Vertex_t{
p[3 * t[0]],
p[3 * t[0] + 1],
p[3 * t[0] + 2]},
127 TGeoTessellated::Vertex_t{
p[3 * t[1]],
p[3 * t[1] + 1],
p[3 * t[1] + 2]},
128 TGeoTessellated::Vertex_t{
p[3 * t[2]],
p[3 * t[2] + 1],
p[3 * t[2] + 2]});
138 auto&
buf = shape->GetBuffer3D(TBuffer3D::kRawSizes | TBuffer3D::kRaw | TBuffer3D::kCore,
false);
139 auto tes = MakeTessellated(
buf);
Collection of utility functions for TGeo.
static TGeoTessellated * TGeoShapeToTGeoTessellated(TGeoShape const *)
< Transform any (primitive) TGeoShape to a tessellated representation
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
GLenum GLuint GLenum GLsizei const GLchar * buf
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...