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
27
28/** \class TShape
29\ingroup g3d
30
31This is the base class for all geometry shapes.
32/The list of shapes currently supported correspond to the shapes
33in Geant version 3:
34
35~~~ {.cpp}
36 TBRIK,TCONE,TCONS,TGTRA,TPARA,TPCON,TPGON
37 TTRAP,TTRD1,TTRD2,THYPE, TTUBE and TTUBS.
38~~~
39
40The figure below shows instances of all these shapes. This figure
41is generated by the ROOT 3-D viewer.
42
43\image html g3d_tshape_classtree.png
44\image html g3d_shapes.png
45*/
46
47////////////////////////////////////////////////////////////////////////////////
48/// Shape default constructor
49
51{
52 fVisibility = 1;
53 fMaterial = 0;
54 fNumber = 0;
55}
56
57////////////////////////////////////////////////////////////////////////////////
58/// Shape normal constructor
59
60TShape::TShape(const char *name,const char *title, const char *materialname)
61 : TNamed (name, title), TAttLine(), TAttFill()
62{
63 fVisibility = 1;
64 if (!gGeometry) gGeometry = new TGeometry("Geometry","Default Geometry");
65 fMaterial = gGeometry->GetMaterial(materialname);
68#ifdef WIN32
69 // The color "1" - default produces a very bad 3D image with OpenGL
70 Color_t lcolor = 16;
71 SetLineColor(lcolor);
72#endif
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// copy constructor
77
79 TNamed(ts),
80 TAttLine(ts),
81 TAttFill(ts),
82 TAtt3D(ts),
83 fNumber(ts.fNumber),
84 fVisibility(ts.fVisibility),
85 fMaterial(ts.fMaterial)
86{
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// assignment operator
91
93{
94 if (this!=&ts) {
96 TAttLine::operator=(ts);
97 TAttFill::operator=(ts);
98 TAtt3D::operator=(ts);
102 }
103 return *this;
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// Shape default destructor
108
110{
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// Distance to primitive.
116
118{
119 Int_t dist = 9999;
120
121 TView *view = gPad->GetView();
122 if (!(numPoints && view)) return dist;
123
124 Double_t *points = new Double_t[3*numPoints];
126 Double_t dpoint2, x1, y1, xndc[3];
127 for (Int_t i = 0; i < numPoints; i++) {
128 if (gGeometry) gGeometry->Local2Master(&points[3*i],&points[3*i]);
129 view->WCtoNDC(&points[3*i], xndc);
130 x1 = gPad->XtoAbsPixel(xndc[0]);
131 y1 = gPad->YtoAbsPixel(xndc[1]);
132 dpoint2= (px-x1)*(px-x1) + (py-y1)*(py-y1);
133 if (dpoint2 < dist) dist = (Int_t)dpoint2;
134 }
135 delete [] points;
136 return Int_t(TMath::Sqrt(Float_t(dist)));
137}
138
139////////////////////////////////////////////////////////////////////////////////
140/// This method is used only when a shape is painted outside a TNode.
141
143{
144 TVirtualViewer3D * viewer3D = gPad->GetViewer3D();
145 if (viewer3D) {
146 const TBuffer3D & buffer = GetBuffer3D(TBuffer3D::kAll);
147 viewer3D->AddObject(buffer);
148 }
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// Set points.
153
155{
156 AbstractMethod("SetPoints(Double_t *buffer) const");
157}
158
159////////////////////////////////////////////////////////////////////////////////
160/// Stream an object of class TShape.
161
163{
164 if (R__b.IsReading()) {
165 UInt_t R__s, R__c;
166 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
167 if (R__v > 1) {
168 R__b.ReadClassBuffer(TShape::Class(), this, R__v, R__s, R__c);
169 return;
170 }
171 //====process old versions before automatic schema evolution
172 TNamed::Streamer(R__b);
173 TAttLine::Streamer(R__b);
174 TAttFill::Streamer(R__b);
175 TAtt3D::Streamer(R__b);
176 R__b >> fNumber;
177 R__b >> fVisibility;
178 R__b >> fMaterial;
179 R__b.CheckByteCount(R__s, R__c, TShape::IsA());
180 //====end of old versions
181
182 } else {
183 R__b.WriteClassBuffer(TShape::Class(),this);
184 }
185}
186
187////////////////////////////////////////////////////////////////////////////////
188/// Transform points (LocalToMaster)
189
191{
192 if (gGeometry && points) {
193 Double_t dlocal[3];
194 Double_t dmaster[3];
195 for (UInt_t j=0; j<NbPnts; j++) {
196 dlocal[0] = points[3*j];
197 dlocal[1] = points[3*j+1];
198 dlocal[2] = points[3*j+2];
199 gGeometry->Local2Master(&dlocal[0],&dmaster[0]);
200 points[3*j] = dmaster[0];
201 points[3*j+1] = dmaster[1];
202 points[3*j+2] = dmaster[2];
203 }
204 }
205}
206
207////////////////////////////////////////////////////////////////////////////////
208/// We have to set kRawSize (unless already done) to allocate buffer space
209/// before kRaw can be filled
210
211void TShape::FillBuffer3D(TBuffer3D & buffer, Int_t reqSections) const
212{
213 if (reqSections & TBuffer3D::kRaw)
214 {
215 if (!(reqSections & TBuffer3D::kRawSizes) && !buffer.SectionsValid(TBuffer3D::kRawSizes))
216 {
217 assert(kFALSE);
218 }
219 }
220
221 if (reqSections & TBuffer3D::kCore) {
222 buffer.ClearSectionsValid();
223
224 // We are only filling TBuffer3D in the master frame. Therefore the shape
225 // described in buffer is a specific placement - and this needs to be
226 // identified uniquely. Use the current node set in TNode::Paint which calls us
227 buffer.fID = gNode;
228 buffer.fColor = GetLineColor();
229 buffer.fTransparency = 0;
230 buffer.fLocalFrame = kFALSE; // Only support master frame for these shapes
231 buffer.fReflection = kFALSE;
232
233 buffer.SetLocalMasterIdentity();
235 }
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Get basic color.
240
242{
243 Int_t basicColor = ((GetLineColor() %8) -1) * 4;
244 if (basicColor < 0) basicColor = 0;
245
246 return basicColor;
247}
248
249////////////////////////////////////////////////////////////////////////////////
250/// Stub to avoid forcing implementation at this stage
251
252const TBuffer3D &TShape::GetBuffer3D(Int_t /* reqSections */ ) const
253{
254 static TBuffer3D buffer(TBuffer3DTypes::kGeneric);
255 Warning("GetBuffer3D", "this must be implemented for shapes in a TNode::Paint hierarchy. This will become a pure virtual fn eventually.");
256 return buffer;
257}
int Int_t
Definition RtypesCore.h:45
short Color_t
Definition RtypesCore.h:92
short Version_t
Definition RtypesCore.h:65
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
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:19
virtual void Streamer(TBuffer &)
Line Attributes class.
Definition TAttLine.h:18
virtual void Streamer(TBuffer &)
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:33
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 Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
Bool_t IsReading() const
Definition TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
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:51
void AbstractMethod(const char *method) const
Use this method to implement an "abstract" method that you don't want to leave purely abstract.
Definition TObject.cxx:1029
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:973
This is the base class for all geometry shapes.
Definition TShape.h:35
TShape & operator=(const TShape &)
assignment operator
Definition TShape.cxx:92
static TClass * Class()
virtual void SetPoints(Double_t *points) const
Set points.
Definition TShape.cxx:154
void Streamer(TBuffer &) override
Stream an object of class TShape.
Definition TShape.cxx:162
void Paint(Option_t *option="") override
This method is used only when a shape is painted outside a TNode.
Definition TShape.cxx:142
Int_t GetBasicColor() const
Get basic color.
Definition TShape.cxx:241
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:117
virtual const TBuffer3D & GetBuffer3D(Int_t reqSections) const
Stub to avoid forcing implementation at this stage.
Definition TShape.cxx:252
TShape()
Shape default constructor.
Definition TShape.cxx:50
~TShape() override
Shape default destructor.
Definition TShape.cxx:109
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:211
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:190
See TView3D.
Definition TView.h:25
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)=0
Abstract 3D shapes viewer.
virtual Int_t AddObject(const TBuffer3D &buffer, Bool_t *addChildren=nullptr)=0
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:662