Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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#include <iostream>
13
14#include "TGeoManager.h"
15#include "TGeoMatrix.h"
16#include "TGeoVolume.h"
17#include "TGeoNode.h"
18#include "TGeoScaledShape.h"
19#include "TBuffer3D.h"
20#include "TBuffer3DTypes.h"
21#include "TMath.h"
22
23/** \class TGeoScaledShape
24\ingroup Geometry_classes
25
26A shape scaled by a TGeoScale transformation
27\image html geom_scaledshape.png
28*/
29
31
32////////////////////////////////////////////////////////////////////////////////
33/// Default constructor
34
36{
37 fShape = nullptr;
38 fScale = nullptr;
39}
40
41////////////////////////////////////////////////////////////////////////////////
42/// Constructor
43
44TGeoScaledShape::TGeoScaledShape(const char *name, TGeoShape *shape, TGeoScale *scale) : TGeoBBox(name, 0, 0, 0)
45{
46 fShape = shape;
47 fScale = scale;
48 if (!fScale->IsRegistered())
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// Constructor
55
57{
58 fShape = shape;
59 fScale = scale;
60 if (!fScale->IsRegistered())
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// destructor
67
69
70////////////////////////////////////////////////////////////////////////////////
71/// Computes capacity of this shape [length^3]
72
74{
75 Double_t capacity = fShape->Capacity();
76 const Double_t *scale = fScale->GetScale();
77 capacity *= scale[0] * scale[1] * scale[2];
78 return capacity;
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Compute bounding box of the scaled shape
83
85{
86 if (!fShape) {
87 Error("ComputeBBox", "Scaled shape %s without shape", GetName());
88 return;
89 }
90 if (fShape->IsAssembly())
93 const Double_t *orig = box->GetOrigin();
94 Double_t point[3], master[3];
95 point[0] = box->GetDX();
96 point[1] = box->GetDY();
97 point[2] = box->GetDZ();
98
100 fScale->LocalToMaster(point, master);
101 fDX = TMath::Abs(master[0]);
102 fDY = TMath::Abs(master[1]);
103 fDZ = TMath::Abs(master[2]);
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// Compute normal to closest surface from POINT.
108
109void TGeoScaledShape::ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm)
110{
111 Double_t local[3], ldir[3], lnorm[3];
112 fScale->MasterToLocal(point, local);
113 fScale->MasterToLocalVect(dir, ldir);
115 fShape->ComputeNormal(local, ldir, lnorm);
116 // fScale->LocalToMasterVect(lnorm, norm);
117 fScale->MasterToLocalVect(lnorm, norm);
119}
120
121////////////////////////////////////////////////////////////////////////////////
122/// Test if point is inside the scaled shape
123
125{
126 Double_t local[3];
127 fScale->MasterToLocal(point, local);
128 return fShape->Contains(local);
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// compute closest distance from point px,py to each vertex. Should not be called.
133
135{
137 return ShapeDistancetoPrimitive(n, px, py);
138}
139
140////////////////////////////////////////////////////////////////////////////////
141/// Compute distance from inside point to surface of the scaled shape.
142
144 Double_t *safe) const
145{
146 Double_t local[3], ldir[3];
147 Double_t lstep;
148 fScale->MasterToLocal(point, local);
149 lstep = fScale->MasterToLocal(step, dir);
150 fScale->MasterToLocalVect(dir, ldir);
152 Double_t dist = fShape->DistFromInside(local, ldir, iact, lstep, safe);
153 if (iact < 3 && safe)
154 *safe = fScale->LocalToMaster(*safe);
155 dist = fScale->LocalToMaster(dist, ldir);
156 return dist;
157}
158
159////////////////////////////////////////////////////////////////////////////////
160/// Compute distance from outside point to surface of the scaled shape.
161
163 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)
177 *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 nullptr;
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 buffer.fScaled = kTRUE;
200
201 // TGeoBBox::FillBuffer3D(buffer, reqSections, localFrame);
202 Double_t halfLengths[3] = {fDX, fDY, fDZ};
203 buffer.SetAABoundingBox(fOrigin, halfLengths);
204 if (!buffer.fLocalFrame) {
205 TransformPoints(buffer.fBBVertex[0], 8);
206 }
207
208 if ((reqSections & TBuffer3D::kRaw) && buffer.SectionsValid(TBuffer3D::kRawSizes)) {
209 SetPoints(buffer.fPnts);
210 if (!buffer.fLocalFrame) {
211 TransformPoints(buffer.fPnts, buffer.NbPnts());
212 }
213 }
214
215 return buffer;
216}
217////////////////////////////////////////////////////////////////////////////////
218/// in case shape has some negative parameters, these has to be computed
219/// in order to fit the mother
220
222{
223 Error("GetMakeRuntimeShape", "Scaled shapes cannot be parametrized.");
224 return nullptr;
225}
226
227////////////////////////////////////////////////////////////////////////////////
228/// Returns numbers of vertices, segments and polygons composing the shape mesh.
229
230void TGeoScaledShape::GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols) const
231{
232 fShape->GetMeshNumbers(nvert, nsegs, npols);
233}
234
235////////////////////////////////////////////////////////////////////////////////
236/// print shape parameters
237
239{
240 printf("*** Shape %s: TGeoScaledShape ***\n", GetName());
241 fScale->Print();
244}
245
246////////////////////////////////////////////////////////////////////////////////
247/// Returns true if the scaled shape is an assembly.
248
250{
251 return fShape->IsAssembly();
252}
253
254////////////////////////////////////////////////////////////////////////////////
255/// Check if the scale transformation is a reflection.
256
258{
259 return fScale->IsReflection();
260}
261
262////////////////////////////////////////////////////////////////////////////////
263/// Creates a TBuffer3D describing *this* shape.
264/// Coordinates are in local reference frame.
265
267{
268 TBuffer3D *buff = fShape->MakeBuffer3D();
269 if (buff)
270 SetPoints(buff->fPnts);
271 return buff;
272}
273
274////////////////////////////////////////////////////////////////////////////////
275/// Create a scaled shape starting from a non-scaled one.
276
278{
279 TGeoShape *old_shape = shape;
280 TGeoShape *new_shape = nullptr;
281 if (shape->IsA() == TGeoScaledShape::Class()) {
282 TGeoScaledShape *sshape = (TGeoScaledShape *)shape;
283 TGeoScale *old_scale = sshape->GetScale();
284 old_shape = sshape->GetShape();
285 scale->SetScale(scale->GetScale()[0] * old_scale->GetScale()[0], scale->GetScale()[1] * old_scale->GetScale()[1],
286 scale->GetScale()[2] * old_scale->GetScale()[2]);
287 }
288 if (old_shape->IsAssembly()) {
289 // The shape is owned by the assembly, so make sure it does not register to TGeoManager
290 new_shape = new TGeoScaledShape(old_shape, scale);
291 new_shape->SetName(name);
292 } else {
293 new_shape = new TGeoScaledShape(name, old_shape, scale);
294 }
295 return new_shape;
296}
297
298////////////////////////////////////////////////////////////////////////////////
299/// Fill TBuffer3D structure for segments and polygons.
300
302{
303 fShape->SetSegsAndPols(buff);
304}
305
306////////////////////////////////////////////////////////////////////////////////
307/// computes the closest distance from given point to this shape, according
308/// to option. The matching point on the shape is stored in spoint.
309
311{
312 Double_t local[3];
313 fScale->MasterToLocal(point, local);
314 Double_t safe = fShape->Safety(local, in);
315 safe = fScale->LocalToMaster(safe);
316 return safe;
317}
318
319////////////////////////////////////////////////////////////////////////////////
320/// Save a primitive as a C++ statement(s) on output stream "out".
321
323{
325 return;
326 out << " // Shape: " << GetName() << " type: " << ClassName() << std::endl;
327 if (!fShape || !fScale) {
328 out << "##### Invalid shape or scale !. Aborting. #####" << std::endl;
329 return;
330 }
332 TString sname = fShape->GetPointerName();
333 const Double_t *sc = fScale->GetScale();
334 out << " // Scale factor:" << std::endl;
335 out << " auto pScale_" << GetPointerName() << " = new TGeoScale(\"" << fScale->GetName() << "\"," << sc[0] << ","
336 << sc[1] << "," << sc[2] << ");" << std::endl;
337 out << " TGeoScaledShape *" << GetPointerName() << " = new TGeoScaledShape(\"" << GetName() << "\"," << sname
338 << ", pScale_" << GetPointerName() << " );" << std::endl;
339}
340
341////////////////////////////////////////////////////////////////////////////////
342/// Mesh points for scaled shapes.
343
345{
346 Int_t npts = fShape->GetNmeshVertices();
348 Double_t master[3];
349 for (Int_t i = 0; i < npts; i++) {
350 fScale->LocalToMaster(&points[3 * i], master);
351 memcpy(&points[3 * i], master, 3 * sizeof(Double_t));
352 }
353}
354
355////////////////////////////////////////////////////////////////////////////////
356/// Mesh points for scaled shapes.
357
359{
360 Int_t npts = fShape->GetNmeshVertices();
362 Double_t master[3];
363 Double_t local[3];
364 Int_t index;
365 for (Int_t i = 0; i < npts; i++) {
366 index = 3 * i;
367 local[0] = points[index];
368 local[1] = points[index + 1];
369 local[2] = points[index + 2];
370 fScale->LocalToMaster(local, master);
371 points[index] = master[0];
372 points[index + 1] = master[1];
373 points[index + 2] = master[2];
374 }
375}
376
377////////////////////////////////////////////////////////////////////////////////
378/// Check the inside status for each of the points in the array.
379/// Input: Array of point coordinates + vector size
380/// Output: Array of Booleans for the inside of each point
381
382void TGeoScaledShape::Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const
383{
384 for (Int_t i = 0; i < vecsize; i++)
385 inside[i] = Contains(&points[3 * i]);
386}
387
388////////////////////////////////////////////////////////////////////////////////
389/// Compute the normal for an array o points so that norm.dot.dir is positive
390/// Input: Arrays of point coordinates and directions + vector size
391/// Output: Array of normal directions
392
393void TGeoScaledShape::ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize)
394{
395 for (Int_t i = 0; i < vecsize; i++)
396 ComputeNormal(&points[3 * i], &dirs[3 * i], &norms[3 * i]);
397}
398
399////////////////////////////////////////////////////////////////////////////////
400/// Compute distance from array of input points having directions specified by dirs. Store output in dists
401
402void TGeoScaledShape::DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize,
403 Double_t *step) const
404{
405 for (Int_t i = 0; i < vecsize; i++)
406 dists[i] = DistFromInside(&points[3 * i], &dirs[3 * i], 3, step[i]);
407}
408
409////////////////////////////////////////////////////////////////////////////////
410/// Compute distance from array of input points having directions specified by dirs. Store output in dists
411
413 Double_t *step) const
414{
415 for (Int_t i = 0; i < vecsize; i++)
416 dists[i] = DistFromOutside(&points[3 * i], &dirs[3 * i], 3, step[i]);
417}
418
419////////////////////////////////////////////////////////////////////////////////
420/// Compute safe distance from each of the points in the input array.
421/// Input: Array of point coordinates, array of statuses for these points, size of the arrays
422/// Output: Safety values
423
424void TGeoScaledShape::Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const
425{
426 for (Int_t i = 0; i < vecsize; i++)
427 safe[i] = Safety(&points[3 * i], inside[i]);
428}
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t points
char name[80]
Definition TGX11.cxx:110
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
Bool_t fLocalFrame
Definition TBuffer3D.h:90
Bool_t fScaled
Definition TBuffer3D.h:92
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...
Double_t * fPnts
Definition TBuffer3D.h:113
Double_t fBBVertex[8][3]
Definition TBuffer3D.h:108
Box class.
Definition TGeoBBox.h:17
Double_t fDX
Definition TGeoBBox.h:20
Double_t fOrigin[3]
Definition TGeoBBox.h:23
void InspectShape() const override
Prints shape parameters.
Definition TGeoBBox.cxx:855
Double_t fDY
Definition TGeoBBox.h:21
Double_t fDZ
Definition TGeoBBox.h:22
Geometrical transformation package.
Definition TGeoMatrix.h:38
void Print(Option_t *option="") const override
print the matrix in 4x4 format
Bool_t IsReflection() const
Definition TGeoMatrix.h:66
virtual void RegisterYourself()
Register the matrix in the current manager, which will become the owner.
static void Normalize(Double_t *vect)
Normalize a vector.
Bool_t IsRegistered() const
Definition TGeoMatrix.h:72
Class describing scale transformations.
Definition TGeoMatrix.h:253
const Double_t * GetScale() const override
Definition TGeoMatrix.h:305
void SetScale(Double_t sx, Double_t sy, Double_t sz)
scale setter
void MasterToLocalVect(const Double_t *master, Double_t *local) const override
convert a point by multiplying its column vector (x, y, z, 1) to matrix
Definition TGeoMatrix.h:283
void LocalToMaster(const Double_t *local, Double_t *master) const override
Convert a local point to the master frame.
void MasterToLocal(const Double_t *master, Double_t *local) const override
Convert a global point to local frame.
A shape scaled by a TGeoScale transformation.
Bool_t Contains(const Double_t *point) const override
Test if point is inside the scaled shape.
TGeoShape * GetMakeRuntimeShape(TGeoShape *mother, TGeoMatrix *mat) const override
in case shape has some negative parameters, these has to be computed in order to fit the mother
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
compute closest distance from point px,py to each vertex. Should not be called.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save a primitive as a C++ statement(s) on output stream "out".
TGeoScaledShape()
Default constructor.
TGeoShape * GetShape() const
void DistFromOutside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const override
Compute distance from array of input points having directions specified by dirs. Store output in dist...
Bool_t IsReflected() const override
Check if the scale transformation is a reflection.
~TGeoScaledShape() override
destructor
TGeoShape * fShape
TGeoScale * fScale
TGeoVolume * Divide(TGeoVolume *voldiv, const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step) override
Cannot divide assemblies.
void InspectShape() const override
print shape parameters
void Safety_v(const Double_t *points, const Bool_t *inside, Double_t *safe, Int_t vecsize) const override
Compute safe distance from each of the points in the input array.
static TClass * Class()
const TBuffer3D & GetBuffer3D(Int_t reqSections, Bool_t localFrame) const override
Fills a static 3D buffer and returns a reference.
Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const override
computes the closest distance from given point to this shape, according to option.
Bool_t IsAssembly() const override
Returns true if the scaled shape is an assembly.
void SetSegsAndPols(TBuffer3D &buffer) const override
Fill TBuffer3D structure for segments and polygons.
Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=nullptr) const override
Compute distance from outside point to surface of the scaled shape.
void SetPoints(Double_t *points) const override
Mesh points for scaled shapes.
Double_t Capacity() const override
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.
void Contains_v(const Double_t *points, Bool_t *inside, Int_t vecsize) const override
Check the inside status for each of the points in the array.
void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) override
Compute normal to closest surface from POINT.
void GetMeshNumbers(Int_t &nvert, Int_t &nsegs, Int_t &npols) const override
Returns numbers of vertices, segments and polygons composing the shape mesh.
Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=nullptr) const override
Compute distance from inside point to surface of the scaled shape.
TBuffer3D * MakeBuffer3D() const override
Creates a TBuffer3D describing this shape.
TGeoScale * GetScale() const
void DistFromInside_v(const Double_t *points, const Double_t *dirs, Double_t *dists, Int_t vecsize, Double_t *step) const override
Compute distance from array of input points having directions specified by dirs. Store output in dist...
void ComputeNormal_v(const Double_t *points, const Double_t *dirs, Double_t *norms, Int_t vecsize) override
Compute the normal for an array o points so that norm.dot.dir is positive Input: Arrays of point coor...
void ComputeBBox() override
Compute bounding box of the scaled shape.
Base abstract class for all shapes.
Definition TGeoShape.h:25
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.
virtual Double_t DistFromInside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=nullptr) const =0
void TransformPoints(Double_t *points, UInt_t NbPoints) const
Tranform a set of points (LocalToMaster)
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.
virtual void InspectShape() const =0
Int_t ShapeDistancetoPrimitive(Int_t numpoints, Int_t px, Int_t py) const
Returns distance to shape primitive mesh.
virtual Double_t DistFromOutside(const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=nullptr) const =0
const char * GetName() const override
Get the shape name.
virtual void ComputeBBox()=0
virtual Double_t Capacity() const =0
virtual Bool_t Contains(const Double_t *point) const =0
@ kGeoSavePrimitive
Definition TGeoShape.h:64
virtual void SetPoints(Double_t *points) const =0
TClass * IsA() const override
Definition TGeoShape.h:171
virtual Bool_t IsAssembly() const
Definition TGeoShape.h:129
virtual TBuffer3D * MakeBuffer3D() const
Definition TGeoShape.h:146
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:201
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition TObject.cxx:751
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:976
Basic string class.
Definition TString.h:139
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
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123