SplatCloudNode.cc 20.3 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
47
48
49
50
51
52
53
54
55
/*===========================================================================*\
*                                                                            *
*                              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 - IMPLEMENTATION
//
//================================================================


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


#include "SplatCloudNode.hh"


56
57
58
59
60
61
//== DEFINES =====================================================


//#define REPORT_VBO_UPDATES


Jan Möbius's avatar
Jan Möbius committed
62
63
64
65
66
67
68
69
70
71
//== NAMESPACES ==================================================


namespace ACG {
namespace SceneGraph {


//== IMPLEMENTATION ==============================================


72
SplatCloudNode::SplatCloudNode( BaseNode *_parent, std::string _name ) : 
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
	BaseNode            ( _parent, _name ), 
	splatCloud_         ( 0 ), 
	pointsModified_     ( false ), 
	normalsModified_    ( false ), 
	pointsizesModified_ ( false ), 
	colorsModified_     ( false ), 
	selectionsModified_ ( false ), 
	pickColorsModified_ ( false ), 
	defaultNormal_      ( Normal(0.0f,0.0f,1.0f) ), 
	defaultPointsize_   ( Pointsize(0.01f) ), 
	defaultColor_       ( Color(255,255,255) ), 
	splatsDrawMode_     ( DrawModes::NONE ), 
	dotsDrawMode_       ( DrawModes::NONE ), 
	pointsDrawMode_     ( DrawModes::NONE ), 
	pickingBaseIndex_   ( 0 ), 
	vboGlId_            ( 0 ), 
	vboNumPoints_       ( 0 ), 
	vboData_            ( 0 ), 
	vboPointsOffset_    ( -1 ), 
	vboNormalsOffset_   ( -1 ), 
	vboPointsizesOffset_( -1 ), 
	vboColorsOffset_    ( -1 ), 
	vboSelectionsOffset_( -1 ), 
	vboPickColorsOffset_( -1 ) 
97
98
99
100
101
102
103
104
105
106
107
108
109
{
	// allocate memory for splat cloud
	splatCloud_ = new SplatCloud;
	if( !splatCloud_ )
	{
		std::cerr << "SplatCloudNode::SplatCloudNode() : Out of memory." << std::endl;
	}

	// add (possibly) new drawmodes
	pointsDrawMode_ = DrawModes::addDrawMode( "Points" );
	dotsDrawMode_   = DrawModes::addDrawMode( "Dots"   );
	splatsDrawMode_ = DrawModes::addDrawMode( "Splats" );

110
	// create a new VBO (will be invalid and rebuilt the next time drawn (or picked))
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
	createVBO();
}


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


SplatCloudNode::~SplatCloudNode()
{
	destroyVBO();

	delete splatCloud_;
	splatCloud_ = 0;
}


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


Jan Möbius's avatar
Jan Möbius committed
130
131
void SplatCloudNode::boundingBox( ACG::Vec3d &_bbMin, ACG::Vec3d &_bbMax )
{
132
133
134
135
	// if something went wrong in the initialization, abort
	if( !splatCloud_ )
		return;

136
137
    ACG::Vec3f bbMin( FLT_MAX, FLT_MAX, FLT_MAX );
    ACG::Vec3f bbMax(-FLT_MAX,-FLT_MAX,-FLT_MAX );
Jan Möbius's avatar
Jan Möbius committed
138

139
140
    SplatCloud::PointVector::const_iterator pointIter, pointsEnd = splatCloud_->points().end();
    for ( pointIter = splatCloud_->points().begin(); pointIter != pointsEnd; ++pointIter )
141
142
    {
        const Point &p = *pointIter;
Jan Möbius's avatar
Jan Möbius committed
143

144
        ACG::Vec3f acgp( p[0], p[1], p[2] );
Jan Möbius's avatar
Jan Möbius committed
145

146
147
148
        bbMin.minimize( acgp );
        bbMax.maximize( acgp );
    }
Jan Möbius's avatar
Jan Möbius committed
149

150
151
    _bbMin.minimize( ACG::Vec3d( bbMin ) );
    _bbMax.maximize( ACG::Vec3d( bbMax ) );
Jan Möbius's avatar
Jan Möbius committed
152
153
154
155
156
}


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

157

Jan Möbius's avatar
Jan Möbius committed
158
159
void SplatCloudNode::draw( GLState &_state, const DrawModes::DrawMode &_drawMode )
{
160
161
162
163
	// if something went wrong in the initialization, abort
	if( !splatCloud_ )
		return;

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
	static const int RENDERMODE_POINTS = 0;
	static const int RENDERMODE_DOTS   = 1;
	static const int RENDERMODE_SPLATS = 2;

	// check if drawmode is valid
	int rendermode;
	if( _drawMode.containsAtomicDrawMode( splatsDrawMode_ ) )
		rendermode = RENDERMODE_SPLATS;
	else if( _drawMode.containsAtomicDrawMode( dotsDrawMode_ ) )
		rendermode = RENDERMODE_DOTS;
	else if( _drawMode.containsAtomicDrawMode( pointsDrawMode_ ) )
		rendermode = RENDERMODE_POINTS;
	else
		return;

	// set desired depth function
	ACG::GLState::depthFunc( _state.depthFunc() );

	// if VBO is invalid or was (partially) modified, then rebuild
	if( !vboData_ || vboModified() )
		rebuildVBO( _state );

	// if VBO is valid...
	if( vboData_ )
	{
		// activate VBO
		ACG::GLState::bindBufferARB( GL_ARRAY_BUFFER_ARB, vboGlId_ );

		// enable arrays:
		// --------------

		// points
		if( vboPointsOffset_ != -1 )
		{
			ACG::GLState::enableClientState( GL_VERTEX_ARRAY );
			ACG::GLState::vertexPointer( 3, GL_FLOAT, 0, (unsigned char *) 0 + vboPointsOffset_ );
		}
		else
		{
			ACG::GLState::disableClientState( GL_VERTEX_ARRAY );
		}

		// normals
		if( vboNormalsOffset_ != -1 )
		{
			ACG::GLState::enableClientState( GL_NORMAL_ARRAY );
			ACG::GLState::normalPointer( GL_FLOAT, 0, (unsigned char *) 0 + vboNormalsOffset_ );
		}
		else
		{
			ACG::GLState::disableClientState( GL_NORMAL_ARRAY );
			glNormal3f( defaultNormal_[0], defaultNormal_[1], defaultNormal_[2] );
		}

		// pointsizes
		if( vboPointsizesOffset_ != -1 )
		{
			glClientActiveTexture( GL_TEXTURE0 ); // TODO: use ACG::GLState::clientActiveTexture() when implemented
			ACG::GLState::enableClientState( GL_TEXTURE_COORD_ARRAY );
			ACG::GLState::texcoordPointer( 1, GL_FLOAT, 0, (unsigned char *) 0 + vboPointsizesOffset_ );
		}
		else
		{
			glClientActiveTexture( GL_TEXTURE0 ); // TODO: use ACG::GLState::clientActiveTexture() when implemented
			ACG::GLState::disableClientState( GL_TEXTURE_COORD_ARRAY );
			glMultiTexCoord1f( GL_TEXTURE0, defaultPointsize_ );
		}

		// colors
		if( vboColorsOffset_ != -1 )
		{
			ACG::GLState::enableClientState( GL_SECONDARY_COLOR_ARRAY );
			glSecondaryColorPointer( 3, GL_UNSIGNED_BYTE, 0, (unsigned char *) 0 + vboColorsOffset_ ); // TODO: use ACG::GLState::secondaryColorPointer() when implemented
		}
		else
		{
			ACG::GLState::disableClientState( GL_SECONDARY_COLOR_ARRAY );
			glSecondaryColor3ub( defaultColor_[0], defaultColor_[1], defaultColor_[2] );
		}

		// selections
		if( vboSelectionsOffset_ != -1 )
		{
			glClientActiveTexture( GL_TEXTURE1 ); // TODO: use ACG::GLState::clientActiveTexture() when implemented
			ACG::GLState::enableClientState( GL_TEXTURE_COORD_ARRAY );
			ACG::GLState::texcoordPointer( 1, GL_FLOAT, 0, (unsigned char *) 0 + vboSelectionsOffset_ );
		}
		else
		{
			glClientActiveTexture( GL_TEXTURE1 ); // TODO: use ACG::GLState::clientActiveTexture() when implemented
			ACG::GLState::disableClientState( GL_TEXTURE_COORD_ARRAY );
			glMultiTexCoord1f( GL_TEXTURE1, 0.0f );
		}

		// pick colors
		if( vboPickColorsOffset_ != -1 )
		{
			ACG::GLState::enableClientState( GL_COLOR_ARRAY );
			ACG::GLState::colorPointer( 4, GL_UNSIGNED_BYTE, 0, (unsigned char *) 0 + vboPickColorsOffset_ );
		}
		else
		{
			ACG::GLState::disableClientState( GL_COLOR_ARRAY );
			glColor4ub( 255, 255, 255, 255 );
		}

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

		// enable "pointsize by program" depending on current rendermode
		if( rendermode == RENDERMODE_SPLATS || rendermode == RENDERMODE_DOTS )
			ACG::GLState::enable( GL_VERTEX_PROGRAM_POINT_SIZE );

		// draw as GLpoints
		glDrawArrays( GL_POINTS, 0, vboNumPoints_ );

		// disable arrays:
		// ---------------

		// points
		ACG::GLState::disableClientState( GL_VERTEX_ARRAY );

		// normals
		ACG::GLState::disableClientState( GL_NORMAL_ARRAY );

		// pointsizes
		glClientActiveTexture( GL_TEXTURE0 ); // TODO: use ACG::GLState::clientActiveTexture() when implemented
		ACG::GLState::disableClientState( GL_TEXTURE_COORD_ARRAY );

		// colors
		ACG::GLState::disableClientState( GL_SECONDARY_COLOR_ARRAY );

		// selections
		glClientActiveTexture( GL_TEXTURE1 ); // TODO: use ACG::GLState::clientActiveTexture() when implemented
		ACG::GLState::disableClientState( GL_TEXTURE_COORD_ARRAY );

		// pick colors
		ACG::GLState::disableClientState( GL_COLOR_ARRAY );

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

		// disable "pointsize by program"
		ACG::GLState::disable( GL_VERTEX_PROGRAM_POINT_SIZE );

		// make defaults current again
		glClientActiveTexture( GL_TEXTURE0 ); // TODO: use ACG::GLState::clientActiveTexture() when implemented
		glColor4f         ( 1.0f, 1.0f, 1.0f, 1.0f );
		glSecondaryColor3f( 1.0f, 1.0f, 1.0f );

		// deactivate VBO
		ACG::GLState::bindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
	}
Jan Möbius's avatar
Jan Möbius committed
315
316
317
318
319
320
321
322
323
}


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


// TODO: hack, because pick() doesn't get a drawmode
static DrawModes::DrawMode g_pickDrawMode;
void SplatCloudNode::enterPick( GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode )
324
325
326
{
    g_pickDrawMode = _drawMode;
}
Jan Möbius's avatar
Jan Möbius committed
327
328
329
330
331

// ----

void SplatCloudNode::pick( GLState &_state, PickTarget _target )
{
332
333
334
335
	// if something went wrong in the initialization, abort
	if( !splatCloud_ )
		return;

336
	// if pick target is valid...
Dominik Sibbing's avatar
Dominik Sibbing committed
337
338
339
	if( _target == PICK_ANYTHING || _target == PICK_VERTEX )
	{
		// set number of pick colors used (each points gets a unique pick color)
340
		if( !_state.pick_set_maximum( splatCloud_->numPoints() ) ) // number of points could have changed, so use new number of points (*not* the one in VBO memory!)
341
342
		{
			std::cerr << "SplatCloudNode::pick() : Color range too small, picking failed." << std::endl;
Dominik Sibbing's avatar
Dominik Sibbing committed
343
			return;
344
		}
Jan Möbius's avatar
Jan Möbius committed
345

346
347
		// if in color picking mode...
		if( _state.color_picking() )
Dominik Sibbing's avatar
Dominik Sibbing committed
348
		{
349
			// if picking base index has changed, rebuild pick colors block in VBO so new pick colors will be used
350
			if( pickingBaseIndex_ != _state.pick_current_index() )
351
352
353
			{
				pickColorsModified_ = true;
			}
Jan Möbius's avatar
Jan Möbius committed
354

355
356
357
			// TODO: see above ( enterPick() )
			draw( _state, g_pickDrawMode );
		}
Dominik Sibbing's avatar
Dominik Sibbing committed
358
	}
Jan Möbius's avatar
Jan Möbius committed
359
360
361
362
363
364
}


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


365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
void SplatCloudNode::copySplatCloud( const SplatCloud &_splatCloud )
{
	delete splatCloud_;

	splatCloud_ = new SplatCloud( _splatCloud );
	if( !splatCloud_ )
	{
		std::cerr << "SplatCloudNode::copySplatCloud() : Out of memory." << std::endl;
	}
}


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


Jan Möbius's avatar
Jan Möbius committed
380
381
void SplatCloudNode::createVBO()
{
382
383
384
385
386
387
388
389
390
	// create new VBO (if *not* already existing)
	if( vboGlId_ == 0 )
	{
		glGenBuffersARB( 1, &vboGlId_ );
		vboNumPoints_ = 0;
		vboData_      = 0;

		modifiedAll(); // (re-)build all data block in VBO memory the first time
	}
Jan Möbius's avatar
Jan Möbius committed
391
392
393
394
395
396
397
398
}


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


void SplatCloudNode::destroyVBO()
{
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
	// delete VBO (if existing)
	if( vboGlId_ != 0 )
	{
		glDeleteBuffersARB( 1, &vboGlId_ );
		vboGlId_      = 0;
		vboNumPoints_ = 0;
		vboData_      = 0;
	}
}


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


void SplatCloudNode::rebuildVBO( GLState &_state )
{
	// if something went wrong in the initialization, make VBO invalid and abort
	if( vboGlId_ == 0 || !splatCloud_)
	{
		vboData_ = 0;
		return;
	}
421

422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
	// activate VBO
	ACG::GLState::bindBufferARB( GL_ARRAY_BUFFER_ARB, vboGlId_ );

	// calculate size of data and offsets
	unsigned int numPoints = splatCloud_->numPoints();
	unsigned int size      = 0;

	int pointsOffset     = -1;
	int normalsOffset    = -1;
	int pointsizesOffset = -1;
	int colorsOffset     = -1;
	int selectionsOffset = -1;
	int pickColorsOffset = -1;

	if( splatCloud_->hasPoints()     ) { pointsOffset     = size; size += numPoints * 12; }
	if( splatCloud_->hasNormals()    ) { normalsOffset    = size; size += numPoints * 12; }
	if( splatCloud_->hasPointsizes() ) { pointsizesOffset = size; size += numPoints * 4;  }
	if( splatCloud_->hasColors()     ) { colorsOffset     = size; size += numPoints * 3;  }
	if( splatCloud_->hasSelections() ) { selectionsOffset = size; size += numPoints * 4;  }
	/* has pick colors = true       */ { pickColorsOffset = size; size += numPoints * 4;  }

	// tell GL that we are seldomly updating the VBO but are often drawing it
	glBufferDataARB( GL_ARRAY_BUFFER_ARB, size, 0, GL_STATIC_DRAW_ARB );

	// get pointer to VBO memory
	unsigned char *data = (unsigned char *) glMapBufferARB( GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB );

	// check if something went wrong during VBO mapping
	if( !data )
	{
		std::cout << "SplatCloudNode::rebuildVBO() : glMapBufferARB() failed." << std::endl;
		vboData_ = 0;
		return;
	}

	// if VBO memory block was moved or the internal block structure has to be changed, rebuild entire VBO
	if( vboData_ != data || vboStructureModified() )
	{
		vboNumPoints_ = numPoints;
		vboData_      = data;

		vboPointsOffset_     = pointsOffset;
		vboNormalsOffset_    = normalsOffset;
		vboPointsizesOffset_ = pointsizesOffset;
		vboColorsOffset_     = colorsOffset;
		vboSelectionsOffset_ = selectionsOffset;
		vboPickColorsOffset_ = pickColorsOffset;

		// mark all data block to rebuild them lateron
		modifiedAll();
	}

	// if in color picking mode...
	if( _state.color_picking() )
	{
		// store picking base index
		pickingBaseIndex_ = _state.pick_current_index();
	}

	// rebuild data blocks if needed
	if( pointsModified_     ) rebuildVBOPoints();
	if( normalsModified_    ) rebuildVBONormals();
	if( pointsizesModified_ ) rebuildVBOPointsizes();
	if( colorsModified_     ) rebuildVBOColors();
	if( selectionsModified_ ) rebuildVBOSelections();
	if( pickColorsModified_ ) rebuildVBOPickColors( _state );

