Commit db712eaf by thery

add distances to Algo/Geom

parent 549167d9
 /******************************************************************************* * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * * version 0.1 * * Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * * * * This library is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published by the * * Free Software Foundation; either version 2.1 of the License, or (at your * * option) any later version. * * * * This library is distributed in the hope that it will be useful, but WITHOUT * * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * * for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this library; if not, write to the Free Software Foundation, * * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * * * Web site: http://cgogn.unistra.fr/ * * Contact information: cgogn@unistra.fr * * * *******************************************************************************/ #ifndef __ALGO_GEOMETRY_DISTANCE_H__ #define __ALGO_GEOMETRY_DISTANCE_H__ namespace CGoGN { namespace Algo { namespace Geometry { /** * compute squared distance from point to the plane of a planar face * @param map the map * @param d a dart of the face * @param P the point * @return the squared distance to tha plane */ template typename PFP::REAL squaredDistancePoint2FacePlane(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const VEC3& P) ; /** * compute squared distance from point to face (assuming face is convex) * Algo: min distance of each subtriangle of face (not optimum ?) * @param map the map * @param d a dart of the face * @param P the point * @return the squared distance */ template typename PFP::REAL squaredDistancePoint2Face(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const VEC3& P) ; /** * compute squared distance from point to an edge * @param map the map * @param d a dart of the edge * @param P the point * @return the squared distance */ template typename PFP::REAL squaredDistancePoint2Edge(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const VEC3& P) ; template bool isPlanar(typename PFP::MAP& map, Dart d, const VertexAttribute& position); } // namespace Geometry } // namespace Algo } // namespace CGoGN #include "Algo/Geometry/distances.hpp" #endif
 /******************************************************************************* * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * * version 0.1 * * Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * * * * This library is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published by the * * Free Software Foundation; either version 2.1 of the License, or (at your * * option) any later version. * * * * This library is distributed in the hope that it will be useful, but WITHOUT * * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * * for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this library; if not, write to the Free Software Foundation, * * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * * * Web site: http://cgogn.unistra.fr/ * * Contact information: cgogn@unistra.fr * * * *******************************************************************************/ #include "Geometry/distances.h" #include "Algo/Geometry/normal.h" #include namespace CGoGN { namespace Algo { namespace Geometry { template bool isPlanar(typename PFP::MAP& map, Dart d, const VertexAttribute& position) { if (map.phi<111>(d)==d) return true; typename PFP::VEC3 No = Algo::Surface::Geometry::triangleNormal(map, d, position) ; Dart e = map.phi<11>(d); while (e != d) { typename PFP::VEC3 n = Algo::Surface::Geometry::triangleNormal(map, e, position) ; e = map.phi1(e); if (e!=d) e = map.phi1(e); } } template typename PFP::REAL squaredDistancePoint2FacePlane(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const VEC3& P) { const typename PFP::VEC3& A = position[d]; d = map.phi1(d); const typename PFP::VEC3& B = position[d]; d = map.phi1(d); const typename PFP::VEC3& C = position[d]; return Geom::squaredDistancePoint2TrianglePlane(P,A,B,C); } template typename PFP::REAL squaredDistancePoint2Face(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const VEC3& P) { typedef typename PFP::REAL REAL; const typename PFP::VEC3& A = position[d]; Dart e = map.phi1(d); Dart f = map.phi1(e); REAL dist2 = Geom::squaredDistancePoint2Triangle(P,A,position[e],position[f]); e = f; f = map.phi1(e); while (f != d) { REAL d2 = Geom::squaredDistancePoint2Triangle(P,A,position[e],position[f]); if (d2 < dist2) dist2 = d2; e = f; f = map.phi1(e); } return dist2; } template typename PFP::REAL squaredDistancePoint2Edge(typename PFP::MAP& map, Dart d, const VertexAttribute& position, const VEC3& P) { const typename PFP::VEC3& A = position[d]; typename PFP::VEC3& AB = position[map.phi1(d)]-A; typename PFP::REAL AB2 = AB*AB; return Geom::squaredDistanceSeg2Point(A,AB,AB2,P) ; } } // namespace Geometry } // namespace Algo } // namespace CGoGN
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment