From db712eaf20b239812d5e15feb12785cc73b78509 Mon Sep 17 00:00:00 2001 From: thery Date: Mon, 17 Feb 2014 15:26:05 +0100 Subject: [PATCH] add distances to Algo/Geom --- include/Algo/Geometry/distances.h | 81 ++++++++++++++++++++ include/Algo/Geometry/distances.hpp | 110 ++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 include/Algo/Geometry/distances.h create mode 100644 include/Algo/Geometry/distances.hpp diff --git a/include/Algo/Geometry/distances.h b/include/Algo/Geometry/distances.h new file mode 100644 index 000000000..9cf6b88e8 --- /dev/null +++ b/include/Algo/Geometry/distances.h @@ -0,0 +1,81 @@ +/******************************************************************************* +* 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 diff --git a/include/Algo/Geometry/distances.hpp b/include/Algo/Geometry/distances.hpp new file mode 100644 index 000000000..4b0a357bf --- /dev/null +++ b/include/Algo/Geometry/distances.hpp @@ -0,0 +1,110 @@ +/******************************************************************************* +* 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 + -- GitLab