#	ifdef REPORT_VBO_UPDATES
	std::cout << std::endl;
#	endif

	// every block in VBO memory has been updated
	pointsModified_     = false;
	normalsModified_    = false;
	pointsizesModified_ = false;
	colorsModified_     = false;
	selectionsModified_ = false;
	pickColorsModified_ = false;

	// release pointer to VBO memory. if something went wrong, make VBO invalid and abort
	if( !glUnmapBufferARB( GL_ARRAY_BUFFER_ARB ) )
	{
		vboData_ = 0;
		return;
	}

	// deactivate VBO
	ACG::GLState::bindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
Jan Möbius's avatar
Jan Möbius committed
510
511
512
513
514
515
516
517
}


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


static void addFloatToBuffer( float _value, unsigned char *&_buffer )
{
518
519
520
521
522
523
524
525
    // get pointer
    unsigned char *v = (unsigned char *) &_value;

    // copy over 4 bytes
    *_buffer++ = *v++;
    *_buffer++ = *v++;
    *_buffer++ = *v++;
    *_buffer++ = *v;
Jan Möbius's avatar
Jan Möbius committed
526
527
528
529
530
531
}


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


532
static void addUCharToBuffer( unsigned char _value, unsigned char *&_buffer )
Jan Möbius's avatar
Jan Möbius committed
533
{
534
535
536
537
538
539
540
541
542
543
544
545
546
547
    // get pointer
    unsigned char *v = (unsigned char *) &_value;

    // copy over 1 byte
    *_buffer++ = *v;
}


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


