summaryrefslogtreecommitdiff
path: root/src/Contraction/example/Garland_heckbert
diff options
context:
space:
mode:
Diffstat (limited to 'src/Contraction/example/Garland_heckbert')
-rwxr-xr-xsrc/Contraction/example/Garland_heckbert/Error_quadric.h4
-rw-r--r--src/Contraction/example/Garland_heckbert/Garland_heckbert_policies.h115
-rw-r--r--src/Contraction/example/Garland_heckbert/Point.h176
3 files changed, 2 insertions, 293 deletions
diff --git a/src/Contraction/example/Garland_heckbert/Error_quadric.h b/src/Contraction/example/Garland_heckbert/Error_quadric.h
index 7a30c35a..725a3a56 100755
--- a/src/Contraction/example/Garland_heckbert/Error_quadric.h
+++ b/src/Contraction/example/Garland_heckbert/Error_quadric.h
@@ -123,11 +123,11 @@ public :
* Det must be passed with the determinant value of the gradient (should be non zero).
*/
inline Point solve_linear_gradient(double det = grad_determinant()) const{
- return Point(
+ return Point({
(-coeff[1]*coeff[5]*coeff[8]+coeff[1]*coeff[7]*coeff[6]+coeff[2]*coeff[8]*coeff[4]-coeff[2]*coeff[5]*coeff[6]-coeff[3]*coeff[4]*coeff[7]+coeff[3]*coeff[5]*coeff[5])/ det,
(coeff[0]*coeff[5]*coeff[8]-coeff[0]*coeff[7]*coeff[6]-coeff[5]*coeff[2]*coeff[3]-coeff[1]*coeff[2]*coeff[8]+coeff[6]*coeff[2]*coeff[2]+coeff[1]*coeff[3]*coeff[7])/det,
(-coeff[8]*coeff[0]*coeff[4]+coeff[8]*coeff[1]*coeff[1]+coeff[2]*coeff[3]*coeff[4]+coeff[5]*coeff[0]*coeff[6]-coeff[5]*coeff[1]*coeff[3]-coeff[1]*coeff[2]*coeff[6])/det
- );
+ });
}
diff --git a/src/Contraction/example/Garland_heckbert/Garland_heckbert_policies.h b/src/Contraction/example/Garland_heckbert/Garland_heckbert_policies.h
deleted file mode 100644
index c792b5b3..00000000
--- a/src/Contraction/example/Garland_heckbert/Garland_heckbert_policies.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Garland_heckbert_policies.h
- * Created on: Feb 10, 2015
- * This file is part of the Gudhi Library. The Gudhi library
- * (Geometric Understanding in Higher Dimensions) is a generic C++
- * library for computational topology.
- *
- * Author(s): David Salinas
- *
- * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-
-#ifndef GARLAND_HECKBERT_POLICIES_H_
-#define GARLAND_HECKBERT_POLICIES_H_
-
-#include "gudhi/Edge_contraction.h"
-#include "Error_quadric.h"
-
-template<typename EdgeProfile>
-class GH_visitor: public Gudhi::contraction::Contraction_visitor<EdgeProfile> {
- typedef typename EdgeProfile::Complex Complex;
- typedef typename Complex::Point Point;
- Complex& complex_;
-public:
- GH_visitor(Complex& complex):complex_(complex){}
-
-
- void on_started(Complex & complex) override{
- //Compute quadrics for every vertex v
- //The quadric of v consists in the sum of quadric
- //of every triangles passing through v weighted by its area
- for(auto v : complex.vertex_range()){
- auto & quadric_v(complex[v].quadric);
- for(auto t : complex.triangle_range(v)){
- auto t_it = t.begin();
- const auto& p0(complex.point(*t_it++));
- const auto& p1(complex.point(*t_it++));
- const auto& p2(complex.point(*t_it++));
- quadric_v+=Error_quadric<Point>(p0,p1,p2);
- }
- }
- }
-
- /**
- * @brief Called when an edge is about to be contracted and replaced by a vertex whose position is *placement.
- */
- void on_contracting(EdgeProfile const &profile, boost::optional< Point > placement)
- override{
- profile.v0().quadric += profile.v1().quadric;
- }
-};
-
-
-template<typename EdgeProfile>
-class GH_placement : public Gudhi::contraction::Placement_policy<EdgeProfile>{
- typedef typename EdgeProfile::Complex Complex;
- Complex& complex_;
-public:
- typedef typename EdgeProfile::Point Point;
- typedef typename Gudhi::contraction::Placement_policy<EdgeProfile>::Placement_type Placement_type;
-
- GH_placement(Complex& complex):complex_(complex){}
-
- Placement_type operator()(const EdgeProfile& profile) const override{
- auto sum_quad(profile.v0().quadric);
- sum_quad += profile.v1().quadric;
-
- boost::optional<Point> min_quadric_pt(sum_quad.min_cost());
- if (min_quadric_pt)
- return Placement_type(*min_quadric_pt);
- else
- return profile.p0();
- }
-};
-
-template<typename EdgeProfile>
-class GH_cost : public Gudhi::contraction::Cost_policy<EdgeProfile>{
- typedef typename EdgeProfile::Complex Complex;
- Complex& complex_;
-public:
-
- typedef typename Gudhi::contraction::Cost_policy<EdgeProfile>::Cost_type Cost_type;
- typedef typename Complex::Point Point;
-
- GH_cost(Complex& complex):complex_(complex){}
-
- Cost_type operator()( EdgeProfile const& profile, boost::optional<Point> const& new_point ) const override {
- Cost_type res;
- if (new_point){
- auto sum_quad(profile.v0().quadric);
- sum_quad += profile.v1().quadric;
- res = sum_quad.cost(*new_point);
- }
- return res;
- }
-};
-
-
-
-#endif /* GARLAND_HECKBERT_POLICIES_H_ */
diff --git a/src/Contraction/example/Garland_heckbert/Point.h b/src/Contraction/example/Garland_heckbert/Point.h
deleted file mode 100644
index eb250347..00000000
--- a/src/Contraction/example/Garland_heckbert/Point.h
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Basic_geometry.h
- * Created on: Feb 10, 2015
- * This file is part of the Gudhi Library. The Gudhi library
- * (Geometric Understanding in Higher Dimensions) is a generic C++
- * library for computational topology.
- *
- * Author(s): David Salinas
- *
- * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-
-#ifndef BASIC_GEOMETRY_H_
-#define BASIC_GEOMETRY_H_
-
-#include <cmath>
-#include <vector>
-#include <cassert>
-#include <cstddef>
-
-class Point_d{
-public:
- Point_d():coords_(3,0){}
- Point_d(size_t dim):coords_(dim,0){}
- Point_d(const Point_d& other):coords_(other.coords_){}
- Point_d(double x,double y,double z):coords_({x,y,z}){}
-
- template<typename CoordsIt>
- Point_d(CoordsIt begin,CoordsIt end):coords_(begin,end){}
-
- size_t dimension() const{
- return coords_.size();
- }
-
- double x() const{
- return coords_[0];
- }
-
- double y() const{
- return coords_[1];
- }
-
- double z() const{
- return coords_[2];
- }
-
- double& x(){
- return coords_[0];
- }
-
- double& y(){
- return coords_[1];
- }
-
- double& z(){
- return coords_[2];
- }
-
- std::vector<double>::const_iterator begin() const{
- return coords_.begin();
- }
-
- std::vector<double>::const_iterator end() const{
- return coords_.end();
- }
-
- double& operator[](unsigned i){
- return coords_[i];
- }
- const double& operator[](unsigned i) const{
- return coords_[i];
- }
-
- double squared_norm() const{
- double res = 0;
- for(auto x : coords_)
- res+= x*x;
- return res;
- }
-
- double squared_dist(const Point_d& other) const{
- assert(dimension()==other.dimension());
- double res = 0;
- for(unsigned i = 0; i < coords_.size(); ++i)
- res+= coords_[i]*coords_[i] + other[i]*other[i];
- return res;
- }
-
- /**
- * dot product
- */
- double operator*(const Point_d& other) const{
- assert(dimension()==other.dimension());
- double res = 0;
- for(unsigned i = 0; i < coords_.size(); ++i)
- res+= coords_[i]*other[i];
- return res;
- }
-
- /**
- * only if points have dimension 3
- */
- Point_d cross_product(const Point_d& other){
- assert(dimension()==3 && other.dimension()==3);
- Point_d res(3);
- res[0] = (*this)[1] * other[2] - (*this)[2] * other[1];
- res[1] = (*this)[2] * other[0] - (*this)[0] * other[2];
- res[2] = (*this)[0] * other[1] - (*this)[1] * other[0];
- return res;
- }
-
- Point_d operator+(const Point_d& other) const{
- assert(dimension()==other.dimension());
- Point_d res(dimension());
- for(unsigned i = 0; i < coords_.size(); ++i)
- res[i] = (*this)[i] + other[i];
- return res;
- }
-
- Point_d operator*(double lambda) const{
- Point_d res(dimension());
- for(unsigned i = 0; i < coords_.size(); ++i)
- res[i] = (*this)[i] * lambda;
- return res;
- }
-
- Point_d operator/(double lambda) const{
- Point_d res(dimension());
- for(unsigned i = 0; i < coords_.size(); ++i)
- res[i] = (*this)[i] / lambda;
- return res;
- }
-
- Point_d operator-(const Point_d& other) const{
- assert(dimension()==other.dimension());
- Point_d res(dimension());
- for(unsigned i = 0; i < coords_.size(); ++i)
- res[i] = (*this)[i] - other[i];
- return res;
- }
-
- friend Point_d unit_normal(const Point_d& p1,const Point_d& p2,const Point_d& p3){
- assert(p1.dimension()==3);
- assert(p2.dimension()==3);
- assert(p3.dimension()==3);
- Point_d p1p2 = p2 - p1;
- Point_d p1p3 = p3 - p1;
- Point_d res(p1p2.cross_product(p1p3));
- return res / std::sqrt(res.squared_norm());
- }
-
-
-private:
- std::vector<double> coords_;
-};
-
-
-
-
-
-#endif /* BASIC_GEOMETRY_H_ */