TTK
Loading...
Searching...
No Matches
DistanceField.h
Go to the documentation of this file.
1
19#pragma once
20
21// base code includes
22#include "Triangulation.h"
23#include <Dijkstra.h>
24
25// std includes
26#include <limits>
27#include <set>
28#include <string>
29
30namespace ttk {
31
32 class DistanceField : virtual public Debug {
33 public:
35
36 template <typename dataType>
37 dataType getDistance(const SimplexId a, const SimplexId b) const;
38
39 template <typename dataType,
40 class triangulationType = ttk::AbstractTriangulation>
41 int execute(const triangulationType *) const;
42
43 inline void setVertexNumber(SimplexId vertexNumber) {
44 vertexNumber_ = vertexNumber;
45 }
46
47 inline void setSourceNumber(SimplexId sourceNumber) {
48 sourceNumber_ = sourceNumber;
49 }
50
52 return triangulation->preconditionVertexNeighbors();
53 }
54
58
59 inline void setOutputScalarFieldPointer(void *data) {
61 }
62
63 inline void setOutputIdentifiers(void *data) {
64 outputIdentifiers_ = data;
65 }
66
67 inline void setOutputSegmentation(void *data) {
69 }
70
71 protected:
78 };
79} // namespace ttk
80
81template <typename dataType, class triangulationType>
82int ttk::DistanceField::execute(const triangulationType *triangulation_) const {
83
84 // start global timer
85 ttk::Timer globalTimer;
86
88 dataType *dist = static_cast<dataType *>(outputScalarFieldPointer_);
89 SimplexId *origin = static_cast<SimplexId *>(outputIdentifiers_);
90 SimplexId *seg = static_cast<SimplexId *>(outputSegmentation_);
91
92 std::fill(dist, dist + vertexNumber_, std::numeric_limits<dataType>::max());
93 std::fill(origin, origin + vertexNumber_, -1);
94
95 // get the sources
96 std::set<SimplexId> isSource;
97 for(SimplexId k = 0; k < sourceNumber_; ++k)
98 isSource.insert(identifiers[k]);
99 std::vector<SimplexId> sources(isSource.begin(), isSource.end());
100 isSource.clear();
101
102 // prepare output
103 std::vector<std::vector<dataType>> scalars(sources.size());
104
105 // @PETER This doesn't seem to very work efficient, there's multilple source
106 // shortest paths algorithms.
107#ifdef TTK_ENABLE_OPENMP
108#pragma omp parallel for num_threads(threadNumber_)
109#endif
110 for(size_t i = 0; i < sources.size(); ++i) {
111 int const ret = Dijkstra::shortestPath<dataType>(
112 sources[i], *triangulation_, scalars[i]);
113 if(ret != 0) {
114 this->printErr(
115 "Algorithm not successful (error code: " + std::to_string(ret) + ").");
116 }
117 }
118
119#ifdef TTK_ENABLE_OPENMP
120#pragma omp parallel for num_threads(threadNumber_)
121#endif
122 for(SimplexId k = 0; k < vertexNumber_; ++k) {
123 for(size_t i = 0; i < sources.size(); ++i) {
124 if(i == 0 or dist[k] > scalars[i][k]) {
125 dist[k] = scalars[i][k];
126 origin[k] = sources[i];
127 seg[k] = i;
128 }
129 }
130 }
131
132 this->printMsg(
133 "Complete", 1.0, globalTimer.getElapsedTime(), this->threadNumber_);
134
135 return 0;
136}
AbstractTriangulation is an interface class that defines an interface for efficient traversal methods...
Minimalist debugging class.
Definition Debug.h:88
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Definition Debug.h:149
TTK processing package for distance field computation on PL manifolds.
void setOutputIdentifiers(void *data)
SimplexId sourceNumber_
void * outputScalarFieldPointer_
void setVertexNumber(SimplexId vertexNumber)
void setVertexIdentifierScalarFieldPointer(SimplexId *const data)
void setOutputScalarFieldPointer(void *data)
int execute(const triangulationType *) const
SimplexId * vertexIdentifierScalarFieldPointer_
void setOutputSegmentation(void *data)
int preconditionTriangulation(AbstractTriangulation *triangulation)
void setSourceNumber(SimplexId sourceNumber)
SimplexId vertexNumber_
dataType getDistance(const SimplexId a, const SimplexId b) const
double getElapsedTime()
Definition Timer.h:15
The Topology ToolKit.
int SimplexId
Identifier type for simplices of any dimension.
Definition DataTypes.h:22
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)