-- cgit v1.2.3 From 3fcbf94481bced31a342f6accec015d8d057a38b Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 7 Apr 2015 09:43:15 +0000 Subject: Fix windows errors git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/windowsbuildfix@543 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 267a1f3345b26d72c3722024fa1769dd41b6075b --- src/Bottleneck/include/gudhi/Persistence_diagrams_graph.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Bottleneck/include/gudhi/Persistence_diagrams_graph.h b/src/Bottleneck/include/gudhi/Persistence_diagrams_graph.h index 7e278209..a430fb4c 100644 --- a/src/Bottleneck/include/gudhi/Persistence_diagrams_graph.h +++ b/src/Bottleneck/include/gudhi/Persistence_diagrams_graph.h @@ -33,9 +33,6 @@ namespace Gudhi { namespace bottleneck { -// Diagram_point is the type of the persistence diagram's points -typedef typename std::pair Diagram_point; - // Return the used index for encoding none of the points int null_point_index(); @@ -44,6 +41,9 @@ int null_point_index(); class Persistence_diagrams_graph { public: + // Diagram_point is the type of the persistence diagram's points + typedef typename std::pair Diagram_point; + // Persistence_diagram1 and 2 are the types of any externals representations of persistence diagrams. // They have to have an iterator over points, which have to have fields first (for birth) and second (for death). template @@ -81,7 +81,7 @@ Persistence_diagrams_graph::Persistence_diagrams_graph(Persistence_diagram1& dia swap(u, v); } -Persistence_diagrams_graph::Persistence_diagrams_graph::Persistence_diagrams_graph() +Persistence_diagrams_graph::Persistence_diagrams_graph() : u(), v() { } inline bool Persistence_diagrams_graph::on_the_u_diagonal(int u_point_index) const { @@ -124,7 +124,7 @@ inline std::vector* Persistence_diagrams_graph::sorted_distances() { return new std::vector(sorted_distances.cbegin(), sorted_distances.cend()); } -inline Diagram_point Persistence_diagrams_graph::get_u_point(int u_point_index) const { +inline Persistence_diagrams_graph::Diagram_point Persistence_diagrams_graph::get_u_point(int u_point_index) const { if (!on_the_u_diagonal(u_point_index)) return u.at(u_point_index); Diagram_point projector = v.at(corresponding_point_in_v(u_point_index)); @@ -132,7 +132,7 @@ inline Diagram_point Persistence_diagrams_graph::get_u_point(int u_point_index) return Diagram_point(x, x); } -inline Diagram_point Persistence_diagrams_graph::get_v_point(int v_point_index) const { +inline Persistence_diagrams_graph::Diagram_point Persistence_diagrams_graph::get_v_point(int v_point_index) const { if (!on_the_v_diagonal(v_point_index)) return v.at(v_point_index); Diagram_point projector = u.at(corresponding_point_in_u(v_point_index)); -- cgit v1.2.3 From 796945fff0a49073d28a56400390594e5ba2371b Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 7 Apr 2015 12:38:11 +0000 Subject: Visual Studio errors fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/windowsbuildfix@545 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 86d04c258c64775217833a0fc5a76c53d5f7aaee --- .../include/gudhi/Persistence_diagrams_graph.h | 12 +- src/Contraction/example/Garland_heckbert.cpp | 207 ++++++++++----------- 2 files changed, 109 insertions(+), 110 deletions(-) diff --git a/src/Bottleneck/include/gudhi/Persistence_diagrams_graph.h b/src/Bottleneck/include/gudhi/Persistence_diagrams_graph.h index a430fb4c..73ad940b 100644 --- a/src/Bottleneck/include/gudhi/Persistence_diagrams_graph.h +++ b/src/Bottleneck/include/gudhi/Persistence_diagrams_graph.h @@ -33,6 +33,9 @@ namespace Gudhi { namespace bottleneck { +// Diagram_point is the type of the persistence diagram's points +typedef std::pair Diagram_point; + // Return the used index for encoding none of the points int null_point_index(); @@ -41,9 +44,6 @@ int null_point_index(); class Persistence_diagrams_graph { public: - // Diagram_point is the type of the persistence diagram's points - typedef typename std::pair Diagram_point; - // Persistence_diagram1 and 2 are the types of any externals representations of persistence diagrams. // They have to have an iterator over points, which have to have fields first (for birth) and second (for death). template @@ -108,7 +108,7 @@ inline double Persistence_diagrams_graph::distance(int u_point_index, int v_poin return 0; Diagram_point p_u = get_u_point(u_point_index); Diagram_point p_v = get_v_point(v_point_index); - return std::max(std::fabs(p_u.first - p_v.first), std::fabs(p_u.second - p_v.second)); + return (std::max)(std::fabs(p_u.first - p_v.first), std::fabs(p_u.second - p_v.second)); } inline int Persistence_diagrams_graph::size() const { @@ -124,7 +124,7 @@ inline std::vector* Persistence_diagrams_graph::sorted_distances() { return new std::vector(sorted_distances.cbegin(), sorted_distances.cend()); } -inline Persistence_diagrams_graph::Diagram_point Persistence_diagrams_graph::get_u_point(int u_point_index) const { +inline Diagram_point Persistence_diagrams_graph::get_u_point(int u_point_index) const { if (!on_the_u_diagonal(u_point_index)) return u.at(u_point_index); Diagram_point projector = v.at(corresponding_point_in_v(u_point_index)); @@ -132,7 +132,7 @@ inline Persistence_diagrams_graph::Diagram_point Persistence_diagrams_graph::get return Diagram_point(x, x); } -inline Persistence_diagrams_graph::Diagram_point Persistence_diagrams_graph::get_v_point(int v_point_index) const { +inline Diagram_point Persistence_diagrams_graph::get_v_point(int v_point_index) const { if (!on_the_v_diagonal(v_point_index)) return v.at(v_point_index); Diagram_point projector = u.at(corresponding_point_in_u(v_point_index)); diff --git a/src/Contraction/example/Garland_heckbert.cpp b/src/Contraction/example/Garland_heckbert.cpp index 5b178ff9..a41f65aa 100644 --- a/src/Contraction/example/Garland_heckbert.cpp +++ b/src/Contraction/example/Garland_heckbert.cpp @@ -7,7 +7,7 @@ * * Author(s): David Salinas * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * 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 @@ -42,72 +42,70 @@ using namespace Gudhi; using namespace skbl; using namespace contraction; - -struct Geometry_trait{ - typedef Point_d Point; +struct Geometry_trait { + typedef Point_d Point; }; /** * The vertex stored in the complex contains a quadric. */ struct Garland_heckbert_traits : public Skeleton_blocker_simple_geometric_traits { + public: -public: - struct Garland_heckbert_vertex : public Simple_geometric_vertex{ - Error_quadric quadric; - }; - typedef Garland_heckbert_vertex Graph_vertex; + struct Garland_heckbert_vertex : public Simple_geometric_vertex { + Error_quadric quadric; + }; + typedef Garland_heckbert_vertex Graph_vertex; }; typedef Skeleton_blocker_geometric_complex< Garland_heckbert_traits > Complex; typedef Edge_profile EdgeProfile; typedef Skeleton_blocker_contractor Complex_contractor; - /** * How the new vertex is placed after an edge collapse : here it is placed at * the point minimizing the cost of the quadric. */ -class GH_placement : public Gudhi::contraction::Placement_policy{ - Complex& complex_; -public: - typedef typename Gudhi::contraction::Placement_policy::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 min_quadric_pt(sum_quad.min_cost()); - if (min_quadric_pt) - return Placement_type(*min_quadric_pt); - else - return profile.p0(); - } +class GH_placement : public Gudhi::contraction::Placement_policy { + Complex& complex_; + public: + typedef Gudhi::contraction::Placement_policy::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 min_quadric_pt(sum_quad.min_cost()); + if (min_quadric_pt) + return Placement_type(*min_quadric_pt); + else + return profile.p0(); + } }; /** * How much cost an edge collapse : here the costs is given by a quadric * which expresses a squared distances with triangles planes. */ -class GH_cost : public Gudhi::contraction::Cost_policy{ - Complex& complex_; -public: - - typedef typename Gudhi::contraction::Cost_policy::Cost_type Cost_type; - - GH_cost(Complex& complex):complex_(complex){} - - Cost_type operator()( EdgeProfile const& profile, boost::optional 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; - } +class GH_cost : public Gudhi::contraction::Cost_policy { + Complex& complex_; + public: + + typedef Gudhi::contraction::Cost_policy::Cost_type Cost_type; + + GH_cost(Complex& complex) : complex_(complex) { } + + Cost_type operator()(EdgeProfile const& profile, boost::optional 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; + } }; /** @@ -115,79 +113,80 @@ public: * Here we initializes the quadrics of every vertex at the on_started call back * and we update them when contracting an edge (the quadric become the sum of both quadrics). */ -class GH_visitor: public Gudhi::contraction::Contraction_visitor { - Complex& complex_; -public: - GH_visitor(Complex& complex):complex_(complex){} - - //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 - void on_started(Complex & complex) override{ - 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(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; - } +class GH_visitor : public Gudhi::contraction::Contraction_visitor { + Complex& complex_; + public: + + GH_visitor(Complex& complex) : complex_(complex) { } + + //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 + + void on_started(Complex & complex) override { + 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(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; + } }; +int main(int argc, char *argv[]) { + if (argc != 4) { + std::cerr << "Usage " << argv[0] << " input.off output.off N to load the file input.off, contract N edges and save the result to output.off.\n"; + return EXIT_FAILURE; + } -int main(int argc, char *argv[]){ - if (argc!=4){ - std::cerr << "Usage "< off_reader(argv[1],complex); - if(!off_reader.is_valid()){ - std::cerr << "Unable to read file:"< off_reader(argv[1], complex); + if (!off_reader.is_valid()) { + std::cerr << "Unable to read file:" << argv[1] << std::endl; + return EXIT_FAILURE; + } - std::cout << "Load complex with "<(), - new GH_visitor(complex) - ); + // constructs the contractor object with Garland Heckbert policies. + Complex_contractor contractor(complex, + new GH_cost(complex), + new GH_placement(complex), + contraction::make_link_valid_contraction(), + new GH_visitor(complex) + ); - std::cout<<"Contract "< off_writer(argv[2],complex); + //write simplified complex + Skeleton_blocker_off_writer off_writer(argv[2], complex); - return EXIT_SUCCESS; + return EXIT_SUCCESS; } -- cgit v1.2.3