AngleLimit.cpp
Go to the documentation of this file.
1 // kate: replace-tabs off; indent-width 4; indent-mode normal
2 // vim: ts=4:sw=4:noexpandtab
3 /*
4 
5 Copyright (c) 2010--2024,
6 François Pomerleau and Stephane Magnenat, ASL, ETHZ, Switzerland
7 Matej Boxan, Norlab, Université Laval, Canada
8 You can contact the authors at <f dot pomerleau at gmail dot com> and
9 <stephane at magnenat dot net> and <matej dot boxan at gmail dot com>
10 
11 All rights reserved.
12 
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15  * Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  * Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  * Neither the name of the <organization> nor the
21  names of its contributors may be used to endorse or promote products
22  derived from this software without specific prior written permission.
23 
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 DISCLAIMED. IN NO EVENT SHALL ETH-ASL BE LIABLE FOR ANY
28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 
35 */
36 #include "AngleLimit.h"
37 #include "pointmatcher/Functions.h"
38 
39 // AngleLimitDataPointsFilter
40 // Constructor
41 template<typename T>
43  PointMatcher<T>::DataPointsFilter("AngleLimitDataPointsFilter",
44  AngleLimitDataPointsFilter::availableParameters(), params),
45  phiMin(Parametrizable::get<T>("phiMin")),
46  phiMax(Parametrizable::get<T>("phiMax")),
47  thetaMin(Parametrizable::get<T>("thetaMin")),
48  thetaMax(Parametrizable::get<T>("thetaMax")),
49  removeInside(Parametrizable::get<bool>("removeInside"))
50 {
51 }
52 
53 template<typename T>
55  const DataPoints& input)
56 {
57  DataPoints output(input);
58  inPlaceFilter(output);
59  return output;
60 }
61 
62 // In-place filter
63 template<typename T>
65  DataPoints& cloud)
66 {
67  using namespace PointMatcherSupport;
68 
69 
70  const int nbPoints = cloud.getNbPoints();
71  const int nbRows = cloud.features.rows();
72 
73  int j = 0;
74  for(int i = 0; i < nbPoints; ++i)
75  {
76  auto point = cloud.features.col(i).head(nbRows-1);
77  T r = point.norm();
78  T r_plane = point.head(nbRows-2).norm();
79  T thetaPoint = PointMatcherSupport::radToDeg(acos(point(nbRows-2) / r));
80  T phiPoint = PointMatcherSupport::radToDeg(acos(point(0) / r_plane));
81 
82  if (point(1) < 0)
83  phiPoint = -phiPoint;
84 
85  if(removeInside)
86  {
87  if((phiPoint < phiMin || phiMax < phiPoint) || (thetaPoint < thetaMin || thetaMax < thetaPoint)) // point is outside range, keep it
88  {
89  cloud.setColFrom(j, cloud, i);
90  ++j;
91  }
92  }
93  else
94  {
95  if (phiMin < phiPoint && phiPoint < phiMax && thetaMin < thetaPoint && thetaPoint < thetaMax) // point is inside range, keep it
96  {
97  cloud.setColFrom(j, cloud, i);
98  ++j;
99  }
100  }
101  }
102  cloud.conservativeResize(j);
103 }
104 
105 template struct AngleLimitDataPointsFilter<float>;
106 template struct AngleLimitDataPointsFilter<double>;
AngleLimitDataPointsFilter::Parameters
Parametrizable::Parameters Parameters
Definition: AngleLimit.h:48
DataPointsFilter
PM::DataPointsFilter DataPointsFilter
Definition: pypoint_matcher_helper.h:22
build_map.T
T
Definition: build_map.py:34
AngleLimit.h
PointMatcher
Functions and classes that are dependant on scalar type are defined in this templatized class.
Definition: PointMatcher.h:130
PointMatcher::DataPoints
A point cloud.
Definition: PointMatcher.h:207
AngleLimitDataPointsFilter
Definition: AngleLimit.h:44
align_sequence.params
params
Definition: align_sequence.py:13
PointMatcher::DataPoints::setColFrom
void setColFrom(Index thisCol, const DataPoints &that, Index thatCol)
Set column thisCol equal to column thatCol of that, copy features and descriptors if any....
Definition: pointmatcher/DataPoints.cpp:393
PointMatcher::DataPoints::getNbPoints
unsigned getNbPoints() const
Return the number of points contained in the point cloud.
Definition: pointmatcher/DataPoints.cpp:158
PointMatcher::DataPoints::features
Matrix features
features of points in the cloud
Definition: PointMatcher.h:331
AngleLimitDataPointsFilter::AngleLimitDataPointsFilter
AngleLimitDataPointsFilter(const Parameters &params=Parameters())
Constructor, uses parameter interface.
Definition: AngleLimit.cpp:42
PointMatcherSupport::Parametrizable
The superclass of classes that are constructed using generic parameters. This class provides the para...
Definition: Parametrizable.h:141
PointMatcherSupport::get
const M::mapped_type & get(const M &m, const typename M::key_type &k)
Definition: Bibliography.cpp:57
PointMatcherSupport::radToDeg
T radToDeg(T rad)
Definition: Functions.h:63
PointMatcher::DataPoints::conservativeResize
void conservativeResize(Index pointCount)
Resize the cloud to pointCount points, conserving existing ones.
Definition: pointmatcher/DataPoints.cpp:328
AngleLimitDataPointsFilter::inPlaceFilter
virtual void inPlaceFilter(DataPoints &cloud)
Apply these filters to a point cloud without copying.
Definition: AngleLimit.cpp:64
Functions.h
PointMatcherSupport
Functions and classes that are not dependant on scalar type are defined in this namespace.
Definition: Bibliography.cpp:45
AngleLimitDataPointsFilter::filter
virtual DataPoints filter(const DataPoints &input)
Apply filters to input point cloud. This is the non-destructive version and returns a copy.
Definition: AngleLimit.cpp:54


libpointmatcher
Author(s):
autogenerated on Sun Dec 22 2024 03:21:52