1
- import { mat3 , mat4 } from 'gl-matrix' ;
1
+ import { mat3 , mat4 , vec3 } from 'gl-matrix' ;
2
2
3
3
import Constants from 'vtk.js/Sources/Rendering/Core/Glyph3DMapper/Constants' ;
4
4
import macro from 'vtk.js/Sources/macro' ;
5
5
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper' ;
6
6
import vtkMath from 'vtk.js/Sources/Common/Core/Math' ;
7
+ import vtkBoundingBox from 'vtk.js/Sources/Common/DataModel/BoundingBox' ;
7
8
8
9
const { OrientationModes, ScaleModes } = Constants ;
9
10
const { vtkErrorMacro } = macro ;
@@ -69,83 +70,18 @@ function vtkGlyph3DMapper(publicAPI, model) {
69
70
if ( ! idata || ! gdata ) {
70
71
return vtkMath . createUninitializedBounds ( ) ;
71
72
}
72
- const ibounds = idata . getBounds ( ) ;
73
- const gbounds = gdata . getBounds ( ) ;
74
-
75
- const sArray = publicAPI . getScaleArrayData ( ) ;
76
-
77
- // either have to compute the full dataset result
78
- // or use a heuristic. The basic gist is for the
79
- // idata points, place a scaled and oriented glyph
80
- // at that location and then compute the bounds.
81
- // we instead take the input bounds, and add to them
82
- // the maximum scaled glyph bounds for any orientation
83
- // To get any orientation we treat the glyph as a
84
- // sphere about the origin making it rotationally
85
- // invarient
86
- let radius = Math . abs ( gbounds [ 0 ] ) ;
87
- for ( let i = 1 ; i < 6 ; ++ i ) {
88
- if ( Math . abs ( gbounds [ i ] ) > radius ) {
89
- radius = gbounds [ i ] ;
90
- }
91
- }
92
-
93
- // compute the max absolute scale
94
- let scale = 1.0 ;
95
- if ( model . scaling ) {
96
- scale = model . scaleFactor ;
97
- }
98
- if ( sArray && model . scaleMode !== ScaleModes . SCALE_BY_CONSTANT ) {
99
- const numC = sArray . getNumberOfComponents ( ) ;
100
- if ( model . scaleMode === ScaleModes . SCALE_BY_COMPONENTS ) {
101
- let maxScale = 0.0 ;
102
- for ( let i = 0 ; i < numC ; ++ i ) {
103
- const srange = sArray . getRange ( i ) ;
104
- if ( - srange [ 0 ] > maxScale ) {
105
- maxScale = - srange [ 0 ] ;
106
- }
107
- if ( srange [ 1 ] > maxScale ) {
108
- maxScale = srange [ 1 ] ;
109
- }
110
- }
111
- scale *= maxScale ;
112
- } else {
113
- const maxScale = [ ] ;
114
- for ( let i = 0 ; i < numC ; ++ i ) {
115
- const srange = sArray . getRange ( i ) ;
116
- maxScale [ i ] = - srange [ 0 ] ;
117
- if ( srange [ 1 ] > maxScale [ i ] ) {
118
- maxScale [ i ] = srange [ 1 ] ;
119
- }
120
- }
121
- scale *= vtkMath . norm ( maxScale , numC ) ;
122
- }
123
- }
124
-
125
- // if orienting then use the radius
126
- if ( model . orienting ) {
127
- model . bounds [ 0 ] = ibounds [ 0 ] - ( radius * scale ) ;
128
- model . bounds [ 1 ] = ibounds [ 1 ] + ( radius * scale ) ;
129
- model . bounds [ 2 ] = ibounds [ 2 ] - ( radius * scale ) ;
130
- model . bounds [ 3 ] = ibounds [ 3 ] + ( radius * scale ) ;
131
- model . bounds [ 4 ] = ibounds [ 4 ] - ( radius * scale ) ;
132
- model . bounds [ 5 ] = ibounds [ 5 ] + ( radius * scale ) ;
133
- } else { // other wise use the actual glyph
134
- model . bounds [ 0 ] = ibounds [ 0 ] + ( gbounds [ 0 ] * scale ) ;
135
- model . bounds [ 1 ] = ibounds [ 1 ] + ( gbounds [ 1 ] * scale ) ;
136
- model . bounds [ 2 ] = ibounds [ 2 ] + ( gbounds [ 2 ] * scale ) ;
137
- model . bounds [ 3 ] = ibounds [ 3 ] + ( gbounds [ 3 ] * scale ) ;
138
- model . bounds [ 4 ] = ibounds [ 4 ] + ( gbounds [ 4 ] * scale ) ;
139
- model . bounds [ 5 ] = ibounds [ 5 ] + ( gbounds [ 5 ] * scale ) ;
140
- }
141
73
74
+ // first we build the arrays used for the glyphing
75
+ publicAPI . buildArrays ( ) ;
142
76
return model . bounds ;
143
77
} ;
144
78
145
79
publicAPI . buildArrays = ( ) => {
146
80
// if the mtgime requires it, rebuild
147
81
const idata = publicAPI . getInputData ( 0 ) ;
148
- if ( model . buildTime . getMTime ( ) < idata . getMTime ( ) ||
82
+ const gdata = publicAPI . getInputData ( 1 ) ;
83
+ if ( model . buildTime . getMTime ( ) < gdata . getMTime ( ) ||
84
+ model . buildTime . getMTime ( ) < idata . getMTime ( ) ||
149
85
model . buildTime . getMTime ( ) < publicAPI . getMTime ( ) ) {
150
86
const pts = idata . getPoints ( ) . getData ( ) ;
151
87
let sArray = publicAPI . getScaleArrayData ( ) ;
@@ -163,6 +99,21 @@ function vtkGlyph3DMapper(publicAPI, model) {
163
99
sArray = null ;
164
100
}
165
101
102
+ // get the glyph bounds
103
+ const gbounds = gdata . getBounds ( ) ;
104
+ // convert them to 8 points so we can compute the
105
+ // overall bounds while building the arrays
106
+ const corners = [ ] ;
107
+ vtkBoundingBox . getCorners ( gbounds , corners ) ;
108
+ model . bounds [ 0 ] = vtkBoundingBox . INIT_BOUNDS [ 0 ] ;
109
+ model . bounds [ 1 ] = vtkBoundingBox . INIT_BOUNDS [ 1 ] ;
110
+ model . bounds [ 2 ] = vtkBoundingBox . INIT_BOUNDS [ 2 ] ;
111
+ model . bounds [ 3 ] = vtkBoundingBox . INIT_BOUNDS [ 3 ] ;
112
+ model . bounds [ 4 ] = vtkBoundingBox . INIT_BOUNDS [ 4 ] ;
113
+ model . bounds [ 5 ] = vtkBoundingBox . INIT_BOUNDS [ 5 ] ;
114
+
115
+ const tcorner = vec3 . create ( ) ;
116
+
166
117
const oArray = publicAPI . getOrientationArrayData ( ) ;
167
118
168
119
const identity = mat4 . create ( ) ;
@@ -251,6 +202,29 @@ function vtkGlyph3DMapper(publicAPI, model) {
251
202
mat4 . scale ( z , z , scale ) ;
252
203
}
253
204
205
+ // update bounds
206
+ for ( let p = 0 ; p < 8 ; ++ p ) {
207
+ vec3 . transformMat4 ( tcorner , corners [ p ] , z ) ;
208
+ if ( tcorner [ 0 ] < model . bounds [ 0 ] ) {
209
+ model . bounds [ 0 ] = tcorner [ 0 ] ;
210
+ }
211
+ if ( tcorner [ 1 ] < model . bounds [ 2 ] ) {
212
+ model . bounds [ 2 ] = tcorner [ 1 ] ;
213
+ }
214
+ if ( tcorner [ 2 ] < model . bounds [ 4 ] ) {
215
+ model . bounds [ 4 ] = tcorner [ 2 ] ;
216
+ }
217
+ if ( tcorner [ 0 ] > model . bounds [ 1 ] ) {
218
+ model . bounds [ 1 ] = tcorner [ 0 ] ;
219
+ }
220
+ if ( tcorner [ 1 ] > model . bounds [ 3 ] ) {
221
+ model . bounds [ 3 ] = tcorner [ 1 ] ;
222
+ }
223
+ if ( tcorner [ 2 ] > model . bounds [ 5 ] ) {
224
+ model . bounds [ 5 ] = tcorner [ 2 ] ;
225
+ }
226
+ }
227
+
254
228
const n = new Float32Array ( nbuff , i * 36 , 9 ) ;
255
229
mat3 . fromMat4 ( n , z ) ;
256
230
mat3 . invert ( n , n ) ;
@@ -311,6 +285,9 @@ export function extend(publicAPI, model, initialValues = {}) {
311
285
model . buildTime = { } ;
312
286
macro . obj ( model . buildTime , { mtime : 0 } ) ;
313
287
288
+ model . boundsTime = { } ;
289
+ macro . obj ( model . boundsTime , { mtime : 0 } ) ;
290
+
314
291
macro . setGet ( publicAPI , model , [
315
292
'orient' ,
316
293
'orientationArray' ,
0 commit comments