53#ifndef DOXY_IGNORE_THIS
59#include "MeshNodeDeprecatedT.hh"
60#include "ShaderNode.hh"
61#include "DrawModes.hh"
62#include <ACG/GL/gl.hh>
63#include <ACG/GL/GLError.hh>
64#include <ACG/GL/ColorTranslator.hh>
67#include <OpenMesh/Core/Utils/Property.hh>
82MeshNodeDeprecatedT<Mesh>::
83MeshNodeDeprecatedT(
const Mesh& _mesh,
89 face_index_buffer_(0),
92 vertexBufferInitialized_(false),
93 normalBufferInitialized_(false),
94 faceIndexBufferInitialized_(false),
97 default_halfedge_textcoord_property_(
"h:texcoords2D"),
98 indexPropertyName_(
"f:textureindex"),
99 updateFaceList_(true),
100 updateVertexList_(true),
101 updateEdgeList_(true),
102 updateAnyList_(true),
107 bbMin_(FLT_MAX, FLT_MAX, FLT_MAX),
108 bbMax_(-FLT_MAX, -FLT_MAX, -FLT_MAX)
110 faceList_ = glGenLists (1);
111 vertexList_ = glGenLists (1);
112 edgeList_ = glGenLists (1);
113 anyList_ = glGenLists (3);
121MeshNodeDeprecatedT<Mesh>::
122~MeshNodeDeprecatedT()
125 glDeleteBuffers(1, (GLuint*) &vertex_buffer_);
128 glDeleteBuffers(1, (GLuint*) &normal_buffer_);
130 if (face_index_buffer_)
131 glDeleteBuffers(1, (GLuint*) &face_index_buffer_ );
134 glDeleteLists (faceList_, 1);
137 glDeleteLists (vertexList_, 1);
140 glDeleteLists (edgeList_, 1);
143 glDeleteLists (anyList_, 3);
152MeshNodeDeprecatedT<Mesh>::
165MeshNodeDeprecatedT<Mesh>::
166availableDrawModes()
const
168 DrawModes::DrawMode drawModes(DrawModes::NONE);
170 drawModes |= DrawModes::POINTS;
171 drawModes |= DrawModes::WIREFRAME;
172 drawModes |= DrawModes::HIDDENLINE;
173 drawModes |= DrawModes::SOLID_SHADER;
175 if (mesh_.has_vertex_normals())
177 drawModes |= DrawModes::POINTS_SHADED;
178 drawModes |= DrawModes::SOLID_SMOOTH_SHADED;
179 drawModes |= DrawModes::SOLID_PHONG_SHADED;
182 if (mesh_.has_vertex_colors())
184 drawModes |= DrawModes::POINTS_COLORED;
185 drawModes |= DrawModes::SOLID_POINTS_COLORED;
188 if (mesh_.has_face_normals())
189 drawModes |= DrawModes::SOLID_FLAT_SHADED;
191 if (mesh_.has_face_colors())
193 drawModes |= DrawModes::SOLID_FACES_COLORED;
195 if( mesh_.has_face_normals() )
196 drawModes |= DrawModes::SOLID_FACES_COLORED_FLAT_SHADED;
199 if (mesh_.has_vertex_texcoords1D())
201 drawModes |= DrawModes::SOLID_1DTEXTURED;
203 if (mesh_.has_vertex_normals())
204 drawModes |= DrawModes::SOLID_1DTEXTURED_SHADED;
207 if (mesh_.has_vertex_texcoords2D())
209 drawModes |= DrawModes::SOLID_TEXTURED;
211 if (mesh_.has_vertex_normals())
212 drawModes |= DrawModes::SOLID_TEXTURED_SHADED;
215 if (mesh_.has_vertex_texcoords3D())
217 drawModes |= DrawModes::SOLID_3DTEXTURED;
219 if (mesh_.has_vertex_normals())
220 drawModes |= DrawModes::SOLID_3DTEXTURED_SHADED;
223 if (mesh_.has_halfedge_texcoords2D())
225 drawModes |= DrawModes::SOLID_2DTEXTURED_FACE;
226 if (mesh_.has_face_normals())
227 drawModes |= DrawModes::SOLID_2DTEXTURED_FACE_SHADED;
239MeshNodeDeprecatedT<Mesh>::
240enable_arrays(
unsigned int _arrays)
245 typedef typename Point::value_type PointScalar;
247 typedef typename Normal::value_type NormalScalar;
250 ((_arrays == VERTEX_ARRAY || _arrays == (VERTEX_ARRAY | NORMAL_ARRAY)) &&
251 (vertexBufferInitialized_ && normalBufferInitialized_) ) ;
257 if (!use_vbo && vertex_buffer_)
262 if (_arrays & VERTEX_ARRAY)
264 if (!(enabled_arrays_ & VERTEX_ARRAY))
266 enabled_arrays_ |= VERTEX_ARRAY;
282 else if (enabled_arrays_ & VERTEX_ARRAY)
284 enabled_arrays_ &= ~VERTEX_ARRAY;
289 if (_arrays & NORMAL_ARRAY)
291 if (!(enabled_arrays_ & NORMAL_ARRAY))
293 enabled_arrays_ |= NORMAL_ARRAY;
309 else if (enabled_arrays_ & NORMAL_ARRAY)
311 enabled_arrays_ &= ~NORMAL_ARRAY;
316 if (_arrays & COLOR_ARRAY)
318 if (!(enabled_arrays_ & COLOR_ARRAY))
320 enabled_arrays_ |= COLOR_ARRAY;
325 else if (enabled_arrays_ & COLOR_ARRAY)
327 enabled_arrays_ &= ~COLOR_ARRAY;
332 if (_arrays & TEXTURE_COORD_1D_ARRAY)
334 if (!(enabled_arrays_ & TEXTURE_COORD_1D_ARRAY))
336 enabled_arrays_ |= TEXTURE_COORD_1D_ARRAY;
341 else if (enabled_arrays_ & TEXTURE_COORD_1D_ARRAY)
343 enabled_arrays_ &= ~TEXTURE_COORD_1D_ARRAY;
348 if (_arrays & TEXTURE_COORD_2D_ARRAY)
350 if (!(enabled_arrays_ & TEXTURE_COORD_2D_ARRAY))
352 enabled_arrays_ |= TEXTURE_COORD_2D_ARRAY;
357 else if (enabled_arrays_ & TEXTURE_COORD_2D_ARRAY)
359 enabled_arrays_ &= ~TEXTURE_COORD_2D_ARRAY;
364 if (_arrays & TEXTURE_COORD_3D_ARRAY)
366 if (!(enabled_arrays_ & TEXTURE_COORD_3D_ARRAY))
368 enabled_arrays_ |= TEXTURE_COORD_3D_ARRAY;
373 else if (enabled_arrays_ & TEXTURE_COORD_3D_ARRAY)
375 enabled_arrays_ &= ~TEXTURE_COORD_3D_ARRAY;
389MeshNodeDeprecatedT<Mesh>::
392 updateFaceList_ =
true;
393 updateVertexList_ =
true;
394 updateEdgeList_ =
true;
395 updateAnyList_ =
true;
397 bbMin_ =
Vec3d(FLT_MAX, FLT_MAX, FLT_MAX);
398 bbMax_ =
Vec3d(-FLT_MAX, -FLT_MAX, -FLT_MAX);
400 v_end(mesh_.vertices_end());
402 for (; v_it!=v_end; ++v_it)
404 bbMin_.minimize(mesh_.point(*v_it));
405 bbMax_.maximize(mesh_.point(*v_it));
409 typedef typename Point::value_type PointScalar;
411 typedef typename Normal::value_type NormalScalar;
417 if (!vertex_buffer_) glGenBuffers(1, (GLuint*) &vertex_buffer_);
420 vertexBufferInitialized_ =
false;
423 if (
sizeof(PointScalar) == 4 ) {
425 glBufferData(GL_ARRAY_BUFFER_ARB,
426 3 * mesh_.n_vertices() *
sizeof(PointScalar),
430 vertexBufferInitialized_ =
true;
436 v_end(mesh_.vertices_end());
438 for ( ; v_it != v_end ; ++v_it )
439 vertices_.push_back(
ACG::Vec3f(mesh_.point(*v_it)) );
441 if ( !vertices_.empty() ) {
443 glBufferData(GL_ARRAY_BUFFER_ARB,
444 3 * mesh_.n_vertices() *
sizeof(
float),
447 vertexBufferInitialized_ =
true;
456 if (!normal_buffer_) glGenBuffers(1, (GLuint*) &normal_buffer_);
458 normalBufferInitialized_ =
false;
461 if (
sizeof(NormalScalar) == 4) {
463 glBufferData(GL_ARRAY_BUFFER_ARB,
464 3 * mesh_.n_vertices() *
sizeof(NormalScalar),
465 mesh_.vertex_normals(),
468 normalBufferInitialized_ =
true;
473 v_end(mesh_.vertices_end());
475 for ( ; v_it != v_end ; ++v_it )
476 normals_.push_back(
ACG::Vec3f(mesh_.normal(*v_it)) );
478 if ( !normals_.empty() ) {
480 glBufferData(GL_ARRAY_BUFFER_ARB,
481 3 * mesh_.n_vertices() *
sizeof(
float),
484 normalBufferInitialized_ =
true;
492 }
else omlog() <<
"MeshNodeDeprecatedT: VBO not supported on this machine\n";
501MeshNodeDeprecatedT<Mesh>::
504 updateFaceList_ =
true;
505 updateVertexList_ =
true;
507 if (mesh_.is_trimesh())
510 f_end(mesh_.faces_end());
516 std::vector<unsigned int>().swap(indices_);
517 indices_.reserve(mesh_.n_faces()*3);
519 for (; f_it!=f_end; ++f_it)
521 fv_it = mesh_.cfv_iter( *f_it );
522 indices_.push_back(fv_it->idx()); ++fv_it;
523 indices_.push_back(fv_it->idx()); ++fv_it;
524 indices_.push_back(fv_it->idx());
530 std::vector<unsigned int>().swap(indices_);
531 omerr() <<
"Topology caching failed\n";
537 faceIndexBufferInitialized_ =
false;
539 if ( !indices_.empty() ) {
542 if (!face_index_buffer_) glGenBuffers(1, (GLuint*) &face_index_buffer_);
547 glBufferData(GL_ELEMENT_ARRAY_BUFFER_ARB,
548 indices_.size() *
sizeof(
unsigned int),
552 faceIndexBufferInitialized_ =
true;
569MeshNodeDeprecatedT<Mesh>::
570draw(GLState& _state,
const DrawModes::DrawMode& _drawMode)
572 GLenum prev_depth = _state.depthFunc();
574 if (_drawMode & DrawModes::POINTS)
576 enable_arrays(VERTEX_ARRAY);
583 if ( ( _drawMode & DrawModes::POINTS_COLORED ) && mesh_.has_vertex_colors())
585 enable_arrays(VERTEX_ARRAY | COLOR_ARRAY);
592 if ( ( _drawMode & DrawModes::POINTS_SHADED ) && mesh_.has_vertex_normals())
594 enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY);
601 if (_drawMode & DrawModes::WIREFRAME)
603 glPushAttrib(GL_ENABLE_BIT);
607 enable_arrays(VERTEX_ARRAY);
610 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
611 draw_faces(PER_VERTEX);
612 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
618 if (_drawMode & DrawModes::HIDDENLINE)
620 enable_arrays(VERTEX_ARRAY);
622 Vec4f clear_color = _state.clear_color();
623 Vec4f base_color = _state.base_color();
624 clear_color[3] = 1.0;
628 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
629 _state.set_base_color(clear_color);
632 draw_faces(PER_VERTEX);
635 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
637 _state.set_base_color(base_color);
638 draw_faces(PER_VERTEX);
640 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
644 if ( ( _drawMode & DrawModes::SOLID_FLAT_SHADED ) && mesh_.has_face_normals())
649 draw_faces(FACE_NORMALS);
654 if ( ( _drawMode & DrawModes::SOLID_SMOOTH_SHADED ) && mesh_.has_vertex_normals())
656 enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY);
660 draw_faces(PER_VERTEX);
664 if ( ( _drawMode & DrawModes::SOLID_PHONG_SHADED ) && mesh_.has_vertex_normals() )
676 enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY);
680 draw_faces(PER_VERTEX);
689 if ( ( _drawMode & DrawModes::SOLID_ENV_MAPPED ) && mesh_.has_vertex_normals())
691 enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY);
695 draw_faces(PER_VERTEX);
700 if ( ( _drawMode & DrawModes::SOLID_FACES_COLORED )&& mesh_.has_face_colors())
702 Vec4f base_color_backup = _state.base_color();
707 draw_faces(FACE_COLORS);
710 _state.set_base_color(base_color_backup);
714 if ( ( _drawMode & DrawModes::SOLID_FACES_COLORED_FLAT_SHADED ) && mesh_.has_face_colors() && mesh_.has_face_normals())
716 Vec4f base_color_backup = _state.base_color();
721 draw_faces(FACE_NORMALS_COLORS);
724 _state.set_base_color(base_color_backup);
728 if ( ( _drawMode & DrawModes::SOLID_POINTS_COLORED ) && mesh_.has_vertex_colors())
730 Vec4f base_color_backup = _state.base_color();
732 enable_arrays(VERTEX_ARRAY | COLOR_ARRAY);
736 draw_faces(PER_VERTEX);
739 _state.set_base_color(base_color_backup);
743 if ( ( _drawMode & DrawModes::SOLID_TEXTURED ) && mesh_.has_vertex_texcoords2D())
745 enable_arrays(VERTEX_ARRAY | TEXTURE_COORD_2D_ARRAY);
750 draw_faces(PER_VERTEX);
756 if ( ( _drawMode & DrawModes::SOLID_TEXTURED_SHADED ) && mesh_.has_vertex_texcoords2D() && mesh_.has_vertex_normals())
758 enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY | TEXTURE_COORD_2D_ARRAY);
763 draw_faces(PER_VERTEX);
769 if ( ( _drawMode & DrawModes::SOLID_1DTEXTURED ) && mesh_.has_vertex_texcoords1D())
771 enable_arrays(VERTEX_ARRAY | TEXTURE_COORD_1D_ARRAY);
773 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
777 draw_faces(PER_VERTEX);
783 if ( ( _drawMode & DrawModes::SOLID_1DTEXTURED_SHADED ) && mesh_.has_vertex_texcoords1D() && mesh_.has_vertex_normals())
786 const Vec4f ambient = _state.ambient_color();
787 const Vec4f diffuse = _state.diffuse_color();
788 const Vec4f specular = _state.specular_color();
789 _state.set_ambient_color (
Vec4f(0.1, 0.1, 0.1, 1.0));
790 _state.set_diffuse_color (
Vec4f(0.8, 0.8, 0.8, 1.0));
791 _state.set_specular_color (
Vec4f(1.0, 1.0, 1.0, 1.0));
795 glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &texmode);
796 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
798 enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY | TEXTURE_COORD_1D_ARRAY);
803 draw_faces(PER_VERTEX);
808 _state.set_ambient_color(ambient);
809 _state.set_diffuse_color(diffuse);
810 _state.set_specular_color(specular);
813 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texmode);
818 if ( ( _drawMode & DrawModes::SOLID_3DTEXTURED ) && mesh_.has_vertex_texcoords3D())
820 enable_arrays(VERTEX_ARRAY | TEXTURE_COORD_3D_ARRAY);
825 draw_faces(PER_VERTEX);
831 if ( ( _drawMode & DrawModes::SOLID_3DTEXTURED_SHADED ) && mesh_.has_vertex_texcoords3D() && mesh_.has_vertex_normals())
833 enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY | TEXTURE_COORD_3D_ARRAY);
838 draw_faces(PER_VERTEX);
845 if ( ( _drawMode & DrawModes::SOLID_2DTEXTURED_FACE ) && mesh_.has_halfedge_texcoords2D())
851 draw_faces(FACE_HALFEDGE_TEXTURED);
858 if ( ( _drawMode & DrawModes::SOLID_2DTEXTURED_FACE_SHADED ) && mesh_.has_halfedge_texcoords2D() && mesh_.has_face_normals())
865 draw_faces(FACE_HALFEDGE_TEXTURED);
872 if ( (_drawMode & DrawModes::SOLID_SHADER ) ) {
874 if ( mesh_.has_face_normals() )
875 enable_arrays( VERTEX_ARRAY | NORMAL_ARRAY);
877 enable_arrays( VERTEX_ARRAY );
882 draw_faces(PER_VERTEX);
896MeshNodeDeprecatedT<Mesh>::
899 glDrawArrays(GL_POINTS, 0, mesh_.n_vertices());
908MeshNodeDeprecatedT<Mesh>::
909draw_faces(FaceMode _mode)
912 f_end(mesh_.faces_end());
920 if (mesh_.is_trimesh())
922 glBegin(GL_TRIANGLES);
923 for (; f_it!=f_end; ++f_it)
927 fv_it=mesh_.cfv_iter(*f_it);
928 glVertex(mesh_.point(*fv_it)); ++fv_it;
929 glVertex(mesh_.point(*fv_it)); ++fv_it;
936 for (; f_it!=f_end; ++f_it)
940 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it)
951 if (mesh_.is_trimesh())
953 glBegin(GL_TRIANGLES);
954 for (; f_it!=f_end; ++f_it)
958 fv_it=mesh_.cfv_iter(*f_it);
959 glVertex(mesh_.point(*fv_it)); ++fv_it;
960 glVertex(mesh_.point(*fv_it)); ++fv_it;
967 for (; f_it!=f_end; ++f_it)
971 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it)
980 case FACE_NORMALS_COLORS:
982 if (mesh_.is_trimesh())
984 glBegin(GL_TRIANGLES);
985 for (; f_it!=f_end; ++f_it)
990 fv_it=mesh_.cfv_iter(*f_it);
991 glVertex(mesh_.point(*fv_it)); ++fv_it;
992 glVertex(mesh_.point(*fv_it)); ++fv_it;
999 for (; f_it!=f_end; ++f_it)
1001 glBegin(GL_POLYGON);
1004 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it)
1016 case FACE_HALFEDGE_TEXTURED:
1018 if (mesh_.is_trimesh())
1022 if ( !mesh_.get_property_handle(texture_index_property,indexPropertyName_) ) {
1023 if( indexPropertyName_ !=
"No Texture Index")
1024 std::cerr <<
"Unable to get per face texture Index property named " << indexPropertyName_ << std::endl;
1025 if ( !mesh_.get_property_handle(texture_index_property,
"f:textureindex") ) {
1026 std::cerr <<
"Unable to get standard per face texture Index property" << std::endl;
1027 texture_index_property.
reset();
1036 if ( !textureMap_ || !texture_index_property.
is_valid() ) {
1040 if ( !mesh_.get_property_handle(texture_coord_property,default_halfedge_textcoord_property_) ) {
1041 std::cerr <<
"Error: Unable to get per face texture coordinate property named "
1042 << default_halfedge_textcoord_property_ << std::endl;
1043 std::cerr <<
"Unable to texture without texture coordinates" << std::endl;
1049 glBegin(GL_TRIANGLES);
1050 for (; f_it!=f_end; ++f_it) {
1052 for (fh_it = mesh_.cfh_iter(*f_it);fh_it.is_valid();++fh_it)
1054 point = mesh_.point(mesh_.to_vertex_handle(*fh_it));
1055 tex2d = mesh_.property(texture_coord_property,*fh_it);
1056 glTexCoord2f(tex2d[0], tex2d[1]);
1064 int last_texture = -1;
1069 for (; f_it!=f_end; ++f_it)
1071 int texture = mesh_.property(texture_index_property,*f_it);
1076 if ( last_texture != texture ) {
1078 if ( textureMap_->find(texture) == textureMap_->end() ) {
1079 std::cerr <<
"Illegal texture index ... trying to access " << texture << std::endl;
1085 if ( !propertyMap_ || !mesh_.get_property_handle(texture_coord_property,(*propertyMap_)[texture]) ) {
1087 std::cerr <<
"Error: Unable to get per face texture coordinate property named "
1088 << (*propertyMap_)[texture] << std::endl;
1089 if ( !mesh_.get_property_handle(texture_coord_property,
"h:texcoords2D") ) {
1090 std::cerr <<
"Fallback: Unable to get standard Property for per halfedge texcoords" << std::endl;
1091 std::cerr <<
"Unable to texture face without texture coordinates" << std::endl;
1100 last_texture = texture;
1104 glBegin(GL_TRIANGLES);
1109 for (fh_it = mesh_.cfh_iter(*f_it);fh_it.is_valid();++fh_it)
1111 point = mesh_.point(mesh_.to_vertex_handle(*fh_it));
1112 tex2d = mesh_.property(texture_coord_property,*fh_it);
1113 glTexCoord2f(tex2d[0], tex2d[1]);
1132 if (mesh_.is_trimesh())
1135 if (!indices_.empty())
1139 if ( faceIndexBufferInitialized_ ) {
1145 glDrawElements(GL_TRIANGLES,
1155 glDrawElements(GL_TRIANGLES,
1167 glBegin(GL_TRIANGLES);
1168 for (; f_it!=f_end; ++f_it)
1171 fv_it=mesh_.cfv_iter(*f_it);
1172 glArrayElement(fv_it->idx()); ++fv_it;
1173 glArrayElement(fv_it->idx()); ++fv_it;
1174 glArrayElement(fv_it->idx());
1181 for (; f_it!=f_end; ++f_it)
1183 glBegin(GL_POLYGON);
1184 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it)
1185 glArrayElement(fv_it->idx());
1200MeshNodeDeprecatedT<Mesh>::
1201pick(GLState& _state, PickTarget _target)
1207 pick_vertices(_state);
1212 pick_vertices(_state,
true);
1235 pick_edges(_state,
true);
1250MeshNodeDeprecatedT<Mesh>::
1251pick_vertices(GLState& _state,
bool _front)
1253 GLenum prev_depth = _state.depthFunc();
1256 v_end(mesh_.vertices_end());
1259 if (!_state.pick_set_maximum (mesh_.n_vertices()))
1261 omerr() <<
"MeshNode::pick_vertices: color range too small, "
1262 <<
"picking failed\n";
1268 enable_arrays(VERTEX_ARRAY);
1270 Vec4f clear_color = _state.clear_color();
1271 Vec4f base_color = _state.base_color();
1272 clear_color[3] = 1.0;
1274 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1275 _state.set_base_color(clear_color);
1278 draw_faces(PER_VERTEX);
1281 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
1283 _state.set_base_color(base_color);
1285 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1291 if (vertexList_ && !updateVertexList_ && _state.pick_current_index () == vertexBaseIndex_)
1293 glCallList (vertexList_);
1300 glNewList (vertexList_, GL_COMPILE);
1301 updateVertexList_ =
false;
1302 vertexBaseIndex_ = _state.pick_current_index ();
1305 if (_state.color_picking ())
1307 update_pick_buffers ();
1309 for (; v_it!=v_end; ++v_it, ++idx)
1311 pickColorBuf_[idx] = _state.pick_get_name_color (idx);
1312 pickVertexBuf_[idx] = mesh_.point(*v_it);
1321 glDrawArrays(GL_POINTS, 0, mesh_.n_vertices());
1328 for (; v_it!=v_end; ++v_it, ++idx)
1330 _state.pick_set_name (idx);
1340 glCallList (vertexList_);
1352MeshNodeDeprecatedT<Mesh>::
1353pick_faces(GLState& _state)
1356 f_end(mesh_.faces_end());
1360 if ( mesh_.n_faces() > 0 )
1362 if (!_state.pick_set_maximum (mesh_.n_faces()))
1364 omerr() <<
"MeshNode::pick_faces: color range too small, "
1365 <<
"picking failed\n";
1371 if (!_state.pick_set_maximum (1))
1373 omerr() <<
"Strange pickSetMAximum failed for index 1 in MeshNode\n";
1378 if (faceList_ && !updateFaceList_ && _state.pick_current_index () == faceBaseIndex_)
1380 glCallList (faceList_);
1386 glNewList (faceList_, GL_COMPILE);
1387 updateFaceList_ =
false;
1388 faceBaseIndex_ = _state.pick_current_index ();
1391 if (_state.color_picking ())
1393 update_pick_buffers ();
1394 unsigned int idx = 0;
1396 if (mesh_.is_trimesh())
1398 for (; f_it!=f_end; ++f_it)
1400 pickColorBuf_[idx] = _state.pick_get_name_color (f_it->idx());
1401 pickColorBuf_[idx+1] = _state.pick_get_name_color (f_it->idx());
1402 pickColorBuf_[idx+2] = _state.pick_get_name_color (f_it->idx());
1404 fv_it=mesh_.cfv_iter(*f_it);
1405 pickVertexBuf_[idx] = mesh_.point(*fv_it); ++fv_it;
1406 pickVertexBuf_[idx+1] = mesh_.point(*fv_it); ++fv_it;
1407 pickVertexBuf_[idx+2] = mesh_.point(*fv_it);
1417 glDrawArrays(GL_TRIANGLES, 0, mesh_.n_faces() * 3);
1425 unsigned int face = 0;
1426 std::vector <GLint> first;
1427 std::vector <GLsizei> count;
1429 first.resize (mesh_.n_faces());
1430 count.resize (mesh_.n_faces());
1432 for (; f_it!=f_end; ++f_it, ++face)
1434 unsigned int cnt = 0;
1438 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it, ++idx, ++cnt)
1440 pickVertexBuf_[idx] = mesh_.point(*fv_it);
1441 pickColorBuf_[idx] = _state.pick_get_name_color (f_it->idx());
1451 glMultiDrawArrays(GL_POLYGON, &first[0], &count[0], mesh_.n_faces());
1460 if (mesh_.is_trimesh())
1462 for (; f_it!=f_end; ++f_it)
1465 _state.pick_set_name (f_it->idx());
1467 glBegin(GL_TRIANGLES);
1469 fv_it=mesh_.cfv_iter(*f_it);
1470 glVertex(mesh_.point(*fv_it)); ++fv_it;
1471 glVertex(mesh_.point(*fv_it)); ++fv_it;
1478 for (; f_it!=f_end; ++f_it)
1481 _state.pick_set_name (f_it->idx());
1483 glBegin(GL_POLYGON);
1485 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it)
1496 glCallList (faceList_);
1505MeshNodeDeprecatedT<Mesh>::
1506pick_edges(GLState& _state,
bool _front)
1509 e_end(mesh_.edges_end());
1511 GLenum prev_depth = _state.depthFunc();
1513 if (!_state.pick_set_maximum (mesh_.n_edges()))
1515 omerr() <<
"MeshNode::pick_edges: color range too small, "
1516 <<
"picking failed\n";
1522 enable_arrays(VERTEX_ARRAY);
1524 Vec4f clear_color = _state.clear_color();
1525 Vec4f base_color = _state.base_color();
1526 clear_color[3] = 1.0;
1528 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1529 _state.set_base_color(clear_color);
1532 draw_faces(PER_VERTEX);
1535 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
1537 _state.set_base_color(base_color);
1539 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1544 if (edgeList_ && !updateEdgeList_ && _state.pick_current_index () == edgeBaseIndex_)
1546 glCallList (edgeList_);
1553 glNewList (edgeList_, GL_COMPILE);
1554 updateEdgeList_ =
false;
1555 edgeBaseIndex_ = _state.pick_current_index ();
1558 if (_state.color_picking ())
1560 unsigned int idx = 0;
1561 update_pick_buffers ();
1563 for (; e_it!=e_end; ++e_it)
1565 pickColorBuf_[idx] = _state.pick_get_name_color (e_it->idx());
1566 pickColorBuf_[idx+1] = _state.pick_get_name_color (e_it->idx());
1567 pickVertexBuf_[idx] = mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 0)));
1568 pickVertexBuf_[idx+1] = mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 1)));
1578 glDrawArrays(GL_LINES, 0, mesh_.n_edges() * 2);
1585 for (; e_it!=e_end; ++e_it)
1587 _state.pick_set_name (e_it->idx());
1589 glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 0))));
1590 glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 1))));
1598 glCallList (edgeList_);
1609MeshNodeDeprecatedT<Mesh>::
1610pick_any(GLState& _state)
1612 GLenum prev_depth = _state.depthFunc();
1614 unsigned int numElements = mesh_.n_faces() + mesh_.n_edges() + mesh_.n_vertices();
1617 if (numElements == 0)
1620 if (!_state.pick_set_maximum (numElements))
1622 omerr() <<
"MeshNode::pick_any: color range too small, "
1623 <<
"picking failed\n";
1627 if (anyList_ && !updateAnyList_ && _state.pick_current_index () == anyBaseIndex_)
1629 glCallList (anyList_);
1630 glCallList (anyList_+1);
1631 glCallList (anyList_+2);
1637 glNewList (anyList_, GL_COMPILE);
1638 updateAnyList_ =
false;
1639 anyBaseIndex_ = _state.pick_current_index ();
1644 f_end(mesh_.faces_end());
1649 e_end(mesh_.edges_end());
1653 v_end(mesh_.vertices_end());
1654 GLuint vidx(mesh_.n_faces() + mesh_.n_edges());
1658 if (_state.color_picking ())
1660 update_pick_buffers ();
1666 unsigned int idx = 0;
1667 if (mesh_.is_trimesh())
1669 for (; f_it!=f_end; ++f_it)
1671 pickColorBuf_[idx] = _state.pick_get_name_color (f_it->idx());
1672 pickColorBuf_[idx+1] = _state.pick_get_name_color (f_it->idx());
1673 pickColorBuf_[idx+2] = _state.pick_get_name_color (f_it->idx());
1675 fv_it=mesh_.cfv_iter(*f_it);
1676 pickVertexBuf_[idx] = mesh_.point(*fv_it); ++fv_it;
1677 pickVertexBuf_[idx+1] = mesh_.point(*fv_it); ++fv_it;
1678 pickVertexBuf_[idx+2] = mesh_.point(*fv_it);
1685 glDrawArrays(GL_TRIANGLES, 0, mesh_.n_faces() * 3);
1690 unsigned int face = 0;
1691 std::vector <GLint> first;
1692 std::vector <GLsizei> count;
1694 first.resize (mesh_.n_faces());
1695 count.resize (mesh_.n_faces());
1697 for (; f_it!=f_end; ++f_it, ++face)
1699 unsigned int cnt = 0;
1703 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it, ++idx, ++cnt)
1705 pickVertexBuf_[idx] = mesh_.point(*fv_it);
1706 pickColorBuf_[idx] = _state.pick_get_name_color (f_it->idx());
1714 glMultiDrawArrays(GL_POLYGON, &first[0], &count[0], mesh_.n_faces());
1721 glNewList (anyList_+1, GL_COMPILE);
1728 for (; e_it!=e_end; ++e_it)
1730 pickColorBuf_[idx] = _state.pick_get_name_color (mesh_.n_faces() + e_it->idx());
1731 pickColorBuf_[idx+1] = _state.pick_get_name_color (mesh_.n_faces() + e_it->idx());
1732 pickVertexBuf_[idx] = mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 0)));
1733 pickVertexBuf_[idx+1] = mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 1)));
1740 glDrawArrays(GL_LINES, 0, mesh_.n_edges() * 2);
1746 glNewList (anyList_+2, GL_COMPILE);
1752 for (; v_it!=v_end; ++v_it, ++idx, ++vidx)
1754 pickColorBuf_[idx] = _state.pick_get_name_color (vidx);
1755 pickVertexBuf_[idx] = mesh_.point(*v_it);
1761 glDrawArrays(GL_POINTS, 0, mesh_.n_vertices());
1769 if (mesh_.is_trimesh())
1771 for (; f_it!=f_end; ++f_it)
1774 _state.pick_set_name (f_it->idx());
1776 glBegin(GL_TRIANGLES);
1778 fv_it=mesh_.cfv_iter(*f_it);
1779 glVertex(mesh_.point(*fv_it)); ++fv_it;
1780 glVertex(mesh_.point(*fv_it)); ++fv_it;
1787 for (; f_it!=f_end; ++f_it)
1790 _state.pick_set_name (f_it->idx());
1792 glBegin(GL_POLYGON);
1794 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it)
1805 glNewList (anyList_+1, GL_COMPILE);
1811 for (; e_it!=e_end; ++e_it)
1813 _state.pick_set_name (mesh_.n_faces() + e_it->idx());
1815 glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 0))));
1816 glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it, 1))));
1824 glNewList (anyList_+2, GL_COMPILE);
1829 for (; v_it!=v_end; ++v_it, ++vidx)
1831 _state.pick_set_name (vidx);
1843 glCallList (anyList_);
1844 glCallList (anyList_+1);
1845 glCallList (anyList_+2);
1853MeshNodeDeprecatedT<Mesh>::
1854update_pick_buffers ()
1856 unsigned int nfv = 0;
1857 if (mesh_.is_trimesh())
1858 nfv = mesh_.n_faces() * 3;
1863 f_end(mesh_.faces_end());
1865 for (; f_it!=f_end; ++f_it)
1867 for (fv_it=mesh_.cfv_iter(*f_it); fv_it.is_valid(); ++fv_it)
1872 pickVertexBuf_.resize (std::max(mesh_.n_vertices(), std::max(mesh_.n_edges() * 2,
size_t(nfv))));
1873 pickColorBuf_.resize (std::max(mesh_.n_vertices(), std::max(mesh_.n_edges() * 2,
size_t(nfv))));
static void disableClientState(GLenum _cap)
replaces glDisableClientState, supports locking
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
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
static void bindBufferARB(GLenum _target, GLuint _buffer)
same function as bindBuffer
static void bindTexture(GLenum _target, GLuint _buffer)
replaces glBindTexture, supports locking
static void normalPointer(GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glNormalPointer, supports locking
static void enableClientState(GLenum _cap)
replaces glEnableClientState, supports locking
static void depthRange(GLclampd _zNear, GLclampd _zFar)
replaces glDepthRange, supports locking
static void texcoordPointer(GLint _size, GLenum _type, GLsizei _stride, const GLvoid *_pointer)
replaces glTexcoordPointer, supports locking
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
bool is_valid() const
The handle is valid iff the index is not negative.
void reset()
reset handle to be invalid
Kernel::ConstFaceIter ConstFaceIter
Scalar type.
Kernel::ConstFaceHalfedgeIter ConstFaceHalfedgeIter
Circulator.
Kernel::ConstFaceVertexIter ConstFaceVertexIter
Circulator.
Kernel::Normal Normal
Normal type.
Kernel::TexCoord2D TexCoord2D
TexCoord2D type.
Kernel::ConstEdgeIter ConstEdgeIter
Scalar type.
Kernel::ConstVertexIter ConstVertexIter
Scalar type.
Kernel::Point Point
Coordinate type.
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
@ PICK_EDGE
picks edges (may not be implemented for all nodes)
@ PICK_ANYTHING
pick any of the prior targets (should be implemented for all nodes)
@ PICK_FRONT_VERTEX
picks only visible front verices (may not be implemented for all nodes)
@ PICK_FACE
picks faces (should be implemented for all nodes)
@ PICK_VERTEX
picks verices (may not be implemented for all nodes)
@ PICK_FRONT_EDGE
picks only visible front edges (may not be implemented for all nodes)
Namespace providing different geometric functions concerning angles.
void glColor(const Vec3f &_v)
Wrapper: glColor for Vec3f.
void glNormal(const Vec3f &_n)
Wrapper: glNormal for Vec3f.
void glVertex(const Vec2i &_v)
Wrapper: glVertex for Vec2i.