Logo ROOT   6.08/07
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 #ifndef ROOT_TGLBoundingBox
20 #include "TGLBoundingBox.h"
21 #endif
22 #ifndef ROOT_TGLUtil
23 #include "TGLUtil.h" // For TGLMatrix
24 #endif
25 
26 class TGLPShapeRef;
27 class TGLLogicalShape;
28 class TGLRnrCtx;
29 
30 class TContextMenu;
31 
32 
34 {
35  friend class TGLLogicalShape; // for replica-list management
36 
37 private:
38  TGLPhysicalShape(const TGLPhysicalShape&); // Not implemented
39  TGLPhysicalShape& operator=(const TGLPhysicalShape&); // Not implemented
40 
41 public:
42  // Flags for permitted manipulation of object
43  enum EManip { kTranslateX = 1 << 0,
44  kTranslateY = 1 << 1,
45  kTranslateZ = 1 << 2,
47  kScaleX = 1 << 3,
48  kScaleY = 1 << 4,
49  kScaleZ = 1 << 5,
51  kRotateX = 1 << 6,
52  kRotateY = 1 << 7,
53  kRotateZ = 1 << 8,
56  };
57 private:
58  // Fields
59  const TGLLogicalShape * fLogicalShape; //! the associated logical shape
60  TGLPhysicalShape* fNextPhysical; //! pointer to next replica
61  TGLPShapeRef * fFirstPSRef; //! pointer to first reference
62 
63  UInt_t fID; //! unique physical ID within containing scene
64  TGLMatrix fTransform; //! transform (placement) of physical instance
65  TGLBoundingBox fBoundingBox; //! bounding box of the physical (transformed)
66  Float_t fColor[17]; //! GL color array
67  EManip fManip; //! permitted manipulation bitflags - see EManip
68  UChar_t fSelected; //! selected state
69  Bool_t fInvertedWind; //! face winding TODO: can get directly from fTransform?
70  Bool_t fModified; //! has been modified - retain across scene rebuilds
72 
73  // Methods
74  void UpdateBoundingBox();
75  void InitColor(const Float_t rgba[4]);
76 
77 public:
78  TGLPhysicalShape(UInt_t ID, const TGLLogicalShape & logicalShape,
79  const TGLMatrix & transform, Bool_t invertedWind,
80  const Float_t rgba[4]);
81  TGLPhysicalShape(UInt_t ID, const TGLLogicalShape & logicalShape,
82  const double * transform, Bool_t invertedWind,
83  const Float_t rgba[4]);
84  virtual ~TGLPhysicalShape();
85 
86  void AddReference (TGLPShapeRef* ref);
87  void RemoveReference(TGLPShapeRef* ref);
88 
89  UInt_t ID() const { return fID; }
90  const TGLBoundingBox & BoundingBox() const { return fBoundingBox; }
91 
92  virtual void CalculateShapeLOD(TGLRnrCtx & rnrCtx, Float_t& pixSize, Short_t& shapeLOD) const;
93  virtual void QuantizeShapeLOD (Short_t shapeLOD, Short_t combiLOD, Short_t& quantLOD) const;
94 
95  void SetupGLColors(TGLRnrCtx & rnrCtx, const Float_t* color=0) const;
96  virtual void Draw(TGLRnrCtx & rnrCtx) const;
97 
98  const TGLLogicalShape * GetLogical() const { return fLogicalShape; }
99  const TGLPhysicalShape * GetNextPhysical() const { return fNextPhysical; }
100 
101  // Modification and manipulation
102  EManip GetManip() const { return fManip; }
103  void SetManip(EManip manip) { fManip = manip; }
104 
105  // Modified - treated as temporary modification
106  void Modified();
107  Bool_t IsModified() const { return fModified; }
108 
109  // Selection
110  Bool_t IsSelected() const { return fSelected != 0; }
111  UChar_t GetSelected() const { return fSelected; }
112  void Select(UChar_t select) { fSelected = select; }
113 
114  // Color
115  const Float_t * Color() const { return fColor; }
116  Bool_t IsTransparent() const { return fColor[3] < 1.f; }
117  Bool_t IsInvisible() const { return fColor[3] == 0.f; }
118  void SetColor(const Float_t rgba[17]);
119  void SetColorOnFamily(const Float_t rgba[17]);
120  void SetDiffuseColor(const Float_t rgba[4]);
121  void SetDiffuseColor(const UChar_t rgba[4]);
122  void SetDiffuseColor(Color_t ci, UChar_t transparency);
123 
124  // Geometry
125  TGLVector3 GetScale() const;
126  TGLVertex3 GetTranslation() const;
127 
128  void SetTransform(const TGLMatrix & transform);
129  void SetTransform(const Double_t vals[16]);
130  void SetTranslation(const TGLVertex3 & translation);
131  void Translate(const TGLVector3 & vect);
132  void Scale(const TGLVector3 & scale);
133  void Rotate(const TGLVertex3 & pivot, const TGLVector3 & axis, Double_t angle);
134 
135  // Context menu
136  void InvokeContextMenu(TContextMenu & menu, UInt_t x, UInt_t y) const;
137 
138  ClassDef(TGLPhysicalShape,0) // a physical (placed, global frame) drawable object
139 };
140 
141 
142 //______________________________________________________________________________
144 {
145  return fTransform.GetScale();
146 }
147 
148 //______________________________________________________________________________
150 {
151  return fTransform.GetTranslation();
152 }
153 
154 //______________________________________________________________________________
155 inline void TGLPhysicalShape::SetTransform(const TGLMatrix & transform)
156 {
157  fTransform = transform;
159  Modified();
160 }
161 
162 //______________________________________________________________________________
163 inline void TGLPhysicalShape::SetTransform(const Double_t vals[16])
164 {
165  fTransform.Set(vals);
167  Modified();
168 }
169 
170 //______________________________________________________________________________
171 inline void TGLPhysicalShape::SetTranslation(const TGLVertex3 & translation)
172 {
173  fTransform.SetTranslation(translation);
175  Modified();
176 }
177 
178 //______________________________________________________________________________
179 inline void TGLPhysicalShape::Translate(const TGLVector3 & vect)
180 {
181  fTransform.Translate(vect);
183  Modified();
184 }
185 
186 //______________________________________________________________________________
187 inline void TGLPhysicalShape::Scale(const TGLVector3 & scale)
188 {
189  TGLVertex3 origCenter = fBoundingBox.Center();
190  fTransform.Scale(scale);
192  TGLVector3 shift = fBoundingBox.Center() - origCenter;
193  Translate(-shift);
195  Modified();
196 }
197 
198 //______________________________________________________________________________
199 inline void TGLPhysicalShape::Rotate(const TGLVertex3 & pivot, const TGLVector3 & axis, Double_t angle)
200 {
202  fTransform.Rotate(pivot, axis, angle);
204  Modified();
205 }
206 
207 #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
return c
UInt_t fID
pointer to first reference
16 component (4x4) transform matrix - column MAJOR as per GL.
Definition: TGLUtil.h:600
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:254
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:86
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:250
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:44
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
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].