1 //
2 // (C) Copyright 2010 Michael P. Gerlek (mpg@flaxen.com)
3 // Distributed under the BSD License
4 // (See accompanying file LICENSE.txt or copy at
5 // http://www.opensource.org/licenses/bsd-license.php)
6 //
7 
8 #ifdef HAVE_LASZIP
9 
10 #include <liblas/liblas.hpp>
11 #include <liblas/variablerecord.hpp>
12 #include <tut/tut.hpp>
13 #include <fstream>
14 #include <string>
15 #include "liblas_test.hpp"
16 #include "common.hpp"
17 
18 namespace tut
19 {
20     struct zipreader_data
21     {
22         std::string file_las;
23         std::string file_laz;
24 
zipreader_datatut::zipreader_data25         zipreader_data() :
26             file_las(g_test_data_path + "//1.2-with-color.las"),
27             file_laz(g_test_data_path + "//1.2-with-color.laz")
28         {}
29     };
30 
31     typedef test_group<zipreader_data> tg;
32     typedef tg::object to;
33 
34     tg test_group_zipreader("liblas::ZipReader");
35 
36     // Test the factory does the right thing and the header is marked as compressed
37     template<>
38     template<>
test()39     void to::test<1>()
40     {
41         std::ifstream ifs_las;
42         ifs_las.open(file_las.c_str(), std::ios::in | std::ios::binary);
43         std::ifstream ifs_laz;
44         ifs_laz.open(file_laz.c_str(), std::ios::in | std::ios::binary);
45 
46         liblas::ReaderFactory factory;
47         liblas::Reader reader_las = factory.CreateWithStream(ifs_las);
48         liblas::Reader reader_laz = factory.CreateWithStream(ifs_laz);
49 
50         liblas::Header const& header_las = reader_las.GetHeader();
51         liblas::Header const& header_laz = reader_laz.GetHeader();
52 
53         ensure_equals(header_las.Compressed(), false);
54         ensure_equals(header_laz.Compressed(), true);
55     }
56 
57     // Test reading 3 points (via ReadNext)
58     template<>
59     template<>
test()60     void to::test<2>()
61     {
62         std::ifstream ifs_las;
63         ifs_las.open(file_las.c_str(), std::ios::in | std::ios::binary);
64         std::ifstream ifs_laz;
65         ifs_laz.open(file_laz.c_str(), std::ios::in | std::ios::binary);
66 
67         liblas::ReaderFactory factory;
68         liblas::Reader reader_las = factory.CreateWithStream(ifs_las);
69         liblas::Reader reader_laz = factory.CreateWithStream(ifs_laz);
70 
71         reader_las.ReadNextPoint();
72         liblas::Point p0_las = reader_las.GetPoint();
73         reader_las.ReadNextPoint();
74         liblas::Point p1_las = reader_las.GetPoint();
75         reader_las.ReadNextPoint();
76         liblas::Point p2_las = reader_las.GetPoint();
77 
78         reader_laz.ReadNextPoint();
79         liblas::Point p0_laz = reader_laz.GetPoint();
80         reader_laz.ReadNextPoint();
81         liblas::Point p1_laz = reader_laz.GetPoint();
82         reader_laz.ReadNextPoint();
83         liblas::Point p2_laz = reader_laz.GetPoint();
84 
85         ensure_equals(p0_las, p0_laz);
86         ensure_equals(p1_las, p1_laz);
87         ensure_equals(p2_las, p2_laz);
88 
89         test_file_12Color_point0(p0_las);
90         test_file_12Color_point1(p1_las);
91         test_file_12Color_point2(p2_las);
92         test_file_12Color_point0(p0_laz);
93         test_file_12Color_point1(p1_laz);
94         test_file_12Color_point2(p2_laz);
95 
96         return;
97     }
98 
99     // Test reading 3 points (via ReadAt)
100     template<>
101     template<>
test()102     void to::test<3>()
103     {
104         std::ifstream ifs_las;
105         ifs_las.open(file_las.c_str(), std::ios::in | std::ios::binary);
106         std::ifstream ifs_laz;
107         ifs_laz.open(file_laz.c_str(), std::ios::in | std::ios::binary);
108 
109         liblas::ReaderFactory factory;
110         liblas::Reader reader_las = factory.CreateWithStream(ifs_las);
111         liblas::Reader reader_laz = factory.CreateWithStream(ifs_laz);
112 
113         // test ReadPointAt()
114         {
115             reader_las.ReadPointAt(2);
116             liblas::Point p2_las = reader_las.GetPoint();
117             reader_las.ReadPointAt(1);
118             liblas::Point p1_las = reader_las.GetPoint();
119             reader_las.ReadPointAt(0);
120             liblas::Point p0_las = reader_las.GetPoint();
121 
122             test_file_12Color_point0(p0_las);
123             test_file_12Color_point1(p1_las);
124             test_file_12Color_point2(p2_las);
125 
126             reader_laz.ReadPointAt(2);
127             liblas::Point p2_laz = reader_laz.GetPoint();
128             reader_laz.ReadPointAt(1);
129             liblas::Point p1_laz = reader_laz.GetPoint();
130             reader_laz.ReadPointAt(0);
131             liblas::Point p0_laz = reader_laz.GetPoint();
132 
133             ensure_equals(p0_laz, p0_las);
134             ensure_equals(p1_laz, p1_las);
135             ensure_equals(p2_laz, p2_las);
136 
137             test_file_12Color_point0(p0_laz);
138             test_file_12Color_point1(p1_laz);
139             test_file_12Color_point2(p2_laz);
140         }
141 
142         // test Seek()
143         {
144             reader_las.Seek(1);
145             reader_las.ReadNextPoint();
146             liblas::Point p1_las = reader_las.GetPoint();
147             reader_las.Seek(0);
148             reader_las.ReadNextPoint();
149             liblas::Point p0_las = reader_las.GetPoint();
150             reader_las.Seek(2);
151             reader_las.ReadNextPoint();
152             liblas::Point p2_las = reader_las.GetPoint();
153 
154             test_file_12Color_point0(p0_las);
155             test_file_12Color_point1(p1_las);
156             test_file_12Color_point2(p2_las);
157 
158             reader_laz.Seek(1);
159             reader_laz.ReadNextPoint();
160             liblas::Point p1_laz = reader_laz.GetPoint();
161             reader_laz.Seek(0);
162             reader_laz.ReadNextPoint();
163             liblas::Point p0_laz = reader_laz.GetPoint();
164             reader_laz.Seek(2);
165             reader_laz.ReadNextPoint();
166             liblas::Point p2_laz = reader_laz.GetPoint();
167 
168             ensure_equals(p0_las, p0_laz);
169             ensure_equals(p1_las, p1_laz);
170             ensure_equals(p2_las, p2_laz);
171 
172             test_file_12Color_point0(p0_laz);
173             test_file_12Color_point1(p1_laz);
174             test_file_12Color_point2(p2_laz);
175         }
176     }
177 
178     // Test the VLR
179     template<>
180     template<>
test()181     void to::test<4>()
182     {
183         std::ifstream ifs;
184         ifs.open(file_laz.c_str(), std::ios::in | std::ios::binary);
185 
186         liblas::ReaderFactory f;
187         liblas::Reader reader = f.CreateWithStream(ifs);
188 
189         liblas::Header const& header = reader.GetHeader();
190         test_laszip_vlr(header);
191 
192         return;
193     }
194 }
195 
196 #endif // HAVE_LASZIP
197