Voxomap
A C++11 voxel container.
example_sided_area.cpp
Go to the documentation of this file.
1 
6 #include <iostream>
8 #include "voxel_octree/SmartArea.hpp"
9 #include "voxel_octree/SidedArea.hpp"
10 
11 // First, we begin by define a user data structure (voxel data)
12 struct UserData
13 {
14  // Constructor
15  UserData(int value = 0) : value(value)
16  {
17  }
18 
19  // Method used by SidedArea to know if we have to merge the side between two neighbor voxel
20  bool mergeSide(UserData const& other) const
21  {
22  return true;
23  }
24 
25  // Attribute of the voxel
26  int64_t value = 0;
27 };
28 
29 // Typedef SmartArea to be use with SidedArea
30 template <typename T_Voxel>
31 using TypedefSmartArea = voxomap::SmartArea<T_Voxel>;
32 
33 void main()
34 {
35  // Create the voxel container
36  // Use SidedArea with SmartArea as voxel leaf structure
38 
39  // Add voxels from position 0, 0, 0 and 0, 1, 0 and 0, 0, 1
40  voxel_octree.addVoxel(0, 0, 0, 42);
41  voxel_octree.addVoxel(0, 1, 0, 1);
42  voxel_octree.addVoxel(0, 0, 1, 2);
43 
44  // Declare iterator
46 
47  // Get iterator on voxel at position 0, 0, 0
48  it = voxel_octree.findVoxel(0, 0, 0);
49 
50  if (it)
51  {
52  // Get the node where the voxel is
54  node = it.node;
55 
56  // Get the voxel area where the voxel is
57  voxomap::SidedArea<TypedefSmartArea, UserData>* area = it.getArea();
58 
59  // Get the voxel pointer
60  voxomap::SidedVoxel<UserData>* voxel = it.voxel;
61 
62  // Write number of side inside the area
63  std::cout << "Number of side: " << area->getNbSide() << std::endl;
64 
65  // Write the internal position of the voxel is inside the node and its value
66  std::cout << "x: " << int(it.x) << " y: " << int(it.y) << " z: " << int(it.z) << " value: " << voxel->value << " side: " << int(voxel->getSide()) << std::endl;
67 
68  // Use operator & of SidedVoxel structure
69  if (*voxel & voxomap::SideEnum::YPOS)
70  {
71  auto tmp_it = node->findVoxel(0, 1, 0);
72 
73  // Write the internal position of the voxel is inside the node and its value
74  std::cout << "x: " << int(tmp_it.x) << " y: " << int(tmp_it.y) << " z: " << int(tmp_it.z) << " value: " << tmp_it.voxel->value << " side: " << int(tmp_it.voxel->getSide()) << std::endl;
75  }
76  }
77 }
78 
voxomap::SidedVoxel::getSide
uint8_t getSide() const
Returns internal side.
voxomap::VoxelOctree::findVoxel
iterator findVoxel(T x, T y, T z)
Returns a voxel iterator.
VoxelOctree.hpp
voxomap::YPOS
@ YPOS
y + 1 of the voxel
Definition: SidedContainer.hpp:27
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::SidedVoxel
Voxel with side informations Side is present if the corresponding neighbor voxel exist....
Definition: SidedContainer.hpp:44
voxomap::VoxelNode::findVoxel
iterator findVoxel(int x, int y, int z)
Search voxel.