00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef ROOT_TGLPhysicalShape
00014 #define ROOT_TGLPhysicalShape
00015
00016
00017
00018
00019 #ifndef ROOT_TGLBoundingBox
00020 #include "TGLBoundingBox.h"
00021 #endif
00022 #ifndef ROOT_TGLUtil
00023 #include "TGLUtil.h"
00024 #endif
00025
00026 class TGLPShapeRef;
00027 class TGLLogicalShape;
00028 class TGLRnrCtx;
00029
00030 class TContextMenu;
00031
00032
00033 class TGLPhysicalShape
00034 {
00035 friend class TGLLogicalShape;
00036
00037 private:
00038 TGLPhysicalShape(const TGLPhysicalShape&);
00039 TGLPhysicalShape& operator=(const TGLPhysicalShape&);
00040
00041 public:
00042
00043 enum EManip { kTranslateX = 1 << 0,
00044 kTranslateY = 1 << 1,
00045 kTranslateZ = 1 << 2,
00046 kTranslateAll = kTranslateX | kTranslateY | kTranslateZ,
00047 kScaleX = 1 << 3,
00048 kScaleY = 1 << 4,
00049 kScaleZ = 1 << 5,
00050 kScaleAll = kScaleX | kScaleY | kScaleZ,
00051 kRotateX = 1 << 6,
00052 kRotateY = 1 << 7,
00053 kRotateZ = 1 << 8,
00054 kRotateAll = kRotateX | kRotateY | kRotateZ,
00055 kManipAll = kTranslateAll | kScaleAll | kRotateAll
00056 };
00057 private:
00058
00059 const TGLLogicalShape * fLogicalShape;
00060 TGLPhysicalShape* fNextPhysical;
00061 TGLPShapeRef * fFirstPSRef;
00062
00063 UInt_t fID;
00064 TGLMatrix fTransform;
00065 TGLBoundingBox fBoundingBox;
00066 Float_t fColor[17];
00067 UChar_t fSelected;
00068 Bool_t fInvertedWind;
00069 Bool_t fModified;
00070 EManip fManip;
00071
00072
00073 void UpdateBoundingBox();
00074 void InitColor(const Float_t rgba[4]);
00075
00076 public:
00077 TGLPhysicalShape(UInt_t ID, const TGLLogicalShape & logicalShape,
00078 const TGLMatrix & transform, Bool_t invertedWind,
00079 const Float_t rgba[4]);
00080 TGLPhysicalShape(UInt_t ID, const TGLLogicalShape & logicalShape,
00081 const double * transform, Bool_t invertedWind,
00082 const Float_t rgba[4]);
00083 virtual ~TGLPhysicalShape();
00084
00085 void AddReference (TGLPShapeRef* ref);
00086 void RemoveReference(TGLPShapeRef* ref);
00087
00088 UInt_t ID() const { return fID; }
00089 const TGLBoundingBox & BoundingBox() const { return fBoundingBox; }
00090
00091 virtual void CalculateShapeLOD(TGLRnrCtx & rnrCtx, Float_t& pixSize, Short_t& shapeLOD) const;
00092 virtual void QuantizeShapeLOD (Short_t shapeLOD, Short_t combiLOD, Short_t& quantLOD) const;
00093
00094 void SetupGLColors(TGLRnrCtx & rnrCtx, const Float_t* color=0) const;
00095 virtual void Draw(TGLRnrCtx & rnrCtx) const;
00096
00097 const TGLLogicalShape * GetLogical() const { return fLogicalShape; }
00098 const TGLPhysicalShape * GetNextPhysical() const { return fNextPhysical; }
00099
00100
00101 EManip GetManip() const { return fManip; }
00102 void SetManip(EManip manip) { fManip = manip; }
00103
00104
00105 void Modified();
00106 Bool_t IsModified() const { return fModified; }
00107
00108
00109 Bool_t IsSelected() const { return fSelected != 0; }
00110 UChar_t GetSelected() const { return fSelected; }
00111 void Select(UChar_t select) { fSelected = select; }
00112
00113
00114 const Float_t * Color() const { return fColor; }
00115 Bool_t IsTransparent() const { return fColor[3] < 1.f; }
00116 Bool_t IsInvisible() const { return fColor[3] == 0.f; }
00117 void SetColor(const Float_t rgba[17]);
00118 void SetColorOnFamily(const Float_t rgba[17]);
00119 void SetDiffuseColor(const Float_t rgba[4]);
00120 void SetDiffuseColor(const UChar_t rgba[4]);
00121 void SetDiffuseColor(Color_t ci, UChar_t transparency);
00122
00123
00124 TGLVector3 GetScale() const;
00125 TGLVertex3 GetTranslation() const;
00126
00127 void SetTransform(const TGLMatrix & transform);
00128 void SetTransform(const Double_t vals[16]);
00129 void SetTranslation(const TGLVertex3 & translation);
00130 void Translate(const TGLVector3 & vect);
00131 void Scale(const TGLVector3 & scale);
00132 void Rotate(const TGLVertex3 & pivot, const TGLVector3 & axis, Double_t angle);
00133
00134
00135 void InvokeContextMenu(TContextMenu & menu, UInt_t x, UInt_t y) const;
00136
00137 ClassDef(TGLPhysicalShape,0)
00138 };
00139
00140
00141
00142 inline TGLVector3 TGLPhysicalShape::GetScale() const
00143 {
00144 return fTransform.GetScale();
00145 }
00146
00147
00148 inline TGLVertex3 TGLPhysicalShape::GetTranslation() const
00149 {
00150 return fTransform.GetTranslation();
00151 }
00152
00153
00154 inline void TGLPhysicalShape::SetTransform(const TGLMatrix & transform)
00155 {
00156 fTransform = transform;
00157 UpdateBoundingBox();
00158 Modified();
00159 }
00160
00161
00162 inline void TGLPhysicalShape::SetTransform(const Double_t vals[16])
00163 {
00164 fTransform.Set(vals);
00165 UpdateBoundingBox();
00166 Modified();
00167 }
00168
00169
00170 inline void TGLPhysicalShape::SetTranslation(const TGLVertex3 & translation)
00171 {
00172 fTransform.SetTranslation(translation);
00173 UpdateBoundingBox();
00174 Modified();
00175 }
00176
00177
00178 inline void TGLPhysicalShape::Translate(const TGLVector3 & vect)
00179 {
00180 fTransform.Translate(vect);
00181 UpdateBoundingBox();
00182 Modified();
00183 }
00184
00185
00186 inline void TGLPhysicalShape::Scale(const TGLVector3 & scale)
00187 {
00188 TGLVertex3 origCenter = fBoundingBox.Center();
00189 fTransform.Scale(scale);
00190 UpdateBoundingBox();
00191 TGLVector3 shift = fBoundingBox.Center() - origCenter;
00192 Translate(-shift);
00193 UpdateBoundingBox();
00194 Modified();
00195 }
00196
00197
00198 inline void TGLPhysicalShape::Rotate(const TGLVertex3 & pivot, const TGLVector3 & axis, Double_t angle)
00199 {
00200 TGLVertex3 c = BoundingBox().Center();
00201 fTransform.Rotate(pivot, axis, angle);
00202 UpdateBoundingBox();
00203 Modified();
00204 }
00205
00206 #endif // ROOT_TGLPhysicalShape