1
/******************************************************************************
3
* Project: libLAS - http://liblas.org - A BSD library for LAS format data.
4
* Purpose: test app for swig/C# bindings for liblas
5
* Author: Michael P. Gerlek (mpg@flaxen.com)
7
******************************************************************************
8
* Copyright (c) 2011, Michael P. Gerlek (mpg@flaxen.com)
10
* All rights reserved.
12
* Redistribution and use in source and binary forms, with or without
13
* modification, are permitted provided that the following
16
* * Redistributions of source code must retain the above copyright
17
* notice, this list of conditions and the following disclaimer.
18
* * Redistributions in binary form must reproduce the above copyright
19
* notice, this list of conditions and the following disclaimer in
20
* the documentation and/or other materials provided
21
* with the distribution.
22
* * Neither the name of the Martin Isenburg or Iowa Department
23
* of Natural Resources nor the names of its contributors may be
24
* used to endorse or promote products derived from this software
25
* without specific prior written permission.
27
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
35
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
37
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
39
****************************************************************************/
42
using System.Collections.Generic;
47
using System.Diagnostics;
54
static string fileA = @"..\..\test\data\1.2-with-color.las";
55
static string fileB = @"..\..\test\data\1.2-with-color.laz";
56
static string fileT = @"tmp.laz";
58
static public bool IsApprox(double a, double b, double tol)
60
double min = Math.Min(a, b);
61
double max = Math.Max(a, b);
62
double delta = max - min;
68
static int Main(string[] args)
79
// reader tests for the generated B
87
private static void Test_ReadA()
89
ReaderFactory factory = new ReaderFactory();
91
SWIGTYPE_p_std__istream ifs = Liblas.ReaderFactory.FileOpen(fileA);
93
// the "using" here is required, because it forces the Reader
94
// to be disposed before the stream explicitly goes away
95
using (Reader reader = factory.CreateWithStream(ifs))
97
TestReader.Test_A(reader);
99
Header header = reader.GetHeader();
100
TestHeader.Test_A(header);
102
TestGuid.Test_A(header.GetProjectId());
104
VectorVariableRecord vlrs = header.GetVLRs();
105
TestVariableRecord.Test_A(vlrs);
107
SpatialReference srs = header.GetSRS();
108
TestSpatialReference.Test(srs);
110
bool ok = reader.ReadPointAt(2);
112
Point pt = reader.GetPoint();
113
TestPoint.Test_A2(pt);
116
Liblas.ReaderFactory.FileClose(ifs);
119
private static void Test_ReadB()
121
ReaderFactory factory = new ReaderFactory();
123
SWIGTYPE_p_std__istream ifs = Liblas.ReaderFactory.FileOpen(fileB);
125
using (Reader reader = factory.CreateWithStream(ifs))
127
TestReader.Test_B(reader);
129
Header header = reader.GetHeader();
130
TestHeader.Test_B(header);
132
TestGuid.Test_B(header.GetProjectId());
134
VectorVariableRecord vlrs = header.GetVLRs();
135
TestVariableRecord.Test_B(vlrs);
137
SpatialReference srs = header.GetSRS();
138
TestSpatialReference.Test(srs);
140
bool ok = reader.ReadPointAt(2);
142
Point pt = reader.GetPoint();
143
TestPoint.Test_B2(pt);
146
Liblas.ReaderFactory.FileClose(ifs);
149
private static void Test_WriteT()
151
// read in all the points from A, and write out to a temp file that looks like B
153
ReaderFactory factory = new ReaderFactory();
155
SWIGTYPE_p_std__istream ifs = Liblas.ReaderFactory.FileOpen(fileB);
156
SWIGTYPE_p_std__ostream ofs = Liblas.WriterFactory.FileCreate(fileT);
158
using (Reader reader = factory.CreateWithStream(ifs))
160
Header rHeader = reader.GetHeader();
163
Header wHeader = new Header(rHeader);
165
wHeader.SetSystemId("liblas test");
166
wHeader.SetSoftwareId("swig test");
167
wHeader.SetCompressed(true);
168
guid g = new guid("D59B08E7-79EE-47E4-AAE1-2B8DE4B87331");
169
wHeader.SetProjectId(g);
170
wHeader.SetCreationYear(2011);
171
wHeader.SetCreationDOY(12);
174
using (Writer writer = new Writer(ofs, wHeader))
176
while (reader.ReadNextPoint())
178
Point pt = reader.GetPoint();
179
bool ok = writer.WritePoint(pt);
186
Liblas.WriterFactory.FileClose(ofs);
187
Liblas.ReaderFactory.FileClose(ifs);
190
private static void Test_ReadT()
192
SWIGTYPE_p_std__istream ifs = Liblas.ReaderFactory.FileOpen(fileT);
194
ReaderFactory factory = new ReaderFactory();
196
using (Reader reader = factory.CreateWithStream(ifs))
198
TestReader.Test_T(reader);
200
Header header = reader.GetHeader();
201
TestHeader.Test_T(header);
203
TestGuid.Test_T(header.GetProjectId());
205
VectorVariableRecord vlrs = header.GetVLRs();
206
TestVariableRecord.Test_T(vlrs);
208
SpatialReference srs = header.GetSRS();
209
TestSpatialReference.Test(srs);
211
bool ok = reader.ReadPointAt(2);
213
Point pt = reader.GetPoint();
214
TestPoint.Test_B2(pt);
216
Liblas.ReaderFactory.FileClose(ifs);