/
XMLSchema.cpp
799 lines (619 loc) · 24.7 KB
/
XMLSchema.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
/******************************************************************************
* Copyright (c) 2011, Howard Butler, hobu.inc@gmail.com *
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following
* conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
****************************************************************************/
#include <pdal/XMLSchema.hpp>
#include <sstream>
#include <iostream>
#include <list>
#include <cstdlib>
#include <map>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
struct XMLDocDeleter
{
template <typename T>
void operator()(T* ptr)
{
::xmlFreeDoc(ptr);
}
};
struct SchemaParserCtxDeleter
{
template <typename T>
void operator()(T* ptr)
{
::xmlSchemaFreeParserCtxt(ptr);
}
};
struct SchemaDeleter
{
template <typename T>
void operator()(T* ptr)
{
::xmlSchemaFree(ptr);
}
};
struct SchemaValidCtxtDeleter
{
template <typename T>
void operator()(T* ptr)
{
::xmlSchemaFreeValidCtxt(ptr);
}
};
struct WriterDeleter
{
template <typename T>
void operator()(T* ptr)
{
::xmlFreeTextWriter(ptr);
}
};
struct BufferDeleter
{
template <typename T>
void operator()(T* ptr)
{
::xmlBufferFree(ptr);
}
};
struct xmlCharDeleter
{
template <typename T>
void operator()(T* ptr)
{
::xmlFree(ptr);
}
};
static bool sort_dimensions(pdal::DimensionLayout const& a, pdal::DimensionLayout const& b)
{
return a < b;
}
namespace pdal { namespace schema {
void OCISchemaStructuredErrorHandler
(void * userData, xmlErrorPtr error)
{
boost::ignore_unused_variable_warning(userData);
std::ostringstream oss;
oss << "XML error: '" << error->message <<"' ";
if (error->str1)
oss << " extra info1: '" << error->str1 << "' ";
if (error->str2)
oss << " extra info2: '" << error->str2 << "' ";
if (error->str3)
oss << " extra info3: '" << error->str3 << "' ";
oss << "on line " << error->line;
if (error->ctxt)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) error->ctxt;
xmlParserInputPtr input = ctxt->input;
xmlParserPrintFileContext(input);
}
throw schema_error(oss.str());
}
void OCISchemaParserStructuredErrorHandler
(void * userData, xmlErrorPtr error)
{
boost::ignore_unused_variable_warning(userData);
std::ostringstream oss;
oss << "Schema parsing error: '" << error->message <<"' ";
oss << "on line " << error->line;
throw schema_parsing_error(oss.str());
}
void OCISchemaValidationStructuredErrorHandler
(void * userData, xmlErrorPtr error)
{
boost::ignore_unused_variable_warning(userData);
std::ostringstream oss;
oss << "Schema validation error: '" << error->message <<"' ";
oss << "on line " << error->line;
throw schema_validation_error(oss.str());
}
void OCISchemaValidityError
(void * ctx, const char* message, ... )
{
boost::ignore_unused_variable_warning(ctx);
const int ERROR_MESSAGE_SIZE = 256;
char error[ERROR_MESSAGE_SIZE];
va_list arg_ptr;
va_start(arg_ptr, message);
vsnprintf(error, ERROR_MESSAGE_SIZE, message, arg_ptr);
va_end(arg_ptr);
std::ostringstream oss;
oss << "Schema valididy error: '" << error <<"' ";
throw schema_validation_error(oss.str());
}
void OCISchemaValidityDebug
(void * ctx, const char* message, ... )
{
boost::ignore_unused_variable_warning(ctx);
const int ERROR_MESSAGE_SIZE = 256;
char error[ERROR_MESSAGE_SIZE];
va_list arg_ptr;
va_start(arg_ptr, message);
vsnprintf(error, ERROR_MESSAGE_SIZE, message, arg_ptr);
va_end(arg_ptr);
std::ostringstream oss;
oss << "Schema validity debug: '" << error <<"' ";
std::cout << oss.str() << std::endl;
}
void OCISchemaGenericErrorHandler
(void * ctx, const char* message, ... )
{
boost::ignore_unused_variable_warning(ctx);
const int ERROR_MESSAGE_SIZE = 256;
char error[ERROR_MESSAGE_SIZE];
va_list arg_ptr;
va_start(arg_ptr, message);
vsnprintf(error, ERROR_MESSAGE_SIZE, message, arg_ptr);
va_end(arg_ptr);
std::ostringstream oss;
oss << "Generic error: '" << error <<"' ";
throw schema_generic_error(oss.str());
}
// XML_PARSE_NONET No network access
// http://xmlsoft.org/html/libxml-parser.html#xmlParserOption
void Reader::Initialize()
{
if (m_xml.size() == 0) throw schema_generic_error("Inputted XML has no size, is there data there?");
// if (m_xsd.size() == 0) throw schema_generic_error("Inputted XSD has no size, is there data there?");
LIBXML_TEST_VERSION
xmlSetGenericErrorFunc(m_global_context, (xmlGenericErrorFunc) &OCISchemaGenericErrorHandler);
xmlSetStructuredErrorFunc(m_global_context, (xmlStructuredErrorFunc) & OCISchemaStructuredErrorHandler);
m_doc = DocPtr(
xmlReadMemory(m_xml.c_str(), m_xml.size(), NULL, NULL, m_doc_options),
XMLDocDeleter());
if (m_xsd.size())
{
m_schema_doc = DocPtr(
xmlReadMemory(m_xsd.c_str(), m_xsd.size(), NULL, NULL, m_doc_options),
XMLDocDeleter());
m_schema_parser_ctx = SchemaParserCtxtPtr(
xmlSchemaNewDocParserCtxt(static_cast<xmlDocPtr>(m_schema_doc.get())),
SchemaParserCtxDeleter());
xmlSchemaSetParserStructuredErrors(static_cast<xmlSchemaParserCtxtPtr>(m_schema_parser_ctx.get()),
&OCISchemaParserStructuredErrorHandler,
m_global_context);
m_schema_ptr = SchemaPtr(
xmlSchemaParse(static_cast<xmlSchemaParserCtxtPtr>(m_schema_parser_ctx.get())),
SchemaDeleter());
m_schema_valid_ctx = SchemaValidCtxtPtr(
xmlSchemaNewValidCtxt(static_cast<xmlSchemaPtr>(m_schema_ptr.get())),
SchemaValidCtxtDeleter());
xmlSchemaSetValidErrors(static_cast<xmlSchemaValidCtxtPtr>(m_schema_valid_ctx.get()),
&OCISchemaValidityError,
&OCISchemaValidityDebug,
m_global_context);
int valid_schema = xmlSchemaValidateDoc(static_cast<xmlSchemaValidCtxtPtr>(m_schema_valid_ctx.get()),
static_cast<xmlDocPtr>(m_doc.get()));
if (valid_schema != 0)
throw schema_error("Document did not validate against schema!");
}
}
Reader::Reader(std::string const& xml, std::string const &xsd)
: m_doc_options(XML_PARSE_NONET)
, m_field_position(512)
{
m_xml = xml;
m_xsd = xsd;
Initialize();
Load();
return;
}
Reader::Reader(std::istream* xml, std::istream *xsd) : m_doc_options(XML_PARSE_NONET)
{
if (!xml)
throw schema_generic_error("pdal::schema::Reader: xml istream pointer was null!");
std::istream::pos_type size;
std::vector<char> data;
xml->seekg(0, std::ios::end);
size = xml->tellg();
data.resize(static_cast<std::vector<char>::size_type>(size));
xml->seekg (0, std::ios::beg);
xml->read (&data.front(), size);
xml->seekg (0, std::ios::beg);
m_xml = std::string(&data[0], data.size());
if (xsd)
{
std::istream::pos_type size;
std::vector<char> data;
xsd->seekg(0, std::ios::end);
size = xsd->tellg();
data.resize(static_cast<std::vector<char>::size_type>(size));
xsd->seekg (0, std::ios::beg);
xsd->read (&data.front(), size);
xsd->seekg(0, std::ios::end);
m_xsd = std::string(&data[0], data.size());
}
Initialize();
Load();
}
Reader::~Reader()
{
}
static void
print_element_names(xmlNode * a_node)
{
xmlNode *cur_node = NULL;
for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
if (cur_node->type == XML_ELEMENT_NODE) {
printf("node type: Element, name: %s\n", cur_node->name);
}
print_element_names(cur_node->children);
}
}
void Reader::Load()
{
std::vector<pdal::DimensionLayout> layouts;
xmlDocPtr doc = static_cast<xmlDocPtr>(m_doc.get());
xmlNode* root = xmlDocGetRootElement(doc);
// print_element_names(root);
if (Utils::compare_no_case((const char*)root->name, "PointCloudSchema"))
throw schema_loading_error("First node of document was not named 'PointCloudSchema'");
xmlNode* dimension = root->children;
while(dimension != NULL)
{
// printf("node name: %s\n", (const char*)dimension->name);
if (dimension->type != XML_ELEMENT_NODE || Utils::compare_no_case((const char*)dimension->name, "dimension"))
{
dimension = dimension->next;
continue;
}
xmlNode* properties = dimension->children;
std::string name;
boost::uint32_t size(0);
boost::uint32_t position(1);
std::string description;
std::string interpretation;
double offset(0.0);
double scale(0.0);
double minimum(0.0);
double maximum(0.0);
EndianType endianness = Endian_Little;
while(properties != NULL)
{
if (properties->type != XML_ELEMENT_NODE)
{
properties = properties->next;
continue;
}
if (!Utils::compare_no_case((const char*)properties->name, "name"))
{
CharPtr n = CharPtr(
xmlNodeListGetString(doc, properties->children, 1),
xmlCharDeleter());
// xmlChar* n = xmlNodeListGetString(doc, properties->children, 1);
if (!n) throw schema_loading_error("Unable to fetch name!");
name = std::string((const char*)n.get());
// xmlFree(n);
// std::cout << "Dimension name: " << name << std::endl;
}
if (!Utils::compare_no_case((const char*)properties->name, "size"))
{
xmlChar* n = xmlNodeListGetString(doc, properties->children, 1);
if (!n) throw schema_loading_error("Unable to fetch size!");
int s = std::atoi((const char*)n);
if (s < 1)
{
throw schema_loading_error("Dimension size is < 1!");
}
xmlFree(n);
size = static_cast<boost::uint32_t>(s);
// std::cout << "Dimension size: " << size << std::endl;
}
if (!Utils::compare_no_case((const char*)properties->name, "position"))
{
xmlChar* n = xmlNodeListGetString(doc, properties->children, 1);
if (!n) throw schema_loading_error("Unable to fetch position!");
int p = std::atoi((const char*)n);
if (p < 1)
{
throw schema_loading_error("Dimension position is < 1!");
}
xmlFree(n);
position = static_cast<boost::uint32_t>(p);
// std::cout << "Dimension position: " << position << std::endl;
}
if (!Utils::compare_no_case((const char*)properties->name, "description"))
{
xmlChar* n = xmlNodeListGetString(doc, properties->children, 1);
if (!n) throw schema_loading_error("Unable to fetch description!");
description = std::string((const char*)n);
xmlFree(n);
}
if (!Utils::compare_no_case((const char*)properties->name, "interpretation"))
{
xmlChar* n = xmlNodeListGetString(doc, properties->children, 1);
if (!n) throw schema_loading_error("Unable to fetch interpretation!");
interpretation = std::string((const char*)n);
xmlFree(n);
}
if (!Utils::compare_no_case((const char*)properties->name, "minimum"))
{
xmlChar* n = xmlGetProp(properties, (const xmlChar*) "value");
if (!n) throw schema_loading_error("Unable to fetch minimum value!");
minimum = std::atof((const char*)n);
xmlFree(n);
// std::cout << "Dimension minimum: " << minimum << std::endl;
}
if (!Utils::compare_no_case((const char*)properties->name, "maximum"))
{
xmlChar* n = xmlGetProp(properties, (const xmlChar*) "value");
if (!n) throw schema_loading_error("Unable to fetch maximum value!");
maximum = std::atof((const char*)n);
xmlFree(n);
// std::cout << "Dimension maximum: " << maximum << std::endl;
}
if (!Utils::compare_no_case((const char*)properties->name, "offset"))
{
xmlChar* n = xmlNodeListGetString(doc, properties->children, 1);
if (!n) throw schema_loading_error("Unable to fetch offset value!");
offset = std::atof((const char*)n);
xmlFree(n);
// std::cout << "Dimension offset: " << offset << std::endl;
}
if (!Utils::compare_no_case((const char*)properties->name, "scale"))
{
xmlChar* n = xmlNodeListGetString(doc, properties->children, 1);
if (!n) throw schema_loading_error("Unable to fetch scale value!");
scale = std::atof((const char*)n);
xmlFree(n);
// std::cout << "Dimension scale: " << scale << std::endl;
}
if (!Utils::compare_no_case((const char*)properties->name, "endianness"))
{
xmlChar* n = xmlNodeListGetString(doc, properties->children, 1);
if (!n) throw schema_loading_error("Unable to fetch endianness value!");
if (!Utils::compare_no_case((const char*) n, "big"))
endianness = Endian_Big;
else
endianness = Endian_Little;
xmlFree(n);
// std::cout << "Dimension endianness: " << endianness << std::endl;
}
// printf("property name: %s\n", properties->name);
properties = properties->next;
}
DimensionId::Id f = DimensionId::getIdFromName(name);
Dimension d(f);
if (! Utils::compare_distance(scale, 0.0))
{
d.setNumericScale(scale);
}
if (! Utils::compare_distance(offset, 0.0))
{
d.setNumericOffset(offset);
}
if (! Utils::compare_distance(minimum, 0.0))
{
d.setMinimum(minimum);
}
if (! Utils::compare_distance(maximum, 0.0))
{
d.setMaximum(maximum);
}
if (description.size())
{
d.setDescription(description);
}
d.setEndianness(endianness);
DimensionLayout l(d);
l.setPosition(position);
layouts.push_back(l);
dimension = dimension->next;
}
std::sort(layouts.begin(), layouts.end(), sort_dimensions);
std::vector<DimensionLayout>::const_iterator i;
for (i = layouts.begin(); i!= layouts.end(); ++i)
{
m_schema.appendDimension(i->getDimension());
}
}
Dimension::DataType Reader::GetDimensionType(std::string const& interpretation)
{
if (!Utils::compare_no_case(interpretation, "int8_t") ||
!Utils::compare_no_case(interpretation, "int8"))
return Dimension::Int8;
if (!Utils::compare_no_case(interpretation, "uint8_t") ||
!Utils::compare_no_case(interpretation, "uint8"))
return Dimension::Uint8;
if (!Utils::compare_no_case(interpretation, "int16_t") ||
!Utils::compare_no_case(interpretation, "int16"))
return Dimension::Int16;
if (!Utils::compare_no_case(interpretation, "uint16_t") ||
!Utils::compare_no_case(interpretation, "uint16"))
return Dimension::Uint16;
if (!Utils::compare_no_case(interpretation, "int32_t") ||
!Utils::compare_no_case(interpretation, "int32"))
return Dimension::Int32;
if (!Utils::compare_no_case(interpretation, "uint32_t") ||
!Utils::compare_no_case(interpretation, "uint32"))
return Dimension::Uint32;
if (!Utils::compare_no_case(interpretation, "int64_t") ||
!Utils::compare_no_case(interpretation, "int64"))
return Dimension::Int64;
if (!Utils::compare_no_case(interpretation, "uint64_t") ||
!Utils::compare_no_case(interpretation, "uint64"))
return Dimension::Uint64;
if (!Utils::compare_no_case(interpretation, "float"))
return Dimension::Float;
if (!Utils::compare_no_case(interpretation, "double"))
return Dimension::Double;
return Dimension::Undefined;
}
Writer::Writer(pdal::Schema const& schema)
: m_schema(schema) {}
std::string Writer::getXML()
{
BufferPtr buffer = BufferPtr(xmlBufferCreate(), BufferDeleter());
xmlBufferPtr b = static_cast<xmlBuffer*>(buffer.get());
TextWriterPtr writer = TextWriterPtr(xmlNewTextWriterMemory(b, 0), WriterDeleter());
write(writer);
xmlTextWriterPtr w = static_cast<xmlTextWriterPtr>(writer.get());
xmlTextWriterFlush(w);
// printf("xml: %s", (const char *) b->content);
return std::string((const char *) b->content, b->size);
}
void Writer::write(TextWriterPtr writer)
{
xmlTextWriterPtr w = static_cast<xmlTextWriterPtr>(writer.get());
xmlTextWriterSetIndent(w, 1);
xmlTextWriterStartDocument(w, NULL, "utf-8", NULL);
xmlTextWriterStartElementNS(w, BAD_CAST "pc", BAD_CAST "PointCloudSchema", NULL);
xmlTextWriterWriteAttributeNS(w, BAD_CAST "xmlns", BAD_CAST "pc", NULL, BAD_CAST "http://pointcloud.org/schemas/PC/1.0");
xmlTextWriterWriteAttributeNS(w, BAD_CAST "xmlns", BAD_CAST "xsi", NULL, BAD_CAST "http://www.w3.org/2001/XMLSchema-instance");
writeSchema(writer);
xmlTextWriterEndElement(w);
xmlTextWriterEndDocument(w);
}
boost::uint32_t GetStreamPrecision(double scale)
{
double frac = 0;
double integer = 0;
frac = std::modf(scale, &integer);
double precision = std::fabs(std::floor(std::log10(frac)));
boost::uint32_t output = static_cast<boost::uint32_t>(precision);
return output;
}
void Writer::writeSchema(TextWriterPtr writer)
{
xmlTextWriterPtr w = static_cast<xmlTextWriterPtr>(writer.get());
const std::vector<Dimension>& dims = m_schema.getDimensions();
for (boost::uint32_t i = 0; i < dims.size(); i++)
{
Dimension const& dim = dims[i];
xmlTextWriterStartElementNS(w, BAD_CAST "pc", BAD_CAST "dimension", NULL);
std::ostringstream position;
position << i+1;
xmlTextWriterWriteElementNS(w, BAD_CAST "pc", BAD_CAST "position", NULL, BAD_CAST position.str().c_str());
std::ostringstream size;
size << dim.getByteSize();
xmlTextWriterWriteElementNS(w, BAD_CAST "pc", BAD_CAST "size", NULL, BAD_CAST size.str().c_str());
std::ostringstream description;
description << dim.getDescription();
if (description.str().size())
xmlTextWriterWriteElementNS(w, BAD_CAST "pc", BAD_CAST "description", NULL, BAD_CAST description.str().c_str());
std::ostringstream name;
name << dim.getName();
if (name.str().size())
xmlTextWriterWriteElementNS(w, BAD_CAST "pc", BAD_CAST "name", NULL, BAD_CAST name.str().c_str());
std::ostringstream type;
pdal::Dimension::DataType t = dim.getDataType();
switch (t)
{
case pdal::Dimension::Int8:
type << "int8_t";
break;
case pdal::Dimension::Uint8:
type << "uint8_t";
break;
case pdal::Dimension::Int16:
type << "int16_t";
break;
case pdal::Dimension::Uint16:
type << "uint16_t";
break;
case pdal::Dimension::Int32:
type << "int32_t";
break;
case pdal::Dimension::Uint32:
type << "uint32_t";
break;
case pdal::Dimension::Int64:
type << "int64_t";
break;
case pdal::Dimension::Uint64:
type << "uint64_t";
break;
case pdal::Dimension::Float:
type << "float";
break;
case pdal::Dimension::Double:
type << "double";
break;
case pdal::Dimension::Pointer:
type << "pointer";
break;
case pdal::Dimension::Undefined:
type << "unknown";
break;
}
xmlTextWriterWriteElementNS(w, BAD_CAST "pc", BAD_CAST "interpretation", NULL, BAD_CAST type.str().c_str());
double minimum = dim.getMinimum();
if (!Utils::compare_distance<double>(minimum, 0.0))
{
std::ostringstream mn;
mn.setf(std::ios_base::fixed, std::ios_base::floatfield);
mn.precision(12);
mn << minimum;
xmlTextWriterStartElementNS(w, BAD_CAST "pc", BAD_CAST "minimum", NULL);
xmlTextWriterWriteAttributeNS(w, BAD_CAST "pc", BAD_CAST "units", NULL, BAD_CAST "double");
xmlTextWriterWriteAttributeNS(w, BAD_CAST "pc", BAD_CAST "value", NULL, BAD_CAST mn.str().c_str());
xmlTextWriterEndElement(w);
}
double maximum = dim.getMaximum();
if (!Utils::compare_distance<double>(minimum, 0.0))
{
std::ostringstream mn;
mn.setf(std::ios_base::fixed, std::ios_base::floatfield);
mn.precision(12);
mn << maximum;
xmlTextWriterStartElementNS(w, BAD_CAST "pc", BAD_CAST "maximum", NULL);
xmlTextWriterWriteAttributeNS(w, BAD_CAST "pc", BAD_CAST "units", NULL, BAD_CAST "double");
xmlTextWriterWriteAttributeNS(w, BAD_CAST "pc", BAD_CAST "value", NULL, BAD_CAST mn.str().c_str());
xmlTextWriterEndElement(w);
}
double scale = dim.getNumericScale();
if (!Utils::compare_distance<double>(scale, 0.0))
{
std::ostringstream out;
out.setf(std::ios_base::fixed, std::ios_base::floatfield);
out.precision(GetStreamPrecision(scale));
out << scale;
xmlTextWriterWriteElementNS(w, BAD_CAST "pc", BAD_CAST "scale", NULL, BAD_CAST out.str().c_str());
}
double offset = dim.getNumericOffset();
if (!Utils::compare_distance<double>(offset, 0.0))
{
std::ostringstream out;
out.setf(std::ios_base::fixed, std::ios_base::floatfield);
out.precision(12);
out << offset;
xmlTextWriterWriteElementNS(w, BAD_CAST "pc", BAD_CAST "offset", NULL, BAD_CAST out.str().c_str());
}
xmlTextWriterWriteElementNS(w, BAD_CAST "pc", BAD_CAST "active", NULL, BAD_CAST "true");
xmlTextWriterEndElement(w);
xmlTextWriterFlush(w);
}
}
} } // namespaces