Image Component Library (ICL)
|
00001 /******************************************************************** 00002 ** Image Component Library (ICL) ** 00003 ** ** 00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** 00005 ** Neuroinformatics Group ** 00006 ** Website: www.iclcv.org and ** 00007 ** http://opensource.cit-ec.de/projects/icl ** 00008 ** ** 00009 ** File : ICLGeom/src/ICLGeom/PlanarRansacEstimator.h ** 00010 ** Module : ICLGeom ** 00011 ** Authors: Andre Ueckermann ** 00012 ** ** 00013 ** ** 00014 ** GNU LESSER GENERAL PUBLIC LICENSE ** 00015 ** This file may be used under the terms of the GNU Lesser General ** 00016 ** Public License version 3.0 as published by the ** 00017 ** ** 00018 ** Free Software Foundation and appearing in the file LICENSE.LGPL ** 00019 ** included in the packaging of this file. Please review the ** 00020 ** following information to ensure the license requirements will ** 00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** 00022 ** ** 00023 ** The development of this software was supported by the ** 00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** 00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** 00026 ** Forschungsgemeinschaft (DFG) in the context of the German ** 00027 ** Excellence Initiative. ** 00028 ** ** 00029 ********************************************************************/ 00030 00031 #pragma once 00032 00033 #include <ICLGeom/GeomDefs.h> 00034 #include <ICLCore/DataSegment.h> 00035 #include <ICLMath/DynMatrix.h> 00036 00037 namespace icl{ 00038 namespace geom{ 00039 00041 00044 class PlanarRansacEstimator{ 00045 00046 public: 00047 enum Mode {BEST, GPU, CPU}; 00048 00050 00052 PlanarRansacEstimator(Mode mode=BEST); 00053 00054 00056 ~PlanarRansacEstimator(); 00057 00058 00059 typedef struct{ 00060 int numPoints;//number of destination points 00061 int countOn;//number of points on the model 00062 int countAbove;//number of points above the model 00063 int countBelow;//number of points below the model 00064 float euclideanThreshold;//selected threshold 00065 Vec n0;//best model (normal) 00066 float dist;//best model (distance) 00067 int tolerance;//tolerance for ON_ONE_SIDE 00068 int acc;//number of accepted passes for ON_ONE_SIDE (result smaller tolerance) 00069 int nacc;//number of rejected passes for ON_ONE_SIDE (result bigger tolerance) 00070 //int maxID;//for assignment of points (all with this id + on plane) 00071 }Result; 00072 00073 00074 enum OptimizationCriterion { 00075 MAX_ON=1, 00076 ON_ONE_SIDE=2 00077 }; 00078 00079 00081 00091 Result apply(core::DataSegment<float,4> &xyzh, std::vector<int> &srcIDs, std::vector<int> &dstIDs, 00092 float threshold, int passes, int subset, int tolerance, int optimization); 00093 00094 00096 00106 Result apply(std::vector<Vec> &srcPoints, std::vector<Vec> &dstPoints, float threshold, 00107 int passes, int subset, int tolerance, int optimization); 00108 00109 00111 00121 math::DynMatrix<Result> apply(core::DataSegment<float,4> &xyzh, std::vector<std::vector<int> > &pointIDs, 00122 math::DynMatrix<bool> &testMatrix, float threshold, int passes, int tolerance, int optimization, core::Img32s labelImage); 00123 00124 00126 00135 void relabel(core::DataSegment<float,4> &xyzh, core::Img8u &newMask, core::Img32s &oldLabel, core::Img32s &newLabel, 00136 int desiredID, int srcID, float threshold, Result &result); 00137 00138 00139 private: 00140 00141 struct Data; 00142 Data *m_data; 00143 00144 void calculateMultiCL(core::DataSegment<float,4> &xyzh, core::Img32s labelImage, math::DynMatrix<bool> &testMatrix, float threshold, int passes, 00145 std::vector<Vec> &n0, std::vector<float> &dist, std::vector<int> &cAbove, std::vector<int> &cBelow, std::vector<int> &cOn, 00146 std::vector<int> &adjs, std::vector<int> &start, std::vector<int> &end); 00147 00148 void calculateMultiCPU(core::DataSegment<float,4> &xyzh, std::vector<std::vector<int> > &pointIDs, math::DynMatrix<bool> &testMatrix, 00149 float threshold, int passes, std::vector<std::vector<Vec> > &n0Pre, std::vector<std::vector<float> > &distPre, std::vector<int> &cAbove, 00150 std::vector<int> &cBelow, std::vector<int> &cOn, std::vector<int> &adjs, std::vector<int> &start, std::vector<int> &end); 00151 00152 void calculateSingleCL(std::vector<Vec> &dstPoints, float threshold, int passes, int subset, 00153 std::vector<Vec> &n0, std::vector<float> &dist, std::vector<int> &cAbove, std::vector<int> &cBelow, std::vector<int> &cOn); 00154 00155 void calculateSingleCPU(std::vector<Vec> &dstPoints, float threshold, int passes, int subset, 00156 std::vector<Vec> &n0, std::vector<float> &dist, std::vector<int> &cAbove, std::vector<int> &cBelow, std::vector<int> &cOn); 00157 00158 void initOpenCL(); 00159 00160 void calculateRandomModels(std::vector<Vec> &srcPoints, std::vector<Vec> &n0, std::vector<float> &dist, int passes); 00161 00162 void calculateRandomModels(core::DataSegment<float,4> &xyzh, std::vector<int> &srcPoints, std::vector<Vec> &n0, std::vector<float> &dist, int passes); 00163 00164 Result createResult(std::vector<Vec> &n0, std::vector<float> &dist, std::vector<int> &cAbove, std::vector<int> &cBelow, std::vector<int> &cOn, 00165 float threshold, int passes, int tolerance, int optimization, int numPoints); 00166 00167 math::DynMatrix<Result> createResultMatrix(math::DynMatrix<bool> &testMatrix, std::vector<int> &start, std::vector<int> &end, std::vector<int> &adjs, 00168 std::vector<int> &cAbove, std::vector<int> &cBelow, std::vector<int> &cOn, std::vector<std::vector<int> > &pointIDs, 00169 std::vector<std::vector<Vec> > &n0Pre, std::vector<std::vector<float> > &distPre, float threshold, int passes, int tolerance, int optimization); 00170 00171 void calculateModel(Vec &fa, Vec &fb, Vec &rPoint, Vec &n0, float &dist); 00172 00173 void relabelCL(core::DataSegment<float,4> &xyzh, core::Img8u &newMask, core::Img32s &oldLabel, core::Img32s &newLabel, 00174 int desiredID, int srcID, float threshold, Result &result, int w, int h); 00175 00176 void relabelCPU(core::DataSegment<float,4> &xyzh, core::Img8u &newMask, core::Img32s &oldLabel, core::Img32s &newLabel, 00177 int desiredID, int srcID, float threshold, Result &result, int w, int h); 00178 00179 }; 00180 00181 } // namespace geom 00182 }