VGM
Version 5.5
Toggle main menu visibility
Loading...
Searching...
No Matches
packages
RootGM
source
solids
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
19
#include "
RootGM/solids/TessellatedSolid.h
"
20
#include "
RootGM/common/Units.h
"
21
#include "
RootGM/solids/SolidMap.h
"
22
23
#include "
VGM/common/Transform.h
"
24
25
#include "TGeoTessellated.h"
26
27
#include <cstdlib>
28
#include <iostream>
29
#include <math.h>
30
31
using
ROOT::Geom::Vertex_t;
32
33
//_____________________________________________________________________________
34
RootGM::TessellatedSolid::TessellatedSolid
(
const
std::string& name,
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
(),
68
vertex0[
VGM::kDy
] /
RootGM::Units::Length
(),
69
vertex0[
VGM::kDz
] /
RootGM::Units::Length
()),
70
Vertex_t(vertex1[
VGM::kDx
] /
RootGM::Units::Length
(),
71
vertex1[
VGM::kDy
] /
RootGM::Units::Length
(),
72
vertex1[
VGM::kDz
] /
RootGM::Units::Length
()),
73
Vertex_t(vertex2[
VGM::kDx
] /
RootGM::Units::Length
(),
74
vertex2[
VGM::kDy
] /
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
(),
86
vertex0[
VGM::kDy
] /
RootGM::Units::Length
(),
87
vertex0[
VGM::kDz
] /
RootGM::Units::Length
()),
88
Vertex_t(vertex1[
VGM::kDx
] /
RootGM::Units::Length
(),
89
vertex1[
VGM::kDy
] /
RootGM::Units::Length
(),
90
vertex1[
VGM::kDz
] /
RootGM::Units::Length
()),
91
Vertex_t(vertex2[
VGM::kDx
] /
RootGM::Units::Length
(),
92
vertex2[
VGM::kDy
] /
RootGM::Units::Length
(),
93
vertex2[
VGM::kDz
] /
RootGM::Units::Length
()),
94
Vertex_t(vertex3[
VGM::kDx
] /
RootGM::Units::Length
(),
95
vertex3[
VGM::kDy
] /
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
//_____________________________________________________________________________
105
RootGM::TessellatedSolid::TessellatedSolid
(TGeoTessellated* tessellated)
106
:
VGM
::ISolid(),
VGM
::ITessellatedSolid(),
BaseVGM
::
VTessellatedSolid
(),
107
fTessellated(tessellated)
108
{
110
111
RootGM::SolidMap::Instance
()->
AddSolid
(
this
, fTessellated);
112
}
113
114
//_____________________________________________________________________________
115
RootGM::TessellatedSolid::TessellatedSolid
()
116
:
VGM
::ISolid(),
VGM
::ITessellatedSolid(),
BaseVGM
::
VTessellatedSolid
(), fTessellated(0)
117
{
119
}
120
121
//_____________________________________________________________________________
122
RootGM::TessellatedSolid::TessellatedSolid
(
const
TessellatedSolid
& rhs)
123
:
VGM
::ISolid(rhs),
124
VGM
::ITessellatedSolid(rhs),
125
BaseVGM
::
VTessellatedSolid
(rhs),
126
fTessellated(0)
127
{
129
}
130
131
//_____________________________________________________________________________
132
RootGM::TessellatedSolid::~TessellatedSolid
()
133
{
134
//
135
}
136
137
//_____________________________________________________________________________
138
void
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
//_____________________________________________________________________________
148
void
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
//_____________________________________________________________________________
161
std::string
RootGM::TessellatedSolid::Name
()
const
{
return
fTessellated->GetName(); }
162
163
//_____________________________________________________________________________
164
int
RootGM::TessellatedSolid::NofFacets
()
const
{
return
fTessellated->GetNfacets(); }
165
166
//_____________________________________________________________________________
167
int
RootGM::TessellatedSolid::NofVertices
(
int
ifacet)
const
168
{
169
CheckFacetIndex(ifacet);
170
171
const
TGeoFacet& facet = fTessellated->GetFacet(ifacet);
172
173
return
facet.GetNvert();
174
}
175
176
//_____________________________________________________________________________
177
VGM::ThreeVector
RootGM::TessellatedSolid::Vertex
(
int
ifacet,
int
index)
const
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
}
Units.h
SolidMap.h
TessellatedSolid.h
Transform.h
BaseVGM::VTessellatedSolid::VTessellatedSolid
VTessellatedSolid()
Definition
VTessellatedSolid.cxx:32
RootGM::SolidMap::AddSolid
void AddSolid(VGM::ISolid *, TGeoShape *)
Definition
SolidMap.cxx:59
RootGM::SolidMap::Instance
static SolidMap * Instance()
Definition
SolidMap.cxx:28
RootGM::TessellatedSolid::~TessellatedSolid
virtual ~TessellatedSolid()
Definition
TessellatedSolid.cxx:132
RootGM::TessellatedSolid::Vertex
virtual VGM::ThreeVector Vertex(int ifacet, int index) const
Return the index-th vertex in the ifacet-th facet.
Definition
TessellatedSolid.cxx:177
RootGM::TessellatedSolid::Name
virtual std::string Name() const
Return the name of this solid.
Definition
TessellatedSolid.cxx:161
RootGM::TessellatedSolid::NofVertices
virtual int NofVertices(int ifacet) const
Return the number of vertices in the the ifacet-th facet.
Definition
TessellatedSolid.cxx:167
RootGM::TessellatedSolid::TessellatedSolid
TessellatedSolid()
Definition
TessellatedSolid.cxx:115
RootGM::TessellatedSolid::NofFacets
virtual int NofFacets() const
Return the number of facets.
Definition
TessellatedSolid.cxx:164
RootGM::TessellatedSolid::TessellatedSolid
TessellatedSolid(const std::string &name, std::vector< std::vector< VGM::ThreeVector > > facets)
Definition
TessellatedSolid.cxx:34
RootGM::Units::Length
static double Length()
Return Root length unit in VGM units.
Definition
Units.h:84
BaseVGM
BaseVGM utilities.
Definition
utilities.h:23
VGM
VGM interfaces.
Definition
VMedium.h:28
VGM::ThreeVector
std::vector< double > ThreeVector
Definition
ThreeVector.h:27
VGM::kDx
@ kDx
Definition
Transform.h:44
VGM::kDz
@ kDz
Definition
Transform.h:46
VGM::kDy
@ kDy
Definition
Transform.h:45
Generated on
for VGM by
1.17.0