SplatCloudNode.cc 19.6 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( const SplatCloud &_splatCloud, BaseNode *_parent, std::string _name ) : 
73
	BaseNode            ( _parent, _name ), 
74
	splatCloud_         ( _splatCloud ), 
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
	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
{
	// add (possibly) new drawmodes
	pointsDrawMode_ = DrawModes::addDrawMode( "Points" );
	dotsDrawMode_   = DrawModes::addDrawMode( "Dots"   );
	splatsDrawMode_ = DrawModes::addDrawMode( "Splats" );

103
	// create a new VBO (will be invalid and rebuilt the next time drawn (or picked))
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
	createVBO();
}


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


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


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


Jan Möbius's avatar
Jan Möbius committed
120 121
void SplatCloudNode::boundingBox( ACG::Vec3d &_bbMin, ACG::Vec3d &_bbMax )
{
122 123
    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
124

125 126
    SplatCloud::PointVector::const_iterator pointIter, pointsEnd = splatCloud_.points().end();
    for ( pointIter = splatCloud_.points().begin(); pointIter != pointsEnd; ++pointIter )
127 128
    {
        const Point &p = *pointIter;
Jan Möbius's avatar
Jan Möbius committed
129

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

132 133 134
        bbMin.minimize( acgp );
        bbMax.maximize( acgp );
    }
Jan Möbius's avatar
Jan Möbius committed
135

136 137
    _bbMin.minimize( ACG::Vec3d( bbMin ) );
    _bbMax.maximize( ACG::Vec3d( bbMax ) );
Jan Möbius's avatar
Jan Möbius committed
138 139 140 141 142
}


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

143

Jan Möbius's avatar
Jan Möbius committed
144 145
void SplatCloudNode::draw( GLState &_state, const DrawModes::DrawMode &_drawMode )
{
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 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
	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
297 298 299 300 301 302 303 304 305
}


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


// 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 )
306 307 308
{
    g_pickDrawMode = _drawMode;
}
Jan Möbius's avatar
Jan Möbius committed
309 310 311 312 313

// ----

void SplatCloudNode::pick( GLState &_state, PickTarget _target )
{
314
	// if pick target is valid...
Dominik Sibbing's avatar
Dominik Sibbing committed
315 316 317
	if( _target == PICK_ANYTHING || _target == PICK_VERTEX )
	{
		// set number of pick colors used (each points gets a unique pick color)
318
		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!)
319 320
		{
			std::cerr << "SplatCloudNode::pick() : Color range too small, picking failed." << std::endl;
Dominik Sibbing's avatar
Dominik Sibbing committed
321
			return;
322
		}
Jan Möbius's avatar
Jan Möbius committed
323

324 325
		// if in color picking mode...
		if( _state.color_picking() )
Dominik Sibbing's avatar
Dominik Sibbing committed
326
		{
327
			// if picking base index has changed, rebuild pick colors block in VBO so new pick colors will be used
328
			if( pickingBaseIndex_ != _state.pick_current_index() )
329 330 331
			{
				pickColorsModified_ = true;
			}
Jan Möbius's avatar
Jan Möbius committed
332

333 334 335
			// TODO: see above ( enterPick() )
			draw( _state, g_pickDrawMode );
		}
Dominik Sibbing's avatar
Dominik Sibbing committed
336
	}
Jan Möbius's avatar
Jan Möbius committed
337 338 339 340 341 342 343 344
}


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


void SplatCloudNode::createVBO()
{
345 346 347 348 349 350 351 352 353
	// 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
354 355 356 357 358 359 360 361
}


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


void SplatCloudNode::destroyVBO()
{
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
	// 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
379
	if( vboGlId_ == 0 )
380 381 382 383
	{
		vboData_ = 0;
		return;
	}
384

385 386 387 388
	// activate VBO
	ACG::GLState::bindBufferARB( GL_ARRAY_BUFFER_ARB, vboGlId_ );

	// calculate size of data and offsets
389
	unsigned int numPoints = splatCloud_.numPoints();
390 391 392 393 394 395 396 397 398
	unsigned int size      = 0;

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

399 400 401 402 403
	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;  }
