Logo ROOT  
Reference Guide
TGeoScaledShape.cxx
Go to the documentation of this file.
1// @(#)root/geom:$Id$
2// Author: Andrei Gheata 26/09/05
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12
13#include "Riostream.h"
14
15#include "TGeoManager.h"
16#include "TGeoMatrix.h"
17#include "TGeoVolume.h"
18#include "TGeoNode.h"
19#include "TGeoScaledShape.h"
20#include "TBuffer3D.h"
21#include "TBuffer3DTypes.h"
22#include "TMath.h"
23
24/** \class TGeoScaledShape
25\ingroup Geometry_classes
26
27A shape scaled by a TGeoScale transformation
28\image html geom_scaledshape.png
29*/
30
32
33////////////////////////////////////////////////////////////////////////////////
34/// Default constructor
35
37{
38 fShape = 0;
39 fScale = 0;
40}
41
42
43////////////////////////////////////////////////////////////////////////////////
44/// Constructor
45
47 :TGeoBBox(name,0,0,0)
48{
49 fShape = shape;
50 fScale = scale;
53
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// Constructor
58
60{
61 fShape = shape;
62 fScale = scale;
65}
66
67////////////////////////////////////////////////////////////////////////////////
68/// destructor
69
71{
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// Computes capacity of this shape [length^3]
76
78{
79 Double_t capacity = fShape->Capacity();
80 const Double_t *scale = fScale->GetScale();
81 capacity *= scale[0]*scale[1]*scale[2];
82 return capacity;
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// Compute bounding box of the scaled shape
87
89{
90 if (!fShape) {
91 Error("ComputeBBox", "Scaled shape %s without shape", GetName());
92 return;
93 }
96 const Double_t *orig = box->GetOrigin();
97 Double_t point[3], master[3];
98 point[0] = box->GetDX();
99 point[1] = box->GetDY();
100 point[2] = box->GetDZ();
101
103 fScale->LocalToMaster(point, master);
104 fDX = TMath::Abs(master[0]);
105 fDY = TMath::Abs(master[1]);
106 fDZ = TMath::Abs(master[2]);
107}
108
109////////////////////////////////////////////////////////////////////////////////
110/// Compute normal to closest surface from POINT.
111
112void TGeoScaledShape::ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm)
113{
114 Double_t local[3], ldir[3], lnorm[3];
115 fScale->MasterToLocal(point,local);
116 fScale->MasterToLocalVect(dir,ldir);
118 fShape->ComputeNormal(local,ldir,lnorm);
119// fScale->LocalToMasterVect(lnorm, norm);
120 fScale->MasterToLocalVect(lnorm, norm);
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Test if point is inside the scaled shape
126
128{
129 Double_t local[3];
130 fScale->MasterToLocal(point,local);
131 return fShape->Contains(local);
132}
133
134////////////////////////////////////////////////////////////////////////////////
135/// compute closest distance from point px,py to each vertex. Should not be called.
136
138{
140 return ShapeDistancetoPrimitive(n, px, py);
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Compute distance from inside point to surface of the scaled shape.
145
146Double_t TGeoScaledShape::DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact, Double_t step, Double_t *safe) const
147{
148 Double_t local[3], ldir[3];
149 Double_t lstep;
150 fScale->MasterToLocal(point,local);
151 lstep = fScale->MasterToLocal(step, dir);
152 fScale->MasterToLocalVect(dir,ldir);
154 Double_t dist = fShape->DistFromInside(local,ldir, iact, lstep, safe);
155 if (iact<3 && safe) *safe = fScale->LocalToMaster(*safe);
156 dist = fScale->LocalToMaster(dist, ldir);
157 return dist;
158}
159
160
161////////////////////////////////////////////////////////////////////////////////
162/// Compute distance from outside point to surface of the scaled shape.
163
164Double_t TGeoScaledShape::DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact, Double_t step, Double_t *safe) const
165{
166 Double_t local[3], ldir[3];
167 Double_t lstep;
168// printf("DistFromOutside(%f,%f,%f, %f,%f,%f)\n", point[0], point[1], point[2], dir[0], dir[1],dir[2]);
169 fScale->MasterToLocal(point,local);
170// printf("local: %f,%f,%f\n", local[0],local[1], local[2]);
171 lstep = fScale->MasterToLocal(step, dir);
172 fScale->MasterToLocalVect(dir,ldir);
174// printf("localdir: %f,%f,%f\n",ldir[0],ldir[1],ldir[2]);
175 Double_t dist = fShape->DistFromOutside(local,ldir, iact, lstep, safe);
176// printf("local distance: %f\n", dist);
177 if (safe) *safe = fScale->LocalToMaster(*safe);
178 dist = fScale->LocalToMaster(dist, ldir);
179// printf("converted distance: %f\n",dist);
180 return dist;
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Cannot divide assemblies.
185
186TGeoVolume *TGeoScaledShape::Divide(TGeoVolume * /*voldiv*/, const char *divname, Int_t /*iaxis*/, Int_t /*ndiv*/,
187 Double_t /*start*/, Double_t /*step*/)
188{
189 Error("Divide", "Scaled shapes cannot be divided. Division volume %s not created", divname);
190 return 0;
191}
192
193////////////////////////////////////////////////////////////////////////////////
194/// Fills a static 3D buffer and returns a reference.
195
196const TBuffer3D & TGeoScaledShape::GetBuffer3D(Int_t reqSections, Bool_t localFrame) const
197{
198 TBuffer3D &buffer = (TBuffer3D &)fShape->GetBuffer3D(reqSections, localFrame);
199
200// TGeoBBox::FillBuffer3D(buffer, reqSections, localFrame);
201 Double_t halfLengths[3] = { fDX, fDY, fDZ };
202 buffer.SetAABoundingBox(fOrigin, halfLengths);
203 if (!buffer.fLocalFrame) {
204 TransformPoints(buffer.fBBVertex[0], 8);
205 }
206
207 if ((reqSections & TBuffer3D::kRaw) && buffer.SectionsValid(TBuffer3D::kRawSizes)) {
208 SetPoints(buffer.fPnts);
209 if (!buffer.fLocalFrame) {
210 TransformPoints(buffer.fPnts, buffer.NbPnts());
211 }
212 }
213
214 return buffer;
215}
216////////////////////////////////////////////////////////////////////////////////
217/// in case shape has some negative parameters, these has to be computed
218/// in order to fit the mother
219
221{
222 Error("GetMakeRuntimeShape", "Scaled shapes cannot be parametrized.");
223 return NULL;
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Returns numbers of vertices, segments and polygons composing the shape mesh.
228
229void TGeoScaledShape::GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols) const
230{
231 fShape->GetMeshNumbers(nvert, nsegs, npols);
232}
233
234////////////////////////////////////////////////////////////////////////////////
235/// print shape parameters
236
238{
239 printf("*** Shape %s: TGeoScaledShape ***\n", GetName());
240 fScale->Print();
243}
244
245////////////////////////////////////////////////////////////////////////////////
246/// Returns true if the scaled shape is an assembly.
247
249{
250 return fShape->IsAssembly();
251}
252
253////////////////////////////////////////////////////////////////////////////////
254/// Check if the scale transformation is a reflection.
255
257{
258 return fScale->IsReflection();
259}
260
261////////////////////////////////////////////////////////////////////////////////
262/// Creates a TBuffer3D describing *this* shape.
263/// Coordinates are in local reference frame.
264
266{
267 TBuffer3D *buff = fShape->MakeBuffer3D();
268 if (buff) SetPoints(buff->fPnts);
269 return buff;
270}
271
272////////////////////////////////////////////////////////////////////////////////
273/// Create a scaled shape starting from a non-scaled one.
274
276{
277 TGeoShape *old_shape = shape;
278 TGeoShape *new_shape = nullptr;
279 if (shape->IsA() == TGeoScaledShape::Class()) {
280 TGeoScaledShape *sshape = (TGeoScaledShape*)shape;
281 TGeoScale *old_scale = sshape->GetScale();
282 old_shape = sshape->GetShape();
283 scale->SetScale(scale->GetScale()[0]*old_scale->GetScale()[0],
284 scale->GetScale()[1]*old_scale->GetScale()[1],
285 scale->GetScale()[2]*old_scale->GetScale()[2]);
286 }
287 if (old_shape->IsAssembly()) {
288 // The shape is owned by the assembly, so make sure it does not register to TGeoManager
289 new_shape = new TGeoScaledShape(old_shape, scale);
290 new_shape->SetName(name);
291 } else {
292 new_shape = new TGeoScaledShape(name, old_shape, scale);
293 }
294 return new_shape;
295}
296
297////////////////////////////////////////////////////////////////////////////////
298/// Fill TBuffer3D structure for segments and polygons.
299
301{
302 fShape->SetSegsAndPols(buff);
303}
304
305////////////////////////////////////////////////////////////////////////////////
306/// computes the closest distance from given point to this shape, according
307/// to option. The matching point on the shape is stored in spoint.
308
310{
311 Double_t local[3];
312 fScale->MasterToLocal(point,local);
313 Double_t safe = fShape->Safety(local,in);
314 safe = fScale->LocalToMaster(safe);
315 return safe;
316}
317
318////////////////////////////////////////////////////////////////////////////////
319/// Save a primitive as a C++ statement(s) on output stream "out".
320
321void TGeoScaledShape::SavePrimitive(std::ostream &out, Option_t *option)
322{
324 out << " // Shape: " << GetName() << " type: " << ClassName() << std::endl;
325 if (!fShape || !fScale) {
326 out << "##### Invalid shape or scale !. Aborting. #####" << std::endl;
327 return;
328 }
329 fShape->SavePrimitive(out, option);
330 TString sname = fShape->GetPointerName();
331 const Double_t *sc = fScale->GetScale();
332 out << " // Scale factor:" << std::endl;
333 out << " TGeoScale *pScale = new TGeoScale(\"" << fScale->GetName()
334 << "\"," << sc[0] << "," << sc[1] << "," << sc[2] << ");" << std::endl;
335 out << " TGeoScaledShape *" << GetPointerName() << " = new TGeoScaledShape(\""
336 << GetName() << "\"," << sname << ", pScale);" << std::endl;
337}
338
339////////////////////////////////////////////////////////////////////////////////
340/// Mesh points for scaled shapes.
341
343{
344 Int_t npts = fShape->GetNmeshVertices();
346 Double_t master[3];
347 for (Int_t i=0; i<npts; i++) {
348 fScale->LocalToMaster(&points[3*i], master);
349 memcpy(&points[3*i], master, 3*sizeof(Double_t));
350 }
351}
352
353////////////////////////////////////////////////////////////////////////////////
354/// Mesh points for scaled shapes.
355
357{
358 Int_t npts = fShape->GetNmeshVertices();
360 Double_t master[3];
361 Double_t local[3];
362 Int_t index;
363 for (Int_t i=0; i<npts; i++) {
364 index = 3*i;
365 local[0] = points[index];
366 local[1] = points[index+1];
367 local[2] = points[index+2];
368 fScale->LocalToMaster(local, master);
369 points[index] = master[0];
370 points[index+1] = master[1];
371 points[index+2] = master[2];
372 }
373}
374
375////////////////////////////////////////////////////////////////////////////////
376/// Check the inside status for each of the points in the array.
377/// Input: Array of point coordinates + vector size
378/// Output: Array of Booleans for the inside of each point
379
380void TGeoScaledShape::Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const
381{
382 for (Int_t i=0; i<vecsize; i++) inside[i] = Contains(&points[3*i]);
383}
384
385////////////////////////////////////////////////////////////////////////////////
386/// Compute the normal for an array o points so that norm.dot.dir is positive
387/// Input: Arrays of point coordinates and directions + vector size
388/// Output: Array of normal directions
389
390void TGeoScaledShape::ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize)
391{
392 for (Int_t i=0; i<vecsize; i++) ComputeNormal(&points[3*i], &dirs[3*i], &norms[3*i]);
393}
394
395////////////////////////////////////////////////////////////////////////////////
396/// Compute distance from array of input points having directions specified by dirs. Store output in dists
397
398void TGeoScaledShape::DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t* step) const
399{
400 for (Int_t i=0; i<vecsize; i++) dists[i] = DistFromInside(&points[3*i], &dirs[3*i], 3, step[i]);
401}
402
403////////////////////////////////////////////////////////////////////////////////
404/// Compute distance from array of input points having directions specified by dirs. Store output in dists
405
406void TGeoScaledShape::DistFromOutside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t* step) const
407{
408 for (Int_t i=0; i<vecsize; i++) dists[i] = DistFromOutside(&points[3*i], &dirs[3*i], 3, step[i]);
409}
410
411////////////////////////////////////////////////////////////////////////////////
412/// Compute safe distance from each of the points in the input array.
413/// Input: Array of point coordinates, array of statuses for these points, size of the arrays
414/// Output: Safety values
415
416void TGeoScaledShape::Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const
417{
418 for (Int_t i=0; i<vecsize; i++) safe[i] = Safety(&points[3*i], inside[i]);
419}
void Class()
Definition: Class.C:29
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
float Float_t
Definition: RtypesCore.h:53
const char Option_t
Definition: RtypesCore.h:62
#define ClassImp(name)
Definition: Rtypes.h:365
char name[80]
Definition: TGX11.cxx:109
point * points
Definition: X3DBuffer.c:22
Generic 3D primitive description class.
Definition: TBuffer3D.h:18
UInt_t NbPnts() const
Definition: TBuffer3D.h:80
Bool_t SectionsValid(UInt_t mask) const
Definition: TBuffer3D.h:67
@ kRawSizes
Definition: TBuffer3D.h:53
Bool_t fLocalFrame
Definition: TBuffer3D.h:90
void SetAABoundingBox(const Double_t origin[3], const Double_t halfLengths[3])
Set fBBVertex in kBoundingBox section to a axis aligned (local) BB using supplied origin and box half...
Definition: TBuffer3D.cxx:320
Double_t * fPnts
Definition: TBuffer3D.h:112
Double_t fBBVertex[8][3]
Definition: TBuffer3D.h:107
Box class.
Definition: TGeoBBox.h:18
Double_t fDX
Definition: TGeoBBox.h:21
virtual void InspectShape() const
Prints shape parameters.
Definition: TGeoBBox.cxx:793
Double_t fOrigin[3]
Definition: TGeoBBox.h:24
Double_t fDY
Definition: TGeoBBox.h:22
Double_t fDZ
Definition: TGeoBBox.h:23
Geometrical transformation package.
Definition: TGeoMatrix.h:41
Bool_t IsReflection() const
Definition: TGeoMatrix.h:69
virtual void RegisterYourself()
Register the matrix in the current manager, which will become the owner.
Definition: TGeoMatrix.cxx:526
static void Normalize(Double_t *vect)
Normalize a vector.
Definition: TGeoMatrix.cxx:473
void Print(Option_t *option="") const
print the matrix in 4x4 format
Definition: TGeoMatrix.cxx:486
Bool_t IsRegistered() const
Definition: TGeoMatrix.h:77
Class describing scale transformations.
Definition: TGeoMatrix.h:245
virtual void MasterToLocal(const Double_t *master, Double_t *local) const
Convert a global point to local frame.
virtual void MasterToLocalVect(const Double_t *master, Double_t *local) const
convert a point by multiplying its column vector (x, y, z, 1) to matrix
Definition: TGeoMatrix.h:272
void SetScale(Double_t sx, Double_t sy, Double_t sz)
scale setter
virtual void LocalToMaster(const Double_t *local, Double_t *master) const
Convert a local point to the master frame.
virtual const Double_t * GetScale() const
Definition: TGeoMatrix.h:279
A shape scaled by a TGeoScale transformation.
virtual Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const
computes the closest distance from given point to this shape, according to option.
TGeoScaledShape()
Default constructor.
virtual void DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const
Compute distance from array of input points having directions specified by dirs. Store output in dist...
virtual void Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const
Check the inside status for each of the points in the array.
TGeoShape * GetShape() const
virtual TGeoVolume * Divide(TGeoVolume *voldiv, const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step)
Cannot divide assemblies.
virtual Bool_t Contains(const Double_t *point) const
Test if point is inside the scaled shape.
TGeoShape * fShape
TGeoScale * fScale
virtual void GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols) const
Returns numbers of vertices, segments and polygons composing the shape mesh.
virtual void ComputeBBox()
Compute bounding box of the scaled shape.
virtual TBuffer3D * MakeBuffer3D() const
Creates a TBuffer3D describing this shape.
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
virtual void SetSegsAndPols(TBuffer3D &buffer) const
Fill TBuffer3D structure for segments and polygons.
virtual void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm)
Compute normal to closest surface from POINT.
virtual ~TGeoScaledShape()
destructor
virtual void InspectShape() const
print shape parameters
virtual Bool_t IsReflected() const
Check if the scale transformation is a reflection.
virtual TGeoShape * GetMakeRuntimeShape(TGeoShape *mother, TGeoMatrix *mat) const
in case shape has some negative parameters, these has to be computed in order to fit the mother
virtual Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=0) const
Compute distance from outside point to surface of the scaled shape.
virtual void SetPoints(Double_t *points) const
Mesh points for scaled shapes.
virtual Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=0) const
Compute distance from inside point to surface of the scaled shape.
virtual Double_t Capacity() const
Computes capacity of this shape [length^3].
static TGeoShape * MakeScaledShape(const char *name, TGeoShape *shape, TGeoScale *scale)
Create a scaled shape starting from a non-scaled one.
virtual void ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize)
Compute the normal for an array o points so that norm.dot.dir is positive Input: Arrays of point coor...
virtual Bool_t IsAssembly() const
Returns true if the scaled shape is an assembly.
TGeoScale * GetScale() const
virtual void Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const
Compute safe distance from each of the points in the input array.
virtual void DistFromOutside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const
Compute distance from array of input points having directions specified by dirs. Store output in dist...
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
compute closest distance from point px,py to each vertex. Should not be called.
virtual const TBuffer3D & GetBuffer3D(Int_t reqSections, Bool_t localFrame) const
Fills a static 3D buffer and returns a reference.
Base abstract class for all shapes.
Definition: TGeoShape.h:26
virtual void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm)=0
virtual const TBuffer3D & GetBuffer3D(Int_t reqSections, Bool_t localFrame) const
Stub implementation to avoid forcing implementation at this stage.
Definition: TGeoShape.cxx:689
void TransformPoints(Double_t *points, UInt_t NbPoints) const
Tranform a set of points (LocalToMaster)
Definition: TGeoShape.cxx:552
virtual Int_t GetNmeshVertices() const
Definition: TGeoShape.h:127
virtual void GetMeshNumbers(Int_t &, Int_t &, Int_t &) const
Definition: TGeoShape.h:125
virtual void SetSegsAndPols(TBuffer3D &buff) const =0
virtual Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const =0
const char * GetPointerName() const
Provide a pointer name containing uid.
Definition: TGeoShape.cxx:699
virtual void InspectShape() const =0
Int_t ShapeDistancetoPrimitive(Int_t numpoints, Int_t px, Int_t py) const
Returns distance to shape primitive mesh.
Definition: TGeoShape.cxx:259
virtual const char * GetName() const
Get the shape name.
Definition: TGeoShape.cxx:248
virtual Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=0) const =0
virtual void ComputeBBox()=0
virtual Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=0) const =0
virtual Double_t Capacity() const =0
virtual Bool_t Contains(const Double_t *point) const =0
@ kGeoSavePrimitive
Definition: TGeoShape.h:65
virtual void SetPoints(Double_t *points) const =0
virtual Bool_t IsAssembly() const
Definition: TGeoShape.h:129
virtual TBuffer3D * MakeBuffer3D() const
Definition: TGeoShape.h:143
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition: TGeoVolume.h:47
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:664
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
Basic string class.
Definition: TString.h:131
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
const Int_t n
Definition: legend1.C:16
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
Short_t Abs(Short_t d)
Definition: TMathBase.h:120