35 original_pc->copyFrom(*pc);
39 const size_t N = pc->
size();
40 std::vector<bool> deletion_mask;
41 deletion_mask.assign(N,
false);
45 ASSERT_(options.previous_keyframes >= 1);
46 bool can_do_filter =
true;
48 std::vector<FrameInfo*> prev_pc;
50 auto it = m_last_frames.rbegin();
51 for (
int i = 0; i < options.previous_keyframes && it!=m_last_frames.rend(); ++i, ++it)
53 prev_pc.push_back(&it->second);
57 if (prev_pc.size() <
static_cast<size_t>(options.previous_keyframes) ) {
58 can_do_filter =
false;
61 for (
int i = 0; can_do_filter && i < options.previous_keyframes; ++i)
65 can_do_filter =
false;
76 for (
int k = 0; k < options.previous_keyframes; ++k) {
77 const CPose3D rel_pose = cur_pc_pose - prev_pc[k]->pose;
78 rel_poses.push_back(rel_pose);
84 std::vector<TPoint3D> pt_km1(options.previous_keyframes);
86 for (
size_t i = 0; i < N; i++)
94 for (
int k = 0; k < options.previous_keyframes; ++k)
95 rel_poses[k].composePoint(pt_k, pt_km1[k]);
98 std::vector<TPoint3D> neig_k;
99 std::vector<float> neig_sq_dist_k;
103 std::vector<TPoint3D> neig_kmi(options.previous_keyframes);
104 std::vector<float> neig_sq_dist_kmi(options.previous_keyframes, std::numeric_limits<float>::max() );
106 for (
int k = 0; k < options.previous_keyframes; ++k) {
107 for (
int prev_tim_idx = 0; prev_tim_idx < options.previous_keyframes; prev_tim_idx++) {
108 if (prev_pc[prev_tim_idx]->pc->
size() > 0) {
109 prev_pc[prev_tim_idx]->pc->kdTreeClosestPoint3D(pt_km1[prev_tim_idx], neig_kmi[prev_tim_idx], neig_sq_dist_kmi[prev_tim_idx]);
116 const double max_allowed_dist_sq =
square(options.min_dist + options.angle_tolerance * pt_k.
norm());
118 bool ok_total =
true;
119 const bool ok_t = neig_k.size() > 1 && neig_sq_dist_k[1] < max_allowed_dist_sq;
120 ok_total = ok_total && ok_t;
122 for (
int k = 0; k < options.previous_keyframes; ++k)
124 const bool ok_tm1 = neig_sq_dist_kmi[k] < max_allowed_dist_sq;
125 ok_total = ok_total && ok_tm1;
129 const bool do_delete = !(ok_total);
130 deletion_mask[i] = do_delete;
132 if (do_delete) del_count++;
136 if ( (
params ==
nullptr ||
params->do_not_delete ==
false) &&
138 del_count/double(N) < options.max_deletion_ratio
145 if (
params !=
nullptr &&
params->out_deletion_mask !=
nullptr) {
146 *
params->out_deletion_mask = deletion_mask;
154 fi.
pose = cur_pc_pose;
156 m_last_frames[pc_timestamp] = fi;
161 for (
auto it = m_last_frames.begin(); it != m_last_frames.end(); )
164 it = m_last_frames.erase(it);
177 too_old_seconds(1.0),
178 previous_keyframes(1),
179 max_deletion_ratio(.4)
197 MRPT_SAVE_CONFIG_VAR_COMMENT(previous_keyframes,
"(Default: 1) How many previous keyframes will be compared with the latest pointcloud.");
198 MRPT_SAVE_CONFIG_VAR_COMMENT(max_deletion_ratio,
"(Default: 0.4) If the ratio [0,1] of points considered invalid (`deletion` ) is larger than this ratio, no point will be deleted since it'd be too suspicious and may indicate a failure of this filter.");
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
void getPointFast(size_t index, float &x, float &y, float &z) const
Just like getPoint() but without checking out-of-bound index and without returning the point weight...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
mrpt::poses::CPose3D pose
double norm() const
Point norm.
static CSimplePointsMapPtr Create()
This class allows loading and storing values and vectors of different types from a configuration text...
T square(const T x)
Inline function for the square of a number.
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors...
This base provides a set of functions for maths stuff.
mrpt::maps::CSimplePointsMapPtr pc
#define MRPT_SAVE_CONFIG_VAR_COMMENT(variableName, __comment)
Lightweight 3D point (float version).
void kdTreeNClosestPoint3D(float x0, float y0, float z0, size_t knn, std::vector< float > &out_x, std::vector< float > &out_y, std::vector< float > &out_z, std::vector< float > &out_dist_sqr) const
KD Tree-based search for the N closest points to some given 3D coordinates.
GLsizei const GLchar ** string
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
#define MRPT_LOAD_CONFIG_VAR(variableName, variableType, configFileObject, sectionNameStr)
An useful macro for loading variables stored in a INI-like file under a key with the same name that t...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void filter(mrpt::maps::CPointsMap *inout_pointcloud, const mrpt::system::TTimeStamp pc_timestamp, const mrpt::poses::CPose3D &pc_reference_pose, TExtraFilterParams *params=nullptr) MRPT_OVERRIDE
Apply the filtering algorithm to the pointcloud.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
#define MRPT_LOAD_CONFIG_VAR_DEGREES(variableName, configFileObject, sectionNameStr)
Loads a double variable, stored as radians but entered in the INI-file as degrees.
T square(const T x)
Inline function for the square of a number.
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string §ion) MRPT_OVERRIDE
This method load the options from a ".ini"-like file or memory-stored string list.
double BASE_IMPEXP timeDifference(const mrpt::system::TTimeStamp t_first, const mrpt::system::TTimeStamp t_later)
Returns the time difference from t1 to t2 (positive if t2 is posterior to t1), in seconds...
#define MRPT_SAVE_CONFIG_VAR_DEGREES_COMMENT(__entryName, __variable, __comment)
void saveToConfigFile(mrpt::utils::CConfigFileBase &c, const std::string §ion) const MRPT_OVERRIDE
This method saves the options to a ".ini"-like file or memory-stored string list. ...
size_t size() const
Returns the number of stored points in the map.
GLenum const GLfloat * params
std::vector< TYPE1, Eigen::aligned_allocator< TYPE1 > > vector_t
void applyDeletionMask(const std::vector< bool > &mask)
Remove from the map the points marked in a bool's array as "true".