43 #ifndef GEOMETRYKERNEL_HH_ 44 #define GEOMETRYKERNEL_HH_ 49 #include "../Geometry/VectorT.hh" 50 #include "TopologyKernel.hh" 54 template <
class VecT,
class TopologyKernelT = TopologyKernel>
59 typedef TopologyKernelT KernelT;
74 vertices_.push_back(_p);
77 return KernelT::add_vertex();
83 assert(_vh.idx() < (int)vertices_.size());
85 vertices_[_vh.idx()] = _p;
90 return vertices_[_vh.idx()];
94 assert(_h.idx() < (int)TopologyKernelT::n_vertices());
96 VertexIter nV = TopologyKernelT::delete_vertex(_h);
98 if (TopologyKernelT::deferred_deletion_enabled())
103 vertices_.erase(vertices_.begin() + _h.idx());
108 virtual void collect_garbage()
110 if (!TopologyKernelT::needs_garbage_collection())
113 if (TopologyKernelT::fast_deletion_enabled()) {
114 TopologyKernelT::collect_garbage();
117 for (
int i = (
int)vertices_.size(); i > 0; --i)
120 vertices_.erase(vertices_.begin() + (i-1));
122 TopologyKernelT::collect_garbage();
129 assert(_h1.idx() >= 0 && _h1.idx() < (int)vertices_.size());
130 assert(_h2.idx() >= 0 && _h2.idx() < (int)vertices_.size());
135 std::swap(vertices_[_h1.idx()], vertices_[_h2.idx()]);
137 TopologyKernelT::swap_vertex_indices(_h1, _h2);
142 virtual void delete_multiple_vertices(
const std::vector<bool>& _tag) {
144 assert(_tag.size() == TopologyKernelT::n_vertices());
146 std::vector<VecT> newVertices;
148 typename std::vector<VecT>::const_iterator v_it = vertices_.begin();
150 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
151 t_end = _tag.end(); t_it != t_end; ++t_it, ++v_it) {
156 newVertices.push_back(*v_it);
161 vertices_.swap(newVertices);
163 TopologyKernelT::delete_multiple_vertices(_tag);
168 virtual void clear(
bool _clearProps =
true) {
171 TopologyKernelT::clear(_clearProps);
174 typename PointT::value_type length(
const EdgeHandle& _eh)
const {
176 const typename TopologyKernelT::Edge& e = TopologyKernelT::edge(_eh);
177 return (
vertex(e.to_vertex()) -
vertex(e.from_vertex())).length();
182 const typename TopologyKernelT::Edge& e = TopologyKernelT::edge(_eh);
183 return (
vertex(e.to_vertex()) -
vertex(e.from_vertex()));
186 PointT barycenter(
const EdgeHandle& _eh)
const {
187 return PointT(0.5 *
vertex(TopologyKernelT::edge(_eh).from_vertex()) +
188 0.5 *
vertex(TopologyKernelT::edge(_eh).to_vertex()));
191 PointT barycenter(
const FaceHandle& _fh)
const {
192 PointT p(
typename PointT::value_type(0));
193 typename PointT::value_type valence = 0;
195 TopologyKernelT::hfv_iter(TopologyKernelT::halfface_handle(_fh, 0));
196 for(; hfv_it.valid(); ++hfv_it, valence += 1) {
203 PointT barycenter(
const CellHandle& _ch)
const {
204 PointT p(
typename PointT::value_type(0));
205 typename PointT::value_type valence = 0;
207 for(; cv_it.valid(); ++cv_it, valence += 1) {
214 void clone_vertices(std::vector<VecT>& _copy)
const {
216 _copy.reserve(vertices_.size());
217 std::copy(vertices_.begin(), vertices_.end(), std::back_inserter(_copy));
220 void swap_vertices(std::vector<VecT>& _copy) {
221 if(_copy.size() != vertices_.size()) {
222 std::cerr <<
"Vertex vectors differ in size! The size of the copy " <<
223 "is artificially set to the correct one. Some values may not be correctly initialized." << std::endl;
224 _copy.resize(vertices_.size());
226 std::swap(vertices_, _copy);
231 std::vector<VecT> vertices_;
virtual VertexHandle add_vertex()
Override of empty add_vertex function.
GeometryKernel()
Constructor.
const VecT & vertex(const VertexHandle &_vh) const
Get point _vh's coordinates.
VertexHandle add_vertex(const VecT &_p)
Add a geometric point to the mesh.
virtual size_t n_vertices() const
Get number of vertices in mesh.
void set_vertex(const VertexHandle &_vh, const VecT &_p)
Set the coordinates of point _vh.
~GeometryKernel()
Destructor.