Class CRandomFieldGridMap3D
Defined in File CRandomFieldGridMap3D.h
Nested Relationships
Nested Types
Inheritance Relationships
Base Types
public mrpt::containers::CDynamicGrid3D< TRandomFieldVoxel >public mrpt::serialization::CSerializablepublic mrpt::system::COutputLogger
Class Documentation
-
class CRandomFieldGridMap3D : public mrpt::containers::CDynamicGrid3D<TRandomFieldVoxel>, public mrpt::serialization::CSerializable, public mrpt::system::COutputLogger
CRandomFieldGridMap3D represents a 3D regular grid where each voxel is associated one real-valued property which is to be estimated by this class.
This class implements a Gaussian Markov Random Field (GMRF) estimator, with each voxel being connected to its 6 immediate neighbors (Up, down, left, right, front, back).
See papers:
”Time-variant gas distribution mapping with obstacle information”, Monroy, J. G., Blanco, J. L., & Gonzalez-Jimenez, J. Autonomous Robots, 40(1), 1-16, 2016.
Note that this class does not derive from mrpt::maps::CMetricMap since the estimated values do not have sensor-especific semantics, i.e. the grid can be used to estimate temperature, gas concentration, etc.
Usage:
Define grid size with either constructor or via
setSize().Initialize the map with
initialize(). This resets the contents of the map, so previously-added observations will be lost.Add observations of 3D voxels with
insertIndividualReading()
Custom connectivity patterns can be defined with setVoxelsConnectivity().
See also
Public Functions
-
CRandomFieldGridMap3D(double x_min = -2, double x_max = 2, double y_min = -2, double y_max = 2, double z_min = -2, double z_max = 2, double voxel_size = 0.5, bool call_initialize_now = true)
Constructor. If you set call_initialize_now to false, the object will be initialized immediately (without the heavy initialization of the GMRF), but you then must call
setSize()orclear()later to properly initialize the object before using it to insert observations.
-
virtual void clear() override
Erases all added observations and start again with an empty gridmap.
-
bool saveAsCSV(const std::string &filName_mean, const std::string &filName_stddev = std::string()) const
Save the current estimated mean values to a CSV file (compatible with Paraview) with fields
x y z mean_value. Optionally, std deviations can be also saved to another file with fieldsx y z stddev_value, iffilName_stddevis provided.- Returns:
false on error writing to file
-
void resize(double new_x_min, double new_x_max, double new_y_min, double new_y_max, double new_z_min, double new_z_max, const TRandomFieldVoxel &defaultValueNewvoxels, double additionalMarginMeters = 2.0) override
Changes the size of the grid, maintaining previous contents.
See also
-
void setSize(const double x_min, const double x_max, const double y_min, const double y_max, const double z_min, const double z_max, const double resolution_xy, const double resolution_z = -1.0, const TRandomFieldVoxel *fill_value = nullptr) override
Changes the size of the grid, erasing previous contents.If
resolution_z<0, the same resolution will be used for all dimensions x,y,z as given inresolution_xySee also
-
void setVoxelsConnectivity(const ConnectivityDescriptor::Ptr &new_connectivity_descriptor)
Sets a custom object to define the connectivity between voxels. Must call clear() or setSize() afterwards for the changes to take place.
-
bool insertIndividualReading(const double sensorReading, const double sensorVariance, const mrpt::math::TPoint3D &point, const TVoxelInterpolationMethod method, const bool update_map)
Direct update of the map with a reading in a given position of the map.
- Parameters:
sensorReading – [in] The value observed in the (x,y,z) position
sensorVariance – [in] The variance of the sensor observation
point – [in] The (x,y,z) location
method – [in] Voxel interpolation method: how many voxels will be affected by the reading
update_map – [in] Run a global map update after inserting this observation (algorithm-dependant)
- Returns:
false if point is out of the grid extension.
-
void updateMapEstimation()
Run the method-specific procedure required to ensure that the mean & variances are up-to-date with all inserted observations, using parameters in insertionOptions
Public Members
-
TInsertionOptions insertionOptions
See also
Public Static Attributes
-
static bool ENABLE_GMRF_PROFILER
[default:false] Enables a profiler to show a performance report at application end.
Protected Functions
-
void internal_initialize(bool erase_prev_contents = true)
Internal: called called after each change of resolution, size, etc. to build the prior factor information
Protected Attributes
-
ConnectivityDescriptor::Ptr m_gmrf_connectivity
Empty: default
-
mrpt::graphs::ScalarFactorGraph m_gmrf
-
std::vector<std::deque<TObservationGMRF>> m_mrf_factors_activeObs
Vector with the active observations and their respective Information, for each map cell.
-
std::deque<TPriorFactorGMRF> m_mrf_factors_priors
Vector with the precomputed priors for each GMRF model
-
struct ConnectivityDescriptor
Base class for user-supplied objects capable of describing voxels connectivity, used to build prior factors of the MRF graph.
See also
setvoxelsConnectivity()
Public Types
-
using Ptr = std::shared_ptr<ConnectivityDescriptor>
Public Functions
-
virtual ~ConnectivityDescriptor() = default
-
virtual bool getEdgeInformation(const CRandomFieldGridMap3D *parent, size_t icx, size_t icy, size_t icz, size_t jcx, size_t jcy, size_t jcz, double &out_edge_information) = 0
Implement the check of whether node i=(icx,icy,icz) is connected with node j=(jcx,jcy,jcy). This visitor method will be called only for immediate neighbors.
- Parameters:
parent – The parent map on which we are running
icx – (cx,cy,cz) for node “i”
jcx – (cx,cy,cz) for node “j”
out_edge_information – Must output here the inverse of the variance of the constraint edge.
- Returns:
true if connected (and the “information” value should be also updated in out_edge_information), false otherwise.
-
using Ptr = std::shared_ptr<ConnectivityDescriptor>
-
struct TInsertionOptions : public mrpt::config::CLoadableOptions
Parameters common to any derived class. Derived classes should derive a new struct from this one, plus mrpt::config::CLoadableOptions, and call the internal_* methods where appropriate to deal with the variables declared here. Derived classes instantions of their “TInsertionOptions” MUST set the pointer “m_insertOptions_common” upon construction.
-
struct TObservationGMRF : public mrpt::graphs::ScalarFactorGraph::UnaryFactorVirtualBase
Public Functions
-
virtual double evaluateResidual() const override
-
virtual double getInformation() const override
-
virtual void evalJacobian(double &dr_dx) const override
-
inline TObservationGMRF(CRandomFieldGridMap3D &parent)
-
virtual double evaluateResidual() const override
-
struct TPriorFactorGMRF : public mrpt::graphs::ScalarFactorGraph::BinaryFactorVirtualBase
Public Functions
-
virtual double evaluateResidual() const override
-
virtual double getInformation() const override
-
virtual void evalJacobian(double &dr_dx_i, double &dr_dx_j) const override
-
inline TPriorFactorGMRF(CRandomFieldGridMap3D &parent)
Public Members
-
double Lambda
“Information” of the observation (=inverse of the variance)
-
virtual double evaluateResidual() const override