laszipper.cpp
Go to the documentation of this file.
1 /*
2 ===============================================================================
3 
4  FILE: laszipper.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 "laszipper.hpp"
32 
33 #include <string.h>
34 #include <stdlib.h>
35 
36 #include "bytestreamout_file.hpp"
38 #include "laswritepoint.hpp"
39 
40 bool LASzipper::open(FILE* outfile, const LASzip* laszip)
41 {
42  if (!outfile) return return_error("FILE* outfile pointer is NULL");
43  if (!laszip) return return_error("const LASzip* laszip pointer is NULL");
44  count = 0;
45  if (writer) delete writer;
46  writer = new LASwritePoint();
47  if (!writer) return return_error("alloc of LASwritePoint failed");
48  if (!writer->setup(laszip->num_items, laszip->items, laszip)) return return_error("setup() of LASwritePoint failed");
49  if (stream) delete stream;
50  if (IS_LITTLE_ENDIAN())
51  stream = new ByteStreamOutFileLE(outfile);
52  else
53  stream = new ByteStreamOutFileBE(outfile);
54  if (!stream) return return_error("alloc of ByteStreamOutFile failed");
55  if (!writer->init(stream)) return return_error("init() of LASwritePoint failed");
56  return true;
57 }
58 
59 bool LASzipper::open(ostream& outstream, const LASzip* laszip)
60 {
61  if (!laszip) return return_error("const LASzip* laszip pointer is NULL");
62  count = 0;
63  if (writer) delete writer;
64  writer = new LASwritePoint();
65  if (!writer) return return_error("alloc of LASwritePoint failed");
66  if (!writer->setup(laszip->num_items, laszip->items, laszip)) return return_error("setup() of LASwritePoint failed");
67  if (stream) delete stream;
68  if (IS_LITTLE_ENDIAN())
69  stream = new ByteStreamOutOstreamLE(outstream);
70  else
71  stream = new ByteStreamOutOstreamBE(outstream);
72  if (!stream) return return_error("alloc of ByteStreamOutStream failed");
73  if (!writer->init(stream)) return return_error("init() of LASwritePoint failed");
74  return true;
75 }
76 
77 bool LASzipper::write(const unsigned char * const * point)
78 {
79  count++;
80  return (writer->write(point) == TRUE);
81 }
82 
84 {
85  if (!writer->chunk()) return return_error("chunk() of LASwritePoint failed");
86  return true;
87 }
88 
90 {
91  BOOL done = TRUE;
92  if (writer)
93  {
94  done = writer->done();
95  delete writer;
96  writer = 0;
97  }
98  if (stream)
99  {
100  delete stream;
101  stream = 0;
102  }
103  if (!done) return return_error("done() of LASwritePoint failed");
104  return true;
105 }
106 
107 const char* LASzipper::get_error() const
108 {
109  return error_string;
110 }
111 
113 {
114  char err[256];
115  sprintf(err, "%s (LASzip v%d.%dr%d)", error, LASZIP_VERSION_MAJOR, LASZIP_VERSION_MINOR, LASZIP_VERSION_REVISION);
116  if (error_string) free(error_string);
117  error_string = strdup(err);
118  return false;
119 }
120 
122 {
123  error_string = 0;
124  count = 0;
125  stream = 0;
126  writer = 0;
127 }
128 
130 {
131  if (error_string) free(error_string);
132  if (writer || stream) close();
133 }
BOOL IS_LITTLE_ENDIAN()
Definition: mydefs.hpp:144
int BOOL
Definition: mydefs.hpp:57
char * error_string
Definition: laszipper.hpp:73
bool write(const unsigned char *const *point)
Definition: laszipper.cpp:77
LASwritePoint * writer
Definition: laszipper.hpp:71
const char * get_error() const
Definition: laszipper.cpp:107
BOOL init(ByteStreamOut *outstream)
#define LASZIP_VERSION_MINOR
Definition: laszip.hpp:50
bool open(FILE *outfile, const LASzip *laszip)
Definition: laszipper.cpp:40
bool return_error(const char *err)
Definition: laszipper.cpp:112
bool chunk()
Definition: laszipper.cpp:83
bool close()
Definition: laszipper.cpp:89
ByteStreamOut * stream
Definition: laszipper.hpp:70
BOOL setup(const U32 num_items, const LASitem *items, const LASzip *laszip=0)
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
LASitem * items
Definition: laszip.hpp:121
#define LASZIP_VERSION_REVISION
Definition: laszip.hpp:51
unsigned short num_items
Definition: laszip.hpp:120
#define TRUE
Definition: mydefs.hpp:137
unsigned int count
Definition: laszipper.hpp:69
BOOL write(const U8 *const *point)


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