void SplatCloudNode::rebuildVBOPoints()
{
	if( vboPointsOffset_ == -1 || !splatCloud_->hasPoints() )
548
549
		return;

550
551
552
#	ifdef REPORT_VBO_UPDATES
	std::cout << "SplatCloudNode::rebuildVBOPoints()" << std::endl;
#	endif
553

554
555
	// get pointer to buffer
	unsigned char *buffer = vboData_ + vboPointsOffset_;
556

557
558
559
560
561
562
563
564
565
566
567
	// for all points...
	unsigned int i, num = splatCloud_->numPoints();
	for( i=0; i<num; ++i )
	{
		// add point
		const Point &p = getPoint( i );
		addFloatToBuffer( p[0], buffer );
		addFloatToBuffer( p[1], buffer );
		addFloatToBuffer( p[2], buffer );
	}
}
568
569


570
//----------------------------------------------------------------
571
572


573
574
575
576
void SplatCloudNode::rebuildVBONormals()
{
	if( vboNormalsOffset_ == -1 || !splatCloud_->hasNormals()  )
		return;
577

578
579
580
#	ifdef REPORT_VBO_UPDATES
	std::cout << "SplatCloudNode::rebuildVBONormals()" << std::endl;
#	endif
581

582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
	// get pointer to buffer
	unsigned char *buffer = vboData_ + vboNormalsOffset_;

	// for all points...
	unsigned int i, num = splatCloud_->numPoints();
	for( i=0; i<num; ++i )
	{
		// add normal
		const Normal &n = getNormal( i );
		addFloatToBuffer( n[0], buffer );
		addFloatToBuffer( n[1], buffer );
		addFloatToBuffer( n[2], buffer );
	}
}


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


