ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkRANSAC.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18
19#ifndef itkRANSAC_h
20#define itkRANSAC_h
21
22#include <set>
23#include <vector>
24#include <stdlib.h>
25#include <math.h>
26#include <time.h>
27#include <limits>
30#include <mutex>
31#include "itkMacro.h"
32#include "nanoflann.hpp"
33
65
66namespace itk
67{
68
75
76template <typename T, typename SType, typename TTransform>
77class ITK_TEMPLATE_EXPORT RANSAC : public Object
78{
79public:
80 ITK_DISALLOW_COPY_AND_MOVE(RANSAC);
81
82 typedef RANSAC Self;
88
89 itkOverrideGetNameOfClassMacro(RANSAC);
91 itkNewMacro(Self);
92
99 void
101 void
103 unsigned int
105
112 void
114
120 void
121 SetData(std::vector<T> & data);
122
128 void
129 SetAgreeData(std::vector<T> & data);
130
148 std::vector<double>
149 Compute(std::vector<SType> & parameters, double desiredProbabilityForNoOutliers);
150
151 void
153
154 bool
156
157 void
159
160 double
162
163protected:
170 ~RANSAC() override;
171
172private:
180 unsigned int
181 Choose(unsigned int n, unsigned int m);
182
184 {
185 private:
187
188 public:
189 SubSetIndexComparator(int arrayLength)
190 : length(arrayLength)
191 {}
192 bool
193 operator()(const int * arr1, const int * arr2) const
194 {
195 for (int i = 0; i < this->length; i++)
196 {
197 if (arr1[i] < arr2[i])
198 return true;
199 else if (arr1[i] > arr2[i])
200 return false;
201 }
202 return false;
203 }
204 };
205
208
209 // number of threads used in computing the RANSAC hypotheses
210 unsigned int numberOfThreads;
211 unsigned int maxIteration{ std::numeric_limits<unsigned int>::max() };
212
215
216 // the following variables are shared by all threads used in the RANSAC
217 // computation
218
219 // array corresponding to length of data array, data[i]== true if it
220 // agrees with the best model, otherwise false
221 bool * bestVotes;
222 unsigned int numVotesForBest;
223 double bestRMSE{ std::numeric_limits<double>::max() };
224
225 std::vector<T> data;
226 std::vector<T> agreeData;
227 std::vector<double> parametersRansac;
228
229 // set which holds all of the subgroups/hypotheses already selected
230 std::set<int *, SubSetIndexComparator> * chosenSubSets;
231 // number of iterations, equivalent to desired number of hypotheses
232 unsigned int numTries;
233
234 double numerator;
235 unsigned int allTries;
236
238 std::mutex hypothesisMutex;
239 std::mutex resultsMutex;
240};
241
242} // end namespace itk
243
244#ifndef ITK_MANUAL_INSTANTIATION
245# include "itkRANSAC.hxx"
246#endif
247
248#endif //_RANSAC_H_
bool operator()(const int *arr1, const int *arr2) const
Definition itkRANSAC.h:193
SubSetIndexComparator(int arrayLength)
Definition itkRANSAC.h:189
SmartPointer< const Self > ConstPointer
Definition itkRANSAC.h:85
std::set< int *, SubSetIndexComparator > * chosenSubSets
Definition itkRANSAC.h:230
std::vector< double > Compute(std::vector< SType > &parameters, double desiredProbabilityForNoOutliers)
void SetCheckCorrespondenceEdgeLength(double inputLength)
unsigned int allTries
Definition itkRANSAC.h:235
typename itk::ParametersEstimator< T, SType > ParametersEstimatorType
Definition itkRANSAC.h:87
unsigned int numberOfThreads
Definition itkRANSAC.h:210
bool GetCheckCorresspondenceDistance()
std::mutex resultsMutex
Definition itkRANSAC.h:239
unsigned int maxIteration
Definition itkRANSAC.h:211
RANSAC Self
Definition itkRANSAC.h:82
void SetCheckCorresspondenceDistance(bool inputFlag)
unsigned int GetNumberOfThreads()
ParametersEstimator< T, SType >::Pointer paramEstimator
Definition itkRANSAC.h:237
void SetMaxIteration(unsigned int maxIteration)
bool * bestVotes
Definition itkRANSAC.h:221
std::mutex hypothesisMutex
Definition itkRANSAC.h:238
SmartPointer< Self > Pointer
Definition itkRANSAC.h:84
double checkCorrespondenceEdgeLengthTest
Definition itkRANSAC.h:214
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION RANSACThreadCallback(void *arg)
void SetParametersEstimator(ParametersEstimatorType *paramEstimator)
void SetData(std::vector< T > &data)
void SetNumberOfThreads(unsigned int numberOfThreads)
double numerator
Definition itkRANSAC.h:234
std::vector< T > data
Definition itkRANSAC.h:225
~RANSAC() override
unsigned int Choose(unsigned int n, unsigned int m)
unsigned int numTries
Definition itkRANSAC.h:232
bool checkCorresspondenceDistanceFlag
Definition itkRANSAC.h:213
double GetCheckCorrespondenceEdgeLength()
void SetAgreeData(std::vector< T > &data)
Object Superclass
Definition itkRANSAC.h:83
std::vector< double > parametersRansac
Definition itkRANSAC.h:227
unsigned int numVotesForBest
Definition itkRANSAC.h:222
typename itk::ParametersEstimator< T, SType >::Pointer ParametersEstimatorPointer
Definition itkRANSAC.h:86
std::vector< T > agreeData
Definition itkRANSAC.h:226
double bestRMSE
Definition itkRANSAC.h:223
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ITK_THREAD_RETURN_TYPE ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION