Perception Tool Kit (PTK) API Guide
pointCloud.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2018 Texas Instruments Incorporated
4  *
5  * All rights reserved not granted herein.
6  *
7  * Limited License.
8  *
9  * Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive
10  * license under copyrights and patents it now or hereafter owns or controls to make,
11  * have made, use, import, offer to sell and sell ("Utilize") this software subject to the
12  * terms herein. With respect to the foregoing patent license, such license is granted
13  * solely to the extent that any such patent is necessary to Utilize the software alone.
14  * The patent license shall not apply to any combinations which include this software,
15  * other than combinations with devices manufactured by or for TI ("TI Devices").
16  * No hardware patent is licensed hereunder.
17  *
18  * Redistributions must preserve existing copyright notices and reproduce this license
19  * (including the above copyright notice and the disclaimer and (if applicable) source
20  * code license limitations below) in the documentation and/or other materials provided
21  * with the distribution
22  *
23  * Redistribution and use in binary form, without modification, are permitted provided
24  * that the following conditions are met:
25  *
26  * * No reverse engineering, decompilation, or disassembly of this software is
27  * permitted with respect to any software provided in binary form.
28  *
29  * * any redistribution and use are licensed by TI for use only with TI Devices.
30  *
31  * * Nothing shall obligate TI to provide you with source code for the software
32  * licensed and provided to you in object code.
33  *
34  * If software source code is provided to you, modification and redistribution of the
35  * source code are permitted provided that the following conditions are met:
36  *
37  * * any redistribution and use of the source code, including any resulting derivative
38  * works, are licensed by TI for use only with TI Devices.
39  *
40  * * any redistribution and use of any object code compiled from the source code
41  * and any resulting derivative works, are licensed by TI for use only with TI Devices.
42  *
43  * Neither the name of Texas Instruments Incorporated nor the names of its suppliers
44  *
45  * may be used to endorse or promote products derived from this software without
46  * specific prior written permission.
47  *
48  * DISCLAIMER.
49  *
50  * THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS
51  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
52  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
53  * IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT,
54  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
55  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
57  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
58  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
59  * OF THE POSSIBILITY OF SUCH DAMAGE.
60  *
61  */
62 #pragma once
63 #ifndef POINT_CLOUD_H
64 #define POINT_CLOUD_H
65 
71 #include <stdint.h>
72 #include <string.h>
73 #include <perception/base/point.h>
75 
89 #ifdef __cplusplus
90 extern "C" {
91 #endif
92 
98 #define PTK_PointCloud_getPoints(pc) (PTK_Point*)((uint8_t*)pc + pc->pointOffset)
99 
105 #define PTK_POINTCLOUD_INVALID_POINT (~0U)
106 
120 typedef struct
121 {
125  uint32_t maxPoints;
126 
128 
129 typedef struct
130 {
133 
135  uint32_t numPoints;
136 
138  uint32_t pointOffset;
139 
141  uint32_t dummy;
142 
144 
155 uint32_t PTK_PointCloud_getSize(const PTK_PointCloudConfig *cfg);
156 
170 PTK_PointCloud *PTK_PointCloud_init(uint8_t *memPtr,
171  const PTK_PointCloudConfig *cfg);
172 
181 
196 uint32_t PTK_PointCloud_hasSpace(const PTK_PointCloud *pc,
197  uint32_t points);
198 
213  const PTK_Point *xyzw);
214 
234  const PTK_Point *xyzw,
235  uint32_t numPoints);
236 
247 uint32_t PTK_PointCloud_getPointCount(const PTK_PointCloud *pc);
248 
265 uint32_t PTK_PointCloud_getPoint(const PTK_PointCloud *pc,
266  uint32_t id,
267  PTK_Point *dst);
268 
283  uint32_t id)
284 {
285  if (id < pc->numPoints)
286  {
287  PTK_Point *points;
288 
289  points = (PTK_Point*)((uint8_t*)pc + pc->pointOffset);
290 
291  return &points[id];
292  }
293 
294  return NULL;
295 }
296 
311  uint32_t id);
312 
325  uint32_t id,
326  uint32_t tag);
327 
340  uint32_t id,
341  uint32_t tag);
342 
360 uint32_t PTK_PointCloud_isTagged(const PTK_PointCloud *pc,
361  uint32_t id,
362  uint32_t tag);
363 
378 uint32_t PTK_PointCloud_readTag(const PTK_PointCloud *pc,
379  uint32_t id);
380 
391  const PTK_PointCloud *src)
392 {
393  /* Copy meta data. */
394  dst->config = src->config;
395  dst->pointOffset = src->pointOffset;
396 
397  return;
398 }
399 
412 uint32_t PTK_PointCloud_copy(PTK_PointCloud *dst,
413  const PTK_PointCloud *src);
414 
434  PTK_PointCloud *src,
435  const PTK_RigidTransform *M);
436 
454  PTK_PointCloud *src,
455  float scale);
456 
477  const PTK_Point *basis,
478  float *minVal,
479  float *maxVal,
480  uint32_t *minId,
481  uint32_t *maxId);
482 
504 uint32_t PTK_PointCloud_ransacPlane(const PTK_PointCloud *pc, const uint32_t *__restrict ids, uint32_t N, float tol, uint32_t iters, float *nd, uint32_t *__restrict foundInliers);
505 
506 #ifdef __cplusplus
507 }
508 #endif
509 
510 #endif
const PTK_Point * PTK_PointCloud_crefPoint(const PTK_PointCloud *pc, uint32_t id)
This gets an immutable pointer to a specific PTK_Point within the point cloud.
uint32_t pointOffset
Definition: pointCloud.h:138
PTK_PointCloud * PTK_PointCloud_init(uint8_t *memPtr, const PTK_PointCloudConfig *cfg)
Initialize an externally allocated piece of memory to be a valid PTK_PointCloud.
static void PTK_PointCloud_copyMetaData(PTK_PointCloud *dst, const PTK_PointCloud *src)
Copy metadata from src to dst.
Definition: pointCloud.h:390
uint32_t PTK_PointCloud_readTag(const PTK_PointCloud *pc, uint32_t id)
This reads the tag for a given point identifier in the given point cloud.
Declarations for PTK_Point and PTK_Vector struct+functions.
uint32_t maxPoints
Definition: pointCloud.h:125
static PTK_Point * PTK_PointCloud_refPoint(PTK_PointCloud *pc, uint32_t id)
This gets a direct pointer to a specific PTK_Point within the point cloud.
Definition: pointCloud.h:282
Definition: pointCloud.h:129
Definition of vector meta data.
Definition: pointCloud.h:120
uint32_t PTK_PointCloud_ransacPlane(const PTK_PointCloud *pc, const uint32_t *__restrict ids, uint32_t N, float tol, uint32_t iters, float *nd, uint32_t *__restrict foundInliers)
uint32_t PTK_PointCloud_getPointCount(const PTK_PointCloud *pc)
This returns the total number of points that have been added since PTK_PointCloud_clear() was last ca...
PTK_PointCloudConfig config
Definition: pointCloud.h:132
void PTK_PointCloud_transform(PTK_PointCloud *dst, PTK_PointCloud *src, const PTK_RigidTransform *M)
Each point in src is transformed by M and then written to the same location in dst. The tag bits are also propagated to dst, and the total number of points present in dst is updated accordingly. src and dst may point to the same PTK_PointCloud. In practice, it is most common for dst to be empty first or to have src= dst. The return value indicates the number of successfully transformed and copied points, which may be important if transforming and appending onto a non-empty cloud for detecting space limitations.
uint32_t PTK_PointCloud_getPoint(const PTK_PointCloud *pc, uint32_t id, PTK_Point *dst)
This copies a PTK_Point out of the point cloud into another (user-supplied) memory location...
Rigid Transform Matrix (single precision).
Definition: rigidTransform.h:85
Definition of a point.
Definition: point.h:136
void PTK_PointCloud_untag(PTK_PointCloud *pc, uint32_t id, uint32_t tag)
This removes tag bits for the point at the given identifier.
void PTK_PointCloud_scale(PTK_PointCloud *dst, PTK_PointCloud *src, float scale)
Each point in src is scaled by scale and then written with the same id in dst. The tag bits are also ...
Declaration of structures and functions for rigid transforms.
void PTK_PointCloud_tag(PTK_PointCloud *pc, uint32_t id, uint32_t tag)
This sets tag bits for the point with the given identifier.
uint32_t PTK_PointCloud_copy(PTK_PointCloud *dst, const PTK_PointCloud *src)
Copy points from src to dst, appending points so long as space remains in the dst cloud...
void PTK_PointCloud_clear(PTK_PointCloud *pc)
Clear a PTK_PointCloud by setting used point count to zero..
uint32_t PTK_PointCloud_getSize(const PTK_PointCloudConfig *cfg)
Compute how much memory is required to store a complete PTK_PointCloud struct matching the given conf...
uint32_t PTK_PointCloud_addv(PTK_PointCloud *pc, const PTK_Point *xyzw, uint32_t numPoints)
Add a copy of each of the points in the array pv to the given point cloud, if there is enough space...
uint32_t PTK_PointCloud_add(PTK_PointCloud *pc, const PTK_Point *xyzw)
Add a copy of the given point to the point cloud, if there is room.
void PTK_PointCloud_getMinMax(const PTK_PointCloud *pc, const PTK_Point *basis, float *minVal, float *maxVal, uint32_t *minId, uint32_t *maxId)
Find PTK_Points with the minimum and maximum PTK Vector dot4 value computed with the given basis...
uint32_t numPoints
Definition: pointCloud.h:135
uint32_t PTK_PointCloud_isTagged(const PTK_PointCloud *pc, uint32_t id, uint32_t tag)
This checks if all of the bits set in tag are also set in the tag for the specified PTK_Point...
uint32_t PTK_PointCloud_hasSpace(const PTK_PointCloud *pc, uint32_t points)
Check if the given point cloud has enough space to accomodate the addition of points additional PTK_P...
uint32_t dummy
Definition: pointCloud.h:141