Skip to content

Commit a112084

Browse files
committed
Add function to get all packed points from a PDALPointViewPtr
1 parent 88087d6 commit a112084

File tree

3 files changed

+109
-6
lines changed

3 files changed

+109
-6
lines changed

source/pdal/capi/PointView.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,40 @@ namespace pdal
143143

144144
return size;
145145
}
146+
147+
uint64_t PDALGetAllPackedPoints(PDALPointViewPtr view, PDALDimTypeListPtr dims, char *buf)
148+
{
149+
uint64_t size = 0;
150+
151+
if (view && dims && buf)
152+
{
153+
pdal::capi::PointView *capiView = reinterpret_cast<pdal::capi::PointView *>(view);
154+
155+
pdal::capi::DimTypeList *capiDims = reinterpret_cast<pdal::capi::DimTypeList *>(dims);
156+
157+
158+
if (*capiView && *capiDims)
159+
{
160+
pdal::DimTypeList *list = capiDims->get();
161+
162+
for (unsigned i = 0; i < (*capiView)->size(); ++i)
163+
{
164+
size_t pointSize = 0;
165+
(*capiView)->getPackedPoint(*list, i, buf);
166+
167+
for (const auto &dim : *list)
168+
{
169+
pointSize += pdal::Dimension::size(dim.m_type);
170+
}
171+
172+
buf += pointSize;
173+
size += pointSize;
174+
}
175+
}
176+
}
177+
178+
return size;
179+
}
146180
}
147181
}
148182
}

source/pdal/capi/PointView.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,30 @@ namespace pdal
101101
PDAL_C_API PDALPointLayoutPtr PDALGetPointViewLayout(PDALPointViewPtr view);
102102

103103
/**
104-
* Fill a buffer with point data specified by the dimension list.
104+
* Retrieves data for a point based on the provided dimension list.
105105
*
106106
* @see pdal::PointView::getPackedPoint
107107
*
108108
* @param view The view that contains the point
109-
* @param dims List of dimensions/types to retrieve.
110-
* @param idx Index of point to get.
111-
* @param[out] buf Pointer to buffer to fill.
109+
* @param dims List of dimensions to retrieve
110+
* @param idx Index of point to get
111+
* @param[out] buf Pointer to buffer to fill
112112
* @return The size of the point stored in `buf`
113113
*/
114114
PDAL_C_API size_t PDALGetPackedPoint(PDALPointViewPtr view, PDALDimTypeListPtr dims, PDALPointId idx, char *buf);
115115

116-
//! PDAL_C_API void getPackedPoints(const DimTypeList& dims, PointId idx, char *buf);
116+
/**
117+
* Retrieves data for all points based on the provided dimension list.
118+
*
119+
* @see pdal::PointView::getPackedPoint
120+
*
121+
* @param view The view that contains the points
122+
* @param dims List of dimensions to retrieve
123+
* @param idx Index of point to get
124+
* @param[out] buf Pointer to buffer to fill
125+
* @return The size of the points stored in `buf`
126+
*/
127+
PDAL_C_API uint64_t PDALGetAllPackedPoints(PDALPointViewPtr view, PDALDimTypeListPtr dims, char *buf);
117128

118129
/**
119130
* Fill a buffer with point data specified by the dimension list, accounts index

tests/pdal/capi/PointViewTest.c.in

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ TEST testPDALGetPointViewLayout(void)
317317

318318
TEST testPDALGetPackedPoint(void)
319319
{
320-
// PDALGetPackedPoint(PDALPointViewPtr view, PDALDimTypeListPtr dims, PDALPointId idx, char *buf)
321320
PDALResetPointViewIterator(gPointViewIterator);
322321
bool hasNext = PDALHasNextPointView(gPointViewIterator);
323322
ASSERT(hasNext);
@@ -363,6 +362,64 @@ TEST testPDALGetPackedPoint(void)
363362
PASS();
364363
}
365364

365+
TEST testPDALGetAllPackedPoints(void)
366+
{
367+
PDALResetPointViewIterator(gPointViewIterator);
368+
bool hasNext = PDALHasNextPointView(gPointViewIterator);
369+
ASSERT(hasNext);
370+
371+
uint64_t actualSize = PDALGetAllPackedPoints(NULL, NULL, NULL);
372+
ASSERT_EQ(0, actualSize);
373+
374+
PDALPointViewPtr view = PDALGetNextPointView(gPointViewIterator);
375+
ASSERT(view);
376+
377+
actualSize = PDALGetAllPackedPoints(view, NULL, NULL);
378+
ASSERT_EQ(0, actualSize);
379+
380+
PDALPointLayoutPtr layout = PDALGetPointViewLayout(view);
381+
ASSERT(layout);
382+
PDALDimTypeListPtr dims = PDALGetPointLayoutDimTypes(layout);
383+
ASSERT(dims);
384+
385+
actualSize = PDALGetAllPackedPoints(NULL, dims, NULL);
386+
ASSERT_EQ(0, actualSize);
387+
actualSize = PDALGetAllPackedPoints(view, dims, NULL);
388+
ASSERT_EQ(0, actualSize);
389+
390+
uint64_t numPoints = PDALGetPointViewSize(view);
391+
size_t pointSize = PDALGetPointSize(layout);
392+
ASSERT(numPoints > 0);
393+
ASSERT(pointSize > 0);
394+
395+
char *actualPoints = calloc(numPoints, pointSize);
396+
ASSERT(actualPoints);
397+
398+
actualSize = PDALGetAllPackedPoints(NULL, NULL, actualPoints);
399+
ASSERT_EQ(0, actualSize);
400+
actualSize = PDALGetAllPackedPoints(view, NULL, actualPoints);
401+
ASSERT_EQ(0, actualSize);
402+
actualSize = PDALGetAllPackedPoints(NULL, dims, actualPoints);
403+
ASSERT_EQ(0, actualSize);
404+
actualSize = PDALGetAllPackedPoints(view, dims, actualPoints);
405+
ASSERT_EQ(numPoints * pointSize, actualSize);
406+
407+
char *expectedPoint = calloc(1, pointSize);
408+
ASSERT(expectedPoint);
409+
410+
for (uint64_t i = 0; i < numPoints; ++i)
411+
{
412+
ASSERT_EQ(pointSize, PDALGetPackedPoint(view, dims, i, expectedPoint));
413+
ASSERT_MEM_EQ(expectedPoint, actualPoints + i * pointSize, pointSize);
414+
}
415+
416+
free(expectedPoint);
417+
free(actualPoints);
418+
PDALDisposePointView(view);
419+
420+
PASS();
421+
}
422+
366423
GREATEST_SUITE(PointViewTest)
367424
{
368425
SET_SETUP(setupPointViewTest, NULL);
@@ -376,6 +433,7 @@ GREATEST_SUITE(PointViewTest)
376433
RUN_TEST(testPDALGetPointViewWkt);
377434
RUN_TEST(testPDALGetPointViewLayout);
378435
RUN_TEST(testPDALGetPackedPoint);
436+
RUN_TEST(testPDALGetAllPackedPoints);
379437

380438
SET_SETUP(NULL, NULL);
381439
SET_TEARDOWN(NULL, NULL);

0 commit comments

Comments
 (0)