MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
voxel.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 <algorithm>
11
12#include "math/vector.h"
13#include "fssr/voxel.h"
14
16
17void
18VoxelIndex::from_path_and_corner (uint8_t level, uint64_t path, int corner)
19{
20 /* Compute node index from the node path. */
21 math::Vector<uint64_t, 3> coords(0, 0, 0);
22 for (int l = level - 1; l >= 0; --l)
23 {
24 uint64_t index = (path >> (3 * l)) & 7;
25 for (int i = 0; i < 3; ++i)
26 {
27 coords[i] = coords[i] << 1;
28 coords[i] += (index & (1 << i)) >> i;
29 }
30 }
31
32 /* Convert node index to voxel index. */
33 for (int i = 0; i < 3; ++i)
34 {
35 coords[i] += (corner >> i) & 1;
36 coords[i] = coords[i] << (20 - level);
37 }
38
39 /* Compute voxel ID. */
40 this->index = coords[0] | coords[1] << 21 | coords[2] << 42;
41}
42
44VoxelIndex::compute_position (math::Vec3d const& center, double size) const
45{
46 double const dim_max = static_cast<double>(1 << 20);
47 double const fx = static_cast<double>(this->get_offset_x()) / dim_max;
48 double const fy = static_cast<double>(this->get_offset_y()) / dim_max;
49 double const fz = static_cast<double>(this->get_offset_z()) / dim_max;
50 return center - size / 2.0 + math::Vec3d(fx, fy, fz) * size;
51}
52
53int32_t
54VoxelIndex::get_offset_x (void) const
55{
56 return static_cast<int32_t>((this->index >> 0) & 0x1fffff);
57}
58
59int32_t
60VoxelIndex::get_offset_y (void) const
61{
62 return static_cast<int32_t>((this->index >> 21) & 0x1fffff);
63}
64
65int32_t
66VoxelIndex::get_offset_z (void) const
67{
68 return static_cast<int32_t>((this->index >> 42) & 0x1fffff);
69}
70
71/* ---------------------------------------------------------------- */
72
74interpolate_voxel (VoxelData const& d1, float w1, VoxelData const& d2, float w2)
75{
76 VoxelData ret;
77 ret.value = w1 * d1.value + w2 * d2.value;
78 ret.conf = std::min(d1.conf, d2.conf);
79 ret.scale = w1 * d1.scale + w2 * d2.scale;
80 ret.color = w1 * d1.color + w2 * d2.color;
81 return ret;
82}
83
Vector class for arbitrary dimensions and types.
Definition vector.h:87
#define FSSR_NAMESPACE_END
Definition defines.h:14
#define FSSR_NAMESPACE_BEGIN
Definition defines.h:13
VoxelData interpolate_voxel(VoxelData const &d1, float w1, VoxelData const &d2, float w2)
Interpolates between two VoxelData objects for Marching Cubes.
Definition voxel.cc:74
Vector< double, 3 > Vec3d
Definition vector.h:39
Stores per voxel data.
Definition voxel.h:61
float conf
Definition voxel.h:67
math::Vec3f color
Definition voxel.h:69
float value
Definition voxel.h:66
float scale
Definition voxel.h:68