53 #define MESHFUNCTIONS_C 59 #include <ACG/Geometry/Algorithms.hh> 60 #include "Math_Tools/Math_Tools.hh" 66 #include <OpenMesh/Core/Geometry/MathDefs.hh> 75 template <
typename MeshT ,
typename VectorT >
77 typename MeshT::VertexHandle _vh,
78 std::vector< std::pair< VectorT , typename MeshT::VertexHandle > >& _boundary)
81 typename MeshT::VertexHandle last = _vh;
82 const typename MeshT::VertexHandle begin = _vh;
84 std::set< typename MeshT::VertexHandle >
set;
92 _boundary.push_back(std::pair< VectorT , typename MeshT::VertexHandle > ( (
VectorT)_mesh.point(_vh) , _vh ) );
95 for (
typename MeshT::VertexOHalfedgeIter vohe_it(_mesh,_vh); vohe_it.is_valid() ; ++vohe_it) {
98 if ( _mesh.is_boundary(*vohe_it) && ( _mesh.to_vertex_handle(*vohe_it) != last ) ) {
100 _vh = _mesh.to_vertex_handle(*vohe_it);
105 }
while (
set.count( _vh ) == 0 );
107 if ( begin != _vh ) {
108 std::cout <<
"Warning in ( GeometryFunctions.cc get_boundary ) : boundary loop may be partial ( start- != endpoint ) " << std::endl;
114 template <
typename MeshT ,
typename VectorT >
116 std::vector< std::pair< VectorT , typename MeshT::VertexHandle > >& _boundary)
118 typename MeshT::VertexHandle vh;
122 for (
typename MeshT::HalfedgeIter he_it=_mesh.halfedges_begin() ; he_it != _mesh.halfedges_end() ; ++he_it) {
123 if ( _mesh.is_boundary(he_it) ) {
124 vh = _mesh.from_vertex_handle(he_it);
133 std::cerr <<
"Did not find Mesh boundary!! ( GeometryFunctions.cc get_boundary )" << std::endl;
138 template <
typename MeshT ,
typename VectorT >
140 typename MeshT::VertexHandle _vh)
142 std::vector< std::pair< VectorT , typename MeshT::VertexHandle > > boundary;
147 for (uint i = 1 ; i <= boundary.size() ; ++i ) {
148 _mesh.point( boundary[ i % boundary.size() ].second ) = ( boundary[ ( i - 1) % boundary.size() ].first
149 + boundary[ ( i ) % boundary.size() ].first * 2.0
150 + boundary[ ( i + 1) % boundary.size() ].first ) * 0.25;
155 template <
typename MeshT >
157 const typename MeshT::FaceHandle& _fh1 ,
158 const typename MeshT::FaceHandle& _fh2 )
160 for (
typename MeshT::FaceFaceIter ff_it(_mesh,_fh1) ; ff_it ; ++ff_it)
167 template <
class MeshT ,
typename VectorT >
172 const typename MeshT::FaceHandle& _fh)
174 typename MeshT::ConstFaceVertexIter fv_it = _mesh.cfv_iter(_fh);
175 const VectorT p0 = _mesh.point( fv_it);
176 const VectorT p1 = _mesh.point(++fv_it);
177 const VectorT p2 = _mesh.point(++fv_it);
179 unsigned int npos(0), nneg(0);
181 if( ACG::Geometry::distPointPlane< VectorT , double >( _porigin, _pnormal, p0) > 0 ) ++npos;
else ++nneg;
182 if( ACG::Geometry::distPointPlane< VectorT , double >( _porigin, _pnormal, p1) > 0 ) ++npos;
else ++nneg;
183 if( ACG::Geometry::distPointPlane< VectorT , double >( _porigin, _pnormal, p2) > 0 ) ++npos;
else ++nneg;
186 if( npos && nneg )
return true;
190 template <
typename MeshT >
195 for (
typename MeshT::ConstFaceIter f_it = _mesh.faces_begin() ; f_it != _mesh.faces_end() ; ++f_it) {
196 typename MeshT::ConstFaceVertexIter fv_it = _mesh.cfv_iter(f_it);
201 area += ((vertex1 - vertex2) % (vertex3-vertex2)).norm();
208 template <
typename MeshT >
214 const typename MeshT::Point p0 = _mesh.point(_vh);
216 typename MeshT::ConstVertexOHalfedgeIter voh_it(_mesh,_vh);
217 typename MeshT::ConstVertexOHalfedgeIter nx_voh_it = voh_it;
221 for ( ; voh_it; ++voh_it , ++nx_voh_it) {
222 const typename MeshT::Point edge_1 = MathTools::sane_normalized( _mesh.point(_mesh.to_vertex_handle(voh_it)) - p0);
223 const typename MeshT::Point edge_2 = MathTools::sane_normalized( (_mesh.point(_mesh.to_vertex_handle(nx_voh_it))) - p0);
230 template<
typename MeshT >
240 typename MeshT::VertexIter v_it = _mesh.vertices_begin();
241 typename MeshT::VertexIter v_end = _mesh.vertices_end();
242 for (; v_it != v_end; ++v_it) {
248 if(_mesh.has_vertex_normals()) {
249 typename MeshT::Normal n = invTranspMat.
transform_vector(_mesh.normal(*v_it));
251 _mesh.set_normal(*v_it, n);
255 typename MeshT::FaceIter f_it = _mesh.faces_begin();
256 typename MeshT::FaceIter f_end = _mesh.faces_end();
257 for (; f_it != f_end; ++f_it) {
260 if(_mesh.has_face_normals()) {
261 typename MeshT::Normal n = invTranspMat.
transform_vector(_mesh.normal(*f_it));
263 _mesh.set_normal(*f_it, n);
268 template<
typename MeshT >
278 typename MeshT::VertexIter v_it = _mesh.vertices_begin();
279 typename MeshT::VertexIter v_end = _mesh.vertices_end();
280 for (; v_it != v_end; ++v_it) {
282 if(!_mesh.status(*v_it).is_bit_set(HANDLEAREA))
continue;
288 if(_mesh.has_vertex_normals()) {
289 typename MeshT::Normal n = invTranspMat.
transform_vector(_mesh.normal(*v_it));
291 _mesh.set_normal(*v_it, n);
296 if(_mesh.has_face_normals()) {
297 _mesh.update_face_normals();
bool invert()
matrix inversion (returns true on success)
bool cut_face(const VectorT &_porigin, const VectorT &_pnormal, const MeshT &_mesh, const typename MeshT::FaceHandle &_fh)
T sane_aarg(T _aarg)
Trigonometry/angles - related.
bool get_boundary(MeshT &_mesh, typename MeshT::VertexHandle _vh, std::vector< std::pair< VectorT, typename MeshT::VertexHandle > > &_boundary)
Namespace providing different Mesh editing functions.
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x',y',z',1) = M * (x,y,z,1)
double calc_angle_around(const MeshT &_mesh, const typename MeshT::VertexHandle &_vh)
void transpose()
transpose matrix
double calc_area(const MeshT &_mesh)
VectorT< double, 3 > Vec3d
bool neighbour(const MeshT &_mesh, const typename MeshT::FaceHandle &_fh1, const typename MeshT::FaceHandle &_fh2)
void smooth_boundary(MeshT &_mesh, typename MeshT::VertexHandle _vh)
void transformMesh(ACG::Matrix4x4d _matrix, MeshT &_mesh)
void transformHandleVertices(ACG::Matrix4x4d _matrix, MeshT &_mesh)
Functions for modifying a Mesh.
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x',y',z',0) = A * (x,y,z,0)