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.epipolar.estimators;
17  
18  import com.irurueta.geometry.EuclideanTransformation3D;
19  
20  /**
21   * Contains decomposition data of an homography.
22   */
23  public class HomographyDecomposition {
24  
25      /**
26       * Length of plane normal vector.
27       */
28      public static final int PLANE_NORMAL_LENGTH = 3;
29  
30      /**
31       * Contains rotation and translation obtained from homography decomposition.
32       */
33      private EuclideanTransformation3D transformation;
34  
35      /**
36       * Contains computed plane normal obtained from homography decomposition.
37       */
38      private double[] planeNormal;
39  
40      /**
41       * Distance to computed plane.
42       */
43      private double planeDistance;
44  
45      /**
46       * Constructor.
47       */
48      public HomographyDecomposition() {
49      }
50  
51      /**
52       * Constructor.
53       *
54       * @param transformation transformation containing rotation and translation
55       *                       obtained from homography decomposition.
56       * @param planeNormal    computed plane normal obtained from homography
57       *                       decomposition.
58       * @param planeDistance  distance to computed plane.
59       * @throws IllegalArgumentException if provided plane normal does not have
60       *                                  length 3.
61       */
62      public HomographyDecomposition(final EuclideanTransformation3D transformation, final double[] planeNormal,
63                                     final double planeDistance) {
64          setPlaneNormal(planeNormal);
65          this.transformation = transformation;
66          this.planeDistance = planeDistance;
67      }
68  
69      /**
70       * Gets rotation and translation obtained from homography decomposition.
71       *
72       * @return rotation and translation obtained from homography decomposition.
73       */
74      public EuclideanTransformation3D getTransformation() {
75          return transformation;
76      }
77  
78      /**
79       * Sets rotation and translation obtained from homography decomposition.
80       *
81       * @param transformation rotation and translation obtained from homography
82       *                       decomposition.
83       */
84      public void setTransformation(final EuclideanTransformation3D transformation) {
85          this.transformation = transformation;
86      }
87  
88      /**
89       * Gets computed plane normal obtained from homography decomposition.
90       *
91       * @return plane normal obtained from homography decomposition.
92       */
93      public double[] getPlaneNormal() {
94          return planeNormal;
95      }
96  
97      /**
98       * Sets computed plane normal obtained from homography decomposition.
99       *
100      * @param planeNormal plane normal obtained from homography decomposition.
101      * @throws IllegalArgumentException if provided plane normal does not have
102      *                                  length 3.
103      */
104     public final void setPlaneNormal(final double[] planeNormal) {
105         if (planeNormal.length != PLANE_NORMAL_LENGTH) {
106             throw new IllegalArgumentException();
107         }
108         this.planeNormal = planeNormal;
109     }
110 
111     /**
112      * Gets distance to computed plane.
113      *
114      * @return distance to computed plane.
115      */
116     public double getPlaneDistance() {
117         return planeDistance;
118     }
119 
120     /**
121      * Sets distance to computed plane.
122      *
123      * @param planeDistance distance to computed plane.
124      */
125     public void setPlaneDistance(final double planeDistance) {
126         this.planeDistance = planeDistance;
127     }
128 }