59 #ifndef DOXY_IGNORE_THIS 60 #define ACG_MESHNODE_C 65 #include "MeshNodeDeprecatedT.hh" 66 #include "ShaderNode.hh" 67 #include "DrawModes.hh" 68 #include <ACG/GL/gl.hh> 69 #include <ACG/GL/GLError.hh> 70 #include <ACG/GL/ColorTranslator.hh> 73 #include <OpenMesh/Core/Utils/Property.hh> 88 MeshNodeDeprecatedT<Mesh>::
89 MeshNodeDeprecatedT(
const Mesh& _mesh,
95 face_index_buffer_(0),
98 vertexBufferInitialized_(false),
99 normalBufferInitialized_(false),
100 faceIndexBufferInitialized_(false),
103 default_halfedge_textcoord_property_(
"h:texcoords2D"),
104 indexPropertyName_(
"f:textureindex"),
105 updateFaceList_(true),
106 updateVertexList_(true),
107 updateEdgeList_(true),
108 updateAnyList_(true),
113 bbMin_(FLT_MAX, FLT_MAX, FLT_MAX),
114 bbMax_(-FLT_MAX, -FLT_MAX, -FLT_MAX)
116 faceList_ = glGenLists (1);
117 vertexList_ = glGenLists (1);
118 edgeList_ = glGenLists (1);
119 anyList_ = glGenLists (3);
127 MeshNodeDeprecatedT<Mesh>::
128 ~MeshNodeDeprecatedT()
131 glDeleteBuffersARB(1, (GLuint*) &vertex_buffer_);
134 glDeleteBuffersARB(1, (GLuint*) &normal_buffer_);
136 if (face_index_buffer_)
137 glDeleteBuffersARB(1, (GLuint*) &face_index_buffer_ );
140 glDeleteLists (faceList_, 1);
143 glDeleteLists (vertexList_, 1);
146 glDeleteLists (edgeList_, 1);
149 glDeleteLists (anyList_, 3);
158 MeshNodeDeprecatedT<Mesh>::
159 boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
161 _bbMin.minimize(bbMin_);
162 _bbMax.maximize(bbMax_);
171 MeshNodeDeprecatedT<Mesh>::
172 availableDrawModes()
const 174 DrawModes::DrawMode drawModes(DrawModes::NONE);
176 drawModes |= DrawModes::POINTS;
177 drawModes |= DrawModes::WIREFRAME;
178 drawModes |= DrawModes::HIDDENLINE;
179 drawModes |= DrawModes::SOLID_SHADER;
181 if (mesh_.has_vertex_normals())
183 drawModes |= DrawModes::POINTS_SHADED;
184 drawModes |= DrawModes::SOLID_SMOOTH_SHADED;
185 drawModes |= DrawModes::SOLID_PHONG_SHADED;
188 if (mesh_.has_vertex_colors())
190 drawModes |= DrawModes::POINTS_COLORED;
191 drawModes |= DrawModes::SOLID_POINTS_COLORED;
194 if (mesh_.has_face_normals())
195 drawModes |= DrawModes::SOLID_FLAT_SHADED;
197 if (mesh_.has_face_colors())
199 drawModes |= DrawModes::SOLID_FACES_COLORED;
201 if( mesh_.has_face_normals() )
202 drawModes |= DrawModes::SOLID_FACES_COLORED_FLAT_SHADED;
205 if (mesh_.has_vertex_texcoords1D())
207 drawModes |= DrawModes::SOLID_1DTEXTURED;
209 if (mesh_.has_vertex_normals())
210 drawModes |= DrawModes::SOLID_1DTEXTURED_SHADED;
213 if (mesh_.has_vertex_texcoords2D())
215 drawModes |= DrawModes::SOLID_TEXTURED;
217 if (mesh_.has_vertex_normals())
218 drawModes |= DrawModes::SOLID_TEXTURED_SHADED;
221 if (mesh_.has_vertex_texcoords3D())
223 drawModes |= DrawModes::SOLID_3DTEXTURED;
225 if (mesh_.has_vertex_normals())
226 drawModes |= DrawModes::SOLID_3DTEXTURED_SHADED;
229 if (mesh_.has_halfedge_texcoords2D())
231 drawModes |= DrawModes::SOLID_2DTEXTURED_FACE;
232 if (mesh_.has_face_normals())
233 drawModes |= DrawModes::SOLID_2DTEXTURED_FACE_SHADED;
245 MeshNodeDeprecatedT<Mesh>::
246 enable_arrays(
unsigned int _arrays)
251 typedef typename Point::value_type PointScalar;
253 typedef typename Normal::value_type NormalScalar;
256 ((_arrays == VERTEX_ARRAY || _arrays == (VERTEX_ARRAY | NORMAL_ARRAY)) &&
257 (vertexBufferInitialized_ && normalBufferInitialized_) ) ;
263 if (!use_vbo && vertex_buffer_)
268 if (_arrays & VERTEX_ARRAY)
270 if (!(enabled_arrays_ & VERTEX_ARRAY))
272 enabled_arrays_ |= VERTEX_ARRAY;
288 else if (enabled_arrays_ & VERTEX_ARRAY)
290 enabled_arrays_ &= ~VERTEX_ARRAY;
295 if (_arrays & NORMAL_ARRAY)
297 if (!(enabled_arrays_ & NORMAL_ARRAY))
299 enabled_arrays_ |= NORMAL_ARRAY;
315 else if (enabled_arrays_ & NORMAL_ARRAY)
317 enabled_arrays_ &= ~NORMAL_ARRAY;
322 if (_arrays & COLOR_ARRAY)
324 if (!(enabled_arrays_ & COLOR_ARRAY))
326 enabled_arrays_ |= COLOR_ARRAY;
331 else if (enabled_arrays_ & COLOR_ARRAY)
333 enabled_arrays_ &= ~COLOR_ARRAY;
338 if (_arrays & TEXTURE_COORD_1D_ARRAY)
340 if (!(enabled_arrays_ & TEXTURE_COORD_1D_ARRAY))
342 enabled_arrays_ |= TEXTURE_COORD_1D_ARRAY;
347 else if (enabled_arrays_ & TEXTURE_COORD_1D_ARRAY)
349 enabled_arrays_ &= ~TEXTURE_COORD_1D_ARRAY;
354 if (_arrays & TEXTURE_COORD_2D_ARRAY)
356 if (!(enabled_arrays_ & TEXTURE_COORD_2D_ARRAY))
358 enabled_arrays_ |= TEXTURE_COORD_2D_ARRAY;
363 else if (enabled_arrays_ & TEXTURE_COORD_2D_ARRAY)
365 enabled_arrays_ &= ~TEXTURE_COORD_2D_ARRAY;
370 if (_arrays & TEXTURE_COORD_3D_ARRAY)
372 if (!(enabled_arrays_ & TEXTURE_COORD_3D_ARRAY))
374 enabled_arrays_ |= TEXTURE_COORD_3D_ARRAY;
379 else if (enabled_arrays_ & TEXTURE_COORD_3D_ARRAY)
381 enabled_arrays_ &= ~TEXTURE_COORD_3D_ARRAY;
395 MeshNodeDeprecatedT<Mesh>::
398 updateFaceList_ =
true;
399 updateVertexList_ =
true;
400 updateEdgeList_ =
true;
401 updateAnyList_ =
true;
403 bbMin_ =
Vec3d(FLT_MAX, FLT_MAX, FLT_MAX);
404 bbMax_ =
Vec3d(-FLT_MAX, -FLT_MAX, -FLT_MAX);
405 typename Mesh::ConstVertexIter v_it(mesh_.vertices_begin()),
406 v_end(mesh_.vertices_end());
408 for (; v_it!=v_end; ++v_it)
410 bbMin_.minimize(mesh_.point(*v_it));
411 bbMax_.maximize(mesh_.point(*v_it));
414 if (GLEW_ARB_vertex_buffer_object) {
416 typedef typename Point::value_type PointScalar;
418 typedef typename Normal::value_type NormalScalar;
424 if (!vertex_buffer_) glGenBuffersARB(1, (GLuint*) &vertex_buffer_);
427 vertexBufferInitialized_ =
false;
430 if (
sizeof(PointScalar) == 4 ) {
432 glBufferDataARB(GL_ARRAY_BUFFER_ARB,
433 3 * mesh_.n_vertices() *
sizeof(PointScalar),
437 vertexBufferInitialized_ =
true;
442 typename Mesh::ConstVertexIter v_it(mesh_.vertices_begin()),
443 v_end(mesh_.vertices_end());
445 for ( ; v_it != v_end ; ++v_it )
446 vertices_.push_back(
ACG::Vec3f(mesh_.point(*v_it)) );
448 if ( !vertices_.empty() ) {
450 glBufferDataARB(GL_ARRAY_BUFFER_ARB,
451 3 * mesh_.n_vertices() *
sizeof(float),
454 vertexBufferInitialized_ =
true;
463 if (!normal_buffer_) glGenBuffersARB(1, (GLuint*) &normal_buffer_);
465 normalBufferInitialized_ =
false;
468 if (
sizeof(NormalScalar) == 4) {
470 glBufferDataARB(GL_ARRAY_BUFFER_ARB,
471 3 * mesh_.n_vertices() *
sizeof(NormalScalar),
472 mesh_.vertex_normals(),
475 normalBufferInitialized_ =
true;
479 typename Mesh::ConstVertexIter v_it(mesh_.vertices_begin()),
480 v_end(mesh_.vertices_end());
482 for ( ; v_it != v_end ; ++v_it )
483 normals_.push_back(
ACG::Vec3f(mesh_.normal(*v_it)) );
485 if ( !normals_.empty() ) {
487 glBufferDataARB(GL_ARRAY_BUFFER_ARB,
488 3 * mesh_.n_vertices() *
sizeof(float),
491 normalBufferInitialized_ =
true;
499 }
else omlog() <<
"MeshNodeDeprecatedT: VBO not supported on this machine\n";
508 MeshNodeDeprecatedT<Mesh>::
511 updateFaceList_ =
true;
512 updateVertexList_ =
true;
516 typename Mesh::ConstFaceIter f_it(mesh_.faces_sbegin()),
517 f_end(mesh_.faces_end());
523 std::vector<unsigned int>().swap(indices_);
524 indices_.reserve(mesh_.n_faces()*3);
526 for (; f_it!=f_end; ++f_it)
528 fv_it = mesh_.cfv_iter( *f_it );
529 indices_.push_back(fv_it->idx()); ++fv_it;
530 indices_.push_back(fv_it->idx()); ++fv_it;
531 indices_.push_back(fv_it->idx());
537 std::vector<unsigned int>().swap(indices_);
538 omerr() <<
"Topology caching failed\n";
544 faceIndexBufferInitialized_ =
false;
546 if ( GLEW_ARB_vertex_buffer_object && !indices_.empty() ) {
549 if (!face_index_buffer_) glGenBuffersARB(1, (GLuint*) &face_index_buffer_);
554 glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
555 indices_.size() *
sizeof(
unsigned int),
559 faceIndexBufferInitialized_ =
true;
576 MeshNodeDeprecatedT<Mesh>::
577 draw(GLState& _state,
const DrawModes::DrawMode& _drawMode)
579 GLenum prev_depth = _state.depthFunc();
581 if (_drawMode & DrawModes::POINTS)
583 enable_arrays(VERTEX_ARRAY);
590 if ( ( _drawMode & DrawModes::POINTS_COLORED ) && mesh_.has_vertex_colors())
592 enable_arrays(VERTEX_ARRAY | COLOR_ARRAY);
599 if ( ( _drawMode & DrawModes::POINTS_SHADED ) && mesh_.has_vertex_normals())
601 enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY);
608 if (_drawMode & DrawModes::WIREFRAME)
610 glPushAttrib(GL_ENABLE_BIT);
614 enable_arrays(VERTEX_ARRAY);
617 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
618 draw_faces(PER_VERTEX);
619 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
625 if (_drawMode & DrawModes::HIDDENLINE)
627 enable_arrays(VERTEX_ARRAY);
629 Vec4f clear_color = _state.clear_color();
630 Vec4f base_color = _state.base_color();
631 clear_color[3] = 1.0;
635 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
636 _state.set_base_color(clear_color);
639 draw_faces(PER_VERTEX);
642 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
644 _state.set_base_color(base_color);
645 draw_faces(PER_VERTEX);
647 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
651 if ( ( _drawMode & DrawModes::SOLID_FLAT_SHADED ) && mesh_.has_face_normals())
656 draw_faces(FACE_NORMALS);
661 if ( ( _drawMode & DrawModes::SOLID_SMOOTH_SHADED ) && mesh_.has_vertex_normals())
663 enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY);
667 draw_faces(PER_VERTEX);
671 if ( ( _drawMode & DrawModes::SOLID_PHONG_SHADED ) && mesh_.has_vertex_normals() )
683 enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY);
687 draw_faces(PER_VERTEX);
696 if ( ( _drawMode & DrawModes::SOLID_ENV_MAPPED ) && mesh_.has_vertex_normals())
698 enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY);
702 draw_faces(PER_VERTEX);
707 if ( ( _drawMode & DrawModes::SOLID_FACES_COLORED )&& mesh_.has_face_colors())
709 Vec4f base_color_backup = _state.base_color();
714 draw_faces(FACE_COLORS);
717 _state.set_base_color(base_color_backup);
721 if ( ( _drawMode & DrawModes::SOLID_FACES_COLORED_FLAT_SHADED ) && mesh_.has_face_colors() && mesh_.has_face_normals())
723 Vec4f base_color_backup = _state.base_color();
728 draw_faces(FACE_NORMALS_COLORS);
731 _state.set_base_color(base_color_backup);
735 if ( ( _drawMode & DrawModes::SOLID_POINTS_COLORED ) && mesh_.has_vertex_colors())
737 Vec4f base_color_backup = _state.base_color();
739 enable_arrays(VERTEX_ARRAY | COLOR_ARRAY);
743 draw_faces(PER_VERTEX);
746 _state.set_base_color(base_color_backup);
750 if ( ( _drawMode & DrawModes::SOLID_TEXTURED ) && mesh_.has_vertex_texcoords2D())
752 enable_arrays(VERTEX_ARRAY | TEXTURE_COORD_2D_ARRAY);
757 draw_faces(PER_VERTEX);
763 if ( ( _drawMode & DrawModes::SOLID_TEXTURED_SHADED ) && mesh_.has_vertex_texcoords2D() && mesh_.has_vertex_normals())
765 enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY | TEXTURE_COORD_2D_ARRAY);
770 draw_faces(PER_VERTEX);
776 if ( ( _drawMode & DrawModes::SOLID_1DTEXTURED ) && mesh_.has_vertex_texcoords1D())
778 enable_arrays(VERTEX_ARRAY | TEXTURE_COORD_1D_ARRAY);
780 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
784 draw_faces(PER_VERTEX);
790 if ( ( _drawMode & DrawModes::SOLID_1DTEXTURED_SHADED ) && mesh_.has_vertex_texcoords1D() && mesh_.has_vertex_normals())
793 const Vec4f ambient = _state.ambient_color();
794 const Vec4f diffuse = _state.diffuse_color();
795 const Vec4f specular = _state.specular_color();
796 _state.set_ambient_color (
Vec4f(0.1, 0.1, 0.1, 1.0));
797 _state.set_diffuse_color (
Vec4f(0.8, 0.8, 0.8, 1.0));
798 _state.set_specular_color (
Vec4f(1.0, 1.0, 1.0, 1.0));
802 glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &texmode);
803 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
805 enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY | TEXTURE_COORD_1D_ARRAY);
810 draw_faces(PER_VERTEX);
815 _state.set_ambient_color(ambient);
816 _state.set_diffuse_color(diffuse);
817 _state.set_specular_color(specular);
820 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texmode);
825 if ( ( _drawMode & DrawModes::SOLID_3DTEXTURED ) && mesh_.has_vertex_texcoords3D())
827 enable_arrays(VERTEX_ARRAY | TEXTURE_COORD_3D_ARRAY);
832 draw_faces(PER_VERTEX);
838 if ( ( _drawMode & DrawModes::SOLID_3DTEXTURED_SHADED ) && mesh_.has_vertex_texcoords3D() && mesh_.has_vertex_normals())
840 enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY | TEXTURE_COORD_3D_ARRAY);
845 draw_faces(PER_VERTEX);
852 if ( ( _drawMode & DrawModes::SOLID_2DTEXTURED_FACE ) && mesh_.has_halfedge_texcoords2D())
858 draw_faces(FACE_HALFEDGE_TEXTURED);
865 if ( ( _drawMode & DrawModes::SOLID_2DTEXTURED_FACE_SHADED ) && mesh_.has_halfedge_texcoords2D() && mesh_.has_face_normals())
872 draw_faces(FACE_HALFEDGE_TEXTURED);
879 if ( (_drawMode & DrawModes::SOLID_SHADER ) ) {
881 if ( mesh_.has_face_normals() )
882 enable_arrays( VERTEX_ARRAY | NORMAL_ARRAY);
884 enable_arrays( VERTEX_ARRAY );
889 draw_faces(PER_VERTEX);
903 MeshNodeDeprecatedT<Mesh>::
906 glDrawArrays(GL_POINTS, 0, mesh_.n_vertices());
915 MeshNodeDeprecatedT<Mesh>::
916 draw_faces(FaceMode _mode)
918 typename Mesh::ConstFaceIter f_it(mesh_.faces_sbegin()),
919 f_end(mesh_.faces_end());
929 glBegin(GL_TRIANGLES);
930 for (; f_it!=f_end; ++f_it)
934 fv_it=mesh_.cfv_iter(*f_it);
935 glVertex(mesh_.point(*fv_it)); ++fv_it;
936 glVertex(mesh_.point(*fv_it)); ++fv_it;
943 for (; f_it!=f_end; ++f_it)
947 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it)
960 glBegin(GL_TRIANGLES);
961 for (; f_it!=f_end; ++f_it)
965 fv_it=mesh_.cfv_iter(*f_it);
966 glVertex(mesh_.point(*fv_it)); ++fv_it;
967 glVertex(mesh_.point(*fv_it)); ++fv_it;
974 for (; f_it!=f_end; ++f_it)
978 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it)
987 case FACE_NORMALS_COLORS:
991 glBegin(GL_TRIANGLES);
992 for (; f_it!=f_end; ++f_it)
997 fv_it=mesh_.cfv_iter(*f_it);
998 glVertex(mesh_.point(*fv_it)); ++fv_it;
999 glVertex(mesh_.point(*fv_it)); ++fv_it;
1006 for (; f_it!=f_end; ++f_it)
1008 glBegin(GL_POLYGON);
1011 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it)
1023 case FACE_HALFEDGE_TEXTURED:
1029 if ( !mesh_.get_property_handle(texture_index_property,indexPropertyName_) ) {
1030 if( indexPropertyName_ !=
"No Texture Index")
1031 std::cerr <<
"Unable to get per face texture Index property named " << indexPropertyName_ << std::endl;
1032 if ( !mesh_.get_property_handle(texture_index_property,
"f:textureindex") ) {
1033 std::cerr <<
"Unable to get standard per face texture Index property" << std::endl;
1034 texture_index_property.
reset();
1043 if ( !textureMap_ || !texture_index_property.
is_valid() ) {
1047 if ( !mesh_.get_property_handle(texture_coord_property,default_halfedge_textcoord_property_) ) {
1048 std::cerr <<
"Error: Unable to get per face texture coordinate property named " 1049 << default_halfedge_textcoord_property_ << std::endl;
1050 std::cerr <<
"Unable to texture without texture coordinates" << std::endl;
1056 glBegin(GL_TRIANGLES);
1057 for (; f_it!=f_end; ++f_it) {
1059 for (fh_it = mesh_.cfh_iter(*f_it);fh_it.is_valid();++fh_it)
1061 point = mesh_.point(mesh_.to_vertex_handle(*fh_it));
1062 tex2d = mesh_.property(texture_coord_property,*fh_it);
1063 glTexCoord2f(tex2d[0], tex2d[1]);
1071 int last_texture = -1;
1076 for (; f_it!=f_end; ++f_it)
1078 int texture = mesh_.property(texture_index_property,*f_it);
1083 if ( last_texture != texture ) {
1085 if ( textureMap_->find(texture) == textureMap_->end() ) {
1086 std::cerr <<
"Illegal texture index ... trying to access " << texture << std::endl;
1092 if ( !propertyMap_ || !mesh_.get_property_handle(texture_coord_property,(*propertyMap_)[texture]) ) {
1094 std::cerr <<
"Error: Unable to get per face texture coordinate property named " 1095 << (*propertyMap_)[texture] << std::endl;
1096 if ( !mesh_.get_property_handle(texture_coord_property,
"h:texcoords2D") ) {
1097 std::cerr <<
"Fallback: Unable to get standard Property for per halfedge texcoords" << std::endl;
1098 std::cerr <<
"Unable to texture face without texture coordinates" << std::endl;
1107 last_texture = texture;
1111 glBegin(GL_TRIANGLES);
1116 for (fh_it = mesh_.cfh_iter(*f_it);fh_it.is_valid();++fh_it)
1118 point = mesh_.point(mesh_.to_vertex_handle(*fh_it));
1119 tex2d = mesh_.property(texture_coord_property,*fh_it);
1120 glTexCoord2f(tex2d[0], tex2d[1]);
1142 if (!indices_.empty())
1146 if ( faceIndexBufferInitialized_ ) {
1152 glDrawElements(GL_TRIANGLES,
1162 glDrawElements(GL_TRIANGLES,
1174 glBegin(GL_TRIANGLES);
1175 for (; f_it!=f_end; ++f_it)
1178 fv_it=mesh_.cfv_iter(*f_it);
1179 glArrayElement(fv_it->idx()); ++fv_it;
1180 glArrayElement(fv_it->idx()); ++fv_it;
1181 glArrayElement(fv_it->idx());
1188 for (; f_it!=f_end; ++f_it)
1190 glBegin(GL_POLYGON);
1191 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it)
1192 glArrayElement(fv_it->idx());
1205 template<
class Mesh>
1207 MeshNodeDeprecatedT<Mesh>::
1208 pick(GLState& _state, PickTarget _target)
1214 pick_vertices(_state);
1219 pick_vertices(_state,
true);
1242 pick_edges(_state,
true);
1255 template<
class Mesh>
1257 MeshNodeDeprecatedT<Mesh>::
1258 pick_vertices(GLState& _state,
bool _front)
1260 GLenum prev_depth = _state.depthFunc();
1262 typename Mesh::ConstVertexIter v_it(mesh_.vertices_begin()),
1263 v_end(mesh_.vertices_end());
1266 if (!_state.pick_set_maximum (mesh_.n_vertices()))
1268 omerr() <<
"MeshNode::pick_vertices: color range too small, " 1269 <<
"picking failed\n";
1275 enable_arrays(VERTEX_ARRAY);
1277 Vec4f clear_color = _state.clear_color();
1278 Vec4f base_color = _state.base_color();
1279 clear_color[3] = 1.0;
1281 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1282 _state.set_base_color(clear_color);
1285 draw_faces(PER_VERTEX);
1288 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
1290 _state.set_base_color(base_color);
1292 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1298 if (vertexList_ && !updateVertexList_ && _state.pick_current_index () == vertexBaseIndex_)
1300 glCallList (vertexList_);
1307 glNewList (vertexList_, GL_COMPILE);
1308 updateVertexList_ =
false;
1309 vertexBaseIndex_ = _state.pick_current_index ();
1312 if (_state.color_picking ())
1314 update_pick_buffers ();
1316 for (; v_it!=v_end; ++v_it, ++idx)
1318 pickColorBuf_[idx] = _state.pick_get_name_color (idx);
1319 pickVertexBuf_[idx] = mesh_.point(*v_it);
1328 glDrawArrays(GL_POINTS, 0, mesh_.n_vertices());
1335 for (; v_it!=v_end; ++v_it, ++idx)
1337 _state.pick_set_name (idx);
1347 glCallList (vertexList_);
1357 template<
class Mesh>
1359 MeshNodeDeprecatedT<Mesh>::
1360 pick_faces(GLState& _state)
1362 typename Mesh::ConstFaceIter f_it(mesh_.faces_sbegin()),
1363 f_end(mesh_.faces_end());
1367 if ( mesh_.n_faces() > 0 )
1369 if (!_state.pick_set_maximum (mesh_.n_faces()))
1371 omerr() <<
"MeshNode::pick_faces: color range too small, " 1372 <<
"picking failed\n";
1378 if (!_state.pick_set_maximum (1))
1380 omerr() <<
"Strange pickSetMAximum failed for index 1 in MeshNode\n";
1385 if (faceList_ && !updateFaceList_ && _state.pick_current_index () == faceBaseIndex_)
1387 glCallList (faceList_);
1393 glNewList (faceList_, GL_COMPILE);
1394 updateFaceList_ =
false;
1395 faceBaseIndex_ = _state.pick_current_index ();
1398 if (_state.color_picking ())
1400 update_pick_buffers ();
1401 unsigned int idx = 0;
1405 for (; f_it!=f_end; ++f_it)
1407 pickColorBuf_[idx] = _state.pick_get_name_color (f_it->idx());
1408 pickColorBuf_[idx+1] = _state.pick_get_name_color (f_it->idx());
1409 pickColorBuf_[idx+2] = _state.pick_get_name_color (f_it->idx());
1411 fv_it=mesh_.cfv_iter(*f_it);
1412 pickVertexBuf_[idx] = mesh_.point(*fv_it); ++fv_it;
1413 pickVertexBuf_[idx+1] = mesh_.point(*fv_it); ++fv_it;
1414 pickVertexBuf_[idx+2] = mesh_.point(*fv_it);
1424 glDrawArrays(GL_TRIANGLES, 0, mesh_.n_faces() * 3);
1432 unsigned int face = 0;
1433 std::vector <GLint> first;
1434 std::vector <GLsizei> count;
1436 first.resize (mesh_.n_faces());
1437 count.resize (mesh_.n_faces());
1439 for (; f_it!=f_end; ++f_it, ++face)
1441 unsigned int cnt = 0;
1445 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it, ++idx, ++cnt)
1447 pickVertexBuf_[idx] = mesh_.point(*fv_it);
1448 pickColorBuf_[idx] = _state.pick_get_name_color (f_it->idx());
1458 glMultiDrawArrays(GL_POLYGON, &first[0], &count[0], mesh_.n_faces());
1469 for (; f_it!=f_end; ++f_it)
1472 _state.pick_set_name (f_it->idx());
1474 glBegin(GL_TRIANGLES);
1476 fv_it=mesh_.cfv_iter(*f_it);
1477 glVertex(mesh_.point(*fv_it)); ++fv_it;
1478 glVertex(mesh_.point(*fv_it)); ++fv_it;
1485 for (; f_it!=f_end; ++f_it)
1488 _state.pick_set_name (f_it->idx());
1490 glBegin(GL_POLYGON);
1492 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it)
1503 glCallList (faceList_);
1510 template<
class Mesh>
1512 MeshNodeDeprecatedT<Mesh>::
1513 pick_edges(GLState& _state,
bool _front)
1515 typename Mesh::ConstEdgeIter e_it(mesh_.edges_sbegin()),
1516 e_end(mesh_.edges_end());
1518 GLenum prev_depth = _state.depthFunc();
1520 if (!_state.pick_set_maximum (mesh_.n_edges()))
1522 omerr() <<
"MeshNode::pick_edges: color range too small, " 1523 <<
"picking failed\n";
1529 enable_arrays(VERTEX_ARRAY);
1531 Vec4f clear_color = _state.clear_color();
1532 Vec4f base_color = _state.base_color();
1533 clear_color[3] = 1.0;
1535 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1536 _state.set_base_color(clear_color);
1539 draw_faces(PER_VERTEX);
1542 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
1544 _state.set_base_color(base_color);
1546 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1551 if (edgeList_ && !updateEdgeList_ && _state.pick_current_index () == edgeBaseIndex_)
1553 glCallList (edgeList_);
1560 glNewList (edgeList_, GL_COMPILE);
1561 updateEdgeList_ =
false;
1562 edgeBaseIndex_ = _state.pick_current_index ();
1565 if (_state.color_picking ())
1567 unsigned int idx = 0;
1568 update_pick_buffers ();
1570 for (; e_it!=e_end; ++e_it)
1572 pickColorBuf_[idx] = _state.pick_get_name_color (e_it->idx());
1573 pickColorBuf_[idx+1] = _state.pick_get_name_color (e_it->idx());
1574 pickVertexBuf_[idx] = mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 0)));
1575 pickVertexBuf_[idx+1] = mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 1)));
1585 glDrawArrays(GL_LINES, 0, mesh_.n_edges() * 2);
1592 for (; e_it!=e_end; ++e_it)
1594 _state.pick_set_name (e_it->idx());
1596 glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 0))));
1597 glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 1))));
1605 glCallList (edgeList_);
1614 template<
class Mesh>
1616 MeshNodeDeprecatedT<Mesh>::
1617 pick_any(GLState& _state)
1619 GLenum prev_depth = _state.depthFunc();
1621 unsigned int numElements = mesh_.n_faces() + mesh_.n_edges() + mesh_.n_vertices();
1624 if (numElements == 0)
1627 if (!_state.pick_set_maximum (numElements))
1629 omerr() <<
"MeshNode::pick_any: color range too small, " 1630 <<
"picking failed\n";
1634 if (anyList_ && !updateAnyList_ && _state.pick_current_index () == anyBaseIndex_)
1636 glCallList (anyList_);
1637 glCallList (anyList_+1);
1638 glCallList (anyList_+2);
1644 glNewList (anyList_, GL_COMPILE);
1645 updateAnyList_ =
false;
1646 anyBaseIndex_ = _state.pick_current_index ();
1650 typename Mesh::ConstFaceIter f_it(mesh_.faces_sbegin()),
1651 f_end(mesh_.faces_end());
1655 typename Mesh::ConstEdgeIter e_it(mesh_.edges_sbegin()),
1656 e_end(mesh_.edges_end());
1659 typename Mesh::ConstVertexIter v_it(mesh_.vertices_begin()),
1660 v_end(mesh_.vertices_end());
1661 GLuint vidx(mesh_.n_faces() + mesh_.n_edges());
1665 if (_state.color_picking ())
1667 update_pick_buffers ();
1673 unsigned int idx = 0;
1676 for (; f_it!=f_end; ++f_it)
1678 pickColorBuf_[idx] = _state.pick_get_name_color (f_it->idx());
1679 pickColorBuf_[idx+1] = _state.pick_get_name_color (f_it->idx());
1680 pickColorBuf_[idx+2] = _state.pick_get_name_color (f_it->idx());
1682 fv_it=mesh_.cfv_iter(*f_it);
1683 pickVertexBuf_[idx] = mesh_.point(*fv_it); ++fv_it;
1684 pickVertexBuf_[idx+1] = mesh_.point(*fv_it); ++fv_it;
1685 pickVertexBuf_[idx+2] = mesh_.point(*fv_it);
1692 glDrawArrays(GL_TRIANGLES, 0, mesh_.n_faces() * 3);
1697 unsigned int face = 0;
1698 std::vector <GLint> first;
1699 std::vector <GLsizei> count;
1701 first.resize (mesh_.n_faces());
1702 count.resize (mesh_.n_faces());
1704 for (; f_it!=f_end; ++f_it, ++face)
1706 unsigned int cnt = 0;
1710 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it, ++idx, ++cnt)
1712 pickVertexBuf_[idx] = mesh_.point(*fv_it);
1713 pickColorBuf_[idx] = _state.pick_get_name_color (f_it->idx());
1721 glMultiDrawArrays(GL_POLYGON, &first[0], &count[0], mesh_.n_faces());
1728 glNewList (anyList_+1, GL_COMPILE);
1735 for (; e_it!=e_end; ++e_it)
1737 pickColorBuf_[idx] = _state.pick_get_name_color (mesh_.n_faces() + e_it->idx());
1738 pickColorBuf_[idx+1] = _state.pick_get_name_color (mesh_.n_faces() + e_it->idx());
1739 pickVertexBuf_[idx] = mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 0)));
1740 pickVertexBuf_[idx+1] = mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 1)));
1747 glDrawArrays(GL_LINES, 0, mesh_.n_edges() * 2);
1753 glNewList (anyList_+2, GL_COMPILE);
1759 for (; v_it!=v_end; ++v_it, ++idx, ++vidx)
1761 pickColorBuf_[idx] = _state.pick_get_name_color (vidx);
1762 pickVertexBuf_[idx] = mesh_.point(*v_it);
1768 glDrawArrays(GL_POINTS, 0, mesh_.n_vertices());
1778 for (; f_it!=f_end; ++f_it)
1781 _state.pick_set_name (f_it->idx());
1783 glBegin(GL_TRIANGLES);
1785 fv_it=mesh_.cfv_iter(*f_it);
1786 glVertex(mesh_.point(*fv_it)); ++fv_it;
1787 glVertex(mesh_.point(*fv_it)); ++fv_it;
1794 for (; f_it!=f_end; ++f_it)
1797 _state.pick_set_name (f_it->idx());
1799 glBegin(GL_POLYGON);
1801 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it)
1812 glNewList (anyList_+1, GL_COMPILE);
1818 for (; e_it!=e_end; ++e_it)
1820 _state.pick_set_name (mesh_.n_faces() + e_it->idx());
1822 glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 0))));
1823 glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 1))));
1831 glNewList (anyList_+2, GL_COMPILE);
1836 for (; v_it!=v_end; ++v_it, ++vidx)
1838 _state.pick_set_name (vidx);
1850 glCallList (anyList_);
1851 glCallList (anyList_+1);
1852 glCallList (anyList_+2);
1858 template<
class Mesh>
1860 MeshNodeDeprecatedT<Mesh>::
1861 update_pick_buffers ()
1863 unsigned int nfv = 0;
1865 nfv = mesh_.n_faces() * 3;
1869 typename Mesh::ConstFaceIter f_it(mesh_.faces_sbegin()),
1870 f_end(mesh_.faces_end());
1872 for (; f_it!=f_end; ++f_it)
1874 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it)
1879 pickVertexBuf_.resize (std::max(mesh_.n_vertices(), std::max(mesh_.n_edges() * 2, size_t(nfv))));
1880 pickColorBuf_.resize (std::max(mesh_.n_vertices(), std::max(mesh_.n_edges() * 2, size_t(nfv))));
1886 #endif // DOXY_IGNORE_THIS static void enable(GLenum _cap)
replaces glEnable, but supports locking
void glColor(const Vec3f &_v)
Wrapper: glColor for Vec3f.
Add normals to mesh item (vertices/faces)
picks only visible front edges (may not be implemented for all nodes)
static void disableClientState(GLenum _cap)
replaces glDisableClientState, supports locking
void glNormal(const Vec3f &_n)
Wrapper: glNormal for Vec3f.
static void enableClientState(GLenum _cap)
replaces glEnableClientState, supports locking
static void texcoordPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glTexcoordPointer, supports locking
void glVertex(const Vec2i &_v)
Wrapper: glVertex for Vec2i.
Kernel::Normal Normal
Normal type.
bool is_valid() const
The handle is valid iff the index is not equal to -1.
Kernel::ConstFaceHalfedgeIter ConstFaceHalfedgeIter
Circulator.
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
static bool is_trimesh()
Determine whether this is a PolyMeshT or TriMeshT ( This function does not check the per face vertex ...
Kernel::ConstFaceVertexIter ConstFaceVertexIter
Circulator.
Namespace providing different geometric functions concerning angles.
picks verices (may not be implemented for all nodes)
static void colorPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glColorPointer, supports locking
static void vertexPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glVertexPointer, supports locking
Kernel::TexCoord2D TexCoord2D
TexCoord2D type.
static void disable(GLenum _cap)
replaces glDisable, but supports locking
picks only visible front verices (may not be implemented for all nodes)
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
picks edges (may not be implemented for all nodes)
Kernel::Point Point
Coordinate type.
static void bindTexture(GLenum _target, GLuint _buffer)
replaces glBindTexture, supports locking
pick any of the prior targets (should be implemented for all nodes)
VectorT< double, 3 > Vec3d
picks faces (should be implemented for all nodes)
void reset()
reset handle to be invalid
static void normalPointer(GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glNormalPointer, supports locking
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking