GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_3dviewinstance.h
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 *****************************************************************************/
22 
24 
25 #ifndef GLC_3DVIEWINSTANCE_H_
26 #define GLC_3DVIEWINSTANCE_H_
27 
28 #include "../glc_global.h"
29 #include "../glc_boundingbox.h"
30 #include "../glc_object.h"
31 #include "../maths/glc_matrix4x4.h"
32 #include "../glc_state.h"
33 #include "../geometry/glc_3drep.h"
34 #include "../shading/glc_renderproperties.h"
35 #include "../glc_context.h"
36 
37 #include <QMutex>
38 
39 #include "../glc_config.h"
40 
41 class GLC_Viewport;
42 
45 
52 
53 
55 {
56 public:
58  enum Viewable
59  {
60  FullViewable= 120,
61  PartialViewable= 121,
62  NoViewable= 122
63  };
65 
67 
68 public:
71 
74 
77 
80 
82  GLC_3DViewInstance(const GLC_3DRep& rep, GLC_uint id);
83 
86 
89 
92 
94 
96 
98 
99 public:
101  inline bool isTransparent() const;
102 
104  inline bool hasTransparentMaterials() const;
105 
107  inline bool isEmpty() const
108  {return m_3DRep.isEmpty();}
109 
111  inline bool isSelected(void) const
112  {return m_RenderProperties.isSelected();}
113 
115  inline int numberOfGeometry() const
116  {return m_3DRep.numberOfBody();}
117 
118 
120  inline GLC_Geometry* geomAt(int index) const
121  {
122  if (!m_3DRep.isEmpty()) return m_3DRep.geomAt(index);
123  else return NULL;
124  }
125 
127  GLC_BoundingBox boundingBox();
128 
130  inline bool boundingBoxValidity() const
131  {return (m_pBoundingBox != NULL) && m_IsBoundingBoxValid && m_3DRep.boundingBoxIsValid();}
132 
134  inline const GLC_Matrix4x4& matrix() const
135  {return m_AbsoluteMatrix;}
136 
138  GLC_3DViewInstance deepCopy() const;
139 
141  GLC_3DViewInstance instanciate();
142 
144 
145  inline GLenum polygonMode() const
146  {return m_RenderProperties.polygonMode();}
147 
149  inline GLC_RenderProperties* renderPropertiesHandle()
150  {return &m_RenderProperties;}
151 
153  inline bool isVisible() const
154  {return m_IsVisible;}
155 
157  inline GLC_3DViewInstance::Viewable viewableFlag() const
158  {return m_ViewableFlag;}
159 
161  inline bool isGeomViewable(int index) const
162  {return m_ViewableGeomFlag.at(index);}
163 
165  inline unsigned int numberOfFaces() const
166  {return m_3DRep.faceCount();}
167 
169  inline unsigned int numberOfVertex() const
170  {return m_3DRep.vertexCount();}
171 
173  inline unsigned int numberOfMaterials() const
174  {return m_3DRep.materialCount();}
175 
177  inline QSet<GLC_Material*> materialSet() const
178  {return m_3DRep.materialSet();}
179 
181  inline int defaultLodValue() const
182  {return m_DefaultLOD;}
183 
185  inline GLC_3DRep representation() const
186  {return m_3DRep;}
187 
189  inline int numberOfBody() const
190  {return m_3DRep.numberOfBody();}
191 
193  inline static int globalDefaultLod()
194  {
195  return m_GlobalDefaultLOD;
196  }
197 
199 
201 
203 
204 public:
205 
207  bool addGeometry(GLC_Geometry* pGeom);
208 
210  inline void removeEmptyGeometry()
211  {m_3DRep.clean();}
212 
214  inline void reverseGeometriesNormals()
215  {m_3DRep.reverseNormals();}
216 
218  GLC_3DViewInstance& translate(double Tx, double Ty, double Tz);
219 
221  inline GLC_3DViewInstance& translate(const GLC_Vector3d& v)
222  {
223  return translate(v.x(), v.y(), v.z());
224  }
225 
227  GLC_3DViewInstance& multMatrix(const GLC_Matrix4x4 &MultMat);
228 
230  GLC_3DViewInstance& setMatrix(const GLC_Matrix4x4 &SetMat);
231 
233  GLC_3DViewInstance& resetMatrix(void);
234 
236 
238  inline void setPolygonMode(GLenum Face, GLenum Mode)
239  {m_RenderProperties.setPolygonMode(Face, Mode);}
240 
242  inline void select(bool primitive)
243  {m_RenderProperties.select(primitive);}
244 
246  inline void unselect(void)
247  {m_RenderProperties.unselect();}
248 
250  inline void setVisibility(bool visibility)
251  {m_IsVisible= visibility;}
252 
254  inline void setId(const GLC_uint id)
255  {
256  GLC_Object::setId(id);
257  glc::encodeRgbId(m_Uid, m_colorId);
258  }
259 
261  inline void setDefaultLodValue(int lod)
262  {
263  m_DefaultLOD= lod;
264  }
265 
267  inline bool setViewable(GLC_3DViewInstance::Viewable flag);
268 
270  inline void setGeomViewable(int index, bool flag)
271  {m_ViewableGeomFlag[index]= flag;}
272 
273 
275  static void setGlobalDefaultLod(int);
276 
278  inline void setRenderProperties(const GLC_RenderProperties& renderProperties)
279  {m_RenderProperties= renderProperties;}
280 
282  void setVboUsage(bool usage);
283 
285 
287 
289 
290 public:
292  void render(glc::RenderFlag renderFlag= glc::ShadingFlag, bool useLod= false, GLC_Viewport* pView= NULL);
293 
295  void renderForBodySelection();
296 
298  int renderForPrimitiveSelection(GLC_uint);
299 
300 
301 private:
303  inline void OpenglVisProperties()
304  {
305  // Polygons display mode
306  glPolygonMode(m_RenderProperties.polyFaceMode(), m_RenderProperties.polygonMode());
307  // Change the current matrix
308  GLC_Context::current()->glcMultMatrix(m_AbsoluteMatrix);
309  }
310 
311 
313 
315 // private services functions
317 private:
319  void computeBoundingBox(void);
320 
322  void clear();
323 
325  int choseLod(const GLC_BoundingBox&, GLC_Viewport*, bool);
326 
328 // Private members
330 private:
331 
334 
337 
340 
343 
346 
349 
351  GLubyte m_colorId[4];
352 
355 
358 
360  QVector<bool> m_ViewableGeomFlag;
361 
363  static QMutex m_Mutex;
364 
366  static int m_GlobalDefaultLOD;
367 
368 
369 };
370 
371 // Return true if the all instance's mesh are transparent
373 {
374  if (m_3DRep.isEmpty()) return false;
377  {
379  }
380  const int size= m_3DRep.numberOfBody();
381  bool result= true;
382  int i= 0;
383  while((i < size) && result)
384  {
385  result= result && m_3DRep.geomAt(i)->isTransparent();
386  ++i;
387  }
389 }
390 
391 // Return true if the instance contains mesh which contains transparent material
393 {
394  if (m_3DRep.isEmpty()) return false;
396  const int size= m_3DRep.numberOfBody();
397  bool result= false;
398  int i= 0;
399  while ((i < size) && !result)
400  {
401  result= result || m_3DRep.geomAt(i)->hasTransparentMaterials();
402  ++i;
403  }
404  return result;
405 }
408 {
409  const int bodyCount= m_3DRep.numberOfBody();
410  if (bodyCount != m_ViewableGeomFlag.size())
411  {
412  m_ViewableGeomFlag.fill(true, bodyCount);
413  }
414  bool asChange= m_ViewableFlag != flag;
415  if (asChange)
416  {
417  m_ViewableFlag= flag;
419  {
420  bool viewable= (flag == GLC_3DViewInstance::FullViewable);
421 
422  for (int i= 0; i < bodyCount; ++i)
423  {
424  m_ViewableGeomFlag[i]= viewable;
425  }
426  }
427  }
428  return asChange;
429 }
430 
431 
432 #endif /*GLC_3DVIEWINSTANCE_H_*/

©2005-2013 Laurent Ribon