Logo ROOT   6.14/05
Reference Guide
TGLPhysicalShape.h
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Richard Maunder 25/05/2005
3 // Parts taken from original TGLSceneObject Timur Pocheptsov
4 
5 /*************************************************************************
6  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 #ifndef ROOT_TGLPhysicalShape
14 #define ROOT_TGLPhysicalShape
15 
16 //#ifndef ROOT_TGLLogicalShape
17 //#include "TGLLogicalShape.h"
18 //#endif
19 #include "TGLBoundingBox.h"
20 #ifndef ROOT_TGLUtil
21 #include "TGLUtil.h" // For TGLMatrix
22 #endif
23 
24 class TGLPShapeRef;
25 class TGLLogicalShape;
26 class TGLRnrCtx;
27 
28 class TContextMenu;
29 
30 
32 {
33  friend class TGLLogicalShape; // for replica-list management
34 
35 private:
36  TGLPhysicalShape(const TGLPhysicalShape&); // Not implemented
37  TGLPhysicalShape& operator=(const TGLPhysicalShape&); // Not implemented
38 
39 public:
40  // Flags for permitted manipulation of object
41  enum EManip { kTranslateX = 1 << 0,
42  kTranslateY = 1 << 1,
43  kTranslateZ = 1 << 2,
45  kScaleX = 1 << 3,
46  kScaleY = 1 << 4,
47  kScaleZ = 1 << 5,
49  kRotateX = 1 << 6,
50  kRotateY = 1 << 7,
51  kRotateZ = 1 << 8,
54  };
55 private:
56  // Fields
57  const TGLLogicalShape * fLogicalShape; //! the associated logical shape
58  TGLPhysicalShape* fNextPhysical; //! pointer to next replica
59  TGLPShapeRef * fFirstPSRef; //! pointer to first reference
60 
61  UInt_t fID; //! unique physical ID within containing scene
62  TGLMatrix fTransform; //! transform (placement) of physical instance
63  TGLBoundingBox fBoundingBox; //! bounding box of the physical (transformed)
64  Float_t fColor[17]; //! GL color array
65  EManip fManip; //! permitted manipulation bitflags - see EManip
66  UChar_t fSelected; //! selected state
67  Bool_t fInvertedWind; //! face winding TODO: can get directly from fTransform?
68  Bool_t fModified; //! has been modified - retain across scene rebuilds
70 
71  // Methods
72  void UpdateBoundingBox();
73  void InitColor(const Float_t rgba[4]);
74 
75 public:
76  TGLPhysicalShape(UInt_t ID, const TGLLogicalShape & logicalShape,
77  const TGLMatrix & transform, Bool_t invertedWind,
78  const Float_t rgba[4]);
79  TGLPhysicalShape(UInt_t ID, const TGLLogicalShape & logicalShape,
80  const double * transform, Bool_t invertedWind,
81  const Float_t rgba[4]);
82  virtual ~TGLPhysicalShape();
83 
84  void AddReference (TGLPShapeRef* ref);
85  void RemoveReference(TGLPShapeRef* ref);
86 
87  UInt_t ID() const { return fID; }
88  const TGLBoundingBox & BoundingBox() const { return fBoundingBox; }
89 
90  virtual void CalculateShapeLOD(TGLRnrCtx & rnrCtx, Float_t& pixSize, Short_t& shapeLOD) const;
91  virtual void QuantizeShapeLOD (Short_t shapeLOD, Short_t combiLOD, Short_t& quantLOD) const;
92 
93  void SetupGLColors(TGLRnrCtx & rnrCtx, const Float_t* color=0) const;
94  virtual void Draw(TGLRnrCtx & rnrCtx) const;
95 
96  const TGLLogicalShape * GetLogical() const { return fLogicalShape; }
97  const TGLPhysicalShape * GetNextPhysical() const { return fNextPhysical; }
98 
99  // Modification and manipulation
100  EManip GetManip() const { return fManip; }
101  void SetManip(EManip manip) { fManip = manip; }
102 
103  // Modified - treated as temporary modification
104  void Modified();
105  Bool_t IsModified() const { return fModified; }
106 
107  // Selection
108  Bool_t IsSelected() const { return fSelected != 0; }
109  UChar_t GetSelected() const { return fSelected; }
110  void Select(UChar_t select) { fSelected = select; }
111 
112  // Color
113  const Float_t * Color() const { return fColor; }
114  Bool_t IsTransparent() const { return fColor[3] < 1.f; }
115  Bool_t IsInvisible() const { return fColor[3] == 0.f; }
116  void SetColor(const Float_t rgba[17]);
117  void SetColorOnFamily(const Float_t rgba[17]);
118  void SetDiffuseColor(const Float_t rgba[4]);
119  void SetDiffuseColor(const UChar_t rgba[4]);
120  void SetDiffuseColor(Color_t ci, UChar_t transparency);
121 
122  // Geometry
123  TGLVector3 GetScale() const;
124  TGLVertex3 GetTranslation() const;
125 
126  void SetTransform(const TGLMatrix & transform);
127  void SetTransform(const Double_t vals[16]);
128  void SetTranslation(const TGLVertex3 & translation);
129  void Translate(const TGLVector3 & vect);
130  void Scale(const TGLVector3 & scale);
131  void Rotate(const TGLVertex3 & pivot, const TGLVector3 & axis, Double_t angle);
132 
133  // Context menu
134  void InvokeContextMenu(TContextMenu & menu, UInt_t x, UInt_t y) const;
135 
136  ClassDef(TGLPhysicalShape,0) // a physical (placed, global frame) drawable object
137 };
138 
139 
140 //______________________________________________________________________________
142 {
143  return fTransform.GetScale();
144 }
145 
146 //______________________________________________________________________________
148 {
149  return fTransform.GetTranslation();
150 }
151 
152 //______________________________________________________________________________
153 inline void TGLPhysicalShape::SetTransform(const TGLMatrix & transform)
154 {
155  fTransform = transform;
157  Modified();
158 }
159 
160 //______________________________________________________________________________
161 inline void TGLPhysicalShape::SetTransform(const Double_t vals[16])
162 {
163  fTransform.Set(vals);
165  Modified();
166 }
167 
168 //______________________________________________________________________________
169 inline void TGLPhysicalShape::SetTranslation(const TGLVertex3 & translation)
170 {
171  fTransform.SetTranslation(translation);
173  Modified();
174 }
175 
176 //______________________________________________________________________________
177 inline void TGLPhysicalShape::Translate(const TGLVector3 & vect)
178 {
179  fTransform.Translate(vect);
181  Modified();
182 }
183 
184 //______________________________________________________________________________
185 inline void TGLPhysicalShape::Scale(const TGLVector3 & scale)
186 {
187  TGLVertex3 origCenter = fBoundingBox.Center();
188  fTransform.Scale(scale);
190  TGLVector3 shift = fBoundingBox.Center() - origCenter;
191  Translate(-shift);
193  Modified();
194 }
195 
196 //______________________________________________________________________________
197 inline void TGLPhysicalShape::Rotate(const TGLVertex3 & pivot, const TGLVector3 & axis, Double_t angle)
198 {
200  fTransform.Rotate(pivot, axis, angle);
202  Modified();
203 }
204 
205 #endif // ROOT_TGLPhysicalShape
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition: TGLRnrCtx.h:40
TGLVertex3 Center() const
void InvokeContextMenu(TContextMenu &menu, UInt_t x, UInt_t y) const
Request creation of context menu on shape, attached to &#39;menu&#39; at screen position &#39;x&#39; &#39;y&#39;...
void Translate(const TGLVector3 &vect)
void SetTranslation(Double_t x, Double_t y, Double_t z)
Set matrix translation components x,y,z.
Definition: TGLUtil.cxx:804
void SetColorOnFamily(const Float_t rgba[17])
Set full color attributes to all physicals sharing the same logical with this object.
float Float_t
Definition: RtypesCore.h:53
UInt_t fID
pointer to first reference
16 component (4x4) transform matrix - column MAJOR as per GL.
Definition: TGLUtil.h:596
virtual ~TGLPhysicalShape()
Destroy the physical shape.
void SetupGLColors(TGLRnrCtx &rnrCtx, const Float_t *color=0) const
Setup colors - avoid setting things not required for current draw flags.
Bool_t fModified
face winding TODO: can get directly from fTransform?
UChar_t fSelected
permitted manipulation bitflags - see EManip
void UpdateBoundingBox()
cache
EManip fManip
GL color array.
bool Bool_t
Definition: RtypesCore.h:59
void Modified()
Call this after modifying the physical so that the information can be propagated to the object refere...
const TGLPhysicalShape * GetNextPhysical() const
UChar_t GetSelected() const
Bool_t fInvertedWind
selected state
const TGLLogicalShape * fLogicalShape
virtual void QuantizeShapeLOD(Short_t shapeLOD, Short_t combiLOD, Short_t &quantLOD) const
Factor in scene/vierer LOD and Quantize ...
Concrete physical shape - a GL drawable.
void InitColor(const Float_t rgba[4])
Initialise the colors, using basic RGBA diffuse material color supplied.
EManip GetManip() const
TGLBoundingBox fBoundingBox
transform (placement) of physical instance
Double_t x[n]
Definition: legend1.C:17
void Translate(const TGLVector3 &vect)
Shift matrix translation components by &#39;vect&#39; in parent frame.
Definition: TGLUtil.cxx:830
#define ClassDef(name, id)
Definition: Rtypes.h:320
void SetColor(const Float_t rgba[17])
Set full color attributes - see OpenGL material documentation for full description.
void Set(const TGLVertex3 &origin, const TGLVector3 &zAxis, const TGLVector3 &xAxis=0)
Set matrix which when applied puts local origin at &#39;origin&#39; and the local Z axis in direction &#39;z&#39;...
Definition: TGLUtil.cxx:764
Bool_t IsSelected() const
3 component (x/y/z) vertex class.
Definition: TGLUtil.h:82
void Rotate(const TGLVertex3 &pivot, const TGLVector3 &axis, Double_t angle)
const TGLBoundingBox & BoundingBox() const
Bool_t IsTransparent() const
TGLVector3 GetScale() const
3 component (x/y/z) vector class.
Definition: TGLUtil.h:246
const Float_t * Color() const
short Color_t
Definition: RtypesCore.h:79
TGLVector3 GetTranslation() const
Return the translation component of matrix.
Definition: TGLUtil.cxx:822
void SetManip(EManip manip)
Bool_t IsInvisible() const
TGLPhysicalShape & operator=(const TGLPhysicalShape &)
TGLPhysicalShape * fNextPhysical
the associated logical shape
This class provides an interface to context sensitive popup menus.
Definition: TContextMenu.h:40
unsigned int UInt_t
Definition: RtypesCore.h:42
void Select(UChar_t select)
short Short_t
Definition: RtypesCore.h:35
Base class for references to TGLPysicalShape that need to be notified when the shape is destroyed...
Definition: TGLPShapeRef.h:19
Abstract logical shape - a GL &#39;drawable&#39; - base for all shapes - faceset sphere etc.
TGLVertex3 GetTranslation() const
virtual void Draw(TGLRnrCtx &rnrCtx) const
Draw physical shape, using LOD flags, potential from display list cache.
Bool_t fIsScaleForRnr
has been modified - retain across scene rebuilds
void Scale(const TGLVector3 &scale)
UInt_t ID() const
void AddReference(TGLPShapeRef *ref)
Add reference ref.
double Double_t
Definition: RtypesCore.h:55
Bool_t IsModified() const
TGLPhysicalShape(const TGLPhysicalShape &)
void Rotate(const TGLVertex3 &pivot, const TGLVector3 &axis, Double_t angle)
Update matrix so resulting transform has been rotated about &#39;pivot&#39; (in parent frame), round vector &#39;axis&#39;, through &#39;angle&#39; (radians) Equivalent to glRotate function, but with addition of translation and compounded on top of existing.
Definition: TGLUtil.cxx:898
void SetTransform(const TGLMatrix &transform)
Double_t y[n]
Definition: legend1.C:17
Float_t fColor[17]
bounding box of the physical (transformed)
TGLMatrix fTransform
unique physical ID within containing scene
Concrete class describing an orientated (free) or axis aligned box of 8 vertices. ...
void RemoveReference(TGLPShapeRef *ref)
Remove reference ref.
void Scale(const TGLVector3 &scale)
Set matrix axis scales to &#39;scale&#39;.
Definition: TGLUtil.cxx:862
#define c(i)
Definition: RSha256.hxx:101
unsigned char UChar_t
Definition: RtypesCore.h:34
void SetTranslation(const TGLVertex3 &translation)
virtual void CalculateShapeLOD(TGLRnrCtx &rnrCtx, Float_t &pixSize, Short_t &shapeLOD) const
Calculate shape-lod, suitable for use under projection defined by &#39;rnrCtx&#39;, taking account of which l...
TGLPShapeRef * fFirstPSRef
pointer to next replica
TGLVector3 GetScale() const
Get local axis scaling factors.
Definition: TGLUtil.cxx:1127
const TGLLogicalShape * GetLogical() const
void SetDiffuseColor(const Float_t rgba[4])
Set color from ROOT color index and transparency [0,100].