void SplatCloudNode::rebuildVBOPointsizes()
{
	if( vboPointsizesOffset_ == -1 || !splatCloud_->hasPointsizes()  )
		return;
605

606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
#	ifdef REPORT_VBO_UPDATES
	std::cout << "SplatCloudNode::rebuildVBOPointsizes()" << std::endl;
#	endif

	// get pointer to buffer
	unsigned char *buffer = vboData_ + vboPointsizesOffset_;

	// for all points...
	unsigned int i, num = splatCloud_->numPoints();
	for( i=0; i<num; ++i )
	{
		// add pointsize
		const Pointsize &ps = getPointsize( i );
		addFloatToBuffer( ps, buffer );
	}
}


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


void SplatCloudNode::rebuildVBOColors()
{
	if( vboColorsOffset_ == -1 || !splatCloud_->hasColors()  )
		return;

#	ifdef REPORT_VBO_UPDATES
	std::cout << "SplatCloudNode::rebuildVBOColors()" << std::endl;
#	endif

	// get pointer to buffer
	unsigned char *buffer = vboData_ + vboColorsOffset_;

	// for all points...
	unsigned int i, num = splatCloud_->numPoints();
	for( i=0; i<num; ++i )
	{
		// add color
		const Color &c = getColor( i );
		addUCharToBuffer( c[0], buffer );
		addUCharToBuffer( c[1], buffer );
		addUCharToBuffer( c[2], buffer );
	}
}


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


