AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
VoxelGridUtils.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19#include <agx/Vec3.h>
20
21namespace 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}
static agx::Vec3i getVoxelIndexFromGridPosition(agx::Vec3 gridPosition, agx::Real voxelSize)
static agx::Vec3 getGridPositionFromVoxelIndex(agx::Vec3i voxelIndex, agx::Real voxelSize)
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition Geometry.h:59
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition agx/Vec3.h:36
Vec3T< Int > Vec3i
Definition agx/Vec3.h:43
double Real
Definition Real.h:42
int64_t Int
Definition Integer.h:28