Logo ROOT   6.16/01
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/// Constructor
57
59{
60 fShape = shape;
61 fScale = scale;
64}
65
66////////////////////////////////////////////////////////////////////////////////
67/// destructor
68
70{
71}
72
73////////////////////////////////////////////////////////////////////////////////
74/// Computes capacity of this shape [length^3]
75
77{
78 Double_t capacity = fShape->Capacity();
79 const Double_t *scale = fScale->GetScale();
80 capacity *= scale[0]*scale[1]*scale[2];
81 return capacity;
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Compute bounding box of the scaled shape
86
88{
89 if (!fShape) {
90 Error("ComputeBBox", "Scaled shape %s without shape", GetName());
91 return;
92 }
95 const Double_t *orig = box->GetOrigin();
96 Double_t point[3], master[3];
97 point[0] = box->GetDX();
98 point[1] = box->GetDY();
99 point[2] = box->GetDZ();
100
102 fScale->LocalToMaster(point, master);
103 fDX = TMath::Abs(master[0]);
104 fDY = TMath::Abs(master[1]);
105 fDZ = TMath::Abs(master[2]);
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Compute normal to closest surface from POINT.
110
111void TGeoScaledShape::ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm)
112{
113 Double_t local[3], ldir[3], lnorm[3];
114 fScale->MasterToLocal(point,local);
115 fScale->MasterToLocalVect(dir,ldir);
117 fShape->ComputeNormal(local,ldir,lnorm);
118// fScale->LocalToMasterVect(lnorm, norm);
119 fScale->MasterToLocalVect(lnorm, norm);
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Test if point is inside the scaled shape
125
127{
128 Double_t local[3];
129 fScale->MasterToLocal(point,local);
130 return fShape->Contains(local);
131}
132
133////////////////////////////////////////////////////////////////////////////////
134/// compute closest distance from point px,py to each vertex. Should not be called.
135
137{
139 return ShapeDistancetoPrimitive(n, px, py);
140}
141
142////////////////////////////////////////////////////////////////////////////////
143/// Compute distance from inside point to surface of the scaled shape.
144
145Double_t TGeoScaledShape::DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact, Double_t step, Double_t *safe) const
146{
147 Double_t local[3], ldir[3];
148 Double_t lstep;
149 fScale->MasterToLocal(point,local);
150 lstep = fScale->MasterToLocal(step, dir);
151 fScale->MasterToLocalVect(dir,ldir);
153 Double_t dist = fShape->DistFromInside(local,ldir, iact, lstep, safe);
154 if (iact<3 && safe) *safe = fScale->LocalToMaster(*safe);
155 dist = fScale->LocalToMaster(dist, ldir);
156 return dist;
157}
158
159
160////////////////////////////////////////////////////////////////////////////////
161/// Compute distance from outside point to surface of the scaled shape.
162
163Double_t TGeoScaledShape::DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact, Double_t step, Double_t *safe) const
164{
165 Double_t local[3], ldir[3];
166 Double_t lstep;
167// printf("DistFromOutside(%f,%f,%f, %f,%f,%f)\n", point[0], point[1], point[2], dir[0], dir[1],dir[2]);
168 fScale->MasterToLocal(point,local);
169// printf("local: %f,%f,%f\n", local[0],local[1], local[2]);
170 lstep = fScale->MasterToLocal(step, dir);
171 fScale->MasterToLocalVect(dir,ldir);
173// printf("localdir: %f,%f,%f\n",ldir[0],ldir[1],ldir[2]);
174 Double_t dist = fShape->DistFromOutside(local,ldir, iact, lstep, safe);
175// printf("local distance: %f\n", dist);
176 if (safe) *safe = fScale->LocalToMaster(*safe);
177 dist = fScale->LocalToMaster(dist, ldir);
178// printf("converted distance: %f\n",dist);
179 return dist;
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Cannot divide assemblies.
184
185TGeoVolume *TGeoScaledShape::Divide(TGeoVolume * /*voldiv*/, const char *divname, Int_t /*iaxis*/, Int_t /*ndiv*/,
186 Double_t /*start*/, Double_t /*step*/)
187{
188 Error("Divide", "Scaled shapes cannot be divided. Division volume %s not created", divname);
189 return 0;
190}
191
192////////////////////////////////////////////////////////////////////////////////
193/// Fills a static 3D buffer and returns a reference.
194
195const TBuffer3D & TGeoScaledShape::GetBuffer3D(Int_t reqSections, Bool_t localFrame) const
196{
197 TBuffer3D &buffer = (TBuffer3D &)fShape->GetBuffer3D(reqSections, localFrame);
198
199// TGeoBBox::FillBuffer3D(buffer, reqSections, localFrame);
200 Double_t halfLengths[3] = { fDX, fDY, fDZ };
201 buffer.SetAABoundingBox(fOrigin, halfLengths);
202 if (!buffer.fLocalFrame) {
203 TransformPoints(buffer.fBBVertex[0], 8);
204 }
205
206 if ((reqSections & TBuffer3D::kRaw) && buffer.SectionsValid(TBuffer3D::kRawSizes)) {
207 SetPoints(buffer.fPnts);
208 if (!buffer.fLocalFrame) {
209 TransformPoints(buffer.fPnts, buffer.NbPnts());
210 }
211 }
212
213 return buffer;
214}
215////////////////////////////////////////////////////////////////////////////////
216/// in case shape has some negative parameters, these has to be computed
217/// in order to fit the mother
218
220{
221 Error("GetMakeRuntimeShape", "Scaled shapes cannot be parametrized.");
222 return NULL;
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// Returns numbers of vertices, segments and polygons composing the shape mesh.
227
228void TGeoScaledShape::GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols) const
229{
230 fShape->GetMeshNumbers(nvert, nsegs, npols);
231}
232
233////////////////////////////////////////////////////////////////////////////////
234/// print shape parameters
235
237{
238 printf("*** Shape %s: TGeoScaledShape ***\n", GetName());
239 fScale->Print();
242}
243
244////////////////////////////////////////////////////////////////////////////////
245/// Returns true if the scaled shape is an assembly.
246
248{
249 return fShape->IsAssembly();
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// Check if the scale transformation is a reflection.
254
256{
257 return fScale->IsReflection();
258}
259
260////////////////////////////////////////////////////////////////////////////////
261/// Creates a TBuffer3D describing *this* shape.
262/// Coordinates are in local reference frame.
263
265{
266 TBuffer3D *buff = fShape->MakeBuffer3D();
267 if (buff) SetPoints(buff->fPnts);
268 return buff;
269}
270
271////////////////////////////////////////////////////////////////////////////////
272/// Create a scaled shape starting from a non-scaled one.
273
275{
276 TGeoShape *new_shape;
277 if (shape->IsA() == TGeoScaledShape::Class()) {
278 TGeoScaledShape *sshape = (TGeoScaledShape*)shape;
279 TGeoScale *old_scale = sshape->GetScale();
280 TGeoShape *old_shape = sshape->GetShape();
281 scale->SetScale(scale->GetScale()[0]*old_scale->GetScale()[0],
282 scale->GetScale()[1]*old_scale->GetScale()[1],
283 scale->GetScale()[2]*old_scale->GetScale()[2]);
284 new_shape = new TGeoScaledShape(name, old_shape, scale);
285 return new_shape;
286 }
287 new_shape = new TGeoScaledShape(name, shape, scale);
288 return new_shape;
289}
290
291////////////////////////////////////////////////////////////////////////////////
292/// Fill TBuffer3D structure for segments and polygons.
293
295{
296 fShape->SetSegsAndPols(buff);
297}
298
299////////////////////////////////////////////////////////////////////////////////
300/// computes the closest distance from given point to this shape, according
301/// to option. The matching point on the shape is stored in spoint.
302
304{
305 Double_t local[3];
306 fScale->MasterToLocal(point,local);
307 Double_t safe = fShape->Safety(local,in);
308 safe = fScale->LocalToMaster(safe);
309 return safe;
310}
311
312////////////////////////////////////////////////////////////////////////////////
313/// Save a primitive as a C++ statement(s) on output stream "out".
314
315void TGeoScaledShape::SavePrimitive(std::ostream &out, Option_t *option)
316{
318 out << " // Shape: " << GetName() << " type: " << ClassName() << std::endl;
319 if (!fShape || !fScale) {
320 out << "##### Invalid shape or scale !. Aborting. #####" << std::endl;
321 return;
322 }
323 fShape->SavePrimitive(out, option);
324 TString sname = fShape->GetPointerName();
325 const Double_t *sc = fScale->GetScale();
326 out << " // Scale factor:" << std::endl;
327 out << " TGeoScale *pScale = new TGeoScale(\"" << fScale->GetName()
328 << "\"," << sc[0] << "," << sc[1] << "," << sc[2] << ");" << std::endl;
329 out << " TGeoScaledShape *" << GetPointerName() << " = new TGeoScaledShape(\""
330 << GetName() << "\"," << sname << ", pScale);" << std::endl;
331}
332
333////////////////////////////////////////////////////////////////////////////////
334/// Mesh points for scaled shapes.
335
337{
338 Int_t npts = fShape->GetNmeshVertices();
340 Double_t master[3];
341 for (Int_t i=0; i<npts; i++) {
342 fScale->LocalToMaster(&points[3*i], master);
343 memcpy(&points[3*i], master, 3*sizeof(Double_t));
344 }
345}
346
347////////////////////////////////////////////////////////////////////////////////
348/// Mesh points for scaled shapes.
349
351{
352 Int_t npts = fShape->GetNmeshVertices();
354 Double_t master[3];
355 Double_t local[3];
356 Int_t index;
357 for (Int_t i=0; i<npts; i++) {
358 index = 3*i;
359 local[0] = points[index];
360 local[1] = points[index+1];
361 local[2] = points[index+2];
362 fScale->LocalToMaster(local, master);
363 points[index] = master[0];
364 points[index+1] = master[1];
365 points[index+2] = master[2];
366 }
367}
368
369////////////////////////////////////////////////////////////////////////////////
370/// Check the inside status for each of the points in the array.
371/// Input: Array of point coordinates + vector size
372/// Output: Array of Booleans for the inside of each point
373
374void TGeoScaledShape::Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const
375{
376 for (Int_t i=0; i<vecsize; i++) inside[i] = Contains(&points[3*i]);
377}
378
379////////////////////////////////////////////////////////////////////////////////
380/// Compute the normal for an array o points so that norm.dot.dir is positive
381/// Input: Arrays of point coordinates and directions + vector size
382/// Output: Array of normal directions
383
384void TGeoScaledShape::ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize)
385{
386 for (Int_t i=0; i<vecsize; i++) ComputeNormal(&points[3*i], &dirs[3*i], &norms[3*i]);
387}
388
389////////////////////////////////////////////////////////////////////////////////
390/// Compute distance from array of input points having directions specified by dirs. Store output in dists
391
392void TGeoScaledShape::DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t* step) const
393{
394 for (Int_t i=0; i<vecsize; i++) dists[i] = DistFromInside(&points[3*i], &dirs[3*i], 3, step[i]);
395}
396
397////////////////////////////////////////////////////////////////////////////////
398/// Compute distance from array of input points having directions specified by dirs. Store output in dists
399
400void TGeoScaledShape::DistFromOutside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t* step) const
401{
402 for (Int_t i=0; i<vecsize; i++) dists[i] = DistFromOutside(&points[3*i], &dirs[3*i], 3, step[i]);
403}
404
405////////////////////////////////////////////////////////////////////////////////
406/// Compute safe distance from each of the points in the input array.
407/// Input: Array of point coordinates, array of statuses for these points, size of the arrays
408/// Output: Safety values
409
410void TGeoScaledShape::Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const
411{
412 for (Int_t i=0; i<vecsize; i++) safe[i] = Safety(&points[3*i], inside[i]);
413}
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:363
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:53
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