53 # pragma warning(disable: 4267 4311) 59 #include <QApplication> 63 #include <OpenMesh/Apps/ProgViewer/ProgViewerWidget.hh> 64 #include <OpenMesh/Core/IO/BinaryHelper.hh> 65 #include <OpenMesh/Core/IO/MeshIO.hh> 66 #include <OpenMesh/Core/Utils/Endian.hh> 71 #include <OpenGL/gl.h> 84 unsigned int i, i0, i1, i2;
85 unsigned int v1, vl, vr;
88 std::ifstream ifs(_filename, std::ios::binary);
91 std::cerr <<
"read error\n";
99 ifs.read(c, 8); c[8] =
'\0';
100 if (std::string(c) != std::string(
"ProgMesh"))
102 std::cerr <<
"Wrong file format.\n";
109 n_max_vertices_ = n_base_vertices_ + n_detail_vertices_;
114 for (i=0; i<n_base_vertices_; ++i)
120 for (i=0; i<n_base_faces_; ++i)
125 mesh_.add_face(mesh_.vertex_handle(i0),
126 mesh_.vertex_handle(i1),
127 mesh_.vertex_handle(i2));
132 for (i=0; i<n_detail_vertices_; ++i)
144 pminfos_.push_back(pminfo);
146 pmiter_ = pminfos_.begin();
154 MyMesh::ConstVertexIter
155 vIt(mesh_.vertices_begin()),
156 vEnd(mesh_.vertices_end());
160 bbMin = bbMax = mesh_.point(*vIt);
161 for (; vIt!=vEnd; ++vIt)
163 bbMin.minimize(mesh_.point(*vIt));
164 bbMax.maximize(mesh_.point(*vIt));
168 set_scene_pos(0.5f*(bbMin + bbMax), 0.5*(bbMin - bbMax).norm());
171 std::cerr << mesh_.n_vertices() <<
" vertices, " 172 << mesh_.n_edges() <<
" edge, " 173 << mesh_.n_faces() <<
" faces, " 174 << n_detail_vertices_ <<
" detail vertices\n";
176 setWindowTitle( QFileInfo(_filename).fileName() );
185 size_t n_vertices = mesh_.n_vertices();
187 while (n_vertices < _n && pmiter_ != pminfos_.end())
201 std::cerr << n_vertices <<
" vertices\n";
210 size_t n_vertices = mesh_.n_vertices();
212 while (n_vertices > _n && pmiter_ != pminfos_.begin())
216 MyMesh::HalfedgeHandle hh =
217 mesh_.find_halfedge(pmiter_->v0, pmiter_->v1);
224 mesh_.garbage_collection();
228 std::cerr << n_vertices <<
" vertices\n";
234 void ProgViewerWidget::keyPressEvent(QKeyEvent* _event)
236 switch (_event->key())
239 if ( _event->modifiers() & ShiftModifier)
240 coarsen(mesh_.n_vertices()-1);
242 coarsen((
unsigned int)(0.9*mesh_.n_vertices()));
247 if (_event->modifiers() & ShiftModifier)
248 refine(mesh_.n_vertices()+1);
250 refine((
unsigned int)(std::max( 1.1*mesh_.n_vertices(),
251 mesh_.n_vertices()+1.0) ));
256 coarsen(n_base_vertices_);
261 if (timer_->isActive())
264 std::cout <<
"animation stopped!" << std::endl;
268 timer_->setSingleShot(
true);
270 std::cout <<
"animation started!" << std::endl;
275 refine(n_base_vertices_ + n_detail_vertices_);
281 const size_t refine_max = 100000;
282 const size_t n_loop = 5;
287 coarsen(0); count = mesh_.n_vertices();
288 refine(refine_max); count = mesh_.n_vertices() - count;
291 for (
size_t i=0; i<n_loop; ++i)
298 std::cout <<
"# collapses/splits: " << 2*(n_loop+1)*count <<
" in " 300 std::cout <<
"# collapses or splits per seconds: " 301 << 2*(n_loop+1)*count/t.
seconds() <<
"\n";
313 std::clog <<
"Current mesh stored in 'result.off'\n";
317 this->Base::keyPressEvent(_event);
321 void ProgViewerWidget::animate(
void )
323 if (animateRefinement_)
325 refine((
unsigned int)( 1.1*(mesh_.n_vertices()+1) ));
326 if ( mesh_.n_vertices() > n_base_vertices_+(0.5*n_detail_vertices_))
327 animateRefinement_ =
false;
331 coarsen((
unsigned int)(0.9*(mesh_.n_vertices()-1)));
332 if ( mesh_.n_vertices() == n_base_vertices_ )
333 animateRefinement_ =
true;
336 timer_->setSingleShot(
true);
Little endian (Intel family and clones)
void refine(unsigned int _n)
refine mesh up to _n vertices
void start(void)
Start measurement.
void open_prog_mesh(const char *_filename)
open progressive mesh
void coarsen(unsigned int _n)
coarsen mesh down to _n vertices
double seconds(void) const
Returns measured time in seconds, if the timer is in state 'Stopped'.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
void update_face_normals()
Update normal vectors for all faces.
Kernel::Point Point
Coordinate type.
std::string as_string(Format format=Automatic)
void update_vertex_normals()
Update normal vectors for all vertices.
void stop(void)
Stop measurement.
static Type local()
Return endian type of host system.
bool write_mesh(const Mesh &_mesh, const std::string &_filename, Options _opt=Options::Default, std::streamsize _precision=6)
Write a mesh to the file _filename.
HalfedgeHandle vertex_split(Point _v0_point, VertexHandle _v1, VertexHandle _vl, VertexHandle _vr)
Vertex Split: inverse operation to collapse().