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
35{
36 fShape = nullptr;
37 fScale = nullptr;
38}
39
40////////////////////////////////////////////////////////////////////////////////
41/// Constructor
42
51
52////////////////////////////////////////////////////////////////////////////////
53/// Constructor
54
63
64////////////////////////////////////////////////////////////////////////////////
65/// destructor
66
68
69////////////////////////////////////////////////////////////////////////////////
70/// Computes capacity of this shape [length^3]
71
73{
74 Double_t capacity = fShape->Capacity();
75 const Double_t *scale = fScale->GetScale();
76 capacity *= scale[0] * scale[1] * scale[2];
77 return capacity;
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Compute bounding box of the scaled shape
82
84{
85 if (!fShape) {
86 Error("ComputeBBox", "Scaled shape %s without shape", GetName());
87 return;
88 }
89 if (fShape->IsAssembly())
92 const Double_t *orig = box->GetOrigin();
93 Double_t point[3], master[3];
94 point[0] = box->GetDX();
95 point[1] = box->GetDY();
96 point[2] = box->GetDZ();
97
100 fDX = TMath::Abs(master[0]);
101 fDY = TMath::Abs(master[1]);
102 fDZ = TMath::Abs(master[2]);
103}
104
105////////////////////////////////////////////////////////////////////////////////
106/// Compute normal to closest surface from POINT.
107
108void TGeoScaledShape::ComputeNormal(const Double_t *point, const Double_t *dir, Double_t *norm) const
109{
110 Double_t local[3], ldir[3], lnorm[3];
111 fScale->MasterToLocal(point, local);
115 // fScale->LocalToMasterVect(lnorm, norm);
118}
119
120////////////////////////////////////////////////////////////////////////////////
121/// Test if point is inside the scaled shape
122
124{
125 Double_t local[3];
126 fScale->MasterToLocal(point, local);
127 return fShape->Contains(local);
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// compute closest distance from point px,py to each vertex. Should not be called.
132
138
139////////////////////////////////////////////////////////////////////////////////
140/// Compute distance from inside point to surface of the scaled shape.
141
143 Double_t *safe) const
144{
145 Double_t local[3], ldir[3];
147 fScale->MasterToLocal(point, local);
148 lstep = fScale->MasterToLocal(step, dir);
152 if (iact < 3 && safe)
154 dist = fScale->LocalToMaster(dist, ldir);
155 return dist;
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// Compute distance from outside point to surface of the scaled shape.
160
162 Double_t *safe) const
163{
164 Double_t local[3], ldir[3];
166 // printf("DistFromOutside(%f,%f,%f, %f,%f,%f)\n", point[0], point[1], point[2], dir[0], dir[1],dir[2]);
167 fScale->MasterToLocal(point, local);
168 // printf("local: %f,%f,%f\n", local[0],local[1], local[2]);
169 lstep = fScale->MasterToLocal(step, dir);
172 // printf("localdir: %f,%f,%f\n",ldir[0],ldir[1],ldir[2]);
174 // printf("local distance: %f\n", dist);
175 if (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 nullptr;
190}
191
192////////////////////////////////////////////////////////////////////////////////
193/// Fills a static 3D buffer and returns a reference.
194
196{
198 buffer.fScaled = kTRUE;
199
200 // TGeoBBox::FillBuffer3D(buffer, reqSections, localFrame);
201 Double_t halfLengths[3] = {fDX, fDY, fDZ};
203 if (!buffer.fLocalFrame) {
204 TransformPoints(buffer.fBBVertex[0], 8);
205 }
206
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 nullptr;
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Returns numbers of vertices, segments and polygons composing the shape mesh.
228
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
260
261////////////////////////////////////////////////////////////////////////////////
262/// Creates a TBuffer3D describing *this* shape.
263/// Coordinates are in local reference frame.
264
266{
268 if (buff)
269 SetPoints(buff->fPnts);
270 return buff;
271}
272
273////////////////////////////////////////////////////////////////////////////////
274/// Create a scaled shape starting from a non-scaled one.
275
277{
278 TGeoShape *old_shape = shape;
279 TGeoShape *new_shape = nullptr;
280 if (shape->IsA() == TGeoScaledShape::Class()) {
282 TGeoScale *old_scale = sshape->GetScale();
283 old_shape = sshape->GetShape();
284 scale->SetScale(scale->GetScale()[0] * old_scale->GetScale()[0], 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
290 new_shape->SetName(name);
291 } else {
293 }
294 return new_shape;
295}
296
297////////////////////////////////////////////////////////////////////////////////
298/// Fill TBuffer3D structure for segments and polygons.
299
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);
315 return safe;
316}
317
318////////////////////////////////////////////////////////////////////////////////
319/// Save a primitive as a C++ statement(s) on output stream "out".
320
322{
324 return;
325 out << " // Shape: " << GetName() << " type: " << ClassName() << std::endl;
326 if (!fShape || !fScale) {
327 out << "##### Invalid shape or scale !. Aborting. #####" << std::endl;
328 return;
329 }
332 const Double_t *sc = fScale->GetScale();
333 out << " // Scale factor:" << std::endl;
334 out << " auto pScale_" << GetPointerName() << " = new TGeoScale(\"" << fScale->GetName() << "\"," << sc[0] << ","
335 << sc[1] << "," << sc[2] << ");" << std::endl;
336 out << " TGeoScaledShape *" << GetPointerName() << " = new TGeoScaledShape(\"" << GetName() << "\"," << sname
337 << ", pScale_" << GetPointerName() << " );" << std::endl;
338}
339
340////////////////////////////////////////////////////////////////////////////////
341/// Mesh points for scaled shapes.
342
344{
347 Double_t master[3];
348 for (Int_t i = 0; i < npts; i++) {
350 memcpy(&points[3 * i], master, 3 * sizeof(Double_t));
351 }
352}
353
354////////////////////////////////////////////////////////////////////////////////
355/// Mesh points for scaled shapes.
356
358{
361 Double_t master[3];
362 Double_t local[3];
363 Int_t index;
364 for (Int_t i = 0; i < npts; i++) {
365 index = 3 * i;
366 local[0] = points[index];
367 local[1] = points[index + 1];
368 local[2] = points[index + 2];
370 points[index] = master[0];
371 points[index + 1] = master[1];
372 points[index + 2] = master[2];
373 }
374}
375
376////////////////////////////////////////////////////////////////////////////////
377/// Check the inside status for each of the points in the array.
378/// Input: Array of point coordinates + vector size
379/// Output: Array of Booleans for the inside of each point
380
382{
383 for (Int_t i = 0; i < vecsize; i++)
384 inside[i] = Contains(&points[3 * i]);
385}
386
387////////////////////////////////////////////////////////////////////////////////
388/// Compute the normal for an array o points so that norm.dot.dir is positive
389/// Input: Arrays of point coordinates and directions + vector size
390/// Output: Array of normal directions
391
393{
394 for (Int_t i = 0; i < vecsize; i++)
395 ComputeNormal(&points[3 * i], &dirs[3 * i], &norms[3 * i]);
396}
397
398////////////////////////////////////////////////////////////////////////////////
399/// Compute distance from array of input points having directions specified by dirs. Store output in dists
400
402 Double_t *step) const
403{
404 for (Int_t i = 0; i < vecsize; i++)
405 dists[i] = DistFromInside(&points[3 * i], &dirs[3 * i], 3, step[i]);
406}
407
408////////////////////////////////////////////////////////////////////////////////
409/// Compute distance from array of input points having directions specified by dirs. Store output in dists
410
412 Double_t *step) const
413{
414 for (Int_t i = 0; i < vecsize; i++)
415 dists[i] = DistFromOutside(&points[3 * i], &dirs[3 * i], 3, step[i]);
416}
417
418////////////////////////////////////////////////////////////////////////////////
419/// Compute safe distance from each of the points in the input array.
420/// Input: Array of point coordinates, array of statuses for these points, size of the arrays
421/// Output: Safety values
422
424{
425 for (Int_t i = 0; i < vecsize; i++)
426 safe[i] = Safety(&points[3 * i], inside[i]);
427}
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)
virtual Int_t GetNmeshVertices() const
Definition TGeoShape.h:134
virtual void GetMeshNumbers(Int_t &, Int_t &, Int_t &) const
Definition TGeoShape.h:132
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:64
virtual void SetPoints(Double_t *points) const =0
TClass * IsA() const override
Definition TGeoShape.h:179
virtual Bool_t IsAssembly() const
Definition TGeoShape.h:137
virtual TBuffer3D * MakeBuffer3D() const
Definition TGeoShape.h:154
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:835
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
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:124