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+ }
0 commit comments