AGX Dynamics  2.38.0.2
VoxelGridUtils.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
19 #include <agx/Vec3.h>
20 
21 namespace agxTerrain
22 {
23  /*
24  This class deals with position-index conversions INSIDE the voxel grid.
25  A position in the grid, aka grid position or voxel space position, is not the
26  same as a local position in the terrain, which has it origo in the middle of
27  the terrain. The voxel space origo is situated in the "bottomleft" corner of
28  the terrain, coinciding with the terrain index (0, 0).
29  */
31  {
32  public:
33  /*
34  \param gridPosition - The position in voxel space.
35  \param voxelSize - The side length of a voxel in the grid.
36  \return the voxel index of the specified voxel space position.
37  */
38  static inline agx::Vec3i getVoxelIndexFromGridPosition(agx::Vec3 gridPosition, agx::Real voxelSize)
39  {
40  gridPosition *= (1.0 / voxelSize);
41  return agx::Vec3i( (agx::Int)std::floor(gridPosition.x() + 0.5),
42  (agx::Int)std::floor(gridPosition.y() + 0.5),
43  (agx::Int)std::floor(gridPosition.z() + 0.5) );
44  }
45 
46  /*
47  \param voxelIndex - the index of a voxel in grid.
48  \param voxelSize - The side length of a voxel in the grid.
49  \return the center position of the specified voxel in voxel space coordinates.
50  */
51  static inline agx::Vec3 getGridPositionFromVoxelIndex(agx::Vec3i voxelIndex, agx::Real voxelSize)
52  {
53  return agx::Vec3( static_cast<agx::Real>((voxelIndex.x()))* voxelSize,
54  static_cast<agx::Real>((voxelIndex.y()))* voxelSize,
55  static_cast<agx::Real>((voxelIndex.z()))* voxelSize );
56  }
57  };
58 }
agx::Real
double Real
Definition: Real.h:42
agxTerrain
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:58
agx::Vec3i
Vec3T< Int > Vec3i
Definition: Vec3.h:43
agxTerrain::VoxelGridUtils::getVoxelIndexFromGridPosition
static agx::Vec3i getVoxelIndexFromGridPosition(agx::Vec3 gridPosition, agx::Real voxelSize)
Definition: VoxelGridUtils.h:38
agx::Vec3T::y
T & y()
Definition: Vec3Template.h:499
agx::Int
int64_t Int
Definition: Integer.h:28
Vec3.h
agx::Vec3
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3.h:36
agx::Vec3T::x
T & x()
Definition: Vec3Template.h:493
agxTerrain::VoxelGridUtils
Definition: VoxelGridUtils.h:30
agx::Vec3T< Int >
agx::Vec3T::z
T & z()
Definition: Vec3Template.h:505
agxTerrain::VoxelGridUtils::getGridPositionFromVoxelIndex
static agx::Vec3 getGridPositionFromVoxelIndex(agx::Vec3i voxelIndex, agx::Real voxelSize)
Definition: VoxelGridUtils.h:51