void SplatCloudNode::rebuildVBOSelections()
{
	if( vboSelectionsOffset_ == -1 || !splatCloud_->hasSelections()  )
		return;

#	ifdef REPORT_VBO_UPDATES
	std::cout << "SplatCloudNode::rebuildVBOSelections()" << std::endl;
#	endif

	// get pointer to buffer
	unsigned char *buffer = vboData_ + vboSelectionsOffset_;

	// for all points...
	unsigned int i, num = splatCloud_->numPoints();
	for( i=0; i<num; ++i )
	{
		const bool &s = getSelection( i );
		addFloatToBuffer( (s ? 1.0f : 0.0f), buffer );
	}
}


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


void SplatCloudNode::rebuildVBOPickColors( GLState &_state )
{
	if( vboPickColorsOffset_ == -1 )
		return;

#	ifdef REPORT_VBO_UPDATES
	std::cout << "SplatCloudNode::rebuildVBOPickColors()" << std::endl;
#	endif

	// get pointer to buffer
	unsigned char *buffer = vboData_ + vboPickColorsOffset_;

	// for all points...
	unsigned int i, num = splatCloud_->numPoints();
	for( i=0; i<num; ++i )
	{
		// add pick color
		const Vec4uc &pc = _state.pick_get_name_color( i );
		addUCharToBuffer( pc[0], buffer );
		addUCharToBuffer( pc[1], buffer );
		addUCharToBuffer( pc[2], buffer );
		addUCharToBuffer( pc[3], buffer );
	}
703
704
705
}


Jan Möbius's avatar
Jan Möbius committed
706
707
708
709
710
//================================================================


} // namespace SceneGraph
} // namespace ACG