lasunzipper.cpp
Go to the documentation of this file.
1 /*
2 ===============================================================================
3 
4  FILE: lasunzipper.cpp
5 
6  CONTENTS:
7 
8  see corresponding header file
9 
10  PROGRAMMERS:
11 
12  martin.isenburg@gmail.com
13 
14  COPYRIGHT:
15 
16  (c) 2011, Martin Isenburg, LASSO - tools to catch reality
17 
18  This is free software; you can redistribute and/or modify it under the
19  terms of the GNU Lesser General Licence as published by the Free Software
20  Foundation. See the COPYING file for more information.
21 
22  This software is distributed WITHOUT ANY WARRANTY and without even the
23  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 
25  CHANGE HISTORY:
26 
27  see corresponding header file
28 
29 ===============================================================================
30 */
31 #include "lasunzipper.hpp"
32 
33 #include <string.h>
34 #include <stdlib.h>
35 
36 #include "bytestreamin_file.hpp"
37 #include "bytestreamin_istream.hpp"
38 #include "lasreadpoint.hpp"
39 
40 bool LASunzipper::open(FILE* infile, const LASzip* laszip)
41 {
42  if (!infile) return return_error("FILE* infile pointer is NULL");
43  if (!laszip) return return_error("const LASzip* laszip pointer is NULL");
44  count = 0;
45  if (reader) delete reader;
46  reader = new LASreadPoint();
47  if (!reader) return return_error("alloc of LASreadPoint failed");
48  if (!reader->setup(laszip->num_items, laszip->items, laszip)) return return_error("setup() of LASreadPoint failed");
49  if (stream) delete stream;
50  if (IS_LITTLE_ENDIAN())
51  stream = new ByteStreamInFileLE(infile);
52  else
53  stream = new ByteStreamInFileBE(infile);
54  if (!stream) return return_error("alloc of ByteStreamInFile failed");
55  if (!reader->init(stream)) return return_error("init() of LASreadPoint failed");
56  return true;
57 }
58 
59 bool LASunzipper::open(istream& instream, const LASzip* laszip)
60 {
61  if (!laszip) return return_error("const LASzip* laszip pointer is NULL");
62  count = 0;
63  if (reader) delete reader;
64  reader = new LASreadPoint();
65  if (!reader) return return_error("alloc of LASreadPoint failed");
66  if (!reader->setup(laszip->num_items, laszip->items, laszip)) return return_error("setup() of LASreadPoint failed");
67  if (stream) delete stream;
68  if (IS_LITTLE_ENDIAN())
69  stream = new ByteStreamInIstreamLE(instream);
70  else
71  stream = new ByteStreamInIstreamBE(instream);
72  if (!stream) return return_error("alloc of ByteStreamInStream failed");
73  if (!reader->init(stream)) return return_error("init() of LASreadPoint failed");
74  return true;
75 }
76 
77 bool LASunzipper::seek(const unsigned int position)
78 {
79  if (!reader->seek(count, position)) return return_error("seek() of LASreadPoint failed");
80  count = position;
81  return true;
82 }
83 
84 unsigned int LASunzipper::tell() const
85 {
86  return count;
87 }
88 
89 bool LASunzipper::read(unsigned char * const * point)
90 {
91  count++;
92  return (reader->read(point) == TRUE);
93 }
94 
96 {
97  BOOL done = TRUE;
98  if (reader)
99  {
100  done = reader->done();
101  delete reader;
102  reader = 0;
103  }
104  if (stream)
105  {
106  delete stream;
107  stream = 0;
108  }
109  if (!done) return return_error("done() of LASreadPoint failed");
110  return true;
111 }
112 
113 const char* LASunzipper::get_error() const
114 {
115  return error_string;
116 }
117 
119 {
120  char err[256];
121  sprintf(err, "%s (LASzip v%d.%dr%d)", error, LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION);
122  if (error_string) free(error_string);
123  error_string = strdup(err);
124  return false;
125 }
126 
128 {
129  error_string = 0;
130  count = 0;
131  stream = 0;
132  reader = 0;
133 }
134 
136 {
137  if (error_string) free(error_string);
138  if (reader || stream) close();
139 }
BOOL IS_LITTLE_ENDIAN()
Definition: mydefs.hpp:144
int BOOL
Definition: mydefs.hpp:57
bool open(FILE *file, const LASzip *laszip)
Definition: lasunzipper.cpp:40
BOOL setup(const U32 num_items, const LASitem *items, const LASzip *laszip=0)
unsigned int count
Definition: lasunzipper.hpp:69
BOOL read(U8 *const *point)
#define LASZIP_VERSION_MINOR
Definition: laszip.hpp:50
BOOL seek(const U32 current, const U32 target)
ByteStreamIn * stream
Definition: lasunzipper.hpp:70
const char * get_error() const
unsigned int tell() const
Definition: lasunzipper.cpp:84
KF_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func="")
Error handler. All GPU functions from this subsystem call the function to report an error...
#define LASZIP_VERSION_MAJOR
Definition: laszip.hpp:49
bool return_error(const char *err)
LASitem * items
Definition: laszip.hpp:121
char * error_string
Definition: lasunzipper.hpp:73
#define LASZIP_VERSION_REVISION
Definition: laszip.hpp:51
unsigned short num_items
Definition: laszip.hpp:120
#define TRUE
Definition: mydefs.hpp:137
BOOL init(ByteStreamIn *instream)
bool seek(const unsigned int position)
Definition: lasunzipper.cpp:77
bool close()
Definition: lasunzipper.cpp:95
LASreadPoint * reader
Definition: lasunzipper.hpp:71
bool read(unsigned char *const *point)
Definition: lasunzipper.cpp:89


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:07