SplatCloudNode.hh 9.71 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
\*===========================================================================*/

/*===========================================================================*\
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
\*===========================================================================*/

//================================================================
//
//  CLASS SplatCloudNode
//
47
48
49
//    SplatCloudNode renders splats by passing points, normals, point sizes and colors (and picking colors) to the GL.
//    These elements are internally stored in an interleaved array using an OpenGL vertex-buffer-object
//    including vertices, normals, texcoords and colors.
Jan Möbius's avatar
Jan Möbius committed
50
51
52
53
54
55
56
57
58
59
60
//
//================================================================


#ifndef ACG_SPLATCLOUDNODE_HH
#define ACG_SPLATCLOUDNODE_HH


//== INCLUDES ====================================================


61
62
#include "SplatCloud/SplatCloud.hh"

Jan Möbius's avatar
Jan Möbius committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <OpenFlipper/common/GlobalDefines.hh>

#include <ACG/Scenegraph/BaseNode.hh>

#include <ACG/Scenegraph/DrawModes.hh>

#include <ACG/GL/gl.hh>


//== NAMESPACES ==================================================


namespace ACG {
namespace SceneGraph {


//== CLASS DEFINITION ============================================


/** \class SplatCloudNode SplatCloudNode.hh <ObjectTypes/SplatCloud/SplatCloudNode.hh>
 *
 * This class is able to render a SplatCloud as splats, dots or points
 */

class DLLEXPORT SplatCloudNode : public BaseNode
{
89
private:
Jan Möbius's avatar
Jan Möbius committed
90
91
92

	//-- TYPEDEFS ----------------------------------------------------

93
94
95
96
	typedef SplatCloud::Point     Point;
	typedef SplatCloud::Normal    Normal;
	typedef SplatCloud::Pointsize Pointsize;
	typedef SplatCloud::Color     Color;
97
	typedef SplatCloud::Selection Selection;
Jan Möbius's avatar
Jan Möbius committed
98
99
100

	//----------------------------------------------------------------

101
102
103
public:

	/// constructor
104
	SplatCloudNode( const SplatCloud &_splatCloud, BaseNode *_parent = 0, std::string _name = "<SplatCloudNode>" );
Jan Möbius's avatar
Jan Möbius committed
105

106
107
	/// destructor
	~SplatCloudNode();
Jan Möbius's avatar
Jan Möbius committed
108
109
110
111

	ACG_CLASSNAME( SplatCloudNode );

	/// return available draw modes
112
	inline DrawModes::DrawMode availableDrawModes() const { return splatsDrawMode_ | dotsDrawMode_ | pointsDrawMode_; }
Jan Möbius's avatar
Jan Möbius committed
113
114
115
116
117
118
119
120
121
122
123

	/// update bounding box
	void boundingBox( ACG::Vec3d &_bbMin, ACG::Vec3d &_bbMax );

	/// draw the SplatCloud
	void draw( GLState &_state, const DrawModes::DrawMode &_drawMode );

	/// picking
	void enterPick( GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode );
	void pick( GLState &_state, PickTarget _target );

124
	// ---- splat cloud ----
Jan Möbius's avatar
Jan Möbius committed
125

126
	inline const SplatCloud &splatCloud() const { return splatCloud_; }
Jan Möbius's avatar
Jan Möbius committed
127

128
	// ---- modification tags ----
Jan Möbius's avatar
Jan Möbius committed
129

130
131
132
133
134
135
136
137
138
	inline void modifiedPoints()     { pointsModified_     = true; }
	inline void modifiedNormals()    { normalsModified_    = true; }
	inline void modifiedPointsizes() { pointsizesModified_ = true; }
	inline void modifiedColors()     { colorsModified_     = true; }
	inline void modifiedSelections() { selectionsModified_ = true; }
	inline void modifiedPickColors() { pickColorsModified_ = true; }

	inline void modifiedAll() { modifiedPoints(); modifiedNormals(); modifiedPointsizes(); modifiedColors(); modifiedSelections(); modifiedPickColors(); }

Jan Möbius's avatar
Jan Möbius committed
139
140
	// ---- default values ----

141
142
143
	inline void setDefaultNormal   ( const Normal    &_normal    ) { defaultNormal_    = _normal;    }
	inline void setDefaultPointsize( const Pointsize &_pointsize ) { defaultPointsize_ = _pointsize; }
	inline void setDefaultColor    ( const Color     &_color     ) { defaultColor_     = _color;     }
Jan Möbius's avatar
Jan Möbius committed
144
145
146
147
148

