~ubuntu-branches/ubuntu/trusty/liblas/trusty-proposed

« back to all changes in this revision

Viewing changes to csharp-new/liblas_swig_test/Program.cs

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2014-01-05 17:00:29 UTC
  • mfrom: (7.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140105170029-ddtp0j63x5jvck2u
Tags: 1.7.0+dfsg-2
Fixed missing linking of system boost component.
(closes: #733282)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 *
 
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)
 
6
 *
 
7
 ******************************************************************************
 
8
 * Copyright (c) 2011, Michael P. Gerlek (mpg@flaxen.com)
 
9
 *
 
10
 * All rights reserved.
 
11
 * 
 
12
 * Redistribution and use in source and binary forms, with or without 
 
13
 * modification, are permitted provided that the following 
 
14
 * conditions are met:
 
15
 * 
 
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.
 
26
 * 
 
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 
 
38
 * OF SUCH DAMAGE.
 
39
 ****************************************************************************/
 
40
 
 
41
using System;
 
42
using System.Collections.Generic;
 
43
using System.Linq;
 
44
using System.Text;
 
45
 
 
46
using Liblas;
 
47
using System.Diagnostics;
 
48
using System.IO;
 
49
 
 
50
namespace swig_test
 
51
{
 
52
   public class Program
 
53
   {
 
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";
 
57
      
 
58
      static public bool IsApprox(double a, double b, double tol)
 
59
      {
 
60
         double min = Math.Min(a, b);
 
61
         double max = Math.Max(a, b);
 
62
         double delta = max - min;
 
63
         if (delta > tol)
 
64
            return false;
 
65
         return true;
 
66
      }
 
67
 
 
68
      static int Main(string[] args)
 
69
      {
 
70
         // reader tests for A
 
71
         Test_ReadA();
 
72
 
 
73
         // reader tests for B
 
74
         Test_ReadB();
 
75
 
 
76
         // writer tests
 
77
         Test_WriteT();
 
78
 
 
79
         // reader tests for the generated B
 
80
         Test_ReadT();
 
81
 
 
82
         File.Delete(fileT);
 
83
 
 
84
         return 0;
 
85
      }
 
86
 
 
87
      private static void Test_ReadA()
 
88
      {
 
89
         ReaderFactory factory = new ReaderFactory();
 
90
 
 
91
         SWIGTYPE_p_std__istream ifs = Liblas.ReaderFactory.FileOpen(fileA);
 
92
 
 
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))
 
96
         {
 
97
            TestReader.Test_A(reader);
 
98
 
 
99
            Header header = reader.GetHeader();
 
100
            TestHeader.Test_A(header);
 
101
 
 
102
            TestGuid.Test_A(header.GetProjectId());
 
103
 
 
104
            VectorVariableRecord vlrs = header.GetVLRs();
 
105
            TestVariableRecord.Test_A(vlrs);
 
106
 
 
107
            SpatialReference srs = header.GetSRS();
 
108
            TestSpatialReference.Test(srs);
 
109
 
 
110
            bool ok = reader.ReadPointAt(2);
 
111
            Debug.Assert(ok);
 
112
            Point pt = reader.GetPoint();
 
113
            TestPoint.Test_A2(pt);
 
114
         }
 
115
 
 
116
         Liblas.ReaderFactory.FileClose(ifs);
 
117
      }
 
118
 
 
119
      private static void Test_ReadB()
 
120
      {
 
121
         ReaderFactory factory = new ReaderFactory();
 
122
 
 
123
         SWIGTYPE_p_std__istream ifs = Liblas.ReaderFactory.FileOpen(fileB);
 
124
 
 
125
         using (Reader reader = factory.CreateWithStream(ifs))
 
126
         {
 
127
            TestReader.Test_B(reader);
 
128
 
 
129
            Header header = reader.GetHeader();
 
130
            TestHeader.Test_B(header);
 
131
 
 
132
            TestGuid.Test_B(header.GetProjectId());
 
133
 
 
134
            VectorVariableRecord vlrs = header.GetVLRs();
 
135
            TestVariableRecord.Test_B(vlrs);
 
136
 
 
137
            SpatialReference srs = header.GetSRS();
 
138
            TestSpatialReference.Test(srs);
 
139
 
 
140
            bool ok = reader.ReadPointAt(2);
 
141
            Debug.Assert(ok);
 
142
            Point pt = reader.GetPoint();
 
143
            TestPoint.Test_B2(pt);
 
144
         }
 
145
 
 
146
         Liblas.ReaderFactory.FileClose(ifs);
 
147
      }
 
148
 
 
149
      private static void Test_WriteT()
 
150
      {
 
151
         // read in all the points from A, and write out to a temp file that looks like B
 
152
 
 
153
         ReaderFactory factory = new ReaderFactory();
 
154
 
 
155
         SWIGTYPE_p_std__istream ifs = Liblas.ReaderFactory.FileOpen(fileB);
 
156
         SWIGTYPE_p_std__ostream ofs = Liblas.WriterFactory.FileCreate(fileT);
 
157
 
 
158
         using (Reader reader = factory.CreateWithStream(ifs))
 
159
         {
 
160
            Header rHeader = reader.GetHeader();
 
161
 
 
162
            {
 
163
               Header wHeader = new Header(rHeader);
 
164
               {
 
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);
 
172
               }
 
173
               {
 
174
                  using (Writer writer = new Writer(ofs, wHeader))
 
175
                  {
 
176
                     while (reader.ReadNextPoint())
 
177
                     {
 
178
                        Point pt = reader.GetPoint();
 
179
                        bool ok = writer.WritePoint(pt);
 
180
                        Debug.Assert(ok);
 
181
                     }
 
182
                  }
 
183
               }
 
184
            }
 
185
         }
 
186
         Liblas.WriterFactory.FileClose(ofs);
 
187
         Liblas.ReaderFactory.FileClose(ifs);
 
188
      }
 
189
 
 
190
      private static void Test_ReadT()
 
191
      {
 
192
         SWIGTYPE_p_std__istream ifs = Liblas.ReaderFactory.FileOpen(fileT);
 
193
 
 
194
         ReaderFactory factory = new ReaderFactory();
 
195
 
 
196
         using (Reader reader = factory.CreateWithStream(ifs))
 
197
         {
 
198
            TestReader.Test_T(reader);
 
199
 
 
200
            Header header = reader.GetHeader();
 
201
            TestHeader.Test_T(header);
 
202
 
 
203
            TestGuid.Test_T(header.GetProjectId());
 
204
 
 
205
            VectorVariableRecord vlrs = header.GetVLRs();
 
206
            TestVariableRecord.Test_T(vlrs);
 
207
 
 
208
            SpatialReference srs = header.GetSRS();
 
209
            TestSpatialReference.Test(srs);
 
210
 
 
211
            bool ok = reader.ReadPointAt(2);
 
212
            Debug.Assert(ok);
 
213
            Point pt = reader.GetPoint();
 
214
            TestPoint.Test_B2(pt);
 
215
         }
 
216
         Liblas.ReaderFactory.FileClose(ifs);
 
217
      }
 
218
 
 
219
   }
 
220
}