-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36311d9
commit 0fb3160
Showing
2 changed files
with
54 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "bonxai/bonxai.hpp" | ||
#include <iostream> | ||
|
||
int main() | ||
{ | ||
const double VOXEL_RESOLUTION = 0.1; | ||
|
||
Bonxai::VoxelGrid<int> grid(VOXEL_RESOLUTION); | ||
// to modify a grid, we need a mutable accessor | ||
auto accessor = grid.createAccessor(); | ||
|
||
int count = 0; | ||
for (double x = -0.5; x < 0.5; x += VOXEL_RESOLUTION) | ||
{ | ||
for (double y = -0.5; y < 0.5; y += VOXEL_RESOLUTION) | ||
{ | ||
for (double z = -0.5; z < 0.5; z += VOXEL_RESOLUTION) | ||
{ | ||
accessor.setValue(grid.posToCoord(x, y, z), count++); | ||
} | ||
} | ||
} | ||
|
||
// To iterate throught all the cells, we can use visitors. | ||
auto mutableVisitor = [](int& value, const Bonxai::CoordT&) | ||
{ | ||
value = 1; | ||
}; | ||
auto& gridRef = grid; | ||
gridRef.forEachCell(mutableVisitor); | ||
|
||
// Const version of the visitor | ||
auto constVisitor = [](const int& value, const Bonxai::CoordT&) | ||
{ | ||
if(value != 1) | ||
{ | ||
throw std::runtime_error("unexpected"); | ||
} | ||
}; | ||
const auto& gridConstRef = grid; | ||
gridConstRef.forEachCell(constVisitor); | ||
|
||
std::cout << "DONE\n"; | ||
return 0; | ||
} |