TTK
Loading...
Searching...
No Matches
ProjectionFromTable.h
Go to the documentation of this file.
1
16
17#pragma once
18
19// ttk common includes
20#include <Debug.h>
21#include <Geometry.h>
22#include <Triangulation.h>
23
24namespace ttk {
25
30 class ProjectionFromTable : virtual public Debug {
31
32 protected:
33 public:
35
36 template <class triangulationType, class xDataType, class yDataType>
38 const triangulationType *triangulation,
39 std::vector<std::tuple<int, double, double>> &surfaceValues,
40 std::array<const long, 2> &surfaceDim,
41 const xDataType *const tableXValues,
42 const yDataType *const tableYValues,
43 const size_t nTableValues,
44 std::vector<std::vector<double>> &inputPoints) {
45 unsigned int const noPoints = nTableValues;
46 inputPoints = std::vector<std::vector<double>>(
47 noPoints, std::vector<double>(3, 0.0));
48
49 // Find quadrant of each point
50 // 0 --- 2
51 // | |
52 // 1 --- 3
53 std::vector<std::array<int, 4>> quadPoints(noPoints);
54 for(unsigned int i = 0; i < noPoints; ++i) {
55 int i0 = 0, i1 = 0;
56 for(unsigned int j = 0; j < surfaceDim[0]; ++j)
57 if(std::get<1>(surfaceValues[j * surfaceDim[1]]) < tableXValues[i])
58 i0 = j;
59 for(unsigned int j = 0; j < surfaceDim[1]; ++j)
60 if(std::get<2>(surfaceValues[j]) < tableYValues[i])
61 i1 = j;
62 quadPoints[i][0] = i0 * surfaceDim[1] + i1 + 1;
63 quadPoints[i][1] = i0 * surfaceDim[1] + i1;
64 quadPoints[i][2] = (i0 + 1) * surfaceDim[1] + i1 + 1;
65 quadPoints[i][3] = (i0 + 1) * surfaceDim[1] + i1;
66 }
67
68 // Iterate through each point
69 std::vector<std::array<double, 4>> coef(noPoints);
70 for(unsigned int i = 0; i < noPoints; ++i) {
71 std::vector<std::array<double, 2>> points(4);
72 for(unsigned int j = 0; j < 4; ++j) {
73 points[j][0] = std::get<1>(surfaceValues[quadPoints[i][j]]);
74 points[j][1] = std::get<2>(surfaceValues[quadPoints[i][j]]);
75 }
76
77 // Find barycentric coordinates
78 std::array<double, 3> tableValues{static_cast<double>(tableXValues[i]),
79 static_cast<double>(tableYValues[i]),
80 0};
81 std::array<std::array<double, 3>, 3> trianglePoints;
82 std::array<int, 3> indexes;
83 std::array<double, 2> mid{(points[3][0] - points[1][0]) / 2.0,
84 (points[0][1] - points[1][1]) / 2.0};
85 if(tableXValues[i] > points[1][0] + mid[0]) {
86 indexes[0] = 2;
87 indexes[1] = 3;
88 if(tableYValues[i] > points[1][1] + mid[1])
89 indexes[2] = 0;
90 else
91 indexes[2] = 1;
92 } else {
93 indexes[0] = 0;
94 indexes[1] = 1;
95 if(tableYValues[i] > points[1][1] + mid[1])
96 indexes[2] = 2;
97 else
98 indexes[2] = 3;
99 }
100
101 for(unsigned int j = 0; j < 3; ++j) {
102 for(unsigned int k = 0; k < 2; ++k)
103 trianglePoints[j][k] = points[indexes[j]][k];
104 trianglePoints[j][2] = 0;
105 }
106
108 tableValues.data(), trianglePoints[0].data(),
109 trianglePoints[1].data(), coef[i][indexes[2]]);
111 tableValues.data(), trianglePoints[0].data(),
112 trianglePoints[2].data(), coef[i][indexes[1]]);
114 tableValues.data(), trianglePoints[1].data(),
115 trianglePoints[2].data(), coef[i][indexes[0]]);
116
117 double const sumArea
118 = coef[i][indexes[2]] + coef[i][indexes[1]] + coef[i][indexes[0]];
119 for(unsigned int j = 0; j < 3; ++j)
120 coef[i][indexes[j]] /= sumArea;
121
122 // Compute new point
123 for(unsigned int k = 0; k < 4; ++k) {
124 float surfacePoint[3];
125 triangulation->getVertexPoint(
126 std::get<0>(surfaceValues[quadPoints[i][k]]), surfacePoint[0],
127 surfacePoint[1], surfacePoint[2]);
128 for(unsigned int j = 0; j < 3; ++j)
129 inputPoints[i][j] += coef[i][k] * surfacePoint[j];
130 }
131 }
132 }
133 }; // ProjectionFromTable class
134
135} // namespace ttk
Minimalist debugging class.
Definition Debug.h:88
void computeInputPoints(const triangulationType *triangulation, std::vector< std::tuple< int, double, double > > &surfaceValues, std::array< const long, 2 > &surfaceDim, const xDataType *const tableXValues, const yDataType *const tableYValues, const size_t nTableValues, std::vector< std::vector< double > > &inputPoints)
int computeTriangleArea(const T *p0, const T *p1, const T *p2, T &area)
Definition Geometry.cpp:281
The Topology ToolKit.