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 const std::vector<bool> *updateMask = nullptr);
106
115 inline void setInputScalarField(const void *const data,
116 const size_t mTime) {
117 inputScalarField_ = std::make_pair(data, mTime);
118 }
119
124 if(data != nullptr) {
125 const auto dim{data->getDimensionality()};
126
131 data->preconditionEdges();
132 data->preconditionEdgeStars();
133 if(dim >= 2) {
135 }
136 if(dim == 2) {
137 data->preconditionCellEdges();
138 } else if(dim == 3) {
142 data->preconditionTriangles();
146 }
147 }
148 }
149
150 static inline void
151 clearCache(const AbstractTriangulation &triangulation) {
152 triangulation.gradientCache_.clear();
153 }
154
158 inline void setLocalGradient() {
159 this->gradient_ = &this->localGradient_;
160 }
161
172 inline void setInputOffsets(const SimplexId *const data) {
173 inputOffsets_ = data;
174 }
175
179 int getDimensionality() const;
180
185 int getNumberOfDimensions() const;
186
190 template <typename triangulationType>
191 SimplexId getNumberOfCells(const int dimension,
192 const triangulationType &triangulation) const;
193
197 template <typename triangulationType>
198 bool isBoundary(const Cell &cell,
199 const triangulationType &triangulation) const;
200
205 bool isCellCritical(const int cellDim, const SimplexId cellId) const;
206 bool isCellCritical(const Cell &cell) const;
207
212 template <typename triangulationType>
213 SimplexId getPairedCell(const Cell &cell,
214 const triangulationType &triangulation,
215 bool isReverse = false) const;
216
220 template <typename triangulationType>
221 int getAscendingPath(const Cell &cell,
222 std::vector<Cell> &vpath,
223 const triangulationType &triangulation,
224 const bool enableCycleDetector = false) const;
225
229 template <typename triangulationType>
230 int getDescendingPath(const Cell &cell,
231 std::vector<Cell> &vpath,
232 const triangulationType &triangulation) const;
233
238 template <typename triangulationType>
239 bool getDescendingPathThroughWall(const Cell &saddle2,
240 const Cell &saddle1,
241 const std::vector<bool> &isVisited,
242 std::vector<Cell> *const vpath,
243 const triangulationType &triangulation,
244 const bool stopIfMultiConnected = false,
245 const bool enableCycleDetector
246 = false) const;
247
252 template <typename triangulationType>
253 bool getAscendingPathThroughWall(const Cell &saddle1,
254 const Cell &saddle2,
255 const std::vector<bool> &isVisited,
256 std::vector<Cell> *const vpath,
257 const triangulationType &triangulation,
258 const bool stopIfMultiConnected = false,
259 const bool enableCycleDetector = false,
260 bool *const cycleFound = nullptr) const;
261
266 template <typename triangulationType>
267 bool detectGradientCycle(const Cell &cell,
268 const triangulationType &triangulation) const;
269
273 template <typename triangulationType>
274 int getDescendingWall(const Cell &cell,
275 VisitedMask &mask,
276 const triangulationType &triangulation,
277 std::vector<Cell> *const wall = nullptr,
278 std::vector<SimplexId> *const saddles
279 = nullptr) const;
280
284 template <typename triangulationType>
285 int getAscendingWall(const Cell &cell,
286 VisitedMask &mask,
287 const triangulationType &triangulation,
288 std::vector<Cell> *const wall = nullptr,
289 std::vector<SimplexId> *const saddles
290 = nullptr) const;
291
296 template <typename triangulationType>
299 const triangulationType &triangulation) const;
300
305 template <typename triangulationType>
308 const triangulationType &triangulation) const;
309
318 template <typename triangulationType>
320 const std::array<std::vector<SimplexId>, 4> &criticalCellsByDim,
321 std::vector<std::array<float, 3>> &points,
322 std::vector<char> &cellDimensions,
323 std::vector<SimplexId> &cellIds,
324 std::vector<char> &isOnBoundary,
325 std::vector<SimplexId> &PLVertexIdentifiers,
326 const triangulationType &triangulation) const;
327
332 template <typename triangulationType>
333 int setCriticalPoints(std::vector<std::array<float, 3>> &points,
334 std::vector<char> &cellDimensions,
335 std::vector<SimplexId> &cellIds,
336 std::vector<char> &isOnBoundary,
337 std::vector<SimplexId> &PLVertexIdentifiers,
338 const triangulationType &triangulation) const;
339
343 template <typename triangulationType>
345 std::array<std::vector<SimplexId>, 4> &criticalCellsByDim,
346 const triangulationType &triangulation) const;
347
348#ifdef TTK_ENABLE_MPI
352 void setCellToGhost(const int cellDim, const SimplexId cellId);
353
354#endif
358 int setManifoldSize(
359 const std::array<std::vector<SimplexId>, 4> &criticalCellsByDim,
360 const SimplexId *const ascendingManifold,
361 const SimplexId *const descendingManifold,
362 std::vector<SimplexId> &manifoldSize) const;
363
367 template <typename triangulationType>
368 int setGradientGlyphs(std::vector<std::array<float, 3>> &points,
369 std::vector<char> &points_pairOrigins,
370 std::vector<char> &cells_pairTypes,
371 std::vector<SimplexId> &cellsIds,
372 std::vector<char> &cellsDimensions,
373 const triangulationType &triangulation) const;
374
375 private:
379 using lowerStarType = std::array<std::vector<CellExt>, 4>;
380
390 template <typename triangulationType>
391 inline void lowerStar(lowerStarType &ls,
392 const SimplexId a,
393 const SimplexId *const offsets,
394 const triangulationType &triangulation) const;
395
405 template <typename triangulationType>
406 inline void lowerStarWithMask(lowerStarType &ls,
407 const SimplexId a,
408 const SimplexId *const offsets,
409 const triangulationType &triangulation,
410 const std::vector<bool> *updateMask
411 = nullptr) const;
412
422 std::pair<size_t, SimplexId>
423 numUnpairedFaces(const CellExt &c, const lowerStarType &ls) const;
424 std::pair<size_t, SimplexId>
425 numUnpairedFacesTriangle(const CellExt &c,
426 const lowerStarType &ls) const;
427 std::pair<size_t, SimplexId>
428 numUnpairedFacesTetra(const CellExt &c, const lowerStarType &ls) const;
429
434 CriticalType criticalTypeFromCellDimension(const int dim) const;
435
442 template <typename triangulationType>
443 inline void pairCells(CellExt &alpha,
444 CellExt &beta,
445 const triangulationType &triangulation);
446
453 template <typename triangulationType>
454 int processLowerStars(const SimplexId *const offsets,
455 const triangulationType &triangulation);
456
463 template <typename triangulationType>
464 int processLowerStarsWithMask(const SimplexId *const offsets,
465 const triangulationType &triangulation,
466 const std::vector<bool> *updateMask
467 = nullptr);
468
472 void initMemory(const AbstractTriangulation &triangulation);
473
474 public:
478 template <typename dataType, typename triangulationType>
479 dataType getPersistence(const Cell &up,
480 const Cell &down,
481 const dataType *const scalars,
482 const triangulationType &triangulation) const;
483
488 bool isMinimum(const Cell &cell) const;
489
494 bool isSaddle1(const Cell &cell) const;
495
500 bool isSaddle2(const Cell &cell) const;
501
506 bool isMaximum(const Cell &cell) const;
507
511 template <typename triangulationType>
512 int reverseAscendingPath(const std::vector<Cell> &vpath,
513 const triangulationType &triangulation) const;
514
518 template <typename triangulationType>
519 int reverseDescendingPath(const std::vector<Cell> &vpath,
520 const triangulationType &triangulation) const;
521
525 template <typename triangulationType>
526 int reverseAscendingPathOnWall(const std::vector<Cell> &vpath,
527 const triangulationType &triangulation,
528 bool cancelReversal = false) const;
529
533 template <typename triangulationType>
535 const std::vector<Cell> &vpath,
536 const triangulationType &triangulation) const;
537
538 protected:
541
542 // spare storage (bypass cache) for gradient internal structure
544 // cache key (scalar field pointer + timestamp)
546 // pointer to either cache entry corresponding to inputScalarField_ or
547 // localGradient_ (if cache is bypassed)
550 };
551
552 } // namespace dcg
553} // namespace ttk
554
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
int reverseAscendingPathOnWall(const std::vector< Cell > &vpath, const triangulationType &triangulation, bool cancelReversal=false) 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 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.
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
int buildGradient(const triangulationType &triangulation, bool bypassCache=false, const std::vector< bool > *updateMask=nullptr)
static void clearCache(const AbstractTriangulation &triangulation)
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, bool *const cycleFound=nullptr) const
void preconditionTriangulation(AbstractTriangulation *const data)
dataType getPersistence(const Cell &up, const Cell &down, const dataType *const scalars, const triangulationType &triangulation) const
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
bool detectGradientCycle(const Cell &cell, 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