194 std::vector<Strip> experiments;
195 std::vector< typename Mesh::HalfedgeHandle > h;
196 std::vector< FaceHandles > faces;
197 typename FaceHandles::iterator fh_it, fh_end;
200 for (f_it=mesh_.faces_begin();
true; ) {
203 for (; f_it != f_end; ++f_it)
204 if (!processed(f_it))
break;
212 experiments.resize( mesh_.valence(f_it) );
214 faces.resize(mesh_.valence(f_it));
219 h.push_back( fhalfedge_it.handle() );
222 unsigned int best_length = 0;
223 unsigned int best_idx = 0;
224 for (
unsigned int i = 0; i < mesh_.valence(f_it) ; ++i)
226 buildStripPolyMesh(h[i], experiments[i], faces[i]);
227 const unsigned int length = experiments[i].indexArray.size();
228 if (length > best_length) {
229 best_length = length;
234 for (fh_it=faces[i].begin(), fh_end=faces[i].end(); fh_it!=fh_end; ++fh_it)
235 used(*fh_it) =
false;
240 fh_it = faces[best_idx].begin();
241 fh_end = faces[best_idx].end();
242 for (; fh_it!=fh_end; ++fh_it)
243 processed(*fh_it) =
true;
246 strips_.push_back(experiments[best_idx]);
255 Strip experiments[3];
259 typename FaceHandles::iterator fh_it, fh_end;
262 for (f_it=mesh_.faces_begin();
true; )
265 for (; f_it!=f_end; ++f_it)
266 if (!processed(f_it))
268 if (f_it==f_end)
break;
272 h[0] = mesh_.halfedge_handle(f_it.handle());
273 h[1] = mesh_.next_halfedge_handle(h[0]);
274 h[2] = mesh_.next_halfedge_handle(h[1]);
277 unsigned int best_length = 0;
278 unsigned int best_idx = 0;
280 for (
unsigned int i=0; i<3; ++i)
282 buildStripTriMesh(h[i], experiments[i], faces[i]);
284 const unsigned int length = experiments[i].
indexArray.size();
285 if ( length > best_length)
287 best_length = length;
291 for (fh_it=faces[i].begin(), fh_end=faces[i].end();
292 fh_it!=fh_end; ++fh_it)
293 used(*fh_it) =
false;
298 fh_it = faces[best_idx].begin();
299 fh_end = faces[best_idx].end();
300 for (; fh_it!=fh_end; ++fh_it)
301 processed(*fh_it) =
true;
304 strips_.push_back(experiments[best_idx]);
318 std::list<unsigned int> strip;
319 std::list<typename Mesh::FaceHandle > faceMap;
327 strip.push_back(mesh_.from_vertex_handle(_start_hh).idx());
328 strip.push_back(mesh_.to_vertex_handle(_start_hh).idx());
334 bool textureHandling =
false;
335 if ( mesh_.get_property_handle(textureIndexProperty, textureIndexPropertyName_) ) {
336 textureHandling =
true;
337 _strip.
textureIndex = mesh_.property(textureIndexProperty,mesh_.face_handle(_start_hh));
345 hh_left = hh_right = _start_hh;
350 hh_right = mesh_.prev_halfedge_handle(hh_right);
353 strip.push_back(mesh_.from_vertex_handle(hh_right).idx());
354 faceMap.push_back(mesh_.face_handle(hh_right));
357 if(mesh_.to_vertex_handle(mesh_.next_halfedge_handle(hh_left)) == mesh_.from_vertex_handle(hh_right)) {
360 fh = mesh_.face_handle(hh_left);
361 _faces.push_back(fh);
365 hh_left = hh_right = mesh_.opposite_halfedge_handle(mesh_.next_halfedge_handle(hh_left));
370 if(mesh_.is_boundary(hh_left))
break;
371 fh = mesh_.face_handle(hh_left);
372 if (processed(fh) || used(fh))
break;
375 if ( textureHandling && ( _strip.
textureIndex != mesh_.property(textureIndexProperty,fh ) ) )
break;
381 hh_left = mesh_.next_halfedge_handle(hh_left);
384 strip.push_back(mesh_.to_vertex_handle(hh_left).idx());
385 faceMap.push_back(mesh_.face_handle(hh_left));
388 if(mesh_.to_vertex_handle(mesh_.next_halfedge_handle(hh_left)) == mesh_.from_vertex_handle(hh_right)) {
390 fh = mesh_.face_handle(hh_left);
391 _faces.push_back(fh);
395 hh_left = hh_right = mesh_.opposite_halfedge_handle(mesh_.next_halfedge_handle(hh_left));
400 if(mesh_.is_boundary(hh_left))
break;
401 fh = mesh_.face_handle(hh_left);
402 if (processed(fh) || used(fh))
break;
405 if ( textureHandling && ( _strip.
textureIndex != mesh_.property(textureIndexProperty,fh ) ) )
break;
417 hh_left = hh_right = mesh_.opposite_halfedge_handle(_start_hh);
422 if(mesh_.is_boundary(hh_left))
break;
425 hh_right = mesh_.prev_halfedge_handle(hh_right);
428 strip.push_front(mesh_.from_vertex_handle(hh_right).idx());
429 faceMap.push_front(mesh_.face_handle(hh_right));
433 if(mesh_.to_vertex_handle(mesh_.next_halfedge_handle(hh_left)) == mesh_.from_vertex_handle(hh_right)) {
436 fh = mesh_.face_handle(hh_right);
437 _faces.push_back(fh);
441 hh_left = hh_right = mesh_.opposite_halfedge_handle(mesh_.next_halfedge_handle(hh_left));
443 if(mesh_.is_boundary(hh_left))
break;
444 fh = mesh_.face_handle(hh_left);
445 if (processed(fh) || used(fh))
break;
448 if ( textureHandling && ( _strip.
textureIndex != mesh_.property(textureIndexProperty,fh ) ) )
break;
458 hh_left = mesh_.next_halfedge_handle(hh_left);
461 strip.push_front( mesh_.to_vertex_handle(hh_left).idx() );
462 faceMap.push_front( mesh_.face_handle(hh_left) );
466 if(mesh_.to_vertex_handle(mesh_.next_halfedge_handle(hh_left)) == mesh_.from_vertex_handle(hh_right)) {
469 fh = mesh_.face_handle(hh_right);
470 _faces.push_back(fh);
474 hh_left = hh_right = mesh_.opposite_halfedge_handle(mesh_.next_halfedge_handle(hh_left));
476 if(mesh_.is_boundary(hh_left))
break;
477 fh = mesh_.face_handle(hh_left);
478 if (processed(fh) || used(fh))
break;
481 if ( textureHandling && ( _strip.
textureIndex != mesh_.property(textureIndexProperty,fh ) ) )
break;
490 strip.push_front(strip.front());
491 faceMap.push_front(mesh_.face_handle(0));
495 faceMap.push_front(mesh_.face_handle(0));
496 faceMap.push_front(mesh_.face_handle(0));
501 std::copy(strip.begin(), strip.end(), std::back_inserter(_strip.
indexArray));
504 _strip.
faceMap.reserve(strip.size());
505 std::copy(faceMap.begin(), faceMap.end(), std::back_inserter(_strip.
faceMap));
519 std::list<unsigned int> strip;
523 std::list<typename Mesh::FaceHandle > faceMap;
531 strip.push_back(mesh_.from_vertex_handle(_start_hh).idx());
532 strip.push_back(mesh_.to_vertex_handle(_start_hh).idx());
537 bool textureHandling =
false;
539 if ( mesh_.get_property_handle(textureIndexProperty, textureIndexPropertyName_) ) {
540 textureHandling =
true;
541 _strip.
textureIndex = mesh_.property(textureIndexProperty,mesh_.face_handle(_start_hh));
551 hh = mesh_.prev_halfedge_handle(mesh_.opposite_halfedge_handle(_start_hh));
555 hh = mesh_.next_halfedge_handle(hh);
556 hh = mesh_.opposite_halfedge_handle(hh);
557 hh = mesh_.next_halfedge_handle(hh);
558 if (mesh_.is_boundary(hh))
break;
559 fh = mesh_.face_handle(hh);
560 if (processed(fh) || used(fh))
break;
563 if ( textureHandling && ( _strip.
textureIndex != mesh_.property(textureIndexProperty,fh ) ) )
break;
565 _faces.push_back(fh);
567 strip.push_back(mesh_.to_vertex_handle(hh).idx());
568 faceMap.push_back(mesh_.face_handle(hh));
571 hh = mesh_.opposite_halfedge_handle(hh);
572 hh = mesh_.next_halfedge_handle(hh);
573 if (mesh_.is_boundary(hh))
break;
574 fh = mesh_.face_handle(hh);
575 if (processed(fh) || used(fh))
break;
578 if ( textureHandling && ( _strip.
textureIndex != mesh_.property(textureIndexProperty,fh ) ) )
break;
580 _faces.push_back(fh);
582 strip.push_back(mesh_.to_vertex_handle(hh).idx());
583 faceMap.push_back(mesh_.face_handle(hh));
589 hh = mesh_.prev_halfedge_handle(_start_hh);
593 hh = mesh_.next_halfedge_handle(hh);
594 hh = mesh_.opposite_halfedge_handle(hh);
595 hh = mesh_.next_halfedge_handle(hh);
596 if (mesh_.is_boundary(hh))
break;
597 fh = mesh_.face_handle(hh);
598 if (processed(fh) || used(fh))
break;
601 if ( textureHandling && ( _strip.
textureIndex != mesh_.property(textureIndexProperty,fh ) ) )
break;
603 _faces.push_back(fh);
605 strip.push_front(mesh_.to_vertex_handle(hh).idx());
606 faceMap.push_front(mesh_.face_handle(hh));
610 hh = mesh_.opposite_halfedge_handle(hh);
611 hh = mesh_.next_halfedge_handle(hh);
612 if (mesh_.is_boundary(hh))
break;
613 fh = mesh_.face_handle(hh);
614 if (processed(fh) || used(fh))
break;
617 if ( textureHandling && ( _strip.
textureIndex != mesh_.property(textureIndexProperty,fh ) ) )
break;
619 _faces.push_back(fh);
621 strip.push_front(mesh_.to_vertex_handle(hh).idx());
622 faceMap.push_front(mesh_.face_handle(hh));
627 strip.push_front(strip.front());
628 faceMap.push_front(mesh_.face_handle(0));
633 faceMap.push_front(mesh_.face_handle(0));
634 faceMap.push_front(mesh_.face_handle(0));
639 std::copy(strip.begin(), strip.end(), std::back_inserter(_strip.
indexArray));
642 _strip.
faceMap.reserve(strip.size());
643 std::copy(faceMap.begin(), faceMap.end(), std::back_inserter(_strip.
faceMap));
748 if (!updatePerEdgeBuffers_)
751 perEdgeVertexBuffer_.resize(mesh_.n_edges() * 2);
753 if ( mesh_.has_edge_colors() ) {
754 perEdgeColorBuffer_.resize(mesh_.n_edges() * 2);
756 perEdgeColorBuffer_.clear();
758 unsigned int idx = 0;
761 for (; e_it!=e_end; ++e_it) {
763 perEdgeVertexBuffer_[idx] = mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it, 0)));
764 perEdgeVertexBuffer_[idx+1] = mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it, 1)));
766 if ( mesh_.has_edge_colors() ) {
767 const Vec4f color = OpenMesh::color_cast<Vec4f>( mesh_.color(e_it) ) ;
768 perEdgeColorBuffer_[ idx ] = color;
769 perEdgeColorBuffer_[ idx + 1 ] = color;
775 updatePerEdgeBuffers_ =
false;
805 if (!updatePerHalfedgeBuffers_)
808 perHalfedgeVertexBuffer_.resize(mesh_.n_halfedges() * 2);
810 if ( mesh_.has_halfedge_colors() ) {
811 perHalfedgeColorBuffer_.resize(mesh_.n_halfedges() * 2);
813 perHalfedgeColorBuffer_.clear();
815 unsigned int idx = 0;
818 for (; he_it!=he_end; ++he_it) {
820 perHalfedgeVertexBuffer_[idx] = halfedge_point(he_it);
821 perHalfedgeVertexBuffer_[idx+1] = halfedge_point(mesh_.prev_halfedge_handle(he_it));
823 if ( mesh_.has_halfedge_colors() ) {
824 const Vec4f color = OpenMesh::color_cast<Vec4f>( mesh_.color(he_it) ) ;
825 perHalfedgeColorBuffer_[ idx ] = color;
826 perHalfedgeColorBuffer_[ idx + 1 ] = color;
832 updatePerHalfedgeBuffers_ =
false;
893 if (!updatePerFaceBuffers_)
899 const bool usePerFaceTextureCoordinateProperty = mesh_.get_property_handle(perFaceTextureCoordinateProperty,perFaceTextureCoordinatePropertyName_);
901 const bool usePerFaceTextureIndex = perFaceTextureIndexAvailable();
903 unsigned int n_faces = 0;
907 for(StripsIterator it = strips_.begin(); it != strips_.end(); ++it)
908 n_faces += (*it).indexArray.size() - 2;
911 perFaceVertexBuffer_.resize(n_faces * 3);
914 unsigned int bufferIndex = 0;
916 if ( mesh_.has_face_normals() )
917 perFaceNormalBuffer_.resize(n_faces * 3);
919 perFaceNormalBuffer_.clear();
921 if ( mesh_.has_vertex_normals() )
922 perFacePerVertexNormalBuffer_.resize(n_faces * 3);
924 perFacePerVertexNormalBuffer_.clear();
926 if ( mesh_.has_face_colors() )
927 perFaceColorBuffer_.resize(n_faces * 3);
929 perFaceColorBuffer_.clear();
931 if ( usePerFaceTextureCoordinateProperty )
932 perFaceTextureCoordArray_.resize(n_faces * 3);
934 perFaceTextureCoordArray_.clear();
936 textureRenderData_.clear();
938 if ( usePerFaceTextureIndex )
939 textureRenderData_.reserve( strips_.size() );
942 for (
unsigned int i = 0 ; i < strips_.size() ; ++i ) {
946 if ( usePerFaceTextureIndex ) {
947 textureRenderData_.push_back(
TextureRenderInfo(strips_[i].textureIndex , strips_[ i ].indexArray.size() -2 ,bufferIndex) );
959 for (
unsigned int stripIndex = 2 ; stripIndex < strips_[ i ].indexArray.size() ; ++stripIndex) {
961 if ( mesh_.has_face_normals() ) {
962 const Vec3d normal = mesh_.normal( strips_[ i ].faceMap[ stripIndex ] );
963 perFaceNormalBuffer_[ bufferIndex + 0 ] = normal;
964 perFaceNormalBuffer_[ bufferIndex + 1 ] = normal;
965 perFaceNormalBuffer_[ bufferIndex + 2 ] = normal;
968 if ( mesh_.has_face_colors() ) {
969 const Vec4f color = OpenMesh::color_cast<Vec4f>( mesh_.color( strips_[ i ].faceMap[ stripIndex ] ) );
970 perFaceColorBuffer_[ bufferIndex + 0 ] = color;
971 perFaceColorBuffer_[ bufferIndex + 1 ] = color;
972 perFaceColorBuffer_[ bufferIndex + 2 ] = color;
977 perFaceVertexBuffer_[ bufferIndex + 0 ] = mesh_.point(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 2 ] ));
978 perFaceVertexBuffer_[ bufferIndex + 1 ] = mesh_.point(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 1 ] ));
979 perFaceVertexBuffer_[ bufferIndex + 2 ] = mesh_.point(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 0 ] ));
982 if ( mesh_.has_vertex_normals() ) {
983 perFacePerVertexNormalBuffer_[ bufferIndex + 0 ] = mesh_.normal(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 2 ] ));
984 perFacePerVertexNormalBuffer_[ bufferIndex + 1 ] = mesh_.normal(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 1 ] ));
985 perFacePerVertexNormalBuffer_[ bufferIndex + 2 ] = mesh_.normal(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 0 ] ));
989 if ( usePerFaceTextureCoordinateProperty ) {
992 for ( ; fhe_it ; ++fhe_it ) {
994 Vec2f texcoord = mesh_.property(perFaceTextureCoordinateProperty,fhe_it);
996 if ( mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 2 ] ) == cvh ) {
997 perFaceTextureCoordArray_[ bufferIndex + 0 ] = texcoord;
999 }
else if ( mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 1 ] ) == cvh ) {
1000 perFaceTextureCoordArray_[ bufferIndex + 1 ] = texcoord;
1002 }
else if ( mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 0 ] ) == cvh ) {
1003 perFaceTextureCoordArray_[ bufferIndex + 2 ] = texcoord;
1013 perFaceVertexBuffer_[ bufferIndex + 2 ] = mesh_.point(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 2 ] ));
1014 perFaceVertexBuffer_[ bufferIndex + 1 ] = mesh_.point(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 1 ] ));
1015 perFaceVertexBuffer_[ bufferIndex + 0 ] = mesh_.point(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 0 ] ));
1018 if ( mesh_.has_vertex_normals() ) {
1019 perFacePerVertexNormalBuffer_[ bufferIndex + 2 ] = mesh_.normal(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 2 ] ));
1020 perFacePerVertexNormalBuffer_[ bufferIndex + 1 ] = mesh_.normal(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 1 ] ));
1021 perFacePerVertexNormalBuffer_[ bufferIndex + 0 ] = mesh_.normal(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 0 ] ));
1024 if ( usePerFaceTextureCoordinateProperty ) {
1027 for ( ; fhe_it ; ++fhe_it ) {
1029 const Vec2f texcoord = mesh_.property(perFaceTextureCoordinateProperty,fhe_it);
1031 if ( mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 2 ] ) == cvh ) {
1032 perFaceTextureCoordArray_[ bufferIndex + 2 ] = texcoord;
1034 }
else if ( mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 1 ] ) == cvh ) {
1035 perFaceTextureCoordArray_[ bufferIndex + 1 ] = texcoord;
1037 }
else if ( mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 0 ] ) == cvh ) {
1038 perFaceTextureCoordArray_[ bufferIndex + 0 ] = texcoord;
1052 updatePerFaceBuffers_ =
false;