libLAS API Reference  (svn-trunk)
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 = new io::stream<io::file_source>();
123  ifs->open(filename.c_str(), mode);
124  if (ifs->is_open() == false) { delete ifs; return NULL; }
125  return ifs;
126 #else
127  std::ifstream* ifs = new std::ifstream();
128  ifs->open(filename.c_str(), mode);
129  if (ifs->is_open() == false) { delete ifs; return NULL; }
130  return ifs;
131 #endif
132 }
133 
142 inline bool Create(std::ofstream& ofs, std::string const& filename) // throw()
143 {
144  ofs.open(filename.c_str(), std::ios::out | std::ios::binary);
145  return ofs.is_open();
146 }
147 
148 inline std::ostream* Create(std::string const& filename, std::ios::openmode mode)
149 {
150 #ifdef USE_BOOST_IO
151  namespace io = boost::iostreams;
152  io::stream<io::file_sink>* ofs = new io::stream<io::file_sink>();
153  ofs->open(filename.c_str(), mode);
154  if (ofs->is_open() == false) return NULL;
155  return ofs;
156 #else
157  std::ofstream* ofs = new std::ofstream();
158  ofs->open(filename.c_str(), mode);
159  if (ofs->is_open() == false) return NULL;
160  return ofs;
161 #endif
162 }
163 
164 inline void Cleanup(std::ostream* ofs)
165 {
166  // An ofstream is closeable and deletable, but
167  // an ostream like &std::cout isn't.
168  if (!ofs) return;
169 #ifdef USE_BOOST_IO
170  namespace io = boost::iostreams;
171  namespace io = boost::iostreams;
172  io::stream<io::file_sink>* source = dynamic_cast<io::stream<io::file_sink>*>(ofs);
173  if (source)
174  {
175  source->close();
176  delete ofs;
177  }
178 
179 #else
180  std::ofstream* source = dynamic_cast<std::ofstream*>(ofs);
181  if (source)
182  {
183  source->close();
184  delete ofs;
185  }
186 
187 #endif
188 }
189 
190 inline void Cleanup(std::istream* ifs)
191 {
192  // An ifstream is closeable and deletable, but
193  // an istream like &std::cin isn't.
194  if (!ifs) return;
195 #ifdef USE_BOOST_IO
196  namespace io = boost::iostreams;
197  io::stream<io::file_source>* source = dynamic_cast<io::stream<io::file_source>*>(ifs);
198  if (source)
199  {
200  source->close();
201  delete ifs;
202  }
203 #else
204  std::ifstream* source = dynamic_cast<std::ifstream*>(ifs);
205  if (source)
206  {
207  source->close();
208  delete ifs;
209  }
210 
211 
212 #endif
213 }
214 
215 class ReaderI
216 {
217 public:
218 
219  virtual liblas::Header const& GetHeader() const = 0;
220  virtual void ReadHeader() = 0;
221  virtual void SetHeader(liblas::Header const& header) = 0;
222  virtual liblas::Point const& GetPoint() const = 0;
223  virtual void ReadNextPoint() = 0;
224  virtual Point const& ReadPointAt(std::size_t n) = 0;
225  virtual void Seek(std::size_t n) = 0;
226 
227  virtual void Reset() = 0;
228 
229  virtual void SetFilters(std::vector<liblas::FilterPtr> const& filters) = 0;
230  virtual void SetTransforms(std::vector<liblas::TransformPtr> const& transforms) = 0;
231 
232  virtual std::vector<liblas::TransformPtr> GetTransforms() const = 0;
233  virtual std::vector<liblas::FilterPtr> GetFilters() const = 0;
234 
235  virtual ~ReaderI() {}
236 };
237 
238 class WriterI
239 {
240 public:
241 
242 
243  virtual liblas::Header& GetHeader() const = 0;
244  virtual void WriteHeader() = 0;
245  virtual void SetHeader(liblas::Header const& header) = 0;
246 
247  virtual void UpdatePointCount(uint32_t count) = 0;
248  virtual void WritePoint(const Point& point) = 0;
249 
250  virtual void SetFilters(std::vector<liblas::FilterPtr> const& filters) = 0;
251  virtual void SetTransforms(std::vector<liblas::TransformPtr> const& transforms) = 0;
252 
253  virtual std::vector<liblas::TransformPtr> GetTransforms() const = 0;
254  virtual std::vector<liblas::FilterPtr> GetFilters() const = 0;
255 
256 
257  virtual ~WriterI() {}
258 
259 };
260 
261 } // namespace liblas
262 
263 #endif // LIBLAS_HPP_INCLUDED
virtual Point const & ReadPointAt(std::size_t n)=0
#define NULL
Definition: las_config.h:63
virtual std::vector< liblas::TransformPtr > GetTransforms() const =0
virtual ~WriterI()
Definition: liblas.hpp:257
void Cleanup(std::ostream *ofs)
Definition: liblas.hpp:164
virtual std::vector< liblas::FilterPtr > GetFilters() const =0
virtual void SetTransforms(std::vector< liblas::TransformPtr > const &transforms)=0
virtual void WriteHeader()=0
Definition: liblas.hpp:215
virtual liblas::Header & GetHeader() const =0
bool Open(std::ifstream &ifs, std::string const &filename)
Open file to read in binary mode.
Definition: liblas.hpp:112
virtual void UpdatePointCount(uint32_t count)=0
virtual std::vector< liblas::TransformPtr > GetTransforms() const =0
virtual void SetFilters(std::vector< liblas::FilterPtr > const &filters)=0
virtual void Reset()=0
virtual void SetHeader(liblas::Header const &header)=0
virtual std::vector< liblas::FilterPtr > GetFilters() const =0
Definition: liblas.hpp:238
bool Create(std::ofstream &ofs, std::string const &filename)
Create file and open to write in binary mode.
Definition: liblas.hpp:142
Namespace grouping all elements of libLAS public interface.
Definition: bounds.hpp:60
virtual liblas::Header const & GetHeader() const =0
Point data record composed with X, Y, Z coordinates and attributes.
Definition: point.hpp:68
virtual liblas::Point const & GetPoint() const =0
virtual ~ReaderI()
Definition: liblas.hpp:235
virtual void Seek(std::size_t n)=0
virtual void ReadHeader()=0
virtual void SetHeader(liblas::Header const &header)=0
virtual void ReadNextPoint()=0
Definition of public header block.
Definition: header.hpp:78
virtual void WritePoint(const Point &point)=0
virtual void SetTransforms(std::vector< liblas::TransformPtr > const &transforms)=0
virtual void SetFilters(std::vector< liblas::FilterPtr > const &filters)=0