Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TShape.cxx
Go to the documentation of this file.
1// @(#)root/g3d:$Id$
2// Author: Nenad Buncic 17/09/95
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 "TNode.h"
13#include "TShape.h"
14#include "TView.h"
15#include "TVirtualPad.h"
16#include "TGeometry.h"
17#include "TMaterial.h"
18#include "TBuffer.h"
19#include "TBuffer3D.h"
20#include "TBuffer3DTypes.h"
21#include "TVirtualViewer3D.h"
22#include "TMath.h"
23
24#include <cassert>
25
26
27/** \class TShape
28\ingroup g3d
29
30This is the base class for all geometry shapes.
31/The list of shapes currently supported correspond to the shapes
32in Geant version 3:
33
34~~~ {.cpp}
35 TBRIK,TCONE,TCONS,TGTRA,TPARA,TPCON,TPGON
36 TTRAP,TTRD1,TTRD2,THYPE, TTUBE and TTUBS.
37~~~
38
39The figure below shows instances of all these shapes. This figure
40is generated by the ROOT 3-D viewer.
41
42\image html g3d_tshape_classtree.png
43\image html g3d_shapes.png
44*/
45
46////////////////////////////////////////////////////////////////////////////////
47/// Shape default constructor
48
50{
51 fVisibility = 1;
52 fMaterial = nullptr;
53 fNumber = 0;
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// Shape normal constructor
58
59TShape::TShape(const char *name,const char *title, const char *materialname)
60 : TNamed (name, title), TAttLine(), TAttFill()
61{
62 fVisibility = 1;
63 if (!gGeometry) gGeometry = new TGeometry("Geometry","Default Geometry");
67#ifdef WIN32
68 // The color "1" - default produces a very bad 3D image with OpenGL
69 Color_t lcolor = 16;
71#endif
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// copy constructor
76
78 TNamed(ts),
79 TAttLine(ts),
80 TAttFill(ts),
81 TAtt3D(ts),
82 fNumber(ts.fNumber),
83 fVisibility(ts.fVisibility),
84 fMaterial(ts.fMaterial)
85{
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// assignment operator
90
92{
93 if (this!=&ts) {
95 TAttLine::operator=(ts);
96 TAttFill::operator=(ts);
97 TAtt3D::operator=(ts);
98 fNumber=ts.fNumber;
99 fVisibility=ts.fVisibility;
100 fMaterial=ts.fMaterial;
101 }
102 return *this;
103}
104
105////////////////////////////////////////////////////////////////////////////////
106/// Shape default destructor
107
112
113////////////////////////////////////////////////////////////////////////////////
114/// Distance to primitive.
115
117{
118 Int_t dist = 9999;
119
120 TView *view = gPad->GetView();
121 if (!(numPoints && view)) return dist;
122
123 Double_t *points = new Double_t[3*numPoints];
125 Double_t dpoint2, x1, y1, xndc[3];
126 for (Int_t i = 0; i < numPoints; i++) {
127 if (gGeometry) gGeometry->Local2Master(&points[3*i],&points[3*i]);
128 view->WCtoNDC(&points[3*i], xndc);
129 x1 = gPad->XtoAbsPixel(xndc[0]);
130 y1 = gPad->YtoAbsPixel(xndc[1]);
131 dpoint2= (px-x1)*(px-x1) + (py-y1)*(py-y1);
132 if (dpoint2 < dist) dist = (Int_t)dpoint2;
133 }
134 delete [] points;
135 return Int_t(TMath::Sqrt(Float_t(dist)));
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// This method is used only when a shape is painted outside a TNode.
140
142{
143 TVirtualViewer3D * viewer3D = gPad->GetViewer3D();
144 if (viewer3D) {
145 const TBuffer3D & buffer = GetBuffer3D(TBuffer3D::kAll);
146 viewer3D->AddObject(buffer);
147 }
148}
149
150////////////////////////////////////////////////////////////////////////////////
151/// Set points.
152
154{
155 AbstractMethod("SetPoints(Double_t *buffer) const");
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// Stream an object of class TShape.
160
162{
163 if (R__b.IsReading()) {
165 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
166 if (R__v > 1) {
167 R__b.ReadClassBuffer(TShape::Class(), this, R__v, R__s, R__c);
168 return;
169 }
170 //====process old versions before automatic schema evolution
175 R__b >> fNumber;
176 R__b >> fVisibility;
177 R__b >> fMaterial;
178 R__b.CheckByteCount(R__s, R__c, TShape::IsA());
179 //====end of old versions
180
181 } else {
182 R__b.WriteClassBuffer(TShape::Class(),this);
183 }
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// Transform points (LocalToMaster)
188
190{
191 if (gGeometry && points) {
192 Double_t dlocal[3];
193 Double_t dmaster[3];
194 for (UInt_t j=0; j<NbPnts; j++) {
195 dlocal[0] = points[3*j];
196 dlocal[1] = points[3*j+1];
197 dlocal[2] = points[3*j+2];
199 points[3*j] = dmaster[0];
200 points[3*j+1] = dmaster[1];
201 points[3*j+2] = dmaster[2];
202 }
203 }
204}
205
206////////////////////////////////////////////////////////////////////////////////
207/// We have to set kRawSize (unless already done) to allocate buffer space
208/// before kRaw can be filled
209
211{
213 {
215 {
216 assert(kFALSE);
217 }
218 }
219
221 buffer.ClearSectionsValid();
222
223 // We are only filling TBuffer3D in the master frame. Therefore the shape
224 // described in buffer is a specific placement - and this needs to be
225 // identified uniquely. Use the current node set in TNode::Paint which calls us
226 buffer.fID = gNode;
227 buffer.fColor = GetLineColor();
228 buffer.fTransparency = 0;
229 buffer.fLocalFrame = kFALSE; // Only support master frame for these shapes
230 buffer.fReflection = kFALSE;
231
232 buffer.SetLocalMasterIdentity();
234 }
235}
236
237////////////////////////////////////////////////////////////////////////////////
238/// Get basic color.
239
241{
242 Int_t basicColor = ((GetLineColor() %8) -1) * 4;
243 if (basicColor < 0) basicColor = 0;
244
245 return basicColor;
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Stub to avoid forcing implementation at this stage
250
251const TBuffer3D &TShape::GetBuffer3D(Int_t /* reqSections */ ) const
252{
253 static TBuffer3D buffer(TBuffer3DTypes::kGeneric);
254 Warning("GetBuffer3D", "this must be implemented for shapes in a TNode::Paint hierarchy. This will become a pure virtual fn eventually.");
255 return buffer;
256}
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
short Color_t
Color number (short)
Definition RtypesCore.h:99
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
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 SetLineColor
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t points
Option_t Option_t TPoint TPoint const char y1
char name[80]
Definition TGX11.cxx:110
R__EXTERN TGeometry * gGeometry
Definition TGeometry.h:158
R__EXTERN TNode * gNode
Definition TShape.h:68
#define gPad
Use this attribute class when an object should have 3D capabilities.
Definition TAtt3D.h:19
virtual void Streamer(TBuffer &)
Fill Area Attributes class.
Definition TAttFill.h:20
virtual void Streamer(TBuffer &)
Line Attributes class.
Definition TAttLine.h:20
virtual void Streamer(TBuffer &)
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:35
Generic 3D primitive description class.
Definition TBuffer3D.h:18
void SetLocalMasterIdentity()
Set kRaw tessellation section of buffer with supplied sizes.
Bool_t SectionsValid(UInt_t mask) const
Definition TBuffer3D.h:67
void ClearSectionsValid()
Clear any sections marked valid.
void SetSectionsValid(UInt_t mask)
Definition TBuffer3D.h:65
Bool_t fLocalFrame
Definition TBuffer3D.h:90
Int_t fColor
Definition TBuffer3D.h:88
Short_t fTransparency
Definition TBuffer3D.h:89
Bool_t fReflection
Definition TBuffer3D.h:91
TObject * fID
Definition TBuffer3D.h:87
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
TGeometry description.
Definition TGeometry.h:39
virtual void Local2Master(Double_t *local, Double_t *master)
Convert one point from local system to master reference system.
TMaterial * GetMaterial(const char *name) const
Return pointer to Material with name.
THashList * GetListOfShapes() const
Definition TGeometry.h:75
TObject * Remove(TObject *obj) override
Remove object from the list.
void Add(TObject *obj) override
Definition TList.h:81
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
void Streamer(TBuffer &) override
Stream an object of class TObject.
TNamed & operator=(const TNamed &rhs)
TNamed assignment operator.
Definition TNamed.cxx:50
void AbstractMethod(const char *method) const
Call this function within a function that you don't want to define as purely virtual,...
Definition TObject.cxx:1122
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
This is the base class for all geometry shapes.
Definition TShape.h:35
TShape & operator=(const TShape &)
assignment operator
Definition TShape.cxx:91
static TClass * Class()
virtual void SetPoints(Double_t *points) const
Set points.
Definition TShape.cxx:153
void Streamer(TBuffer &) override
Stream an object of class TShape.
Definition TShape.cxx:161
void Paint(Option_t *option="") override
This method is used only when a shape is painted outside a TNode.
Definition TShape.cxx:141
Int_t GetBasicColor() const
Get basic color.
Definition TShape.cxx:240
Int_t fVisibility
Definition TShape.h:39
Int_t ShapeDistancetoPrimitive(Int_t numPoints, Int_t px, Int_t py)
Distance to primitive.
Definition TShape.cxx:116
virtual const TBuffer3D & GetBuffer3D(Int_t reqSections) const
Stub to avoid forcing implementation at this stage.
Definition TShape.cxx:251
TShape()
Shape default constructor.
Definition TShape.cxx:49
~TShape() override
Shape default destructor.
Definition TShape.cxx:108
virtual void FillBuffer3D(TBuffer3D &buffer, Int_t reqSections) const
We have to set kRawSize (unless already done) to allocate buffer space before kRaw can be filled.
Definition TShape.cxx:210
Int_t fNumber
Definition TShape.h:38
TClass * IsA() const override
Definition TShape.h:65
TMaterial * fMaterial
Definition TShape.h:40
void TransformPoints(Double_t *points, UInt_t NbPnts) const
Transform points (LocalToMaster)
Definition TShape.cxx:189
See TView3D.
Definition TView.h:25
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)=0
Abstract 3D shapes viewer.
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:673