IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
DistortionCoefficients.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Globalization;
4
6
52public class DistortionCoefficients : IEquatable<DistortionCoefficients>
53{
58 public const int RadialDistortionMaxElements = 6;
59
64 public const int TangentialDistortionMaxElements = 2;
65
70 public const int PrismDistortionMaxElements = 4;
71
76 public const int TiltDistortionMaxElements = 2;
77
91 public DistortionCoefficients(double[] radialDistortion, double[] tangentialDistortion)
92 {
93 RadialDistortion = radialDistortion;
94 TangentialDistortion = tangentialDistortion;
95 PrismDistortion = Array.Empty<double>();
96 TiltDistortion = Array.Empty<double>();
97
99 }
100
118 double[] radialDistortion,
119 double[] tangentialDistortion,
120 double[] prismDistortion)
121 {
122 RadialDistortion = radialDistortion;
123 TangentialDistortion = tangentialDistortion;
124 PrismDistortion = prismDistortion;
125 TiltDistortion = Array.Empty<double>();
126
128 }
129
150 double[] radialDistortion,
151 double[] tangentialDistortion,
152 double[] prismDistortion,
153 double[] tiltDistortion)
154 {
155 RadialDistortion = radialDistortion;
156 TangentialDistortion = tangentialDistortion;
157 PrismDistortion = prismDistortion;
158 TiltDistortion = tiltDistortion;
159
161 }
162
163 internal DistortionCoefficients(Backend.Types.peak_icv_distortion_coefficients distortionCoefficients)
164 {
165 unsafe
166 {
167 RadialDistortion = Utils.FromFixedArray(distortionCoefficients.radial_distortion.coefficients,
169 TangentialDistortion = Utils.FromFixedArray(
170 distortionCoefficients.tangential_distortion.coefficients,
172 PrismDistortion = Utils.FromFixedArray(distortionCoefficients.prism_distortion.coefficients,
174 TiltDistortion = Utils.FromFixedArray(distortionCoefficients.tilt_distortion.coefficients,
176 }
177 }
178
183 public double[] PrismDistortion { get; }
184
189 public double[] RadialDistortion { get; }
190
195 public double[] TangentialDistortion { get; }
196
201 public double[] TiltDistortion { get; }
202
207 public bool Equals(DistortionCoefficients? other)
208 {
209 if (ReferenceEquals(other, null)) return false;
210 return RadialDistortion.SequenceEqual(other.RadialDistortion) &&
211 TangentialDistortion.SequenceEqual(other.TangentialDistortion) &&
212 PrismDistortion.SequenceEqual(other.PrismDistortion) &&
213 TiltDistortion.SequenceEqual(other.TiltDistortion);
214 }
215
220 public override bool Equals(object? other)
221 {
222 if (other is null) return false;
223 if (ReferenceEquals(this, other)) return true;
224 return Equals(other as DistortionCoefficients);
225 }
226
231 public override int GetHashCode()
232 {
233 return (
234 StructuralComparisons.StructuralEqualityComparer.GetHashCode(RadialDistortion),
235 StructuralComparisons.StructuralEqualityComparer.GetHashCode(TangentialDistortion),
236 StructuralComparisons.StructuralEqualityComparer.GetHashCode(PrismDistortion),
237 StructuralComparisons.StructuralEqualityComparer.GetHashCode(TiltDistortion)).GetHashCode();
238 }
239
244 public override string ToString()
245 {
246 return "Radial: " + FormatDistortion(RadialDistortion) + ", " +
247 "Tangential: " + FormatDistortion(TangentialDistortion) + ", " +
248 "Prism: " + FormatDistortion(PrismDistortion) + ", " +
249 "Tilt: " + FormatDistortion(TiltDistortion);
250
251 string FormatDistortion(double[] distortionArray)
252 {
253 return "(" + string.Join(", ",
254 distortionArray.Select(d => d.ToString("0.0", CultureInfo.InvariantCulture))) + ")";
255 }
256 }
257
258 internal Backend.Types.peak_icv_distortion_coefficients ToCType()
259 {
260 unsafe
261 {
262 var result = new Backend.Types.peak_icv_distortion_coefficients();
263
264 Utils.ToFixedArray(RadialDistortion, result.radial_distortion.coefficients);
265 Utils.ToFixedArray(TangentialDistortion, result.tangential_distortion.coefficients);
266 Utils.ToFixedArray(PrismDistortion, result.prism_distortion.coefficients);
267 Utils.ToFixedArray(TiltDistortion, result.tilt_distortion.coefficients);
268
269 return result;
270 }
271 }
272
273 private static void ValidateArraySizes(
274 double[] radialDistortion,
275 double[] tangentialDistortion,
276 double[] prismDistortion,
277 double[] tiltDistortion)
278 {
279 ValidateSize(radialDistortion, RadialDistortionMaxElements, "radial distortion");
280 ValidateSize(tangentialDistortion, TangentialDistortionMaxElements, " tangential distortion");
281 ValidateSize(prismDistortion, PrismDistortionMaxElements, "prism distortion");
282 ValidateSize(tiltDistortion, TiltDistortionMaxElements, "tilt distortion");
283 return;
284
285 void ValidateSize(double[] distortionArray, int maxSize, string name)
286 {
287 if (distortionArray.Length > maxSize)
288 {
289 throw new IcvNotPossibleException(
290 $"The given {name} array size is incorrect. Expected to be smaller than or equal to size: {maxSize}, but got: {distortionArray.Length}.");
291 }
292 }
293 }
294}
const int RadialDistortionMaxElements
Maximum number of radial distortion coefficients.
const int PrismDistortionMaxElements
Maximum number of prism distortion coefficients.
override bool Equals(object? other)
Compares the distortion coefficients by value.
DistortionCoefficients(double[] radialDistortion, double[] tangentialDistortion, double[] prismDistortion)
Creates distortion coefficients from radial, tangential and prism distortion coefficients.
override int GetHashCode()
Generates a hash code from the coefficients.
bool Equals(DistortionCoefficients? other)
Compares the distortion coefficients by value.
override string ToString()
Returns a string representation of the distortion coefficients.
DistortionCoefficients(double[] radialDistortion, double[] tangentialDistortion)
Creates distortion coefficients from radial and tangential distortion coefficients.
DistortionCoefficients(double[] radialDistortion, double[] tangentialDistortion, double[] prismDistortion, double[] tiltDistortion)
Creates distortion coefficients from radial, tangential, prism and tilt distortion coefficients.
const int TangentialDistortionMaxElements
Maximum number of tangential distortion coefficients.
const int TiltDistortionMaxElements
Maximum number of tilt distortion coefficients.
Occurs when an operation cannot be performed due to logical constraints (e.g., camera calibration wit...
Definition Exception.cs:102