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()];
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 TopologyKernelT::collect_garbage();
112 for (
unsigned int i = vertices_.size(); i > 0; --i)
113 if (TopologyKernelT::is_deleted(VertexHandle(i-1)))
115 vertices_.erase(vertices_.begin() + (i-1));
120 virtual void swap_vertices(VertexHandle _h1, VertexHandle _h2)
122 assert(_h1.idx() >= 0 && _h1.idx() < (int)vertices_.size());
123 assert(_h2.idx() >= 0 && _h2.idx() < (int)vertices_.size());
128 std::swap(vertices_[_h1.idx()], vertices_[_h2.idx()]);
130 TopologyKernelT::swap_vertices(_h1, _h2);
135 virtual void delete_multiple_vertices(
const std::vector<bool>& _tag) {
137 assert(_tag.size() == TopologyKernelT::n_vertices());
139 std::vector<VecT> newVertices;
141 typename std::vector<VecT>::const_iterator v_it = vertices_.begin();
143 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
144 t_end = _tag.end(); t_it != t_end; ++t_it, ++v_it) {
149 newVertices.push_back(*v_it);
154 vertices_.swap(newVertices);
156 TopologyKernelT::delete_multiple_vertices(_tag);
161 virtual void clear(
bool _clearProps =
true) {
164 TopologyKernelT::clear(_clearProps);
167 typename PointT::value_type length(
const EdgeHandle& _eh)
const {
169 const typename TopologyKernelT::Edge& e = TopologyKernelT::edge(_eh);
170 return (
vertex(e.to_vertex()) -
vertex(e.from_vertex())).length();
173 PointT vector(
const EdgeHandle& _eh)
const {
175 const typename TopologyKernelT::Edge& e = TopologyKernelT::edge(_eh);
176 return (
vertex(e.to_vertex()) -
vertex(e.from_vertex()));
179 PointT barycenter(
const EdgeHandle& _eh)
const {
180 return PointT(0.5 *
vertex(TopologyKernelT::edge(_eh).from_vertex()) +
181 0.5 *
vertex(TopologyKernelT::edge(_eh).to_vertex()));
184 PointT barycenter(
const FaceHandle& _fh)
const {
185 PointT p(
typename PointT::value_type(0));
186 typename PointT::value_type valence = 0;
187 HalfFaceVertexIter hfv_it =
188 TopologyKernelT::hfv_iter(TopologyKernelT::halfface_handle(_fh, 0));
189 for(; hfv_it.valid(); ++hfv_it, valence += 1) {
196 PointT barycenter(
const CellHandle& _ch)
const {
197 PointT p(
typename PointT::value_type(0));
198 typename PointT::value_type valence = 0;
199 CellVertexIter cv_it = TopologyKernelT::cv_iter(_ch);
200 for(; cv_it.valid(); ++cv_it, valence += 1) {
207 void clone_vertices(std::vector<VecT>& _copy)
const {
209 _copy.reserve(vertices_.size());
210 std::copy(vertices_.begin(), vertices_.end(), std::back_inserter(_copy));
213 void swap_vertices(std::vector<VecT>& _copy) {
214 if(_copy.size() != vertices_.size()) {
215 std::cerr <<
"Vertex vectors differ in size! The size of the copy " <<
216 "is artificially set to the correct one. Some values may not be correctly initialized." << std::endl;
217 _copy.resize(vertices_.size());
219 std::swap(vertices_, _copy);
224 std::vector<VecT> vertices_;
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.
GeometryKernel()
Constructor.
const VecT & vertex(const VertexHandle &_vh) const
Get point _vh's coordinates.
~GeometryKernel()
Destructor.
virtual VertexHandle add_vertex()
Override of empty add_vertex function.
void set_vertex(const VertexHandle &_vh, const VecT &_p)
Set the coordinates of point _vh.