-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathE57SimpleImpl.cpp
More file actions
2752 lines (2442 loc) · 115 KB
/
Copy pathE57SimpleImpl.cpp
File metadata and controls
2752 lines (2442 loc) · 115 KB
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
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////////////////////////////////////////////////////////////////////////
//
// E57SimpleImpl.cpp - private implementation header of E57 format reference implementation.
//
// Copyright (c) 2010 Stan Coleby (scoleby@intelisum.com)
// All rights reserved.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// The Boost license Vestion 1.0 - August 17th, 2003 is discussed in
// http://www.boost.org/users/license.html.
//
// This source code is only intended as a supplement to promote the
// ASTM E57.04 3D Imaging System File Format standard for interoperability
// of Lidar Data. See http://www.libe57.org.
//
//////////////////////////////////////////////////////////////////////////
//
// New E57SimpleImpl.cpp
// V1 May 18, 2010 Stan Coleby scoleby@intelisum.com
// V6 June 8, 2010 Stan Coleby scoleby@intelisum.com
//
//////////////////////////////////////////////////////////////////////////
//! @file E57SimpleImpl.cpp
#if defined(WIN32)
# if defined(_MSC_VER)
# include <io.h>
# include <fcntl.h>
# include <sys\stat.h>
# include <windows.h>
//#include <stdint.h> //if you need this then remove <boost/cstdint.hpp> in E57Foundation.h line 48
# elif defined(__GNUC__)
# define _LARGEFILE64_SOURCE
# define __LARGE64_FILES
# include <sys/types.h>
# include <unistd.h>
# include <boost/uuid/uuid.hpp>
# include <boost/uuid/uuid_generators.hpp>
# include <boost/uuid/uuid_io.hpp>
# include <fcntl.h>
# include <sys\stat.h>
# else
# error "no supported compiler defined"
# endif
#elif defined(LINUX)
# define _LARGEFILE64_SOURCE
# define __LARGE64_FILES
# include <sys/types.h>
# include <unistd.h>
# include <boost/uuid/uuid.hpp>
# include <boost/uuid/uuid_generators.hpp>
# include <boost/uuid/uuid_io.hpp>
#elif defined(__APPLE__)
# define _LARGEFILE64_SOURCE
# define __LARGE64_FILES
# include <sys/types.h>
# include <sys/stat.h>
# include <unistd.h>
# include <fcntl.h>
# include <boost/uuid/uuid.hpp>
# include <boost/uuid/uuid_generators.hpp>
# include <boost/uuid/uuid_io.hpp>
#else
# error "no supported OS platform defined"
#endif
#include <sstream>
#include "E57SimpleImpl.h"
#include "time_conversion.h"
using namespace e57;
using namespace std;
//using namespace boost;
namespace e57 {
char * GetNewGuid(void);
double GetGPSTime(void);
double GetGPSDateTimeFromUTC(
int utc_year, //!< The year 1900-9999
int utc_month, //!< The month 1-12
int utc_day, //!< The day 1-31
int utc_hour, //!< The hour 0-23
int utc_minute, //!< The minute 0-59
float utc_seconds //!< The seconds 0.0 - 59.999
);
void GetUTCFromGPSDateTime(
double gpsTime, //!< GPS Date Time
int &utc_year, //!< The year 1900-9999
int &utc_month, //!< The month 1-12
int &utc_day, //!< The day 1-31
int &utc_hour, //!< The hour 0-23
int &utc_minute, //!< The minute 0-59
float &utc_seconds //!< The seconds 0.0 - 59.999
);
#if defined(WIN32)
double GetGPSDateTimeFromSystemTime(
SYSTEMTIME sysTim //!< Windows System Time
);
void GetSystemTimeFromGPSDateTime(
double gpsTime, //!< GPS Date Time
SYSTEMTIME &sysTim //!< Windows System Time
);
#endif
};
////////////////////////////////////////////////////////////////////
//
// e57::GetGPSTime
//
double e57::GetGPSTime(void)
{
#ifdef _C_TIMECONV_H_
unsigned short utc_year; //!< Universal Time Coordinated [year]
unsigned char utc_month; //!< Universal Time Coordinated [1-12 months]
unsigned char utc_day; //!< Universal Time Coordinated [1-31 days]
unsigned char utc_hour; //!< Universal Time Coordinated [hours]
unsigned char utc_minute; //!< Universal Time Coordinated [minutes]
float utc_seconds; //!< Universal Time Coordinated [s]
unsigned char utc_offset; //!< Integer seconds that GPS is ahead of UTC time, always positive [s], obtained from a look up table
double julian_date; //!< Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
unsigned short gps_week; //!< GPS week (0-1024+) [week]
double gps_tow; //!< GPS time of week (0-604800.0) [s]
BOOL ret = TIMECONV_GetSystemTime(&utc_year, &utc_month, &utc_day, &utc_hour, &utc_minute, &utc_seconds,
&utc_offset, &julian_date, &gps_week, &gps_tow);
double gpsTime = (gps_week * 604800.) + gps_tow;
#elif defined(WIN32)
SYSTEMTIME currentSystemTime;
GetSystemTime(¤tSystemTime); //current UTC Time
double gpsTime = e57::GetGPSDateTimeFromSystemTime(currentSystemTime);
#endif
return gpsTime;
};
#if defined(WIN32)
////////////////////////////////////////////////////////////////////
//
// e57::GetGPSDateTimeFromSystemTime
//
double e57::GetGPSDateTimeFromSystemTime(
SYSTEMTIME sysTim //!< Windows System Time
)
{
#ifdef _C_TIMECONV_H_
int utc_year = sysTim.wYear; //!< The year 1900-9999
int utc_month = sysTim.wMonth; //!< The month 0-11
int utc_day = sysTim.wDay; //!< The day 1-31
int utc_hour = sysTim.wHour; //!< The hour 0-23
int utc_minute = sysTim.wMinute; //!< The minute 0-59
float utc_seconds = sysTim.wSecond; //!< The seconds 0.0 - 59.999
utc_seconds += sysTim.wMilliseconds/1000;
double gpsTime = e57::GetGPSDateTimeFromUTC(
utc_year, utc_month, utc_day, utc_hour, utc_minute, utc_seconds);
#else
FILETIME currentFileTime;
SystemTimeToFileTime(&sysTim,¤tFileTime);
ULARGE_INTEGER currentTime;
currentTime.LowPart = currentFileTime.dwLowDateTime;
currentTime.HighPart = currentFileTime.dwHighDateTime;
SYSTEMTIME gpsSystemTime = {1980,1,0,6,0,0,0,0}; //GPS started in Jan. 6, 1980
FILETIME gpsFileTime;
SystemTimeToFileTime(&gpsSystemTime,&gpsFileTime);
ULARGE_INTEGER gpsStartTime;
gpsStartTime.LowPart = gpsFileTime.dwLowDateTime;
gpsStartTime.HighPart = gpsFileTime.dwHighDateTime;
double gpsTime = (double) (currentTime.QuadPart - gpsStartTime.QuadPart); //number of 100 nanosecond;
gpsTime /= 10000000.; //number of seconds
gpsTime += 15.; //Add utc offset leap seconds
#endif
return gpsTime;
};
////////////////////////////////////////////////////////////////////
//
// e57::GetSystemTimeFromGPSDateTime
//
void e57::GetSystemTimeFromGPSDateTime(
double gpsTime, //!< GPS Date Time
SYSTEMTIME &sysTim //!< Windows System Time
)
{
#ifdef _C_TIMECONV_H_
int utc_year; //!< The year 1900-9999
int utc_month; //!< The month 0-11
int utc_day; //!< The day 1-31
int utc_hour; //!< The hour 0-23
int utc_minute; //!< The minute 0-59
float utc_seconds; //!< The seconds 0.0 - 59.999
e57::GetUTCFromGPSDateTime(gpsTime, utc_year, utc_month,
utc_day, utc_hour, utc_minute, utc_seconds);
double julian_date = 0;
unsigned char day_of_week = 0;
TIMECONV_GetJulianDateFromUTCTime( utc_year, utc_month, utc_day,
utc_hour, utc_minute, utc_seconds, &julian_date );
TIMECONV_GetDayOfWeekFromJulianDate( julian_date, &day_of_week );
sysTim.wDayOfWeek = day_of_week;
sysTim.wYear = utc_year;
sysTim.wMonth = utc_month;
sysTim.wDay = utc_day;
sysTim.wHour = utc_hour;
sysTim.wMinute = utc_minute;
sysTim.wSecond = (WORD)(floor(utc_seconds));
sysTim.wMilliseconds = (WORD)((utc_seconds - sysTim.wSecond)*1000);
#else
gpsTime -= 15.; //Sub utc offset leap seconds
gpsTime *= 10000000.; //convert to 100 nanoseconds;
SYSTEMTIME gpsSystemTime = {1980,1,0,6,0,0,0,0}; //GPS started in Jan. 6, 1980
FILETIME gpsFileTime;
SystemTimeToFileTime(&gpsSystemTime,&gpsFileTime);
ULARGE_INTEGER gpsStartTime;
gpsStartTime.LowPart = gpsFileTime.dwLowDateTime;
gpsStartTime.HighPart = gpsFileTime.dwHighDateTime;
ULARGE_INTEGER currentTime;
currentTime.QuadPart = ((ULONGLONG)gpsTime) + gpsStartTime.QuadPart;
FILETIME currentFileTime;
currentFileTime.dwLowDateTime = currentTime.LowPart;
currentFileTime.dwHighDateTime = currentTime.HighPart;
FileTimeToSystemTime(¤tFileTime,&sysTim);
#endif
};
#endif
////////////////////////////////////////////////////////////////////
//
// e57::GetGPSDateTimeFromUTC
//
double e57::GetGPSDateTimeFromUTC(
int utc_year, //!< The year 1900-9999
int utc_month, //!< The month 0-11
int utc_day, //!< The day 1-31
int utc_hour, //!< The hour 0-23
int utc_minute, //!< The minute 0-59
float utc_seconds //!< The seconds 0.0 - 59.999
)
{
#ifdef _C_TIMECONV_H_
double julian_date; //!< Number of days since noon Universal Time Jan 1, 4713 BCE (Julian calendar) [days]
unsigned char utc_offset; //!< Integer seconds that GPS is ahead of UTC time, always positive
unsigned short gps_week; //!< GPS week (0-1024+) [week]
double gps_tow; //!< GPS time of week (0-604800.0) [s]
BOOL result = TIMECONV_GetJulianDateFromUTCTime(
utc_year,
utc_month,
utc_day,
utc_hour,
utc_minute,
utc_seconds,
&julian_date );
result = TIMECONV_DetermineUTCOffset(
julian_date,
&utc_offset );
result = TIMECONV_GetGPSTimeFromJulianDate(
julian_date,
utc_offset,
&gps_week,
&gps_tow );
double gpsTime = (gps_week * 604800.) + gps_tow;
#elif defined(WIN32)
SYSTEMTIME sysTim;
sysTim.wDayOfWeek = day_of_week;
sysTim.wYear = utc_year;
sysTim.wMonth = utc_month;
sysTim.wDay = utc_day;
sysTim.wHour = utc_hour;
sysTim.wMinute = utc_minute;
sysTim.wSecond = (WORD)(floor(utc_seconds));
sysTim.wMilliseconds = (WORD)((utc_seconds - t.wSecond)*1000);
double gpsTime = e57::GetGPSDateTimeFromSystemTime(sysTim);
#endif
return gpsTime;
};
////////////////////////////////////////////////////////////////////
//
// e57::GetUTCFromGPSDateTime
//
void e57::GetUTCFromGPSDateTime(
double gpsTime, //!< GPS Date Time
int &utc_Year, //!< The year 1900-9999
int &utc_Month, //!< The month 0-11
int &utc_Day, //!< The day 1-31
int &utc_Hour, //!< The hour 0-23
int &utc_Minute, //!< The minute 0-59
float &utc_seconds //!< The seconds 0.0 - 59.999
)
{
#ifdef _C_TIMECONV_H_
unsigned short utc_year; //!< Universal Time Coordinated [year]
unsigned char utc_month; //!< Universal Time Coordinated [1-12 months]
unsigned char utc_day; //!< Universal Time Coordinated [1-31 days]
unsigned char utc_hour; //!< Universal Time Coordinated [hours]
unsigned char utc_minute; //!< Universal Time Coordinated [minutes]
unsigned short gps_week; //!< GPS week (0-1024+) [week]
double gps_tow; //!< GPS time of week (0-604800.0) [s]
gps_week = ((int)floor(gpsTime))/604800;
gps_tow = gpsTime - gps_week * 604800.;
BOOL result = TIMECONV_GetUTCTimeFromGPSTime(
gps_week,
gps_tow,
&utc_year,
&utc_month,
&utc_day,
&utc_hour,
&utc_minute,
&utc_seconds);
utc_Year = utc_year;
utc_Month = utc_month;
utc_Day = utc_day;
utc_Hour = utc_hour;
utc_Minute = utc_minute;
#elif defined(WIN32)
SYSTEMTIME sysTim;
e57::GetSystemTimeFromGPSDateTime(gpsTime,sysTim);
utc_year = sysTim.wYear; //!< The year 1900-9999
utc_month = sysTim.wMonth; //!< The month 0-11
utc_day = sysTim.wDay; //!< The day 1-31
utc_hour = sysTim.wHour; //!< The hour 0-23
utc_minute = sysTim.wMinute; //!< The minute 0-59
utc_seconds = sysTim.wSecond; //!< The seconds 0.0 - 59.999
utc_seconds += sysTim.wMilliseconds/1000;
#endif
return;
};
////////////////////////////////////////////////////////////////////
//
// e57::GetNewGuid
//
char * e57::GetNewGuid(void)
{
static char fileGuid[64];
#if defined(_MSC_VER)
GUID guid;
CoCreateGuid((GUID*)&guid);
OLECHAR wbuffer[64];
StringFromGUID2(guid,&wbuffer[0],64);
size_t converted = 0;
wcstombs_s(&converted, fileGuid,wbuffer,64);
#else
boost::uuids::random_generator gen;
boost::uuids::uuid u = gen();
std::stringstream s;
s << u;
std::string c = s.str();
fileGuid[0] = '{';
memcpy(&fileGuid[1],&c[0],36);
fileGuid[37] = '}';
fileGuid[38] = 0;
#endif
return fileGuid;
};
////////////////////////////////////////////////////////////////////
//
// e57::ReaderImpl
//
ReaderImpl::ReaderImpl(
const ustring & filePath)
: imf_(filePath,"r")
, root_(imf_.root())
, data3D_(root_.get("/data3D"))
, images2D_(root_.get("/images2D"))
{
};
ReaderImpl::~ReaderImpl(void)
{
if(IsOpen())
Close();
};
//! This function returns true if the file is open
bool ReaderImpl :: IsOpen(void)
{
if( imf_.isOpen())
return true;
return false;
};
//! This function closes the file
bool ReaderImpl :: Close(void)
{
if(IsOpen())
{
imf_.close();
return true;
}
return false;
};
////////////////////////////////////////////////////////////////////
//
// File information
//
//! This function returns the file header information
bool ReaderImpl :: GetE57Root(
E57Root & fileHeader) //!< This is the main header information
{
if(IsOpen())
{
fileHeader.Reset();
fileHeader.formatName = StringNode(root_.get("formatName")).value();
fileHeader.versionMajor = (int32_t) IntegerNode(root_.get("versionMajor")).value();
fileHeader.versionMinor = (int32_t) IntegerNode(root_.get("versionMinor")).value();
fileHeader.guid = StringNode(root_.get("guid")).value();
if(root_.isDefined("e57LibraryVersion"))
fileHeader.e57LibraryVersion = StringNode(root_.get("e57LibraryVersion")).value();
if(root_.isDefined("coordinateMetadata"))
fileHeader.coordinateMetadata = StringNode(root_.get("coordinateMetadata")).value();
if(root_.isDefined("creationDateTime"))
{
StructureNode creationDateTime(root_.get("creationDateTime"));
fileHeader.creationDateTime.dateTimeValue =
FloatNode(creationDateTime.get("dateTimeValue")).value();
fileHeader.creationDateTime.isAtomicClockReferenced =
(int32_t) IntegerNode(creationDateTime.get("isAtomicClockReferenced")).value();
}
fileHeader.data3DSize = (int32_t) data3D_.childCount();
fileHeader.images2DSize = (int32_t) images2D_.childCount();
return true;
}
return false;
};
////////////////////////////////////////////////////////////////////
//
// Camera Image picture data
//
//! This function returns the total number of Picture Blocks
int32_t ReaderImpl :: GetImage2DCount( void)
{
return (int32_t) images2D_.childCount();
};
//! This function returns the Image2Ds header and positions the cursor
bool ReaderImpl :: ReadImage2D(
int32_t imageIndex, //!< This in the index into the Image2Ds vector
Image2D & image2DHeader //!< pointer to the Image2D structure to receive the picture information
) //!< /return Returns true if sucessful
{
if(IsOpen())
{
if( (imageIndex < 0) || (imageIndex >= images2D_.childCount()))
return false;
image2DHeader.Reset();
StructureNode image(images2D_.get(imageIndex));
image2DHeader.guid = StringNode(image.get("guid")).value();
if(image.isDefined("name"))
image2DHeader.name = StringNode(image.get("name")).value();
if(image.isDefined("description"))
image2DHeader.description = StringNode(image.get("description")).value();
if(image.isDefined("sensorVendor"))
image2DHeader.sensorVendor = StringNode(image.get("sensorVendor")).value();
if(image.isDefined("sensorModel"))
image2DHeader.sensorModel = StringNode(image.get("sensorModel")).value();
if(image.isDefined("sensorSerialNumber"))
image2DHeader.sensorSerialNumber = StringNode(image.get("sensorSerialNumber")).value();
if(image.isDefined("associatedData3DGuid"))
image2DHeader.associatedData3DGuid = StringNode(image.get("associatedData3DGuid")).value();
if(image.isDefined("acquisitionDateTime"))
{
StructureNode acquisitionDateTime(image.get("acquisitionDateTime"));
image2DHeader.acquisitionDateTime.dateTimeValue =
FloatNode(acquisitionDateTime.get("dateTimeValue")).value();
image2DHeader.acquisitionDateTime.isAtomicClockReferenced = (int32_t)
IntegerNode(acquisitionDateTime.get("isAtomicClockReferenced")).value();
}
// Get pose structure for scan.
if(image.isDefined("pose"))
{
StructureNode pose(image.get("pose"));
if(pose.isDefined("rotation")){
StructureNode rotation(pose.get("rotation"));
image2DHeader.pose.rotation.w = FloatNode(rotation.get("w")).value();
image2DHeader.pose.rotation.x = FloatNode(rotation.get("x")).value();
image2DHeader.pose.rotation.y = FloatNode(rotation.get("y")).value();
image2DHeader.pose.rotation.z = FloatNode(rotation.get("z")).value();
}
if(pose.isDefined("translation")){
StructureNode translation(pose.get("translation"));
image2DHeader.pose.translation.x = FloatNode(translation.get("x")).value();
image2DHeader.pose.translation.y = FloatNode(translation.get("y")).value();
image2DHeader.pose.translation.z = FloatNode(translation.get("z")).value();
}
}
if(image.isDefined("visualReferenceRepresentation"))
{
StructureNode visualReferenceRepresentation(image.get("visualReferenceRepresentation"));
if(visualReferenceRepresentation.isDefined("jpegImage"))
image2DHeader.visualReferenceRepresentation.jpegImageSize =
BlobNode(visualReferenceRepresentation.get("jpegImage")).byteCount();
if(visualReferenceRepresentation.isDefined("pngImage"))
image2DHeader.visualReferenceRepresentation.pngImageSize =
BlobNode(visualReferenceRepresentation.get("pngImage")).byteCount();
if(visualReferenceRepresentation.isDefined("imageMask"))
image2DHeader.visualReferenceRepresentation.imageMaskSize =
BlobNode(visualReferenceRepresentation.get("imageMask")).byteCount();
image2DHeader.visualReferenceRepresentation.imageHeight = (int32_t)
IntegerNode(visualReferenceRepresentation.get("imageHeight")).value();
image2DHeader.visualReferenceRepresentation.imageWidth = (int32_t)
IntegerNode(visualReferenceRepresentation.get("imageWidth")).value();
}
if(image.isDefined("pinholeRepresentation"))
{
StructureNode pinholeRepresentation(image.get("pinholeRepresentation"));
if(pinholeRepresentation.isDefined("jpegImage"))
image2DHeader.pinholeRepresentation.jpegImageSize =
BlobNode(pinholeRepresentation.get("jpegImage")).byteCount();
if(pinholeRepresentation.isDefined("pngImage"))
image2DHeader.pinholeRepresentation.pngImageSize =
BlobNode(pinholeRepresentation.get("pngImage")).byteCount();
if(pinholeRepresentation.isDefined("imageMask"))
image2DHeader.pinholeRepresentation.imageMaskSize =
BlobNode(pinholeRepresentation.get("imageMask")).byteCount();
image2DHeader.pinholeRepresentation.focalLength =
FloatNode(pinholeRepresentation.get("focalLength")).value();
image2DHeader.pinholeRepresentation.imageHeight = (int32_t)
IntegerNode(pinholeRepresentation.get("imageHeight")).value();
image2DHeader.pinholeRepresentation.imageWidth = (int32_t)
IntegerNode(pinholeRepresentation.get("imageWidth")).value();
image2DHeader.pinholeRepresentation.pixelHeight =
FloatNode(pinholeRepresentation.get("pixelHeight")).value();
image2DHeader.pinholeRepresentation.pixelWidth =
FloatNode(pinholeRepresentation.get("pixelWidth")).value();
image2DHeader.pinholeRepresentation.principalPointX =
FloatNode(pinholeRepresentation.get("principalPointX")).value();
image2DHeader.pinholeRepresentation.principalPointY =
FloatNode(pinholeRepresentation.get("principalPointY")).value();
}
else if(image.isDefined("sphericalRepresentation"))
{
StructureNode sphericalRepresentation(image.get("sphericalRepresentation"));
if(sphericalRepresentation.isDefined("jpegImage"))
image2DHeader.sphericalRepresentation.jpegImageSize =
BlobNode(sphericalRepresentation.get("jpegImage")).byteCount();
if(sphericalRepresentation.isDefined("pngImage"))
image2DHeader.sphericalRepresentation.pngImageSize =
BlobNode(sphericalRepresentation.get("pngImage")).byteCount();
if(sphericalRepresentation.isDefined("imageMask"))
image2DHeader.sphericalRepresentation.imageMaskSize =
BlobNode(sphericalRepresentation.get("imageMask")).byteCount();
image2DHeader.sphericalRepresentation.imageHeight = (int32_t)
IntegerNode(sphericalRepresentation.get("imageHeight")).value();
image2DHeader.sphericalRepresentation.imageWidth = (int32_t)
IntegerNode(sphericalRepresentation.get("imageWidth")).value();
image2DHeader.sphericalRepresentation.pixelHeight =
FloatNode(sphericalRepresentation.get("pixelHeight")).value();
image2DHeader.sphericalRepresentation.pixelWidth =
FloatNode(sphericalRepresentation.get("pixelWidth")).value();
}
else if(image.isDefined("cylindricalRepresentation"))
{
StructureNode cylindricalRepresentation(image.get("cylindricalRepresentation"));
if(cylindricalRepresentation.isDefined("jpegImage"))
image2DHeader.cylindricalRepresentation.jpegImageSize =
BlobNode(cylindricalRepresentation.get("jpegImage")).byteCount();
if(cylindricalRepresentation.isDefined("pngImage"))
image2DHeader.cylindricalRepresentation.pngImageSize =
BlobNode(cylindricalRepresentation.get("pngImage")).byteCount();
if(cylindricalRepresentation.isDefined("imageMask"))
image2DHeader.cylindricalRepresentation.imageMaskSize =
BlobNode(cylindricalRepresentation.get("imageMask")).byteCount();
image2DHeader.cylindricalRepresentation.imageHeight = (int32_t)
IntegerNode(cylindricalRepresentation.get("imageHeight")).value();
image2DHeader.cylindricalRepresentation.imageWidth = (int32_t)
IntegerNode(cylindricalRepresentation.get("imageWidth")).value();
image2DHeader.cylindricalRepresentation.pixelHeight =
FloatNode(cylindricalRepresentation.get("pixelHeight")).value();
image2DHeader.cylindricalRepresentation.pixelWidth =
FloatNode(cylindricalRepresentation.get("pixelWidth")).value();
image2DHeader.cylindricalRepresentation.principalPointY =
FloatNode(cylindricalRepresentation.get("principalPointY")).value();
image2DHeader.cylindricalRepresentation.radius =
FloatNode(cylindricalRepresentation.get("radius")).value();
}
return true;
}
return false;
};
//! This function reads one of the image blobs
int64_t ReaderImpl :: ReadImage2DNode(
e57::StructureNode image, //!< 1 of 3 projects or the visual
e57::Image2DType imageType, //!< identifies the image format desired.
void * pBuffer, //!< pointer the buffer
int64_t start, //!< position in the block to start reading
int64_t count //!< size of desired chuck or buffer size
) //!< /return Returns the number of bytes transferred.
{
int64_t transferred = 0;
switch(imageType)
{
case E57_JPEG_IMAGE:
{
if(image.isDefined("jpegImage"))
{
BlobNode jpegImage(image.get("jpegImage"));
jpegImage.read((uint8_t*) pBuffer, start, (size_t) count);
transferred = count;
}
break;
}
case E57_PNG_IMAGE:
{
if( image.isDefined("pngImage"))
{
BlobNode pngImage(image.get("pngImage"));
pngImage.read((uint8_t*) pBuffer, start, (size_t) count);
transferred = count;
}
break;
}
case E57_PNG_IMAGE_MASK:
{
if( image.isDefined("imageMask"))
{
BlobNode imageMask(image.get("imageMask"));
imageMask.read((uint8_t*) pBuffer, start, (size_t) count);
transferred = count;
}
break;
}
};
return transferred;
};
//! This function reads one of the image blobs
bool ReaderImpl :: GetImage2DNodeSizes(
e57::StructureNode image, //!< 1 of 3 projects or the visual
e57::Image2DType & imageType, //!< identifies the image format desired.
int64_t & imageWidth, //!< The image width (in pixels).
int64_t & imageHeight, //!< The image height (in pixels).
int64_t & imageSize, //!< This is the total number of bytes for the image blob.
e57::Image2DType & imageMaskType //!< This is E57_PNG_IMAGE_MASK if "imageMask" is defined in the projection
) //!< /return Returns the number of bytes transferred.
{
imageWidth = 0;
imageHeight = 0;
imageSize = 0;
imageType = E57_NO_IMAGE;
imageMaskType = E57_NO_IMAGE;
if(image.isDefined("imageWidth"))
imageWidth = IntegerNode(image.get("imageWidth")).value();
else return false;
if(image.isDefined("imageHeight"))
imageHeight = IntegerNode(image.get("imageHeight")).value();
else return false;
if(image.isDefined("jpegImage"))
{
imageSize = BlobNode(image.get("jpegImage")).byteCount();
imageType = E57_JPEG_IMAGE;
}
else if( image.isDefined("pngImage"))
{
imageSize = BlobNode(image.get("pngImage")).byteCount();
imageType = E57_PNG_IMAGE;
}
if( image.isDefined("imageMask"))
{
if(imageType == E57_NO_IMAGE)
{
imageSize = BlobNode(image.get("imageMask")).byteCount();
imageType = E57_PNG_IMAGE_MASK;
}
imageMaskType = E57_PNG_IMAGE_MASK;
}
return true;
};
// This function returns the image sizes
bool ReaderImpl :: GetImage2DSizes(
int32_t imageIndex, //!< This in the index into the image2D vector
e57::Image2DProjection &imageProjection,//!< identifies the projection desired.
e57::Image2DType & imageType, //!< identifies the image format desired.
int64_t & imageWidth, //!< The image width (in pixels).
int64_t & imageHeight, //!< The image height (in pixels).
int64_t & imageSize, //!< This is the total number of bytes for the image blob.
e57::Image2DType & imageMaskType, //!< This is E57_PNG_IMAGE_MASK if "imageMask" is defined in the projection
e57::Image2DType & imageVisualType //!< This is image type of the VisualReferenceRepresentation if given.
)
{
if( (imageIndex < 0) || (imageIndex >= images2D_.childCount()))
return 0;
imageProjection = E57_NO_PROJECTION;
imageType = E57_NO_IMAGE;
imageMaskType = E57_NO_IMAGE;
imageVisualType = E57_NO_IMAGE;
bool ret = false;
StructureNode image(images2D_.get(imageIndex));
if(image.isDefined("visualReferenceRepresentation"))
{
imageProjection = E57_VISUAL;
StructureNode visualReferenceRepresentation(image.get("visualReferenceRepresentation"));
ret = GetImage2DNodeSizes(visualReferenceRepresentation, imageType, imageWidth, imageHeight, imageSize, imageMaskType);
imageVisualType = imageType;
}
if(image.isDefined("pinholeRepresentation"))
{
imageProjection = E57_PINHOLE;
StructureNode pinholeRepresentation(image.get("pinholeRepresentation"));
ret = GetImage2DNodeSizes(pinholeRepresentation, imageType, imageWidth, imageHeight, imageSize, imageMaskType);
}
else if(image.isDefined("sphericalRepresentation"))
{
imageProjection = E57_SPHERICAL;
StructureNode sphericalRepresentation(image.get("sphericalRepresentation"));
ret = GetImage2DNodeSizes(sphericalRepresentation, imageType, imageWidth, imageHeight, imageSize, imageMaskType);
}
else if(image.isDefined("cylindricalRepresentation"))
{
imageProjection = E57_CYLINDRICAL;
StructureNode cylindricalRepresentation(image.get("cylindricalRepresentation"));
ret = GetImage2DNodeSizes(cylindricalRepresentation, imageType, imageWidth, imageHeight, imageSize, imageMaskType);
};
return ret;
};
//! This function reads the block
int64_t ReaderImpl :: ReadImage2DData(
int32_t imageIndex, //!< picture block index
e57::Image2DProjection imageProjection,//!< identifies the projection desired.
e57::Image2DType imageType, //!< identifies the image format desired.
void * pBuffer, //!< pointer the buffer
int64_t start, //!< position in the block to start reading
int64_t count //!< size of desired chuck or buffer size
) //!< /return Returns the number of bytes transferred.
{
if( (imageIndex < 0) || (imageIndex >= images2D_.childCount()))
return 0;
int64_t transferred = 0;
StructureNode image(images2D_.get(imageIndex));
switch(imageProjection)
{
case E57_VISUAL:
if(image.isDefined("visualReferenceRepresentation"))
{
StructureNode visualReferenceRepresentation(image.get("visualReferenceRepresentation"));
transferred = ReadImage2DNode(visualReferenceRepresentation, imageType, pBuffer, start, count);
}
break;
case E57_PINHOLE:
if(image.isDefined("pinholeRepresentation"))
{
StructureNode pinholeRepresentation(image.get("pinholeRepresentation"));
transferred = ReadImage2DNode(pinholeRepresentation, imageType, pBuffer, start, count);
}
break;
case E57_SPHERICAL:
if(image.isDefined("sphericalRepresentation"))
{
StructureNode sphericalRepresentation(image.get("sphericalRepresentation"));
transferred = ReadImage2DNode(sphericalRepresentation, imageType, pBuffer, start, count);
}
break;
case E57_CYLINDRICAL:
if(image.isDefined("cylindricalRepresentation"))
{
StructureNode cylindricalRepresentation(image.get("cylindricalRepresentation"));
transferred = ReadImage2DNode(cylindricalRepresentation, imageType, pBuffer, start, count);
}
break;
};
return transferred;
};
////////////////////////////////////////////////////////////////////
//
// Scanner Image 3d data
//
//! This function returns the total number of Image Blocks
int32_t ReaderImpl :: GetData3DCount( void)
{
return (int32_t) data3D_.childCount();
};
//! This function returns the file raw E57Root Structure Node
StructureNode ReaderImpl :: GetRawE57Root(void)
{
return root_;
}; //!< /return Returns the E57Root StructureNode
//! This function returns the raw Data3D Vector Node
VectorNode ReaderImpl :: GetRawData3D(void)
{
return data3D_;
};//!< /return Returns the raw Data3D VectorNode
//! This function returns the raw Images2D Vector Node
VectorNode ReaderImpl :: GetRawImages2D(void)
{
return images2D_;
}; //!< /return Returns the raw Image2D VectorNode
//! This function returns the ram ImageFile Node which is need to add enhancements
ImageFile ReaderImpl :: GetRawIMF(void)
{
return imf_;
}; //!< /return Returns the raw ImageFile
//! This function returns the Data3D header and positions the cursor
bool ReaderImpl :: ReadData3D(
int32_t dataIndex, //!< This in the index into the images3D vector
Data3D & data3DHeader //!< pointer to the Data3D structure to receive the image information
) //!< /return Returns true if sucessful
{
if(IsOpen())
{
if( (dataIndex < 0) || (dataIndex >= data3D_.childCount()))
return false;
data3DHeader.Reset();
StructureNode scan(data3D_.get(dataIndex));
CompressedVectorNode points(scan.get("points"));
data3DHeader.pointsSize = points.childCount();
StructureNode proto(points.prototype());
data3DHeader.guid = StringNode(scan.get("guid")).value();
if(scan.isDefined("name"))
data3DHeader.name = StringNode(scan.get("name")).value();
if(scan.isDefined("description"))
data3DHeader.description = StringNode(scan.get("description")).value();
if(scan.isDefined("originalGuids"))
{
VectorNode originalGuids(scan.get("originalGuids"));
if(originalGuids.childCount() > 0)
{
data3DHeader.originalGuids.clear();
int i;
for( i = 0; i < originalGuids.childCount(); i++)
{
e57::ustring str = StringNode(originalGuids.get(i)).value();
data3DHeader.originalGuids.push_back(str);
}
}
}
// Get various sensor and version strings to scan.
if(scan.isDefined("sensorVendor"))
data3DHeader.sensorVendor = StringNode(scan.get("sensorVendor")).value();
if(scan.isDefined("sensorModel"))
data3DHeader.sensorModel = StringNode(scan.get("sensorModel")).value();
if(scan.isDefined("sensorSerialNumber"))
data3DHeader.sensorSerialNumber = StringNode(scan.get("sensorSerialNumber")).value();
if(scan.isDefined("sensorHardwareVersion"))
data3DHeader.sensorHardwareVersion = StringNode(scan.get("sensorHardwareVersion")).value();
if(scan.isDefined("sensorSoftwareVersion"))
data3DHeader.sensorSoftwareVersion = StringNode(scan.get("sensorSoftwareVersion")).value();
if(scan.isDefined("sensorFirmwareVersion"))
data3DHeader.sensorFirmwareVersion = StringNode(scan.get("sensorFirmwareVersion")).value();
// Get temp/humidity to scan.
if(scan.isDefined("temperature"))
data3DHeader.temperature = (float) FloatNode(scan.get("temperature")).value();
if(scan.isDefined("relativeHumidity"))
data3DHeader.relativeHumidity = (float) FloatNode(scan.get("relativeHumidity")).value();
if(scan.isDefined("atmosphericPressure"))
data3DHeader.atmosphericPressure = (float) FloatNode(scan.get("atmosphericPressure")).value();
if(scan.isDefined("indexBounds"))
{
StructureNode ibox(scan.get("indexBounds"));
if(ibox.isDefined("rowMaximum"))
{
data3DHeader.indexBounds.rowMinimum = IntegerNode(ibox.get("rowMinimum")).value();
data3DHeader.indexBounds.rowMaximum = IntegerNode(ibox.get("rowMaximum")).value();
}
if(ibox.isDefined("columnMaximum"))
{
data3DHeader.indexBounds.columnMinimum = IntegerNode(ibox.get("columnMinimum")).value();
data3DHeader.indexBounds.columnMaximum = IntegerNode(ibox.get("columnMaximum")).value();
}
if(ibox.isDefined("returnMaximum"))
{
data3DHeader.indexBounds.returnMinimum = IntegerNode(ibox.get("returnMinimum")).value();
data3DHeader.indexBounds.returnMaximum = IntegerNode(ibox.get("returnMaximum")).value();
}
}
if(scan.isDefined("pointGroupingSchemes"))
{
StructureNode pointGroupingSchemes(scan.get("pointGroupingSchemes"));
if(pointGroupingSchemes.isDefined("groupingByLine"))
{
StructureNode groupingByLine(pointGroupingSchemes.get("groupingByLine"));
data3DHeader.pointGroupingSchemes.groupingByLine.idElementName =
StringNode(groupingByLine.get("idElementName")).value();
CompressedVectorNode groups(groupingByLine.get("groups"));
data3DHeader.pointGroupingSchemes.groupingByLine.groupsSize = groups.childCount();
StructureNode lineGroupRecord(groups.prototype());
if(lineGroupRecord.isDefined("pointCount"))
data3DHeader.pointGroupingSchemes.groupingByLine.pointCountSize =
IntegerNode(lineGroupRecord.get("pointCount")).maximum();
}
}
// Get Cartesian bounding box to scan.
if(scan.isDefined("cartesianBounds"))
{
StructureNode bbox(scan.get("cartesianBounds"));
if( bbox.get("xMinimum").type() == E57_SCALED_INTEGER ) {
data3DHeader.cartesianBounds.xMinimum = (double) ScaledIntegerNode(bbox.get("xMinimum")).scaledValue();
data3DHeader.cartesianBounds.xMaximum = (double) ScaledIntegerNode(bbox.get("xMaximum")).scaledValue();
data3DHeader.cartesianBounds.yMinimum = (double) ScaledIntegerNode(bbox.get("yMinimum")).scaledValue();
data3DHeader.cartesianBounds.yMaximum = (double) ScaledIntegerNode(bbox.get("yMaximum")).scaledValue();
data3DHeader.cartesianBounds.zMinimum = (double) ScaledIntegerNode(bbox.get("zMinimum")).scaledValue();