
* mln/geom/complex_geometry.hh (mln::geom::complex_geometry<D, P>::reserve): New. Use it... * mln/io/off/load.hh: ...here. Aesthetic changes. --- milena/ChangeLog | 10 ++++++++++ milena/mln/geom/complex_geometry.hh | 17 +++++++++++++++-- milena/mln/io/off/load.hh | 30 +++++++++++++++--------------- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 4697665..b1288ef 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,13 @@ +2011-03-01 Roland Levillain <roland@lrde.epita.fr> + + Add a pre-allocation routine to mln::geom::complex_geometry. + + * mln/geom/complex_geometry.hh + (mln::geom::complex_geometry<D, P>::reserve): New. + Use it... + * mln/io/off/load.hh: ...here. + Aesthetic changes. + 2010-07-28 Roland Levillain <roland@lrde.epita.fr> Regen Milena's Makefile helpers. diff --git a/milena/mln/geom/complex_geometry.hh b/milena/mln/geom/complex_geometry.hh index f1c604c..7ca99f8 100644 --- a/milena/mln/geom/complex_geometry.hh +++ b/milena/mln/geom/complex_geometry.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2008, 2009, 2011 EPITA Research and Development +// Laboratory (LRDE) // // This file is part of Olena. // @@ -43,7 +44,7 @@ /* FIXME: Also provide functors where the locations are computed using - a function (useful for a complex on a regular grid/support. */ + a function (useful for a complex on a regular grid/support). */ /* FIXME: This class could probably be turned into something more generic, usable for other other purpose, e.g. attaching sites to @@ -106,6 +107,9 @@ namespace mln /// Retrieve the site associated to \a f. site operator()(const mln::topo::face<D>& f) const; + /// Pre-allocate memory. + void reserve(size_t n); + private: mln::util::tracked_ptr< internal::complex_geometry_data<P> > data_; }; @@ -170,6 +174,15 @@ namespace mln return s; } + template <unsigned D, typename P> + inline + void + complex_geometry<D, P>::reserve(size_t n) + { + mln_precondition(data_); + data_->zero_faces_geom.reserve(n); + } + # endif // ! MLN_INCLUDE_ONLY } // end of mln::geom diff --git a/milena/mln/io/off/load.hh b/milena/mln/io/off/load.hh index c9c4af7..e66ae28 100644 --- a/milena/mln/io/off/load.hh +++ b/milena/mln/io/off/load.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2008, 2009, 2011 EPITA Research and Development +// Laboratory (LRDE) // // This file is part of Olena. // @@ -296,17 +297,17 @@ namespace mln /* ``The vertices are listed with x, y, z coordinates, written one per line.'' */ - /* FIXME: We should have a faster way to create a bunch of - 0-faces (vertices). */ - for (unsigned v = 0; v < nvertices; ++v) - c.add_face(); - typedef point3df P; typedef mln_coord_(P) C; typedef geom::complex_geometry<D, P> G; G geom; + geom.reserve(nvertices); for (unsigned v = 0; v < nvertices; ++v) { + // Create a 0-face. + c.add_face(); + + // Record the geometry (point) associated to this vertex. C x, y, z; istr >> &self::eat_comment >> x >> &self::eat_comment >> y @@ -346,10 +347,10 @@ namespace mln topo::n_faces_set<1, D> face_edges_set; face_edges_set.reserve(nface_vertices); - // The first vertex id of the face. + // Remember the first vertex id of the face. unsigned first_vertex_id; istr >> &self::eat_comment >> first_vertex_id; - // The current vertex id initialized with the first id. + // The current vertex id, initialized with the first id. unsigned vertex_id = first_vertex_id; if (first_vertex_id >= nvertices) { @@ -366,7 +367,7 @@ namespace mln mesh/complex. */ unsigned next_vertex_id; /* When V is the id of the last vertex of the face F, - set next_vertex_id to first_vertex_id; otherwise, + set NEXT_VERTEX_ID to FIRST_VERTEX_ID; otherwise, read it from the input. */ if (v == nface_vertices - 1) next_vertex_id = first_vertex_id; @@ -376,7 +377,7 @@ namespace mln if (next_vertex_id >= nvertices) { std::cerr << me << ": `" << filename - << "': invalid vertex id " + << "': invalid vertex id: " << next_vertex_id << std::endl; std::exit(1); } @@ -386,15 +387,14 @@ namespace mln topo::n_face<0, D> next_vertex(c, next_vertex_id); // The current edge. topo::algebraic_n_face<1, D> edge; - // If the edge has been constructed yet, create it; - // otherwise, retrieve its id from the complex. + // If the edge has not been constructed yet, create + // it; otherwise, retrieve its id from the complex. if (!complex_edges[vertex_id][next_vertex_id]) { complex_edges[vertex_id][next_vertex_id] = true; complex_edges[next_vertex_id][vertex_id] = true; edge = - make_algebraic_n_face(c.add_face(vertex - - next_vertex), + make_algebraic_n_face(c.add_face(vertex - next_vertex), true); } else @@ -422,7 +422,7 @@ namespace mln // Site set. domain s(c, geom); - // Values + // Values. values vs; exact(this)->assign(vs, s); -- 1.5.6.5