35 #ifndef GEOMETRYKERNEL_HH_ 36 #define GEOMETRYKERNEL_HH_ 41 #include "../Geometry/VectorT.hh" 42 #include "TopologyKernel.hh" 46 template <
class VecT,
class TopologyKernelT = TopologyKernel>
51 typedef TopologyKernelT KernelT;
59 template<
class OtherTopoKernel>
61 TopologyKernelT::assign(other);
62 other->clone_vertices(vertices_);
72 vertices_.push_back(_p);
75 return KernelT::add_vertex();
81 assert(_vh.idx() < (int)vertices_.size());
83 vertices_[_vh.idx()] = _p;
88 return vertices_[_vh.idx()];
92 assert(_h.idx() < (int)TopologyKernelT::n_vertices());
94 VertexIter nV = TopologyKernelT::delete_vertex(_h);
96 if (TopologyKernelT::deferred_deletion_enabled())
101 vertices_.erase(vertices_.begin() + _h.idx());
106 void collect_garbage()
override 108 if (!TopologyKernelT::needs_garbage_collection())
111 if (TopologyKernelT::fast_deletion_enabled()) {
112 TopologyKernelT::collect_garbage();
115 for (
int i = (
int)vertices_.size(); i > 0; --i)
118 vertices_.erase(vertices_.begin() + (i-1));
120 TopologyKernelT::collect_garbage();
127 assert(_h1.idx() >= 0 && _h1.idx() < (int)vertices_.size());
128 assert(_h2.idx() >= 0 && _h2.idx() < (int)vertices_.size());
133 std::swap(vertices_[_h1.idx()], vertices_[_h2.idx()]);
135 TopologyKernelT::swap_vertex_indices(_h1, _h2);
140 void delete_multiple_vertices(
const std::vector<bool>& _tag)
override{
142 assert(_tag.size() == TopologyKernelT::n_vertices());
144 std::vector<VecT> newVertices;
146 typename std::vector<VecT>::const_iterator v_it = vertices_.begin();
148 for(std::vector<bool>::const_iterator t_it = _tag.begin(),
149 t_end = _tag.end(); t_it != t_end; ++t_it, ++v_it) {
154 newVertices.push_back(*v_it);
159 vertices_.swap(newVertices);
161 TopologyKernelT::delete_multiple_vertices(_tag);
166 void clear(
bool _clearProps =
true)
override {
169 TopologyKernelT::clear(_clearProps);
172 typename PointT::value_type length(
const HalfEdgeHandle& _heh)
const {
173 return vector(_heh).length();
176 typename PointT::value_type length(
const EdgeHandle& _eh)
const {
177 return vector(_eh).length();
182 const typename TopologyKernelT::Edge& e = TopologyKernelT::halfedge(_heh);
183 return (
vertex(e.to_vertex()) -
vertex(e.from_vertex()));
188 const typename TopologyKernelT::Edge& e = TopologyKernelT::edge(_eh);
189 return (
vertex(e.to_vertex()) -
vertex(e.from_vertex()));
192 PointT barycenter(
const EdgeHandle& _eh)
const {
193 return PointT(0.5 *
vertex(TopologyKernelT::edge(_eh).from_vertex()) +
194 0.5 *
vertex(TopologyKernelT::edge(_eh).to_vertex()));
197 PointT barycenter(
const FaceHandle& _fh)
const {
198 PointT p(
typename PointT::value_type(0));
199 typename PointT::value_type valence = 0;
201 TopologyKernelT::hfv_iter(TopologyKernelT::halfface_handle(_fh, 0));
202 for(; hfv_it.valid(); ++hfv_it, valence += 1) {
209 PointT barycenter(
const CellHandle& _ch)
const {
210 PointT p(
typename PointT::value_type(0));
211 typename PointT::value_type valence = 0;
213 for(; cv_it.valid(); ++cv_it, valence += 1) {
220 void clone_vertices(std::vector<VecT>& _copy)
const {
222 _copy.reserve(vertices_.size());
223 std::copy(vertices_.begin(), vertices_.end(), std::back_inserter(_copy));
226 void swap_vertices(std::vector<VecT>& _copy) {
227 if(_copy.size() != vertices_.size()) {
228 std::cerr <<
"Vertex vectors differ in size! The size of the copy " <<
229 "is artificially set to the correct one. Some values may not be correctly initialized." << std::endl;
230 _copy.resize(vertices_.size());
232 std::swap(vertices_, _copy);
237 std::vector<VecT> vertices_;
VertexHandle add_vertex(const VecT &_p)
Add a geometric point to the mesh.
GeometryKernel()=default
Constructor.
~GeometryKernel() override=default
Destructor.
size_t n_vertices() const override
Get number of vertices in mesh.
void set_vertex(const VertexHandle &_vh, const VecT &_p)
Set the coordinates of point _vh.
const VecT & vertex(const VertexHandle &_vh) const
Get point _vh's coordinates.
VertexHandle add_vertex() override
Override of empty add_vertex function.