59 #define ACG_POLYLINECOLLECTIONNODET_C
65 #include "PolyLineCollectionNodeT.hh"
66 #include <ACG/GL/gl.hh>
67 #include <ACG/Utils/VSToolsT.hh>
69 #include <OpenMesh/Core/Utils/vector_cast.hh>
85 template <
class PolyLineCollection>
88 polyline_collection_(_pl),
92 total_vertex_count_(0)
101 template <
class PolyLineCollection>
110 for (
unsigned int i=0; i< polyline->
n_vertices(); ++i)
112 _bbMin.minimize(polyline->
point(i));
113 _bbMax.maximize(polyline->
point(i));
123 template <
class PolyLineCollection>
135 template <
class PolyLineCollection>
141 if ( polyline_collection_.n_polylines() == 0 )
153 vertexDecl_.activateFixedFunction();
167 glDrawArrays(GL_POINTS, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
182 glDrawArrays(GL_POINTS, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
200 glDrawArrays(GL_LINE_STRIP, offsets_[it.idx()].first, offsets_[it.idx()].second);
203 glDrawArrays(GL_LINE_STRIP, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
217 glDrawArrays(GL_LINE_STRIP, offsets_[it.idx()].first, offsets_[it.idx()].second);
219 glDrawArrays(GL_LINE_STRIP, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
227 std::vector<int> selected_indices;
233 int offset = offsets_[it.idx()].first;
234 for(
size_t i = 0; i < polyline->
n_vertices(); ++i){
238 if(polyline->edge_selected(i)){
239 selected_indices.push_back(offset + i);
240 selected_indices.push_back(offset + i + 1);
246 if(selected_indices.size() > 0){
247 glDrawElements(GL_LINES, selected_indices.size(), GL_UNSIGNED_INT, selected_indices.data());
254 vertexDecl_.deactivateFixedFunction();
261 template <
class PolyLineCollection>
267 if ( polyline_collection_.n_polylines() == 0 )
271 vertexDecl_.activateFixedFunction();;
275 glDepthRange(0.0, 0.999999);
279 glPointSize(point_size_old+3.0f);
288 glDrawArrays(GL_POINTS, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
292 glPointSize(point_size_old);
295 glLineWidth(line_width_old+3.0f);
306 glDrawArrays(GL_LINE_STRIP, offsets_[it.idx()].first, offsets_[it.idx()].second);
309 glDrawArrays(GL_LINE_STRIP, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
314 glLineWidth(line_width_old);
315 glDepthRange(0.0, 1.0);
317 vertexDecl_.deactivateFixedFunction();
323 template <
class PolyLineCollection>
328 bool lines_did_change =
false;
330 if( offsets_.size() != polyline_collection_.n_polylines() ){
331 offsets_.resize(polyline_collection_.n_polylines());
332 lines_did_change =
true;
336 total_vertex_count_ = 0;
338 std::pair<size_t, size_t> current_offset;
339 current_offset.first = offset;
341 current_offset.second = it->n_vertices() + 1;
343 current_offset.second = 0;
346 if(current_offset != offsets_[it.idx()]){
347 lines_did_change =
true;
350 offsets_[it.idx()] = current_offset;
351 total_vertex_count_ += current_offset.second;
353 offset += current_offset.second;
356 if(lines_did_change){
369 unsigned int bufferSize = vertexDecl_.getVertexStride() * offset;
372 char* vboData_ =
new char[bufferSize];
378 size_t offset = offsets_[it.idx()].first;
379 for (
unsigned int i = 0 ; i < polyline->
n_vertices(); ++i) {
380 writeVertex(polyline, i, vboData_ + (offset + i) * vertexDecl_.getVertexStride());
384 writeVertex(polyline, 0, vboData_ + (offset + polyline->
n_vertices()) * vertexDecl_.getVertexStride());
404 template <
class PolyLineCollection>
416 template <
class PolyLineCollection>
422 if ( polyline_collection_.n_polylines() == 0 )
428 _state.
enable(GL_COLOR_MATERIAL);
429 _state.
enable(GL_LIGHTING);
432 ro.setMaterial(_mat);
448 ro.debugName =
"PolyLineCollection";
472 ro.setMaterial(&localMaterial);
475 if(props->primitive() == ACG::SceneGraph::DrawModes::PRIMITIVE_POINT){
477 ro.debugName =
"polyline.Points.selected";
479 ro.setMaterial(&localMaterial);
485 ro.debugName =
"polylinecollection.Points";
487 ro.setMaterial(&localMaterial);
491 if(*it && (*it)->n_vertices() > 0){
492 ro.glDrawArrays(GL_POINTS, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
498 applyRenderObjectSettings(props->primitive(), &ro);
504 }
else if(props->primitive() == ACG::SceneGraph::DrawModes::PRIMITIVE_WIREFRAME){
506 ro.debugName =
"polyline.Wireframe.selected";
508 ro.setMaterial(&localMaterial);
513 ro.debugName =
"polylinecollection.Wireframe";
515 ro.setMaterial(&localMaterial);
521 if(*it && (*it)->n_vertices() > 0){
522 if ( (*it)->is_closed() ){
523 ro.glDrawArrays(GL_LINE_STRIP, offsets_[it.idx()].first, offsets_[it.idx()].second);
525 ro.glDrawArrays(GL_LINE_STRIP, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
534 applyRenderObjectSettings(props->primitive(), &ro);
void getRenderObjects(ACG::IRenderer *_renderer, ACG::GLState &_state, const ACG::SceneGraph::DrawModes::DrawMode &_drawMode, const ACG::SceneGraph::Material *_mat)
Add the objects to the given renderer.
void pick(GLState &_state, PickTarget _target)
picking
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
int viewport_height() const
get viewport height
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
const Vec4f & diffuse_color() const
get diffuse color
void setupLineRendering(float _lineWidth, const Vec2f &_screenSize)
Setup rendering of thick lines.
void draw(GLState &, const DrawModes::DrawMode &_drawMode)
draw lines and normals
static void bufferDataARB(GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage)
const Vec4f & diffuse_color() const
get diffuse color
Interface class between scenegraph and renderer.
static void genBuffersARB(GLsizei n, GLuint *buffers)
picks edges (may not be implemented for all nodes)
DrawMode WIREFRAME
draw wireframe
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
const Vec4f & ambient_color() const
get ambient color
Namespace providing different geometric functions concerning angles.
static void enable(GLenum _cap)
replaces glEnable, but supports locking
const Vec4f & ambient_color() const
get ambient color
static void disable(GLenum _cap)
replaces glDisable, but supports locking
DrawMode POINTS
draw unlighted points using the default base color
pick any of the prior targets (should be implemented for all nodes)
void setupShaderGenFromDrawmode(const SceneGraph::DrawModes::DrawModeProperties *_props)
Fills out ShaderGenDesc parameters based on Drawmode properties.
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
void writeVertex(typename PolyLineCollection::PolyLine *_polyline, unsigned int _vertex, void *_dst)
Write vertex data for rendering to a buffer.
void updateVBO()
Trigger an update of the vbo.
float line_width() const
get line width
int priority
Priority to allow sorting of objects.
float point_size() const
get point size
Point & point(unsigned int _i)
Get a point of the polyline.
int viewport_width() const
get viewport width
void vector_cast(const src_t &_src, dst_t &_dst, GenProg::Int2Type< n >)
Cast vector type to another vector type by copying the vector elements.
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
PolyLineCollectionNodeT(PolyLineCollection &_pl, BaseNode *_parent=0, std::string _name="<PolyLineCollectionNode>")
Constructor.
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
bool is_closed() const
Check if the polyline is marked as closed.
void pointSize(float _sz)
set point size (default: 1.0)
void setupPointRendering(float _pointSize, const Vec2f &_screenSize)
Setup rendering of circle points.
DrawModes::DrawMode availableDrawModes() const
return available draw modes
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
void set_point_size(float _f)
set point size
VectorT< float, 4 > Vec4f
void set_color(const Vec4f &_col)
set color
size_t n_vertices() const
Get number of vertices.
float line_width() const
get line width
PickTarget
What target to use for picking.
void pick_set_name(size_t _idx)
sets the current name/color (like glLoadName(_idx))
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
size_t getNumLayers() const
returns the layer count
ShaderGenDesc shaderDesc
Drawmode and other shader params.
DrawModeProperties stores a set of properties that defines, how to render an object.
void set_line_width(float _f)
set line width
void baseColor(const Vec4f &_c)
set the base color
picks verices (may not be implemented for all nodes)