VoxelLine.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <Eigen/Core>
4
5
6
namespace
visionx
7
{
8
9
/**
10
* @brief A line of voxels, from start voxel to an end voxel.
11
*
12
* Voxels are represented by their 3D integer index.
13
*
14
* Usage:
15
*
16
* (1) (a) Construct a VoxelLine line.
17
* (b) while !line.finished(), call line.next().
18
*
19
* (2) Call VoxelLine::getLineVoxels() to get all voxels at once.
20
*
21
*
22
* Uses Bresenham's algorithm for line drawing in 3D (i.e. drawing voxels).
23
*
24
* Implementation based on:
25
* https://www.geeksforgeeks.org/bresenhams-algorithm-for-3-d-line-drawing/
26
*/
27
class
VoxelLine
28
{
29
30
public
:
31
32
/// Construct an empty voxel line.
33
VoxelLine
();
34
35
/**
36
* @brief Construct a voxel line from start to end.
37
*
38
* @param start the start voxel
39
* @param end the end voxel
40
* @param includeStart if true, the start voxel is included in the result list
41
* @param includeEnd if true, the end voxel is included in the result list
42
*
43
* If `start` and `end` are equal and any of `includeStart` or
44
* `includeEnd` is true, the point is included.
45
*/
46
VoxelLine
(
const
Eigen::Vector3i& start,
const
Eigen::Vector3i& end,
47
bool
includeStart =
true
,
bool
includeEnd =
true
);
48
49
50
/// Indicate whether there are more voxels on the line.
51
bool
finished
()
const
;
52
53
/// Get the next voxel.
54
/// @throw `std::logic_error` if there are no more voxels (`this->finished()`)
55
Eigen::Vector3i
next
();
56
57
58
/// Get the voxels indices of the line from start to end.
59
/// @see `VoxelLine::VoxelLine()` (constructor)
60
static
std::vector<Eigen::Vector3i>
getLineVoxels
(
61
const
Eigen::Vector3i& start,
const
Eigen::Vector3i& end,
62
bool
includeStart =
true
,
bool
includeEnd =
true
);
63
64
65
private
:
66
67
using
Index = Eigen::Vector3i::Index;
68
static
const
Eigen::IOFormat iof;
69
70
71
void
init();
72
void
advance();
73
74
75
// INPUT
76
/// Start voxel.
77
Eigen::Vector3i start;
78
/// End voxel.
79
Eigen::Vector3i end;
80
81
/// Whether to include the start voxel.
82
bool
includeStart;
83
/// Whether to include the end voxel.
84
bool
includeEnd;
85
86
87
// COMPUTATION
88
89
Eigen::Vector3i delta;
///< The cwise absolute (end - start).
90
Eigen::Vector3i step;
///< Step directions (+1/-1).
91
92
Index x;
///< The driving axis.
93
Index y, z;
///< The two non-driving axes.
94
int
py, pz;
///< Slope error terms.
95
96
///< The current voxel (most recently returned).
97
Eigen::Vector3i _next;
98
bool
_finished =
false
;
99
100
};
101
102
}
visionx
ArmarX headers.
Definition:
OpenPoseStressTest.h:38
visionx::VoxelLine
A line of voxels, from start voxel to an end voxel.
Definition:
VoxelLine.h:27
visionx::VoxelLine::getLineVoxels
static std::vector< Eigen::Vector3i > getLineVoxels(const Eigen::Vector3i &start, const Eigen::Vector3i &end, bool includeStart=true, bool includeEnd=true)
Get the voxels indices of the line from start to end.
Definition:
VoxelLine.cpp:108
visionx::VoxelLine::next
Eigen::Vector3i next()
Get the next voxel.
Definition:
VoxelLine.cpp:94
visionx::VoxelLine::VoxelLine
VoxelLine()
Construct an empty voxel line.
Definition:
VoxelLine.cpp:12
visionx::VoxelLine::finished
bool finished() const
Indicate whether there are more voxels on the line.
Definition:
VoxelLine.cpp:89
VisionX
libraries
VoxelGridCore
VoxelLine.h
Generated on Sat Oct 12 2024 09:14:18 for armarx_documentation by
1.8.17