TTK
Loading...
Searching...
No Matches
TopologicalSimplification.h
Go to the documentation of this file.
1
107
108#pragma once
109
110// base code includes
111
112#include <Debug.h>
116#include <Triangulation.h>
117
118#include <cmath>
119#include <set>
120#include <tuple>
121#include <type_traits>
122
123namespace ttk {
124
125 class TopologicalSimplification : virtual public Debug {
126 public:
128
129 enum class BACKEND { LEGACY, LTS, TO };
130 /*
131 * Either execute this file "legacy" algorithm, or the
132 * lts algorithm. The choice depends on the value of the variable backend_.
133 * Default is lts (localized).
134 */
135 template <typename dataType, typename triangulationType>
136 int execute(const dataType *const inputScalars,
137 dataType *const outputScalars,
138 const SimplexId *const identifiers,
139 const SimplexId *const inputOffsets,
140 SimplexId *const offsets,
141 const SimplexId constraintNumber,
142 const bool addPerturbation,
143 triangulationType &triangulation,
144 const ttk::DiagramType &constraintDiagram = {});
145
146 inline void setBackend(const BACKEND arg) {
147 backend_ = arg;
148 }
149
151 switch(backend_) {
152 case BACKEND::LEGACY:
153 legacyObject_.setDebugLevel(debugLevel_);
154 legacyObject_.setThreadNumber(threadNumber_);
155 legacyObject_.preconditionTriangulation(triangulation);
156 break;
157
158 case BACKEND::LTS:
159 ltsObject_.setDebugLevel(debugLevel_);
160 ltsObject_.setThreadNumber(threadNumber_);
161 ltsObject_.preconditionTriangulation(triangulation);
162 break;
163
164 case BACKEND::TO:
165 topologyOptimizer_.setDebugLevel(debugLevel_);
166 topologyOptimizer_.setThreadNumber(threadNumber_);
167 topologyOptimizer_.preconditionTriangulation(triangulation);
168 break;
169
170 default:
171 this->printErr(
172 "Error, the backend for topological simplification is invalid");
173 return -1;
174 }
175 return 0;
176 }
177
178 protected:
183
187 int EpochNumber{1000};
188
189 // if PDCMethod == 0 then we use Progressive approach
190 // if PDCMethod == 1 then we use Classical Auction approach
191 int PDCMethod{1};
192
193 // if MethodOptimization == 0 then we use direct optimization
194 // if MethodOptimization == 1 then we use Adam
196
197 // if FinePairManagement == 0 then we let the algorithm choose
198 // if FinePairManagement == 1 then we fill the domain
199 // if FinePairManagement == 2 then we cut the domain
201
202 // Adam
204 double LearningRate{0.0001};
205
206 // Direct Optimization : Gradient Step Size
207 double Alpha{0.5};
208
209 // Stopping criterion: when the loss becomes less than a percentage (e.g.
210 // 1%) of the original loss (between input diagram and simplified diagram)
211 double CoefStopCondition{0.01};
212
213 //
216 double Threshold{0.01};
220
222
224 };
225} // namespace ttk
226
227template <typename dataType, typename triangulationType>
229 const dataType *const inputScalars,
230 dataType *const outputScalars,
231 const SimplexId *const identifiers,
232 const SimplexId *const inputOffsets,
233 SimplexId *const offsets,
234 const SimplexId constraintNumber,
235 const bool addPerturbation,
236 triangulationType &triangulation,
237 const ttk::DiagramType &constraintDiagram) {
238 switch(backend_) {
239 case BACKEND::LTS:
240 return ltsObject_
241 .removeUnauthorizedExtrema<dataType, SimplexId, triangulationType>(
242 outputScalars, offsets, &triangulation, identifiers, constraintNumber,
243 addPerturbation);
244 case BACKEND::LEGACY:
245 return legacyObject_.execute(inputScalars, outputScalars, identifiers,
246 inputOffsets, offsets, constraintNumber,
247 triangulation);
248
249 case BACKEND::TO:
250 topologyOptimizer_.setUseFastPersistenceUpdate(UseFastPersistenceUpdate);
251 topologyOptimizer_.setFastAssignmentUpdate(FastAssignmentUpdate);
252 topologyOptimizer_.setEpochNumber(EpochNumber);
253 topologyOptimizer_.setPDCMethod(PDCMethod);
254 topologyOptimizer_.setMethodOptimization(MethodOptimization);
255 topologyOptimizer_.setFinePairManagement(FinePairManagement);
256 topologyOptimizer_.setChooseLearningRate(ChooseLearningRate);
257 topologyOptimizer_.setLearningRate(LearningRate);
258 topologyOptimizer_.setAlpha(Alpha);
259 topologyOptimizer_.setCoefStopCondition(CoefStopCondition);
260 topologyOptimizer_.setOptimizationWithoutMatching(
262 topologyOptimizer_.setThresholdMethod(ThresholdMethod);
263 topologyOptimizer_.setThresholdPersistence(Threshold);
264 topologyOptimizer_.setLowerThreshold(LowerThreshold);
265 topologyOptimizer_.setUpperThreshold(UpperThreshold);
266 topologyOptimizer_.setPairTypeToDelete(PairTypeToDelete);
267 topologyOptimizer_.setConstraintAveraging(ConstraintAveraging);
268 topologyOptimizer_.setPrintFrequency(PrintFrequency);
269
270 return topologyOptimizer_.execute(inputScalars, outputScalars, offsets,
271 &triangulation, constraintDiagram);
272 default:
273 this->printErr(
274 "Error, the backend for topological simplification is invalid");
275 return -1;
276 }
277}
AbstractTriangulation is an interface class that defines an interface for efficient traversal methods...
int debugLevel_
Definition Debug.h:379
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 the topological simplification of scalar data.
LegacyTopologicalSimplification legacyObject_
int preconditionTriangulation(AbstractTriangulation *triangulation)
lts::LocalizedTopologicalSimplification ltsObject_
int execute(const dataType *const inputScalars, dataType *const outputScalars, const SimplexId *const identifiers, const SimplexId *const inputOffsets, SimplexId *const offsets, const SimplexId constraintNumber, const bool addPerturbation, triangulationType &triangulation, const ttk::DiagramType &constraintDiagram={})
ttk::TopologicalOptimization topologyOptimizer_
TTK base package defining the standard types.
int SimplexId
Identifier type for simplices of any dimension.
Definition DataTypes.h:22
std::vector< PersistencePair > DiagramType
Persistence Diagram type as a vector of Persistence pairs.