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
00023
00024
00026
00027 #ifndef GLC_3DVIEWINSTANCE_H_
00028 #define GLC_3DVIEWINSTANCE_H_
00029
00030 #include "../glc_global.h"
00031 #include "../glc_boundingbox.h"
00032 #include "../glc_object.h"
00033 #include "../maths/glc_matrix4x4.h"
00034 #include "../glc_state.h"
00035 #include "../geometry/glc_3drep.h"
00036 #include "../shading/glc_renderproperties.h"
00037
00038 #include <QMutex>
00039
00040 #include "glc_config.h"
00041
00042 class GLC_Viewport;
00043
00046
00053
00054
00055 class GLC_LIB_EXPORT GLC_3DViewInstance : public GLC_Object
00056 {
00057 public:
00059 enum Viewable
00060 {
00061 FullViewable= 120,
00062 PartialViewable= 121,
00063 NoViewable= 122
00064 };
00066
00068
00069 public:
00071 GLC_3DViewInstance();
00072
00074 GLC_3DViewInstance(GLC_Geometry* pGeom);
00075
00077 GLC_3DViewInstance(const GLC_3DRep&);
00078
00080 GLC_3DViewInstance(const GLC_3DViewInstance& );
00081
00083 GLC_3DViewInstance &operator=(const GLC_3DViewInstance&);
00084
00086 ~GLC_3DViewInstance();
00087
00089
00091
00093
00094 public:
00096 inline bool isTransparent() const;
00097
00099 inline bool hasTransparentMaterials() const;
00100
00102 inline bool isEmpty() const
00103 {return m_3DRep.isEmpty();}
00104
00106 inline bool isSelected(void) const
00107 {return m_RenderProperties.isSelected();}
00108
00110 inline int numberOfGeometry() const
00111 {return m_3DRep.numberOfBody();}
00112
00113
00115 inline GLC_Geometry* geomAt(int index) const
00116 {
00117 if (!m_3DRep.isEmpty()) return m_3DRep.geomAt(index);
00118 else return NULL;
00119 }
00120
00122 GLC_BoundingBox boundingBox();
00123
00125 inline bool boundingBoxValidity() const
00126 {return (m_pBoundingBox != NULL) && m_IsBoundingBoxValid && m_3DRep.boundingBoxIsValid();}
00127
00129 inline const GLC_Matrix4x4& matrix() const
00130 {return m_AbsoluteMatrix;}
00131
00133 GLC_3DViewInstance deepCopy() const;
00134
00136 GLC_3DViewInstance instanciate();
00137
00139
00140 inline GLenum polygonMode() const
00141 {return m_RenderProperties.polygonMode();}
00142
00144 inline GLC_RenderProperties* renderPropertiesHandle()
00145 {return &m_RenderProperties;}
00146
00148 inline bool isVisible() const
00149 {return m_IsVisible;}
00150
00152 inline GLC_3DViewInstance::Viewable viewableFlag() const
00153 {return m_ViewableFlag;}
00154
00156 inline bool isGeomViewable(int index) const
00157 {return m_ViewableGeomFlag.at(index);}
00158
00160 inline unsigned int numberOfFaces() const
00161 {return m_3DRep.faceCount();}
00162
00164 inline unsigned int numberOfVertex() const
00165 {return m_3DRep.vertexCount();}
00166
00168 inline unsigned int numberOfMaterials() const
00169 {return m_3DRep.materialCount();}
00170
00172 inline QSet<GLC_Material*> materialSet() const
00173 {return m_3DRep.materialSet();}
00174
00176 inline int defaultLodValue() const
00177 {return m_DefaultLOD;}
00178
00180 inline GLC_3DRep representation() const
00181 {return m_3DRep;}
00182
00184 inline int numberOfBody() const
00185 {return m_3DRep.numberOfBody();}
00186
00188 inline static int globalDefaultLod()
00189 {
00190 return m_GlobalDefaultLOD;
00191 }
00192
00194
00196
00198
00199 public:
00200
00202
00205 bool setGeometry(GLC_Geometry* pGeom);
00206
00208 inline void removeEmptyGeometry()
00209 {m_3DRep.clean();}
00210
00212 inline void reverseGeometriesNormals()
00213 {m_3DRep.reverseNormals();}
00214
00216 GLC_3DViewInstance& translate(double Tx, double Ty, double Tz);
00217
00219 inline GLC_3DViewInstance& translate(const GLC_Vector3d& v)
00220 {
00221 return translate(v.x(), v.y(), v.z());
00222 }
00223
00225 GLC_3DViewInstance& multMatrix(const GLC_Matrix4x4 &MultMat);
00226
00228 GLC_3DViewInstance& setMatrix(const GLC_Matrix4x4 &SetMat);
00229
00231 GLC_3DViewInstance& resetMatrix(void);
00232
00234
00236 inline void setPolygonMode(GLenum Face, GLenum Mode)
00237 {m_RenderProperties.setPolygonMode(Face, Mode);}
00238
00240 inline void select(bool primitive)
00241 {m_RenderProperties.select(primitive);}
00242
00244 inline void unselect(void)
00245 {m_RenderProperties.unselect();}
00246
00248 inline void setVisibility(bool visibility)
00249 {m_IsVisible= visibility;}
00250
00252 inline void setId(const GLC_uint id)
00253 {
00254 GLC_Object::setId(id);
00255 glc::encodeRgbId(m_Uid, m_colorId);
00256 }
00257
00259 inline void setDefaultLodValue(int lod)
00260 {
00261 m_DefaultLOD= lod;
00262 }
00263
00265 inline bool setViewable(GLC_3DViewInstance::Viewable flag);
00266
00268 inline void setGeomViewable(int index, bool flag)
00269 {m_ViewableGeomFlag[index]= flag;}
00270
00271
00273 static void setGlobalDefaultLod(int);
00274
00276 inline void setRenderProperties(const GLC_RenderProperties& renderProperties)
00277 {m_RenderProperties= renderProperties;}
00278
00280
00282
00284
00285 public:
00287 void render(glc::RenderFlag renderFlag= glc::ShadingFlag, bool useLoad= false, GLC_Viewport* pView= NULL);
00288
00290 void renderForBodySelection();
00291
00293 int renderForPrimitiveSelection(GLC_uint);
00294
00295
00296 private:
00298 inline void OpenglVisProperties()
00299 {
00300
00301 glPolygonMode(m_RenderProperties.polyFaceMode(), m_RenderProperties.polygonMode());
00302
00303 glMultMatrixd(m_AbsoluteMatrix.data());
00304 }
00305
00306
00308
00310
00312 private:
00314 void computeBoundingBox(void);
00315
00317 void clear();
00318
00320 int choseLod(const GLC_BoundingBox&, GLC_Viewport*);
00321
00323
00325 private:
00326
00328 GLC_3DRep m_3DRep;
00329
00331 GLC_BoundingBox* m_pBoundingBox;
00332
00334 GLC_Matrix4x4 m_AbsoluteMatrix;
00335
00337 bool m_IsBoundingBoxValid;
00338
00340 GLC_RenderProperties m_RenderProperties;
00341
00343 bool m_IsVisible;
00344
00346 GLubyte m_colorId[4];
00347
00349 int m_DefaultLOD;
00350
00352 static QMutex m_Mutex;
00353
00355 static int m_GlobalDefaultLOD;
00356
00358 Viewable m_ViewableFlag;
00359
00361 QVector<bool> m_ViewableGeomFlag;
00362
00363 };
00364
00365
00366 bool GLC_3DViewInstance::isTransparent() const
00367 {
00368 if (m_3DRep.isEmpty()) return false;
00369 if (m_RenderProperties.renderingMode() == glc::OverwriteTransparency) return true;
00370 if (m_RenderProperties.renderingMode() == glc::OverwriteMaterial)
00371 {
00372 return m_RenderProperties.overwriteMaterial()->isTransparent();
00373 }
00374 const int size= m_3DRep.numberOfBody();
00375 bool result= true;
00376 int i= 0;
00377 while((i < size) && result)
00378 {
00379 result= result && m_3DRep.geomAt(i)->isTransparent();
00380 ++i;
00381 }
00382 return result && m_RenderProperties.needToRenderWithTransparency();
00383 }
00384
00385
00386 bool GLC_3DViewInstance::hasTransparentMaterials() const
00387 {
00388 if (m_3DRep.isEmpty()) return false;
00389 if (m_RenderProperties.needToRenderWithTransparency()) return true;
00390 const int size= m_3DRep.numberOfBody();
00391 bool result= false;
00392 int i= 0;
00393 while ((i < size) && !result)
00394 {
00395 result= result || m_3DRep.geomAt(i)->hasTransparentMaterials();
00396 ++i;
00397 }
00398 return result;
00399 }
00401 bool GLC_3DViewInstance::setViewable(GLC_3DViewInstance::Viewable flag)
00402 {
00403 const int bodyCount= m_3DRep.numberOfBody();
00404 if (bodyCount != m_ViewableGeomFlag.size())
00405 {
00406 m_ViewableGeomFlag.fill(true, bodyCount);
00407 }
00408 bool asChange= m_ViewableFlag != flag;
00409 if (asChange)
00410 {
00411 m_ViewableFlag= flag;
00412 if (flag != GLC_3DViewInstance::PartialViewable)
00413 {
00414 bool viewable= (flag == GLC_3DViewInstance::FullViewable);
00415
00416 for (int i= 0; i < bodyCount; ++i)
00417 {
00418 m_ViewableGeomFlag[i]= viewable;
00419 }
00420 }
00421 }
00422 return asChange;
00423 }
00424
00425
00426 #endif