PolyFEM
Loading...
Searching...
No Matches
EdgeSampler.cpp
Go to the documentation of this file.
1#include "EdgeSampler.hpp"
2
3#include <cassert>
4
5namespace polyfem
6{
7 namespace utils
8 {
9 void EdgeSampler::sample_2d_cube(const int resolution, Eigen::MatrixXd &samples)
10 {
11 samples.resize(4 * resolution, 2);
12
13 const Eigen::MatrixXd t = Eigen::VectorXd::LinSpaced(resolution, 0, 1);
14 samples.setConstant(-1);
15
16 int n = 0;
17 samples.block(n, 0, resolution, 1) = Eigen::MatrixXd::Ones(resolution, 1);
18 samples.block(n, 1, resolution, 1) = t;
19 n += resolution;
20
21 samples.block(n, 0, resolution, 1) = t;
22 samples.block(n, 1, resolution, 1) = Eigen::MatrixXd::Ones(resolution, 1);
23 n += resolution;
24
25 samples.block(n, 0, resolution, 1) = Eigen::MatrixXd::Zero(resolution, 1);
26 samples.block(n, 1, resolution, 1) = t;
27 n += resolution;
28
29 samples.block(n, 0, resolution, 1) = t;
30 samples.block(n, 1, resolution, 1) = Eigen::MatrixXd::Zero(resolution, 1);
31 n += resolution;
32
33 assert(long(n) == samples.rows());
34 assert(samples.minCoeff() >= 0);
35 assert(samples.maxCoeff() <= 1);
36 }
37
38 void EdgeSampler::sample_2d_simplex(const int resolution, Eigen::MatrixXd &samples)
39 {
40 samples.resize(3 * resolution, 2);
41
42 const Eigen::MatrixXd t = Eigen::VectorXd::LinSpaced(resolution, 0, 1);
43 samples.setConstant(-1);
44
45 int n = 0;
46 samples.block(n, 0, resolution, 1) = t;
47 samples.block(n, 1, resolution, 1) = Eigen::MatrixXd::Ones(resolution, 1) - t;
48 n += resolution;
49
50 samples.block(n, 0, resolution, 1) = Eigen::MatrixXd::Zero(resolution, 1);
51 samples.block(n, 1, resolution, 1) = t;
52 n += resolution;
53
54 samples.block(n, 0, resolution, 1) = t;
55 samples.block(n, 1, resolution, 1) = Eigen::MatrixXd::Zero(resolution, 1);
56 n += resolution;
57
58 assert(long(n) == samples.rows());
59 assert(samples.minCoeff() >= 0);
60 assert(samples.maxCoeff() <= 1);
61 }
62
63 void EdgeSampler::sample_3d_simplex(const int resolution, Eigen::MatrixXd &samples)
64 {
65 samples.resize(6 * resolution, 3);
66 samples.setZero();
67 const Eigen::MatrixXd t = Eigen::VectorXd::LinSpaced(resolution, 0, 1);
68 const Eigen::MatrixXd oo = Eigen::VectorXd::Ones(resolution);
69 // X
70 int ii = 0;
71 samples.block(ii * resolution, 0, resolution, 1) = t;
72 samples.block(ii * resolution, 1, resolution, 1).setZero();
73 samples.block(ii * resolution, 2, resolution, 1).setZero();
74
75 // Y
76 ++ii;
77 samples.block(ii * resolution, 0, resolution, 1).setZero();
78 samples.block(ii * resolution, 1, resolution, 1) = t;
79 samples.block(ii * resolution, 2, resolution, 1).setZero();
80
81 // Z
82 ++ii;
83 samples.block(ii * resolution, 0, resolution, 1).setZero();
84 samples.block(ii * resolution, 1, resolution, 1).setZero();
85 samples.block(ii * resolution, 2, resolution, 1) = t;
86
87 ++ii;
88 samples.block(ii * resolution, 0, resolution, 1) = oo - t;
89 samples.block(ii * resolution, 1, resolution, 1) = t;
90 samples.block(ii * resolution, 2, resolution, 1).setZero();
91
92 ++ii;
93 samples.block(ii * resolution, 0, resolution, 1).setZero();
94 samples.block(ii * resolution, 1, resolution, 1) = oo - t;
95 samples.block(ii * resolution, 2, resolution, 1) = t;
96
97 ++ii;
98 samples.block(ii * resolution, 0, resolution, 1) = t;
99 samples.block(ii * resolution, 1, resolution, 1).setZero();
100 samples.block(ii * resolution, 2, resolution, 1) = oo - t;
101 }
102
103 void EdgeSampler::sample_3d_cube(const int resolution, Eigen::MatrixXd &samples)
104 {
105 samples.resize(12 * resolution, 3);
106 const Eigen::MatrixXd t = Eigen::VectorXd::LinSpaced(resolution, 0, 1);
107 // X
108 int ii = 0;
109 samples.block(ii * resolution, 0, resolution, 1) = t;
110 samples.block(ii * resolution, 1, resolution, 1).setZero();
111 samples.block(ii * resolution, 2, resolution, 1).setZero();
112
113 ++ii;
114 samples.block(ii * resolution, 0, resolution, 1) = t;
115 samples.block(ii * resolution, 1, resolution, 1).setOnes();
116 samples.block(ii * resolution, 2, resolution, 1).setZero();
117
118 ++ii;
119 samples.block(ii * resolution, 0, resolution, 1) = t;
120 samples.block(ii * resolution, 1, resolution, 1).setZero();
121 samples.block(ii * resolution, 2, resolution, 1).setOnes();
122
123 ++ii;
124 samples.block(ii * resolution, 0, resolution, 1) = t;
125 samples.block(ii * resolution, 1, resolution, 1).setOnes();
126 samples.block(ii * resolution, 2, resolution, 1).setOnes();
127
128 // Y
129 ++ii;
130 samples.block(ii * resolution, 0, resolution, 1).setZero();
131 samples.block(ii * resolution, 1, resolution, 1) = t;
132 samples.block(ii * resolution, 2, resolution, 1).setZero();
133
134 ++ii;
135 samples.block(ii * resolution, 0, resolution, 1).setOnes();
136 samples.block(ii * resolution, 1, resolution, 1) = t;
137 samples.block(ii * resolution, 2, resolution, 1).setZero();
138
139 ++ii;
140 samples.block(ii * resolution, 0, resolution, 1).setZero();
141 samples.block(ii * resolution, 1, resolution, 1) = t;
142 samples.block(ii * resolution, 2, resolution, 1).setOnes();
143
144 ++ii;
145 samples.block(ii * resolution, 0, resolution, 1).setOnes();
146 samples.block(ii * resolution, 1, resolution, 1) = t;
147 samples.block(ii * resolution, 2, resolution, 1).setOnes();
148
149 // Z
150 ++ii;
151 samples.block(ii * resolution, 0, resolution, 1).setZero();
152 samples.block(ii * resolution, 1, resolution, 1).setZero();
153 samples.block(ii * resolution, 2, resolution, 1) = t;
154
155 ++ii;
156 samples.block(ii * resolution, 0, resolution, 1).setOnes();
157 samples.block(ii * resolution, 1, resolution, 1).setZero();
158 samples.block(ii * resolution, 2, resolution, 1) = t;
159
160 ++ii;
161 samples.block(ii * resolution, 0, resolution, 1).setZero();
162 samples.block(ii * resolution, 1, resolution, 1).setOnes();
163 samples.block(ii * resolution, 2, resolution, 1) = t;
164
165 ++ii;
166 samples.block(ii * resolution, 0, resolution, 1).setOnes();
167 samples.block(ii * resolution, 1, resolution, 1).setOnes();
168 samples.block(ii * resolution, 2, resolution, 1) = t;
169 }
170 } // namespace utils
171} // namespace polyfem
static void sample_3d_simplex(const int resolution, Eigen::MatrixXd &samples)
static void sample_3d_cube(const int resolution, Eigen::MatrixXd &samples)
static void sample_2d_cube(const int resolution, Eigen::MatrixXd &samples)
static void sample_2d_simplex(const int resolution, Eigen::MatrixXd &samples)