TTK
Loading...
Searching...
No Matches
Quadrangulation.cpp
Go to the documentation of this file.
1#include <Quadrangulation.h>
2
3#include <OneSkeleton.h>
4#include <ZeroSkeleton.h>
5
9
11
12 this->preconditionEdges();
13
14 ZeroSkeleton zsk{};
15 zsk.setDebugLevel(this->debugLevel_);
16 zsk.setThreadNumber(this->threadNumber_);
17
18 return zsk.buildVertexNeighbors(
19 this->nVerts_, this->vertexNeighbors_, this->edges_);
20}
21
23
24 ZeroSkeleton zsk{};
25 zsk.setDebugLevel(this->debugLevel_);
26 zsk.setThreadNumber(this->threadNumber_);
27
28 return zsk.buildVertexStars(
29 this->nVerts_, this->buildQuadOffsets(), this->vertexStars_);
30}
31
33
34 OneSkeleton osk{};
35 osk.setDebugLevel(this->debugLevel_);
36 osk.setThreadNumber(this->threadNumber_);
37
38 return osk.buildEdgeList(this->nVerts_, this->buildQuadOffsets(),
39 this->edges_, this->edgeStars_, this->quadEdges_);
40}
41
42ttk::CellArray ttk::Quadrangulation::buildQuadOffsets() {
43
44 if(static_cast<SimplexId>(this->quadOffsets_.size()) != this->nCells_ + 1) {
45 this->quadOffsets_.resize(this->nCells_ + 1);
46 this->quadOffsets_[0] = 0;
47#ifdef TTK_ENABLE_OPENMP
48#pragma omp parallel for num_threads(this->threadNumber_)
49#endif // TTK_ENABLE_OPENMP
50 for(SimplexId i = 0; i < this->nCells_; ++i) {
51 this->quadOffsets_[i + 1] = this->cells_[i].size() * (i + 1);
52 }
53 }
54
55 return CellArray{this->cells_[0].data(), this->quadOffsets_.data(),
56 static_cast<LongSimplexId>(this->nCells_)};
57}
58
60 std::vector<SimplexId> &vertsValence,
61 std::vector<float> &vertsDensity,
62 std::vector<float> &vertsDeformity,
63 std::vector<float> &quadArea,
64 std::vector<float> &quadDiagsRatio,
65 std::vector<float> &quadEdgesRatio,
66 std::vector<float> &quadAnglesRatio) const {
67
68 Timer tm;
69
70 vertsValence.resize(this->nVerts_);
71 vertsDensity.resize(this->nVerts_);
72 vertsDeformity.resize(this->nVerts_);
73
74#ifdef TTK_ENABLE_OPENMP
75#pragma omp parallel for num_threads(this->threadNumber_)
76#endif // TTK_ENABLE_OPENMP
77 for(SimplexId i = 0; i < this->nVerts_; ++i) {
78 vertsValence[i] = this->getVertexNeighborNumber(i);
79 }
80
81#ifdef TTK_ENABLE_OPENMP
82#pragma omp parallel for num_threads(this->threadNumber_)
83#endif // TTK_ENABLE_OPENMP
84 for(SimplexId i = 0; i < this->nVerts_; ++i) {
85 this->computeDensityAndDeformity(i, vertsDensity[i], vertsDeformity[i]);
86 }
87
88 quadArea.resize(this->nCells_);
89 quadDiagsRatio.resize(this->nCells_);
90 quadEdgesRatio.resize(this->nCells_);
91 quadAnglesRatio.resize(this->nCells_);
92
93#ifdef TTK_ENABLE_OPENMP
94#pragma omp parallel for num_threads(this->threadNumber_)
95#endif // TTK_ENABLE_OPENMP
96 for(SimplexId i = 0; i < this->nCells_; ++i) {
97 const auto &q = this->cells_[i];
98 const auto &pi = this->vertCoords_[q[0]];
99 const auto &pj = this->vertCoords_[q[1]];
100 const auto &pk = this->vertCoords_[q[2]];
101 const auto &pl = this->vertCoords_[q[3]];
102
103 // quadrangle area
104 float area0{}, area1{};
105 Geometry::computeTriangleArea(pi.data(), pj.data(), pk.data(), area0);
106 Geometry::computeTriangleArea(pi.data(), pk.data(), pl.data(), area1);
107 quadArea[i] = area0 + area1;
108
109 // diagonals ratio
110 const auto diag0 = Geometry::distance(pi.data(), pk.data());
111 const auto diag1 = Geometry::distance(pj.data(), pl.data());
112 quadDiagsRatio[i] = std::min(diag0, diag1) / std::max(diag0, diag1);
113
114 // edges ratio
115 const std::array<float, 4> edges{
116 Geometry::distance(pi.data(), pj.data()), // ij
117 Geometry::distance(pj.data(), pk.data()), // jk
118 Geometry::distance(pk.data(), pl.data()), // kl
119 Geometry::distance(pl.data(), pi.data()), // li
120 };
121 quadEdgesRatio[i] = *std::min_element(edges.begin(), edges.end())
122 / *std::max_element(edges.begin(), edges.end());
123
124 // angles ratio
125 const std::array<float, 4> angles{
126 Geometry::angle(pi.data(), pl.data(), pi.data(), pj.data()), // lij
127 Geometry::angle(pj.data(), pi.data(), pj.data(), pk.data()), // ijk
128 Geometry::angle(pk.data(), pj.data(), pk.data(), pl.data()), // jkl
129 Geometry::angle(pl.data(), pk.data(), pl.data(), pi.data()), // kli
130 };
131
132 const auto min_max{std::minmax_element(angles.begin(), angles.end())};
133 quadAnglesRatio[i] = *min_max.first / *min_max.second;
134 }
135
136 // compute ratio between quad area and mean quad area
137
138 // global surface area
139 float sumArea{};
140 for(const auto a : quadArea) {
141 sumArea += a;
142 }
143 for(auto &a : quadArea) {
144 a *= quadArea.size() / sumArea;
145 }
146
147 this->printMsg("Computed statistics", 1.0, tm.getElapsedTime(),
148 this->threadNumber_, debug::LineMode::NEW,
150}
SimplexId PeriodicImplicitTriangulation::TTK_TRIANGULATION_INTERNAL() getVertexNeighborNumber(const SimplexId &vertexId) const
CellArray generic array of cells
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
virtual int setDebugLevel(const int &debugLevel)
Definition Debug.cpp:147
OneSkeleton processing package.
Definition OneSkeleton.h:25
void computeStatistics(std::vector< SimplexId > &vertsValence, std::vector< float > &vertsDensity, std::vector< float > &vertsDifformity, std::vector< float > &quadArea, std::vector< float > &quadDiagsRatio, std::vector< float > &quadEdgesRatio, std::vector< float > &quadAnglesRatio) const
double getElapsedTime()
Definition Timer.h:15
ZeroSkeleton processing package.
int computeTriangleArea(const T *p0, const T *p1, const T *p2, T &area)
Definition Geometry.cpp:281
T angle(const T *vA0, const T *vA1, const T *vB0, const T *vB1)
Definition Geometry.cpp:13
T distance(const T *p0, const T *p1, const int &dimension=3)
Definition Geometry.cpp:362
long long int LongSimplexId
Identifier type for simplices of any dimension.
Definition DataTypes.h:15
int SimplexId
Identifier type for simplices of any dimension.
Definition DataTypes.h:22
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)