-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcdff_types.pyx
More file actions
2952 lines (2282 loc) · 91.9 KB
/
cdff_types.pyx
File metadata and controls
2952 lines (2282 loc) · 91.9 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
# distutils: language = c++
cimport cdff_types
cimport _cdff_types
import cython
from cython.operator cimport dereference as deref
from libc.string cimport memcpy
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t
from libc.stdlib cimport malloc, free
import math
cimport numpy as np
import numpy as np
import warnings
np.import_array() # must be here because we use the NumPy C API
cdef class Time:
def __cinit__(self):
self.thisptr = NULL
self.delete_thisptr = False
def __dealloc__(self):
if self.thisptr != NULL and self.delete_thisptr:
del self.thisptr
def __init__(self):
self.thisptr = new _cdff_types.asn1SccTime()
self.delete_thisptr = True
def __str__(self):
return "{type: Time, microseconds: %d}" % self.thisptr.microseconds
def assign(self, Time other):
self.thisptr.assign(deref(other.thisptr))
def _get_microseconds(self):
return self.thisptr.microseconds
def _set_microseconds(self, microseconds):
self.thisptr.microseconds = <int64_t> microseconds
microseconds = property(_get_microseconds, _set_microseconds)
def _get_usec_per_sec(self):
return self.thisptr.usecPerSec
def _set_usec_per_sec(self, int64_t usecPerSec):
self.thisptr.usecPerSec = usecPerSec
usec_per_sec = property(_get_usec_per_sec, _set_usec_per_sec)
cdef class Vector2d:
def __cinit__(self):
self.thisptr = NULL
self.delete_thisptr = False
def __dealloc__(self):
if self.thisptr != NULL and self.delete_thisptr:
del self.thisptr
def __init__(self):
self.thisptr = new _cdff_types.asn1SccVector2d()
self.delete_thisptr = True
def __len__(self):
return 2
def __str__(self):
return str("{type: Vector2d, data: [%g, %g]}"
% (self.thisptr.arr[0], self.thisptr.arr[1]))
def __array__(self, dtype=None):
cdef np.npy_intp shape[1]
shape[0] = <np.npy_intp> 2
return np.PyArray_SimpleNewFromData(
1, shape, np.NPY_DOUBLE, <void*> self.thisptr.arr)
def __getitem__(self, int i):
if i < 0 or i > 1:
raise KeyError("index must be 0 or 1 but was %d" % i)
return self.thisptr.arr[i]
def __setitem__(self, int i, double v):
if i < 0 or i > 1:
raise KeyError("index must be 0 or 1 but was %d" % i)
self.thisptr.arr[i] = v
def assign(self, Vector2d other):
self.thisptr.assign(deref(other.thisptr))
def toarray(self):
cdef np.ndarray[double, ndim=1] array = np.empty(2)
cdef int i
for i in range(2):
array[i] = self.thisptr.arr[i]
return array
def fromarray(self, np.ndarray[double, ndim=1] array):
cdef int i
for i in range(2):
self.thisptr.arr[i] = array[i]
cdef class Vector3d:
def __cinit__(self):
self.thisptr = NULL
self.delete_thisptr = False
def __dealloc__(self):
if self.thisptr != NULL and self.delete_thisptr:
del self.thisptr
def __init__(self):
self.thisptr = new _cdff_types.asn1SccVector3d()
self.delete_thisptr = True
def __len__(self):
return 3
def __str__(self):
return str("{type: Vector3d, data: [%g, %g, %g]}"
% (self.thisptr.arr[0], self.thisptr.arr[1],
self.thisptr.arr[2]))
def __array__(self, dtype=None):
cdef np.npy_intp shape[1]
shape[0] = <np.npy_intp> 3
return np.PyArray_SimpleNewFromData(
1, shape, np.NPY_DOUBLE, <void*> self.thisptr.arr)
def __getitem__(self, int i):
if i < 0 or i > 2:
raise KeyError("index must be 0, 1, or 2 but was %d" % i)
return self.thisptr.arr[i]
def __setitem__(self, int i, double v):
if i < 0 or i > 2:
raise KeyError("index must be 0, 1, or 2 but was %d" % i)
self.thisptr.arr[i] = v
def assign(self, Vector3d other):
self.thisptr.assign(deref(other.thisptr))
def toarray(self):
cdef np.ndarray[double, ndim=1] array = np.empty(3)
cdef int i
for i in range(3):
array[i] = self.thisptr.arr[i]
return array
def fromarray(self, np.ndarray[double, ndim=1] array):
cdef int i
for i in range(3):
self.thisptr.arr[i] = array[i]
cdef class Vector4d:
def __cinit__(self):
self.thisptr = NULL
self.delete_thisptr = False
def __dealloc__(self):
if self.thisptr != NULL and self.delete_thisptr:
del self.thisptr
def __init__(self):
self.thisptr = new _cdff_types.asn1SccVector4d()
self.delete_thisptr = True
def __len__(self):
return 4
def __str__(self):
return str("{type: Vector4d, data: [%g, %g, %g, %g]}"
% (self.thisptr.arr[0], self.thisptr.arr[1],
self.thisptr.arr[2], self.thisptr.arr[3]))
def __array__(self, dtype=None):
cdef np.npy_intp shape[1]
shape[0] = <np.npy_intp> 4
return np.PyArray_SimpleNewFromData(
1, shape, np.NPY_DOUBLE, <void*> self.thisptr.arr)
def __getitem__(self, int i):
if i < 0 or i > 3:
raise KeyError("index must be 0, 1, or 2 but was %d" % i)
return self.thisptr.arr[i]
def __setitem__(self, int i, double v):
if i < 0 or i > 3:
raise KeyError("index must be 0, 1, or 2 but was %d" % i)
self.thisptr.arr[i] = v
def assign(self, Vector4d other):
self.thisptr.assign(deref(other.thisptr))
def toarray(self):
cdef np.ndarray[double, ndim=1] array = np.empty(4)
cdef int i
for i in range(4):
array[i] = self.thisptr.arr[i]
return array
def fromarray(self, np.ndarray[double, ndim=1] array):
cdef int i
for i in range(4):
self.thisptr.arr[i] = array[i]
cdef class Vector6d:
def __cinit__(self):
self.thisptr = NULL
self.delete_thisptr = False
def __dealloc__(self):
if self.thisptr != NULL and self.delete_thisptr:
del self.thisptr
def __init__(self):
self.thisptr = new _cdff_types.asn1SccVector6d()
self.delete_thisptr = True
def __len__(self):
return 6
def __str__(self):
return ("{type: Vector6d, data: [%g, %g, %g, %g, %g, %g]}"
% (self.thisptr.arr[0], self.thisptr.arr[1],
self.thisptr.arr[2], self.thisptr.arr[3],
self.thisptr.arr[4], self.thisptr.arr[5]))
def __array__(self, dtype=None):
cdef np.npy_intp shape[1]
shape[0] = <np.npy_intp> 6
return np.PyArray_SimpleNewFromData(
1, shape, np.NPY_DOUBLE, <void*> self.thisptr.arr)
def __getitem__(self, int i):
if i < 0 or i > 5:
raise KeyError("index must be in [0, 5] but was %d" % i)
return self.thisptr.arr[i]
def __setitem__(self, int i, double v):
if i < 0 or i > 5:
raise KeyError("index must be in [0, 5] but was %d" % i)
self.thisptr.arr[i] = v
def assign(self, Vector6d other):
self.thisptr.assign(deref(other.thisptr))
def toarray(self):
cdef np.ndarray[double, ndim=1] array = np.empty(6)
cdef int i
for i in range(6):
array[i] = self.thisptr.arr[i]
return array
def fromarray(self, np.ndarray[double, ndim=1] array):
cdef int i
for i in range(6):
self.thisptr.arr[i] = array[i]
cdef class VectorXd:
def __cinit__(self):
self.thisptr = NULL
self.delete_thisptr = False
def __dealloc__(self):
if self.thisptr != NULL and self.delete_thisptr:
del self.thisptr
def __init__(self, int n_count=1):
self.thisptr = new _cdff_types.asn1SccVectorXd()
self.thisptr.nCount = n_count
self.delete_thisptr = True
def __len__(self):
return self.thisptr.nCount
def __str__(self):
return str("{type: VectorXd, data: [%s]}"
% ", ".join(["%g" % self.thisptr.arr[i]
for i in range(self.thisptr.nCount)]))
def __array__(self, dtype=None):
cdef np.npy_intp shape[1]
shape[0] = <np.npy_intp> self.thisptr.nCount
return np.PyArray_SimpleNewFromData(
1, shape, np.NPY_DOUBLE, <void*> self.thisptr.arr)
def __getitem__(self, int i):
if i < 0 or i >= self.thisptr.nCount:
raise KeyError("index out of range: %d" % i)
return self.thisptr.arr[i]
def __setitem__(self, int i, double v):
if i < 0 or i >= 100:
raise KeyError("index out of range: %d" % i)
if i >= self.thisptr.nCount:
self.thisptr.nCount = i + 1
self.thisptr.arr[i] = v
def assign(self, VectorXd other):
self.thisptr.assign(deref(other.thisptr))
def toarray(self):
cdef np.ndarray[double, ndim=1] array = np.empty(self.thisptr.nCount)
cdef int i
for i in range(self.thisptr.nCount):
array[i] = self.thisptr.arr[i]
return array
def fromarray(self, np.ndarray[double, ndim=1] array):
if len(array) > 100:
raise ValueError("VectorXd supports a maximum length of 100!")
self.thisptr.nCount = len(array)
cdef int i
for i in range(self.thisptr.nCount):
self.thisptr.arr[i] = array[i]
cdef class Matrix2d:
def __cinit__(self):
self.thisptr = NULL
self.delete_thisptr = False
def __dealloc__(self):
if self.thisptr != NULL and self.delete_thisptr:
del self.thisptr
def __init__(self):
self.thisptr = new _cdff_types.asn1SccMatrix2d()
self.delete_thisptr = True
def __len__(self):
return 2
def __str__(self):
return ("{type: Matrix2d, data: [[%g, %g], [%g, %g]]}"
% tuple(self.toarray().ravel()))
def __array__(self, dtype=None):
return self.toarray().astype(dtype)
def __getitem__(self, tuple indices):
cdef int i, j
i, j = indices
if i < 0 or i >= 2:
raise KeyError("index out of range %d" % i)
if j < 0 or j >= 2:
raise KeyError("index out of range %d" % j)
return self.thisptr.arr[i].arr[j]
def __setitem__(self, tuple indices, double v):
cdef int i, j
i, j = indices
if i < 0 or i >= 2:
raise KeyError("index out of range %d" % i)
if j < 0 or j >= 2:
raise KeyError("index out of range %d" % j)
self.thisptr.arr[i].arr[j] = v
@property
def shape(self):
return (2, 2)
def assign(self, Matrix2d other):
self.thisptr.assign(deref(other.thisptr))
def toarray(self):
cdef np.ndarray[double, ndim=2] array = np.empty((2, 2))
cdef int i, j
for i in range(2):
for j in range(2):
array[i, j] = self.thisptr.arr[i].arr[j]
return array
def fromarray(self, np.ndarray[double, ndim=2] array):
cdef int i, j
for i in range(2):
for j in range(2):
self.thisptr.arr[i].arr[j] = array[i, j]
cdef class Matrix3d:
def __cinit__(self):
self.thisptr = NULL
self.delete_thisptr = False
def __dealloc__(self):
if self.thisptr != NULL and self.delete_thisptr:
del self.thisptr
def __init__(self):
self.thisptr = new _cdff_types.asn1SccMatrix3d()
self.delete_thisptr = True
def __len__(self):
return 3
def __str__(self):
return ("{type: Matrix3d, data: [[%g, %g, %g], [%g, %g, %g], "
"[%g, %g, %g]]}" % tuple(self.toarray().ravel()))
def __array__(self, dtype=None):
return self.toarray().astype(dtype)
def __getitem__(self, tuple indices):
cdef int i, j
i, j = indices
if i < 0 or i >= 3:
raise KeyError("index out of range %d" % i)
if j < 0 or j >= 3:
raise KeyError("index out of range %d" % j)
return self.thisptr.arr[i].arr[j]
def __setitem__(self, tuple indices, double v):
cdef int i, j
i, j = indices
if i < 0 or i >= 3:
raise KeyError("index out of range %d" % i)
if j < 0 or j >= 3:
raise KeyError("index out of range %d" % j)
self.thisptr.arr[i].arr[j] = v
@property
def shape(self):
return (3, 3)
def assign(self, Matrix3d other):
self.thisptr.assign(deref(other.thisptr))
def toarray(self):
cdef np.ndarray[double, ndim=2] array = np.empty((3, 3))
cdef int i, j
for i in range(3):
for j in range(3):
array[i, j] = self.thisptr.arr[i].arr[j]
return array
def fromarray(self, np.ndarray[double, ndim=2] array):
cdef int i, j
for i in range(3):
for j in range(3):
self.thisptr.arr[i].arr[j] = array[i, j]
cdef class Matrix6d:
def __cinit__(self):
self.thisptr = NULL
self.delete_thisptr = False
def __dealloc__(self):
if self.thisptr != NULL and self.delete_thisptr:
del self.thisptr
def __init__(self):
self.thisptr = new _cdff_types.asn1SccMatrix6d()
self.delete_thisptr = True
def __len__(self):
return 6
def __str__(self):
return ("{type: Matrix6d, data: [[%g, %g, %g, %g, %g, %g], "
"[%g, %g, %g, %g, %g, %g], [%g, %g, %g, %g, %g, %g], "
"[%g, %g, %g, %g, %g, %g], [%g, %g, %g, %g, %g, %g], "
"[%g, %g, %g, %g, %g, %g]]}"
% tuple(self.toarray().ravel()))
def __array__(self, dtype=None):
return self.toarray().astype(dtype)
def __getitem__(self, tuple indices):
cdef int i, j
i, j = indices
if i < 0 or i >= 6:
raise KeyError("index out of range %d" % i)
if j < 0 or j >= 6:
raise KeyError("index out of range %d" % j)
return self.thisptr.arr[i].arr[j]
def __setitem__(self, tuple indices, double v):
cdef int i, j
i, j = indices
if i < 0 or i >= 6:
raise KeyError("index out of range %d" % i)
if j < 0 or j >= 6:
raise KeyError("index out of range %d" % j)
self.thisptr.arr[i].arr[j] = v
@property
def shape(self):
return (6, 6)
def assign(self, Matrix6d other):
self.thisptr.assign(deref(other.thisptr))
def toarray(self):
cdef np.ndarray[double, ndim=2] array = np.empty((6, 6))
cdef int i, j
for i in range(6):
for j in range(6):
array[i, j] = self.thisptr.arr[i].arr[j]
return array
def fromarray(self, np.ndarray[double, ndim=2] array):
cdef int i, j
for i in range(6):
for j in range(6):
self.thisptr.arr[i].arr[j] = array[i, j]
cdef class Quaterniond:
def __cinit__(self):
self.thisptr = NULL
self.delete_thisptr = False
def __dealloc__(self):
if self.thisptr != NULL and self.delete_thisptr:
del self.thisptr
def __init__(self, x=0.0, y=0.0, z=0.0, w=1.0):
self.thisptr = new _cdff_types.asn1SccQuaterniond()
self.delete_thisptr = True
self.thisptr.arr[0] = x
self.thisptr.arr[1] = y
self.thisptr.arr[2] = z
self.thisptr.arr[3] = w
def __len__(self):
return 4
def __str__(self):
return str("{type: Quaterniond, data: {x: %g, y: %g, z: %g, w: %g}}"
% (self.thisptr.arr[0], self.thisptr.arr[1],
self.thisptr.arr[2], self.thisptr.arr[3]))
def __array__(self, dtype=None):
cdef np.npy_intp shape[1]
shape[0] = <np.npy_intp> 4
return np.PyArray_SimpleNewFromData(
1, shape, np.NPY_DOUBLE, <void*> self.thisptr.arr)
def __getitem__(self, int i):
if i < 0 or i > 3:
raise KeyError("index must be 0, 1, or 2 but was %d" % i)
return self.thisptr.arr[i]
def __setitem__(self, int i, double v):
if i < 0 or i > 3:
raise KeyError("index must be 0, 1, or 2 but was %d" % i)
self.thisptr.arr[i] = v
def assign(self, Quaterniond other):
self.thisptr.assign(deref(other.thisptr))
def toarray(self):
cdef np.ndarray[double, ndim=1] array = np.empty(4)
cdef int i
for i in range(4):
array[i] = self.thisptr.arr[i]
return array
def fromarray(self, np.ndarray[double, ndim=1] array):
cdef int i
for i in range(4):
self.thisptr.arr[i] = array[i]
def conjugate(self):
conj = Quaterniond()
conj[0] = -self.thisptr.arr[0]
conj[1] = -self.thisptr.arr[1]
conj[2] = -self.thisptr.arr[2]
conj[3] = self.thisptr.arr[3]
return conj
def __mul__(self, Quaterniond other):
cdef Quaterniond result = Quaterniond()
result[0] = self[3] * other[0] + other[3] * self[0] + self[1] * other[2] - self[2] * other[1]
result[1] = self[3] * other[1] + other[3] * self[1] + self[2] * other[0] - self[0] * other[2]
result[2] = self[3] * other[2] + other[3] * self[2] + self[0] * other[1] - self[1] * other[0]
result[3] = self[3] * other[3] - self[0] * other[0] - self[1] * other[1] - self[2] * other[2]
return result
cdef class Pose:
def __cinit__(self):
self.thisptr = NULL
self.delete_thisptr = False
def __dealloc__(self):
if self.thisptr != NULL and self.delete_thisptr:
del self.thisptr
def __init__(self):
self.thisptr = new _cdff_types.asn1SccPose()
self.delete_thisptr = True
def __str__(self):
return "{type: Pose, pos: %s, orient: %s}" % (self.pos, self.orient)
@property
def pos(self):
cdef Vector3d pos = Vector3d()
del pos.thisptr
pos.delete_thisptr = False
pos.thisptr = &self.thisptr.pos
return pos
@property
def orient(self):
cdef Quaterniond orient = Quaterniond()
del orient.thisptr
orient.delete_thisptr = False
orient.thisptr = &self.thisptr.orient
return orient
cdef class TransformWithCovariance_MetadataReference:
def __cinit__(self):
self.thisptr = NULL
def __dealloc__(self):
pass
def __str__(self):
return ("{msg_version: %d, producer_id: %s, parent_frame_id: %s, "
"parent_time: %s, child_frame_id: %s, child_time: %s}"
% (self.thisptr.msgVersion, self.producer_id,
self.parent_frame_id, self.parent_time, self.child_frame_id,
self.child_time))
def _get_msg_version(self):
return self.thisptr.msgVersion
def _set_msg_version(self, uint32_t msg_version):
self.thisptr.msgVersion = msg_version
msg_version = property(_get_msg_version, _set_msg_version)
def _get_producer_id(self):
cdef bytes producer_id = self.thisptr.producerId.arr
return producer_id.decode()
def _set_producer_id(self, str producer_id):
cdef string value = producer_id.encode()
memcpy(self.thisptr.producerId.arr, value.c_str(), len(producer_id))
self.thisptr.producerId.nCount = len(producer_id)
producer_id = property(_get_producer_id, _set_producer_id)
# TODO asn1SccTransformWithCovariance_Metadata_dataEstimated dataEstimated
def _get_parent_frame_id(self):
cdef bytes parent_frame_id = self.thisptr.parentFrameId.arr
return parent_frame_id.decode()
def _set_parent_frame_id(self, str parent_frame_id):
cdef string value = parent_frame_id.encode()
memcpy(self.thisptr.parentFrameId.arr, value.c_str(), len(parent_frame_id))
self.thisptr.parentFrameId.nCount = len(parent_frame_id)
parent_frame_id = property(_get_parent_frame_id, _set_parent_frame_id)
def _get_parent_time(self):
cdef Time parent_time = Time()
del parent_time.thisptr
parent_time.thisptr = &self.thisptr.parentTime
parent_time.delete_thisptr = False
return parent_time
def _set_parent_time(self, Time parent_time):
self.thisptr.parentTime = deref(parent_time.thisptr)
parent_time = property(_get_parent_time, _set_parent_time)
def _get_child_frame_id(self):
cdef bytes child_frame_id = self.thisptr.childFrameId.arr
return child_frame_id.decode()
def _set_child_frame_id(self, str child_frame_id):
cdef string value = child_frame_id.encode()
memcpy(self.thisptr.childFrameId.arr, value.c_str(), len(child_frame_id))
self.thisptr.childFrameId.nCount = len(child_frame_id)
child_frame_id = property(_get_child_frame_id, _set_child_frame_id)
def _get_child_time(self):
cdef Time child_time = Time()
del child_time.thisptr
child_time.thisptr = &self.thisptr.childTime
child_time.delete_thisptr = False
return child_time
def _set_child_time(self, Time child_time):
self.thisptr.childTime = deref(child_time.thisptr)
child_time = property(_get_child_time, _set_child_time)
cdef class TransformWithCovariance_DataReference:
def __cinit__(self):
self.thisptr = NULL
def __dealloc__(self):
pass
def __str__(self):
return ("{translation: %s, orientation: %s, cov: %s}"
% (self.translation, self.orientation, self.cov))
@property
def translation(self):
cdef Vector3d translation = Vector3d()
del translation.thisptr
translation.delete_thisptr = False
translation.thisptr = &self.thisptr.translation
return translation
@property
def orientation(self):
cdef Quaterniond orientation = Quaterniond()
del orientation.thisptr
orientation.delete_thisptr = False
orientation.thisptr = &self.thisptr.orientation
return orientation
@property
def cov(self):
cdef Matrix6d cov = Matrix6d()
del cov.thisptr
cov.delete_thisptr = False
cov.thisptr = &self.thisptr.cov
return cov
cdef class TransformWithCovariance:
def __cinit__(self):
self.thisptr = NULL
self.delete_thisptr = False
def __dealloc__(self):
if self.thisptr != NULL and self.delete_thisptr:
del self.thisptr
def __init__(self):
self.thisptr = new _cdff_types.asn1SccTransformWithCovariance()
self.delete_thisptr = True
def __str__(self):
return ("{metadata: %s, data: %s}"
% (self.metadata, self.data))
@property
def metadata(self):
cdef TransformWithCovariance_MetadataReference metadata = \
TransformWithCovariance_MetadataReference()
metadata.thisptr = &self.thisptr.metadata
return metadata
@property
def data(self):
cdef TransformWithCovariance_DataReference data = \
TransformWithCovariance_DataReference()
data.thisptr = &self.thisptr.data
return data
def from_uper(self, list data):
cdef unsigned char* uper_buffer = <unsigned char*> malloc(
_cdff_types.asn1SccTransformWithCovariance_REQUIRED_BYTES_FOR_ENCODING *
sizeof(unsigned char))
cdef _cdff_types.BitStream* b = new _cdff_types.BitStream()
cdef int i
_cdff_types.BitStream_Init(
b, uper_buffer, _cdff_types.asn1SccTransformWithCovariance_REQUIRED_BYTES_FOR_ENCODING)
for i in range(len(data)):
uper_buffer[i] = data[i]
for i in range(len(data), _cdff_types.asn1SccTransformWithCovariance_REQUIRED_BYTES_FOR_ENCODING):
uper_buffer[i] = 0
cdef int error_code
cdef bool success
success = _cdff_types.asn1SccTransformWithCovariance_Decode(self.thisptr, b, &error_code)
if not success:
raise RuntimeError(
"Conversion from uPER failed, error code: %d" % error_code)
free(uper_buffer)
del b
cdef class PointCloud_Data_pointsReference:
def __cinit__(self):
self.thisptr = NULL
def __dealloc__(self):
pass
def __getitem__(self, tuple indices):
cdef int i, j
i, j = indices
if i < 0 or i >= self.thisptr.nCount:
raise KeyError("index out of range %d" % i)
if j < 0 or j >= 3:
raise KeyError("index out of range %d" % j)
return self.thisptr.arr[i].arr[j]
def __setitem__(self, tuple indices, double v):
cdef int i, j, k
i, j = indices
if self.thisptr.nCount <= i:
self.thisptr.nCount = i + 1
if i < 0 or i >= self.thisptr.nCount:
raise KeyError("index out of range %d" % i)
if j < 0 or j >= 3:
raise KeyError("index out of range %d" % j)
self.thisptr.arr[i].arr[j] = v
@property
def shape(self):
return (self.thisptr.nCount, 3)
def resize(self, int size):
self.thisptr.nCount = size
def size(self):
return self.thisptr.nCount
def fill(self, list data):
cdef int data_len = len(data)
self.resize(data_len)
cdef int i, j
for i in range(data_len):
for j in range(3):
self.thisptr.arr[i].arr[j] = data[i][j]
cdef class PointCloud_Data_colorsReference:
def __cinit__(self):
self.thisptr = NULL
def __dealloc__(self):
pass
def __getitem__(self, tuple indices):
cdef int i, j
i, j = indices
if i < 0 or i >= self.thisptr.nCount:
raise KeyError("index out of range %d" % i)
if j < 0 or j >= 3:
raise KeyError("index out of range %d" % j)
return self.thisptr.arr[i].arr[j]
def __setitem__(self, tuple indices, double v):
cdef int i, j, k
i, j = indices
if self.thisptr.nCount <= i:
self.thisptr.nCount = i + 1
if i < 0 or i >= self.thisptr.nCount:
raise KeyError("index out of range %d" % i)
if j < 0 or j >= 3:
raise KeyError("index out of range %d" % j)
self.thisptr.arr[i].arr[j] = v
@property
def shape(self):
return (self.thisptr.nCount, 3)
def resize(self, int size):
self.thisptr.nCount = size
def size(self):
return self.thisptr.nCount
def fill(self, list data):
cdef int data_len = len(data)
self.resize(data_len)
cdef int i, j
for i in range(data_len):
for j in range(3):
self.thisptr.arr[i].arr[j] = data[i][j]
cdef class PointCloud_Data_intensityReference:
def __cinit__(self):
self.thisptr = NULL
def __dealloc__(self):
pass
def __getitem__(self, int i):
return self.thisptr.arr[i]
def __setitem__(self, int i, int32_t v):
if i >= 400000:
warnings.warn("Maximum size of Pointcloud is %d" % 400000)
return
if self.thisptr.nCount <= i:
self.thisptr.nCount = i + 1
self.thisptr.arr[i] = v
def __len__(self):
return self.thisptr.nCount
def resize(self, int size):
self.thisptr.nCount = size
def size(self):
return self.thisptr.nCount
def fill(self, list data):
cdef int data_len = len(data)
self.resize(data_len)
cdef int i
for i in range(data_len):
self.thisptr.arr[i] = data[i]
cdef class PointCloud_DataReference:
def __cinit__(self):
self.thisptr = NULL
def __dealloc__(self):
pass
def __str__(self):
return ("{points: %d, colors: %d, intensity: %d}"
% (self.points.size(), self.colors.size(),
self.intensity.size()))
@property
def points(self):
cdef PointCloud_Data_pointsReference points = \
PointCloud_Data_pointsReference()
points.thisptr = &self.thisptr.points
return points
@property
def colors(self):
cdef PointCloud_Data_colorsReference colors = \
PointCloud_Data_colorsReference()
colors.thisptr = &self.thisptr.colors
return colors
@property
def intensity(self):
cdef PointCloud_Data_intensityReference intensity = \
PointCloud_Data_intensityReference()
intensity.thisptr = &self.thisptr.intensity
return intensity
cdef class PointCloud_MetadataReference:
def __cinit__(self):
self.thisptr = NULL
def __dealloc__(self):
pass
def __str__(self):
return ("{msg_version: %d, time_stamp: %s, sensor_id: %s, frame_id: %s,"
" height: %d, width: %d, is_registered: %s, is_ordered: %s, "
"has_fixed_transform: %s, pose_fixed_frame_robot_frame: %s}"
% (self.msg_version, self.time_stamp, self.sensor_id,
self.frame_id, self.height, self.width, self.is_registered,
self.is_ordered, self.has_fixed_transform,
self.pose_fixed_frame_robot_frame))
def _get_time_stamp(self):
cdef Time time = Time()
del time.thisptr
time.thisptr = &self.thisptr.timeStamp
time.delete_thisptr = False
return time
def _set_time_stamp(self, Time time):
self.thisptr.timeStamp = deref(time.thisptr)
time_stamp = property(_get_time_stamp, _set_time_stamp)
def _get_msg_version(self):
return self.thisptr.msgVersion