Image Component Library (ICL)
PlanarRansacEstimator.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLGeom/src/ICLGeom/PlanarRansacEstimator.h **
10 ** Module : ICLGeom **
11 ** Authors: Andre Ueckermann **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLGeom/GeomDefs.h>
34 #include <ICLCore/DataSegment.h>
35 #include <ICLMath/DynMatrix.h>
36 
37 namespace icl{
38  namespace geom{
39 
41 
45 
46  public:
47  enum Mode {BEST, GPU, CPU};
48 
50 
53 
54 
57 
58 
59  typedef struct{
60  int numPoints;//number of destination points
61  int countOn;//number of points on the model
62  int countAbove;//number of points above the model
63  int countBelow;//number of points below the model
64  float euclideanThreshold;//selected threshold
65  Vec n0;//best model (normal)
66  float dist;//best model (distance)
67  int tolerance;//tolerance for ON_ONE_SIDE
68  int acc;//number of accepted passes for ON_ONE_SIDE (result smaller tolerance)
69  int nacc;//number of rejected passes for ON_ONE_SIDE (result bigger tolerance)
70  //int maxID;//for assignment of points (all with this id + on plane)
71  }Result;
72 
73 
75  MAX_ON=1,
77  };
78 
79 
81 
91  Result apply(core::DataSegment<float,4> &xyzh, std::vector<int> &srcIDs, std::vector<int> &dstIDs,
92  float threshold, int passes, int subset, int tolerance, int optimization);
93 
94 
96 
106  Result apply(std::vector<Vec> &srcPoints, std::vector<Vec> &dstPoints, float threshold,
107  int passes, int subset, int tolerance, int optimization);
108 
109 
111 
121  math::DynMatrix<Result> apply(core::DataSegment<float,4> &xyzh, std::vector<std::vector<int> > &pointIDs,
122  math::DynMatrix<bool> &testMatrix, float threshold, int passes, int tolerance, int optimization, core::Img32s labelImage);
123 
124 
126 
135  void relabel(core::DataSegment<float,4> &xyzh, core::Img8u &newMask, core::Img32s &oldLabel, core::Img32s &newLabel,
136  int desiredID, int srcID, float threshold, Result &result);
137 
138 
140 
145  static void calculateRandomModels(std::vector<Vec> &srcPoints, std::vector<Vec> &n0, std::vector<float> &dist, int passes);
146 
147 
149 
155  static void calculateRandomModels(core::DataSegment<float,4> &xyzh, std::vector<int> &srcPoints, std::vector<Vec> &n0, std::vector<float> &dist, int passes);
156 
157  private:
158 
159  struct Data;
160  Data *m_data;
161 
162  void calculateMultiCL(core::DataSegment<float,4> &xyzh, core::Img32s labelImage, math::DynMatrix<bool> &testMatrix, float threshold, int passes,
163  std::vector<Vec> &n0, std::vector<float> &dist, std::vector<int> &cAbove, std::vector<int> &cBelow, std::vector<int> &cOn,
164  std::vector<int> &adjs, std::vector<int> &start, std::vector<int> &end);
165 
166  void calculateMultiCPU(core::DataSegment<float,4> &xyzh, std::vector<std::vector<int> > &pointIDs, math::DynMatrix<bool> &testMatrix,
167  float threshold, int passes, std::vector<std::vector<Vec> > &n0Pre, std::vector<std::vector<float> > &distPre, std::vector<int> &cAbove,
168  std::vector<int> &cBelow, std::vector<int> &cOn, std::vector<int> &adjs, std::vector<int> &start, std::vector<int> &end);
169 
170  void calculateSingleCL(std::vector<Vec> &dstPoints, float threshold, int passes, int subset,
171  std::vector<Vec> &n0, std::vector<float> &dist, std::vector<int> &cAbove, std::vector<int> &cBelow, std::vector<int> &cOn);
172 
173  void calculateSingleCPU(std::vector<Vec> &dstPoints, float threshold, int passes, int subset,
174  std::vector<Vec> &n0, std::vector<float> &dist, std::vector<int> &cAbove, std::vector<int> &cBelow, std::vector<int> &cOn);
175 
176  void initOpenCL();
177 
178  Result createResult(std::vector<Vec> &n0, std::vector<float> &dist, std::vector<int> &cAbove, std::vector<int> &cBelow, std::vector<int> &cOn,
179  float threshold, int passes, int tolerance, int optimization, int numPoints);
180 
181  math::DynMatrix<Result> createResultMatrix(math::DynMatrix<bool> &testMatrix, std::vector<int> &start, std::vector<int> &end, std::vector<int> &adjs,
182  std::vector<int> &cAbove, std::vector<int> &cBelow, std::vector<int> &cOn, std::vector<std::vector<int> > &pointIDs,
183  std::vector<std::vector<Vec> > &n0Pre, std::vector<std::vector<float> > &distPre, float threshold, int passes, int tolerance, int optimization);
184 
185  static void calculateModel(Vec &fa, Vec &fb, Vec &rPoint, Vec &n0, float &dist);
186 
187  void relabelCL(core::DataSegment<float,4> &xyzh, core::Img8u &newMask, core::Img32s &oldLabel, core::Img32s &newLabel,
188  int desiredID, int srcID, float threshold, Result &result, int w, int h);
189 
190  void relabelCPU(core::DataSegment<float,4> &xyzh, core::Img8u &newMask, core::Img32s &oldLabel, core::Img32s &newLabel,
191  int desiredID, int srcID, float threshold, Result &result, int w, int h);
192 
193  };
194 
195  } // namespace geom
196 }
int numPoints
Definition: PlanarRansacEstimator.h:60
void calculateMultiCL(core::DataSegment< float, 4 > &xyzh, core::Img32s labelImage, math::DynMatrix< bool > &testMatrix, float threshold, int passes, std::vector< Vec > &n0, std::vector< float > &dist, std::vector< int > &cAbove, std::vector< int > &cBelow, std::vector< int > &cOn, std::vector< int > &adjs, std::vector< int > &start, std::vector< int > &end)
ICLIO_API void labelImage(core::ImgBase *image, const std::string &label)
draws a label into the upper left image corner
Definition: PlanarRansacEstimator.h:47
static void calculateModel(Vec &fa, Vec &fb, Vec &rPoint, Vec &n0, float &dist)
undocument this line if you encounter any issues!
Definition: Any.h:37
void relabelCL(core::DataSegment< float, 4 > &xyzh, core::Img8u &newMask, core::Img32s &oldLabel, core::Img32s &newLabel, int desiredID, int srcID, float threshold, Result &result, int w, int h)
int countAbove
Definition: PlanarRansacEstimator.h:62
Definition: PlanarRansacEstimator.h:47
float euclideanThreshold
Definition: PlanarRansacEstimator.h:64
Highly flexible and optimized matrix class implementation.
Definition: DynMatrix.h:81
int acc
Definition: PlanarRansacEstimator.h:68
Result createResult(std::vector< Vec > &n0, std::vector< float > &dist, std::vector< int > &cAbove, std::vector< int > &cBelow, std::vector< int > &cOn, float threshold, int passes, int tolerance, int optimization, int numPoints)
math::DynMatrix< Result > createResultMatrix(math::DynMatrix< bool > &testMatrix, std::vector< int > &start, std::vector< int > &end, std::vector< int > &adjs, std::vector< int > &cAbove, std::vector< int > &cBelow, std::vector< int > &cOn, std::vector< std::vector< int > > &pointIDs, std::vector< std::vector< Vec > > &n0Pre, std::vector< std::vector< float > > &distPre, float threshold, int passes, int tolerance, int optimization)
Definition: PlanarRansacEstimator.h:47
int nacc
Definition: PlanarRansacEstimator.h:69
Result apply(core::DataSegment< float, 4 > &xyzh, std::vector< int > &srcIDs, std::vector< int > &dstIDs, float threshold, int passes, int subset, int tolerance, int optimization)
Applies the planar RANSAC estimation on a destination region with a model from the src region (e....
class for planar RANSAC estimation on poincloud data (xyzh).
Definition: PlanarRansacEstimator.h:44
float dist
Definition: PlanarRansacEstimator.h:66
OptimizationCriterion
Definition: PlanarRansacEstimator.h:74
Vec n0
Definition: PlanarRansacEstimator.h:65
int countBelow
Definition: PlanarRansacEstimator.h:63
Definition: PlanarRansacEstimator.h:76
void calculateMultiCPU(core::DataSegment< float, 4 > &xyzh, std::vector< std::vector< int > > &pointIDs, math::DynMatrix< bool > &testMatrix, float threshold, int passes, std::vector< std::vector< Vec > > &n0Pre, std::vector< std::vector< float > > &distPre, std::vector< int > &cAbove, std::vector< int > &cBelow, std::vector< int > &cOn, std::vector< int > &adjs, std::vector< int > &start, std::vector< int > &end)
Mode
Definition: PlanarRansacEstimator.h:47
void relabel(core::DataSegment< float, 4 > &xyzh, core::Img8u &newMask, core::Img32s &oldLabel, core::Img32s &newLabel, int desiredID, int srcID, float threshold, Result &result)
Create a label image of all points on the planar model (incl. the original surface)
void relabelCPU(core::DataSegment< float, 4 > &xyzh, core::Img8u &newMask, core::Img32s &oldLabel, core::Img32s &newLabel, int desiredID, int srcID, float threshold, Result &result, int w, int h)
Data * m_data
internal data type
Definition: PlanarRansacEstimator.h:159
int countOn
Definition: PlanarRansacEstimator.h:61
PlanarRansacEstimator(Mode mode=BEST)
Constructor.
void calculateSingleCL(std::vector< Vec > &dstPoints, float threshold, int passes, int subset, std::vector< Vec > &n0, std::vector< float > &dist, std::vector< int > &cAbove, std::vector< int > &cBelow, std::vector< int > &cOn)
static void calculateRandomModels(std::vector< Vec > &srcPoints, std::vector< Vec > &n0, std::vector< float > &dist, int passes)
Creates random models (n and distance) for RANSAC.
Definition: PlanarRansacEstimator.h:59
void calculateSingleCPU(std::vector< Vec > &dstPoints, float threshold, int passes, int subset, std::vector< Vec > &n0, std::vector< float > &dist, std::vector< int > &cAbove, std::vector< int > &cBelow, std::vector< int > &cOn)
Definition: PlanarRansacEstimator.h:75
The Img class implements the ImgBase Image interface with type specific functionalities .
Definition: Img.h:49
int tolerance
Definition: PlanarRansacEstimator.h:67