summaryrefslogtreecommitdiff
path: root/src/GudhUI/utils/Edge_contractor.h
diff options
context:
space:
mode:
authorsalinasd <salinasd@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-01-27 10:20:13 +0000
committersalinasd <salinasd@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-01-27 10:20:13 +0000
commitf527cde6342c5b8109a20f0a6b483327c6569844 (patch)
tree1c0464b56b21ef7767f814b9a35a6e5c68aa7613 /src/GudhUI/utils/Edge_contractor.h
parentdf6c26bdcb28805e8949d08dad5acd012e91ecb8 (diff)
Merge GudhUI, a UI for gudhi based on Qt
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@427 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 17fedd974f14a8225b27d94361e835964eeb5cba
Diffstat (limited to 'src/GudhUI/utils/Edge_contractor.h')
-rw-r--r--src/GudhUI/utils/Edge_contractor.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/GudhUI/utils/Edge_contractor.h b/src/GudhUI/utils/Edge_contractor.h
new file mode 100644
index 00000000..c7a86e0b
--- /dev/null
+++ b/src/GudhUI/utils/Edge_contractor.h
@@ -0,0 +1,68 @@
+/*
+ * Contractor.h
+ *
+ * Created on: Sep 25, 2014
+ * Author: dsalinas
+ */
+
+#ifndef EDGE_CONTRACTOR_H_
+#define EDGE_CONTRACTOR_H_
+
+
+#include "gudhi/Skeleton_blocker_contractor.h"
+
+#include "gudhi/Contraction/Edge_profile.h"
+#include "gudhi/Contraction/policies/Cost_policy.h"
+
+
+/**
+ * Iteratively puts every vertex at the center of its neighbors
+ */
+template<typename SkBlComplex> class Edge_contractor{
+private:
+ SkBlComplex& complex_;
+ unsigned num_contractions_;
+
+ /**
+ * @brief return a cost corresponding to the squared length of the edge
+ */
+ template< typename EdgeProfile> class Length_cost : public contraction::Cost_policy<EdgeProfile>{
+ public:
+ typedef typename contraction::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{
+ Cost_type res;
+ if(!placement) return res;
+ return Geometry_trait::Squared_distance_d()(profile.p0(),profile.p1()); //not working??
+ }
+ };
+
+ public:
+ typedef typename SkBlComplex::Vertex_handle Vertex_handle;
+ typedef typename SkBlComplex::Edge_handle Edge_handle;
+
+ /**
+ * @brief Modify complex to be the expansion of the k-nearest neighbor
+ * symetric graph.
+ */
+ Edge_contractor(SkBlComplex& complex,unsigned num_contractions):
+ complex_(complex),num_contractions_(num_contractions)
+ {
+ typedef typename contraction::Edge_profile<Complex> Profile;
+ num_contractions = (std::min)((int)num_contractions,(int)(complex_.num_vertices()-1));
+ contraction::Skeleton_blocker_contractor<Complex> contractor(
+ complex_,
+ new Length_cost<contraction::Edge_profile<Complex>>(),
+ contraction::make_first_vertex_placement<Profile>(),
+ contraction::make_link_valid_contraction<Profile>(),
+ contraction::make_remove_popable_blockers_visitor<Profile>()
+ );
+ contractor.contract_edges(num_contractions);
+ }
+
+
+};
+
+
+
+#endif /* EDGE_CONTRACTOR_H_ */