Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SplatCloudNode.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
5 * www.openflipper.org *
6 * *
7 *--------------------------------------------------------------------------- *
8 * This file is part of OpenFlipper. *
9 * *
10 * OpenFlipper is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenFlipper is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenFlipper. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36 * *
37 * $Revision: 14927 $ *
38 * $LastChangedBy: moebius $ *
39 * $Date: 2012-07-06 16:16:39 +0200 (Fr, 06 Jul 2012) $ *
40 * *
41 \*===========================================================================*/
42 
43 //================================================================
44 //
45 // CLASS SplatCloudNode
46 //
47 // SplatCloudNode renders splats by passing positions, normals, pointsizes and colors (and picking colors) to the GL.
48 // These elements are internally stored in an array using an OpenGL vertex-buffer-object
49 // including vertices, normals, texcoords and colors.
50 //
51 //================================================================
52 
53 
54 #ifndef ACG_SPLATCLOUDNODE_HH
55 #define ACG_SPLATCLOUDNODE_HH
56 
57 
58 //== INCLUDES ====================================================
59 
60 
61 #include "SplatCloud/SplatCloud.hh"
62 
64 
65 #include <ACG/Scenegraph/BaseNode.hh>
66 
67 #include <ACG/Scenegraph/DrawModes.hh>
68 
69 #include <ACG/GL/gl.hh>
70 
71 
72 //== NAMESPACES ==================================================
73 
74 
75 namespace ACG {
76 namespace SceneGraph {
77 
78 
79 //== CLASS DEFINITION ============================================
80 
81 
88 {
89 public:
90 
91  //-- TYPEDEFS ----------------------------------------------------
92 
93  typedef SplatCloud::Position Position;
94  typedef SplatCloud::Color Color;
95  typedef SplatCloud::Normal Normal;
96  typedef SplatCloud::Pointsize Pointsize;
97  typedef SplatCloud::Index Index;
98  typedef SplatCloud::Viewlist Viewlist;
99  typedef SplatCloud::Selection Selection;
100 
101  //----------------------------------------------------------------
102 
103 public:
104 
106  SplatCloudNode( const SplatCloud &_splatCloud, BaseNode *_parent = 0, std::string _name = "<SplatCloudNode>" );
107 
109  ~SplatCloudNode();
110 
111  ACG_CLASSNAME( SplatCloudNode );
112 
114  inline DrawModes::DrawMode availableDrawModes() const { return splatsDrawMode_ | dotsDrawMode_ | pointsDrawMode_; }
115 
117  void boundingBox( ACG::Vec3d &_bbMin, ACG::Vec3d &_bbMax );
118 
120  void draw( GLState &_state, const DrawModes::DrawMode &_drawMode );
121 
123  void pick( GLState &_state, PickTarget _target );
124 
125  // TODO: hack, because pick() doesn't get a drawmode
126  inline void enterPick( GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode ) { pickDrawMode_ = _drawMode; }
127 
128  // ---- splat cloud ----
129 
130  inline const SplatCloud &splatCloud() const { return splatCloud_; }
131 
132  // ---- modification tags ----
133 
134  inline void modifiedPositions() { positionsModified_ = true; }
135  inline void modifiedColors() { colorsModified_ = true; }
136  inline void modifiedNormals() { normalsModified_ = true; }
137  inline void modifiedPointsizes() { pointsizesModified_ = true; }
138  inline void modifiedSelections() { selectionsModified_ = true; }
139  inline void modifiedPickColors() { pickColorsModified_ = true; }
140 
141  inline void modifiedAll()
142  {
143  modifiedPositions();
144  modifiedColors();
145  modifiedNormals();
146  modifiedPointsizes();
147  modifiedSelections();
148  modifiedPickColors();
149  }
150 
151  // ---- default values ----
152 
153  inline void setDefaultColor ( const Color &_color ) { defaultColor_ = _color; }
154  inline void setDefaultNormal ( const Normal &_normal ) { defaultNormal_ = _normal; }
155  inline void setDefaultPointsize( const Pointsize &_pointsize ) { defaultPointsize_ = _pointsize; }
156 
157  inline const Color &defaultColor() const { return defaultColor_; }
158  inline const Normal &defaultNormal() const { return defaultNormal_; }
159  inline const Pointsize &defaultPointsize() const { return defaultPointsize_; }
160 
162  inline const Position &getPosition ( int _idx ) const { return splatCloud_.hasPositions() ? splatCloud_.positions ( _idx ) : DEFAULT_POSITION; }
163  inline const Color &getColor ( int _idx ) const { return splatCloud_.hasColors() ? splatCloud_.colors ( _idx ) : defaultColor_; }
164  inline const Normal &getNormal ( int _idx ) const { return splatCloud_.hasNormals() ? splatCloud_.normals ( _idx ) : defaultNormal_; }
165  inline const Pointsize &getPointsize( int _idx ) const { return splatCloud_.hasPointsizes() ? splatCloud_.pointsizes( _idx ) : defaultPointsize_; }
166  inline const Index &getIndex ( int _idx ) const { return splatCloud_.hasIndices() ? splatCloud_.indices ( _idx ) : DEFAULT_INDEX; }
167  inline const Viewlist &getViewlist ( int _idx ) const { return splatCloud_.hasViewlists() ? splatCloud_.viewlists ( _idx ) : DEFAULT_VIEWLIST; }
168  inline const Selection &getSelection( int _idx ) const { return splatCloud_.hasSelections() ? splatCloud_.selections( _idx ) : DEFAULT_SELECTION; }
169 
170  //----------------------------------------------------------------
171 
172 private:
173 
174  // ---- splat cloud ----
175 
178 
179  // ---- modification tags ----
180 
183  bool colorsModified_;
184  bool normalsModified_;
185  bool pointsizesModified_;
186  bool selectionsModified_;
187  bool pickColorsModified_;
188 
190  inline bool vboModified() const
191  {
192  return positionsModified_ ||
193  colorsModified_ ||
194  normalsModified_ ||
195  pointsizesModified_ ||
196  selectionsModified_ ||
197  pickColorsModified_;
198  }
199 
200  // ---- default values ----
201 
204  Normal defaultNormal_;
205  Pointsize defaultPointsize_;
206 
207  // ---- draw modes ----
208 
209  DrawModes::DrawMode splatsDrawMode_;
210  DrawModes::DrawMode dotsDrawMode_;
211  DrawModes::DrawMode pointsDrawMode_;
212 
213  // ---- picking ----
214 
215  unsigned int pickingBaseIndex_;
216 
217  // TODO: hack, see enterPick()
218  DrawModes::DrawMode pickDrawMode_;
219 
220  // ---- vertex buffer object ----
221 
222  GLuint vboGlId_;
223  unsigned int vboNumSplats_;
224  unsigned char *vboData_;
225 
228  int vboColorsOffset_;
229  int vboNormalsOffset_;
230  int vboPointsizesOffset_;
231  int vboSelectionsOffset_;
232  int vboPickColorsOffset_;
233 
235  inline bool vboStructureModified() const
236  {
237  return vboNumSplats_ != splatCloud_.numSplats() ||
238  (vboPositionsOffset_ != -1) != splatCloud_.hasPositions() ||
239  (vboColorsOffset_ != -1) != splatCloud_.hasColors() ||
240  (vboNormalsOffset_ != -1) != splatCloud_.hasNormals() ||
241  (vboPointsizesOffset_ != -1) != splatCloud_.hasPointsizes() ||
242  (vboSelectionsOffset_ != -1) != splatCloud_.hasSelections();
243  }
244 
245  void createVBO();
246  void destroyVBO();
247  void rebuildVBO( GLState &_state );
248 
249  void rebuildVBOPositions();
250  void rebuildVBOColors();
251  void rebuildVBONormals();
252  void rebuildVBOPointsizes();
253  void rebuildVBOSelections();
254  void rebuildVBOPickColors( GLState &_state );
255 
256  static const Position DEFAULT_POSITION;
257  static const Index DEFAULT_INDEX;
258  static const Viewlist DEFAULT_VIEWLIST;
259  static const Selection DEFAULT_SELECTION;
260 };
261 
262 
263 //================================================================
264 
265 
266 } // namespace SceneGraph
267 } // namespace ACG
268 
269 
270 //================================================================
271 
272 
273 #endif // ACG_SPLATCLOUDNODE_HH