VGM Version 5.3
Loading...
Searching...
No Matches
TessellatedSolid.cxx
Go to the documentation of this file.
1// $Id$
2
3// -----------------------------------------------------------------------
4// The RootGM package of the Virtual Geometry Model
5// Copyright (C) 2007, Ivana Hrivnacova
6// All rights reserved.
7//
8// For the licensing terms see vgm/LICENSE.
9// Contact: ivana@ipno.in2p3.fr
10// -----------------------------------------------------------------------
11
12//
13// Class TessellatedSolid
14// ----------------------
15// VGM implementation for Root Tessellated solid.
16//
17// Author: Ivana Hrivnacova; IJCLab Orsay
18
20#include "RootGM/common/Units.h"
22
24
25#include "TGeoTessellated.h"
26
27#include <cstdlib>
28#include <iostream>
29#include <math.h>
30
31using ROOT::Geom::Vertex_t;
32
33//_____________________________________________________________________________
35 std::vector<std::vector<VGM::ThreeVector> > facets)
36 : VGM::ISolid(), VGM::ITessellatedSolid(), BaseVGM::VTessellatedSolid(),
37 fTessellated(0)
38{
42
43 fTessellated = new TGeoTessellated();
44 fTessellated->SetName(name.data());
45
46 // Add triangular facets
47 //
48 for (Int_t i = 0; i < Int_t(facets.size()); i++) {
49
50 std::vector<VGM::ThreeVector> facet = facets[i];
51
52 // check number of vertices
53 if (facet.size() != 3 && facet.size() != 4) {
54 std::cerr << "+++ Error +++" << std::endl;
55 std::cerr << " Number of vertices in a facet = " << facet.size()
56 << " has to be == 3 or 4" << std::endl;
57 exit(1);
58 }
59
60 if (facet.size() == 3 ) {
61 // Triangular facet
62 VGM::ThreeVector vertex0 = facet[0];
63 VGM::ThreeVector vertex1 = facet[1];
64 VGM::ThreeVector vertex2 = facet[2];
65
66 fTessellated->AddFacet(
67 Vertex_t(vertex0[VGM::kDx] / RootGM::Units::Length(),
69 vertex0[VGM::kDz] / RootGM::Units::Length()),
70 Vertex_t(vertex1[VGM::kDx] / RootGM::Units::Length(),
72 vertex1[VGM::kDz] / RootGM::Units::Length()),
73 Vertex_t(vertex2[VGM::kDx] / RootGM::Units::Length(),
75 vertex2[VGM::kDz] / RootGM::Units::Length()));
76 }
77 else {
78 // Quadrilateral facet
79 VGM::ThreeVector vertex0 = facet[0];
80 VGM::ThreeVector vertex1 = facet[1];
81 VGM::ThreeVector vertex2 = facet[2];
82 VGM::ThreeVector vertex3 = facet[3];
83
84 fTessellated->AddFacet(
85 Vertex_t(vertex0[VGM::kDx] / RootGM::Units::Length(),
87 vertex0[VGM::kDz] / RootGM::Units::Length()),
88 Vertex_t(vertex1[VGM::kDx] / RootGM::Units::Length(),
90 vertex1[VGM::kDz] / RootGM::Units::Length()),
91 Vertex_t(vertex2[VGM::kDx] / RootGM::Units::Length(),
93 vertex2[VGM::kDz] / RootGM::Units::Length()),
94 Vertex_t(vertex3[VGM::kDx] / RootGM::Units::Length(),
96 vertex3[VGM::kDz] / RootGM::Units::Length()));
97 }
98 }
99 fTessellated->CloseShape();
100
101 RootGM::SolidMap::Instance()->AddSolid(this, fTessellated);
102}
103
104//_____________________________________________________________________________
106 : VGM::ISolid(), VGM::ITessellatedSolid(), BaseVGM::VTessellatedSolid(),
107 fTessellated(tessellated)
108{
110
111 RootGM::SolidMap::Instance()->AddSolid(this, fTessellated);
112}
113
114//_____________________________________________________________________________
116 : VGM::ISolid(), VGM::ITessellatedSolid(), BaseVGM::VTessellatedSolid(), fTessellated(0)
117{
119}
120
121//_____________________________________________________________________________
123 : VGM::ISolid(rhs),
124 VGM::ITessellatedSolid(rhs),
125 BaseVGM::VTessellatedSolid(rhs),
126 fTessellated(0)
127{
129}
130
131//_____________________________________________________________________________
136
137//_____________________________________________________________________________
138void RootGM::TessellatedSolid::CheckFacetIndex(int ifacet) const
139{
140 if (ifacet < 0 || ifacet > NofFacets()) {
141 std::cerr << "+++ Error +++" << std::endl;
142 std::cerr << " Wrong facet index: " << ifacet << std::endl;
143 exit(1);
144 }
145}
146
147//_____________________________________________________________________________
148void RootGM::TessellatedSolid::CheckVertexIndex(int ifacet, int index) const
149{
150 CheckFacetIndex(ifacet);
151
152 if (index < 0 || index > NofVertices(ifacet)) {
153 std::cerr << "+++ Error +++" << std::endl;
154 std::cerr << " Wrong vertex index: " << index << " in " << ifacet
155 << " th facet." << std::endl;
156 exit(1);
157 }
158}
159
160//_____________________________________________________________________________
161std::string RootGM::TessellatedSolid::Name() const { return fTessellated->GetName(); }
162
163//_____________________________________________________________________________
164int RootGM::TessellatedSolid::NofFacets() const { return fTessellated->GetNfacets(); }
165
166//_____________________________________________________________________________
168{
169 CheckFacetIndex(ifacet);
170
171 const TGeoFacet& facet = fTessellated->GetFacet(ifacet);
172
173 return facet.GetNvert();
174}
175
176//_____________________________________________________________________________
178{
179 CheckVertexIndex(ifacet, index);
180
181#if ROOT_VERSION_CODE > ROOT_VERSION(6, 30, 4)
182 const auto& rvertex = fTessellated->GetVertex((fTessellated->GetFacet(ifacet))[index]);
183#else
184 const auto& rvertex = fTessellated->GetFacet(ifacet).GetVertex(index);
185#endif
186
187 VGM::ThreeVector vertex;
188 vertex.push_back(rvertex.fVec[0] * RootGM::Units::Length());
189 vertex.push_back(rvertex.fVec[1] * RootGM::Units::Length());
190 vertex.push_back(rvertex.fVec[2] * RootGM::Units::Length());
191
192 return vertex;
193}
void AddSolid(VGM::ISolid *, TGeoShape *)
Definition SolidMap.cxx:59
static SolidMap * Instance()
Definition SolidMap.cxx:28
VGM implementation for Root tessellated solid.
virtual VGM::ThreeVector Vertex(int ifacet, int index) const
Return the index-th vertex in the ifacet-th facet.
virtual std::string Name() const
Return the name of this solid.
virtual int NofVertices(int ifacet) const
Return the number of vertices in the the ifacet-th facet.
virtual int NofFacets() const
Return the number of facets.
static double Length()
Return Root length unit in VGM units.
Definition Units.h:84
BaseVGM utilities.
Definition utilities.h:23
VGM interfaces.
Definition VMedium.h:28
std::vector< double > ThreeVector
Definition ThreeVector.h:27
@ kDx
Definition Transform.h:44
@ kDz
Definition Transform.h:46
@ kDy
Definition Transform.h:45