Skip to content

Commit 7431a19

Browse files
committed
Add Csharp scripts
1 parent 79a8c70 commit 7431a19

File tree

7 files changed

+1105
-0
lines changed

7 files changed

+1105
-0
lines changed

csharp/Config.cs

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
/******************************************************************************
2+
* Copyright (c) 2019, Simverge Software LLC. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following
6+
* conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* 3. Neither the name of Simverge Software LLC nor the names of its
14+
* contributors may be used to endorse or promote products derived from this
15+
* software without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
*****************************************************************************/
29+
30+
using System.IO;
31+
using System.Runtime.InteropServices;
32+
using System.Text;
33+
using UnityEngine;
34+
35+
namespace Pdal
36+
{
37+
public class PdalConfiguration
38+
{
39+
public static void ConfigurePdal()
40+
{
41+
Config config = new Config();
42+
Debug.Log("GDAL Data Path: " + config.GdalData);
43+
Debug.Log("Proj4 Data Path: " + config.Proj4Data);
44+
45+
Debug.Log("PDAL Version Integer: " + config.VersionInteger);
46+
Debug.Log("PDAL Version Major: " + config.VersionMajor);
47+
Debug.Log("PDAL Version Minor: " + config.VersionMinor);
48+
Debug.Log("PDAL Version Patch: " + config.VersionPatch);
49+
50+
Debug.Log("PDAL Full Version: " + config.FullVersion);
51+
Debug.Log("PDAL Version: " + config.Version);
52+
Debug.Log("PDAL SHA1: " + config.Sha1);
53+
Debug.Log("PDAL Debug Info: " + config.DebugInfo);
54+
}
55+
}
56+
57+
/**
58+
* A utility to retrieve PDAL version and configuration information
59+
*/
60+
public class Config
61+
{
62+
private const string PDALC_LIBRARY = "pdalc";
63+
64+
[DllImport(PDALC_LIBRARY, EntryPoint="PDALGetGdalDataPath")]
65+
private static extern int getGdalDataPath([MarshalAs(UnmanagedType.LPStr)] StringBuilder buffer, uint size);
66+
67+
[DllImport(PDALC_LIBRARY, EntryPoint="PDALGetProj4DataPath")]
68+
private static extern int getProj4DataPath([MarshalAs(UnmanagedType.LPStr)] StringBuilder buffer, uint size);
69+
70+
[DllImport(PDALC_LIBRARY, EntryPoint="PDALSetGdalDataPath")]
71+
private static extern void setGdalDataPath(string path);
72+
73+
[DllImport(PDALC_LIBRARY, EntryPoint="PDALSetProj4DataPath")]
74+
private static extern void setProj4DataPath(string path);
75+
76+
[DllImport(PDALC_LIBRARY, EntryPoint="PDALFullVersionString")]
77+
private static extern void getFullVersion([MarshalAs(UnmanagedType.LPStr)] StringBuilder buffer, uint size);
78+
79+
[DllImport(PDALC_LIBRARY, EntryPoint="PDALVersionString")]
80+
private static extern void getVersion([MarshalAs(UnmanagedType.LPStr)] StringBuilder buffer, uint size);
81+
82+
[DllImport(PDALC_LIBRARY, EntryPoint="PDALVersionInteger")]
83+
private static extern int getVersionInteger();
84+
85+
[DllImport(PDALC_LIBRARY, EntryPoint="PDALSha1")]
86+
private static extern void getSha1([MarshalAs(UnmanagedType.LPStr)] StringBuilder buffer, uint size);
87+
88+
[DllImport(PDALC_LIBRARY, EntryPoint="PDALVersionMajor")]
89+
private static extern int getVersionMajor();
90+
91+
[DllImport(PDALC_LIBRARY, EntryPoint="PDALVersionMinor")]
92+
private static extern int getVersionMinor();
93+
94+
[DllImport(PDALC_LIBRARY, EntryPoint="PDALVersionPatch")]
95+
private static extern int getVersionPatch();
96+
97+
[DllImport(PDALC_LIBRARY, EntryPoint="PDALDebugInformation")]
98+
private static extern void getDebugInfo([MarshalAs(UnmanagedType.LPStr)] StringBuilder buffer, uint size);
99+
100+
/**
101+
* Creates a new PDAL configuration.
102+
*
103+
* @post GdalData will be initialized to `"Assets/gdal/Data"`
104+
* @post Proj4Data will be initialized to `"Assets/proj4/Data"`
105+
*
106+
* @note Set GdalData and Proj4Data as needed if their initialization
107+
* values do not correspond to the actual GDAL and proj4 data
108+
* directory paths.
109+
*/
110+
public Config()
111+
{
112+
//string cwd = Environment.CurrentDirectory;
113+
114+
string gdalPath = Application.streamingAssetsPath;
115+
GdalData = Path.Combine(gdalPath, "gdal-data");
116+
Proj4Data = Path.Combine(gdalPath, "proj");
117+
}
118+
119+
/// The path to the GDAL data directory
120+
public string GdalData
121+
{
122+
get
123+
{
124+
StringBuilder buffer = new StringBuilder(256);
125+
getGdalDataPath(buffer, (uint) buffer.Capacity);
126+
return buffer.ToString();
127+
}
128+
129+
set { setGdalDataPath(value); }
130+
}
131+
132+
/// The path to the proj4 data directory
133+
public string Proj4Data
134+
{
135+
get
136+
{
137+
StringBuilder buffer = new StringBuilder(256);
138+
getProj4DataPath(buffer, (uint) buffer.Capacity);
139+
return buffer.ToString();
140+
}
141+
142+
set { setProj4DataPath(value); }
143+
}
144+
145+
/// The PDAL full version string with dot-separated major, minor, and patch version numbers and PDAL commit SHA1
146+
public string FullVersion
147+
{
148+
get
149+
{
150+
StringBuilder buffer = new StringBuilder(64);
151+
getFullVersion(buffer, (uint) buffer.Capacity);
152+
return buffer.ToString();
153+
}
154+
}
155+
156+
/// The PDAL version string with dot-separated major, minor, and patch version numbers
157+
public string Version
158+
{
159+
get
160+
{
161+
StringBuilder buffer = new StringBuilder(64);
162+
getVersion(buffer, (uint) buffer.Capacity);
163+
return buffer.ToString();
164+
}
165+
}
166+
167+
/**
168+
* The PDAL version number as a single integer.
169+
* The version number is equal to the sum of 10,000 times the major version number,
170+
* 100 times the minor version number, and the patch version number. For example,
171+
* version _1.7.1_ is represented as `10701`.
172+
*/
173+
public int VersionInteger
174+
{
175+
get { return getVersionInteger(); }
176+
}
177+
178+
/// The SHA1 checksum of the Git commit used to build the underlying PDAL library
179+
public string Sha1
180+
{
181+
get
182+
{
183+
StringBuilder buffer = new StringBuilder(64);
184+
getSha1(buffer, (uint) buffer.Capacity);
185+
return buffer.ToString();
186+
}
187+
}
188+
189+
/// The PDAL major version number
190+
public int VersionMajor
191+
{
192+
get { return getVersionMajor(); }
193+
}
194+
195+
/// The PDAL minor version number
196+
public int VersionMinor
197+
{
198+
get { return getVersionMinor(); }
199+
}
200+
201+
/// The PDAL patch version number
202+
public int VersionPatch
203+
{
204+
get { return getVersionPatch(); }
205+
}
206+
207+
/// The string describing useful debugging information from the underlying PDAL library
208+
public string DebugInfo
209+
{
210+
get
211+
{
212+
StringBuilder buffer = new StringBuilder(1024);
213+
getDebugInfo(buffer, (uint) buffer.Capacity);
214+
return buffer.ToString();
215+
}
216+
}
217+
}
218+
}

csharp/DimType.cs

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/******************************************************************************
2+
* Copyright (c) 2019, Simverge Software LLC. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following
6+
* conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* 3. Neither the name of Simverge Software LLC nor the names of its
14+
* contributors may be used to endorse or promote products derived from this
15+
* software without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
*****************************************************************************/
29+
30+
using System;
31+
using System.Runtime.InteropServices;
32+
using System.Text;
33+
34+
namespace Pdal
35+
{
36+
public class DimType
37+
{
38+
private const string PDALC_LIBRARY = "pdalc";
39+
private const int BUFFER_SIZE = 1024;
40+
41+
[StructLayout(LayoutKind.Sequential, Pack = 1)]
42+
public struct NativeDimType
43+
{
44+
public UInt32 id;
45+
public UInt32 interpretation;
46+
public double scale;
47+
public double offset;
48+
};
49+
50+
[DllImport(PDALC_LIBRARY, EntryPoint="PDALGetInvalidDimType")]
51+
[return:MarshalAs(UnmanagedType.Struct)]
52+
private static extern NativeDimType getInvalidDimType();
53+
54+
[DllImport(PDALC_LIBRARY, EntryPoint="PDALGetDimTypeIdName")]
55+
private static extern int getIdName([MarshalAs(UnmanagedType.Struct)] NativeDimType type, [MarshalAs(UnmanagedType.LPStr)] StringBuilder buffer, uint size);
56+
57+
[DllImport(PDALC_LIBRARY, EntryPoint="PDALGetDimTypeInterpretationName")]
58+
private static extern int getInterpretationName([MarshalAs(UnmanagedType.Struct)] NativeDimType type, [MarshalAs(UnmanagedType.LPStr)] StringBuilder buffer, uint size);
59+
60+
[DllImport(PDALC_LIBRARY, EntryPoint="PDALGetDimTypeInterpretationByteCount")]
61+
private static extern int getInterpretationByteCount([MarshalAs(UnmanagedType.Struct)] NativeDimType type);
62+
63+
private NativeDimType mType = getInvalidDimType();
64+
65+
public DimType()
66+
{
67+
// Do nothing
68+
}
69+
70+
public DimType(NativeDimType nativeType)
71+
{
72+
mType = nativeType;
73+
}
74+
75+
public DimType(uint id, uint interpretation, double scale = 1.0, double offset = 0.0)
76+
{
77+
mType.id = id;
78+
mType.interpretation = interpretation;
79+
mType.scale = scale;
80+
mType.offset = offset;
81+
}
82+
83+
public uint Id
84+
{
85+
get { return mType.id; }
86+
set { mType.id = value; }
87+
}
88+
89+
public string IdName
90+
{
91+
get
92+
{
93+
StringBuilder buffer = new StringBuilder(256);
94+
getIdName(mType, buffer, (uint) buffer.Capacity);
95+
return buffer.ToString();
96+
}
97+
}
98+
99+
public uint Interpretation
100+
{
101+
get { return mType.interpretation; }
102+
set { mType.interpretation = value; }
103+
}
104+
105+
public string InterpretationName
106+
{
107+
get
108+
{
109+
StringBuilder buffer = new StringBuilder(256);
110+
getInterpretationName(mType, buffer, (uint) buffer.Capacity);
111+
return buffer.ToString();
112+
}
113+
}
114+
115+
public int InterpretationByteCount
116+
{
117+
get { return getInterpretationByteCount(mType); }
118+
}
119+
120+
public double Scale
121+
{
122+
get { return mType.scale; }
123+
}
124+
125+
public double Offset
126+
{
127+
get { return mType.offset; }
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)