5 #include <cgv/utils/progression.h>
6 #include <cgv/math/qem.h>
7 #include <cgv/math/mfunc.h>
8 #include <cgv/media/axis_aligned_box.h>
9 #include "streaming_mesh.h"
19 greater_equal(
const T& _value) : reference_value(_value) {}
20 bool operator () (
const T& _value)
const {
return _value >= reference_value; }
27 equal(
const T& _value) : reference_value(_value) {}
28 bool operator () (
const T& _value)
const {
return _value == reference_value; }
33 template <
typename T,
class P>
38 std::vector<bool> flags;
39 std::vector<int> indices;
41 c_slice_info(
unsigned int _resx,
unsigned int _resy) : resx(_resx), resy(_resy) {
42 unsigned int n = resx*resy;
43 flags.resize(n,
false);
44 indices.resize(n, -1);
49 std::fill(flags.begin(), flags.end(),
false);
50 std::fill(indices.begin(), indices.end(), -1);
53 int linear_index(
int x,
int y)
const {
return y*resx + x; }
55 bool flag(
int x,
int y)
const {
return (x>=0) && (y>=0) && flags[linear_index(x, y)]; }
57 void set_flag(
int x,
int y,
bool flag) { flags[linear_index(x, y)] = flag; }
59 const int& index(
int x,
int y)
const {
return indices[linear_index(x, y)]; }
60 void set_index(
int x,
int y,
int idx) {
61 indices[linear_index(x,y)] = idx;
67 template <
typename X,
typename T,
class P>
78 unsigned int resx, resy, resz;
88 func(_func), pred(_pred)
107 for (j = 0, p(1) = minp(1); j <= resy; ++j, p(1) += d(1)) {
108 for (i = 0, p(0) = minp(0); i <= resx; ++i, p(0) += d(0)) {
110 I[0]->set_flag(i, j, i < resx && j < resy && pred(func.
evaluate(p.
to_vec())));
112 bool need_vertex =
false;
113 need_vertex = need_vertex || (I[0]->flag(i, j) != I[1]->flag(i, j));
114 need_vertex = need_vertex || (I[0]->flag(i, j) != I[0]->flag(i, j - 1));
115 need_vertex = need_vertex || (I[1]->flag(i, j) != I[1]->flag(i, j - 1));
116 need_vertex = need_vertex || (I[0]->flag(i, j) != I[0]->flag(i - 1, j));
117 need_vertex = need_vertex || (I[1]->flag(i, j) != I[1]->flag(i - 1, j));
119 need_vertex = need_vertex || (I[0]->flag(i - 1, j) != I[1]->flag(i - 1, j));
120 need_vertex = need_vertex || (I[0]->flag(i - 1, j) != I[0]->flag(i - 1, j - 1));
121 need_vertex = need_vertex || (I[1]->flag(i - 1, j) != I[1]->flag(i - 1, j - 1));
123 need_vertex = need_vertex || (I[0]->flag(i - 1, j - 1) != I[1]->flag(i - 1, j - 1));
127 need_vertex = need_vertex || (I[0]->flag(i, j - 1) != I[1]->flag(i - 1, j));
128 need_vertex = need_vertex || (I[0]->flag(i, j - 1) != I[0]->flag(i - 1, j - 1));
129 need_vertex = need_vertex || (I[1]->flag(i, j - 1) != I[1]->flag(i - 1, j - 1));
133 I[0]->set_index(i, j,
new_vertex(p - T(0.5)*d));
137 for (j = 0, p(1) = minp(1); j <= resy; ++j, p(1) += d(1)) {
138 for (i = 0, p(0) = minp(0); i <= resx; ++i, p(0) += d(0)) {
139 if ((j < resy) && (I[1]->flag(i - 1, j) != I[1]->flag(i, j)))
140 generate_edge_quad(I[1]->index(i, j), I[1]->index(i, j + 1), I[0]->index(i, j + 1), I[0]->index(i, j), I[1]->flag(i, j));
141 if ((i < resx) && (I[1]->flag(i, j - 1) != I[1]->flag(i, j)))
142 generate_edge_quad(I[1]->index(i, j), I[0]->index(i, j), I[0]->index(i + 1, j), I[1]->index(i + 1, j), I[1]->flag(i, j));
143 if ((i < resx) && (j < resy) && (I[1]->flag(i, j) != I[0]->flag(i, j)))
144 generate_edge_quad(I[0]->index(i, j), I[0]->index(i + 1, j), I[0]->index(i + 1, j + 1), I[0]->index(i, j + 1), I[0]->flag(i, j));
150 unsigned int _resx,
unsigned int _resy,
unsigned int _resz,
151 bool show_progress =
false)
154 resx = _resx; resy = _resy; resz = _resz;
157 d(0) /= (resx-1); d(1) /= (resy-1); d(2) /= (resz-1);
162 prog.init(
"extraction", resz+1, 10);
167 for (
unsigned k=0; k<=resz; ++k, p(2) += d(2)) {
173 std::swap(I[0], I[1]);