Skip to content

Commit f5c0929

Browse files
committed
Add PDALGetPackedPoint function
1 parent 27d76bc commit f5c0929

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed

source/pdal/capi/Forward.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ namespace pdal
3838
}
3939
}
4040

41+
#else
42+
#include <stdint.h> // for uint64_t
4143
#endif /* __cplusplus */
4244

4345
/// A pointer to a dimension type list
@@ -46,6 +48,9 @@ typedef void* PDALDimTypeListPtr;
4648
/// A pointer to a pipeline
4749
typedef void* PDALPipelinePtr;
4850

51+
/// An index to a point in a list
52+
typedef uint64_t PDALPointId;
53+
4954
/// A pointer to a point layout
5055
typedef void* PDALPointLayoutPtr;
5156

source/pdal/capi/PointView.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,33 @@ namespace pdal
116116

117117
return layout;
118118
}
119+
120+
size_t PDALGetPackedPoint(PDALPointViewPtr view, PDALDimTypeListPtr dims, PDALPointId idx, char *buf)
121+
{
122+
size_t size = 0;
123+
124+
if (view && dims && buf)
125+
{
126+
pdal::capi::PointView *capiView = reinterpret_cast<pdal::capi::PointView *>(view);
127+
128+
pdal::capi::DimTypeList *capiDims = reinterpret_cast<pdal::capi::DimTypeList *>(dims);
129+
130+
131+
if (*capiView && *capiDims)
132+
{
133+
pdal::DimTypeList *list = capiDims->get();
134+
135+
(*capiView)->getPackedPoint(*list, idx, buf);
136+
137+
for (const auto &dim : *list)
138+
{
139+
size += pdal::Dimension::size(dim.m_type);
140+
}
141+
}
142+
}
143+
144+
return size;
145+
}
119146
}
120147
}
121148
}

source/pdal/capi/PointView.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,16 @@ namespace pdal
102102

103103
/**
104104
* Fill a buffer with point data specified by the dimension list.
105-
*
105+
*
106+
* @see pdal::PointView::getPackedPoint
107+
*
108+
* @param view The view that contains the point
106109
* @param dims List of dimensions/types to retrieve.
107110
* @param idx Index of point to get.
108111
* @param[out] buf Pointer to buffer to fill.
112+
* @return The size of the point stored in `buf`
109113
*/
110-
//! PDAL_C_API void getPackedPoint(const DimTypeList& dims, PointId idx, char *buf);
114+
PDAL_C_API size_t PDALGetPackedPoint(PDALPointViewPtr view, PDALDimTypeListPtr dims, PDALPointId idx, char *buf);
111115

112116
//! PDAL_C_API void getPackedPoints(const DimTypeList& dims, PointId idx, char *buf);
113117

tests/pdal/capi/PointViewTest.c.in

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,54 @@ TEST testPDALGetPointViewLayout(void)
235235
PASS();
236236
}
237237

238+
TEST testPDALGetPackedPoint(void)
239+
{
240+
// PDALGetPackedPoint(PDALPointViewPtr view, PDALDimTypeListPtr dims, PDALPointId idx, char *buf)
241+
PDALResetPointViewIterator(gPointViewIterator);
242+
bool hasNext = PDALHasNextPointView(gPointViewIterator);
243+
ASSERT(hasNext);
244+
245+
PDALPointViewPtr view = PDALGetNextPointView(gPointViewIterator);
246+
ASSERT(view);
247+
248+
PDALPointLayoutPtr layout = PDALGetPointViewLayout(view);
249+
ASSERT(layout);
250+
PDALDimTypeListPtr dims = PDALGetPointLayoutDimTypes(layout);
251+
ASSERT(dims);
252+
253+
uint64_t numPoints = PDALGetPointViewSize(view);
254+
size_t expected = PDALGetPointSize(layout);
255+
256+
size_t capacity = 512;
257+
char buffer[512];
258+
ASSERT(expected > 0 && expected <= capacity);
259+
260+
for (uint64_t i = 0; i < numPoints; ++i)
261+
{
262+
size_t actual = PDALGetPackedPoint(NULL, NULL, i, NULL);
263+
ASSERT_EQ(0, actual);
264+
actual = PDALGetPackedPoint(NULL, NULL, i, buffer);
265+
ASSERT_EQ(0, actual);
266+
actual = PDALGetPackedPoint(NULL, dims, i, NULL);
267+
ASSERT_EQ(0, actual);
268+
actual = PDALGetPackedPoint(NULL, dims, i, buffer);
269+
ASSERT_EQ(0, actual);
270+
actual = PDALGetPackedPoint(view, NULL, i, NULL);
271+
ASSERT_EQ(0, actual);
272+
actual = PDALGetPackedPoint(view, NULL, i, buffer);
273+
ASSERT_EQ(0, actual);
274+
actual = PDALGetPackedPoint(view, dims, i, NULL);
275+
ASSERT_EQ(0, actual);
276+
277+
actual = PDALGetPackedPoint(view, dims, i, buffer);
278+
ASSERT_EQ(expected, actual);
279+
}
280+
281+
PDALDisposePointView(view);
282+
283+
PASS();
284+
}
285+
238286
GREATEST_SUITE(PointViewTest)
239287
{
240288
SET_SETUP(setupPointViewTest, NULL);
@@ -247,6 +295,7 @@ GREATEST_SUITE(PointViewTest)
247295
RUN_TEST(testPDALGetPointViewProj4);
248296
RUN_TEST(testPDALGetPointViewWkt);
249297
RUN_TEST(testPDALGetPointViewLayout);
298+
RUN_TEST(testPDALGetPackedPoint);
250299

251300
SET_SETUP(NULL, NULL);
252301
SET_TEARDOWN(NULL, NULL);

0 commit comments

Comments
 (0)