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

« back to all changes in this revision

Viewing changes to test/unit/reader_test.cpp

  • 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
// $Id$
 
2
//
 
3
// (C) Copyright Mateusz Loskot 2008, mateusz@loskot.net
 
4
// Distributed under the BSD License
 
5
// (See accompanying file LICENSE.txt or copy at
 
6
// http://www.opensource.org/licenses/bsd-license.php)
 
7
//
 
8
 
 
9
#include <liblas/liblas.hpp>
 
10
#include <tut/tut.hpp>
 
11
#include <fstream>
 
12
#include <string>
 
13
#include "liblas_test.hpp"
 
14
#include "common.hpp"
 
15
 
 
16
namespace tut
 
17
 
18
    struct lasreader_data
 
19
    {
 
20
        std::string file10_;
 
21
        std::string file12_;
 
22
 
 
23
        lasreader_data()
 
24
            : file10_(g_test_data_path + "//TO_core_last_clip.las")
 
25
            , file12_(g_test_data_path + "//certainty3d-color-utm-feet-navd88.las")
 
26
        {}
 
27
    };
 
28
 
 
29
    typedef test_group<lasreader_data> tg;
 
30
    typedef tg::object to;
 
31
 
 
32
    tg test_group_lasreader("liblas::Reader");
 
33
 
 
34
    // Test user-declared constructor
 
35
    template<>
 
36
    template<>
 
37
    void to::test<1>()
 
38
    {
 
39
        std::ifstream ifs;
 
40
        ifs.open(file10_.c_str(), std::ios::in | std::ios::binary);
 
41
        liblas::Reader reader(ifs);
 
42
 
 
43
        ensure_equals(reader.GetHeader().GetVersionMinor(), 0);
 
44
    }
 
45
 
 
46
    // Test reading header
 
47
    template<>
 
48
    template<>
 
49
    void to::test<2>()
 
50
    {
 
51
        std::ifstream ifs;
 
52
        ifs.open(file10_.c_str(), std::ios::in | std::ios::binary);
 
53
        liblas::Reader reader(ifs);
 
54
        liblas::Header const& hdr = reader.GetHeader();
 
55
 
 
56
        test_file10_header(hdr);
 
57
    }
 
58
 
 
59
    // Test GetPoint method
 
60
    template<>
 
61
    template<>
 
62
    void to::test<3>()
 
63
    {
 
64
        std::ifstream ifs;
 
65
        ifs.open(file10_.c_str(), std::ios::in | std::ios::binary);
 
66
        liblas::Reader reader(ifs);
 
67
 
 
68
        // uninitialized point object, a null-point
 
69
        liblas::Point const& p = reader.GetPoint();
 
70
        ensure(p == liblas::Point());
 
71
    }
 
72
 
 
73
    // Test ReadPoint and GetPoint pair
 
74
    template<>
 
75
    template<>
 
76
    void to::test<4>()
 
77
    {
 
78
        std::ifstream ifs;
 
79
        ifs.open(file10_.c_str(), std::ios::in | std::ios::binary);
 
80
        liblas::Reader reader(ifs);
 
81
 
 
82
        // read 1st point
 
83
        reader.ReadNextPoint();
 
84
        test_file10_point1(reader.GetPoint());
 
85
 
 
86
        // read 2nd point
 
87
        reader.ReadNextPoint();
 
88
        test_file10_point2(reader.GetPoint());
 
89
 
 
90
        // read and skip 3rd point
 
91
        reader.ReadNextPoint();
 
92
 
 
93
        // read 4th point
 
94
        reader.ReadNextPoint();
 
95
        test_file10_point4(reader.GetPoint());
 
96
 
 
97
        // read and count remaining points from 5 to 8
 
98
        unsigned short c = 0;
 
99
        while (reader.ReadNextPoint())
 
100
        {
 
101
            ++c;
 
102
        }
 
103
        ensure_equals(c, 4);
 
104
    }
 
105
 
 
106
    // Test ReadPointAt and GetPoint pair
 
107
    template<>
 
108
    template<>
 
109
    void to::test<5>()
 
110
    {
 
111
        std::ifstream ifs;
 
112
        ifs.open(file10_.c_str(), std::ios::in | std::ios::binary);
 
113
        liblas::Reader reader(ifs);
 
114
 
 
115
        // read 1st point
 
116
        reader.ReadPointAt(0);
 
117
        test_file10_point1(reader.GetPoint());
 
118
 
 
119
        // read 4th point
 
120
        reader.ReadPointAt(3);
 
121
        test_file10_point4(reader.GetPoint());
 
122
 
 
123
        // read back to 2nd point
 
124
        reader.ReadPointAt(1);
 
125
        test_file10_point2(reader.GetPoint());
 
126
    }
 
127
 
 
128
    // Test operator[] and GetPoint pair
 
129
    template<>
 
130
    template<>
 
131
    void to::test<6>()
 
132
    {
 
133
        std::ifstream ifs;
 
134
        ifs.open(file10_.c_str(), std::ios::in | std::ios::binary);
 
135
        liblas::Reader reader(ifs);
 
136
 
 
137
        // read 1st point
 
138
        test_file10_point1(reader[0]);
 
139
 
 
140
        // read 4th point
 
141
        test_file10_point4(reader[3]);
 
142
 
 
143
        // read back to 2nd point
 
144
        test_file10_point2(reader[1]);
 
145
    }
 
146
 
 
147
    // Test seek and GetPoint pair
 
148
    template<>
 
149
    template<>
 
150
    void to::test<7>()
 
