TTK
Loading...
Searching...
No Matches
FTRScalars.h
Go to the documentation of this file.
1#pragma once
2
3#include "FTRCommon.h"
4#include "FTRDataTypes.h"
5
6#include <iostream>
7#include <memory>
8#include <vector>
9
10#include <Debug.h>
11
12namespace ttk {
13 namespace ftr {
14 template <typename ScalarType>
15 struct Vert {
17 ScalarType value;
18 };
19
20 template <typename ScalarType>
21 class Scalars : virtual public Debug {
22 private:
23 idVertex size_{nullVertex};
24
25 ScalarType *values_{};
26 const SimplexId *offsets_{};
27
28 std::vector<Vert<ScalarType>> vertices_{};
29
30 public:
31 Scalars() = default;
32
33 // Heavy, prevent using it
34 Scalars(const Scalars &o) = delete;
35
36 ScalarType *getScalars() {
37 return values_;
38 }
39
40 const SimplexId *getOffsets() const {
41 return offsets_;
42 }
43
44 idVertex getSize() const {
45 return size_;
46 }
47
48 ScalarType getVal(const idVertex i) const {
49 return values_[i];
50 }
51
53 return vertices_[i].id;
54 }
55
56 idVertex getMirror(const idVertex i) const {
57 return offsets_[i];
58 }
59
60 void setSize(const idVertex size) {
61 size_ = size;
62 }
63
64 void setScalars(ScalarType *values) {
65 values_ = values;
66 }
67
76 void setOffsets(const SimplexId *const sos) {
77 offsets_ = sos;
78 }
79
80 void alloc() {
81 vertices_.resize(size_);
82 }
83
84 void init() {
85 // Copy everything in the main array
86#ifdef TTK_ENABLE_OPENMP
87#pragma omp parallel for schedule(static, size_ / threadNumber_)
88#endif
89 for(idVertex i = 0; i < size_; i++) {
90 // ids and value sorted by offset value
91 // vertices_[0] -> global minimum
92 // vertices_[size_ - 1] -> global maximum
93 vertices_[offsets_[i]].id = i;
94 vertices_[offsets_[i]].value = values_[i];
95 }
96 }
97
98 void removeNaN() {
99 // This section is aimed to prevent un-deterministic results if the
100 // data-set have NaN values in it. In this loop, we replace every NaN by
101 // a 0 value. Recall: Equals values are distinguished using Simulation
102 // of Simplicity in the FTM tree computation Note: Can we detect NaN
103 // using vtk ?
104 if(std::numeric_limits<ScalarType>::has_quiet_NaN) {
105#ifdef TTK_ENABLE_OPENMP
106#pragma omp parallel for num_threads(threadNumber_) \
107 schedule(static, size_ / threadNumber_)
108#endif
109 for(idVertex i = 0; i < size_; i++) {
110 if(::std::isnan((double)values_[i])) {
111 values_[i] = 0;
112 }
113 }
114 }
115 }
116
117 // Need vertices to be sorted : use mirrorVertices.
118
119 bool isLower(const idVertex a, const idVertex b) const {
120 return offsets_[a] < offsets_[b];
121 }
122 bool isHigher(const idVertex a, const idVertex b) const {
123 return offsets_[a] > offsets_[b];
124 }
125 };
126 } // namespace ftr
127} // namespace ttk
Minimalist debugging class.
Definition: Debug.h:88
const SimplexId * getOffsets() const
Definition: FTRScalars.h:40
idVertex getMirror(const idVertex i) const
Definition: FTRScalars.h:56
void setSize(const idVertex size)
Definition: FTRScalars.h:60
idVertex getSortedVert(const idVertex i) const
Definition: FTRScalars.h:52
void setScalars(ScalarType *values)
Definition: FTRScalars.h:64
ScalarType * getScalars()
Definition: FTRScalars.h:36
bool isLower(const idVertex a, const idVertex b) const
Definition: FTRScalars.h:119
bool isHigher(const idVertex a, const idVertex b) const
Definition: FTRScalars.h:122
ScalarType getVal(const idVertex i) const
Definition: FTRScalars.h:48
void setOffsets(const SimplexId *const sos)
Definition: FTRScalars.h:76
Scalars(const Scalars &o)=delete
idVertex getSize() const
Definition: FTRScalars.h:44
SimplexId idVertex
Vertex index in scalars_.
Definition: FTRDataTypes.h:29
The Topology ToolKit.
int SimplexId
Identifier type for simplices of any dimension.
Definition: DataTypes.h:22
ScalarType value
Definition: FTRScalars.h:17
idVertex id
Definition: FTRScalars.h:16