59 #include <ACG/GL/acg_glew.hh> 61 #include "SplatCloudNode.hh" 80 const SplatCloudNode::Index SplatCloudNode::DEFAULT_INDEX ( -1);
81 const SplatCloudNode::Viewlist SplatCloudNode::DEFAULT_VIEWLIST ( 0.0);
82 const SplatCloudNode::Selection SplatCloudNode::DEFAULT_SELECTION(
false);
90 splatCloud_ ( _splatCloud ),
91 positionsModified_ ( false ),
92 colorsModified_ ( false ),
93 normalsModified_ ( false ),
94 pointsizesModified_ ( false ),
95 selectionsModified_ ( false ),
96 pickColorsModified_ ( false ),
97 defaultColor_ (
Color (0,0,0) ),
98 defaultNormal_ (
Normal (0,0,0) ),
99 defaultPointsize_ ( Pointsize( 0.0) ),
100 splatsDrawMode_ ( DrawModes::NONE ),
101 dotsDrawMode_ ( DrawModes::NONE ),
102 pointsDrawMode_ ( DrawModes::NONE ),
103 pickingBaseIndex_ ( 0 ),
104 pickDrawMode_ ( DrawModes::NONE ),
108 vboPositionsOffset_ ( -1 ),
109 vboColorsOffset_ ( -1 ),
110 vboNormalsOffset_ ( -1 ),
111 vboPointsizesOffset_( -1 ),
112 vboSelectionsOffset_( -1 ),
113 vboPickColorsOffset_( -1 )
139 ACG::Vec3f bbMin( FLT_MAX, FLT_MAX, FLT_MAX );
140 ACG::Vec3f bbMax(-FLT_MAX,-FLT_MAX,-FLT_MAX );
145 for( i=0; i<num; ++i )
167 static const int RENDERMODE_DOTS = 1;
168 static const int RENDERMODE_SPLATS = 2;
173 rendermode = RENDERMODE_SPLATS;
175 rendermode = RENDERMODE_DOTS;
177 static const int RENDERMODE_POINTS = 0;
178 rendermode = RENDERMODE_POINTS;
187 rebuildVBO( _state );
210 if( vboColorsOffset_ != -1 )
213 glSecondaryColorPointer( 3, GL_UNSIGNED_BYTE, 0, (
unsigned char *) 0 + vboColorsOffset_ );
222 if( vboNormalsOffset_ != -1 )
230 glNormal3f( defaultNormal_[0], defaultNormal_[1], defaultNormal_[2] );
234 if( vboPointsizesOffset_ != -1 )
236 glClientActiveTexture( GL_TEXTURE0 );
242 glClientActiveTexture( GL_TEXTURE0 );
244 glMultiTexCoord1f( GL_TEXTURE0, defaultPointsize_ );
248 if( vboSelectionsOffset_ != -1 )
250 glClientActiveTexture( GL_TEXTURE1 );
256 glClientActiveTexture( GL_TEXTURE1 );
258 glMultiTexCoord1f( GL_TEXTURE1, 0.0f );
262 if( vboPickColorsOffset_ != -1 )
270 glColor4ub( 255, 255, 255, 255 );
277 if( rendermode == RENDERMODE_SPLATS || rendermode == RENDERMODE_DOTS )
283 glDrawArrays( GL_POINTS, 0, vboNumSplats_ );
298 glClientActiveTexture( GL_TEXTURE0 );
302 glClientActiveTexture( GL_TEXTURE1 );
315 glClientActiveTexture( GL_TEXTURE0 );
316 glColor4f ( 1.0f, 1.0f, 1.0f, 1.0f );
317 glSecondaryColor3f( 1.0f, 1.0f, 1.0f );
336 std::cerr <<
"SplatCloudNode::pick() : Color range too small, picking failed." << std::endl;
346 pickColorsModified_ =
true;
350 draw( _state, pickDrawMode_ );
359 void SplatCloudNode::createVBO()
364 glGenBuffersARB( 1, &vboGlId_ );
376 void SplatCloudNode::destroyVBO()
381 glDeleteBuffersARB( 1, &vboGlId_ );
392 void SplatCloudNode::rebuildVBO(
GLState &_state )
406 unsigned int size = 0;
408 int positionsOffset = -1;
409 int colorsOffset = -1;
410 int normalsOffset = -1;
411 int pointsizesOffset = -1;
412 int selectionsOffset = -1;
413 int pickColorsOffset = -1;
420 { pickColorsOffset = size; size += numSplats * 4; }
423 glBufferDataARB( GL_ARRAY_BUFFER_ARB, size, 0, GL_STATIC_DRAW_ARB );
426 unsigned char *data = (
unsigned char *) glMapBufferARB( GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB );
431 std::cout <<
"SplatCloudNode::rebuildVBO() : glMapBufferARB() failed." << std::endl;
439 vboNumSplats_ = numSplats;
443 vboColorsOffset_ = colorsOffset;
444 vboNormalsOffset_ = normalsOffset;
445 vboPointsizesOffset_ = pointsizesOffset;
446 vboSelectionsOffset_ = selectionsOffset;
447 vboPickColorsOffset_ = pickColorsOffset;
462 if( colorsModified_ ) rebuildVBOColors();
463 if( normalsModified_ ) rebuildVBONormals();
464 if( pointsizesModified_ ) rebuildVBOPointsizes();
465 if( selectionsModified_ ) rebuildVBOSelections();
466 if( pickColorsModified_ ) rebuildVBOPickColors( _state );
468 # ifdef REPORT_VBO_UPDATES 469 std::cout << std::endl;
474 colorsModified_ =
false;
475 normalsModified_ =
false;
476 pointsizesModified_ =
false;
477 selectionsModified_ =
false;
478 pickColorsModified_ =
false;
481 if( !glUnmapBufferARB( GL_ARRAY_BUFFER_ARB ) )
483 std::cout <<
"SplatCloudNode::rebuildVBO() : glUnmapBufferARB() failed." << std::endl;
496 static void addFloatToBuffer(
float _value,
unsigned char *&_buffer )
499 unsigned char *v = (
unsigned char *) &_value;
512 static void addIntToBuffer(
int _value,
unsigned char *&_buffer )
515 unsigned char *v = (
unsigned char *) &_value;
528 static void addUCharToBuffer(
unsigned char _value,
unsigned char *&_buffer )
531 unsigned char *v = (
unsigned char *) &_value;
541 void SplatCloudNode::rebuildVBOPositions()
546 # ifdef REPORT_VBO_UPDATES 547 std::cout <<
"SplatCloudNode::rebuildVBOPositions()" << std::endl;
555 for( i=0; i<num; ++i )
559 addFloatToBuffer( p[0], buffer );
560 addFloatToBuffer( p[1], buffer );
561 addFloatToBuffer( p[2], buffer );
569 void SplatCloudNode::rebuildVBOColors()
574 # ifdef REPORT_VBO_UPDATES 575 std::cout <<
"SplatCloudNode::rebuildVBOColors()" << std::endl;
579 unsigned char *buffer = vboData_ + vboColorsOffset_;
583 for( i=0; i<num; ++i )
586 const Color &c = getColor( i );
587 addUCharToBuffer( c[0], buffer );
588 addUCharToBuffer( c[1], buffer );
589 addUCharToBuffer( c[2], buffer );
597 void SplatCloudNode::rebuildVBONormals()
602 # ifdef REPORT_VBO_UPDATES 603 std::cout <<
"SplatCloudNode::rebuildVBONormals()" << std::endl;
607 unsigned char *buffer = vboData_ + vboNormalsOffset_;
611 for( i=0; i<num; ++i )
614 const Normal &n = getNormal( i );
615 addFloatToBuffer( n[0], buffer );
616 addFloatToBuffer( n[1], buffer );
617 addFloatToBuffer( n[2], buffer );
625 void SplatCloudNode::rebuildVBOPointsizes()
630 # ifdef REPORT_VBO_UPDATES 631 std::cout <<
"SplatCloudNode::rebuildVBOPointsizes()" << std::endl;
635 unsigned char *buffer = vboData_ + vboPointsizesOffset_;
639 for( i=0; i<num; ++i )
642 const Pointsize &ps = getPointsize( i );
643 addFloatToBuffer( ps, buffer );
651 void SplatCloudNode::rebuildVBOSelections()
656 # ifdef REPORT_VBO_UPDATES 657 std::cout <<
"SplatCloudNode::rebuildVBOSelections()" << std::endl;
661 unsigned char *buffer = vboData_ + vboSelectionsOffset_;
665 for( i=0; i<num; ++i )
667 const bool &s = getSelection( i );
668 addFloatToBuffer( (s ? 1.0f : 0.0f), buffer );
676 void SplatCloudNode::rebuildVBOPickColors(
GLState &_state )
681 # ifdef REPORT_VBO_UPDATES 682 std::cout <<
"SplatCloudNode::rebuildVBOPickColors()" << std::endl;
686 unsigned char *buffer = vboData_ + vboPickColorsOffset_;
690 for( i=0; i<num; ++i )
694 addUCharToBuffer( pc[0], buffer );
695 addUCharToBuffer( pc[1], buffer );
696 addUCharToBuffer( pc[2], buffer );
697 addUCharToBuffer( pc[3], buffer );
unsigned int pick_current_index() const
Returns the current color picking index (can be used for caching)
static void colorPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glColorPointer, supports locking
static void enableClientState(GLenum _cap)
replaces glEnableClientState, supports locking
const DrawMode & addDrawMode(const std::string &_name, bool _propertyBased)
Add a custom DrawMode.
bool hasSelections() const
Return the availability of the predefined property.
bool hasPointsizes() const
Return the availability of the predefined property.
bool hasColors() const
Return the availability of the predefined property.
bool color_picking() const
Is color picking active?
bool vboStructureModified() const
returns true iff the internal block structure of the VBO has to be changed
static void vertexPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glVertexPointer, supports locking
Vec4uc pick_get_name_color(unsigned int _idx)
int vboPositionsOffset_
offsets relative to vboData_ or -1 if not present in VBO
bool positionsModified_
marks if parts of the data has been modified
PickTarget
What target to use for picking.
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
static void enable(GLenum _cap)
replaces glEnable, but supports locking
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
bool pick_set_maximum(unsigned int _idx)
Set the maximal number of primitives/components of your object.
unsigned int numSplats() const
Get the number of splats.
SplatCloudNode(const SplatCloud &_splatCloud, BaseNode *_parent=0, std::string _name="<SplatCloudNode>")
constructor
Position & positions(int _idx)
Get a reference of the predefined property's value.
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
static void disable(GLenum _cap)
replaces glDisable, but supports locking
Namespace providing different geometric functions concerning angles.
picks verices (may not be implemented for all nodes)
static void disableClientState(GLenum _cap)
replaces glDisableClientState, supports locking
const SplatCloud & splatCloud_
reference to class containing all the data
bool hasNormals() const
Return the availability of the predefined property.
static void normalPointer(GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glNormalPointer, supports locking
bool containsAtomicDrawMode(DrawMode _atomicDrawMode) const
Check whether an Atomic DrawMode is active in this draw Mode.
static void texcoordPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glTexcoordPointer, supports locking
bool vboModified() const
return true iff any of the data values in the VBO has to be changed
void pick(GLState &_state, PickTarget _target)
picking
bool hasPositions() const
Return the availability of the predefined property.
pick any of the prior targets (should be implemented for all nodes)
~SplatCloudNode()
destructor
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
void boundingBox(ACG::Vec3d &_bbMin, ACG::Vec3d &_bbMax)
update bounding box
const Position & getPosition(int _idx) const
if the data array exists, the entry with the given index is returned, otherwise the default value is ...
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw the SplatCloud
Color defaultColor_
the default values will be used when the specific array is not present
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active