71 if (json.get<
int>() < 0)
81 const std::string VoxelGrid::JSON_VOXEL_ARRAY_NAME =
"labels";
92 VoxelGrid::getUniqueLabels()
const
95 for (
const Voxel& voxel : *
this)
119 "Provided density grid has different structure, but adoptStructure is false.");
123 for (std::size_t i = 0; i <
numVoxels(); ++i)
138 VoxelGrid::writeJson(std::ostream& os)
const
144 VoxelGrid::writeJson(
const std::filesystem::path& file)
const
150 VoxelGrid::readJson(std::istream& is)
156 VoxelGrid::readJson(
const std::filesystem::path& file)
Voxel grid storing the number of points per label in each voxel.
Map of labels (object IDs) to number of points.
bool isFree() const
Indicate whether this voxel is free, i.e. it contains no points.
Label getMaxLabel() const
Get the label with most points.
Voxel grid storing the number of points per label in each voxel.
void setByLabelDensity(const LabelDensity::VoxelGrid &density, bool adoptStructure=false)
Set the voxels by selecting the label with most points for each voxel.
static const std::string JSON_VOXEL_ARRAY_NAME
Name of the single voxel array in JSON.
VoxelGrid()
Construct a voxel grid with 0 voxels of size 1.0.
A voxel storing whether it is occupied or free and the object label it is occupied by.
void setFree()
Set the voxel to free, i.e. unoccupied.
Voxel()
Construct an unoccupied voxel.
bool isOccupied() const
Indicate whether this voxel is occupied.
Label getLabel() const
Get the label. Voxel must be occupied.
bool isFree() const
Indicate whether this voxel is free (i.e. it is not occupied).
void setOccupied(Label label)
Set the voxel to occupied and set its label.
A 3D grid of voxels of type _VoxelT.
VoxelGridStructure getStructure() const
Get the voxel grid structure.
void resetStructure(const VoxelGridStructure &structure)
VoxelT & getVoxel(std::size_t index)
Get the voxel with the given index.
std::size_t numVoxels() const
Indicates that a voxel grid structure should have matched another one, but did not.
static void toJson(nlohmann::json &j, const VoxelGrid< VoxelT > &grid, const VoxelAttributeGetterMap< VoxelT > &attributeMap)
Serialize a voxel grid to JSON.
static void fromJson(const nlohmann::json &j, VoxelGrid< VoxelT > &grid, const VoxelAttributeSetterMap< VoxelT > &attributeMap)
Deserialize a voxel grid from JSON.
static nlohmann::json readJson(const std::string &filename)
Read JSON from file.
static void writeJson(const std::string &filename, const nlohmann::json &j, int indent=-1, char indentChar=' ')
Write JSON json to file.
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
void to_json(nlohmann::json &json, const Voxel &voxel)
Set json to the voxel's label if occupied, and to -1 if free.
void from_json(const nlohmann::json &json, Voxel &voxel)
Set this voxel free, if json is < 0.
uint32_t Label
Type of an object label.