Developer Documentation
SplatCloudNode.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 
43 
44 //================================================================
45 //
46 // CLASS SplatCloudNode
47 //
48 // SplatCloudNode renders splats by passing positions, normals, pointsizes and colors (and picking colors) to the GL.
49 // These elements are internally stored in an array using an OpenGL vertex-buffer-object
50 // including vertices, normals, texcoords and colors.
51 //
52 //================================================================
53 
54 
55 #ifndef ACG_SPLATCLOUDNODE_HH
56 #define ACG_SPLATCLOUDNODE_HH
57 
58 
59 //== INCLUDES ====================================================
60 
61 
62 #include "SplatCloud/SplatCloud.hh"
63 
65 
66 #include <ACG/Scenegraph/BaseNode.hh>
67 
68 #include <ACG/Scenegraph/DrawModes.hh>
69 
70 #include <ACG/GL/gl.hh>
71 
72 #include <ACG/GL/VertexDeclaration.hh>
73 
74 //== NAMESPACES ==================================================
75 
76 
77 namespace ACG {
78 namespace SceneGraph {
79 
80 
81 //== CLASS DEFINITION ============================================
82 
83 
89 class OBJECTTYPEDLLEXPORT SplatCloudNode : public BaseNode
90 {
91 public:
92 
93  //-- TYPEDEFS ----------------------------------------------------
94 
96  typedef SplatCloud::Color Color;
97  typedef SplatCloud::Normal Normal;
98  typedef SplatCloud::Pointsize Pointsize;
99  typedef SplatCloud::Index Index;
100  typedef SplatCloud::Viewlist Viewlist;
101  typedef SplatCloud::Selection Selection;
102 
103  //----------------------------------------------------------------
104 
105 public:
106 
108  SplatCloudNode( const SplatCloud &_splatCloud, BaseNode *_parent = 0, std::string _name = "<SplatCloudNode>" );
109 
111  ~SplatCloudNode();
112 
113  ACG_CLASSNAME( SplatCloudNode );
114 
116  inline DrawModes::DrawMode availableDrawModes() const override { return splatsDrawMode_ | dotsDrawMode_ | pointsDrawMode_; }
117 
119  void boundingBox( ACG::Vec3d &_bbMin, ACG::Vec3d &_bbMax ) override;
120 
122  void draw( GLState &_state, const DrawModes::DrawMode &_drawMode ) override;
123 
125  void getRenderObjects( IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat ) override;
126 
128  void pick( GLState &_state, PickTarget _target ) override;
129 
130  // TODO: hack, because pick() doesn't get a drawmode
131  inline void enterPick( GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode ) override { pickDrawMode_ = _drawMode; }
132 
133  // ---- splat cloud ----
134 
135  inline const SplatCloud &splatCloud() const { return splatCloud_; }
136 
137  // ---- modification tags ----
138 
139  inline void modifiedPositions() { positionsModified_ = true; }
140  inline void modifiedColors() { colorsModified_ = true; }
141  inline void modifiedNormals() { normalsModified_ = true; }
142  inline void modifiedPointsizes() { pointsizesModified_ = true; }
143  inline void modifiedSelections() { selectionsModified_ = true; }
144  inline void modifiedPickColors() { pickColorsModified_ = true; }
145 
146  inline void modifiedAll()
147  {
148  modifiedPositions();
149  modifiedColors();
150  modifiedNormals();
151  modifiedPointsizes();
152  modifiedSelections();
153  modifiedPickColors();
154  }
155 
156  // ---- default values ----
157 
158  inline void setDefaultColor ( const Color &_color ) { defaultColor_ = _color; }
159  inline void setDefaultNormal ( const Normal &_normal ) { defaultNormal_ = _normal; }
160  inline void setDefaultPointsize( const Pointsize &_pointsize ) { defaultPointsize_ = _pointsize; }
161 
162  inline const Color &defaultColor() const { return defaultColor_; }
163  inline const Normal &defaultNormal() const { return defaultNormal_; }
164  inline const Pointsize &defaultPointsize() const { return defaultPointsize_; }
165 
167  inline const Position &getPosition ( int _idx ) const { return splatCloud_.hasPositions() ? splatCloud_.positions ( _idx ) : DEFAULT_POSITION; }
168  inline const Color &getColor ( int _idx ) const { return splatCloud_.hasColors() ? splatCloud_.colors ( _idx ) : defaultColor_; }
169  inline const Normal &getNormal ( int _idx ) const { return splatCloud_.hasNormals() ? splatCloud_.normals ( _idx ) : defaultNormal_; }
170  inline const Pointsize &getPointsize( int _idx ) const { return splatCloud_.hasPointsizes() ? splatCloud_.pointsizes( _idx ) : defaultPointsize_; }
171  inline const Index &getIndex ( int _idx ) const { return splatCloud_.hasIndices() ? splatCloud_.indices ( _idx ) : DEFAULT_INDEX; }
172  inline const Viewlist &getViewlist ( int _idx ) const { return splatCloud_.hasViewlists() ? splatCloud_.viewlists ( _idx ) : DEFAULT_VIEWLIST; }
173  inline const Selection &getSelection( int _idx ) const { return splatCloud_.hasSelections() ? splatCloud_.selections( _idx ) : DEFAULT_SELECTION; }
174 
175 
176  // ---- render object params ----
177 
178  inline void setPointsizeScale(float _scale) { pointsizeScale_ = _scale; }
179  inline void setBackfaceCulling(bool _enable) { backfaceCulling_ = _enable; }
180  inline void setGeometryShaderQuads(bool _enable) { geometryShaderQuads_ = _enable; }
181 
182  inline float getPointsizeScale() const { return pointsizeScale_; }
183  inline bool getBackfaceCulling() const { return backfaceCulling_; }
184  inline bool getGeometryShaderQuads() const { return geometryShaderQuads_; }
185 
186 
187  //----------------------------------------------------------------
188 
189 private:
190 
191  // ---- splat cloud ----
192 
195 
196  // ---- modification tags ----
197 
200  bool colorsModified_;
201  bool normalsModified_;
202  bool pointsizesModified_;
203  bool selectionsModified_;
204  bool pickColorsModified_;
205 
207  inline bool vboModified() const
208  {
209  return positionsModified_ ||
210  colorsModified_ ||
211  normalsModified_ ||
212  pointsizesModified_ ||
213  selectionsModified_ ||
214  pickColorsModified_;
215  }
216 
217  // ---- default values ----
218 
221  Normal defaultNormal_;
222  Pointsize defaultPointsize_;
223 
224  // ---- draw modes ----
225 
226  DrawModes::DrawMode splatsDrawMode_;
227  DrawModes::DrawMode dotsDrawMode_;
228  DrawModes::DrawMode pointsDrawMode_;
229 
230  // ---- picking ----
231 
232  unsigned int pickingBaseIndex_;
233 
234  // TODO: hack, see enterPick()
235  DrawModes::DrawMode pickDrawMode_;
236 
237  // ---- vertex buffer object ----
238 
239  GLuint vboGlId_;
240  unsigned int vboNumSplats_;
241  unsigned char *vboData_;
242  unsigned int vboStride_;
243 
246  int vboColorsOffset_;
247  int vboNormalsOffset_;
248  int vboPointsizesOffset_;
249  int vboSelectionsOffset_;
250  int vboPickColorsOffset_;
251 
252  ACG::VertexDeclaration vboDecl_;
253 
255  inline bool vboStructureModified() const
256  {
257  return vboNumSplats_ != splatCloud_.numSplats() ||
258  (vboPositionsOffset_ != -1) != splatCloud_.hasPositions() ||
259  (vboColorsOffset_ != -1) != splatCloud_.hasColors() ||
260  (vboNormalsOffset_ != -1) != splatCloud_.hasNormals() ||
261  (vboPointsizesOffset_ != -1) != splatCloud_.hasPointsizes() ||
262  (vboSelectionsOffset_ != -1) != splatCloud_.hasSelections();
263  }
264 
265  void createVBO();
266  void destroyVBO();
267  void rebuildVBO( GLState &_state );
268 
269  void rebuildVBOPositions();
270  void rebuildVBOColors();
271  void rebuildVBONormals();
272  void rebuildVBOPointsizes();
273  void rebuildVBOSelections();
274  void rebuildVBOPickColors( GLState &_state );
275 
276  static const Position DEFAULT_POSITION;
277  static const Index DEFAULT_INDEX;
278  static const Viewlist DEFAULT_VIEWLIST;
279  static const Selection DEFAULT_SELECTION;
280 
281  // ---- rendering params ----
282 
283  float pointsizeScale_;
284  bool backfaceCulling_;
285  bool geometryShaderQuads_;
286 };
287 
288 
289 //================================================================
290 
291 
292 } // namespace SceneGraph
293 } // namespace ACG
294 
295 
296 //================================================================
297 
298 
299 #endif // ACG_SPLATCLOUDNODE_HH
DrawModes::DrawMode availableDrawModes() const override
return available draw modes
unsigned int numSplats() const
Get the number of splats.
Definition: SplatCloud.hh:179
Namespace providing different geometric functions concerning angles.
bool hasSelections() const
Return the availability of the predefined property.
Definition: SplatCloud.hh:613
Class to define the vertex input layout.
const SplatCloud & splatCloud_
reference to class containing all the data
bool hasPositions() const
Return the availability of the predefined property.
Definition: SplatCloud.hh:607
bool hasColors() const
Return the availability of the predefined property.
Definition: SplatCloud.hh:608
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:83
bool hasNormals() const
Return the availability of the predefined property.
Definition: SplatCloud.hh:609
bool vboStructureModified() const
returns true iff the internal block structure of the VBO has to be changed
const Position & getPosition(int _idx) const
if the data array exists, the entry with the given index is returned, otherwise the default value is ...
bool positionsModified_
marks if parts of the data has been modified
ACG::SceneGraph::SplatCloudNode SplatCloudNode
Simple Name for SplatCloudNode.
Color defaultColor_
the default values will be used when the specific array is not present
int vboPositionsOffset_
offsets relative to vboData_ or -1 if not present in VBO
bool hasPointsizes() const
Return the availability of the predefined property.
Definition: SplatCloud.hh:610
bool vboModified() const
return true iff any of the data values in the VBO has to be changed