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 }
LASzip::num_items
unsigned short num_items
Definition: laszip.hpp:120
LASzipper::error_string
char * error_string
Definition: laszipper.hpp:73
LASzipper::return_error
bool return_error(const char *err)
Definition: laszipper.cpp:112
LASzipper::chunk
bool chunk()
Definition: laszipper.cpp:83
laswritepoint.hpp
LASzip
Definition: laszip.hpp:80
LASwritePoint::write
BOOL write(const U8 *const *point)
Definition: laswritepoint.cpp:243
LASzipper::open
bool open(FILE *outfile, const LASzip *laszip)
Definition: laszipper.cpp:40
TRUE
#define TRUE
Definition: mydefs.hpp:137
LASzip::items
LASitem * items
Definition: laszip.hpp:121
LASZIP_VERSION_REVISION
#define LASZIP_VERSION_REVISION
Definition: laszip.hpp:51
LASwritePoint::chunk
BOOL chunk()
Definition: laswritepoint.cpp:276
LASzipper::count
unsigned int count
Definition: laszipper.hpp:69
LASZIP_VERSION_MINOR
#define LASZIP_VERSION_MINOR
Definition: laszip.hpp:50
bytestreamout_ostream.hpp
LASzipper::stream
ByteStreamOut * stream
Definition: laszipper.hpp:70
ByteStreamOutOstreamLE
Definition: bytestreamout_ostream.hpp:66
LASZIP_VERSION_MAJOR
#define LASZIP_VERSION_MAJOR
Definition: laszip.hpp:49
laszipper.hpp
ByteStreamOutOstreamBE
Definition: bytestreamout_ostream.hpp:86
BOOL
int BOOL
Definition: mydefs.hpp:57
bytestreamout_file.hpp
LASzipper::writer
LASwritePoint * writer
Definition: laszipper.hpp:71
LASwritePoint
Definition: laswritepoint.hpp:48
ByteStreamOutFileBE
Definition: bytestreamout_file.hpp:87
LASwritePoint::done
BOOL done()
Definition: laswritepoint.cpp:289
LASzipper::~LASzipper
~LASzipper()
Definition: laszipper.cpp:129
LASwritePoint::setup
BOOL setup(const U32 num_items, const LASitem *items, const LASzip *laszip=0)
Definition: laswritepoint.cpp:61
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
IS_LITTLE_ENDIAN
BOOL IS_LITTLE_ENDIAN()
Definition: mydefs.hpp:144
LASzipper::write
bool write(const unsigned char *const *point)
Definition: laszipper.cpp:77
LASzipper::close
bool close()
Definition: laszipper.cpp:89
LASwritePoint::init
BOOL init(ByteStreamOut *outstream)
Definition: laswritepoint.cpp:204
LASzipper::LASzipper
LASzipper()
Definition: laszipper.cpp:121
LASzipper::get_error
const char * get_error() const
Definition: laszipper.cpp:107
ByteStreamOutFileLE
Definition: bytestreamout_file.hpp:67


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:24