Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
31 class TGLPhysicalShape
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,
44  kTranslateAll = kTranslateX | kTranslateY | kTranslateZ,
45  kScaleX = 1 << 3,
46  kScaleY = 1 << 4,
47  kScaleZ = 1 << 5,
48  kScaleAll = kScaleX | kScaleY | kScaleZ,
49  kRotateX = 1 << 6,
50  kRotateY = 1 << 7,
51  kRotateZ = 1 << 8,
52  kRotateAll = kRotateX | kRotateY | kRotateZ,
53  kManipAll = kTranslateAll | kScaleAll | kRotateAll
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
69  Bool_t fIsScaleForRnr;//! cache
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 //______________________________________________________________________________
141 inline TGLVector3 TGLPhysicalShape::GetScale() const
142 {
143  return fTransform.GetScale();
144 }
145 
146 //______________________________________________________________________________
147 inline TGLVertex3 TGLPhysicalShape::GetTranslation() const
148 {
149  return fTransform.GetTranslation();
150 }
151 
152 //______________________________________________________________________________
153 inline void TGLPhysicalShape::SetTransform(const TGLMatrix & transform)
154 {
155  fTransform = transform;
156  UpdateBoundingBox();
157  Modified();
158 }
159 
160 //______________________________________________________________________________
161 inline void TGLPhysicalShape::SetTransform(const Double_t vals[16])
162 {
163  fTransform.Set(vals);
164  UpdateBoundingBox();
165  Modified();
166 }
167 
168 //______________________________________________________________________________
169 inline void TGLPhysicalShape::SetTranslation(const TGLVertex3 & translation)
170 {
171  fTransform.SetTranslation(translation);
172  UpdateBoundingBox();
173  Modified();
174 }
175 
176 //______________________________________________________________________________
177 inline void TGLPhysicalShape::Translate(const TGLVector3 & vect)
178 {
179  fTransform.Translate(vect);
180  UpdateBoundingBox();
181  Modified();
182 }
183 
184 //______________________________________________________________________________
185 inline void TGLPhysicalShape::Scale(const TGLVector3 & scale)
186 {
187  TGLVertex3 origCenter = fBoundingBox.Center();
188  fTransform.Scale(scale);
189  UpdateBoundingBox();
190  TGLVector3 shift = fBoundingBox.Center() - origCenter;
191  Translate(-shift);
192  UpdateBoundingBox();
193  Modified();
194 }
195 
196 //______________________________________________________________________________
197 inline void TGLPhysicalShape::Rotate(const TGLVertex3 & pivot, const TGLVector3 & axis, Double_t angle)
198 {
199  TGLVertex3 c = BoundingBox().Center();
200  fTransform.Rotate(pivot, axis, angle);
201  UpdateBoundingBox();
202  Modified();
203 }
204 
205 #endif // ROOT_TGLPhysicalShape