Jan Möbius's avatar
Jan Möbius committed
404
	/* has pick colors = true      */ { pickColorsOffset = size; size += numPoints * 4;  }
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 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

	// 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
473 474 475 476 477 478 479 480
}


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


static void addFloatToBuffer( float _value, unsigned char *&_buffer )
{
481 482 483 484 485 486 487 488
    // 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
489 490 491 492 493 494
}


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


495
static void addUCharToBuffer( unsigned char _value, unsigned char *&_buffer )
Jan Möbius's avatar
Jan Möbius committed
496
{
497 498 499 500 501 502 503 504 505 506 507 508 509
    // get pointer
    unsigned char *v = (unsigned char *) &_value;

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


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


void SplatCloudNode::rebuildVBOPoints()
{
510
	if( vboPointsOffset_ == -1 || !splatCloud_.hasPoints() )
511 512
		return;

513 514 515
#	ifdef REPORT_VBO_UPDATES
	std::cout << "SplatCloudNode::rebuildVBOPoints()" << std::endl;
#	endif
516

517 518
	// get pointer to buffer
	unsigned char *buffer = vboData_ + vboPointsOffset_;
519

520
	// for all points...
521
	unsigned int i, num = splatCloud_.numPoints();
522 523 524 525 526 527 528 529 530
	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 );
	}
}
531 532


533
//----------------------------------------------------------------
534 535


536 537
void SplatCloudNode::rebuildVBONormals()
{
538
	if( vboNormalsOffset_ == -1 || !splatCloud_.hasNormals()  )
539
		return;
540

541 542 543
#	ifdef REPORT_VBO_UPDATES
	std::cout << "SplatCloudNode::rebuildVBONormals()" << std::endl;
#	endif
544

545 546 547 548
	// get pointer to buffer
	unsigned char *buffer = vboData_ + vboNormalsOffset_;

	// for all points...
549
	unsigned int i, num = splatCloud_.numPoints();
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
	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()
{
566
	if( vboPointsizesOffset_ == -1 || !splatCloud_.hasPointsizes()  )
567
		return;
568

569 570 571 572 573 574 575 576
#	ifdef REPORT_VBO_UPDATES
	std::cout << "SplatCloudNode::rebuildVBOPointsizes()" << std::endl;
#	endif

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

	// for all points...
577
	unsigned int i, num = splatCloud_.numPoints();
578 579 580 581 582 583 584 585 586 587 588 589 590 591
	for( i=0; i<num; ++i )
	{
		// add pointsize
		const Pointsize &ps = getPointsize( i );
		addFloatToBuffer( ps, buffer );
	}
}


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


void SplatCloudNode::rebuildVBOColors()
{
592
	if( vboColorsOffset_ == -1 || !splatCloud_.hasColors()  )
593 594 595 596 597 598 599 600 601 602
		return;

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

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

	// for all points...
603
	unsigned int i, num = splatCloud_.numPoints();
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
	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()
{
620
	if( vboSelectionsOffset_ == -1 || !splatCloud_.hasSelections()  )
621 622 623 624 625 626 627 628 629 630
		return;

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

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

	// for all points...
631
	unsigned int i, num = splatCloud_.numPoints();
632 633 634 635 636 637 638 639 640 641 642 643 644
	for( i=0; i<num; ++i )
	{
		const bool &s = getSelection( i );
		addFloatToBuffer( (s ? 1.0f : 0.0f), buffer );
	}
}


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


void SplatCloudNode::rebuildVBOPickColors( GLState &_state )
{
Jan Möbius's avatar
Jan Möbius committed
645
	if( vboPickColorsOffset_ == -1 || !splatCloud_.hasPoints() )
646 647 648 649 650 651 652 653 654 655
		return;

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

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

	// for all points...
656
	unsigned int i, num = splatCloud_.numPoints();
657 658 659 660 661 662 663 664 665
	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 );
	}
666 667 668
}


Jan Möbius's avatar
Jan Möbius committed
669 670 671 672 673
//================================================================


} // namespace SceneGraph
} // namespace ACG