	inline const Normal    &defaultNormal()    const { return defaultNormal_;    }
	inline const Pointsize &defaultPointsize() const { return defaultPointsize_; }
	inline const Color     &defaultColor()     const { return defaultColor_;     }

149
150
151
152
153
154
	/// if the data array exists, the entry with the given _index is returned, otherwise the default value is returned
	inline Point     getPoint    ( unsigned int _index ) const { return splatCloud_.hasPoints()     ? splatCloud_.points()    [ _index ] : Point(0.0f,0.0f,0.0f); }
	inline Normal    getNormal   ( unsigned int _index ) const { return splatCloud_.hasNormals()    ? splatCloud_.normals()   [ _index ] : defaultNormal_       ; }
	inline Pointsize getPointsize( unsigned int _index ) const { return splatCloud_.hasPointsizes() ? splatCloud_.pointsizes()[ _index ] : defaultPointsize_    ; }
	inline Color     getColor    ( unsigned int _index ) const { return splatCloud_.hasColors()     ? splatCloud_.colors()    [ _index ] : defaultColor_        ; }
	inline Selection getSelection( unsigned int _index ) const { return splatCloud_.hasSelections() ? splatCloud_.selections()[ _index ] : false                ; }
Dominik Sibbing's avatar
Dominik Sibbing committed
155

Jan Möbius's avatar
Jan Möbius committed
156
157
158
	//----------------------------------------------------------------

private:
Dominik Sibbing's avatar
Dominik Sibbing committed
159

160
	// ---- splat cloud ----
161

162
163
164
165
	/// reference to class containing all the data
	const SplatCloud &splatCloud_;

	// ---- modification tags ----
166

167
168
169
170
171
172
173
174
175
176
177
	/// marks if parts of the data has been modified
	bool pointsModified_;
	bool normalsModified_;
	bool pointsizesModified_;
	bool colorsModified_;
	bool selectionsModified_;
	bool pickColorsModified_;

	/// return true iff any of the data values in the VBO has to be changed
	inline bool vboModified() const { return pointsModified_ || normalsModified_ || pointsizesModified_ || colorsModified_ || selectionsModified_ || pickColorsModified_; }

178
	// ---- default values ----
179

180
181
182
183
	/// the default values will be used when the specific array is not present
	Normal    defaultNormal_;
	Pointsize defaultPointsize_;
	Color     defaultColor_;
Jan Möbius's avatar
Jan Möbius committed
184
185

	// ---- draw modes ----
186

187
188
189
	DrawModes::DrawMode splatsDrawMode_;
	DrawModes::DrawMode dotsDrawMode_;
	DrawModes::DrawMode pointsDrawMode_;
Jan Möbius's avatar
Jan Möbius committed
190

191
	// ---- picking base index ----
192

193
	unsigned int pickingBaseIndex_;
Dominik Sibbing's avatar
Dominik Sibbing committed
194

Jan Möbius's avatar
Jan Möbius committed
195
	// ---- vertex buffer object ----
196
197
198
199
200
201
202
203
204
205
206
207
208

	GLuint        vboGlId_;
	unsigned int  vboNumPoints_;
	unsigned char *vboData_;

	/// offsets relative to vboData_ or -1 if *not* present in VBO
	int vboPointsOffset_;
	int vboNormalsOffset_;
	int vboPointsizesOffset_;
	int vboColorsOffset_;
	int vboSelectionsOffset_;
	int vboPickColorsOffset_;

209
210
211
212
213
214
215
216
217
218
	/// returns true iff the internal block structure of the VBO has to be changed
	inline bool vboStructureModified() const
	{
		return vboNumPoints_                != splatCloud_.numPoints()     || 
		       (vboPointsOffset_     != -1) != splatCloud_.hasPoints()     || 
		       (vboNormalsOffset_    != -1) != splatCloud_.hasNormals()    || 
		       (vboPointsizesOffset_ != -1) != splatCloud_.hasPointsizes() || 
		       (vboColorsOffset_     != -1) != splatCloud_.hasColors()     || 
		       (vboSelectionsOffset_ != -1) != splatCloud_.hasSelections();
	}
Jan Möbius's avatar
Jan Möbius committed
219
220
221

	void createVBO();
	void destroyVBO();
Dominik Sibbing's avatar
Dominik Sibbing committed
222
	void rebuildVBO( GLState &_state );
223
224
225
226
227
228
229

	void rebuildVBOPoints();
	void rebuildVBONormals();
	void rebuildVBOPointsizes();
	void rebuildVBOColors();
	void rebuildVBOSelections();
	void rebuildVBOPickColors( GLState &_state );
Jan Möbius's avatar
Jan Möbius committed
230
231
232
233
234
235
236
237
238
239
240
241
242
243
};


//================================================================


} // namespace SceneGraph
} // namespace ACG


//================================================================


#endif // ACG_SPLATCLOUDNODE_HH