Voxomap
A C++11 voxel container.
example_array_area.cpp
Go to the documentation of this file.
1 
5 #include <iostream>
7 #include "voxel_octree/ArrayArea.hpp"
8 
9 // First, we begin by define a user data structure (voxel data)
10 struct UserData
11 {
12  // Constructor
13  UserData(int value = 0) : value(value)
14  {
15  }
16 
17  // Bool operator used by ArrayArea to determine if the voxel is empty or not
18  operator bool() const
19  {
20  return value != 0;
21  }
22 
23  // Attribute of the voxel
24  int64_t value = 0;
25 };
26 
27 void main()
28 {
29  // Create the voxel container
30  // Use ArrayArea as voxel leaf structure
32 
33  // Add a voxel at position 0, 0, 0 with value 42
34  voxel_octree.addVoxel(0, 0, 0, 42);
35 
36  // Update value of voxel at position 0, 0, 0 with value 43
37  voxel_octree.updateVoxel(0, 0, 0, 43);
38 
39  // Declare iterator
41 
42  // Get iterator on voxel at position 0, 0, 0
43  it = voxel_octree.findVoxel(0, 0, 0);
44 
45  if (it)
46  {
47  // Get the node where the voxel is
49  node = it.node;
50 
51  // Get the voxel area where the voxel is
52  voxomap::ArrayArea<UserData>* area = it.getArea();
53 
54  // Write the internal position of the voxel is inside the node and its value
55  std::cout << "x: " << int(it.x) << " y: " << int(it.y) << " z: " << int(it.z) << " value: " << it.voxel->value << std::endl;
56  }
57 
58  // Remove voxel at position 0, 0, 0
59  voxel_octree.removeVoxel(0, 0, 0);
60 }
voxomap::VoxelOctree::findVoxel
iterator findVoxel(T x, T y, T z)
Returns a voxel iterator.
VoxelOctree.hpp
voxomap::VoxelOctree::removeVoxel
bool removeVoxel(T x, T y, T z, Args &&... args)
Removes a voxel.
voxomap::VoxelOctree::addVoxel
std::pair< iterator, bool > addVoxel(T x, T y, T z, Args &&... args)
Add the voxel if not exist.
voxomap::VoxelNode
Node optimized for voxel.
Definition: VoxelNode.hpp:14
voxomap::VoxelOctree
Octree optimized for voxel.
Definition: VoxelOctree.hpp:17
voxomap::VoxelOctree::updateVoxel
iterator updateVoxel(T x, T y, T z, Args &&... args)
Update the voxel if already exist.