@@ -29,30 +29,51 @@ import {COORDINATE} from '../constants';
29
29
const DEFAULT_ORIGIN = [ 0 , 0 , 0 ] ;
30
30
31
31
// Export only for testing
32
- export function resolveLinksTransform ( links , streams , streamName ) {
32
+ export function resolveLinksTransform ( links , poses , streamName ) {
33
33
const transforms = [ ] ;
34
- let parentPose = links [ streamName ] && links [ streamName ] . target_pose ;
34
+
35
+ // If streamName has a pose entry, ensure we capture it
36
+ if ( poses [ streamName ] ) {
37
+ transforms . push ( poses [ streamName ] ) ;
38
+ }
35
39
36
40
// TODO(twojtasz): we could cache the resulting transform based on the entry
37
41
// into the link structure.
42
+ let missingPose = '' ;
43
+ let cycleDetected = false ;
44
+ if ( links ) {
45
+ let parentPoseName = links [ streamName ] && links [ streamName ] . target_pose ;
46
+ const seen = new Set ( ) ;
47
+
48
+ // Collect all poses from child to root
49
+ while ( parentPoseName ) {
50
+ cycleDetected = seen . has ( parentPoseName ) ;
51
+ if ( cycleDetected ) {
52
+ break ;
53
+ }
54
+ seen . add ( parentPoseName ) ;
55
+
56
+ if ( ! poses [ parentPoseName ] ) {
57
+ missingPose = parentPoseName ;
58
+ break ;
59
+ }
60
+
61
+ transforms . push ( poses [ parentPoseName ] ) ;
62
+ parentPoseName = links [ parentPoseName ] && links [ parentPoseName ] . target_pose ;
63
+ }
64
+ }
38
65
39
- let missingPose = false ;
66
+ if ( missingPose ) {
67
+ // TODO(twojtasz): report issue
68
+ return null ;
69
+ }
40
70
41
- // Collect all poses from child to root
42
- while ( parentPose ) {
43
- if ( ! streams [ parentPose ] ) {
44
- missingPose = true ;
45
- break ;
46
- }
47
- transforms . push ( streams [ parentPose ] ) ;
48
- parentPose = links [ parentPose ] && links [ parentPose ] . target_pose ;
71
+ if ( cycleDetected ) {
72
+ // TODO(twojtasz): report issue
73
+ return null ;
49
74
}
50
75
51
- // Resolve pose transforms. If missingPose is true, which can happen if a
52
- // persistent link is defined before normal state has been sent, ignore it
53
- // TODO(twojtasz): Flag stream affected by missingPose so it can be reported
54
- // by application
55
- if ( ! missingPose && transforms . length ) {
76
+ if ( transforms . length ) {
56
77
// process from root to child
57
78
return transforms . reduceRight ( ( acc , val ) => {
58
79
return acc . multiplyRight ( new Pose ( val ) . getTransformationMatrix ( ) ) ;
@@ -69,13 +90,14 @@ export function resolveLinksTransform(links, streams, streamName) {
69
90
* streamMetadata - Anym metadata associated with the stream
70
91
* getTransformMatrix - A callback function for when stream metadata specifieds a DYNAMIC coordinate system
71
92
*/
93
+ /* eslint-disable complexity */
72
94
export function resolveCoordinateTransform (
73
95
frame ,
74
96
streamName ,
75
97
streamMetadata = { } ,
76
98
getTransformMatrix
77
99
) {
78
- const { origin, links = { } , streams, transforms = { } , vehicleRelativeTransform} = frame ;
100
+ const { origin, links, poses , streams, transforms = { } , vehicleRelativeTransform} = frame ;
79
101
const { coordinate, transform, pose} = streamMetadata ;
80
102
81
103
let coordinateSystem = COORDINATE_SYSTEM . METER_OFFSETS ;
@@ -105,7 +127,7 @@ export function resolveCoordinateTransform(
105
127
106
128
default :
107
129
case COORDINATE . IDENTITY :
108
- modelMatrix = resolveLinksTransform ( links , streams , streamName ) ;
130
+ modelMatrix = resolveLinksTransform ( links , poses || streams , streamName ) ;
109
131
break ;
110
132
}
111
133
@@ -126,6 +148,7 @@ export function resolveCoordinateTransform(
126
148
modelMatrix
127
149
} ;
128
150
}
151
+ /* eslint-enable complexity */
129
152
130
153
export function positionToLngLat ( [ x , y , z ] , { coordinateSystem, coordinateOrigin, modelMatrix} ) {
131
154
if ( modelMatrix ) {
0 commit comments