151
    {
 
152
        std::ifstream ifs;
 
153
        ifs.open(file10_.c_str(), std::ios::in | std::ios::binary);
 
154
        liblas::Reader reader(ifs);
 
155
 
 
156
        // read 1st point
 
157
        reader.ReadNextPoint();
 
158
        test_file10_point1(reader.GetPoint());
 
159
        
 
160
        // seek to 4th point
 
161
        reader.Seek(4);
 
162
 
 
163
        // read 4th point
 
164
        test_file10_point4(reader[3]);
 
165
 
 
166
    }
 
167
 
 
168
    // Test summarization and valid values
 
169
    template<>
 
170
    template<>
 
171
    void to::test<8>()
 
172
    {
 
173
        std::ifstream ifs;
 
174
        ifs.open(file12_.c_str(), std::ios::in | std::ios::binary);
 
175
        liblas::Reader reader(ifs);
 
176
        
 
177
        liblas::Summary summary;
 
178
        liblas::CoordinateSummary coord_summary;
 
179
        
 
180
        bool read = reader.ReadNextPoint();
 
181
        while (read)
 
182
        {
 
183
            summary.AddPoint(reader.GetPoint());
 
184
            coord_summary.AddPoint(reader.GetPoint());
 
185
            read = reader.ReadNextPoint();
 
186
        }
 
187
 
 
188
        liblas::property_tree::ptree tree = summary.GetPTree();
 
189
        
 
190
        ensure_equals("Point count not correct", 
 
191
                       tree.get<boost::uint32_t>("summary.points.count"),
 
192
                       static_cast<boost::uint32_t>(10126));
 
193
                       
 
194
        ensure_distance("Min X does not match", 
 
195
                        tree.get<double>("summary.points.minimum.x"), 
 
196
                        6326726.536120,
 
197
                        0.000001);
 
198
 
 
199
        ensure_distance("Min Y does not match", 
 
200
                        tree.get<double>("summary.points.minimum.y"), 
 
201
                        2068062.385430,
 
202
                        0.000001);
 
203
 
 
204
        ensure_distance("Min Z does not match", 
 
205
                        tree.get<double>("summary.points.minimum.z"), 
 
206
                        2700.5303501,
 
207
                        0.000001);
 
208
 
 
209
 
 
210
        ensure_distance("Max X does not match", 
 
211
                        tree.get<double>("summary.points.maximum.x"), 
 
212
                        6330162.951062,
 
213
                        0.000001);
 
214
 
 
215
        ensure_distance("Max Y does not match", 
 
216
                        tree.get<double>("summary.points.maximum.y"), 
 
217
                        2071932.240223,
 
218
                        0.000001);
 
219
 
 
220
        ensure_distance("Max Z does not match", 
 
221
                        tree.get<double>("summary.points.maximum.z"), 
 
222
                        2975.7118862,
 
223
                        0.000001);
 
224
 
 
225
        ensure_equals("Min red not correct", 
 
226
                       tree.get<boost::uint16_t>("summary.points.minimum.color.red"),
 
227
                       static_cast<boost::uint16_t>(4096)); 
 
228
        ensure_equals("Min green not correct", 
 
229
                       tree.get<boost::uint16_t>("summary.points.minimum.color.green"),
 
230
                       static_cast<boost::uint16_t>(2304));                                              
 
231
        ensure_equals("Min blue not correct", 
 
232
                       tree.get<boost::uint16_t>("summary.points.minimum.color.blue"),
 
233
                       static_cast<boost::uint16_t>(0)); 
 
234
 
 
235
        ensure_equals("Max red not correct", 
 
236
                       tree.get<boost::uint16_t>("summary.points.maximum.color.red"),
 
237
                       static_cast<boost::uint16_t>(65280)); 
 
238
        ensure_equals("Max green not correct", 
 
239
                       tree.get<boost::uint16_t>("summary.points.maximum.color.green"),
 
240
                       static_cast<boost::uint16_t>(64512));                                              
 
241
        ensure_equals("Max blue not correct", 
 
242
                       tree.get<boost::uint16_t>("summary.points.maximum.color.blue"),
 
243
                       static_cast<boost::uint16_t>(56320));   
 
244
        
 
245
        tree = coord_summary.GetPTree();
 
246
        ensure_distance("Coordinate Summary Min X does not match", 
 
247
                        tree.get<double>("summary.points.minimum.x"), 
 
248
                        6326726.536120,
 
249
                        0.000001);
 
250
 
 
251
        ensure_distance("Coordinate Summary Min Y does not match", 
 
252
                        tree.get<double>("summary.points.minimum.y"), 
 
253
                        2068062.385430,
 
254
                        0.000001);
 
255
 
 
256
        ensure_distance("Coordinate Summary Min Z does not match", 
 
257
                        tree.get<double>("summary.points.minimum.z"), 
 
258
                        2700.5303501,
 
259
                        0.000001);
 
260
 
 
261
 
 
262
        ensure_distance("Coordinate Summary Max X does not match", 
 
263
                        tree.get<double>("summary.points.maximum.x"), 
 
264
                        6330162.951062,
 
265
                        0.000001);
 
266
 
 
267
        ensure_distance("Coordinate Summary Max Y does not match", 
 
268
                        tree.get<double>("summary.points.maximum.y"), 
 
269
                        2071932.240223,
 
270
                        0.000001);
 
271
 
 
272
        ensure_distance("Coordinate Summary Max Z does not match", 
 
273
                        tree.get<double>("summary.points.maximum.z"), 
 
274
                        2975.7118862,
 
275
                        0.000001);
 
276
 
 
277
    }
 
278
 
 
279
}
 
280