59 #define MESHFUNCTIONS_C
65 #include <ACG/Geometry/Algorithms.hh>
66 #include "Math_Tools/Math_Tools.hh"
72 #include <OpenMesh/Core/Geometry/MathDefs.hh>
81 template <
typename MeshT ,
typename VectorT >
83 typename MeshT::VertexHandle _vh,
84 std::vector< std::pair< VectorT , typename MeshT::VertexHandle > >& _boundary)
87 typename MeshT::VertexHandle last = _vh;
88 const typename MeshT::VertexHandle begin = _vh;
90 std::set< typename MeshT::VertexHandle > set;
98 _boundary.push_back(std::pair< VectorT , typename MeshT::VertexHandle > ( (
VectorT)_mesh.point(_vh) , _vh ) );
101 for (
typename MeshT::VertexOHalfedgeIter vohe_it(_mesh,_vh); vohe_it.is_valid() ; ++vohe_it) {
104 if ( _mesh.is_boundary(*vohe_it) && ( _mesh.to_vertex_handle(*vohe_it) != last ) ) {
106 _vh = _mesh.to_vertex_handle(*vohe_it);
111 }
while ( set.count( _vh ) == 0 );
113 if ( begin != _vh ) {
114 std::cout <<
"Warning in ( GeometryFunctions.cc get_boundary ) : boundary loop may be partial ( start- != endpoint ) " << std::endl;
120 template <
typename MeshT ,
typename VectorT >
122 std::vector< std::pair< VectorT , typename MeshT::VertexHandle > >& _boundary)
124 typename MeshT::VertexHandle vh;
128 for (
typename MeshT::HalfedgeIter he_it=_mesh.halfedges_begin() ; he_it != _mesh.halfedges_end() ; ++he_it) {
129 if ( _mesh.is_boundary(he_it) ) {
130 vh = _mesh.from_vertex_handle(he_it);
139 std::cerr <<
"Did not find Mesh boundary!! ( GeometryFunctions.cc get_boundary )" << std::endl;
144 template <
typename MeshT ,
typename VectorT >
146 typename MeshT::VertexHandle _vh)
148 std::vector< std::pair< VectorT , typename MeshT::VertexHandle > > boundary;
153 for (uint i = 1 ; i <= boundary.size() ; ++i ) {
154 _mesh.point( boundary[ i % boundary.size() ].second ) = ( boundary[ ( i - 1) % boundary.size() ].first
155 + boundary[ ( i ) % boundary.size() ].first * 2.0
156 + boundary[ ( i + 1) % boundary.size() ].first ) * 0.25;
161 template <
typename MeshT >
163 const typename MeshT::FaceHandle _fh1 ,
164 const typename MeshT::FaceHandle _fh2 )
166 for (
typename MeshT::FaceFaceIter ff_it(_mesh,_fh1) ; ff_it ; ++ff_it)
173 template <
class MeshT ,
typename VectorT >
178 const typename MeshT::FaceHandle& _fh)
180 typename MeshT::ConstFaceVertexIter fv_it = _mesh.cfv_iter(_fh);
181 const VectorT p0 = _mesh.point( fv_it);
182 const VectorT p1 = _mesh.point(++fv_it);
183 const VectorT p2 = _mesh.point(++fv_it);
185 unsigned int npos(0), nneg(0);
187 if( ACG::Geometry::distPointPlane< VectorT , double >( _porigin, _pnormal, p0) > 0 ) ++npos;
else ++nneg;
188 if( ACG::Geometry::distPointPlane< VectorT , double >( _porigin, _pnormal, p1) > 0 ) ++npos;
else ++nneg;
189 if( ACG::Geometry::distPointPlane< VectorT , double >( _porigin, _pnormal, p2) > 0 ) ++npos;
else ++nneg;
192 if( npos && nneg )
return true;
196 template <
typename MeshT >
201 for (
typename MeshT::ConstFaceIter f_it = _mesh.faces_begin() ; f_it != _mesh.faces_end() ; ++f_it) {
202 typename MeshT::ConstFaceVertexIter fv_it = _mesh.cfv_iter(f_it);
207 area += ((vertex1 - vertex2) % (vertex3-vertex2)).norm();
214 template <
typename MeshT >
220 const typename MeshT::Point p0 = _mesh.point(_vh);
222 typename MeshT::ConstVertexOHalfedgeIter voh_it(_mesh,_vh);
223 typename MeshT::ConstVertexOHalfedgeIter nx_voh_it = voh_it;
227 for ( ; voh_it; ++voh_it , ++nx_voh_it) {
228 const typename MeshT::Point edge_1 = MathTools::sane_normalized( _mesh.point(_mesh.to_vertex_handle(voh_it)) - p0);
229 const typename MeshT::Point edge_2 = MathTools::sane_normalized( (_mesh.point(_mesh.to_vertex_handle(nx_voh_it))) - p0);
236 template<
typename MeshT >
246 typename MeshT::VertexIter v_it = _mesh.vertices_begin();
247 typename MeshT::VertexIter v_end = _mesh.vertices_end();
248 for (; v_it != v_end; ++v_it) {
254 if(_mesh.has_vertex_normals()) {
257 _mesh.set_normal(*v_it, n);
261 typename MeshT::FaceIter f_it = _mesh.faces_begin();
262 typename MeshT::FaceIter f_end = _mesh.faces_end();
263 for (; f_it != f_end; ++f_it) {
266 if(_mesh.has_face_normals()) {
269 _mesh.set_normal(*f_it, n);
274 template<
typename MeshT >
284 typename MeshT::VertexIter v_it = _mesh.vertices_begin();
285 typename MeshT::VertexIter v_end = _mesh.vertices_end();
286 for (; v_it != v_end; ++v_it) {
288 if(!_mesh.status(*v_it).is_bit_set(HANDLEAREA))
continue;
294 if(_mesh.has_vertex_normals()) {
297 _mesh.set_normal(*v_it, n);
302 if(_mesh.has_face_normals()) {
303 _mesh.update_face_normals();
void transformMesh(ACG::Matrix4x4d _matrix, MeshT &_mesh)
void transformHandleVertices(ACG::Matrix4x4d _matrix, MeshT &_mesh)
void smooth_boundary(MeshT &_mesh, typename MeshT::VertexHandle _vh)
bool neighbour(const MeshT &_mesh, const typename MeshT::FaceHandle _fh1, const typename MeshT::FaceHandle _fh2)
VectorT< double, 3 > Vec3d
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x',y',z',0) = A * (x,y,z,0)
Functions for modifying a Mesh.
double calc_angle_around(const MeshT &_mesh, const typename MeshT::VertexHandle _vh)
Namespace providing different Mesh editing functions.
bool get_boundary(MeshT &_mesh, typename MeshT::VertexHandle _vh, std::vector< std::pair< VectorT, typename MeshT::VertexHandle > > &_boundary)
bool cut_face(const VectorT &_porigin, const VectorT &_pnormal, const MeshT &_mesh, const typename MeshT::FaceHandle &_fh)
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x',y',z',1) = M * (x,y,z,1)
Add normals to mesh item (vertices/faces)
double calc_area(const MeshT &_mesh)
void transpose()
transpose matrix
bool invert()
matrix inversion (returns true on success)
T sane_aarg(T _aarg)
Trigonometry/angles - related.