summaryrefslogtreecommitdiff
path: root/include/gudhi/Contraction
diff options
context:
space:
mode:
Diffstat (limited to 'include/gudhi/Contraction')
-rw-r--r--include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h101
-rw-r--r--include/gudhi/Contraction/Edge_profile.h130
-rw-r--r--include/gudhi/Contraction/policies/Contraction_visitor.h91
-rw-r--r--include/gudhi/Contraction/policies/Cost_policy.h53
-rw-r--r--include/gudhi/Contraction/policies/Dummy_valid_contraction.h49
-rw-r--r--include/gudhi/Contraction/policies/Edge_length_cost.h56
-rw-r--r--include/gudhi/Contraction/policies/First_vertex_placement.h52
-rw-r--r--include/gudhi/Contraction/policies/Link_condition_valid_contraction.h56
-rw-r--r--include/gudhi/Contraction/policies/Middle_placement.h51
-rw-r--r--include/gudhi/Contraction/policies/Placement_policy.h51
-rw-r--r--include/gudhi/Contraction/policies/Valid_contraction_policy.h51
11 files changed, 741 insertions, 0 deletions
diff --git a/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h b/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h
new file mode 100644
index 00000000..5a55c513
--- /dev/null
+++ b/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h
@@ -0,0 +1,101 @@
+// Copyright (c) 2006-2011 GeometryFactory (France). All rights reserved.
+//
+// This file is part of CGAL (www.cgal.org); 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 3 of the License,
+// or (at your option) any later version.
+//
+// Licensees holding a valid commercial license may use this file in
+// accordance with the commercial license agreement provided with the software.
+//
+// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// $URL$
+// $Id$
+//
+// Author(s) : Fernando Cacciola <fernando.cacciola@geometryfactory.com>
+//
+#ifndef CONTRACTION_CGAL_QUEUE_MODIFIABLE_PRIORITY_QUEUE_H_
+#define CONTRACTION_CGAL_QUEUE_MODIFIABLE_PRIORITY_QUEUE_H_
+
+#define CGAL_SURFACE_MESH_SIMPLIFICATION_USE_RELAXED_HEAP
+
+#include <boost/optional.hpp>
+#include <boost/pending/relaxed_heap.hpp>
+
+#include <climits> // Neeeded by the following Boost header for CHAR_BIT.
+#include <functional> // for less
+
+namespace CGAL {
+
+template <class IndexedType_, class Compare_ = std::less<IndexedType_>, class ID_ = boost::identity_property_map>
+class Modifiable_priority_queue {
+ public:
+ typedef Modifiable_priority_queue Self;
+
+ typedef IndexedType_ IndexedType;
+ typedef Compare_ Compare;
+ typedef ID_ ID;
+
+ typedef boost::relaxed_heap<IndexedType, Compare, ID> Heap;
+ typedef typename Heap::value_type value_type;
+ typedef typename Heap::size_type size_type;
+
+ typedef bool handle;
+
+ public:
+ Modifiable_priority_queue(size_type largest_ID, Compare const& c, ID const& id) : mHeap(largest_ID, c, id) { }
+
+ handle push(value_type const& v) {
+ mHeap.push(v);
+ return handle(true);
+ }
+
+ handle update(value_type const& v, handle h) {
+ mHeap.update(v);
+ return h;
+ }
+
+ handle erase(value_type const& v, handle) {
+ mHeap.remove(v);
+ return null_handle();
+ }
+
+ value_type top() const {
+ return mHeap.top();
+ }
+
+ void pop() {
+ mHeap.pop();
+ }
+
+ bool empty() const {
+ return mHeap.empty();
+ }
+
+ bool contains(value_type const& v) {
+ return mHeap.contains(v);
+ }
+
+ boost::optional<value_type> extract_top() {
+ boost::optional<value_type> r;
+ if (!empty()) {
+ value_type v = top();
+ pop();
+ r = boost::optional<value_type>(v);
+ }
+ return r;
+ }
+
+ static handle null_handle() {
+ return handle(false);
+ }
+
+ private:
+ Heap mHeap;
+};
+
+} // namespace CGAL
+
+#endif // CONTRACTION_CGAL_QUEUE_MODIFIABLE_PRIORITY_QUEUE_H_
diff --git a/include/gudhi/Contraction/Edge_profile.h b/include/gudhi/Contraction/Edge_profile.h
new file mode 100644
index 00000000..e4910b27
--- /dev/null
+++ b/include/gudhi/Contraction/Edge_profile.h
@@ -0,0 +1,130 @@
+/* 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-Mediterranee (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 CONTRACTION_EDGE_PROFILE_H_
+#define CONTRACTION_EDGE_PROFILE_H_
+
+#include <ostream>
+
+namespace Gudhi {
+
+namespace contraction {
+
+template<typename GeometricSimplifiableComplex> class Edge_profile {
+ public:
+ typedef GeometricSimplifiableComplex Complex;
+ typedef typename Complex::GT GT;
+
+ typedef typename GeometricSimplifiableComplex::Vertex_handle Vertex_handle;
+ typedef typename GeometricSimplifiableComplex::Root_vertex_handle Root_vertex_handle;
+
+
+ typedef typename GeometricSimplifiableComplex::Edge_handle Edge_handle;
+ typedef typename GeometricSimplifiableComplex::Graph_vertex Graph_vertex;
+ typedef typename GeometricSimplifiableComplex::Graph_edge Graph_edge;
+ typedef typename GeometricSimplifiableComplex::Point Point;
+
+ Edge_profile(GeometricSimplifiableComplex& complex, Edge_handle edge) : complex_(complex), edge_handle_(edge),
+ v0_(complex_.first_vertex(edge_handle_)), v1_(complex_.second_vertex(edge_handle_)) {
+ assert(complex_.get_address(complex_[edge_handle_].first()));
+ assert(complex_.get_address(complex_[edge_handle_].second()));
+ assert(complex_.contains_edge(v0_handle(), v1_handle()));
+ assert(v0_handle() != v1_handle());
+ }
+
+ virtual ~Edge_profile() { }
+
+ GeometricSimplifiableComplex& complex() const {
+ return complex_;
+ }
+
+ Edge_handle edge_handle() const {
+ return edge_handle_;
+ }
+
+ Graph_edge& edge() const {
+ return complex_[edge_handle_];
+ }
+
+ Graph_vertex& v0() const {
+ return complex_[v0_handle()];
+ }
+
+ Graph_vertex& v1() const {
+ return complex_[v1_handle()];
+ }
+
+ Vertex_handle v0_handle() const {
+ return v0_;
+ // Root_vertex_handle root = complex_[edge_handle_].first();
+ // assert(complex_.get_address(root));
+ // return *complex_.get_address(root);
+ }
+
+ Vertex_handle v1_handle() const {
+ return v1_;
+ // Root_vertex_handle root = complex_[edge_handle_].second();
+ // assert(complex_.get_address(root));
+ // return *complex_.get_address(root);
+ }
+
+ const Point& p0() const {
+ return complex_.point(v0_handle());
+ }
+
+ const Point& p1() const {
+ return complex_.point(v1_handle());
+ }
+
+ friend std::ostream& operator<<(std::ostream& o, const Edge_profile& v) {
+ return o << "v0:" << v.v0_handle() << " v1:" << v.v1_handle();
+ }
+
+ private:
+ GeometricSimplifiableComplex& complex_;
+
+ Edge_handle edge_handle_;
+
+ Vertex_handle v0_;
+
+ Vertex_handle v1_;
+};
+
+template<typename EdgeProfile> class Edge_profile_factory {
+ public:
+ typedef typename EdgeProfile::Edge_handle Edge_handle_;
+ typedef typename EdgeProfile::Complex Complex_;
+
+ virtual EdgeProfile make_profile(
+ Complex_& complex,
+ Edge_handle_ edge) const {
+ return EdgeProfile(complex, edge);
+ }
+
+ virtual ~Edge_profile_factory() { }
+};
+
+} // namespace contraction
+
+} // namespace Gudhi
+
+#endif // CONTRACTION_EDGE_PROFILE_H_
diff --git a/include/gudhi/Contraction/policies/Contraction_visitor.h b/include/gudhi/Contraction/policies/Contraction_visitor.h
new file mode 100644
index 00000000..7ee05aad
--- /dev/null
+++ b/include/gudhi/Contraction/policies/Contraction_visitor.h
@@ -0,0 +1,91 @@
+/* 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-Mediterranee (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 CONTRACTION_POLICIES_CONTRACTION_VISITOR_H_
+#define CONTRACTION_POLICIES_CONTRACTION_VISITOR_H_
+
+#include <gudhi/Contraction/Edge_profile.h>
+#include <boost/optional.hpp>
+
+namespace Gudhi {
+
+namespace contraction {
+
+/**
+ *@class Contraction_visitor
+ *@brief Interface for a visitor of the edge contraction process.
+ *@ingroup contr
+ */
+template <typename EdgeProfile>
+class Contraction_visitor { // : public Dummy_complex_visitor<typename EdgeProfile::Vertex_handle> {
+ public:
+ // typedef typename ComplexType::GeometryTrait GT;
+ typedef EdgeProfile Profile;
+ typedef double FT;
+ typedef typename Profile::Complex Complex;
+ typedef Complex ComplexType;
+ typedef typename ComplexType::Point Point;
+
+ virtual ~Contraction_visitor() { }
+
+ /**
+ * @brief Called before the edge contraction process starts.
+ */
+ virtual void on_started(ComplexType & complex) { }
+
+ /**
+ * @brief Called when the algorithm stops.
+ */
+ virtual void on_stop_condition_reached() { }
+
+ /**
+ * @brief Called during the collecting phase (when a cost is assigned to the edges), for each edge collected.
+ */
+ virtual void on_collected(const Profile &profile, boost::optional< FT > cost) { }
+
+ /**
+ * @brief Called during the processing phase (when edges are contracted), for each edge that is selected.
+ */
+ virtual void on_selected(const Profile &profile, boost::optional< FT > cost, int initial_count, int current_count) { }
+
+ /**
+ * @brief Called when an edge is about to be contracted and replaced by a vertex whose position is *placement.
+ */
+ virtual void on_contracting(const Profile &profile, boost::optional< Point > placement) { }
+
+ /**
+ * @brief Called when after an edge has been contracted onto a new point placement.
+ * A possibility would to remove popable blockers at this point for instance.
+ */
+ virtual void on_contracted(const Profile &profile, boost::optional< Point > placement) { }
+
+ /**
+ * @brief Called for each selected edge which cannot be contracted because the ValidContractionPredicate is false
+ */
+ virtual void on_non_valid(const Profile &profile) { }
+};
+
+} // namespace contraction
+
+} // namespace Gudhi
+
+#endif // CONTRACTION_POLICIES_CONTRACTION_VISITOR_H_
diff --git a/include/gudhi/Contraction/policies/Cost_policy.h b/include/gudhi/Contraction/policies/Cost_policy.h
new file mode 100644
index 00000000..f4d343ec
--- /dev/null
+++ b/include/gudhi/Contraction/policies/Cost_policy.h
@@ -0,0 +1,53 @@
+/* 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-Mediterranee (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 CONTRACTION_POLICIES_COST_POLICY_H_
+#define CONTRACTION_POLICIES_COST_POLICY_H_
+
+#include <boost/optional.hpp>
+
+namespace Gudhi {
+
+namespace contraction {
+
+/**
+ *@brief Policy to specify the cost of contracting an edge.
+ *@ingroup contr
+ */
+template< typename EdgeProfile>
+class Cost_policy {
+ public:
+ typedef typename EdgeProfile::Point Point;
+ typedef typename EdgeProfile::Graph_vertex Graph_vertex;
+
+ typedef boost::optional<double> Cost_type;
+
+ virtual Cost_type operator()(const EdgeProfile& profile, const boost::optional<Point>& placement) const = 0;
+
+ virtual ~Cost_policy() { }
+};
+
+} // namespace contraction
+
+} // namespace Gudhi
+
+#endif // CONTRACTION_POLICIES_COST_POLICY_H_
diff --git a/include/gudhi/Contraction/policies/Dummy_valid_contraction.h b/include/gudhi/Contraction/policies/Dummy_valid_contraction.h
new file mode 100644
index 00000000..5d329496
--- /dev/null
+++ b/include/gudhi/Contraction/policies/Dummy_valid_contraction.h
@@ -0,0 +1,49 @@
+/* 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-Mediterranee (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 CONTRACTION_POLICIES_DUMMY_VALID_CONTRACTION_H_
+#define CONTRACTION_POLICIES_DUMMY_VALID_CONTRACTION_H_
+
+#include <gudhi/Contraction/policies/Valid_contraction_policy.h>
+
+namespace Gudhi {
+
+namespace contraction {
+
+/**
+ *@brief Policy that accept all edge contraction.
+ */
+template< typename EdgeProfile>
+class Dummy_valid_contraction : public Valid_contraction_policy<EdgeProfile> {
+ public:
+ typedef typename EdgeProfile::Point Point;
+
+ bool operator()(const EdgeProfile& profile, const boost::optional<Point>& placement) {
+ return true;
+ }
+};
+
+} // namespace contraction
+
+} // namespace Gudhi
+
+#endif // CONTRACTION_POLICIES_DUMMY_VALID_CONTRACTION_H_
diff --git a/include/gudhi/Contraction/policies/Edge_length_cost.h b/include/gudhi/Contraction/policies/Edge_length_cost.h
new file mode 100644
index 00000000..dac2d448
--- /dev/null
+++ b/include/gudhi/Contraction/policies/Edge_length_cost.h
@@ -0,0 +1,56 @@
+/* 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-Mediterranee (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 CONTRACTION_POLICIES_EDGE_LENGTH_COST_H_
+#define CONTRACTION_POLICIES_EDGE_LENGTH_COST_H_
+
+#include <gudhi/Contraction/policies/Cost_policy.h>
+
+namespace Gudhi {
+
+namespace contraction {
+
+/**
+ * @brief return a cost corresponding to the squared length of the edge
+ */
+template< typename EdgeProfile>
+class Edge_length_cost : public Cost_policy<EdgeProfile> {
+ public:
+ typedef typename Cost_policy<EdgeProfile>::Cost_type Cost_type;
+ typedef typename EdgeProfile::Point Point;
+
+ Cost_type operator()(const EdgeProfile& profile, const boost::optional<Point>& placement) const override {
+ double res = 0;
+ auto p0_coord = profile.p0().begin();
+ auto p1_coord = profile.p1().begin();
+ for (; p0_coord != profile.p0().end(); p0_coord++, p1_coord++) {
+ res += (*p0_coord - *p1_coord) * (*p0_coord - *p1_coord);
+ }
+ return res;
+ }
+};
+
+} // namespace contraction
+
+} // namespace Gudhi
+
+#endif // CONTRACTION_POLICIES_EDGE_LENGTH_COST_H_
diff --git a/include/gudhi/Contraction/policies/First_vertex_placement.h b/include/gudhi/Contraction/policies/First_vertex_placement.h
new file mode 100644
index 00000000..1f68db0d
--- /dev/null
+++ b/include/gudhi/Contraction/policies/First_vertex_placement.h
@@ -0,0 +1,52 @@
+/* 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-Mediterranee (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 CONTRACTION_POLICIES_FIRST_VERTEX_PLACEMENT_H_
+#define CONTRACTION_POLICIES_FIRST_VERTEX_PLACEMENT_H_
+
+#include <gudhi/Contraction/policies/Placement_policy.h>
+
+namespace Gudhi {
+
+namespace contraction {
+
+/**
+ * @brief Places the contracted point onto the first point of the edge
+ */
+template< typename EdgeProfile>
+class First_vertex_placement : public Placement_policy<EdgeProfile> {
+ public:
+ typedef typename EdgeProfile::Point Point;
+ typedef typename EdgeProfile::Edge_handle Edge_handle;
+
+ typedef typename Placement_policy<EdgeProfile>::Placement_type Placement_type;
+
+ Placement_type operator()(const EdgeProfile& profile) const override {
+ return Placement_type(profile.p0());
+ }
+};
+
+} // namespace contraction
+
+} // namespace Gudhi
+
+#endif // CONTRACTION_POLICIES_FIRST_VERTEX_PLACEMENT_H_
diff --git a/include/gudhi/Contraction/policies/Link_condition_valid_contraction.h b/include/gudhi/Contraction/policies/Link_condition_valid_contraction.h
new file mode 100644
index 00000000..250bba27
--- /dev/null
+++ b/include/gudhi/Contraction/policies/Link_condition_valid_contraction.h
@@ -0,0 +1,56 @@
+/* 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-Mediterranee (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 CONTRACTION_POLICIES_LINK_CONDITION_VALID_CONTRACTION_H_
+#define CONTRACTION_POLICIES_LINK_CONDITION_VALID_CONTRACTION_H_
+
+#include <gudhi/Contraction/policies/Valid_contraction_policy.h>
+#include <gudhi/Debug_utils.h>
+
+
+namespace Gudhi {
+
+namespace contraction {
+
+/**
+ *@brief Policy that only accept edges verifying the link condition (and therefore whose contraction preserving homotopy type).
+ *@ingroup contr
+ */
+template< typename EdgeProfile>
+class Link_condition_valid_contraction : public Valid_contraction_policy<EdgeProfile> {
+ public:
+ typedef typename EdgeProfile::Edge_handle Edge_handle;
+ typedef typename EdgeProfile::Point Point;
+ // typedef typename EdgeProfile::Edge_handle Edge_handle;
+
+ bool operator()(const EdgeProfile& profile, const boost::optional<Point>& placement) const override {
+ Edge_handle edge(profile.edge_handle());
+ DBGMSG("Link_condition_valid_contraction:", profile.complex().link_condition(edge));
+ return profile.complex().link_condition(edge);
+ }
+};
+
+} // namespace contraction
+
+} // namespace Gudhi
+
+#endif // CONTRACTION_POLICIES_LINK_CONDITION_VALID_CONTRACTION_H_
diff --git a/include/gudhi/Contraction/policies/Middle_placement.h b/include/gudhi/Contraction/policies/Middle_placement.h
new file mode 100644
index 00000000..4b59f1b5
--- /dev/null
+++ b/include/gudhi/Contraction/policies/Middle_placement.h
@@ -0,0 +1,51 @@
+/* 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-Mediterranee (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 CONTRACTION_POLICIES_MIDDLE_PLACEMENT_H_
+#define CONTRACTION_POLICIES_MIDDLE_PLACEMENT_H_
+
+#include <gudhi/Contraction/policies/Placement_policy.h>
+
+namespace Gudhi {
+
+namespace contraction {
+
+template< typename EdgeProfile>
+class Middle_placement : public Placement_policy<EdgeProfile> {
+ public:
+ typedef typename EdgeProfile::Point Point;
+ typedef typename EdgeProfile::Edge_handle Edge_handle;
+ typedef typename EdgeProfile::Graph_vertex Graph_vertex;
+
+ typedef typename Placement_policy<EdgeProfile>::Placement_type Placement_type;
+
+ Placement_type operator()(const EdgeProfile& profile) const override {
+ // todo compute the middle
+ return Placement_type(profile.p0());
+ }
+};
+
+} // namespace contraction
+
+} // namespace Gudhi
+
+#endif // CONTRACTION_POLICIES_MIDDLE_PLACEMENT_H_
diff --git a/include/gudhi/Contraction/policies/Placement_policy.h b/include/gudhi/Contraction/policies/Placement_policy.h
new file mode 100644
index 00000000..34ffa49f
--- /dev/null
+++ b/include/gudhi/Contraction/policies/Placement_policy.h
@@ -0,0 +1,51 @@
+/* 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-Mediterranee (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 CONTRACTION_POLICIES_PLACEMENT_POLICY_H_
+#define CONTRACTION_POLICIES_PLACEMENT_POLICY_H_
+
+#include <boost/optional.hpp>
+
+namespace Gudhi {
+
+namespace contraction {
+
+/**
+ *@brief Policy to specify where the merged point had to be placed after an edge contraction.
+ *@ingroup contr
+ */
+template< typename EdgeProfile>
+class Placement_policy {
+ public:
+ typedef typename EdgeProfile::Point Point;
+ typedef boost::optional<Point> Placement_type;
+
+ virtual Placement_type operator()(const EdgeProfile& profile) const = 0;
+
+ virtual ~Placement_policy() { }
+};
+
+} // namespace contraction
+
+} // namespace Gudhi
+
+#endif // CONTRACTION_POLICIES_PLACEMENT_POLICY_H_
diff --git a/include/gudhi/Contraction/policies/Valid_contraction_policy.h b/include/gudhi/Contraction/policies/Valid_contraction_policy.h
new file mode 100644
index 00000000..78d61173
--- /dev/null
+++ b/include/gudhi/Contraction/policies/Valid_contraction_policy.h
@@ -0,0 +1,51 @@
+/* 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-Mediterranee (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 CONTRACTION_POLICIES_VALID_CONTRACTION_POLICY_H_
+#define CONTRACTION_POLICIES_VALID_CONTRACTION_POLICY_H_
+
+namespace Gudhi {
+
+namespace contraction {
+
+/**
+ *@brief Policy to specify if an edge contraction is valid or not.
+ *@ingroup contr
+ */
+template< typename EdgeProfile>
+class Valid_contraction_policy {
+ public:
+ typedef typename EdgeProfile::Point Point;
+ typedef typename EdgeProfile::Edge_handle Edge_handle;
+ typedef typename EdgeProfile::Graph_vertex Graph_vertex;
+
+ virtual bool operator()(const EdgeProfile& profile, const boost::optional<Point>& placement) const = 0;
+
+ virtual ~Valid_contraction_policy() { }
+};
+
+} // namespace contraction
+
+} // namespace Gudhi
+
+
+#endif // CONTRACTION_POLICIES_VALID_CONTRACTION_POLICY_H_