53 #define ACG_POLYLINECOLLECTIONNODET_C 59 #include "PolyLineCollectionNodeT.hh" 60 #include <ACG/GL/gl.hh> 61 #include <ACG/Utils/VSToolsT.hh> 63 #include <OpenMesh/Core/Utils/vector_cast.hh> 79 template <
class PolyLineCollection>
82 polyline_collection_(_pl),
85 total_vertex_count_(0),
86 total_segment_count_(0)
90 drawMode(DrawModes::WIREFRAME | DrawModes::POINTS );
95 template <
class PolyLineCollection>
98 for (
size_t i = 0; i < polylineNodes_.size(); ++i)
99 delete polylineNodes_[i];
104 template <
class PolyLineCollection>
113 for (
unsigned int i=0; i< polyline->
n_vertices(); ++i)
126 template <
class PolyLineCollection>
131 return (DrawModes::WIREFRAME | DrawModes::POINTS | DrawModes::POINTS_COLORED | DrawModes::EDGES_COLORED );
138 template <
class PolyLineCollection>
144 if ( polyline_collection_.n_polylines() == 0 )
156 vertexDecl_.activateFixedFunction();
160 bool vertexColors = _drawMode & DrawModes::POINTS_COLORED;
163 if (_drawMode & DrawModes::POINTS || vertexColors)
168 vertexDecl_.deactivateFixedFunction();
169 vertexDeclVColor_.activateFixedFunction();
173 glDrawArrays(GL_POINTS, 0, total_vertex_count_);
176 vertexDeclVColor_.deactivateFixedFunction();
177 vertexDecl_.activateFixedFunction();
191 glDrawArrays(GL_POINTS, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
200 bool edgeColors = _drawMode & DrawModes::EDGES_COLORED;
203 if (_drawMode & DrawModes::WIREFRAME || edgeColors) {
208 vertexDecl_.deactivateFixedFunction();
209 vertexDeclEColor_.activateFixedFunction();
213 glDrawElements(GL_LINES, total_segment_count_ * 2, GL_UNSIGNED_INT, 0);
217 vertexDeclEColor_.deactivateFixedFunction();
218 vertexDecl_.activateFixedFunction();
230 glDrawArrays(GL_LINE_STRIP, offsets_[it.idx()].first, offsets_[it.idx()].second);
232 glDrawArrays(GL_LINE_STRIP, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
240 std::vector<int> selected_indices;
246 int offset = offsets_[it.idx()].first;
247 for(
size_t i = 0; i < polyline->
n_vertices(); ++i){
251 if(polyline->edge_selected(i)){
252 selected_indices.push_back(offset + i);
253 selected_indices.push_back(offset + i + 1);
259 if(selected_indices.size() > 0){
260 glDrawElements(GL_LINES, selected_indices.size(), GL_UNSIGNED_INT, selected_indices.data());
267 vertexDecl_.deactivateFixedFunction();
274 template <
class PolyLineCollection>
279 size_t numPolyLines = polyline_collection_.n_polylines();
281 if ( numPolyLines == 0 )
289 size_t numPickIDs = 0;
291 for (
size_t i = 0; i < numPolyLines; ++i)
300 pick_vertices( _state);
306 size_t numPickIDs = 0;
308 for (
size_t i = 0; i < numPolyLines; ++i)
317 pick_edges(_state, 0);
323 size_t numPickVertices = 0;
324 size_t numPickIDs = 0;
326 for (
size_t i = 0; i < numPolyLines; ++i)
341 pick_vertices( _state);
342 pick_edges( _state, static_cast<unsigned int>(numPickVertices));
353 template <
class PolyLineCollection>
358 size_t numPolyLines = polyline_collection_.n_polylines();
363 glPointSize(point_size_old+3.0f);
366 desc.vertexTemplateFile =
"Picking/pick_vertices_vs.glsl";
367 desc.fragmentTemplateFile =
"Picking/pick_vertices_fs.glsl";
370 if (pickVertexShader && pickVertexShader->
isLinked())
376 pickVertexShader->
use();
382 vertexDecl_.activateShaderPipeline(pickVertexShader);
385 for (
size_t i = 0; i < numPolyLines; ++i)
391 pickVertexShader->
setUniform(
"pickVertexOffset", pickVertexOffset);
393 glDrawArrays(GL_POINTS, offsets_[i].first, offsets_[i].second-1);
395 pickVertexOffset += int(offsets_[i].second - 1);
399 vertexDecl_.deactivateShaderPipeline(pickVertexShader);
410 size_t curPickID = 0;
412 for (
size_t i = 0; i < numPolyLines; ++i)
418 for (
size_t v = 0; v < line->
n_vertices(); ++v)
430 glPointSize(point_size_old);
435 template <
class PolyLineCollection>
440 size_t numPolyLines = polyline_collection_.n_polylines();
444 glLineWidth(line_width_old+3.0f);
449 desc.vertexTemplateFile =
"Picking/vertex.glsl";
450 desc.fragmentTemplateFile =
"Picking/pick_vertices_fs2.glsl";
454 desc.vertexTemplateFile =
"Picking/pick_vertices_vs.glsl";
455 desc.fragmentTemplateFile =
"Picking/pick_vertices_fs.glsl";
459 if (pickEdgeShader && pickEdgeShader->
isLinked())
465 pickEdgeShader->
use();
471 vertexDecl_.activateShaderPipeline(pickEdgeShader);
473 for (
size_t i = 0; i < numPolyLines; ++i)
479 pickEdgeShader->
setUniform(
"pickVertexOffset", pickVertexOffset);
481 size_t numIndices = line->
is_closed() ? offsets_[i].second : offsets_[i].second - 1;
482 glDrawArrays(GL_LINE_STRIP, offsets_[i].first, numIndices);
484 pickVertexOffset += int(line->
n_edges());
488 vertexDecl_.deactivateShaderPipeline(pickEdgeShader);
499 size_t curPickID = _offset;
501 for (
size_t i = 0; i < numPolyLines; ++i)
509 for (
size_t v = 0; v < line->
n_edges(); ++v)
524 glLineWidth(line_width_old);
529 template <
class PolyLineCollection>
534 bool lines_did_change =
false;
536 if( offsets_.size() != polyline_collection_.n_polylines() ){
537 offsets_.resize(polyline_collection_.n_polylines());
538 lines_did_change =
true;
542 total_vertex_count_ = 0;
543 total_segment_count_ = 0;
545 std::pair<size_t, size_t> current_offset;
546 current_offset.first = offset;
548 current_offset.second = it->n_vertices() + 1;
550 current_offset.second = 0;
553 if(current_offset != offsets_[it.idx()]){
554 lines_did_change =
true;
557 offsets_[it.idx()] = current_offset;
558 total_vertex_count_ += current_offset.second;
559 total_segment_count_ += it->n_edges();
561 offset += current_offset.second;
564 if(lines_did_change){
571 size_t prevLineCount = polylineNodes_.size();
572 size_t curLineCount = polyline_collection_.n_polylines();
576 if (curLineCount < prevLineCount)
578 for (
size_t i = curLineCount; i < prevLineCount; ++i)
579 delete polylineNodes_[i];
582 polylineNodes_.resize(curLineCount);
585 for(
size_t i = 0; i < curLineCount; ++i) {
594 vertexDeclVColor_.clear();
595 vertexDeclEColor_.clear();
598 if (curLineCount > 0) {
600 polylineNodes_[0]->setupVertexDeclaration(&vertexDeclVColor_, 1);
601 polylineNodes_[0]->setupVertexDeclaration(&vertexDeclEColor_, 2);
605 bool equalVertexFormat =
true;
607 for (
size_t i = 1; i < curLineCount; ++i) {
611 for (
int k = 0; k < 3; ++k)
612 polylineNodes_[i]->setupVertexDeclaration(&decl[k], k);
614 if (decl[0] != vertexDecl_ ||
615 decl[1] != vertexDeclVColor_ ||
616 decl[2] != vertexDeclEColor_)
617 equalVertexFormat =
false;
621 if (!equalVertexFormat)
622 std::cerr <<
"PolyLineCollection error: polylines do not have the same vertex format, so the collection vbo could not be created" << std::endl;
627 size_t bufferSize = stride * offset;
629 if (bufferSize > 0) {
630 std::vector<char> vboData(bufferSize);
631 std::vector<unsigned int> iboData(total_segment_count_ * 2);
633 size_t offsetSegment = 0;
635 for(
size_t i = 0; i < curLineCount; ++i) {
639 if (polyline && polylineNodes_[i] && polyline->
n_vertices() > 0) {
642 size_t offset = offsets_[i].first;
644 polylineNodes_[i]->fillVertexBuffer(&vboData[(offset) * stride], bufferSize,
true);
647 for (
size_t k = 0; k < polyline->
n_edges(); ++k) {
648 iboData[(offsetSegment + k) * 2] = offset + k;
649 iboData[(offsetSegment + k) * 2 + 1] = offset + (k + 1) % polyline->
n_vertices();
651 offsetSegment += polyline->
n_edges();
658 vbo_.upload(vboData.size() *
sizeof(vboData[0]), &vboData[0], GL_STATIC_DRAW);
661 ibo_.upload(iboData.size() *
sizeof(iboData[0]), &iboData[0], GL_STATIC_DRAW);
678 template <
class PolyLineCollection>
684 if ( polyline_collection_.n_polylines() == 0 )
690 _state.
enable(GL_COLOR_MATERIAL);
691 _state.
enable(GL_LIGHTING);
694 ro.setMaterial(_mat);
707 ro.debugName =
"PolyLineCollection";
753 ro.setMaterial(&localMaterial);
756 if(props->primitive() == ACG::SceneGraph::DrawModes::PRIMITIVE_POINT){
758 ro.debugName =
"polyline.Points.selected";
760 ro.setMaterial(&localMaterial);
766 ro.debugName =
"polylinecollection.Points";
768 ro.setMaterial(&localMaterial);
775 applyRenderObjectSettings(props->primitive(), &ro);
778 ro.glDrawArrays(GL_POINTS, 0, total_vertex_count_);
781 }
else if(props->primitive() == ACG::SceneGraph::DrawModes::PRIMITIVE_WIREFRAME ||
782 props->primitive() == ACG::SceneGraph::DrawModes::PRIMITIVE_EDGE){
784 ro.debugName =
"polyline.Wireframe.selected";
786 ro.setMaterial(&localMaterial);
791 ro.debugName =
"polylinecollection.Wireframe";
793 ro.setMaterial(&localMaterial);
802 applyRenderObjectSettings(props->primitive(), &ro);
806 ro.glDrawElements(GL_LINES, total_segment_count_ * 2, GL_UNSIGNED_INT, 0);
const Vec4f & diffuse_color() const
get diffuse color
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
void pointSize(float _sz)
set point size (default: 1.0)
float line_width() const
get line width
float point_size() const
get point size
void use()
Enables the program object for using.
Namespace providing different geometric functions concerning angles.
VectorT< float, 4 > Vec4f
void baseColor(const Vec4f &_c)
set the base color (Sets the baseColor which is the same as the emission(const Vec4f& _c) ) ...
int viewport_height() const
get viewport height
Class to define the vertex input layout.
ShaderGenDesc shaderDesc
Drawmode and other shader params.
size_t pick_current_index() const
Returns the current color picking index (can be used for caching)
QString vertexColorsInterpolator
interpolation qualifier for input vertex colors: "flat", "smooth", "noperspective" ...
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
const Vec4f & diffuse_color() const
get diffuse color
bool isLinked()
Returns if the program object has been succesfully linked.
void setupLineRendering(float _lineWidth, const Vec2f &_screenSize)
Setup rendering of thick lines.
void setupVertexDeclaration(VertexDeclaration *_dst, int _colorSource) const
Create the vertex declaration.
bool colored() const
Are colors used?
bool ACGDLLEXPORT openGLVersionTest(const int _major, const int _minor)
PickTarget
What target to use for picking.
unsigned int getVertexStride(unsigned int i=0) const
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
static ShaderCache * getInstance()
Return instance of the ShaderCache singleton.
void setupPointRendering(float _pointSize, const Vec2f &_screenSize)
Setup rendering of circle points.
Point & point(unsigned int _i)
Get a point of the polyline.
void set_point_size(float _f)
set point size
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
GLuint indexBuffer
Use vertex array object.
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
GLSL::Program * getProgram(const ShaderGenDesc *_desc, const std::vector< unsigned int > &_mods)
Query a dynamically generated program from cache.
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
const Vec4f & ambient_color() const
get ambient color
int viewport_width() const
get viewport width
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
void disable()
Resets to standard rendering pipeline.
DrawModeProperties stores a set of properties that defines, how to render an object.
void set_color(const Vec4f &_col)
set color
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
int priority
Priority to allow sorting of objects.
size_t n_vertices() const
Get number of vertices.
void set_line_width(float _f)
set line width
void pick_set_name(size_t _idx)
sets the current name/color (like glLoadName(_idx))
const GLMatrixd & modelview() const
get modelview matrix
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
bool is_closed() const
Check if the polyline is marked as closed.
size_t n_edges() const
Get number of edges.
void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties *_props)
Fills out ShaderGenDesc parameters based on Drawmode properties.
PolyLineCollectionNodeT(PolyLineCollection &_pl, BaseNode *_parent=0, std::string _name="<PolyLineCollectionNode>")
Constructor.
float line_width() const
get line width
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
const GLMatrixd & projection() const
get projection matrix
Interface class between scenegraph and renderer.
size_t getNumLayers() const
returns the layer count
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
const Vec4f & ambient_color() const
get ambient color