Main MRPT website > C++ reference for MRPT 1.9.9
CRandomFieldGridMap3D_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
11 #include <gtest/gtest.h>
12 
13 TEST(CRandomFieldGridMap3D, insertCheckMapBounds)
14 {
16 
19 
21  // grid3d.setMinLoggingLevel(mrpt::system::LVL_DEBUG);
22 
23  grid3d.setSize(
24  -4.0, 4.0, 0.0, 4.0, 0.0, 4.0,
25  1.0 /*voxel size*/); // x:[-10,10] * y:[0,5] * z:[0,4]
26 
27  const double val = 10.0, var = 1.0;
28 
29  // Inside:
30  EXPECT_TRUE(
32  1.0 * val, var, TPoint3D(2.0, 3.0, 1.0), im, false));
33  EXPECT_TRUE(
35  2.0 * val, var, TPoint3D(-3.0, 0.4, 1.0), im, false));
36  EXPECT_TRUE(
38  3.0 * val, var, TPoint3D(3.0, 3.8, 3.0), im, false));
39  // Outside:
40  EXPECT_FALSE(
42  val, var, TPoint3D(-11.0, 2.0, 2.0), im, false));
43  EXPECT_FALSE(
45  val, var, TPoint3D(11.0, 2.0, 3.0), im, false));
46  EXPECT_FALSE(
48  val, var, TPoint3D(2.0, -1.0, 11.0), im, false));
49  EXPECT_FALSE(
51  val, var, TPoint3D(2.0, 6.0, 3.0), im, false));
52 
53 #if 0
54  grid3d.updateMapEstimation();
55  grid3d.saveAsCSV("map3D.csv");
56  grid3d.saveAsVtkStructuredGrid("map3D.vts");
57 #endif
58 }
59 
60 TEST(CRandomFieldGridMap3D, insertPointsAndRead)
61 {
63 
67  // grid3d.setMinLoggingLevel(mrpt::system::LVL_DEBUG);
68 
69  grid3d.setSize(
70  -4.0, 4.0, 0.0, 4.0, 0.0, 4.0,
71  1.0 /*voxel size*/); // x:[-10,10] * y:[0,5] * z:[0,4]
72 
73  const double val = 55.0, var = 1.0;
74 
75  EXPECT_TRUE(
77  val, var, TPoint3D(2.0, 3.0, 1.0), im, false));
78 
80  grid3d.updateMapEstimation();
81 
82  {
83  const double map_value = grid3d.cellByPos(2.0, 3.0, 1.0)->mean_value;
84  EXPECT_NEAR(map_value, val, 1e-6);
85  }
86 
87  // Test after map enlarge:
88  grid3d.resize(
89  -5.0, 5.0, -1.0, 5.0, -1.0, 5.0, mrpt::maps::TRandomFieldVoxel(), .0);
90  {
91  const double map_value = grid3d.cellByPos(2.0, 3.0, 1.0)->mean_value;
92  EXPECT_NEAR(map_value, val, 1e-6);
93  }
94 }
mrpt::maps::CRandomFieldGridMap3D::saveAsCSV
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 mea...
Definition: CRandomFieldGridMap3D.cpp:254
mrpt::maps::CRandomFieldGridMap3D::TVoxelInterpolationMethod
TVoxelInterpolationMethod
Definition: CRandomFieldGridMap3D.h:202
mrpt::maps::CRandomFieldGridMap3D::setSize
virtual 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 b...
Definition: CRandomFieldGridMap3D.cpp:51
mrpt::maps::CRandomFieldGridMap3D::insertIndividualReading
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.
Definition: CRandomFieldGridMap3D.cpp:340
mrpt::maps::CRandomFieldGridMap3D::updateMapEstimation
void updateMapEstimation()
Run the method-specific procedure required to ensure that the mean & variances are up-to-date with al...
Definition: CRandomFieldGridMap3D.cpp:310
mrpt::maps::CRandomFieldGridMap3D::saveAsVtkStructuredGrid
bool saveAsVtkStructuredGrid(const std::string &fil) const
Save the current estimated grid to a VTK file (.vts) as a "structured grid".
Definition: CRandomFieldGridMap3D.cpp:223
val
int val
Definition: mrpt_jpeglib.h:955
mrpt::maps::CRandomFieldGridMap3D::insertionOptions
TInsertionOptions insertionOptions
Definition: CRandomFieldGridMap3D.h:152
mrpt::containers::CDynamicGrid3D::cellByPos
T * cellByPos(double x, double y, double z)
Returns a pointer to the contents of a voxel given by its coordinates, or nullptr if it is out of the...
Definition: CDynamicGrid3D.h:247
mrpt::math::TPoint3D
Lightweight 3D point.
Definition: lightweight_geom_data.h:378
mrpt::maps::CRandomFieldGridMap3D::gimNearest
@ gimNearest
Definition: CRandomFieldGridMap3D.h:204
mrpt::maps::CRandomFieldGridMap3D
CRandomFieldGridMap3D represents a 3D regular grid where each voxel is associated one real-valued pro...
Definition: CRandomFieldGridMap3D.h:78
CRandomFieldGridMap3D.h
mrpt::maps::TRandomFieldVoxel
The contents of each voxel in a CRandomFieldGridMap3D map.
Definition: CRandomFieldGridMap3D.h:36
TEST
TEST(CRandomFieldGridMap3D, insertCheckMapBounds)
Definition: CRandomFieldGridMap3D_unittest.cpp:13
mrpt::maps::CRandomFieldGridMap3D::resize
virtual 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.
Definition: CRandomFieldGridMap3D.cpp:67
mrpt::maps::CRandomFieldGridMap3D::TInsertionOptions::GMRF_skip_variance
bool GMRF_skip_variance
(Default:false) Skip the computation of the variance, just compute the mean
Definition: CRandomFieldGridMap3D.h:147



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST