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