Skip to content

Commit

Permalink
Merge pull request #1005 from MClemot/ripsPersistenceDiagram
Browse files Browse the repository at this point in the history
Rips persistence diagram
  • Loading branch information
julien-tierny authored Feb 2, 2024
2 parents 0b76f06 + 559de95 commit cd1ce59
Show file tree
Hide file tree
Showing 11 changed files with 1,574 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/base/ripsPersistenceDiagram/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ttk_add_base_library(ripsPersistenceDiagram
SOURCES
RipsPersistenceDiagram.cpp
ripserpy.cpp
HEADERS
RipsPersistenceDiagram.h
ripser.h
DEPENDS
common
)
16 changes: 16 additions & 0 deletions core/base/ripsPersistenceDiagram/RipsPersistenceDiagram.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <RipsPersistenceDiagram.h>

ttk::RipsPersistenceDiagram::RipsPersistenceDiagram() {
// inherited from Debug: prefix will be printed at the beginning of every msg
this->setDebugMsgPrefix("RipsPersistenceDiagram");
}

int ttk::RipsPersistenceDiagram::execute(
const std::vector<std::vector<double>> &points,
std::vector<std::vector<ripser::pers_pair_t>> &ph) const {

ripser::ripser(points, SimplexMaximumDiameter, SimplexMaximumDimension,
InputIsDistanceMatrix, ph);

return 0;
}
55 changes: 55 additions & 0 deletions core/base/ripsPersistenceDiagram/RipsPersistenceDiagram.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/// \ingroup base
/// \class ttk::RipsPersistenceDiagram
/// \author Mattéo Clémot <matteo.clemot@univ-lyon1.fr>
/// \date January 2024.
///
/// \brief TTK base class that computes the persistence diagram of a Rips
/// complex.
///
/// This module defines the %RipsPersistenceDiagram class that takes a point
/// cloud or a distance matrix and computes the persistence diagram of its Rips
/// complex.
///
/// \sa ttk::Triangulation
/// \sa ttkRipsPersistenceDiagram.cpp %for a usage example.

#pragma once

// ttk common includes
#include <Debug.h>

#include <ripser.h>

namespace ttk {

/**
* The RipsPersistenceDiagram class provides a method to call the code Ripser
* in order to compute the persistence diagram of the Rips complex of the
* input.
*/
class RipsPersistenceDiagram : virtual public Debug {

public:
RipsPersistenceDiagram();

/**
* @brief Main entry point
*
* @param[in] points Input point cloud in any dimension or input distance
* matrix
* @param[out] ph Computed Rips persistence diagram
*/
int execute(const std::vector<std::vector<double>> &points,
std::vector<std::vector<ripser::pers_pair_t>> &ph) const;

protected:
/** Max dimension of computed persistence diagram */
int SimplexMaximumDimension{1};
/** Rips threshold */
double SimplexMaximumDiameter{1.0};
/** is input a distance matrix */
int InputIsDistanceMatrix{0};

}; // RipsPersistenceDiagram class

} // namespace ttk
34 changes: 34 additions & 0 deletions core/base/ripsPersistenceDiagram/ripser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/// \ingroup base
/// \author Mattéo Clémot <matteo.clemot@univ-lyon1.fr>
/// \date January 2024.

#pragma once

#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <fstream>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <unordered_map>

namespace ripser {

using value_t = double;
using index_t = int64_t;
using coefficient_t = uint16_t;

using simplex_t = std::vector<index_t>;
using simplex_diam_t = std::pair<simplex_t, value_t>;
using pers_pair_t = std::pair<simplex_diam_t, simplex_diam_t>;

void ripser(std::vector<std::vector<value_t>> points,
value_t threshold,
index_t dim_max,
bool distanceMatrix,
std::vector<std::vector<pers_pair_t>> &ph);

} // namespace ripser
Loading

0 comments on commit cd1ce59

Please sign in to comment.