VGM Version 5.3
Loading...
Searching...
No Matches
ExtrudedSolid.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 ExtrudedSolid
14// --------------------
15// VGM implementation for Root ExtrudedSolid solid.
16//
17// Author: Ivana Hrivnacova; IPN Orsay
18
20#include "RootGM/common/Units.h"
22
23#include "TGeoXtru.h"
24
25#include <cstdlib>
26#include <iostream>
27#include <math.h>
28
29//_____________________________________________________________________________
31 std::vector<VGM::TwoVector> polygon,
32 std::vector<std::vector<double> > zsections)
33 : VGM::ISolid(), VGM::IExtrudedSolid(), BaseVGM::VExtrudedSolid(), fXtru(0)
34{
39
40 if (zsections.size() < 2) {
41 std::cerr << "+++ Error +++" << std::endl;
42 std::cerr << " Number of z-sections = " << zsections.size()
43 << " has to be >= 2" << std::endl;
44 exit(1);
45 }
46
47 fXtru = new TGeoXtru(zsections.size());
48 fXtru->SetName(name.data());
49
50 // set polygon
51 Int_t nv = polygon.size();
52 double* xv = new double[nv];
53 double* yv = new double[nv];
54 for (unsigned int i = 0; i < polygon.size(); ++i) {
55 xv[i] = polygon[i].first / RootGM::Units::Length();
56 yv[i] = polygon[i].second / RootGM::Units::Length();
57 }
58 fXtru->DefinePolygon(nv, xv, yv);
59
60 // set z-sections
61 for (unsigned int i = 0; i < zsections.size(); ++i) {
62 fXtru->DefineSection(i, zsections[i][0] / RootGM::Units::Length(),
63 zsections[i][1] / RootGM::Units::Length(),
64 zsections[i][2] / RootGM::Units::Length(), zsections[i][3]);
65 }
66
68
69 delete[] xv;
70 delete[] yv;
71}
72
73//_____________________________________________________________________________
75 : VGM::ISolid(), VGM::IExtrudedSolid(), BaseVGM::VExtrudedSolid(), fXtru(xtru)
76{
78
80}
81
82//_____________________________________________________________________________
84 : VGM::ISolid(), VGM::IExtrudedSolid(), BaseVGM::VExtrudedSolid(), fXtru(0)
85{
87}
88
89//_____________________________________________________________________________
91 : VGM::ISolid(rhs),
92 VGM::IExtrudedSolid(rhs),
93 BaseVGM::VExtrudedSolid(rhs),
94 fXtru(0)
95{
97}
98
99//_____________________________________________________________________________
104
105/*
106//_____________________________________________________________________________
107void RootGM::ExtrudedSolid::AddZPlane(double zpos,
108 VGM::TwoVector offset, double scale)
109{
110 if ( !fXtru ) {
111 // add error
112 return;
113 }
114
115 if ( fNofZSections == NofZSections() ) {
116 // add error
117 return;
118 }
119
120 Double_t z = zpos / RootGM::Units::Length();
121 Double_t x0 = offset.first / RootGM::Units::Length();
122 Double_t y0 = offset.second / RootGM::Units::Length();
123
124 fXtru->DefineSection(fNofZSections++, z, x0, y0, scale);
125}
126*/
127
128//_____________________________________________________________________________
129std::string RootGM::ExtrudedSolid::Name() const { return fXtru->GetName(); }
130
131//_____________________________________________________________________________
132int RootGM::ExtrudedSolid::NofVertices() const { return fXtru->GetNvert(); }
133
134//_____________________________________________________________________________
136{
137 if (index < 0 || index > NofVertices()) {
138 std::cerr << "+++ Error +++" << std::endl;
139 std::cerr << " Wrong vertex index: " << index << std::endl;
140 exit(1);
141 }
142
143 return VGM::TwoVector(fXtru->GetX(index) * RootGM::Units::Length(),
144 fXtru->GetY(index) * RootGM::Units::Length());
145}
146
147//_____________________________________________________________________________
148int RootGM::ExtrudedSolid::NofZSections() const { return fXtru->GetNz(); }
149
150//_____________________________________________________________________________
152{
153 if (iz < 0 || iz > NofZSections()) {
154 std::cerr << "+++ Error +++" << std::endl;
155 std::cerr << " Wrong index: " << iz << std::endl;
156 exit(1);
157 }
158
159 return fXtru->GetZ(iz) * RootGM::Units::Length();
160}
161
162//_____________________________________________________________________________
164{
165 if (iz < 0 || iz > NofZSections()) {
166 std::cerr << "+++ Error +++" << std::endl;
167 std::cerr << " Wrong index: " << iz << std::endl;
168 exit(1);
169 }
170
171 return VGM::TwoVector(fXtru->GetXOffset(iz) * RootGM::Units::Length(),
172 fXtru->GetYOffset(iz) * RootGM::Units::Length());
173}
174
175//_____________________________________________________________________________
177{
178 if (iz < 0 || iz > NofZSections()) {
179 std::cerr << "+++ Error +++" << std::endl;
180 std::cerr << " Wrong index: " << iz << std::endl;
181 exit(1);
182 }
183
184 return fXtru->GetScale(iz);
185}
VGM implementation for Root extruded solid.
virtual std::string Name() const
Return the name of this solid.
virtual int NofZSections() const
Return the number of planes perpendicular to the z axis.
virtual VGM::TwoVector Offset(int iz) const
Return the polygon offset in iz-th side.
virtual double ZPosition(int iz) const
Return the z position of the iz-th plane in mm.
int NofVertices() const
Return the number of vertices of outline polygon.
VGM::TwoVector Vertex(int index) const
Return the index-th vertex of outline polygon.
virtual double Scale(int iz) const
Return the polygon scale in iz-th side.
void AddSolid(VGM::ISolid *, TGeoShape *)
Definition SolidMap.cxx:59
static SolidMap * Instance()
Definition SolidMap.cxx:28
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::pair< double, double > TwoVector
Definition TwoVector.h:28