View Javadoc
1   /*
2    * Copyright (C) 2017 Alberto Irurueta Carro (alberto@irurueta.com)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.irurueta.ar.sfm;
17  
18  import com.irurueta.ar.epipolar.CorrectorType;
19  import com.irurueta.ar.epipolar.estimators.FundamentalMatrixEstimatorMethod;
20  import com.irurueta.ar.epipolar.estimators.FundamentalMatrixRobustEstimator;
21  import com.irurueta.ar.epipolar.estimators.PROSACFundamentalMatrixRobustEstimator;
22  import com.irurueta.geometry.PinholeCameraIntrinsicParameters;
23  import com.irurueta.geometry.estimators.ProjectiveTransformation2DRobustEstimator;
24  import com.irurueta.numerical.robust.RobustEstimatorMethod;
25  
26  import java.io.Serializable;
27  
28  /**
29   * Base class containing configuration for a two view sparse re-constructor.
30   *
31   * @param <T> an actual implementation of a configuration class.
32   */
33  public abstract class BaseTwoViewsSparseReconstructorConfiguration<
34          T extends BaseTwoViewsSparseReconstructorConfiguration<T>> implements Serializable {
35      /**
36       * Default robust fundamental matrix estimator method.
37       * This is only used when general scenes are allowed.
38       */
39      public static final RobustEstimatorMethod DEFAULT_ROBUST_FUNDAMENTAL_MATRIX_ESTIMATOR_METHOD =
40              RobustEstimatorMethod.PROSAC;
41  
42      /**
43       * Default non-robust fundamental matrix estimator method used internally
44       * within a robust estimator.
45       * This is only used when general scenes are allowed.
46       */
47      public static final FundamentalMatrixEstimatorMethod DEFAULT_NON_ROBUST_FUNDAMENTAL_MATRIX_ESTIMATOR_METHOD =
48              FundamentalMatrixEstimatorMethod.SEVEN_POINTS_ALGORITHM;
49  
50      /**
51       * Indicates that estimated fundamental matrix is refined by default using
52       * all found inliers.
53       * This is only used when general scenes are allowed.
54       */
55      public static final boolean DEFAULT_REFINE_FUNDAMENTAL_MATRIX = true;
56  
57      /**
58       * Indicates that fundamental matrix covariance is kept by default after the
59       * estimation.
60       * This is only used when general scenes are allowed.
61       */
62      public static final boolean DEFAULT_KEEP_FUNDAMENTAL_MATRIX_COVARIANCE = false;
63  
64      /**
65       * Default confidence of robustly estimated fundamental matrix. By default,
66       * this is 99%.
67       * This is only used when general scenes are allowed.
68       */
69      public static final double DEFAULT_FUNDAMENTAL_MATRIX_CONFIDENCE =
70              FundamentalMatrixRobustEstimator.DEFAULT_CONFIDENCE;
71  
72      /**
73       * Default maximum number of iterations to make while robustly estimating
74       * fundamental matrix. By default, this is 5000 iterations.
75       * This is only used when general scenes are allowed.
76       */
77      public static final int DEFAULT_FUNDAMENTAL_MATRIX_MAX_ITERATIONS =
78              FundamentalMatrixRobustEstimator.DEFAULT_MAX_ITERATIONS;
79  
80      /**
81       * Default threshold to determine whether samples for robust fundamental
82       * matrix estimation are inliers or not.
83       * This is only used when general scenes are allowed.
84       */
85      public static final double DEFAULT_FUNDAMENTAL_MATRIX_THRESHOLD =
86              PROSACFundamentalMatrixRobustEstimator.DEFAULT_THRESHOLD;
87  
88      /**
89       * Default value indicating that inlier data is kept after robust
90       * fundamental matrix estimation.
91       * This is only used when general scenes are allowed.
92       */
93      public static final boolean DEFAULT_FUNDAMENTAL_MATRIX_COMPUTE_AND_KEEP_INLIERS = true;
94  
95      /**
96       * Default value indicating that residual data is kept after robust
97       * fundamental matrix estimation.
98       * This is only used when general scenes are allowed.
99       */
100     public static final boolean DEFAULT_FUNDAMENTAL_MATRIX_COMPUTE_AND_KEEP_RESIDUALS = true;
101 
102     /**
103      * Default method to use for initial estimation of cameras.
104      */
105     public static final InitialCamerasEstimatorMethod DEFAULT_INITIAL_CAMERAS_ESTIMATOR_METHOD =
106             InitialCamerasEstimatorMethod.DUAL_ABSOLUTE_QUADRIC_AND_ESSENTIAL_MATRIX;
107 
108     /**
109      * Indicates whether an homogeneous point triangulator is used for point
110      * triangulation when Dual Absolute Quadric (DAQ) camera initialization is
111      * used.
112      */
113     public static final boolean DEFAULT_DAQ_USE_HOMOGENEOUS_POINT_TRIANGULATOR = true;
114 
115     /**
116      * Default aspect ratio for initial cameras.
117      */
118     public static final double DEFAULT_INITIAL_CAMERAS_ASPECT_RATIO = 1.0;
119 
120     /**
121      * Default horizontal principal point value to use for initial cameras
122      * estimation using Dual Image of Absolute Conic (DIAC) or Dual Absolute
123      * Quadric (DAQ) methods.
124      */
125     public static final double DEFAULT_INITIAL_CAMERAS_PRINCIPAL_POINT_X = 0.0;
126 
127     /**
128      * Default vertical principal point value to use for initial cameras
129      * estimation using Dual Image of Absolute Conic (DIAC) or Dual Absolute
130      * Quadric (DAQ) methods.
131      */
132     public static final double DEFAULT_INITIAL_CAMERAS_PRINCIPAL_POINT_Y = 0.0;
133 
134     /**
135      * Default corrector type to use for point triangulation when initial
136      * cameras are being estimated using either Dual Image of Absolute Conic
137      * (DIAC), Dual Absolute Quadric (DAQ) or essential matrix methods.
138      */
139     public static final CorrectorType DEFAULT_INITIAL_CAMERAS_CORRECTOR_TYPE = CorrectorType.SAMPSON_CORRECTOR;
140 
141     /**
142      * Default value indicating whether valid triangulated points are marked
143      * during initial cameras estimation using either Dual Image of Absolute
144      * Conic (DIAC) or essential matrix methods.
145      */
146     public static final boolean DEFAULT_INITIAL_CAMERAS_MARK_VALID_TRIANGULATED_POINTS = true;
147 
148     /**
149      * Indicates whether a general (points are laying in a general 3D position)
150      * scene is allowed.
151      * When true, an initial geometry estimation is attempted for general
152      * points.
153      */
154     public static final boolean DEFAULT_ALLOW_GENERAL_SCENE = true;
155 
156     /**
157      * Indicates whether a planar (points laying in a 3D plane) scene is
158      * allowed.
159      * When true, an initial geometry estimation is attempted for planar points.
160      */
161     public static final boolean DEFAULT_ALLOW_PLANAR_SCENE = true;
162 
163     /**
164      * Default robust planar homography estimator method.
165      * This is only used when planar scenes are allowed.
166      */
167     public static final RobustEstimatorMethod DEFAULT_ROBUST_PLANAR_HOMOGRAPHY_ESTIMATOR_METHOD =
168             RobustEstimatorMethod.PROMEDS;
169 
170     /**
171      * Indicates that planar homography is refined by default using all found
172      * inliers.
173      * This is only used when planar scenes are allowed.
174      */
175     public static final boolean DEFAULT_REFINE_PLANAR_HOMOGRAPHY = true;
176 
177     /**
178      * Indicates that planar homography covariance is kept by default after
179      * estimation.
180      * This is only used when planar scenes are allowed.
181      */
182     public static final boolean DEFAULT_KEEP_PLANAR_HOMOGRAPHY_COVARIANCE = false;
183 
184     /**
185      * Default confidence of robustly estimated planar homography. By default,
186      * this is 99%.
187      * This is only used when planar scenes are allowed.
188      */
189     public static final double DEFAULT_PLANAR_HOMOGRAPHY_CONFIDENCE =
190             ProjectiveTransformation2DRobustEstimator.DEFAULT_CONFIDENCE;
191 
192     /**
193      * Default maximum number of iterations to make while robustly estimating
194      * planar homography. By default, this is 5000 iterations.
195      * This is only used when planar scenes are allowed.
196      */
197     public static final int DEFAULT_PLANAR_HOMOGRAPHY_MAX_ITERATIONS =
198             ProjectiveTransformation2DRobustEstimator.DEFAULT_MAX_ITERATIONS;
199 
200     /**
201      * Default threshold to determine whether samples for robust projective
202      * 2D transformation estimation are inliers or not.
203      * This is only used when planar scenes are allowed.
204      */
205     public static final double DEFAULT_PLANAR_HOMOGRAPHY_THRESHOLD = 1e-3;
206 
207     /**
208      * Default value indicating that inlier data is kept after robust planar
209      * homography estimation.
210      * This is only used when planar scenes are allowed.
211      */
212     public static final boolean DEFAULT_PLANAR_HOMOGRAPHY_COMPUTE_AND_KEEP_INLIERS = true;
213 
214     /**
215      * Default value indicating that residual data is kept after robust planar
216      * homography estimation.
217      * This is only used when planar scenes are allowed.
218      */
219     public static final boolean DEFAULT_PLANAR_HOMOGRAPHY_COMPUTE_AND_KEEP_RESIDUALS = true;
220 
221     /**
222      * Method to use for non-robust fundamental matrix estimation.
223      * This is only used when general scenes are allowed.
224      */
225     private FundamentalMatrixEstimatorMethod mNonRobustFundamentalMatrixEstimatorMethod =
226             DEFAULT_NON_ROBUST_FUNDAMENTAL_MATRIX_ESTIMATOR_METHOD;
227 
228     /**
229      * Method to use for robust fundamental matrix estimation.
230      * This is only used when general scenes are allowed.
231      */
232     private RobustEstimatorMethod mRobustFundamentalMatrixEstimatorMethod =
233             DEFAULT_ROBUST_FUNDAMENTAL_MATRIX_ESTIMATOR_METHOD;
234 
235     /**
236      * Indicates whether estimated fundamental matrix is refined among all found
237      * inliers.
238      * This is only used when general scenes are allowed.
239      */
240     private boolean refineFundamentalMatrix = DEFAULT_REFINE_FUNDAMENTAL_MATRIX;
241 
242     /**
243      * Indicates whether covariance of estimated fundamental matrix is kept
244      * after the estimation.
245      * This is only used when general scenes are allowed.
246      */
247     private boolean keepFundamentalMatrixCovariance = DEFAULT_KEEP_FUNDAMENTAL_MATRIX_COVARIANCE;
248 
249     /**
250      * Confidence of robustly estimated fundamental matrix.
251      * This is only used when general scenes are allowed.
252      */
253     private double fundamentalMatrixConfidence = DEFAULT_FUNDAMENTAL_MATRIX_CONFIDENCE;
254 
255     /**
256      * Maximum number of iterations to robustly estimate fundamental matrix.
257      * This is only used when general scenes are allowed.
258      */
259     private int fundamentalMatrixMaxIterations = DEFAULT_FUNDAMENTAL_MATRIX_MAX_ITERATIONS;
260 
261     /**
262      * Threshold to determine whether samples for robust fundamental matrix
263      * estimation are inliers or not.
264      * This is only used when general scenes are allowed.
265      */
266     private double fundamentalMatrixThreshold = DEFAULT_FUNDAMENTAL_MATRIX_THRESHOLD;
267 
268     /**
269      * Indicates whether inliers must be kept during robust fundamental matrix
270      * estimation.
271      * This is only used when general scenes are allowed.
272      */
273     private boolean fundamentalMatrixComputeAndKeepInliers = DEFAULT_FUNDAMENTAL_MATRIX_COMPUTE_AND_KEEP_INLIERS;
274 
275     /**
276      * Indicates whether residuals must be computed and kept during robust
277      * fundamental matrix estimation.
278      * This is only used when general scenes are allowed.
279      */
280     private boolean fundamentalMatrixComputeAndKeepResiduals = DEFAULT_FUNDAMENTAL_MATRIX_COMPUTE_AND_KEEP_RESIDUALS;
281 
282     /**
283      * Method to use for initial estimation of cameras.
284      */
285     private InitialCamerasEstimatorMethod initialCamerasEstimatorMethod = DEFAULT_INITIAL_CAMERAS_ESTIMATOR_METHOD;
286 
287     /**
288      * Indicates whether an homogeneous point triangulator is used for point
289      * triangulation when Dual Absolute Quadric (DAQ) camera initialization is
290      * used.
291      */
292     private boolean daqUseHomogeneousPointTriangulator = DEFAULT_DAQ_USE_HOMOGENEOUS_POINT_TRIANGULATOR;
293 
294     /**
295      * Aspect ratio for initial cameras.
296      */
297     private double initialCamerasAspectRatio = DEFAULT_INITIAL_CAMERAS_ASPECT_RATIO;
298 
299     /**
300      * Horizontal principal point value to use for initial cameras estimation
301      * using Dual Image of Absolute Conic (DIAC) or Dual Absolute Quadric (DAQ)
302      * methods.
303      */
304     private double principalPointX = DEFAULT_INITIAL_CAMERAS_PRINCIPAL_POINT_X;
305 
306     /**
307      * Vertical principal point value to use for initial cameras estimation
308      * using Dual Image of Absolute Conic (DIAC) or Dual Absolute Quadric (DAQ)
309      * methods.
310      */
311     private double principalPointY = DEFAULT_INITIAL_CAMERAS_PRINCIPAL_POINT_Y;
312 
313     /**
314      * Corrector type to use for point triangulation when initial cameras are
315      * being estimated using either Dual Image of Absolute Conic (DIAC) or
316      * essential matrix methods or null if no corrector is used.
317      */
318     private CorrectorType initialCamerasCorrectorType = DEFAULT_INITIAL_CAMERAS_CORRECTOR_TYPE;
319 
320     /**
321      * Value indicating whether valid triangulated points are marked during
322      * initial cameras estimation using either Dual Image of Absolute Conic
323      * (DIAC) or essential matrix methods.
324      */
325     private boolean initialCamerasMarkValidTriangulatedPoints = DEFAULT_INITIAL_CAMERAS_MARK_VALID_TRIANGULATED_POINTS;
326 
327     /**
328      * Intrinsic parameters of first camera estimated using the essential matrix
329      * method.
330      */
331     private PinholeCameraIntrinsicParameters initialIntrinsic1;
332 
333     /**
334      * Intrinsic parameters of second camera estimated using the essential
335      * matrix method.
336      */
337     private PinholeCameraIntrinsicParameters initialIntrinsic2;
338 
339     /**
340      * Indicates whether a general scene (points laying in a general 3D
341      * position) is allowed.
342      * When true, an initial geometry estimation is attempted for general
343      * points.
344      */
345     private boolean allowGeneralScene = DEFAULT_ALLOW_GENERAL_SCENE;
346 
347     /**
348      * Indicates whether a planar scene (points laying in a 3D plane) is allowed.
349      * When true, an initial geometry estimation is attempted for planar points.
350      */
351     private boolean allowPlanarScene = DEFAULT_ALLOW_PLANAR_SCENE;
352 
353     /**
354      * Robust method to use for planar homography estimation.
355      * This is only used when planar scenes are allowed.
356      */
357     private RobustEstimatorMethod robustPlanarHomographyEstimatorMethod =
358             DEFAULT_ROBUST_PLANAR_HOMOGRAPHY_ESTIMATOR_METHOD;
359 
360     /**
361      * Indicates whether planar homography is refined using all found inliers or
362      * not.
363      * This is only used when planar scenes are allowed.
364      */
365     private boolean refinePlanarHomography = DEFAULT_REFINE_PLANAR_HOMOGRAPHY;
366 
367     /**
368      * Indicates whether planar homography covariance is kept after estimation.
369      * This is only used when planar scenes are allowed.
370      */
371     private boolean keepPlanarHomographyCovariance = DEFAULT_KEEP_PLANAR_HOMOGRAPHY_COVARIANCE;
372 
373     /**
374      * Confidence of robustly estimated planar homography. By default, this is
375      * 99%.
376      * This is only used when planar scenes are allowed.
377      */
378     private double planarHomographyConfidence = DEFAULT_PLANAR_HOMOGRAPHY_CONFIDENCE;
379 
380     /**
381      * Maximum number of iterations to make while robustly estimating planar
382      * homography. By default, this is 5000.
383      * This is only used when planar scenes are allowed.
384      */
385     private int planarHomographyMaxIterations = DEFAULT_PLANAR_HOMOGRAPHY_MAX_ITERATIONS;
386 
387     /**
388      * Threshold to determine whether samples for robust projective 2D
389      * transformation estimation are inliers or not.
390      */
391     private double planarHomographyThreshold = DEFAULT_PLANAR_HOMOGRAPHY_THRESHOLD;
392 
393     /**
394      * Value indicating that inlier data is kept after robust planar homography
395      * estimation.
396      * This is only used when planar scenes are allowed.
397      */
398     private boolean planarHomographyComputeAndKeepInliers = DEFAULT_PLANAR_HOMOGRAPHY_COMPUTE_AND_KEEP_INLIERS;
399 
400     /**
401      * Value indicating that residual data is kept after robust planar
402      * homography estimation.
403      * This is only used when planar scenes are allowed.
404      */
405     private boolean planarHomographyComputeAndKeepResiduals = DEFAULT_PLANAR_HOMOGRAPHY_COMPUTE_AND_KEEP_RESIDUALS;
406 
407     /**
408      * Constructor.
409      */
410     protected BaseTwoViewsSparseReconstructorConfiguration() {
411     }
412 
413     /**
414      * Gets method to use for non-robust fundamental matrix estimation.
415      * This is only used when general scenes are allowed.
416      *
417      * @return method to use for non-robust fundamental matrix estimation.
418      */
419     public FundamentalMatrixEstimatorMethod getNonRobustFundamentalMatrixEstimatorMethod() {
420         return mNonRobustFundamentalMatrixEstimatorMethod;
421     }
422 
423     /**
424      * Sets method to use for non-robust fundamental matrix estimation.
425      * This is only used when general scenes are allowed.
426      *
427      * @param method method to use for non-robust fundamental matrix estimation.
428      * @return this instance so that method can be easily chained.
429      */
430     public T setNonRobustFundamentalMatrixEstimatorMethod(final FundamentalMatrixEstimatorMethod method) {
431         mNonRobustFundamentalMatrixEstimatorMethod = method;
432         //noinspection unchecked
433         return (T) this;
434     }
435 
436     /**
437      * Gets method to use for robust fundamental matrix estimation.
438      * This is only used when general scenes are allowed.
439      *
440      * @return method to use for robust fundamental matrix estimation.
441      */
442     public RobustEstimatorMethod getRobustFundamentalMatrixEstimatorMethod() {
443         return mRobustFundamentalMatrixEstimatorMethod;
444     }
445 
446     /**
447      * Sets method to use for robust fundamental matrix estimation.
448      * This is only used when general scenes are allowed.
449      *
450      * @param method method to use for robust fundamental matrix estimation.
451      * @return this instance so that method can be easily chained.
452      */
453     public T setRobustFundamentalMatrixEstimatorMethod(final RobustEstimatorMethod method) {
454         mRobustFundamentalMatrixEstimatorMethod = method;
455         //noinspection unchecked
456         return (T) this;
457     }
458 
459     /**
460      * Indicates whether estimated fundamental matrix is refined among all found
461      * inliers.
462      * This is only used when general scenes are allowed.
463      *
464      * @return true if fundamental matrix is refined, false otherwise.
465      */
466     public boolean isFundamentalMatrixRefined() {
467         return refineFundamentalMatrix;
468     }
469 
470     /**
471      * Specifies whether estimated fundamental matrix is refined among all found
472      * inliers.
473      * This is only used when general scenes are allowed.
474      *
475      * @param refineFundamentalMatrix true if fundamental matrix is refined,
476      *                                false otherwise.
477      * @return this instance so that method can be easily chained.
478      */
479     public T setFundamentalMatrixRefined(final boolean refineFundamentalMatrix) {
480         this.refineFundamentalMatrix = refineFundamentalMatrix;
481         //noinspection unchecked
482         return (T) this;
483     }
484 
485     /**
486      * Indicates whether covariance of estimated fundamental matrix is kept
487      * after the estimation.
488      * This is only used when general scenes are allowed.
489      *
490      * @return true if covariance is kept, false otherwise.
491      */
492     public boolean isFundamentalMatrixCovarianceKept() {
493         return keepFundamentalMatrixCovariance;
494     }
495 
496     /**
497      * Specifies whether covariance of estimated fundamental matrix is kept
498      * after the estimation.
499      * This is only used when general scenes are allowed.
500      *
501      * @param keepFundamentalMatrixCovariance true if covariance is kept, false
502      *                                        otherwise.
503      * @return this instance so that method can be easily chained.
504      */
505     public T setFundamentalMatrixCovarianceKept(final boolean keepFundamentalMatrixCovariance) {
506         this.keepFundamentalMatrixCovariance = keepFundamentalMatrixCovariance;
507         //noinspection unchecked
508         return (T) this;
509     }
510 
511     /**
512      * Gets confidence of robustly estimated fundamental matrix.
513      * This is only used when general scenes are allowed.
514      *
515      * @return confidence of robustly estimated fundamental matrix.
516      */
517     public double getFundamentalMatrixConfidence() {
518         return fundamentalMatrixConfidence;
519     }
520 
521     /**
522      * Sets confidence of robustly estimated fundamental matrix.
523      * This is only used when general scenes are allowed.
524      *
525      * @param fundamentalMatrixConfidence confidence of robustly estimated
526      *                                    fundamental matrix.
527      * @return this instance so that method can be easily chained.
528      */
529     public T setFundamentalMatrixConfidence(final double fundamentalMatrixConfidence) {
530         this.fundamentalMatrixConfidence = fundamentalMatrixConfidence;
531         //noinspection unchecked
532         return (T) this;
533     }
534 
535     /**
536      * Gets maximum number of iterations to robustly estimate fundamental
537      * matrix.
538      * This is only used when general scenes are allowed.
539      *
540      * @return maximum number of iterations to robustly estimate fundamental
541      * matrix.
542      */
543     public int getFundamentalMatrixMaxIterations() {
544         return fundamentalMatrixMaxIterations;
545     }
546 
547     /**
548      * Sets maximum number of iterations to robustly estimate fundamental
549      * matrix.
550      * This is only used when general scenes are allowed.
551      *
552      * @param fundamentalMatrixMaxIterations maximum number of iterations to
553      *                                       robustly estimate fundamental matrix.
554      * @return this instance so that method can be easily chained.
555      */
556     public T setFundamentalMatrixMaxIterations(final int fundamentalMatrixMaxIterations) {
557         this.fundamentalMatrixMaxIterations = fundamentalMatrixMaxIterations;
558         //noinspection unchecked
559         return (T) this;
560     }
561 
562     /**
563      * Gets threshold to determine whether samples for robust fundamental matrix
564      * estimation are inliers or not.
565      * This is only used when general scenes are allowed.
566      *
567      * @return threshold to determine whether samples for robust fundamental
568      * matrix estimation are inliers or not.
569      */
570     public double getFundamentalMatrixThreshold() {
571         return fundamentalMatrixThreshold;
572     }
573 
574     /**
575      * Sets threshold to determine whether samples for robust fundamental matrix
576      * estimation are inliers or not.
577      * This is only used when general scenes are allowed.
578      *
579      * @param fundamentalMatrixThreshold threshold to determine whether samples
580      *                                   for robust fundamental matrix estimation are inliers or not.
581      * @return this instance so that method can be easily chained.
582      */
583     public T setFundamentalMatrixThreshold(final double fundamentalMatrixThreshold) {
584         this.fundamentalMatrixThreshold = fundamentalMatrixThreshold;
585         //noinspection unchecked
586         return (T) this;
587     }
588 
589     /**
590      * Indicates whether inliers must be kept during robust fundamental matrix
591      * estimation.
592      * This is only used when general scenes are allowed.
593      *
594      * @return true if inliers must be kept during robust fundamental matrix
595      * estimation, false otherwise.
596      */
597     public boolean getFundamentalMatrixComputeAndKeepInliers() {
598         return fundamentalMatrixComputeAndKeepInliers;
599     }
600 
601     /**
602      * Specifies whether inliers must be kept during robust fundamental matrix
603      * estimation.
604      * This is only used when general scenes are allowed.
605      *
606      * @param fundamentalMatrixComputeAndKeepInliers true if inliers must be
607      *                                               kept during robust fundamental matrix estimation,
608      *                                               false otherwise.
609      * @return this instance so that method can be easily chained.
610      */
611     public T setFundamentalMatrixComputeAndKeepInliers(final boolean fundamentalMatrixComputeAndKeepInliers) {
612         this.fundamentalMatrixComputeAndKeepInliers = fundamentalMatrixComputeAndKeepInliers;
613         //noinspection unchecked
614         return (T) this;
615     }
616 
617     /**
618      * Indicates whether residuals must be computed and kept during robust
619      * fundamental matrix estimation.
620      * This is only used when general scenes are allowed.
621      *
622      * @return true if residuals must be computed and kept, false otherwise.
623      */
624     public boolean getFundamentalMatrixComputeAndKeepResiduals() {
625         return fundamentalMatrixComputeAndKeepResiduals;
626     }
627 
628     /**
629      * Specifies whether residuals must be computed and kept during robust
630      * fundamental matrix estimation.
631      * This is only used when general scenes are allowed.
632      *
633      * @param fundamentalMatrixComputeAndKeepResiduals true if residuals must be
634      *                                                 computed and kept, false otherwise.
635      * @return this instance so that method can be easily chained.
636      */
637     public T setFundamentalMatrixComputeAndKeepResiduals(final boolean fundamentalMatrixComputeAndKeepResiduals) {
638         this.fundamentalMatrixComputeAndKeepResiduals = fundamentalMatrixComputeAndKeepResiduals;
639         //noinspection unchecked
640         return (T) this;
641     }
642 
643     /**
644      * Gets method to use for initial estimation of cameras.
645      *
646      * @return method to use for initial estimation of cameras.
647      */
648     public InitialCamerasEstimatorMethod getInitialCamerasEstimatorMethod() {
649         return initialCamerasEstimatorMethod;
650     }
651 
652     /**
653      * Sets method to use for initial estimation of cameras.
654      *
655      * @param method method to use for initial estimation of cameras.
656      * @return this instance so that method can be easily chained.
657      */
658     public T setInitialCamerasEstimatorMethod(final InitialCamerasEstimatorMethod method) {
659         initialCamerasEstimatorMethod = method;
660         //noinspection unchecked
661         return (T) this;
662     }
663 
664     /**
665      * Indicates whether an homogeneous point triangulator is used for point
666      * triangulation when Dual Absolute Quadric (DAQ) camera initialization is
667      * used.
668      *
669      * @return true if homogeneous point triangulator is used, false if an
670      * inhomogeneous point triangulator is used instead.
671      */
672     public boolean getDaqUseHomogeneousPointTriangulator() {
673         return daqUseHomogeneousPointTriangulator;
674     }
675 
676     /**
677      * Specifies whether an homogeneous point triangulator is used for point
678      * triangulation when Dual Absolute Quadric (DAQ) camera initialization is
679      * used.
680      *
681      * @param daqUseHomogeneousPointTriangulator true if homogeneous point
682      *                                           triangulator is used, false if an inhomogeneous point
683      *                                           triangulator is used instead.
684      * @return this instance so that method can be easily chained.
685      */
686     public T setDaqUseHomogeneousPointTriangulator(final boolean daqUseHomogeneousPointTriangulator) {
687         this.daqUseHomogeneousPointTriangulator = daqUseHomogeneousPointTriangulator;
688         //noinspection unchecked
689         return (T) this;
690     }
691 
692     /**
693      * Gets aspect ratio for initial cameras estimation using DAQ or DIAC
694      * methods.
695      *
696      * @return aspect ratio for initial cameras using DAQ or DIAC methods.
697      */
698     public double getInitialCamerasAspectRatio() {
699         return initialCamerasAspectRatio;
700     }
701 
702     /**
703      * Sets aspect ratio for initial cameras using DAQ or DIAC methods.
704      *
705      * @param initialCamerasAspectRatio aspect ratio for initial cameras using
706      *                                  DAQ or DIAC methods.
707      * @return this instance so that method can be easily chained.
708      */
709     public T setInitialCamerasAspectRatio(final double initialCamerasAspectRatio) {
710         this.initialCamerasAspectRatio = initialCamerasAspectRatio;
711         //noinspection unchecked
712         return (T) this;
713     }
714 
715     /**
716      * Gets horizontal principal point value to use for initial cameras
717      * estimation using DIAC or DAQ methods.
718      *
719      * @return horizontal principal point value to use for initial cameras
720      * estimation using DIAC or DAQ methods.
721      */
722     public double getPrincipalPointX() {
723         return principalPointX;
724     }
725 
726     /**
727      * Sets horizontal principal point value to use for initial cameras
728      * estimation using DIAC or DAQ methods.
729      *
730      * @param principalPointX horizontal principal point value to use for
731      *                        initial cameras estimation using DIAC or DAQ methods.
732      * @return this instance so that method can be easily chained.
733      */
734     public T setPrincipalPointX(final double principalPointX) {
735         this.principalPointX = principalPointX;
736         //noinspection unchecked
737         return (T) this;
738     }
739 
740     /**
741      * Gets vertical principal point value to use for initial cameras estimation
742      * using DIAC or DAQ methods.
743      *
744      * @return vertical principal point value to use for initial cameras
745      * estimation using DIAC or DAQ methods.
746      */
747     public double getPrincipalPointY() {
748         return principalPointY;
749     }
750 
751     /**
752      * Sets vertical principal point value to use for initial cameras estimation
753      * using DIAC or DAQ methods.
754      *
755      * @param principalPointY vertical principal point value to use for
756      *                        initial cameras estimation using DIAC or DAQ methods.
757      * @return this instance so that method can be easily chained.
758      */
759     public T setPrincipalPointY(final double principalPointY) {
760         this.principalPointY = principalPointY;
761         //noinspection unchecked
762         return (T) this;
763     }
764 
765     /**
766      * Gets corrector type to use for point triangulation when initial cameras
767      * are being estimated using either DIAC or essential matrix methods or null
768      * if no corrector is used.
769      *
770      * @return corrector type to use for point triangulation when initial
771      * cameras are being estimated using either DIAC or essential matrix methods
772      * or null if no corrector is used.
773      */
774     public CorrectorType getInitialCamerasCorrectorType() {
775         return initialCamerasCorrectorType;
776     }
777 
778     /**
779      * Sets corrector type to use for point triangulation when initial cameras
780      * are being estimated using either DIAC or essential matrix methods or null
781      * if no corrector is used.
782      *
783      * @param type corrector type to use for point triangulation when initial
784      *             cameras are being estimated using either DIAC or essential matrix methods
785      *             or null if no corrector is used.
786      * @return this instance so that method can be easily chained.
787      */
788     public T setInitialCamerasCorrectorType(final CorrectorType type) {
789         initialCamerasCorrectorType = type;
790         //noinspection unchecked
791         return (T) this;
792     }
793 
794     /**
795      * Gets value indicating whether valid triangulated points are marked during
796      * initial cameras estimation using either DIAC or essential matrix methods.
797      *
798      * @return value indicating whether valid triangulated points are marked
799      * during initial cameras estimation using either DIAC or essential matrix
800      * methods.
801      */
802     public boolean getInitialCamerasMarkValidTriangulatedPoints() {
803         return initialCamerasMarkValidTriangulatedPoints;
804     }
805 
806     /**
807      * Sets value indicating whether valid triangulated points are marked during
808      * initial cameras estimation using either DIAC or essential matrix methods.
809      *
810      * @param initialCamerasMarkValidTriangulatedPoints value indicating whether
811      *                                                  valid triangulated points are marked during
812      *                                                  initial cameras estimation using either DIAC or
813      *                                                  essential matrix methods.
814      * @return this instance so that method can be easily chained.
815      */
816     public T setInitialCamerasMarkValidTriangulatedPoints(final boolean initialCamerasMarkValidTriangulatedPoints) {
817         this.initialCamerasMarkValidTriangulatedPoints = initialCamerasMarkValidTriangulatedPoints;
818         //noinspection unchecked
819         return (T) this;
820     }
821 
822     /**
823      * Gets intrinsic parameters of first camera estimated using the essential
824      * matrix method.
825      *
826      * @return intrinsic parameters of first camera estimated using the
827      * essential matrix method.
828      */
829     public PinholeCameraIntrinsicParameters getInitialIntrinsic1() {
830         return initialIntrinsic1;
831     }
832 
833     /**
834      * Sets intrinsic parameters of first camera estimated using the essential
835      * matrix method.
836      *
837      * @param initialIntrinsic1 intrinsic parameters of first camera estimated
838      *                          using the essential matrix method.
839      * @return this instance so that method can be easily chained.
840      */
841     public T setInitialIntrinsic1(final PinholeCameraIntrinsicParameters initialIntrinsic1) {
842         this.initialIntrinsic1 = initialIntrinsic1;
843         //noinspection unchecked
844         return (T) this;
845     }
846 
847     /**
848      * Gets intrinsic parameters of second camera estimated using the essential
849      * matrix method.
850      *
851      * @return intrinsic parameters of second camera estimated using the
852      * essential matrix method.
853      */
854     public PinholeCameraIntrinsicParameters getInitialIntrinsic2() {
855         return initialIntrinsic2;
856     }
857 
858     /**
859      * Sets intrinsic parameters of second camera estimated using the essential
860      * matrix method.
861      *
862      * @param initialIntrinsic2 intrinsic parameters of second camera estimated
863      *                          using the essential matrix method.
864      * @return this instance so that method can be easily chained.
865      */
866     public T setInitialIntrinsic2(final PinholeCameraIntrinsicParameters initialIntrinsic2) {
867         this.initialIntrinsic2 = initialIntrinsic2;
868         //noinspection unchecked
869         return (T) this;
870     }
871 
872     /**
873      * Indicates whether a general scene (points laying in a general 3D
874      * position) is allowed.
875      * When true, an initial geometry estimation is attempted for general
876      * points.
877      *
878      * @return true if general scene is allowed, false otherwise.
879      */
880     public boolean isGeneralSceneAllowed() {
881         return allowGeneralScene;
882     }
883 
884     /**
885      * Specifies whether a general scene (points laying in a general 3D
886      * position) is allowed.
887      * When true, an initial geometry estimation is attempted for general
888      * points.
889      *
890      * @param allowGeneralScene true if general scene is allowed, false
891      *                          otherwise.
892      * @return this instance so that method can be easily chained.
893      */
894     public T setGeneralSceneAllowed(final boolean allowGeneralScene) {
895         this.allowGeneralScene = allowGeneralScene;
896         //noinspection unchecked
897         return (T) this;
898     }
899 
900     /**
901      * Indicates whether a planar scene (points laying in a 3D plane) is allowed
902      * or not.
903      * When true, an initial geometry estimation is attempted for planar points.
904      *
905      * @return true if planar scene is allowed, false otherwise.
906      */
907     public boolean isPlanarSceneAllowed() {
908         return allowPlanarScene;
909     }
910 
911     /**
912      * Specifies whether a planar scene (points laying in a 3D plane) is allowed
913      * or not.
914      * When true, an initial geometry estimation is attempted for planar points.
915      *
916      * @param allowPlanarScene true if planar scene is allowed, false otherwise.
917      * @return this instance so that method can be easily chained.
918      */
919     public T setPlanarSceneAllowed(final boolean allowPlanarScene) {
920         this.allowPlanarScene = allowPlanarScene;
921         //noinspection unchecked
922         return (T) this;
923     }
924 
925     /**
926      * Gets robust method to use for planar homography estimation.
927      * This is only used when planar scenes are allowed.
928      *
929      * @return robust method to use for planar homography estimation.
930      */
931     public RobustEstimatorMethod getRobustPlanarHomographyEstimatorMethod() {
932         return robustPlanarHomographyEstimatorMethod;
933     }
934 
935     /**
936      * Sets robust method to use for planar homography estimation.
937      * This is only used when planar scenes are allowed.
938      *
939      * @param robustPlanarHomographyEstimatorMethod robust method to use for
940      *                                              planar homography estimation.
941      * @return this instance so that method can be easily chained.
942      */
943     public T setRobustPlanarHomographyEstimatorMethod(
944             final RobustEstimatorMethod robustPlanarHomographyEstimatorMethod) {
945         this.robustPlanarHomographyEstimatorMethod = robustPlanarHomographyEstimatorMethod;
946         //noinspection unchecked
947         return (T) this;
948     }
949 
950     /**
951      * Indicates whether planar homography is refined using all found inliers or
952      * not.
953      * This is only used when planar scenes are allowed.
954      *
955      * @return true if planar homography is refined, false otherwise.
956      */
957     public boolean isPlanarHomographyRefined() {
958         return refinePlanarHomography;
959     }
960 
961     /**
962      * Specifies whether planar homography is refined using all found inliers or
963      * not.
964      * This is only used when planar scenes are allowed.
965      *
966      * @param refinePlanarHomography true if planar homography must be refined,
967      *                               false otherwise.
968      * @return this instance so that method can be easily chained.
969      */
970     public T setPlanarHomographyRefined(final boolean refinePlanarHomography) {
971         this.refinePlanarHomography = refinePlanarHomography;
972         //noinspection unchecked
973         return (T) this;
974     }
975 
976     /**
977      * Indicates whether planar homography covariance is kept after estimation.
978      * This is only used when planar scenes are allowed.
979      *
980      * @return true if planar homography covariance is kept, false otherwise.
981      */
982     public boolean isPlanarHomographyCovarianceKept() {
983         return keepPlanarHomographyCovariance;
984     }
985 
986     /**
987      * Specifies whether planar homography covariance is kept after estimation.
988      * This is only used when planar scenes are allowed.
989      *
990      * @param keepPlanarHomographyCovariance true if planar homography
991      *                                       covariance is kept, false otherwise.
992      * @return this instance so that method can be easily chained.
993      */
994     public T setPlanarHomographyCovarianceKept(final boolean keepPlanarHomographyCovariance) {
995         this.keepPlanarHomographyCovariance = keepPlanarHomographyCovariance;
996         //noinspection unchecked
997         return (T) this;
998     }
999 
1000     /**
1001      * Gets confidence of robustly estimated planar homography. By default, this
1002      * is 99%.
1003      * This is only used when planar scenes are allowed.
1004      *
1005      * @return confidence of robustly estimated planar homography.
1006      */
1007     public double getPlanarHomographyConfidence() {
1008         return planarHomographyConfidence;
1009     }
1010 
1011     /**
1012      * Sets confidence of robustly estimated planar homography. By default, this
1013      * is 99%.
1014      * This is only used when planar scenes are allowed.
1015      *
1016      * @param planarHomographyConfidence confidence of robustly estimated planar
1017      *                                   homography.
1018      * @return this instance so that method can be easily chained.
1019      */
1020     public T setPlanarHomographyConfidence(final double planarHomographyConfidence) {
1021         this.planarHomographyConfidence = planarHomographyConfidence;
1022         //noinspection unchecked
1023         return (T) this;
1024     }
1025 
1026     /**
1027      * Gets maximum number of iterations to make while robustly estimating
1028      * planar homography. By default, this is 5000.
1029      * This is only used when planar scenes are allowed.
1030      *
1031      * @return maximum number of iterations to make while robustly estimating
1032      * planar homography.
1033      */
1034     public int getPlanarHomographyMaxIterations() {
1035         return planarHomographyMaxIterations;
1036     }
1037 
1038     /**
1039      * Sets maximum number of iterations to make while robustly estimating
1040      * planar homography. By default, this is 5000.
1041      * This is only used when planar scenes are allowed.
1042      *
1043      * @param planarHomographyMaxIterations maximum number of iterations to make
1044      *                                      while robustly estimating planar homography.
1045      * @return this instance so that method can be easily chained.
1046      */
1047     public T setPlanarHomographyMaxIterations(final int planarHomographyMaxIterations) {
1048         this.planarHomographyMaxIterations = planarHomographyMaxIterations;
1049         //noinspection unchecked
1050         return (T) this;
1051     }
1052 
1053     /**
1054      * Gets threshold to determine whether samples for robust projective 2D
1055      * transformation estimation are inliers or not.
1056      * This is only used when planar scenes are allowed.
1057      *
1058      * @return threshold to robustly estimate projective 2D transformation.
1059      */
1060     public double getPlanarHomographyThreshold() {
1061         return planarHomographyThreshold;
1062     }
1063 
1064     /**
1065      * Sets threshold to determine whether samples for robust projective 2D
1066      * transformation estimation are inliers or not.
1067      * This is only used when planar scenes are allowed.
1068      *
1069      * @param planarHomographyThreshold threshold to robustly estimate
1070      *                                  projective 2D transformation.
1071      * @return this instance so that method can be easily chained.
1072      */
1073     public T setPlanarHomographyThreshold(final double planarHomographyThreshold) {
1074         this.planarHomographyThreshold = planarHomographyThreshold;
1075         //noinspection unchecked
1076         return (T) this;
1077     }
1078 
1079     /**
1080      * Gets value indicating that inlier data is kept after robust planar
1081      * homography estimation.
1082      * This is only used when planar scenes are allowed.
1083      *
1084      * @return true if inlier data is kept, false otherwise.
1085      */
1086     public boolean getPlanarHomographyComputeAndKeepInliers() {
1087         return planarHomographyComputeAndKeepInliers;
1088     }
1089 
1090     /**
1091      * Specifies whether inlier data is kept after robust planar homography
1092      * estimation.
1093      * This is only used when planar scenes are allowed.
1094      *
1095      * @param planarHomographyComputeAndKeepInliers true if inlier data is kept,
1096      *                                              false otherwise.
1097      * @return this instance so that method can be easily chained.
1098      */
1099     public T setPlanarHomographyComputeAndKeepInliers(final boolean planarHomographyComputeAndKeepInliers) {
1100         this.planarHomographyComputeAndKeepInliers = planarHomographyComputeAndKeepInliers;
1101         //noinspection unchecked
1102         return (T) this;
1103     }
1104 
1105     /**
1106      * Gets value indicating that residual data is kept after robust planar
1107      * homography estimation.
1108      * This is only used when planar scenes are allowed.
1109      *
1110      * @return true if residual data is kept, false otherwise.
1111      */
1112     public boolean getPlanarHomographyComputeAndKeepResiduals() {
1113         return planarHomographyComputeAndKeepResiduals;
1114     }
1115 
1116     /**
1117      * Sets value indicating that residual data is kept after robust planar
1118      * homography estimation.
1119      * This is only used when planar scenes are allowed.
1120      *
1121      * @param planarHomographyComputeAndKeepResiduals true if residual data is
1122      *                                                kept, false otherwise.
1123      * @return this instance so that method can be easily chained.
1124      */
1125     public T setPlanarHomographyComputeAndKeepResiduals(final boolean planarHomographyComputeAndKeepResiduals) {
1126         this.planarHomographyComputeAndKeepResiduals = planarHomographyComputeAndKeepResiduals;
1127         //noinspection unchecked
1128         return (T) this;
1129     }
1130 }