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 }
LASzip::num_items
unsigned short num_items
Definition: laszip.hpp:120
LASreadPoint::seek
BOOL seek(const U32 current, const U32 target)
Definition: lasreadpoint.cpp:253
lasunzipper.hpp
LASunzipper::seek
bool seek(const unsigned int position)
Definition: lasunzipper.cpp:77
bytestreamin_istream.hpp
LASunzipper::count
unsigned int count
Definition: lasunzipper.hpp:69
LASreadPoint
Definition: lasreadpoint.hpp:48
LASzip
Definition: laszip.hpp:80
TRUE
#define TRUE
Definition: mydefs.hpp:137
LASunzipper::LASunzipper
LASunzipper()
Definition: lasunzipper.cpp:127
lasreadpoint.hpp
LASzip::items
LASitem * items
Definition: laszip.hpp:121
LASZIP_VERSION_REVISION
#define LASZIP_VERSION_REVISION
Definition: laszip.hpp:51
LASreadPoint::done
BOOL done()
Definition: lasreadpoint.cpp:389
LASZIP_VERSION_MINOR
#define LASZIP_VERSION_MINOR
Definition: laszip.hpp:50
LASunzipper::get_error
const char * get_error() const
Definition: lasunzipper.cpp:113
LASreadPoint::setup
BOOL setup(const U32 num_items, const LASitem *items, const LASzip *laszip=0)
Definition: lasreadpoint.cpp:64
LASunzipper::open
bool open(FILE *file, const LASzip *laszip)
Definition: lasunzipper.cpp:40
LASreadPoint::read
BOOL read(U8 *const *point)
Definition: lasreadpoint.cpp:325
LASZIP_VERSION_MAJOR
#define LASZIP_VERSION_MAJOR
Definition: laszip.hpp:49
LASunzipper::error_string
char * error_string
Definition: lasunzipper.hpp:73
LASunzipper::~LASunzipper
~LASunzipper()
Definition: lasunzipper.cpp:135
BOOL
int BOOL
Definition: mydefs.hpp:57
ByteStreamInIstreamLE
Definition: bytestreamin_istream.hpp:66
ByteStreamInFileLE
Definition: bytestreamin_file.hpp:65
LASunzipper::read
bool read(unsigned char *const *point)
Definition: lasunzipper.cpp:89
bytestreamin_file.hpp
LASunzipper::close
bool close()
Definition: lasunzipper.cpp:95
LASreadPoint::init
BOOL init(ByteStreamIn *instream)
Definition: lasreadpoint.cpp:217
kfusion::cuda::error
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....
Definition: device_memory.cpp:7
LASunzipper::reader
LASreadPoint * reader
Definition: lasunzipper.hpp:71
LASunzipper::stream
ByteStreamIn * stream
Definition: lasunzipper.hpp:70
IS_LITTLE_ENDIAN
BOOL IS_LITTLE_ENDIAN()
Definition: mydefs.hpp:144
LASunzipper::tell
unsigned int tell() const
Definition: lasunzipper.cpp:84
ByteStreamInIstreamBE
Definition: bytestreamin_istream.hpp:86
ByteStreamInFileBE
Definition: bytestreamin_file.hpp:85
LASunzipper::return_error
bool return_error(const char *err)
Definition: lasunzipper.cpp:118


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 Wed Mar 2 2022 00:37:23