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
162void TShape::Streamer(TBuffer &R__b)
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}
static const double x1[5]
int Int_t
Definition RtypesCore.h:45
short Version_t
Definition RtypesCore.h:65
unsigned int UInt_t
Definition RtypesCore.h:46
const Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
short Color_t
Definition RtypesCore.h:92
float Float_t
Definition RtypesCore.h:57
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
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
point * points
Definition X3DBuffer.c:22
Use this attribute class when an object should have 3D capabilities.
Definition TAtt3D.h:19
Fill Area Attributes class.
Definition TAttFill.h:19
Line Attributes class.
Definition TAttLine.h:18
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:33
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
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 ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=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)
Remove object from the list.
virtual void Add(TObject *obj)
Definition TList.h:81
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
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:1005
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:949
This is the base class for all geometry shapes.
Definition TShape.h:35
virtual void Paint(Option_t *option="")
This method is used only when a shape is painted outside a TNode.
Definition TShape.cxx:142
TShape & operator=(const TShape &)
assignment operator
Definition TShape.cxx:92
virtual void SetPoints(Double_t *points) const
Set points.
Definition TShape.cxx:154
virtual ~TShape()
Shape default destructor.
Definition TShape.cxx:109
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
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
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=0)=0
Double_t Sqrt(Double_t x)
Definition TMath.h:641