Voxomap
A C++11 voxel container.
example_find_voxel.cpp
Go to the documentation of this file.
1 
5 #include <iostream>
7 #include "voxel_octree/SmartArea.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  // Attribute of the voxel
18  int64_t value = 0;
19 };
20 
21 void main()
22 {
23  // Create the voxel container
24  // Use SmartArea as voxel leaf structure
26 
27  // Add voxels from position 0, 0, 0 to 42, 42, 42
28  int user_value = 1;
29  for (int x = 0; x < 42; ++x)
30  {
31  for (int y = 0; y < 42; ++y)
32  {
33  for (int z = 0; z < 42; ++z)
34  {
35  voxel_octree.addVoxel(x, y, z, user_value);
36  ++user_value;
37  }
38  }
39  }
40 
41  // Declare iterator
43 
44  // Get iterator on the voxel at position 10, 11, 12
45  it = voxel_octree.findVoxel(10, 11, 12);
46 
47  if (it)
48  {
49  // Get the node where the voxel is
51  node = it.node;
52 
53  // Get the voxel area where the voxel is
54  voxomap::SmartArea<UserData>* area = it.getArea();
55 
56  // Write the internal position of the voxel is inside the node and its value
57  std::cout << "x: " << int(it.x) << " y: " << int(it.y) << " z: " << int(it.z) << " value: " << it.voxel->value << std::endl;
58 
59  // Get iterator on the voxel at position -1, 0, 1 relative to the node position
60  auto tmp_it = node->findRelativeVoxel(-1, 0, 1);
61 
62  // Get iterator on voxels around the voxel at position 10, 11, 12
63  for (int ix = -1; ix <= 1; ++ix)
64  {
65  for (int iy = -1; iy <= 1; ++iy)
66  {
67  for (int iz = -1; iz <= 1; ++iz)
68  {
69  // Avoid to search the voxel at position 10, 11, 12
70  if (ix == 0 && iy == 0 && iz == 0)
71  continue;
72 
73  // Find voxel at position 10 + ix, 11 + iy, 12 + iz
74  tmp_it = node->findRelativeVoxel(ix + it.x, iy + it.y, iz + it.z);
75 
76  std::cout << "x: " << int(tmp_it.x) << " y: " << int(tmp_it.y) << " z: " << int(tmp_it.z) << " value: " << tmp_it.voxel->value << std::endl;
77 
78  }
79  }
80  }
81  }
82 }
voxomap::VoxelNode::findRelativeVoxel
iterator findRelativeVoxel(int x, int y, int z) const
Search voxel with position relative to the node position.
voxomap::VoxelOctree::findVoxel
iterator findVoxel(T x, T y, T z)
Returns a voxel iterator.
VoxelOctree.hpp
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