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
57 }
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 Timer t;
93
94 std::fill(dist, dist + vertexNumber_, std::numeric_limits<dataType>::max());
95 std::fill(origin, origin + vertexNumber_, -1);
96
97 // get the sources
98 std::set<SimplexId> isSource;
99 for(SimplexId k = 0; k < sourceNumber_; ++k)
100 isSource.insert(identifiers[k]);
101 std::vector<SimplexId> sources(isSource.begin(), isSource.end());
102 isSource.clear();
103
104 // prepare output
105 std::vector<std::vector<dataType>> scalars(sources.size());
106
107 // @PETER This doesn't seem to very work efficient, there's multilple source
108 // shortest paths algorithms.
109#ifdef TTK_ENABLE_OPENMP
110#pragma omp parallel for num_threads(threadNumber_)
111#endif
112 for(size_t i = 0; i < sources.size(); ++i) {
113 int ret = Dijkstra::shortestPath<dataType>(
114 sources[i], *triangulation_, scalars[i]);
115 if(ret != 0) {
116 this->printErr(
117 "Algorithm not successful (error code: " + std::to_string(ret) + ").");
118 }
119 }
120
121#ifdef TTK_ENABLE_OPENMP
122#pragma omp parallel for num_threads(threadNumber_)
123#endif
124 for(SimplexId k = 0; k < vertexNumber_; ++k) {
125 for(size_t i = 0; i < sources.size(); ++i) {
126 if(i == 0 or dist[k] > scalars[i][k]) {
127 dist[k] = scalars[i][k];
128 origin[k] = sources[i];
129 seg[k] = i;
130 }
131 }
132 }
133
134 this->printMsg(
135 "Complete", 1.0, globalTimer.getElapsedTime(), this->threadNumber_);
136
137 return 0;
138}
AbstractTriangulation is an interface class that defines an interface for efficient traversal methods...
Minimalist debugging class.
Definition: Debug.h:88
int printMsg(const std::string &msg, const debug::Priority &priority=debug::Priority::INFO, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cout) const
Definition: Debug.h:118
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.
Definition: DistanceField.h:32
void setOutputIdentifiers(void *data)
Definition: DistanceField.h:63
SimplexId sourceNumber_
Definition: DistanceField.h:73
void * outputScalarFieldPointer_
Definition: DistanceField.h:75
void setVertexNumber(SimplexId vertexNumber)
Definition: DistanceField.h:43
void setVertexIdentifierScalarFieldPointer(SimplexId *const data)
Definition: DistanceField.h:55
void setOutputScalarFieldPointer(void *data)
Definition: DistanceField.h:59
int execute(const triangulationType *) const
Definition: DistanceField.h:82
SimplexId * vertexIdentifierScalarFieldPointer_
Definition: DistanceField.h:74
void * outputSegmentation_
Definition: DistanceField.h:77
void setOutputSegmentation(void *data)
Definition: DistanceField.h:67
int preconditionTriangulation(AbstractTriangulation *triangulation)
Definition: DistanceField.h:51
void setSourceNumber(SimplexId sourceNumber)
Definition: DistanceField.h:47
SimplexId vertexNumber_
Definition: DistanceField.h:72
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