MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
volume.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 */
9
10#include "math/vector.h"
11#include "mve/marching_tets.h"
12#include "mve/marching_cubes.h"
13#include "mve/volume.h"
14
16
17VolumeMTAccessor::VolumeMTAccessor (void)
18 : iter(-1)
19{
20}
21
22/* ---------------------------------------------------------------- */
23
24bool
26{
27 std::size_t const width = static_cast<std::size_t>(this->vol->width());
28 std::size_t const height = static_cast<std::size_t>(this->vol->height());
29 std::size_t const depth = static_cast<std::size_t>(this->vol->depth());
30
31 this->iter += 1;
32 if (this->iter == (width - 1) * (height - 1) * (depth - 1) * 6)
33 return false;
34
35 int tet_id = static_cast<int>(this->iter % 6);
36 if (tet_id == 0)
37 this->load_new_cube();
38
39 for (int i = 0; i < 4; ++i)
40 {
41 int vertexid = mve::geom::mt_freudenthal[tet_id][i];
42 this->vid[i] = this->cube_vids[vertexid];
43 this->sdf[i] = this->vol->get_data()[this->vid[i]];
44 this->pos[i] = this->cube_pos[vertexid];
45 }
46
47 return true;
48}
49
50/* ---------------------------------------------------------------- */
51
52void
54{
55 int const width = this->vol->width();
56 int const height = this->vol->height();
57
58 int const base_x = (this->iter / 6) % (width - 1);
59 int const base_y = (this->iter / (6 * (width - 1))) % (height - 1);
60 int const base_z = (this->iter / (6 * (width - 1) * (height - 1)));
61 int const base = base_z * width * height + base_y * width + base_x;
62
63 float spacing = 1.0f / (float)(width - 1);
64
65 this->cube_vids[0] = base;
66 this->cube_vids[1] = base + 1;
67 this->cube_vids[2] = base + 1 + width * height;
68 this->cube_vids[3] = base + width * height;
69 this->cube_vids[4] = base + width;
70 this->cube_vids[5] = base + 1 + width;
71 this->cube_vids[6] = base + 1 + width + width * height;
72 this->cube_vids[7] = base + width + width * height;
73
74 /* Find 8 voxel positions. */
75 math::Vec3f basepos(base_x * spacing - 0.5f, base_y * spacing - 0.5f, base_z * spacing - 0.5f);
76 this->cube_pos[0] = basepos;
77 this->cube_pos[1] = basepos + math::Vec3f(spacing, 0, 0);
78 this->cube_pos[2] = basepos + math::Vec3f(spacing, 0, spacing);
79 this->cube_pos[3] = basepos + math::Vec3f(0, 0, spacing);
80 this->cube_pos[4] = basepos + math::Vec3f(0, spacing, 0);
81 this->cube_pos[5] = basepos + math::Vec3f(spacing, spacing, 0);
82 this->cube_pos[6] = basepos + math::Vec3f(spacing, spacing, spacing);
83 this->cube_pos[7] = basepos + math::Vec3f(0, spacing, spacing);
84}
85
86/* ---------------------------------------------------------------- */
87
89 : iter(-1)
90{
91}
92
93bool
95{
96 std::size_t const width = static_cast<std::size_t>(this->vol->width());
97 std::size_t const height = static_cast<std::size_t>(this->vol->height());
98 std::size_t const depth = static_cast<std::size_t>(this->vol->depth());
99
100 this->iter += 1;
101 if (this->iter == (width - 1) * (height - 1) * (depth - 1))
102 return false;
103
104 int const base_x = iter % (width - 1);
105 int const base_y = (iter / (width - 1)) % (height - 1);
106 int const base_z = iter / ((width - 1) * (height - 1));
107 int const base = base_z * width * height + base_y * width + base_x;
108
109 float spacing = 1.0f / (float)(width - 1);
110
111 this->vid[0] = base;
112 this->vid[1] = base + 1;
113 this->vid[2] = base + 1 + width * height;
114 this->vid[3] = base + width * height;
115 this->vid[4] = base + width;
116 this->vid[5] = base + 1 + width;
117 this->vid[6] = base + 1 + width + width * height;
118 this->vid[7] = base + width + width * height;
119
120 for (int i = 0; i < 8; ++i)
121 this->sdf[i] = this->vol->get_data()[this->vid[i]];
122
123 /* Find 8 voxel positions. */
124 math::Vec3f basepos(base_x * spacing - 0.5f,
125 base_y * spacing - 0.5f, base_z * spacing - 0.5f);
126 this->pos[0] = basepos;
127 this->pos[1] = basepos + math::Vec3f(spacing, 0, 0);
128 this->pos[2] = basepos + math::Vec3f(spacing, 0, spacing);
129 this->pos[3] = basepos + math::Vec3f(0, 0, spacing);
130 this->pos[4] = basepos + math::Vec3f(0, spacing, 0);
131 this->pos[5] = basepos + math::Vec3f(spacing, spacing, 0);
132 this->pos[6] = basepos + math::Vec3f(spacing, spacing, spacing);
133 this->pos[7] = basepos + math::Vec3f(0, spacing, spacing);
134
135 return true;
136}
137
138bool
140{
141 return false;
142}
143
Vector class for arbitrary dimensions and types.
Definition vector.h:87
bool next(void)
Definition volume.cc:94
math::Vec3f pos[8]
Definition volume.h:73
mve::FloatVolume::Ptr vol
Definition volume.h:70
std::size_t vid[8]
Definition volume.h:72
bool has_colors(void) const
Definition volume.cc:139
mve::FloatVolume::Ptr vol
Definition volume.h:93
void load_new_cube(void)
Definition volume.cc:53
bool next(void)
Definition volume.cc:25
math::Vec3f pos[4]
Definition volume.h:96
std::size_t vid[4]
Definition volume.h:95
#define MVE_NAMESPACE_BEGIN
Definition defines.h:13
#define MVE_NAMESPACE_END
Definition defines.h:14
Vector< float, 3 > Vec3f
Definition vector.h:31
int mt_freudenthal[6][4]
Freudenthal cube partitioning, that subdivides the cube into 6 tetrahera for continuous reconstructio...
Definition marching.cc:338