TTK
Loading...
Searching...
No Matches
DiscreteGradient.h
Go to the documentation of this file.
1
15
16#pragma once
17
18// base code includes
19#include <Geometry.h>
20#include <Triangulation.h>
21#include <VisitedMask.h>
22
23#include <algorithm>
24#include <array>
25#include <functional>
26#include <queue>
27#include <set>
28#include <utility>
29
30namespace ttk {
31
32 namespace dcg {
37 struct Cell {
38 explicit Cell() = default;
39
40 explicit Cell(const int dim, const SimplexId id) : dim_{dim}, id_{id} {
41 }
42
43 inline bool operator==(const Cell &other) const {
44 return std::tie(this->dim_, this->id_)
45 == std::tie(other.dim_, other.id_);
46 }
47
48 inline std::string to_string() const {
49 return '{' + std::to_string(this->dim_) + ' '
50 + std::to_string(this->id_) + '}';
51 }
52
53 int dim_{-1};
55 };
56
58
62 struct CellExt : Cell {
63 explicit CellExt(const int dim, const SimplexId id) : Cell{dim, id} {
64 }
65 explicit CellExt(const int dim,
66 const SimplexId id,
67 const std::array<SimplexId, 3> &lowVerts,
68 const std::array<uint8_t, 3> &faces)
69 : Cell{dim, id}, lowVerts_{lowVerts}, faces_{faces} {
70 }
71
72 // (order field value on) lower vertices in current lower star
73 // (1 for edges, 2 for triangles, 3 for tetras)
74 const std::array<SimplexId, 3> lowVerts_{};
75 // indices of faces (cells of dimensions dim_ - 1) in lower star
76 // structure, only applicable for triangles (2 edge faces) and tetras (3
77 // triangle faces)
78 const std::array<uint8_t, 3> faces_{};
79 // if cell has been paired with another in current lower star
80 bool paired_{false};
81 };
82
88 class DiscreteGradient : virtual public Debug {
89
90 public:
92 this->setDebugMsgPrefix("DiscreteGradient");
93#ifdef TTK_ENABLE_MPI
94 hasMPISupport_ = true;
95#endif
96 }
97
102 template <typename triangulationType>
103 int buildGradient(const triangulationType &triangulation,
104 bool bypassCache = false);
105
114 inline void setInputScalarField(const void *const data,
115 const size_t mTime) {
116 inputScalarField_ = std::make_pair(data, mTime);
117 }
118
123 if(data != nullptr) {
124 const auto dim{data->getDimensionality()};
125
130 data->preconditionEdges();
131 data->preconditionEdgeStars();
132 if(dim >= 2) {
134 }
135 if(dim == 2) {
136 data->preconditionCellEdges();
137 } else if(dim == 3) {
141 data->preconditionTriangles();
145 }
146 }
147 }
148
149 static inline void
150 clearCache(const AbstractTriangulation &triangulation) {
151 triangulation.gradientCache_.clear();
152 }
153
157 inline void setLocalGradient() {
158 this->gradient_ = &this->localGradient_;
159 }
160
171 inline void setInputOffsets(const SimplexId *const data) {
172 inputOffsets_ = data;
173 }
174
178 int getDimensionality() const;
179
184 int getNumberOfDimensions() const;
185
189 template <typename triangulationType>
190 SimplexId getNumberOfCells(const int dimension,
191 const triangulationType &triangulation) const;
192
196 template <typename triangulationType>
197 bool isBoundary(const Cell &cell,
198 const triangulationType &triangulation) const;
199
204 bool isCellCritical(const int cellDim, const SimplexId cellId) const;
205 bool isCellCritical(const Cell &cell) const;
206
211 template <typename triangulationType>
212 SimplexId getPairedCell(const Cell &cell,
213 const triangulationType &triangulation,
214 bool isReverse = false) const;
215
219 template <typename triangulationType>
220 int getAscendingPath(const Cell &cell,
221 std::vector<Cell> &vpath,
222 const triangulationType &triangulation,
223 const bool enableCycleDetector = false) const;
224
228 template <typename triangulationType>
229 int getDescendingPath(const Cell &cell,
230 std::vector<Cell> &vpath,
231 const triangulationType &triangulation) const;
232
237 template <typename triangulationType>
238 bool getDescendingPathThroughWall(const Cell &saddle2,
239 const Cell &saddle1,
240 const std::vector<bool> &isVisited,
241 std::vector<Cell> *const vpath,
242 const triangulationType &triangulation,
243 const bool stopIfMultiConnected = false,
244 const bool enableCycleDetector
245 = false) const;
246
251 template <typename triangulationType>
252 bool getAscendingPathThroughWall(const Cell &saddle1,
253 const Cell &saddle2,
254 const std::vector<bool> &isVisited,
255 std::vector<Cell> *const vpath,
256 const triangulationType &triangulation,
257 const bool stopIfMultiConnected = false,
258 const bool enableCycleDetector
259 = false) const;
260
264 template <typename triangulationType>
265 int getDescendingWall(const Cell &cell,
266 VisitedMask &mask,
267 const triangulationType &triangulation,
268 std::vector<Cell> *const wall = nullptr,
269 std::vector<SimplexId> *const saddles
270 = nullptr) const;
271
275 template <typename triangulationType>
276 int getAscendingWall(const Cell &cell,
277 VisitedMask &mask,
278 const triangulationType &triangulation,
279 std::vector<Cell> *const wall = nullptr,
280 std::vector<SimplexId> *const saddles
281 = nullptr) const;
282
287 template <typename triangulationType>
290 const triangulationType &triangulation) const;
291
296 template <typename triangulationType>
299 const triangulationType &triangulation) const;
300
309 template <typename triangulationType>
311 const std::array<std::vector<SimplexId>, 4> &criticalCellsByDim,
312 std::vector<std::array<float, 3>> &points,
313 std::vector<char> &cellDimensions,
314 std::vector<SimplexId> &cellIds,
315 std::vector<char> &isOnBoundary,
316 std::vector<SimplexId> &PLVertexIdentifiers,
317 const triangulationType &triangulation) const;
318
323 template <typename triangulationType>
324 int setCriticalPoints(std::vector<std::array<float, 3>> &points,
325 std::vector<char> &cellDimensions,
326 std::vector<SimplexId> &cellIds,
327 std::vector<char> &isOnBoundary,
328 std::vector<SimplexId> &PLVertexIdentifiers,
329 const triangulationType &triangulation) const;
330
334 template <typename triangulationType>
336 std::array<std::vector<SimplexId>, 4> &criticalCellsByDim,
337 const triangulationType &triangulation) const;
338
339#ifdef TTK_ENABLE_MPI
343 void setCellToGhost(const int cellDim, const SimplexId cellId);
344
345#endif
349 int setManifoldSize(
350 const std::array<std::vector<SimplexId>, 4> &criticalCellsByDim,
351 const SimplexId *const ascendingManifold,
352 const SimplexId *const descendingManifold,
353 std::vector<SimplexId> &manifoldSize) const;
354
358 template <typename triangulationType>
359 int setGradientGlyphs(std::vector<std::array<float, 3>> &points,
360 std::vector<char> &points_pairOrigins,
361 std::vector<char> &cells_pairTypes,
362 std::vector<SimplexId> &cellsIds,
363 std::vector<char> &cellsDimensions,
364 const triangulationType &triangulation) const;
365
366 private:
370 using lowerStarType = std::array<std::vector<CellExt>, 4>;
371
381 template <typename triangulationType>
382 inline void lowerStar(lowerStarType &ls,
383 const SimplexId a,
384 const SimplexId *const offsets,
385 const triangulationType &triangulation) const;
386
396 std::pair<size_t, SimplexId>
397 numUnpairedFaces(const CellExt &c, const lowerStarType &ls) const;
398 std::pair<size_t, SimplexId>
399 numUnpairedFacesTriangle(const CellExt &c,
400 const lowerStarType &ls) const;
401 std::pair<size_t, SimplexId>
402 numUnpairedFacesTetra(const CellExt &c, const lowerStarType &ls) const;
403
408 CriticalType criticalTypeFromCellDimension(const int dim) const;
409
416 template <typename triangulationType>
417 inline void pairCells(CellExt &alpha,
418 CellExt &beta,
419 const triangulationType &triangulation);
420
427 template <typename triangulationType>
428 int processLowerStars(const SimplexId *const offsets,
429 const triangulationType &triangulation);
430
434 void initMemory(const AbstractTriangulation &triangulation);
435
436 public:
440 template <typename dataType, typename triangulationType>
441 dataType getPersistence(const Cell &up,
442 const Cell &down,
443 const dataType *const scalars,
444 const triangulationType &triangulation) const;
445
450 bool isMinimum(const Cell &cell) const;
451
456 bool isSaddle1(const Cell &cell) const;
457
462 bool isSaddle2(const Cell &cell) const;
463
468 bool isMaximum(const Cell &cell) const;
469
473 template <typename triangulationType>
474 int reverseAscendingPath(const std::vector<Cell> &vpath,
475 const triangulationType &triangulation) const;
476
480 template <typename triangulationType>
481 int reverseDescendingPath(const std::vector<Cell> &vpath,
482 const triangulationType &triangulation) const;
483
487 template <typename triangulationType>
489 const std::vector<Cell> &vpath,
490 const triangulationType &triangulation) const;
491
495 template <typename triangulationType>
497 const std::vector<Cell> &vpath,
498 const triangulationType &triangulation) const;
499
500 protected:
503
504 // spare storage (bypass cache) for gradient internal structure
506 // cache key (scalar field pointer + timestamp)
508 // pointer to either cache entry corresponding to inputScalarField_ or
509 // localGradient_ (if cache is bypassed)
512 };
513
514 } // namespace dcg
515} // namespace ttk
516
AbstractTriangulation is an interface class that defines an interface for efficient traversal methods...
std::pair< const void *, size_t > gradientKeyType
Key type for gradientCacheType.
virtual int getDimensionality() const
std::array< std::vector< gradIdType >, 6 > gradientType
Discrete gradient internal struct.
Minimalist debugging class.
Definition: Debug.h:88
void setDebugMsgPrefix(const std::string &prefix)
Definition: Debug.h:364
void clear()
Definition: Cache.h:38
TTK discreteGradient processing package.
SimplexId getCellLowerVertex(const Cell c, const triangulationType &triangulation) const
int reverseAscendingPath(const std::vector< Cell > &vpath, const triangulationType &triangulation) const
bool isMinimum(const Cell &cell) const
void setInputOffsets(const SimplexId *const data)
int reverseDescendingPath(const std::vector< Cell > &vpath, const triangulationType &triangulation) const
int setGradientGlyphs(std::vector< std::array< float, 3 > > &points, std::vector< char > &points_pairOrigins, std::vector< char > &cells_pairTypes, std::vector< SimplexId > &cellsIds, std::vector< char > &cellsDimensions, const triangulationType &triangulation) const
bool getDescendingPathThroughWall(const Cell &saddle2, const Cell &saddle1, const std::vector< bool > &isVisited, std::vector< Cell > *const vpath, const triangulationType &triangulation, const bool stopIfMultiConnected=false, const bool enableCycleDetector=false) const
bool isSaddle1(const Cell &cell) const
bool getAscendingPathThroughWall(const Cell &saddle1, const Cell &saddle2, const std::vector< bool > &isVisited, std::vector< Cell > *const vpath, const triangulationType &triangulation, const bool stopIfMultiConnected=false, const bool enableCycleDetector=false) const
bool isMaximum(const Cell &cell) const
bool isSaddle2(const Cell &cell) const
AbstractTriangulation::gradientKeyType inputScalarField_
int setManifoldSize(const std::array< std::vector< SimplexId >, 4 > &criticalCellsByDim, const SimplexId *const ascendingManifold, const SimplexId *const descendingManifold, std::vector< SimplexId > &manifoldSize) const
void setInputScalarField(const void *const data, const size_t mTime)
SimplexId getNumberOfCells(const int dimension, const triangulationType &triangulation) const
void setLocalGradient()
Use local storage instead of cache.
int reverseAscendingPathOnWall(const std::vector< Cell > &vpath, const triangulationType &triangulation) const
bool isBoundary(const Cell &cell, const triangulationType &triangulation) const
bool isCellCritical(const int cellDim, const SimplexId cellId) const
SimplexId getPairedCell(const Cell &cell, const triangulationType &triangulation, bool isReverse=false) const
int getAscendingWall(const Cell &cell, VisitedMask &mask, const triangulationType &triangulation, std::vector< Cell > *const wall=nullptr, std::vector< SimplexId > *const saddles=nullptr) const
int reverseDescendingPathOnWall(const std::vector< Cell > &vpath, const triangulationType &triangulation) const
SimplexId getCellGreaterVertex(const Cell c, const triangulationType &triangulation) const
int getCriticalPoints(std::array< std::vector< SimplexId >, 4 > &criticalCellsByDim, const triangulationType &triangulation) const
static void clearCache(const AbstractTriangulation &triangulation)
void preconditionTriangulation(AbstractTriangulation *const data)
dataType getPersistence(const Cell &up, const Cell &down, const dataType *const scalars, const triangulationType &triangulation) const
int buildGradient(const triangulationType &triangulation, bool bypassCache=false)
int setCriticalPoints(const std::array< std::vector< SimplexId >, 4 > &criticalCellsByDim, std::vector< std::array< float, 3 > > &points, std::vector< char > &cellDimensions, std::vector< SimplexId > &cellIds, std::vector< char > &isOnBoundary, std::vector< SimplexId > &PLVertexIdentifiers, const triangulationType &triangulation) const
int getDescendingPath(const Cell &cell, std::vector< Cell > &vpath, const triangulationType &triangulation) const
int getAscendingPath(const Cell &cell, std::vector< Cell > &vpath, const triangulationType &triangulation, const bool enableCycleDetector=false) const
AbstractTriangulation::gradientType localGradient_
int getDescendingWall(const Cell &cell, VisitedMask &mask, const triangulationType &triangulation, std::vector< Cell > *const wall=nullptr, std::vector< SimplexId > *const saddles=nullptr) const
AbstractTriangulation::gradientType * gradient_
const SimplexId * inputOffsets_
The Topology ToolKit.
CriticalType
default value for critical index
Definition: DataTypes.h:80
int SimplexId
Identifier type for simplices of any dimension.
Definition: DataTypes.h:22
Auto-cleaning re-usable graph propagations data structure.
Definition: VisitedMask.h:27
Extended Cell structure for processLowerStars.
CellExt(const int dim, const SimplexId id, const std::array< SimplexId, 3 > &lowVerts, const std::array< uint8_t, 3 > &faces)
CellExt(const int dim, const SimplexId id)
const std::array< SimplexId, 3 > lowVerts_
const std::array< uint8_t, 3 > faces_
std::string to_string() const
bool operator==(const Cell &other) const
Cell(const int dim, const SimplexId id)
Cell()=default