TGLPhysicalShape.h

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLPhysicalShape.h 32465 2010-03-04 20:29:52Z matevz $
00002 // Author:  Richard Maunder  25/05/2005
00003 // Parts taken from original TGLSceneObject Timur Pocheptsov
00004 
00005 /*************************************************************************
00006  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
00007  * All rights reserved.                                                  *
00008  *                                                                       *
00009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00011  *************************************************************************/
00012 
00013 #ifndef ROOT_TGLPhysicalShape
00014 #define ROOT_TGLPhysicalShape
00015 
00016 //#ifndef ROOT_TGLLogicalShape
00017 //#include "TGLLogicalShape.h"
00018 //#endif
00019 #ifndef ROOT_TGLBoundingBox
00020 #include "TGLBoundingBox.h"
00021 #endif
00022 #ifndef ROOT_TGLUtil
00023 #include "TGLUtil.h" // For TGLMatrix
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; // for replica-list management
00036 
00037 private:
00038    TGLPhysicalShape(const TGLPhysicalShape&);            // Not implemented
00039    TGLPhysicalShape& operator=(const TGLPhysicalShape&); // Not implemented
00040 
00041 public:
00042    // Flags for permitted manipulation of object
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    // Fields
00059    const TGLLogicalShape * fLogicalShape; //! the associated logical shape
00060          TGLPhysicalShape* fNextPhysical; //! pointer to next replica
00061          TGLPShapeRef    * fFirstPSRef;   //! pointer to first reference
00062 
00063    UInt_t                  fID;           //! unique physical ID within containing scene
00064    TGLMatrix               fTransform;    //! transform (placement) of physical instance
00065    TGLBoundingBox          fBoundingBox;  //! bounding box of the physical (transformed)
00066    Float_t                 fColor[17];    //! GL color array
00067    UChar_t                 fSelected;     //! selected state
00068    Bool_t                  fInvertedWind; //! face winding TODO: can get directly from fTransform?
00069    Bool_t                  fModified;     //! has been modified - retain across scene rebuilds
00070    EManip                  fManip;        //! permitted manipulation bitflags - see EManip
00071 
00072    // Methods
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    // Modification and manipulation
00101    EManip  GetManip()   const      { return fManip;  }
00102    void    SetManip(EManip manip)  { fManip = manip; }
00103 
00104    // Modified - treated as temporary modification
00105    void    Modified();
00106    Bool_t  IsModified() const      { return fModified; }
00107 
00108    // Selection
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    // Color
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    // Geometry
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    // Context menu
00135    void             InvokeContextMenu(TContextMenu & menu, UInt_t x, UInt_t y) const;
00136 
00137    ClassDef(TGLPhysicalShape,0) // a physical (placed, global frame) drawable object
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

Generated on Tue Jul 5 14:16:49 2011 for ROOT_528-00b_version by  doxygen 1.5.1