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
30
31////////////////////////////////////////////////////////////////////////////////
32/// Default constructor
33
40
41////////////////////////////////////////////////////////////////////////////////
42/// Constructor
43
53
54////////////////////////////////////////////////////////////////////////////////
55/// Constructor
56
66
67////////////////////////////////////////////////////////////////////////////////
68/// destructor
69
71
72////////////////////////////////////////////////////////////////////////////////
73/// Computes capacity of this shape [length^3]
74
76{
77 Double_t capacity = fShape->Capacity();
78 const Double_t *scale = fScale->GetScale();
79 capacity *= scale[0] * scale[1] * scale[2];
80 return capacity;
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Compute bounding box of the scaled shape
85
87{
88 if (!fShape) {
89 Error("ComputeBBox", "Scaled shape %s without shape", GetName());
90 return;
91 }
92 if (fShape->IsAssembly())
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) const
112{
113 Double_t local[3], ldir[3], lnorm[3];
114 fScale->MasterToLocal(point, local);
118 // fScale->LocalToMasterVect(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
141
142////////////////////////////////////////////////////////////////////////////////
143/// Compute distance from inside point to surface of the scaled shape.
144
146 Double_t *safe) const
147{
148 Double_t local[3], ldir[3];
150 fScale->MasterToLocal(point, local);
151 lstep = fScale->MasterToLocal(step, dir);
155 if (iact < 3 && safe)
157 dist = fScale->LocalToMaster(dist, ldir);
158 return dist;
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Compute distance from outside point to surface of the scaled shape.
163
165 Double_t *safe) const
166{
167 Double_t local[3], ldir[3];
169 // printf("DistFromOutside(%f,%f,%f, %f,%f,%f)\n", point[0], point[1], point[2], dir[0], dir[1],dir[2]);
170 fScale->MasterToLocal(point, local);
171 // printf("local: %f,%f,%f\n", local[0],local[1], local[2]);
172 lstep = fScale->MasterToLocal(step, dir);
175 // printf("localdir: %f,%f,%f\n",ldir[0],ldir[1],ldir[2]);
177 // printf("local distance: %f\n", dist);
178 if (safe)
180 dist = fScale->LocalToMaster(dist, ldir);
181 // printf("converted distance: %f\n",dist);
182 return dist;
183}
184
185////////////////////////////////////////////////////////////////////////////////
186/// Cannot divide assemblies.
187
188TGeoVolume *TGeoScaledShape::Divide(TGeoVolume * /*voldiv*/, const char *divname, Int_t /*iaxis*/, Int_t /*ndiv*/,
189 Double_t /*start*/, Double_t /*step*/)
190{
191 Error("Divide", "Scaled shapes cannot be divided. Division volume %s not created", divname);
192 return nullptr;
193}
194
195////////////////////////////////////////////////////////////////////////////////
196/// Fills a static 3D buffer and returns a reference.
197
199{
201 buffer.fScaled = kTRUE;
202
203 // TGeoBBox::FillBuffer3D(buffer, reqSections, localFrame);
204 Double_t halfLengths[3] = {fDX, fDY, fDZ};
206 if (!buffer.fLocalFrame) {
207 TransformPoints(buffer.fBBVertex[0], 8);
208 }
209
211 SetPoints(buffer.fPnts);
212 if (!buffer.fLocalFrame) {
213 TransformPoints(buffer.fPnts, buffer.NbPnts());
214 }
215 }
216
217 return buffer;
218}
219////////////////////////////////////////////////////////////////////////////////
220/// in case shape has some negative parameters, these has to be computed
221/// in order to fit the mother
222
224{
225 Error("GetMakeRuntimeShape", "Scaled shapes cannot be parametrized.");
226 return nullptr;
227}
228
229////////////////////////////////////////////////////////////////////////////////
230/// Returns numbers of vertices, segments and polygons composing the shape mesh.
231
236
237////////////////////////////////////////////////////////////////////////////////
238/// print shape parameters
239
241{
242 printf("*** Shape %s: TGeoScaledShape ***\n", GetName());
243 fScale->Print();
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Returns true if the scaled shape is an assembly.
250
252{
253 return fShape->IsAssembly();
254}
255
256////////////////////////////////////////////////////////////////////////////////
257/// Check if the scale transformation is a reflection.
258
263
264////////////////////////////////////////////////////////////////////////////////
265/// Creates a TBuffer3D describing *this* shape.
266/// Coordinates are in local reference frame.
267
269{
271 if (buff)
272 SetPoints(buff->fPnts);
273 return buff;
274}
275
276////////////////////////////////////////////////////////////////////////////////
277/// Create a scaled shape starting from a non-scaled one.
278
280{
281 TGeoShape *old_shape = shape;
282 TGeoShape *new_shape = nullptr;
283 if (shape->IsA() == TGeoScaledShape::Class()) {
285 TGeoScale *old_scale = sshape->GetScale();
286 old_shape = sshape->GetShape();
287 scale->SetScale(scale->GetScale()[0] * old_scale->GetScale()[0], scale->GetScale()[1] * old_scale->GetScale()[1],
288 scale->GetScale()[2] * old_scale->GetScale()[2]);
289 }
290 if (old_shape->IsAssembly()) {
291 // The shape is owned by the assembly, so make sure it does not register to TGeoManager
293 new_shape->SetName(name);
294 } else {
296 }
297 return new_shape;
298}
299
300////////////////////////////////////////////////////////////////////////////////
301/// Fill TBuffer3D structure for segments and polygons.
302
307
308////////////////////////////////////////////////////////////////////////////////
309/// computes the closest distance from given point to this shape, according
310/// to option. The matching point on the shape is stored in spoint.
311
313{
314 Double_t local[3];
315 fScale->MasterToLocal(point, local);
318 return safe;
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// Save a primitive as a C++ statement(s) on output stream "out".
323
325{
327 return;
328 out << " // Shape: " << GetName() << " type: " << ClassName() << std::endl;
329 if (!fShape || !fScale) {
330 out << "##### Invalid shape or scale !. Aborting. #####" << std::endl;
331 return;
332 }
335 const Double_t *sc = fScale->GetScale();
336 out << " // Scale factor:" << std::endl;
337 out << " auto pScale_" << GetPointerName() << " = new TGeoScale(\"" << fScale->GetName() << "\"," << sc[0] << ","
338 << sc[1] << "," << sc[2] << ");" << std::endl;
339 out << " TGeoScaledShape *" << GetPointerName() << " = new TGeoScaledShape(\"" << GetName() << "\"," << sname
340 << ", pScale_" << GetPointerName() << " );" << std::endl;
341}
342
343////////////////////////////////////////////////////////////////////////////////
344/// Mesh points for scaled shapes.
345
347{
350 Double_t master[3];
351 for (Int_t i = 0; i < npts; i++) {
353 memcpy(&points[3 * i], master, 3 * sizeof(Double_t));
354 }
355}
356
357////////////////////////////////////////////////////////////////////////////////
358/// Mesh points for scaled shapes.
359
361{
364 Double_t master[3];
365 Double_t local[3];
366 Int_t index;
367 for (Int_t i = 0; i < npts; i++) {
368 index = 3 * i;
369 local[0] = points[index];
370 local[1] = points[index + 1];
371 local[2] = points[index + 2];
373 points[index] = master[0];
374 points[index + 1] = master[1];
375 points[index + 2] = master[2];
376 }
377}
378
379////////////////////////////////////////////////////////////////////////////////
380/// Check the inside status for each of the points in the array.
381/// Input: Array of point coordinates + vector size
382/// Output: Array of Booleans for the inside of each point
383
385{
386 for (Int_t i = 0; i < vecsize; i++)
387 inside[i] = Contains(&points[3 * i]);
388}
389
390////////////////////////////////////////////////////////////////////////////////
391/// Compute the normal for an array o points so that norm.dot.dir is positive
392/// Input: Arrays of point coordinates and directions + vector size
393/// Output: Array of normal directions
394
396{
397 for (Int_t i = 0; i < vecsize; i++)
398 ComputeNormal(&points[3 * i], &dirs[3 * i], &norms[3 * i]);
399}
400
401////////////////////////////////////////////////////////////////////////////////
402/// Compute distance from array of input points having directions specified by dirs. Store output in dists
403
405 Double_t *step) const
406{
407 for (Int_t i = 0; i < vecsize; i++)
408 dists[i] = DistFromInside(&points[3 * i], &dirs[3 * i], 3, step[i]);
409}
410
411////////////////////////////////////////////////////////////////////////////////
412/// Compute distance from array of input points having directions specified by dirs. Store output in dists
413
415 Double_t *step) const
416{
417 for (Int_t i = 0; i < vecsize; i++)
418 dists[i] = DistFromOutside(&points[3 * i], &dirs[3 * i], 3, step[i]);
419}
420
421////////////////////////////////////////////////////////////////////////////////
422/// Compute safe distance from each of the points in the input array.
423/// Input: Array of point coordinates, array of statuses for these points, size of the arrays
424/// Output: Safety values
425
427{
428 for (Int_t i = 0; i < vecsize; i++)
429 safe[i] = Safety(&points[3 * i], inside[i]);
430}
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:810
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 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.
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
void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const override
Compute normal to closest surface from POINT.
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 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.
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 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)
void SetShapeBit(UInt_t f, Bool_t set)
Equivalent of TObject::SetBit.
virtual Int_t GetNmeshVertices() const
Definition TGeoShape.h:135
virtual void GetMeshNumbers(Int_t &, Int_t &, Int_t &) const
Definition TGeoShape.h:133
virtual void SetSegsAndPols(TBuffer3D &buff) const =0
virtual Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const =0
virtual void ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) 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:65
virtual void SetPoints(Double_t *points) const =0
TClass * IsA() const override
Definition TGeoShape.h:180
virtual Bool_t IsAssembly() const
Definition TGeoShape.h:138
virtual TBuffer3D * MakeBuffer3D() const
Definition TGeoShape.h:155
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:202
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:226
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition TObject.cxx:852
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1088
Basic string class.
Definition TString.h:138
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:122