Skip to content

Commit c1439fa

Browse files
committed
Added PointLayout C functions and unit tests
1 parent e340b2d commit c1439fa

File tree

6 files changed

+198
-0
lines changed

6 files changed

+198
-0
lines changed

source/pdal/capi/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ message(STATUS "Found PDAL ${PDAL_VERSION}")
55

66
set(SOURCES
77
Pipeline.cpp
8+
PointLayout.cpp
89
PointView.cpp
910
PointViewCollection.cpp
1011
)
@@ -13,6 +14,7 @@ set(HEADERS
1314
Defines.h
1415
Forward.h
1516
Pipeline.h
17+
PointLayout.h
1618
PointView.h
1719
PointViewCollection.h
1820
)

source/pdal/capi/PointLayout.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) Simverge Software LLC - All Rights Reserved
3+
*/
4+
5+
#include "PointLayout.h"
6+
7+
#include <pdal/Dimension.hpp>
8+
#include <pdal/DimType.hpp>
9+
#include <pdal/PointLayout.hpp>
10+
11+
namespace pdal
12+
{
13+
namespace capi
14+
{
15+
16+
size_t PDALGetDimSize(PDALPointLayoutPtr layout, const char *name)
17+
{
18+
pdal::PointLayoutPtr nativeLayout = reinterpret_cast<pdal::PointLayoutPtr>(layout);
19+
return (name && nativeLayout) ? nativeLayout->dimSize(nativeLayout->findDim(name)) : 0;
20+
}
21+
22+
size_t PDALGetDimPackedOffset(PDALPointLayoutPtr layout, const char *name)
23+
{
24+
size_t offset = 0;
25+
26+
pdal::PointLayoutPtr nativeLayout = reinterpret_cast<pdal::PointLayoutPtr>(layout);
27+
28+
if (name && nativeLayout)
29+
{
30+
pdal::DimType type = nativeLayout->findDimType(name);
31+
pdal::DimTypeList dims = nativeLayout->dimTypes();
32+
std::string name = pdal::Dimension::name(type.m_id);
33+
34+
for (auto dim : dims)
35+
{
36+
if (name == pdal::Dimension::name(dim.m_id))
37+
{
38+
break;
39+
}
40+
else
41+
{
42+
offset += nativeLayout->dimSize(dim.m_id);
43+
}
44+
}
45+
}
46+
47+
return offset;
48+
}
49+
50+
size_t PDALGetPointSize(PDALPointLayoutPtr layout)
51+
{
52+
53+
pdal::PointLayoutPtr nativeLayout = reinterpret_cast<pdal::PointLayoutPtr>(layout);
54+
return nativeLayout ? nativeLayout->pointSize() : 0;
55+
}
56+
}
57+
}

source/pdal/capi/PointLayout.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) Simverge Software LLC - All Rights Reserved
3+
*/
4+
5+
#ifndef PDAL_CAPI_POINTLAYOUT_H
6+
#define PDAL_CAPI_POINTLAYOUT_H
7+
8+
#include "Forward.h"
9+
10+
#ifdef __cplusplus
11+
namespace pdal
12+
{
13+
namespace capi
14+
{
15+
16+
extern "C"
17+
{
18+
#endif
19+
//! PDAL_C_API PDALDimTypeList PDALGetPointLayoutDimTypes(PDALPointLayoutPtr layout);
20+
21+
//! PDAL_C_API PDALDimType PDALFindDimType(PDALPointLayoutPtr layout, const char *name);
22+
23+
PDAL_C_API size_t PDALGetDimSize(PDALPointLayoutPtr layout, const char *name);
24+
25+
PDAL_C_API size_t PDALGetDimPackedOffset(PDALPointLayoutPtr layout, const char *name);
26+
27+
PDAL_C_API size_t PDALGetPointSize(PDALPointLayoutPtr layout);
28+
29+
30+
#ifdef __cplusplus
31+
} // extern "C"
32+
} // namespace capi
33+
} // namespace pdal
34+
#endif
35+
36+
#endif

tests/pdal/capi/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(DEPENDENCIES pdal_c)
77

