49 if (this->file) this->file =
file;
56 return open(out, header, compressor, requested_version, chunk_size);
63 fprintf(stderr,
"ERROR: file name pointer is zero\n");
67 file = fopen(file_name,
"wb");
70 fprintf(stderr,
"ERROR: cannot open file '%s'\n", file_name);
74 if (setvbuf(
file,
NULL, _IOFBF, io_buffer_size) != 0)
76 fprintf(stderr,
"WARNING: setvbuf() failed with buffer size %u\n", io_buffer_size);
85 return open(out, header, compressor, requested_version, chunk_size);
92 fprintf(stderr,
"ERROR: file pointer is zero\n");
99 if(_setmode( _fileno( stdout ), _O_BINARY ) == -1 )
101 fprintf(stderr,
"ERROR: cannot set stdout to binary (untranslated) mode\n");
112 return open(out, header, compressor, requested_version, chunk_size);
123 return open(out, header, compressor, requested_version, chunk_size);
132 fprintf(stderr,
"ERROR: ByteStreamOut pointer is zero\n");
139 fprintf(stderr,
"ERROR: LASheader pointer is zero\n");
158 U8 point_data_format;
159 U16 point_data_record_length;
164 point_is_standard = header->
laszip->
is_standard(&point_data_format, &point_data_record_length);
176 U32 laszip_vlr_data_size = 0;
177 if (compressor || point_is_standard ==
FALSE)
183 else if (requested_version) laszip->
request_version(requested_version);
185 laszip_vlr_data_size = 34 + 6*laszip->
num_items;
208 fprintf(stderr,
"ERROR: writing header->file_signature\n");
213 fprintf(stderr,
"ERROR: writing header->file_source_id\n");
218 fprintf(stderr,
"ERROR: writing header->global_encoding\n");
223 fprintf(stderr,
"ERROR: writing header->project_ID_GUID_data_1\n");
228 fprintf(stderr,
"ERROR: writing header->project_ID_GUID_data_2\n");
233 fprintf(stderr,
"ERROR: writing header->project_ID_GUID_data_3\n");
238 fprintf(stderr,
"ERROR: writing header->project_ID_GUID_data_4\n");
244 fprintf(stderr,
"WARNING: header->version_major is %d. writing 1 instead.\n", header->
version_major);
247 fprintf(stderr,
"ERROR: writing header->version_major\n");
255 fprintf(stderr,
"ERROR: writing header->version_major\n");
262 fprintf(stderr,
"WARNING: header->version_minor is %d. writing 4 instead.\n", header->
version_minor);
265 fprintf(stderr,
"ERROR: writing header->version_minor\n");
273 fprintf(stderr,
"ERROR: writing header->version_minor\n");
279 fprintf(stderr,
"ERROR: writing header->system_identifier\n");
284 fprintf(stderr,
"ERROR: writing header->generating_software\n");
289 fprintf(stderr,
"ERROR: writing header->file_creation_day\n");
294 fprintf(stderr,
"ERROR: writing header->file_creation_year\n");
299 fprintf(stderr,
"ERROR: writing header->header_size\n");
303 if (laszip) offset_to_point_data += (54 + laszip_vlr_data_size);
304 if (header->
vlr_lastiling) offset_to_point_data += (54 + 28);
307 fprintf(stderr,
"ERROR: writing header->offset_to_point_data\n");
311 if (laszip) number_of_variable_length_records++;
312 if (header->
vlr_lastiling) number_of_variable_length_records++;
313 if (!stream->
put32bitsLE((
U8*)&(number_of_variable_length_records)))
315 fprintf(stderr,
"ERROR: writing header->number_of_variable_length_records\n");
318 if (compressor) point_data_format |= 128;
319 if (!stream->
putByte(point_data_format))
321 fprintf(stderr,
"ERROR: writing header->point_data_format\n");
326 fprintf(stderr,
"ERROR: writing header->point_data_record_length\n");
331 fprintf(stderr,
"ERROR: writing header->number_of_point_records\n");
334 for (i = 0; i < 5; i++)
338 fprintf(stderr,
"ERROR: writing header->number_of_points_by_return[%d]\n", i);
344 fprintf(stderr,
"ERROR: writing header->x_scale_factor\n");
349 fprintf(stderr,
"ERROR: writing header->y_scale_factor\n");
354 fprintf(stderr,
"ERROR: writing header->z_scale_factor\n");
359 fprintf(stderr,
"ERROR: writing header->x_offset\n");
364 fprintf(stderr,
"ERROR: writing header->y_offset\n");
369 fprintf(stderr,
"ERROR: writing header->z_offset\n");
374 fprintf(stderr,
"ERROR: writing header->max_x\n");
379 fprintf(stderr,
"ERROR: writing header->min_x\n");
384 fprintf(stderr,
"ERROR: writing header->max_y\n");
389 fprintf(stderr,
"ERROR: writing header->min_y\n");
394 fprintf(stderr,
"ERROR: writing header->max_z\n");
399 fprintf(stderr,
"ERROR: writing header->min_z\n");
414 U64 start_of_waveform_data_packet_record = 0;
415 if (!stream->
put64bitsLE((
U8*)&start_of_waveform_data_packet_record))
417 fprintf(stderr,
"ERROR: writing start_of_waveform_data_packet_record\n");
425 fprintf(stderr,
"ERROR: writing header->start_of_waveform_data_packet_record\n");
436 fprintf(stderr,
"ERROR: writing header->start_of_first_extended_variable_length_record\n");
441 fprintf(stderr,
"ERROR: writing header->number_of_extended_variable_length_records\n");
451 fprintf(stderr,
"ERROR: writing header->extended_number_of_point_records\n");
454 for (i = 0; i < 15; i++)
462 fprintf(stderr,
"ERROR: writing header->extended_number_of_points_by_return[%d]\n", i);
476 fprintf(stderr,
"ERROR: writing %d bytes of data from header->user_data_in_header\n", header->
user_data_in_header_size);
482 fprintf(stderr,
"ERROR: there should be %d bytes of data in header->user_data_in_header\n", header->
user_data_in_header_size);
502 fprintf(stderr,
"ERROR: writing header->vlrs[%d].reserved\n", i);
507 fprintf(stderr,
"ERROR: writing header->vlrs[%d].user_id\n", i);
512 fprintf(stderr,
"ERROR: writing header->vlrs[%d].record_id\n", i);
517 fprintf(stderr,
"ERROR: writing header->vlrs[%d].record_length_after_header\n", i);
522 fprintf(stderr,
"ERROR: writing header->vlrs[%d].description\n", i);
552 U16 reserved = 0xAABB;
555 fprintf(stderr,
"ERROR: writing reserved %d\n", (
I32)reserved);
558 U8 user_id[16] =
"laszip encoded\0";
561 fprintf(stderr,
"ERROR: writing user_id %s\n", user_id);
564 U16 record_id = 22204;
567 fprintf(stderr,
"ERROR: writing record_id %d\n", (
I32)record_id);
570 U16 record_length_after_header = laszip_vlr_data_size;
571 if (!stream->
put16bitsLE((
U8*)&(record_length_after_header)))
573 fprintf(stderr,
"ERROR: writing record_length_after_header %d\n", (
I32)record_length_after_header);
576 char description[32];
577 memset(description, 0, 32);
581 fprintf(stderr,
"ERROR: writing description %s\n", description);
602 fprintf(stderr,
"ERROR: writing compressor %d\n", (
I32)compressor);
607 fprintf(stderr,
"ERROR: writing coder %d\n", (
I32)laszip->
coder);
612 fprintf(stderr,
"ERROR: writing version_major %d\n", laszip->
version_major);
617 fprintf(stderr,
"ERROR: writing version_minor %d\n", laszip->
version_minor);
622 fprintf(stderr,
"ERROR: writing version_revision %d\n", laszip->
version_revision);
627 fprintf(stderr,
"ERROR: writing options %d\n", (
I32)laszip->
options);
632 fprintf(stderr,
"ERROR: writing chunk_size %d\n", laszip->
chunk_size);
637 fprintf(stderr,
"ERROR: writing num_points %d\n", (
I32)laszip->
num_points);
642 fprintf(stderr,
"ERROR: writing num_bytes %d\n", (
I32)laszip->
num_bytes);
647 fprintf(stderr,
"ERROR: writing num_items %d\n", laszip->
num_items);
654 fprintf(stderr,
"ERROR: writing type %d of item %d\n", laszip->
items[i].
type, i);
659 fprintf(stderr,
"ERROR: writing size %d of item %d\n", laszip->
items[i].
size, i);
664 fprintf(stderr,
"ERROR: writing version %d of item %d\n", laszip->
items[i].
version, i);
676 U16 reserved = 0xAABB;
679 fprintf(stderr,
"ERROR: writing reserved %d\n", (
I32)reserved);
682 U8 user_id[16] =
"lastools tile\0\0";
685 fprintf(stderr,
"ERROR: writing user_id %s\n", user_id);
688 U16 record_id = 22204;
691 fprintf(stderr,
"ERROR: writing record_id %d\n", (
I32)record_id);
694 U16 record_length_after_header = 28;
695 if (!stream->
put16bitsLE((
U8*)&(record_length_after_header)))
697 fprintf(stderr,
"ERROR: writing record_length_after_header %d\n", (
I32)record_length_after_header);
700 U8 description[32] =
"LAStools tile for streaming TIN";
703 fprintf(stderr,
"ERROR: writing description %s\n", description);
719 fprintf(stderr,
"ERROR: writing header->vlr_lastiling->level %u\n", header->
vlr_lastiling->
level);
734 fprintf(stderr,
"ERROR: writing header->vlr_lastiling->min_x %g\n", header->
vlr_lastiling->
min_x);
739 fprintf(stderr,
"ERROR: writing header->vlr_lastiling->max_x %g\n", header->
vlr_lastiling->
max_x);
744 fprintf(stderr,
"ERROR: writing header->vlr_lastiling->min_y %g\n", header->
vlr_lastiling->
min_y);
749 fprintf(stderr,
"ERROR: writing header->vlr_lastiling->max_y %g\n", header->
vlr_lastiling->
max_y);
768 fprintf(stderr,
"ERROR: there should be %d bytes of data in header->user_data_after_header\n", header->
user_data_after_header_size);
799 fprintf(stderr,
"ERROR: header pointer is zero\n");
804 fprintf(stderr,
"ERROR: stream pointer is zero\n");
809 fprintf(stderr,
"ERROR: stream is not seekable\n");
817 fprintf(stderr,
"ERROR: updating header->number_of_point_records\n");
821 for (i = 0; i < 5; i++)
825 fprintf(stderr,
"ERROR: updating header->number_of_points_by_return[%d]\n", i);
834 fprintf(stderr,
"ERROR: updating header->max_x\n");
840 fprintf(stderr,
"ERROR: updating header->min_x\n");
846 fprintf(stderr,
"ERROR: updating header->max_y\n");
852 fprintf(stderr,
"ERROR: updating header->min_y\n");
858 fprintf(stderr,
"ERROR: updating header->max_z\n");
864 fprintf(stderr,
"ERROR: updating header->min_z\n");
873 fprintf(stderr,
"ERROR: updating header->number_of_point_records\n");
877 for (i = 0; i < 5; i++)
881 fprintf(stderr,
"ERROR: updating header->number_of_points_by_return[%d]\n", i);
888 fprintf(stderr,
"ERROR: updating header->max_x\n");
893 fprintf(stderr,
"ERROR: updating header->min_x\n");
898 fprintf(stderr,
"ERROR: updating header->max_y\n");
903 fprintf(stderr,
"ERROR: updating header->min_y\n");
908 fprintf(stderr,
"ERROR: updating header->max_z\n");
913 fprintf(stderr,
"ERROR: updating header->min_z\n");
917 if (update_extra_bytes)
953 fprintf(stderr,
"WARNING: written %I64d points but expected %I64d points\n",
p_count,
npoints);
955 fprintf(stderr,
"WARNING: written %lld points but expected %lld points\n",
p_count,
npoints);
973 fprintf(stderr,
"ERROR: stream not seekable. cannot update header from %I64d to %I64d points.\n",
npoints,
p_count);
975 fprintf(stderr,
"ERROR: stream not seekable. cannot update header from %lld to %lld points.\n",
npoints,
p_count);
BOOL write_point(const LASpoint *point)
virtual BOOL putBytes(const U8 *bytes, U32 num_bytes)=0
BOOL update_header(const LASheader *header, BOOL use_inventory=TRUE, BOOL update_extra_bytes=FALSE)
unsigned char version_minor
U16 record_length_after_header
virtual BOOL seek(const I64 position)=0
bool set_chunk_size(const unsigned int chunk_size)
bool setup(unsigned short *num_items, LASitem **items, const unsigned char point_type, const unsigned short point_size, const unsigned short compressor=LASZIP_COMPRESSOR_NONE)
virtual I64 tell() const =0
unsigned short compressor
BOOL init(const LASquantizer *quantizer, const U8 point_type, const U16 point_size, const LASattributer *attributer=0)
U32 number_of_point_records
BOOL open(const LASheader *header, U32 compressor=LASZIP_COMPRESSOR_NONE, I32 requested_version=0, I32 chunk_size=50000)
BOOL init(ByteStreamOut *outstream)
virtual BOOL put16bitsLE(const U8 *bytes)=0
I64 header_start_position
bool is_standard(const unsigned short num_items, const LASitem *items, unsigned char *point_type=0, unsigned short *record_length=0)
virtual BOOL putByte(U8 byte)=0
virtual BOOL put64bitsLE(const U8 *bytes)=0
#define LASZIP_COMPRESSOR_NONE
unsigned short version_revision
U32 number_of_points_by_return[8]
F64 get_y(const I32 y) const
virtual BOOL isSeekable() const =0
I32 number_extra_attributes
BOOL setup(const U32 num_items, const LASitem *items, const LASzip *laszip=0)
F64 get_z(const I32 z) const
virtual BOOL put32bitsLE(const U8 *bytes)=0
#define LAS_TOOLS_VERSION
bool request_version(const unsigned short requested_version)
F64 get_x(const I32 x) const
I64 close(BOOL update_npoints=true)
BOOL write(const U8 *const *point)
LASattribute * extra_attributes
unsigned char version_major