Skip to content

Commit 51f4410

Browse files
committed
Move DimType-related functions to their own compilation unit
1 parent 65ed2e6 commit 51f4410

File tree

7 files changed

+206
-111
lines changed

7 files changed

+206
-111
lines changed

source/pdal/capi/CMakeLists.txt

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

66
set(SOURCES
7+
DimType.cpp
78
Pipeline.cpp
89
PointLayout.cpp
910
PointView.cpp
@@ -12,6 +13,7 @@ set(SOURCES
1213

1314
set(HEADERS
1415
Defines.h
16+
DimType.h
1517
Forward.h
1618
Pipeline.h
1719
PointLayout.h

source/pdal/capi/DimType.cpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright (c) Simverge Software LLC - All Rights Reserved
3+
*/
4+
5+
#include "DimType.h"
6+
#include <pdal/DimType.hpp>
7+
8+
namespace pdal
9+
{
10+
namespace capi
11+
{
12+
size_t PDALGetDimTypeListSize(PDALDimTypeListPtr types)
13+
{
14+
pdal::capi::DimTypeList *wrapper = reinterpret_cast<pdal::capi::DimTypeList *>(types);
15+
16+
size_t size = 0;
17+
18+
if (wrapper && wrapper->get())
19+
{
20+
try
21+
{
22+
pdal::DimTypeList *list = wrapper->get();
23+
size = list->size();
24+
}
25+
catch (const std::exception &e)
26+
{
27+
printf("%s\n", e.what());
28+
}
29+
}
30+
31+
return size;
32+
}
33+
34+
PDALDimType PDALGetInvalidDimType()
35+
{
36+
PDALDimType dim ={
37+
static_cast<uint32_t>(pdal::Dimension::id("")), static_cast<uint32_t>(pdal::Dimension::type("")),
38+
1.0, 0.0
39+
};
40+
41+
return dim;
42+
}
43+
44+
size_t PDALGetDimTypeIdName(PDALDimType dim, char *name, size_t size)
45+
{
46+
size_t result = 0;
47+
48+
if (name && size > 0)
49+
{
50+
std::string s = pdal::Dimension::name(
51+
static_cast<pdal::Dimension::Id>(dim.id));
52+
std::strncpy(name, s.c_str(), size);
53+
result = std::min(std::strlen(name), size);
54+
}
55+
56+
return result;
57+
}
58+
59+
size_t PDALGetDimTypeInterpretationName(PDALDimType dim, char *name, size_t size)
60+
{
61+
size_t result = 0;
62+
63+
if (name && size > 0)
64+
{
65+
std::string s = pdal::Dimension::interpretationName(
66+
static_cast<pdal::Dimension::Type>(dim.type));
67+
std::strncpy(name, s.c_str(), size);
68+
result = std::min(std::strlen(name), size);
69+
}
70+
71+
return result;
72+
}
73+
74+
PDALDimType PDALGetDimType(PDALDimTypeListPtr types, size_t index)
75+
{
76+
pdal::capi::DimTypeList *wrapper = reinterpret_cast<pdal::capi::DimTypeList *>(types);
77+
78+
PDALDimType dim = PDALGetInvalidDimType();
79+
// PDALDimType dim = {
80+
// static_cast<uint32_t>(pdal::Dimension::id("")), static_cast<uint32_t>(pdal::Dimension::type("")),
81+
// 1.0, 0.0
82+
// };
83+
84+
if (wrapper && wrapper->get())
85+
{
86+
try
87+
{
88+
pdal::DimTypeList *list = wrapper->get();
89+
90+
if (index < list->size())
91+
{
92+
pdal::DimType nativeDim = list->at(index);
93+
dim.id = static_cast<uint32_t>(nativeDim.m_id);
94+
dim.type = static_cast<uint32_t>(nativeDim.m_type);
95+
dim.scale = nativeDim.m_xform.m_scale.m_val;
96+
dim.offset = nativeDim.m_xform.m_offset.m_val;
97+
}
98+
}
99+
catch (const std::exception &e)
100+
{
101+
printf("%s\n", e.what());
102+
}
103+
}
104+
105+
return dim;
106+
}
107+
108+
void PDALDisposeDimTypeList(PDALDimTypeListPtr types)
109+
{
110+
if (types)
111+
{
112+
pdal::capi::DimTypeList *ptr = reinterpret_cast<pdal::capi::DimTypeList *>(types);
113+
delete ptr;
114+
}
115+
}
116+
}
117+
}

source/pdal/capi/DimType.h

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (c) Simverge Software LLC - All Rights Reserved
3+
*/
4+
5+
#ifndef PDAL_CAPI_DIMTYPE_H
6+
#define PDAL_CAPI_DIMTYPE_H
7+
8+
#include "Forward.h"
9+
10+
#ifdef __cplusplus
11+
12+
namespace pdal
13+
{
14+
namespace capi
15+
{
16+
extern "C"
17+
{
18+
#endif
19+
/**
20+
* Returns the number of elements in a dimension type list.
21+
*
22+
* @param types A pointer to the dimension type list
23+
* @return The number of dimension type elements in the list
24+
*/
25+
PDAL_C_API size_t PDALGetDimTypeListSize(PDALDimTypeListPtr types);
26+
27+
/**
28+
* Returns the invalid dimension type. This dimension type has:
29+
* - An ID value of 0 that corresponds to pdal::Dimension::Id::Unknown
30+
* - An interpretation (data type) value of 0 that corresponds to pdal::Dimension::Type::None
31+
* - A scale value of 1.0
32+
* - An offset value of 0.0
33+
*
34+
* @return The invalid dimension type
35+
*/
36+
PDAL_C_API PDALDimType PDALGetInvalidDimType();
37+
38+
/**
39+
* Returns the dimension type at the provided `index` from a dimension type list.
40+
*
41+
* @param types A pointer to the dimension type list
42+
* @param index The index of the dimension type element
43+
* @return The element the `index`
44+
* or the value returned by PDALGetInvalidDimType if the index is out of the list's bounds
45+
*/
46+
PDAL_C_API PDALDimType PDALGetDimType(PDALDimTypeListPtr types, size_t index);
47+
48+
/**
49+
* Retrieves the name of a dimension type's ID.
50+
*
51+
* @param dim The dimension type
52+
* @param[out] name The buffer used to store the retrieved name
53+
* @param size The size of the `name` buffer which will also be the maximum size of the retrieved name
54+
* @return The size of the retrieved ID name
55+
* or zero if the `name` buffer is NULL or buffer `size` is zero
56+
*/
57+
PDAL_C_API size_t PDALGetDimTypeIdName(PDALDimType dim, char *name, size_t size);
58+
59+
/**
60+
* Retrieves the name of a dimension type's interpretation, i.e., its data type.
61+
*
62+
* @param dim The dimension type
63+
* @param[out] name The buffer used to store the retrieved name
64+
* @param size The size of the `name` buffer which will also be the maximum size of the retrieved name
65+
* @return The size of the retrieved interpretation name
66+
* or zero if the `name` buffer is NULL or buffer`size` is zero
67+
*/
68+
PDAL_C_API size_t PDALGetDimTypeInterpretationName(PDALDimType dim, char *name, size_t size);
69+
70+
/**
71+
* Disposes the provided dimension type list.
72+
*
73+
* @param types A pointer to the dimension type list
74+
*/
75+
PDAL_C_API void PDALDisposeDimTypeList(PDALDimTypeListPtr types);
76+
77+
#ifdef __cplusplus
78+
}
79+
}
80+
81+
}
82+
#endif
83+
#endif

source/pdal/capi/PointLayout.cpp

Lines changed: 2 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -3,101 +3,15 @@
33
*/
44

55
#include "PointLayout.h"
6+
#include "DimType.h"
67

7-
#include <pdal/Dimension.hpp>
88
#include <pdal/DimType.hpp>
99
#include <pdal/PointLayout.hpp>
1010

1111
namespace pdal
1212
{
1313
namespace capi
1414
{
15-
size_t PDALGetDimTypeListSize(PDALDimTypeListPtr types)
16-
{
17-
pdal::capi::DimTypeList *wrapper = reinterpret_cast<pdal::capi::DimTypeList *>(types);
18-
19-
size_t size = 0;
20-
21-
if (wrapper && wrapper->get())
22-
{
23-
try
24-
{
25-
pdal::DimTypeList *list = wrapper->get();
26-
size = list->size();
27-
}
28-
catch (const std::exception &e)
29-
{
30-
printf("%s\n", e.what());
31-
}
32-
}
33-
34-
return size;
35-
}
36-
37-
38-
size_t PDALGetDimTypeIdName(PDALDimType dim, char *name, size_t size)
39-
{
40-
size_t result = 0;
41-
42-
if (name && size > 0)
43-
{
44-
std::string s = pdal::Dimension::name(
45-
static_cast<pdal::Dimension::Id>(dim.id));
46-
std::strncpy(name, s.c_str(), size);
47-
result = std::min(std::strlen(name), size);
48-
}
49-
50-
return result;
51-
}
52-
53-
size_t PDALGetDimTypeInterpretationName(PDALDimType dim, char *name, size_t size)
54-
{
55-
size_t result = 0;
56-
57-
if (name && size > 0)
58-
{
59-
std::string s = pdal::Dimension::interpretationName(
60-
static_cast<pdal::Dimension::Type>(dim.type));
61-
std::strncpy(name, s.c_str(), size);
62-
result = std::min(std::strlen(name), size);
63-
}
64-
65-
return result;
66-
}
67-
68-
69-
PDALDimType PDALGetDimType(PDALDimTypeListPtr types, size_t index)
70-
{
71-
pdal::capi::DimTypeList *wrapper = reinterpret_cast<pdal::capi::DimTypeList *>(types);
72-
73-
PDALDimType dim = {
74-
static_cast<uint32_t>(pdal::Dimension::id("")), static_cast<uint32_t>(pdal::Dimension::type("")),
75-
1.0, 0.0
76-
};
77-
78-
if (wrapper && wrapper->get())
79-
{
80-
try
81-
{
82-
pdal::DimTypeList *list = wrapper->get();
83-
84-
if (index < list->size())
85-
{
86-
pdal::DimType nativeDim = list->at(index);
87-
dim.id = static_cast<uint32_t>(nativeDim.m_id);
88-
dim.type = static_cast<uint32_t>(nativeDim.m_type);
89-
dim.scale = nativeDim.m_xform.m_scale.m_val;
90-
dim.offset = nativeDim.m_xform.m_offset.m_val;
91-
}
92-
}
93-
catch (const std::exception &e)
94-
{
95-
printf("%s\n", e.what());
96-
}
97-
}
98-
99-
return dim;
100-
}
10115

10216
PDALDimTypeListPtr PDALGetPointLayoutDimTypes(PDALPointLayoutPtr layout)
10317
{
@@ -114,22 +28,9 @@ namespace pdal
11428
return types;
11529
}
11630

117-
void PDALDisposeDimTypeList(PDALDimTypeListPtr types)
118-
{
119-
if (types)
120-
{
121-
pdal::capi::DimTypeList *ptr = reinterpret_cast<pdal::capi::DimTypeList *>(types);
122-
delete ptr;
123-
}
124-
}
125-
12631
PDALDimType PDALFindDimType(PDALPointLayoutPtr layout, const char *name)
12732
{
128-
PDALDimType dim = {
129-
static_cast<uint32_t>(pdal::Dimension::id("")), static_cast<uint32_t>(pdal::Dimension::type("")),
130-
1.0, 0.0
131-
};
132-
33+
PDALDimType dim = PDALGetInvalidDimType();
13334
pdal::PointLayoutPtr nativeLayout = reinterpret_cast<pdal::PointLayoutPtr>(layout);
13435

13536
if (name && nativeLayout)

source/pdal/capi/PointLayout.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ namespace pdal
1616
extern "C"
1717
{
1818
#endif
19-
PDAL_C_API size_t PDALGetDimTypeListSize(PDALDimTypeListPtr types);
20-
21-
PDAL_C_API PDALDimType PDALGetDimType(PDALDimTypeListPtr types, size_t index);
22-
23-
PDAL_C_API size_t PDALGetDimTypeIdName(PDALDimType dim, char *name, size_t size);
24-
25-
PDAL_C_API size_t PDALGetDimTypeInterpretationName(PDALDimType dim, char *name, size_t size);
26-
2719
/**
2820
* Returns the list of dimension types used by the provided `layout`.
2921
*
@@ -35,8 +27,6 @@ namespace pdal
3527
*/
3628
PDAL_C_API PDALDimTypeListPtr PDALGetPointLayoutDimTypes(PDALPointLayoutPtr layout);
3729

38-
PDAL_C_API void PDALDisposeDimTypeList(PDALDimTypeListPtr types);
39-
4030
/**
4131
* Finds the dimension type identified by the provided `name` in a `layout`.
4232
*

tests/pdal/capi/PointLayoutTest.c.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "greatest.h"
1010

11+
#include <pdal/capi/DimType.h>
1112
#include <pdal/capi/Pipeline.h>
1213
#include <pdal/capi/PointLayout.h>
1314
#include <pdal/capi/PointView.h>

tests/pdal/capi/PointViewTest.c.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "greatest.h"
1010

11+
#include <pdal/capi/DimType.h>
1112
#include <pdal/capi/Pipeline.h>
1213
#include <pdal/capi/PointLayout.h>
1314
#include <pdal/capi/PointView.h>

0 commit comments

Comments
 (0)