TTK
Loading...
Searching...
No Matches
ScalarFieldSmoother.h
Go to the documentation of this file.
1
41
42#pragma once
43
44// base code includes
45#include <Triangulation.h>
46
47namespace ttk {
48
49 class ScalarFieldSmoother : virtual public Debug {
50
51 public:
54
55 inline void setDimensionNumber(const int &dimensionNumber) {
56 dimensionNumber_ = dimensionNumber;
57 }
58
59 inline void setInputDataPointer(void *data) {
60 inputData_ = data;
61 }
62
63 inline void setOutputDataPointer(void *data) {
64 outputData_ = data;
65 }
66
67 inline void setMaskDataPointer(const char *const mask) {
68 mask_ = mask;
69 }
70
72 // Pre-condition functions.
73 if(triangulation) {
74 triangulation->preconditionVertexNeighbors();
75#ifdef TTK_ENABLE_MPI
76 triangulation->preconditionExchangeGhostVertices();
77#endif // TTK_ENABLE_MPI
78 }
79 return 0;
80 }
81
82 template <class dataType, class triangulationType = AbstractTriangulation>
83 int smooth(const triangulationType *triangulation,
84 const int &numberOfIterations) const;
85
86 protected:
88 void *inputData_{nullptr}, *outputData_{nullptr};
89 const char *mask_{nullptr};
90 };
91
92} // namespace ttk
93
94// template functions
95template <class dataType, class triangulationType>
96int ttk::ScalarFieldSmoother::smooth(const triangulationType *triangulation,
97 const int &numberOfIterations) const {
98
99 Timer t;
100
101#ifndef TTK_ENABLE_KAMIKAZE
102 if(!triangulation)
103 return -1;
105 return -2;
106 if(!inputData_)
107 return -3;
108 if(!outputData_)
109 return -4;
110#endif
111
112 SimplexId vertexNumber = triangulation->getNumberOfVertices();
113
114 std::vector<dataType> tmpData(vertexNumber * dimensionNumber_, 0);
115
116 dataType *outputData = (dataType *)outputData_;
117 dataType *inputData = (dataType *)inputData_;
118 // init the output
119 for(SimplexId i = 0; i < vertexNumber; i++) {
120 for(int j = 0; j < dimensionNumber_; j++) {
121 outputData[dimensionNumber_ * i + j]
122 = inputData[dimensionNumber_ * i + j];
123 }
124 }
125
126 printMsg("Smoothing " + std::to_string(vertexNumber) + " vertices", 0, 0,
128
129 int timeBuckets = 10;
130 if(numberOfIterations < timeBuckets)
131 timeBuckets = numberOfIterations;
132
133 for(int it = 0; it < numberOfIterations; it++) {
134#ifdef TTK_ENABLE_OPENMP
135#pragma omp parallel for num_threads(threadNumber_)
136#endif
137 for(SimplexId i = 0; i < vertexNumber; i++) {
138
139 // avoid to process masked vertices
140 if(mask_ != nullptr && mask_[i] == 0)
141 continue;
142
143 for(int j = 0; j < dimensionNumber_; j++) {
144 const auto curr{dimensionNumber_ * i + j};
145 tmpData[curr] = outputData[curr];
146
147 const auto neighborNumber = triangulation->getVertexNeighborNumber(i);
148 for(SimplexId k = 0; k < neighborNumber; k++) {
149 SimplexId neighborId = -1;
150 triangulation->getVertexNeighbor(i, k, neighborId);
151 tmpData[curr] += outputData[dimensionNumber_ * (neighborId) + j];
152 }
153 tmpData[curr] /= static_cast<double>(neighborNumber + 1);
154 }
155 }
156
157 if(numberOfIterations) {
158 // assign the tmpData back to the output
159 for(SimplexId i = 0; i < vertexNumber; i++) {
160 for(int j = 0; j < dimensionNumber_; j++) {
161 // only set value for unmasked points
162 if(mask_ == nullptr || mask_[i] != 0) {
163 outputData[dimensionNumber_ * i + j]
164 = tmpData[dimensionNumber_ * i + j];
165 }
166 }
167 }
168 }
169#ifdef TTK_ENABLE_MPI
170 if(ttk::isRunningWithMPI()) {
171 // after each iteration we need to exchange the ghostcell values with our
172 // neighbors
173 exchangeGhostVertices<dataType, triangulationType>(
174 outputData, triangulation, ttk::MPIcomm_, dimensionNumber_);
175 }
176#endif // TTK_ENABLE_MPI
177
178 if(debugLevel_ >= (int)(debug::Priority::INFO)) {
179 if(!(it % ((numberOfIterations) / timeBuckets))) {
180 printMsg("Smoothing " + std::to_string(vertexNumber) + " vertices",
181 (it / (float)numberOfIterations), t.getElapsedTime(),
183 }
184 }
185 }
186
187 printMsg("Smoothed " + std::to_string(vertexNumber) + " vertices", 1,
189
190 return 0;
191}
AbstractTriangulation is an interface class that defines an interface for efficient traversal methods...
int threadNumber_
Definition: BaseClass.h:95
Minimalist debugging class.
Definition: Debug.h:88
int debugLevel_
Definition: Debug.h:379
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
TTK processing package for scalar field smoothing.
void setMaskDataPointer(const char *const mask)
int preconditionTriangulation(AbstractTriangulation *triangulation)
void setDimensionNumber(const int &dimensionNumber)
void setOutputDataPointer(void *data)
~ScalarFieldSmoother() override
int smooth(const triangulationType *triangulation, const int &numberOfIterations) const
void setInputDataPointer(void *data)
double getElapsedTime()
Definition: Timer.h:15
The Topology ToolKit.
int SimplexId
Identifier type for simplices of any dimension.
Definition: DataTypes.h:22