88
set(TESTS
99
PipelineTest
10+
PointLayoutTest
1011
PointViewCollectionTest
1112
PointViewTest
1213
)
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright (c) Simverge Software LLC - All Rights Reserved
3+
*/
4+
5+
#include <stdlib.h>
6+
#include <stdio.h>
7+
#include <assert.h>
8+
9+
#include "greatest.h"
10+
11+
#include <pdal/capi/Pipeline.h>
12+
#include <pdal/capi/PointLayout.h>
13+
#include <pdal/capi/PointView.h>
14+
#include <pdal/capi/PointViewCollection.h>
15+
16+
SUITE(PointLayoutTest);
17+
18+
static PDALPipelinePtr gPipeline = NULL;
19+
static PDALPointViewPtr gPointView = NULL;
20+
21+
static void setupPointLayoutTest(void *arg)
22+
{
23+
FILE *file = fopen("@CMAKE_BINARY_DIR@/data/simple-reproject.json", "rb");
24+
char *json = NULL;
25+
26+
if (file)
27+
{
28+
fseek(file, 0, SEEK_END);
29+
long length = ftell(file);
30+
fseek(file, 0, SEEK_SET);
31+
char *json = malloc(length + 1);
32+
33+
if (json)
34+
{
35+
fread(json, 1, length, file);
36+
json[length] = '\0';
37+
gPipeline = PDALCreatePipeline(json);
38+
39+
if (gPipeline && PDALExecutePipeline(gPipeline))
40+
{
41+
PDALPointViewCollectionPtr views = PDALGetPointViews(gPipeline);
42+
43+
if (PDALHasNextPointView(views))
44+
{
45+
gPointView = PDALGetNextPointView(views);
46+
}
47+
}
48+
49+
free(json);
50+
}
51+
52+
fclose(file);
53+
}
54+
}
55+
56+
static void teardownPointLayoutTest(void *arg)
57+
{
58+
PDALDisposePointView(gPointView);
59+
PDALDisposePipeline(gPipeline);
60+
}
61+
62+
TEST testPDALGetDimSize(void)
63+
{
64+
size_t size = PDALGetDimSize(NULL, NULL);
65+
ASSERT_EQ(0, size);
66+
67+
int numTypes = 3;
68+
const char *types[] = {"X", "Y", "Z"};
69+
70+
for (int i = 0; i < numTypes; ++i)
71+
{
72+
size = PDALGetDimSize(NULL, types[i]);
73+
ASSERT_EQ(0, size);
74+
}
75+
76+
PASS();
77+
}
78+
79+
TEST testPDALGetDimPackedOffset(void)
80+
{
81+
PASS();
82+
}
83+
84+
TEST testPDALGetPointSize(void)
85+
{
86+
PASS();
87+
}
88+
89+
GREATEST_SUITE(PointLayoutTest)
90+
{
91+
SET_SETUP(setupPointLayoutTest, NULL);
92+
SET_TEARDOWN(teardownPointLayoutTest, NULL);
93+
94+
RUN_TEST(testPDALGetDimSize);
95+
RUN_TEST(testPDALGetDimPackedOffset);
96+
RUN_TEST(testPDALGetPointSize);
97+
98+
SET_SETUP(NULL, NULL);
99+
SET_TEARDOWN(NULL, NULL);
100+
}

tests/pdal/capi/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "greatest.h"
1010

1111
SUITE_EXTERN(PipelineTest);
12+
SUITE_EXTERN(PointLayoutTest);
1213
SUITE_EXTERN(PointViewCollectionTest);
1314
SUITE_EXTERN(PointViewTest);
1415

@@ -18,6 +19,7 @@ int main(int argc, char **argv)
1819
{
1920
GREATEST_MAIN_BEGIN();
2021
RUN_SUITE(PipelineTest);
22+
RUN_SUITE(PointLayoutTest);
2123
RUN_SUITE(PointViewCollectionTest);
2224
RUN_SUITE(PointViewTest);
2325
GREATEST_MAIN_END();

0 commit comments

Comments
 (0)