Developer Documentation
PolyLineCollectionNodeT_impl.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 
43 
44 
45 
46 
47 //=============================================================================
48 //
49 // CLASS PolyLineNodeT - IMPLEMENTATION
50 //
51 //=============================================================================
52 
53 #define ACG_POLYLINECOLLECTIONNODET_C
54 
55 //== INCLUDES =================================================================
56 
57 
58 
59 #include "PolyLineCollectionNodeT.hh"
60 #include <ACG/GL/gl.hh>
61 #include <ACG/Utils/VSToolsT.hh>
62 #include <vector>
63 #include <OpenMesh/Core/Utils/vector_cast.hh>
64 
65 #ifdef _WIN32
66 #include <cstdint>
67 #else
68 #include <stdint.h>
69 #endif
70 
71 //== NAMESPACES ===============================================================
72 
73 namespace ACG {
74 namespace SceneGraph {
75 
76 //== IMPLEMENTATION ==========================================================
77 
79 template <class PolyLineCollection>
81  BaseNode(_parent, _name),
82  polyline_collection_(_pl),
83  updateVBO_(true),
84  sphere_(0),
85  total_vertex_count_(0),
86  total_segment_count_(0)
87 
88 {
89  // Initial default draw mode
90  drawMode(DrawModes::WIREFRAME | DrawModes::POINTS );
91 }
92 
93 //----------------------------------------------------------------------------
94 
95 template <class PolyLineCollection>
97 {
98  for (size_t i = 0; i < polylineNodes_.size(); ++i)
99  delete polylineNodes_[i];
100 }
101 
102 //----------------------------------------------------------------------------
103 
104 template <class PolyLineCollection>
105 void
107 boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
108 {
109  for(typename PolyLineCollection::iterator it = polyline_collection_.iter(); it; ++it){
110  typename PolyLineCollection::PolyLine* polyline = *it;
111 
112  if(polyline){
113  for (unsigned int i=0; i< polyline->n_vertices(); ++i)
114  {
115  _bbMin.minimize(polyline->point(i));
116  _bbMax.maximize(polyline->point(i));
117  }
118  }
119  }
120 }
121 
122 
123 //----------------------------------------------------------------------------
124 
125 
126 template <class PolyLineCollection>
130 {
131  return (DrawModes::WIREFRAME | DrawModes::POINTS | DrawModes::POINTS_COLORED | DrawModes::EDGES_COLORED );
132 }
133 
134 
135 //----------------------------------------------------------------------------
136 
137 
138 template <class PolyLineCollection>
139 void
141 draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
142 {
143  // Block if we do not have any polylines
144  if ( polyline_collection_.n_polylines() == 0 )
145  return;
146 
147  // Update the vbo only if required.
148  if ( updateVBO_ )
149  updateVBO();
150 
151  ACG::GLState::disable(GL_LIGHTING);
152  ACG::GLState::disable(GL_TEXTURE_2D);
153 
154  // Bind the vertex array
155  vbo_.bind();
156  vertexDecl_.activateFixedFunction();
157 
158  ACG::Vec4f color = _state.ambient_color() + _state.diffuse_color();
159 
160  bool vertexColors = _drawMode & DrawModes::POINTS_COLORED;
161 
162  // draw points
163  if (_drawMode & DrawModes::POINTS || vertexColors)
164  {
165  _state.set_color( color );
166 
167  if (vertexColors) {
168  vertexDecl_.deactivateFixedFunction();
169  vertexDeclVColor_.activateFixedFunction();
170  }
171 
172  // Draw all vertices (don't care about selection)
173  glDrawArrays(GL_POINTS, 0, total_vertex_count_);
174 
175  if (vertexColors) {
176  vertexDeclVColor_.deactivateFixedFunction();
177  vertexDecl_.activateFixedFunction();
178  }
179 
180 
181  float point_size_old = _state.point_size();
182  _state.set_point_size(point_size_old+4.0f);
183 
184  _state.set_color( Vec4f(1.0f,0.0f,0.0f,1.0f) );
185 
186  // Draw selected polylines
187  for(typename PolyLineCollection::index_iterator it = polyline_collection_.selected_iter(); it; ++it){
188  typename PolyLineCollection::PolyLine* polyline = *it;
189 
190  if(polyline && polyline->n_vertices() > 0){
191  glDrawArrays(GL_POINTS, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
192  }
193  }
194 
195  _state.set_point_size(point_size_old);
196 
197  }
198 
199 
200  bool edgeColors = _drawMode & DrawModes::EDGES_COLORED;
201 
202  // draw line segments
203  if (_drawMode & DrawModes::WIREFRAME || edgeColors) {
204 
205  _state.set_color( color );
206 
207  if (edgeColors) {
208  vertexDecl_.deactivateFixedFunction();
209  vertexDeclEColor_.activateFixedFunction();
210  }
211 
212  ibo_.bind();
213  glDrawElements(GL_LINES, total_segment_count_ * 2, GL_UNSIGNED_INT, 0);
214  ibo_.unbind();
215 
216  if (edgeColors) {
217  vertexDeclEColor_.deactivateFixedFunction();
218  vertexDecl_.activateFixedFunction();
219  }
220 
221  float line_width_old = _state.line_width();
222  _state.set_color(Vec4f(1, 0, 0, 1));
223  _state.set_line_width(2 * line_width_old);
224 
225  for(typename PolyLineCollection::index_iterator it = polyline_collection_.selected_iter(); it; ++it){
226  typename PolyLineCollection::PolyLine* polyline = *it;
227 
228  if(polyline && polyline->n_vertices() > 0){
229  if ( polyline->is_closed() ){
230  glDrawArrays(GL_LINE_STRIP, offsets_[it.idx()].first, offsets_[it.idx()].second);
231  }else{
232  glDrawArrays(GL_LINE_STRIP, offsets_[it.idx()].first, offsets_[it.idx()].second-1);
233  }
234 
235  //offset += polyline->n_vertices() + 1;
236  }
237  }
238 
239  // Draw selected edges
240  std::vector<int> selected_indices;
241  for(typename PolyLineCollection::index_iterator it = polyline_collection_.visible_iter(); it; ++it){
242  typename PolyLineCollection::PolyLine* polyline = *it;
243 
244 
245  if(polyline){
246  int offset = offsets_[it.idx()].first;
247  for(size_t i = 0; i < polyline->n_vertices(); ++i){
248  if(!polyline->is_closed() && i == polyline->n_vertices() - 1){
249  continue;
250  }
251  if(polyline->edge_selected(i)){
252  selected_indices.push_back(offset + i);
253  selected_indices.push_back(offset + i + 1);
254  }
255  }
256  }
257  }
258 
259  if(selected_indices.size() > 0){
260  glDrawElements(GL_LINES, selected_indices.size(), GL_UNSIGNED_INT, selected_indices.data());
261  }
262 
263  _state.set_line_width(line_width_old);
264 
265  }
266 
267  vertexDecl_.deactivateFixedFunction();
268  ACG::GLState::bindBuffer(GL_ARRAY_BUFFER_ARB, 0);
269 }
270 
271 //----------------------------------------------------------------------------
272 
273 
274 template <class PolyLineCollection>
275 void
277 pick(GLState& _state, PickTarget _target)
278 {
279  size_t numPolyLines = polyline_collection_.n_polylines();
280 
281  if ( numPolyLines == 0 )
282  return;
283 
284 
285  switch (_target)
286  {
287  case PICK_VERTEX:
288  {
289  size_t numPickIDs = 0;
290 
291  for (size_t i = 0; i < numPolyLines; ++i)
292  {
293  typename PolyLineCollection::PolyLine* line = polyline_collection_.polyline(i);
294 
295  if (line)
296  numPickIDs += line->n_vertices();
297  }
298 
299  _state.pick_set_maximum (numPickIDs);
300  pick_vertices( _state);
301  break;
302  }
303 
304  case PICK_EDGE:
305  {
306  size_t numPickIDs = 0;
307 
308  for (size_t i = 0; i < numPolyLines; ++i)
309  {
310  typename PolyLineCollection::PolyLine* line = polyline_collection_.polyline(i);
311 
312  if (line)
313  numPickIDs += line->n_edges();
314  }
315 
316  _state.pick_set_maximum (numPickIDs);
317  pick_edges(_state, 0);
318  break;
319  }
320 
321  case PICK_ANYTHING:
322  {
323  size_t numPickVertices = 0;
324  size_t numPickIDs = 0;
325 
326  for (size_t i = 0; i < numPolyLines; ++i)
327  {
328  typename PolyLineCollection::PolyLine* line = polyline_collection_.polyline(i);
329 
330  if (line)
331  {
332  numPickIDs += line->n_vertices();
333  numPickIDs += line->n_edges();
334 
335  numPickVertices += line->n_vertices();
336  }
337  }
338 
339  _state.pick_set_maximum (numPickIDs);
340 
341  pick_vertices( _state);
342  pick_edges( _state, static_cast<unsigned int>(numPickVertices));
343  break;
344  }
345 
346  default:
347  break;
348  }
349 }
350 
351 //----------------------------------------------------------------------------
352 
353 template <class PolyLineCollection>
354 void
356 pick_vertices(GLState &_state)
357 {
358  size_t numPolyLines = polyline_collection_.n_polylines();
359 
360  // draw vertex pick IDs
361 
362  float point_size_old = _state.point_size();
363  glPointSize(point_size_old+3.0f);
364 
365  static ShaderGenDesc desc;
366  desc.vertexTemplateFile = "Picking/pick_vertices_vs.glsl";
367  desc.fragmentTemplateFile = "Picking/pick_vertices_fs.glsl";
368  GLSL::Program* pickVertexShader = ACG::ShaderCache::getInstance()->getProgram(&desc, nullptr);
369 
370  if (pickVertexShader && pickVertexShader->isLinked())
371  {
372  // shader needs picking ID offset and transform matrix
373  int pickVertexOffset = int(_state.pick_current_index());
374  GLMatrixf mWVP = _state.projection() * _state.modelview();
375 
376  pickVertexShader->use();
377 
378  pickVertexShader->setUniform("mWVP", mWVP);
379 
380  vbo_.bind();
381 
382  vertexDecl_.activateShaderPipeline(pickVertexShader);
383 
384 
385  for (size_t i = 0; i < numPolyLines; ++i)
386  {
387  typename PolyLineCollection::PolyLine* line = polyline_collection_.polyline(i);
388 
389  if (line && line->n_vertices() > 0)
390  {
391  pickVertexShader->setUniform("pickVertexOffset", pickVertexOffset);
392 
393  glDrawArrays(GL_POINTS, offsets_[i].first, offsets_[i].second-1);
394 
395  pickVertexOffset += int(offsets_[i].second - 1);
396  }
397  }
398 
399  vertexDecl_.deactivateShaderPipeline(pickVertexShader);
400 
401  vbo_.unbind();
402 
403  pickVertexShader->disable();
404  }
405  else
406  {
407  // fallback implementation: draw picking ids without shader
408  glBegin(GL_POINTS);
409 
410  size_t curPickID = 0;
411 
412  for (size_t i = 0; i < numPolyLines; ++i)
413  {
414  typename PolyLineCollection::PolyLine* line = polyline_collection_.polyline(i);
415 
416  if (line && line->n_vertices() > 0)
417  {
418  for (size_t v = 0; v < line->n_vertices(); ++v)
419  {
420  _state.pick_set_name(curPickID++);
421 
422  glVertex3d(line->point(v)[0], line->point(v)[1], line->point(v)[2]);
423  }
424  }
425  }
426 
427  glEnd();
428  }
429 
430  glPointSize(point_size_old);
431 }
432 
433 //----------------------------------------------------------------------------
434 
435 template <class PolyLineCollection>
436 void
438 pick_edges(GLState &_state, unsigned int _offset)
439 {
440  size_t numPolyLines = polyline_collection_.n_polylines();
441 
442  // draw edge picking IDs
443  float line_width_old = _state.line_width();
444  glLineWidth(line_width_old+3.0f);
445 
446  static ShaderGenDesc desc;
447  if(ACG::openGLVersionTest(3,2))
448  {
449  desc.vertexTemplateFile = "Picking/vertex.glsl";
450  desc.fragmentTemplateFile = "Picking/pick_vertices_fs2.glsl";
451  }
452  else
453  {
454  desc.vertexTemplateFile = "Picking/pick_vertices_vs.glsl";
455  desc.fragmentTemplateFile = "Picking/pick_vertices_fs.glsl";
456  }
457  GLSL::Program* pickEdgeShader = ACG::ShaderCache::getInstance()->getProgram(&desc, nullptr);
458 
459  if (pickEdgeShader && pickEdgeShader->isLinked())
460  {
461  // shader needs picking ID offset and transform matrix
462  int pickVertexOffset = int(_state.pick_current_index() + _offset);
463  GLMatrixf mWVP = _state.projection() * _state.modelview();
464 
465  pickEdgeShader->use();
466 
467  pickEdgeShader->setUniform("mWVP", mWVP);
468 
469  vbo_.bind();
470 
471  vertexDecl_.activateShaderPipeline(pickEdgeShader);
472 
473  for (size_t i = 0; i < numPolyLines; ++i)
474  {
475  typename PolyLineCollection::PolyLine* line = polyline_collection_.polyline(i);
476 
477  if (line && line->n_vertices() > 0)
478  {
479  pickEdgeShader->setUniform("pickVertexOffset", pickVertexOffset);
480 
481  size_t numIndices = line->is_closed() ? offsets_[i].second : offsets_[i].second - 1;
482  glDrawArrays(GL_LINE_STRIP, offsets_[i].first, numIndices);
483 
484  pickVertexOffset += int(line->n_edges());
485  }
486  }
487 
488  vertexDecl_.deactivateShaderPipeline(pickEdgeShader);
489 
490  vbo_.unbind();
491 
492  pickEdgeShader->disable();
493  }
494  else
495  {
496  // fallback implementation: draw picking ids without shader
497  glBegin(GL_LINES);
498 
499  size_t curPickID = _offset;
500 
501  for (size_t i = 0; i < numPolyLines; ++i)
502  {
503  typename PolyLineCollection::PolyLine* line = polyline_collection_.polyline(i);
504 
505  if (line)
506  {
507  size_t nv = line->n_vertices();
508 
509  for (size_t v = 0; v < line->n_edges(); ++v)
510  {
511  _state.pick_set_name(curPickID++);
512 
513  glVertex3d(line->point(v)[0], line->point(v)[1], line->point(v)[2]);
514 
515  size_t e = (v+1)%nv;
516  glVertex3d(line->point(e)[0], line->point(e)[1], line->point(e)[2]);
517  }
518  }
519  }
520 
521  glEnd();
522  }
523 
524  glLineWidth(line_width_old);
525 }
526 
527 //----------------------------------------------------------------------------
528 
529 template <class PolyLineCollection>
530 void
533 
534  bool lines_did_change = false;
535 
536  if( offsets_.size() != polyline_collection_.n_polylines() ){
537  offsets_.resize(polyline_collection_.n_polylines());
538  lines_did_change = true;
539  }
540 
541  int offset = 0;
542  total_vertex_count_ = 0;
543  total_segment_count_ = 0;
544  for(typename PolyLineCollection::iterator it = polyline_collection_.iter(); it; ++it){
545  std::pair<size_t, size_t> current_offset;
546  current_offset.first = offset;
547  if(*it){
548  current_offset.second = it->n_vertices() + 1;
549  }else{
550  current_offset.second = 0;
551  }
552 
553  if(current_offset != offsets_[it.idx()]){
554  lines_did_change = true;
555  }
556 
557  offsets_[it.idx()] = current_offset;
558  total_vertex_count_ += current_offset.second;
559  total_segment_count_ += it->n_edges();
560 
561  offset += current_offset.second;
562  }
563 
564  if(lines_did_change){
565 
566 
567  // update internal line node
568  // these are used exclusively used to fill the vertex buffer
569 
570 
571  size_t prevLineCount = polylineNodes_.size();
572  size_t curLineCount = polyline_collection_.n_polylines();
573 
574 
575  // free memory for removed lines
576  if (curLineCount < prevLineCount)
577  {
578  for (size_t i = curLineCount; i < prevLineCount; ++i)
579  delete polylineNodes_[i];
580  }
581 
582  polylineNodes_.resize(curLineCount);
583 
584 
585  for(size_t i = 0; i < curLineCount; ++i) {
586  typename PolyLineCollection::PolyLine* polyline = polyline_collection_.polyline(i);
587  polylineNodes_[i] = new PolyLineNodeT<typename PolyLineCollection::PolyLine>(*polyline);
588  }
589 
590 
591 
592  // Update the vertex declaration based on the input data:
593  vertexDecl_.clear();
594  vertexDeclVColor_.clear();
595  vertexDeclEColor_.clear();
596 
597 
598  if (curLineCount > 0) {
599  polylineNodes_[0]->setupVertexDeclaration(&vertexDecl_, 0);
600  polylineNodes_[0]->setupVertexDeclaration(&vertexDeclVColor_, 1);
601  polylineNodes_[0]->setupVertexDeclaration(&vertexDeclEColor_, 2);
602 
603 
604  // make sure that all polylines have the same vertex format
605  bool equalVertexFormat = true;
606 
607  for (size_t i = 1; i < curLineCount; ++i) {
608 
609  VertexDeclaration decl[3];
610 
611  for (int k = 0; k < 3; ++k)
612  polylineNodes_[i]->setupVertexDeclaration(&decl[k], k);
613 
614  if (decl[0] != vertexDecl_ ||
615  decl[1] != vertexDeclVColor_ ||
616  decl[2] != vertexDeclEColor_)
617  equalVertexFormat = false;
618  }
619 
620 
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;
623  else {
624 
625  // size in bytes of vbo, create additional vertex for closed loop indexing
626  size_t stride = vertexDecl_.getVertexStride();
627  size_t bufferSize = stride * offset;
628 
629  if (bufferSize > 0) {
630  std::vector<char> vboData(bufferSize);
631  std::vector<unsigned int> iboData(total_segment_count_ * 2);
632 
633  size_t offsetSegment = 0;
634 
635  for(size_t i = 0; i < curLineCount; ++i) {
636  typename PolyLineCollection::PolyLine* polyline = polyline_collection_.polyline(i);
637 
638 
639  if (polyline && polylineNodes_[i] && polyline->n_vertices() > 0) {
640 
641  // fill vertex buffer data
642  size_t offset = offsets_[i].first;
643 
644  polylineNodes_[i]->fillVertexBuffer(&vboData[(offset) * stride], bufferSize, true);
645 
646  // fill index buffer data
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();
650  }
651  offsetSegment += polyline->n_edges();
652 
653  }
654 
655  }
656 
657  // Move data to the buffer in gpu memory
658  vbo_.upload(vboData.size() * sizeof(vboData[0]), &vboData[0], GL_STATIC_DRAW);
659  vbo_.unbind();
660 
661  ibo_.upload(iboData.size() * sizeof(iboData[0]), &iboData[0], GL_STATIC_DRAW);
662  ibo_.unbind();
663  }
664 
665  }
666 
667  }
668  }
669 
670 
671 
672  // Update done.
673  updateVBO_ = false;
674 }
675 
676 //----------------------------------------------------------------------------
677 
678 template <class PolyLineCollection>
679 void
682 
683  // Block if we do not have any vertices
684  if ( polyline_collection_.n_polylines() == 0 )
685  return;
686 
687  // init base render object
689 
690  _state.enable(GL_COLOR_MATERIAL);
691  _state.enable(GL_LIGHTING);
692  ro.initFromState(&_state);
693 
694  ro.setMaterial(_mat);
695 
696  // draw after scene-meshes
697  ro.priority = 1;
698 
699  // Update the vbo only if required.
700  if ( updateVBO_ )
701  updateVBO();
702 
703  // Set to the right vbo
704  ro.vertexBuffer = vbo_.id();
705 
706  // Set style
707  ro.debugName = "PolyLineCollection";
708  ro.blending = false;
709  ro.depthTest = true;
710 
711  // Default color
712  ACG::Vec4f defaultColor = _state.ambient_color() + _state.diffuse_color();
713  ACG::Vec4f selectionColor = ACG::Vec4f(1.0,0.0,0.0,1.0);
714 
715  // Viewport size
716  ACG::Vec2f screenSize(float(_state.viewport_width()), float(_state.viewport_height()));
717 
718  for (size_t i = 0; i < _drawMode.getNumLayers(); ++i) {
719  ACG::SceneGraph::Material localMaterial = *_mat;
720 
721  const ACG::SceneGraph::DrawModes::DrawModeProperties* props = _drawMode.getLayer(i);
722 
723  ro.setupShaderGenFromDrawmode(props);
724  ro.shaderDesc.shadeMode = SG_SHADE_UNLIT;
725 
726 
727  if (props->colored())
728  {
729  if (props->colorSource() == ACG::SceneGraph::DrawModes::COLOR_PER_EDGE)
730  {
731  ro.vertexDecl = &vertexDeclEColor_;
733  }
734  else
735  {
736  ro.vertexDecl = &vertexDeclVColor_;
738  }
739 
740  ro.shaderDesc.vertexColors = true;
741  }
742  else
743  {
744  ro.vertexDecl = &vertexDecl_;
745  ro.shaderDesc.vertexColors = false;
746  }
747 
748  //---------------------------------------------------
749  // No lighting!
750  // Therefore we need some emissive color
751  //---------------------------------------------------
752  localMaterial.baseColor(defaultColor);
753  ro.setMaterial(&localMaterial);
754 
755 
756  if(props->primitive() == ACG::SceneGraph::DrawModes::PRIMITIVE_POINT){
757  // Render all vertices which are selected via an index buffer
758  ro.debugName = "polyline.Points.selected";
759  localMaterial.baseColor(selectionColor);
760  ro.setMaterial(&localMaterial);
761 
762  // Point Size geometry shader
763  ro.setupPointRendering(_mat->pointSize(), screenSize);
764 
765  // Render all vertices (ignore selection here!)
766  ro.debugName = "polylinecollection.Points";
767  localMaterial.baseColor(defaultColor);
768  ro.setMaterial(&localMaterial);
769 
770 
771  // Point Size geometry shader
772  ro.setupPointRendering(_mat->pointSize(), screenSize);
773 
774  // apply user settings
775  applyRenderObjectSettings(props->primitive(), &ro);
776 
777 
778  ro.glDrawArrays(GL_POINTS, 0, total_vertex_count_);
779  _renderer->addRenderObject(&ro);
780 
781  }else if(props->primitive() == ACG::SceneGraph::DrawModes::PRIMITIVE_WIREFRAME ||
782  props->primitive() == ACG::SceneGraph::DrawModes::PRIMITIVE_EDGE){
783  // Render all edges which are selected via an index buffer
784  ro.debugName = "polyline.Wireframe.selected";
785  localMaterial.baseColor(selectionColor);
786  ro.setMaterial(&localMaterial);
787 
788  // Line Width geometry shader
789  ro.setupLineRendering(_state.line_width(), screenSize);
790 
791  ro.debugName = "polylinecollection.Wireframe";
792  localMaterial.baseColor(defaultColor);
793  ro.setMaterial(&localMaterial);
794  // The first point is mapped to an additional last point in buffer, so we can
795  // just Render one point more to get a closed line
796 
797 
798  // Line Width geometry shader
799  ro.setupLineRendering(_state.line_width(), screenSize);
800 
801  // apply user settings
802  applyRenderObjectSettings(props->primitive(), &ro);
803 
804 
805  ro.indexBuffer = ibo_.id();
806  ro.glDrawElements(GL_LINES, total_segment_count_ * 2, GL_UNSIGNED_INT, 0);
807 
808  _renderer->addRenderObject(&ro);
809  ro.indexBuffer = 0;
810 
811  }
812  }
813 
814 }
815 
816 //=============================================================================
817 } // namespace SceneGraph
818 } // namespace ACG
819 //=============================================================================
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
Definition: GLState.cc:1507
void initFromState(GLState *_glState)
Initializes a RenderObject instance.
Definition: RenderObject.cc:61
void pointSize(float _sz)
set point size (default: 1.0)
picks edges (may not be implemented for all nodes)
Definition: PickTarget.hh:80
float point_size() const
get point size
Definition: GLState.hh:995
void use()
Enables the program object for using.
Definition: GLSLShader.cc:345
int viewport_width() const
get viewport width
Definition: GLState.hh:847
Namespace providing different geometric functions concerning angles.
VectorT< float, 4 > Vec4f
Definition: VectorT.hh:138
void baseColor(const Vec4f &_c)
set the base color (Sets the baseColor which is the same as the emission(const Vec4f& _c) ) ...
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)
Definition: GLState.cc:1131
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
Definition: Vector11T.hh:587
GLuint vertexBuffer
VBO, IBO ids, ignored if VAO is provided.
const Vec4f & diffuse_color() const
get diffuse color
Definition: GLState.hh:961
bool isLinked()
Returns if the program object has been succesfully linked.
Definition: GLSLShader.cc:370
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?
Definition: DrawModes.hh:222
bool ACGDLLEXPORT openGLVersionTest(const int _major, const int _minor)
Definition: gl.hh:275
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
unsigned int getVertexStride(unsigned int i=0) const
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
Definition: GLState.cc:1527
GLSL program class.
Definition: GLSLShader.hh:211
static ShaderCache * getInstance()
Return instance of the ShaderCache singleton.
Definition: ShaderCache.cc:84
void setupPointRendering(float _pointSize, const Vec2f &_screenSize)
Setup rendering of circle points.
pick any of the prior targets (should be implemented for all nodes)
Definition: PickTarget.hh:84
Point & point(unsigned int _i)
Get a point of the polyline.
Definition: PolyLineT.hh:142
void set_point_size(float _f)
set point size
Definition: GLState.cc:776
bool pick_set_maximum(size_t _idx)
Set the maximal number of primitives/components of your object.
Definition: GLState.cc:1051
picks verices (may not be implemented for all nodes)
Definition: PickTarget.hh:82
GLuint indexBuffer
Use vertex array object.
int viewport_height() const
get viewport height
Definition: GLState.hh:849
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition: Vector11T.hh:559
GLSL::Program * getProgram(const ShaderGenDesc *_desc, const std::vector< unsigned int > &_mods)
Query a dynamically generated program from cache.
Definition: ShaderCache.cc:102
void setUniform(const char *_name, GLint _value)
Set int uniform to specified value.
Definition: GLSLShader.cc:385
const VertexDeclaration * vertexDecl
Defines the vertex buffer layout, ignored if VAO is provided.
void disable()
Resets to standard rendering pipeline.
Definition: GLSLShader.cc:355
DrawModeProperties stores a set of properties that defines, how to render an object.
Definition: DrawModes.hh:177
void set_color(const Vec4f &_col)
set color
Definition: GLState.cc:691
virtual void addRenderObject(RenderObject *_renderObject)
Callback for the scenegraph nodes, which send new render objects via this function.
Definition: IRenderer.cc:104
int priority
Priority to allow sorting of objects.
size_t n_vertices() const
Get number of vertices.
Definition: PolyLineT.hh:116
void set_line_width(float _f)
set line width
Definition: GLState.cc:791
void pick_set_name(size_t _idx)
sets the current name/color (like glLoadName(_idx))
Definition: GLState.cc:1061
const GLMatrixd & modelview() const
get modelview matrix
Definition: GLState.hh:816
bool is_closed() const
Check if the polyline is marked as closed.
Definition: PolyLineT.hh:107
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
Definition: GLState.hh:1000
const DrawModeProperties * getLayer(unsigned int _i) const
returns the property set at layer i
Definition: DrawModes.cc:527
const GLMatrixd & projection() const
get projection matrix
Definition: GLState.hh:811
Interface class between scenegraph and renderer.
Definition: RenderObject.hh:98
size_t getNumLayers() const
returns the layer count
Definition: DrawModes.cc:523
static void bindBuffer(GLenum _target, GLuint _buffer)
replaces glBindBuffer, supports locking
Definition: GLState.cc:1820
const Vec4f & ambient_color() const
get ambient color
Definition: GLState.hh:956