Go to the documentation of this file.
8 #include <SimoxUtility/json/json.hpp>
12 #include "../VoxelGrid.hpp"
19 template <
class VoxelT>
22 template <
class VoxelT>
26 template <
class VoxelT>
29 template <
class VoxelT>
34 template <
class VoxelT,
class MemberT>
36 makeGetter(MemberT VoxelT::*memberVariable)
38 return [memberVariable](
const VoxelT&
v) {
return nlohmann::json(
v.*memberVariable); };
43 template <
class VoxelT,
class MemberT>
44 static VoxelAttributeGetter<VoxelT>
45 makeGetter(MemberT (VoxelT::*memberFunc)()
const)
47 return [memberFunc](
const VoxelT&
v) {
return (
v.*memberFunc)(); };
52 template <
class VoxelT,
class MemberT>
53 static VoxelAttributeSetter<VoxelT>
54 makeSetter(MemberT VoxelT::*memberVariable)
56 return [memberVariable](
const nlohmann::json& j, VoxelT&
v)
57 {
return v.*memberVariable = j.get<MemberT>(); };
62 template <
class VoxelT,
class MemberT>
63 static VoxelAttributeSetter<VoxelT>
64 makeSetter(
void (VoxelT::*memberFunc)(
const MemberT&))
66 return [memberFunc](
const nlohmann::json& j, VoxelT&
v)
67 {
return (
v.*memberFunc)(j.get<MemberT>()); };
99 template <
class VoxelT>
105 char indentChar =
' ')
111 template <
class VoxelT>
117 char indentChar =
' ')
125 template <
class VoxelT>
135 template <
class VoxelT>
140 template <
class VoxelT>
150 template <
class VoxelT>
158 template <
class VoxelT>
159 static void toJson(nlohmann::json& j,
164 template <
class VoxelT>
170 template <
class VoxelT>
171 static void toJson(nlohmann::json& j,
173 const std::string& voxelArrayName =
"voxels");
177 template <
class VoxelT>
179 const std::string& voxelArrayName =
"voxels");
185 template <
class VoxelT>
186 static void fromJson(
const nlohmann::json& j,
193 template <
class VoxelT>
194 static void fromJson(
const nlohmann::json& j,
196 const std::string& voxelArrayName =
"voxels");
201 const nlohmann::json& j,
203 char indentChar =
' ');
206 const nlohmann::json& j,
208 char indentChar =
' ');
213 static nlohmann::json
readJson(std::istream& is);
216 template <
class VoxelT>
225 template <
class VoxelT>
230 read(is, grid, attributeMap);
234 template <
class VoxelT>
240 toJson(j, grid, attributeMap);
244 template <
class VoxelT>
256 for (
const auto& item : attributeMap)
258 j[item.first] = nlohmann::json::array();
262 for (
const VoxelT& voxel : grid)
264 for (
const auto& item : attributeMap)
267 j[item.first].push_back(item.second(voxel));
272 template <
class VoxelT>
276 const std::string& voxelArrayName)
284 template <
class VoxelT>
289 toJson(j, grid, voxelArrayName);
293 template <
class VoxelT>
305 for (std::size_t i = 0; i < grid.
numVoxels(); ++i)
307 VoxelT& voxel = grid[i];
308 for (
const auto& item : attributeMap)
311 item.second(j[item.first].at(i), voxel);
316 template <
class VoxelT>
320 const std::string& voxelArrayName)
327 grid.
setVoxels(j.at(voxelArrayName).get<std::vector<VoxelT>>());
static void read(const std::string &filename, VoxelGrid< VoxelT > &grid, const VoxelAttributeGetterMap< VoxelT > &attributeMap)
Read a voxel grid from file.
static void fromJson(const nlohmann::json &j, VoxelGrid< VoxelT > &grid, const VoxelAttributeSetterMap< VoxelT > &attributeMap)
Deserialize a voxel grid from JSON.
void setVoxels(const std::vector< VoxelT > &voxels)
Set the voxels.
std::function< nlohmann::json(const VoxelT &voxel)> VoxelAttributeGetter
Function to get an attribute of a voxel.
static void toJson(nlohmann::json &j, const VoxelGrid< VoxelT > &grid, const VoxelAttributeGetterMap< VoxelT > &attributeMap)
Serialize a voxel grid to JSON.
std::map< std::string, VoxelAttributeGetter< VoxelT > > VoxelAttributeGetterMap
Map of attribute name to attribute getter.
static void read(std::istream &is, VoxelGrid< VoxelT > &grid, const VoxelAttributeGetterMap< VoxelT > &attributeMap)
Read a voxel grid from is.
void resetStructure(const VoxelGridStructure &structure)
Set the voxel grid structure and reset voxel data.
static void write(const std::string &filename, const VoxelGrid< VoxelT > &grid, const VoxelAttributeGetterMap< VoxelT > &attributeMap, int indent=-1, char indentChar=' ')
Write a voxel grid to file.
static void writeJson(const std::string &filename, const nlohmann::json &j, int indent=-1, char indentChar=' ')
Write JSON json to file.
VoxelGridStructure getStructure() const
Get the voxel grid structure.
std::size_t numVoxels() const
Get the number of voxels in the grid.
Geometric structure of a 3D voxel grid.
Class to store voxel grids in a vectorized JSON format.
static nlohmann::json readJson(const std::string &filename)
Read JSON from file.
static void write(std::ostream &os, const VoxelGrid< VoxelT > &grid, const VoxelAttributeGetterMap< VoxelT > &attributeMap, int indent=-1, char indentChar=' ')
Write a voxel grid to os.
std::map< std::string, VoxelAttributeSetter< VoxelT > > VoxelAttributeSetterMap
Map of attribute name to attribute setter.
double v(double t, double v0, double a0, double j)
std::size_t getNumVoxels() const
Get the number of voxels contained in the structure.
const std::vector< VoxelT > & getVoxels() const
Get the voxels.
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
std::function< void(const nlohmann::json &j, VoxelT &voxel)> VoxelAttributeSetter
Function to set an attribute of a voxel.