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