libLAS API Reference  1.8.1
liblas.hpp
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id$
3  *
4  * Project: libLAS - http://liblas.org - A BSD library for LAS format data.
5  * Purpose: LAS include file
6  * Author: Mateusz Loskot, mateusz@loskot.net
7  *
8  ******************************************************************************
9  * Copyright (c) 2008, Mateusz Loskot
10  * Copyright (c) 2008, Phil Vachon
11  * Copyright (c) 2008, Howard Butler
12  *
13  * All rights reserved.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following
17  * conditions are met:
18  *
19  * * Redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer.
21  * * Redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in
23  * the documentation and/or other materials provided
24  * with the distribution.
25  * * Neither the name of the Martin Isenburg or Iowa Department
26  * of Natural Resources nor the names of its contributors may be
27  * used to endorse or promote products derived from this software
28  * without specific prior written permission.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
33  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
34  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
35  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
36  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
37  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
38  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
39  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
40  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
41  * OF SUCH DAMAGE.
42  ****************************************************************************/
43 
44 #ifndef LIBLAS_HPP_INCLUDED
45 #define LIBLAS_HPP_INCLUDED
46 
47 // liblas
48 #include <liblas/version.hpp>
49 #include <liblas/exception.hpp>
50 #include <liblas/iterator.hpp>
51 #include <liblas/bounds.hpp>
53 #include <liblas/color.hpp>
54 #include <liblas/error.hpp>
55 #include <liblas/filter.hpp>
56 #include <liblas/header.hpp>
57 #include <liblas/point.hpp>
58 #include <liblas/reader.hpp>
59 #include <liblas/schema.hpp>
61 #include <liblas/transform.hpp>
63 #include <liblas/version.hpp>
64 #include <liblas/writer.hpp>
65 #include <liblas/utility.hpp>
66 #include <liblas/detail/endian.hpp>
67 #include <liblas/detail/private_utility.hpp>
69 #include <liblas/export.hpp>
70 #include <liblas/factory.hpp>
71 
72 // booost
73 #include <boost/array.hpp>
74 #include <boost/concept_check.hpp>
75 
76 #include <boost/shared_ptr.hpp>
77 
78 //#define USE_BOOST_IO
79 #ifdef USE_BOOST_IO
80 #include <ostream>
81 #include <boost/iostreams/device/file.hpp>
82 #include <boost/iostreams/stream.hpp>
83 #include <boost/iostreams/stream_buffer.hpp>
84 #endif
85 
86 
87 // std
88 #include <cstring>
89 #include <fstream>
90 #include <string>
91 #include <vector>
92 #include <stdint.h>
93 
101 namespace liblas
102 {
103 
112 inline bool Open(std::ifstream& ifs, std::string const& filename) // throw()
113 {
114  ifs.open(filename.c_str(), std::ios::in | std::ios::binary);
115  return ifs.is_open();
116 }
117 
118 inline std::istream* Open(std::string const& filename, std::ios::openmode mode) // throw()
119 {
120 #ifdef USE_BOOST_IO
121  namespace io = boost::iostreams;
122  io::stream<io::file_source>* ifs = NULL;
123  try
124  {
125  ifs = new io::stream<io::file_source>();
126  ifs->open(filename.c_str(), mode);
127  if (ifs->is_open() == false) return NULL;
128  return ifs;
129  }
130  catch (...)
131  {
132  delete ifs;
133  }
134 #else
135  std::ifstream* ifs = NULL;
136  try
137  {
138  ifs = new std::ifstream();
139  ifs->open(filename.c_str(), mode);
140  if (ifs->is_open() == false) {
141  delete ifs;
142  return NULL;
143  }
144  return ifs;
145  }
146  catch (...)
147  {
148  delete ifs;
149  }
150 #endif
151  return NULL;
152 }
153 
162 inline bool Create(std::ofstream& ofs, std::string const& filename) // throw()
163 {
164  ofs.open(filename.c_str(), std::ios::out | std::ios::binary);
165  return ofs.is_open();
166 }
167 
168 inline std::ostream* Create(std::string const& filename, std::ios::openmode mode)
169 {
170 #ifdef USE_BOOST_IO
171  namespace io = boost::iostreams;
172  io::stream<io::file_sink>* ofs = new io::stream<io::file_sink>();
173  ofs->open(filename.c_str(), mode);
174  if (ofs->is_open() == false) return NULL;
175  return ofs;
176 #else
177  std::ofstream* ofs = new std::ofstream();
178  ofs->open(filename.c_str(), mode);
179  if (ofs->is_open() == false) return NULL;
180  return ofs;
181 #endif
182 }
183 
184 inline void Cleanup(std::ostream* ofs)
185 {
186  // An ofstream is closeable and deletable, but
187  // an ostream like &std::cout isn't.
188  if (!ofs) return;
189 #ifdef USE_BOOST_IO
190  namespace io = boost::iostreams;
191  namespace io = boost::iostreams;
192  io::stream<io::file_sink>* source = dynamic_cast<io::stream<io::file_sink>*>(ofs);
193  if (source)
194  {
195  source->close();
196  delete ofs;
197  }
198 
199 #else
200  std::ofstream* source = dynamic_cast<std::ofstream*>(ofs);
201  if (source)
202  {
203  source->close();
204  delete ofs;
205  }
206 
207 #endif
208 }
209 
210 inline void Cleanup(std::istream* ifs)
211 {
212  // An ifstream is closeable and deletable, but
213  // an istream like &std::cin isn't.
214  if (!ifs) return;
215 #ifdef USE_BOOST_IO
216  namespace io = boost::iostreams;
217  io::stream<io::file_source>* source = dynamic_cast<io::stream<io::file_source>*>(ifs);
218  if (source)
219  {
220  source->close();
221  delete ifs;
222  }
223 #else
224  std::ifstream* source = dynamic_cast<std::ifstream*>(ifs);
225  if (source)
226  {
227  source->close();
228  delete ifs;
229  }
230 
231 
232 #endif
233 }
234 
235 class ReaderI
236 {
237 public:
238 
239  virtual liblas::Header const& GetHeader() const = 0;
240  virtual void ReadHeader() = 0;
241  virtual void SetHeader(liblas::Header const& header) = 0;
242  virtual liblas::Point const& GetPoint() const = 0;
243  virtual void ReadNextPoint() = 0;
244  virtual Point const& ReadPointAt(std::size_t n) = 0;
245  virtual void Seek(std::size_t n) = 0;
246 
247  virtual void Reset() = 0;
248 
249  virtual void SetFilters(std::vector<liblas::FilterPtr> const& filters) = 0;
250  virtual void SetTransforms(std::vector<liblas::TransformPtr> const& transforms) = 0;
251 
252  virtual std::vector<liblas::TransformPtr> GetTransforms() const = 0;
253  virtual std::vector<liblas::FilterPtr> GetFilters() const = 0;
254 
255  virtual ~ReaderI() {}
256 };
257 
258 class WriterI
259 {
260 public:
261 
262 
263  virtual liblas::Header& GetHeader() const = 0;
264  virtual void WriteHeader() = 0;
265  virtual void SetHeader(liblas::Header const& header) = 0;
266 
267  virtual void UpdatePointCount(uint32_t count) = 0;
268  virtual void WritePoint(const Point& point) = 0;
269 
270  virtual void SetFilters(std::vector<liblas::FilterPtr> const& filters) = 0;
271  virtual void SetTransforms(std::vector<liblas::TransformPtr> const& transforms) = 0;
272 
273  virtual std::vector<liblas::TransformPtr> GetTransforms() const = 0;
274  virtual std::vector<liblas::FilterPtr> GetFilters() const = 0;
275 
276 
277  virtual ~WriterI() {}
278 
279 };
280 
281 } // namespace liblas
282 
283 #endif // LIBLAS_HPP_INCLUDED
virtual Point const & ReadPointAt(std::size_t n)=0
#define NULL
Definition: las_config.h:63
virtual ~WriterI()
Definition: liblas.hpp:277
void Cleanup(std::ostream *ofs)
Definition: liblas.hpp:184
virtual std::vector< liblas::FilterPtr > GetFilters() const =0
Definition: liblas.hpp:235
bool Open(std::ifstream &ifs, std::string const &filename)
Open file to read in binary mode.
Definition: liblas.hpp:112
virtual liblas::Point const & GetPoint() const =0
virtual void Reset()=0
virtual void SetHeader(liblas::Header const &header)=0
Definition: liblas.hpp:258
bool Create(std::ofstream &ofs, std::string const &filename)
Create file and open to write in binary mode.
Definition: liblas.hpp:162
Namespace grouping all elements of libLAS public interface.
Definition: bounds.hpp:60
Point data record composed with X, Y, Z coordinates and attributes.
Definition: point.hpp:68
virtual ~ReaderI()
Definition: liblas.hpp:255
virtual std::vector< liblas::TransformPtr > GetTransforms() const =0
virtual void Seek(std::size_t n)=0
virtual void ReadHeader()=0
virtual void ReadNextPoint()=0
virtual liblas::Header const & GetHeader() const =0
Definition of public header block.
Definition: header.hpp:78
virtual void SetTransforms(std::vector< liblas::TransformPtr > const &transforms)=0
virtual void SetFilters(std::vector< liblas::FilterPtr > const &filters)=0