40#include <OpenVolumeMesh/Geometry/VectorT.hh>
41#include <OpenVolumeMesh/Core/TopologyKernel.hh>
43namespace OpenVolumeMesh {
47using GeometryKernelT = PropertyPtr<VecT, Entity::Vertex>;
49template <
class VecT,
class TopologyKernelT = TopologyKernel>
55 using KernelT = TopologyKernelT;
57 template<
typename OtherVec,
typename OtherTopo>
62 , position_{make_prop()}
66 : TopologyKernelT(other)
67 , position_{make_prop()}
69 std::copy(other.position_.begin(), other.position_.end(),
82 return this->
template operator=<TopologyKernelT>(other);
90 template<
typename OtherTopoKernelT>
94 TopologyKernel::operator=(
static_cast<TopologyKernel const&
>(other));
97 position_ = make_prop();
100 std::copy(other.position_.begin(), other.position_.end(),
108 using TopologyKernelT::add_vertex;
112 VH vh = TopologyKernelT::add_vertex();
121 assert(_vh.idx() < (
int)position_.size());
128 return position_[_vh];
131 void swap_vertices(std::vector<VecT> &_other) {
132 position_.swap(_other);
137 typename PointT::value_type length(HalfEdgeHandle _heh)
const {
138 return vector(_heh).length();
141 typename PointT::value_type length(EdgeHandle _eh)
const {
142 return vector(_eh).length();
145 PointT vector(HalfEdgeHandle _heh)
const {
147 const typename TopologyKernelT::Edge& e = TopologyKernelT::halfedge(_heh);
148 return (
vertex(e.to_vertex()) -
vertex(e.from_vertex()));
151 PointT vector(EdgeHandle _eh)
const {
153 const typename TopologyKernelT::Edge& e = TopologyKernelT::edge(_eh);
154 return (
vertex(e.to_vertex()) -
vertex(e.from_vertex()));
157 PointT barycenter(EdgeHandle _eh)
const {
158 return PointT(0.5 *
vertex(TopologyKernelT::edge(_eh).from_vertex()) +
159 0.5 *
vertex(TopologyKernelT::edge(_eh).to_vertex()));
162 PointT barycenter(FaceHandle _fh)
const {
163 PointT p(
typename PointT::value_type(0));
164 typename PointT::value_type
valence = 0;
165 HalfFaceVertexIter hfv_it =
166 TopologyKernelT::hfv_iter(TopologyKernelT::halfface_handle(_fh, 0));
167 for(; hfv_it.valid(); ++hfv_it,
valence += 1) {
174 PointT barycenter(CellHandle _ch)
const {
175 PointT p(
typename PointT::value_type(0));
176 typename PointT::value_type
valence = 0;
177 CellVertexIter cv_it = TopologyKernelT::cv_iter(_ch);
178 for(; cv_it.valid(); ++cv_it,
valence += 1) {
189 if(TopologyKernelT::halfface(_hfh).halfedges().size() < 3) {
190 std::cerr <<
"Warning: Degenerate face: "
191 << TopologyKernelT::face_handle(_hfh) << std::endl;
192 return PointT {0.0, 0.0, 0.0};
195 const std::vector<HalfEdgeHandle>& halfedges = TopologyKernelT::halfface(_hfh).halfedges();
196 std::vector<HalfEdgeHandle>::const_iterator he_it = halfedges.begin();
198 const PointT &p1 =
vertex(TopologyKernelT::halfedge(*he_it).from_vertex());
199 const PointT &p2 =
vertex(TopologyKernelT::halfedge(*he_it).to_vertex());
201 const PointT &p3 =
vertex(TopologyKernelT::halfedge(*he_it).to_vertex());
203 const PointT
n = (p2 - p1).cross(p3 - p2);
204 return n.normalized();
208 GeometryKernelT<VecT> & vertex_positions() & {
return position_;}
211 GeometryKernelT<VecT> get_prop() {
212 auto prop = this->
template get_property<VecT, Entity::Vertex>(
"ovm:position");
213 assert(prop.has_value());
216 GeometryKernelT<VecT> make_prop() {
217 auto prop = this->
template create_shared_property<VecT, Entity::Vertex>(
"ovm:position", VecT(0));
218 assert(prop.has_value());
223 GeometryKernelT<VecT> position_;
VertexHandle add_vertex(const VecT &_p)
Add a geometric point to the mesh.
void set_vertex(VertexHandle _vh, const VecT &_p)
Set the coordinates of point _vh.
const VecT & vertex(VertexHandle _vh) const
Get point _vh's coordinates.
PointT normal(HalfFaceHandle _hfh) const
GeometryKernel operator=(GeometryKernel< VecT, OtherTopoKernelT > const &other)
size_t n() const
Get number of entities of given kind in mesh.
size_t valence(VertexHandle _vh) const
Get valence of vertex (number of incident edges)