glc_3dviewinstance.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00025 #ifndef GLC_3DVIEWINSTANCE_H_
00026 #define GLC_3DVIEWINSTANCE_H_
00027
00028 #include "../glc_global.h"
00029 #include "../glc_boundingbox.h"
00030 #include "../glc_object.h"
00031 #include "../maths/glc_matrix4x4.h"
00032 #include "../glc_state.h"
00033 #include "../geometry/glc_3drep.h"
00034 #include "../shading/glc_renderproperties.h"
00035
00036 #include <QMutex>
00037
00038 #include "../glc_config.h"
00039
00040 class GLC_Viewport;
00041
00044
00051
00052
00053 class GLC_LIB_EXPORT GLC_3DViewInstance : public GLC_Object
00054 {
00055 public:
00057 enum Viewable
00058 {
00059 FullViewable= 120,
00060 PartialViewable= 121,
00061 NoViewable= 122
00062 };
00064
00066
00067 public:
00069 GLC_3DViewInstance();
00070
00072 GLC_3DViewInstance(GLC_Geometry* pGeom);
00073
00075 GLC_3DViewInstance(const GLC_3DRep&);
00076
00078 GLC_3DViewInstance(const GLC_3DViewInstance& );
00079
00081 GLC_3DViewInstance &operator=(const GLC_3DViewInstance&);
00082
00084 ~GLC_3DViewInstance();
00085
00087
00089
00091
00092 public:
00094 inline bool isTransparent() const;
00095
00097 inline bool hasTransparentMaterials() const;
00098
00100 inline bool isEmpty() const
00101 {return m_3DRep.isEmpty();}
00102
00104 inline bool isSelected(void) const
00105 {return m_RenderProperties.isSelected();}
00106
00108 inline int numberOfGeometry() const
00109 {return m_3DRep.numberOfBody();}
00110
00111
00113 inline GLC_Geometry* geomAt(int index) const
00114 {
00115 if (!m_3DRep.isEmpty()) return m_3DRep.geomAt(index);
00116 else return NULL;
00117 }
00118
00120 GLC_BoundingBox boundingBox();
00121
00123 inline bool boundingBoxValidity() const
00124 {return (m_pBoundingBox != NULL) && m_IsBoundingBoxValid && m_3DRep.boundingBoxIsValid();}
00125
00127 inline const GLC_Matrix4x4& matrix() const
00128 {return m_AbsoluteMatrix;}
00129
00131 GLC_3DViewInstance deepCopy() const;
00132
00134 GLC_3DViewInstance instanciate();
00135
00137
00138 inline GLenum polygonMode() const
00139 {return m_RenderProperties.polygonMode();}
00140
00142 inline GLC_RenderProperties* renderPropertiesHandle()
00143 {return &m_RenderProperties;}
00144
00146 inline bool isVisible() const
00147 {return m_IsVisible;}
00148
00150 inline GLC_3DViewInstance::Viewable viewableFlag() const
00151 {return m_ViewableFlag;}
00152
00154 inline bool isGeomViewable(int index) const
00155 {return m_ViewableGeomFlag.at(index);}
00156
00158 inline unsigned int numberOfFaces() const
00159 {return m_3DRep.faceCount();}
00160
00162 inline unsigned int numberOfVertex() const
00163 {return m_3DRep.vertexCount();}
00164
00166 inline unsigned int numberOfMaterials() const
00167 {return m_3DRep.materialCount();}
00168
00170 inline QSet<GLC_Material*> materialSet() const
00171 {return m_3DRep.materialSet();}
00172
00174 inline int defaultLodValue() const
00175 {return m_DefaultLOD;}
00176
00178 inline GLC_3DRep representation() const
00179 {return m_3DRep;}
00180
00182 inline int numberOfBody() const
00183 {return m_3DRep.numberOfBody();}
00184
00186 inline static int globalDefaultLod()
00187 {
00188 return m_GlobalDefaultLOD;
00189 }
00190
00192
00194
00196
00197 public:
00198
00200
00203 bool setGeometry(GLC_Geometry* pGeom);
00204
00206 inline void removeEmptyGeometry()
00207 {m_3DRep.clean();}
00208
00210 inline void reverseGeometriesNormals()
00211 {m_3DRep.reverseNormals();}
00212
00214 GLC_3DViewInstance& translate(double Tx, double Ty, double Tz);
00215
00217 inline GLC_3DViewInstance& translate(const GLC_Vector3d& v)
00218 {
00219 return translate(v.x(), v.y(), v.z());
00220 }
00221
00223 GLC_3DViewInstance& multMatrix(const GLC_Matrix4x4 &MultMat);
00224
00226 GLC_3DViewInstance& setMatrix(const GLC_Matrix4x4 &SetMat);
00227
00229 GLC_3DViewInstance& resetMatrix(void);
00230
00232
00234 inline void setPolygonMode(GLenum Face, GLenum Mode)
00235 {m_RenderProperties.setPolygonMode(Face, Mode);}
00236
00238 inline void select(bool primitive)
00239 {m_RenderProperties.select(primitive);}
00240
00242 inline void unselect(void)
00243 {m_RenderProperties.unselect();}
00244
00246 inline void setVisibility(bool visibility)
00247 {m_IsVisible= visibility;}
00248
00250 inline void setId(const GLC_uint id)
00251 {
00252 GLC_Object::setId(id);
00253 glc::encodeRgbId(m_Uid, m_colorId);
00254 }
00255
00257 inline void setDefaultLodValue(int lod)
00258 {
00259 m_DefaultLOD= lod;
00260 }
00261
00263 inline bool setViewable(GLC_3DViewInstance::Viewable flag);
00264
00266 inline void setGeomViewable(int index, bool flag)
00267 {m_ViewableGeomFlag[index]= flag;}
00268
00269
00271 static void setGlobalDefaultLod(int);
00272
00274 inline void setRenderProperties(const GLC_RenderProperties& renderProperties)
00275 {m_RenderProperties= renderProperties;}
00276
00278
00280
00282
00283 public:
00285 void render(glc::RenderFlag renderFlag= glc::ShadingFlag, bool useLoad= false, GLC_Viewport* pView= NULL);
00286
00288 void renderForBodySelection();
00289
00291 int renderForPrimitiveSelection(GLC_uint);
00292
00293
00294 private:
00296 inline void OpenglVisProperties()
00297 {
00298
00299 glPolygonMode(m_RenderProperties.polyFaceMode(), m_RenderProperties.polygonMode());
00300
00301 glMultMatrixd(m_AbsoluteMatrix.getData());
00302 }
00303
00304
00306
00308
00310 private:
00312 void computeBoundingBox(void);
00313
00315 void clear();
00316
00318 int choseLod(const GLC_BoundingBox&, GLC_Viewport*, bool);
00319
00321
00323 private:
00324
00326 GLC_3DRep m_3DRep;
00327
00329 GLC_BoundingBox* m_pBoundingBox;
00330
00332 GLC_Matrix4x4 m_AbsoluteMatrix;
00333
00335 bool m_IsBoundingBoxValid;
00336
00338 GLC_RenderProperties m_RenderProperties;
00339
00341 bool m_IsVisible;
00342
00344 GLubyte m_colorId[4];
00345
00347 int m_DefaultLOD;
00348
00350 Viewable m_ViewableFlag;
00351
00353 QVector<bool> m_ViewableGeomFlag;
00354
00356 static QMutex m_Mutex;
00357
00359 static int m_GlobalDefaultLOD;
00360
00361
00362 };
00363
00364
00365 bool GLC_3DViewInstance::isTransparent() const
00366 {
00367 if (m_3DRep.isEmpty()) return false;
00368 if (m_RenderProperties.renderingMode() == glc::OverwriteTransparency) return true;
00369 if (m_RenderProperties.renderingMode() == glc::OverwriteMaterial)
00370 {
00371 return m_RenderProperties.overwriteMaterial()->isTransparent();
00372 }
00373 const int size= m_3DRep.numberOfBody();
00374 bool result= true;
00375 int i= 0;
00376 while((i < size) && result)
00377 {
00378 result= result && m_3DRep.geomAt(i)->isTransparent();
00379 ++i;
00380 }
00381 return result && m_RenderProperties.needToRenderWithTransparency();
00382 }
00383
00384
00385 bool GLC_3DViewInstance::hasTransparentMaterials() const
00386 {
00387 if (m_3DRep.isEmpty()) return false;
00388 if (m_RenderProperties.needToRenderWithTransparency()) return true;
00389 const int size= m_3DRep.numberOfBody();
00390 bool result= false;
00391 int i= 0;
00392 while ((i < size) && !result)
00393 {
00394 result= result || m_3DRep.geomAt(i)->hasTransparentMaterials();
00395 ++i;
00396 }
00397 return result;
00398 }
00400 bool GLC_3DViewInstance::setViewable(GLC_3DViewInstance::Viewable flag)
00401 {
00402 const int bodyCount= m_3DRep.numberOfBody();
00403 if (bodyCount != m_ViewableGeomFlag.size())
00404 {
00405 m_ViewableGeomFlag.fill(true, bodyCount);
00406 }
00407 bool asChange= m_ViewableFlag != flag;
00408 if (asChange)
00409 {
00410 m_ViewableFlag= flag;
00411 if (flag != GLC_3DViewInstance::PartialViewable)
00412 {
00413 bool viewable= (flag == GLC_3DViewInstance::FullViewable);
00414
00415 for (int i= 0; i < bodyCount; ++i)
00416 {
00417 m_ViewableGeomFlag[i]= viewable;
00418 }
00419 }
00420 }
00421 return asChange;
00422 }
00423
00424
00425 #endif