IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
PointCloudXYZI.cs
Go to the documentation of this file.
1using System.Runtime.InteropServices;
7
9
17public class PointCloudXYZI : PointCloudT<PointXYZI>
18{
39 public PointCloudXYZI(XYZImage image, Image intensityImage)
40 : base(CreateFromXYZImage(image, intensityImage))
41 {
42 }
43
69 public PointCloudXYZI(UndistortedImage undistortedDepthMap, Image intensityImage)
70 : base(CreateFromUndistortedImage(undistortedDepthMap, intensityImage))
71 {
72 }
73
101 public PointCloudXYZI(string filePath, PixelFormat pixelFormat)
102 : base(LoadFromFile(filePath, pixelFormat))
103 {
104 }
105
119 public PointCloudXYZI(PointXYZI[] points, PixelFormat pixelFormat)
120 : base(CreateFromPoints(points, pixelFormat))
121 {
122 _points = points;
123 }
124
125 private PointCloudXYZI()
126 {
127 }
128
129 private PointCloudXYZI(Handle handle) : base(handle)
130 {
131 }
132
135 public override PointXYZI[] Points
136 {
137 get
138 {
139 if (_points != null)
140 {
141 return _points;
142 }
143
144 nuint numPoints = 0;
145 DllHelper.ExecuteAndMapReturnCodes(() =>
146 CInterface.peak_icv_PointCloud_GetPoints_GetCount(_handle, out numPoints));
147
148 if (numPoints == 0)
149 {
150 _points = Array.Empty<PointXYZI>();
151 return _points;
152 }
153
154 var pointsC = new Backend.Types.peak_icv_point_xyzi[numPoints];
155 var size = Marshal.SizeOf<Backend.Types.peak_icv_point_xyzi>();
156
157 var handle = GCHandle.Alloc(pointsC, GCHandleType.Pinned);
158
159 try
160 {
161 IntPtr ptr = handle.AddrOfPinnedObject();
162
163 DllHelper.ExecuteAndMapReturnCodes(() =>
164 CInterface.peak_icv_PointCloud_GetPoints(
165 _handle,
166 ptr,
167 (nuint) (size * (int) numPoints)));
168
169 _points = pointsC
170 .Select(np => new PointXYZI(np.x, np.y, np.z, np.intensity))
171 .ToArray();
172 }
173 finally
174 {
175 handle.Free();
176 }
177
178 return _points;
179 }
180 }
181
186 public static IEqualityComparer<PointCloudXYZI> Comparer { get; } = new PointCloudEqualityComparer();
187
188
200 {
201 var pointCloud = new PointCloudXYZI();
202 var cMatrix = matrix.ToCType();
203 DllHelper.ExecuteAndMapReturnCodes(() =>
204 CInterface.peak_icv_PointCloud_Transform(_handle, cMatrix,
205 ref pointCloud._handle));
206 return pointCloud;
207 }
208
220 {
221 var pointCloud = new PointCloudXYZI();
222 DllHelper.ExecuteAndMapReturnCodes(() =>
223 CInterface.peak_icv_PointCloud_TransformToWorkspace(_handle, extrinsicParameters.ToCType(),
224 (nuint) Marshal.SizeOf<Backend.Types.peak_icv_extrinsic_parameters>(),
225 ref pointCloud._handle));
226 return pointCloud;
227 }
228
229 private static Handle CreateFromXYZImage(XYZImage image, Image intensityImage)
230 {
231 var handle = new Handle();
232 DllHelper.ExecuteAndMapReturnCodes(() =>
233 CInterface.peak_icv_PointCloud_CreateFromXYZImageAndIntensityImage(out handle, image._handle,
234 intensityImage._handle));
235 return handle;
236 }
237
238 private static Handle CreateFromUndistortedImage(UndistortedImage undistortedDepthMap, Image intensityImage)
239 {
240 using var xyz = new XYZImage(undistortedDepthMap);
241 return CreateFromXYZImage(xyz, intensityImage);
242 }
243
244 private static Handle LoadFromFile(string filePath, PixelFormat pixelFormat)
245 {
246 var handle = new Handle();
247 DllHelper.ExecuteAndMapReturnCodes(() =>
248 CInterface.peak_icv_PointCloud_CreateFromFile(out handle,
249 PixelFormatToPointType(pixelFormat), Utils.ToUtf8(filePath)));
250 return handle;
251 }
252
253 private static Handle CreateFromPoints(PointXYZI[] points, PixelFormat pixelFormat)
254 {
255 Backend.Types.peak_icv_point_xyzi[] pointsC = points.Select(point =>
256 new Backend.Types.peak_icv_point_xyzi
257 {
258 x = point.X,
259 y = point.Y,
260 z = point.Z,
261 intensity = point.Intensity
262 }).ToArray();
263
264 var handle = new Handle();
265 DllHelper.ExecuteAndMapReturnCodes(() =>
266 CInterface.peak_icv_PointCloud_CreateFromPoints(
267 out handle, pointsC, (nuint) pointsC.Length,
268 PixelFormatToPointType(pixelFormat)));
269
270 return handle;
271 }
272
273 private static Backend.Types.peak_icv_point_type PixelFormatToPointType(PixelFormat pixelFormat)
274 {
275 return pixelFormat switch
276 {
277 PixelFormat.Mono8 => Backend.Types.peak_icv_point_type.PEAK_ICV_POINT_TYPE_XYZ_I8,
278 PixelFormat.Mono10 => Backend.Types.peak_icv_point_type.PEAK_ICV_POINT_TYPE_XYZ_I10,
279 PixelFormat.Mono12 => Backend.Types.peak_icv_point_type.PEAK_ICV_POINT_TYPE_XYZ_I12,
280 _ => throw new IcvNotSupportedException(
281 "Unsupported pixel format. Supported formats are Mono8, Mono10, and Mono12.")
282 };
283 }
284
285 private sealed class PointCloudEqualityComparer : IEqualityComparer<PointCloudXYZI>
286 {
287 public bool Equals(PointCloudXYZI x, PointCloudXYZI y)
288 {
289 if (ReferenceEquals(x, y))
290 {
291 return true;
292 }
293
294 if (ReferenceEquals(x, null))
295 {
296 return false;
297 }
298
299 if (ReferenceEquals(y, null))
300 {
301 return false;
302 }
303
304 return x.Points.SequenceEqual(y.Points, PointXYZI.Comparer);
305 }
306
307 public int GetHashCode(PointCloudXYZI obj)
308 {
309 PointXYZI[] points = obj.Points;
310 var count = points.Count();
311
312 return (
313 count,
314 PointXYZI.Comparer.GetHashCode(points.First()),
315 PointXYZI.Comparer.GetHashCode(points.ElementAt(count / 2)),
316 PointXYZI.Comparer.GetHashCode(points.Last())
317 ).GetHashCode();
318 }
319 }
320}
Represents the extrinsic parameters for camera calibration, including rotation, translation and the t...
Occurs when a requested operation is not implemented or supported (e.g., exporting to an unsupported ...
Definition Exception.cs:62
Represents a 3D point with floating-point coordinates (X, Y, Z) and intensity value.
Definition PointXYZI.cs:9
static IEqualityComparer< PointXYZI > Comparer
Gets a default equality comparer for comparing PointXYZI data values.
Definition PointXYZI.cs:58
Constructs an Image from an IImageView Instance.
Definition Image.cs:18
Represents a point cloud consisting of points with x, y, z coordinates and an intensity value.
PointCloudXYZI(XYZImage image, Image intensityImage)
Constructs a point cloud from the specified XYZ image and intensity image.
PointCloudXYZI(UndistortedImage undistortedDepthMap, Image intensityImage)
Constructs a point cloud from the specified undistorted depth map and intensity image.
PointCloudXYZI TransformToWorkspace(ExtrinsicParameters extrinsicParameters)
Transforms the point cloud to the workspace coordinate system using the extrinsic parameters.
static IEqualityComparer< PointCloudXYZI > Comparer
Gets a default equality comparer for comparing PointCloudXYZI data values.
PointCloudXYZI(string filePath, PixelFormat pixelFormat)
Constructs a point cloud by loading it from the specified file.
PointCloudXYZI(PointXYZI[] points, PixelFormat pixelFormat)
Constructs a point cloud from the specified list of points.
PointCloudXYZI Transform(TransformationMatrix3D matrix)
Applies a transformation to the point cloud.
A transformation matrix is a square matrix that, when multiplied by the coordinates of a geometric ob...
Represents an image that has undergone undistortion.
Represents a three-channel image encoding cartesian coordinates (x, y, z) of a 3D point.
Definition XYZImage.cs:27
PixelFormat
Each enumerator represents a specific pixel layout and bit-depth, used for interpreting raw image dat...