@@ -26,13 +26,15 @@ function IsosurfaceTrace(scene, mesh, uid) {
26
26
27
27
var proto = IsosurfaceTrace . prototype ;
28
28
29
- function findNearestOnAxis ( w , arr ) {
30
- for ( var q = arr . length - 1 ; q > 0 ; q -- ) {
31
- var min = Math . min ( arr [ q ] , arr [ q - 1 ] ) ;
32
- var max = Math . max ( arr [ q ] , arr [ q - 1 ] ) ;
29
+ function findNearestOnAxis ( w , arr , nPoints , nDim , step ) {
30
+ var id = nDim ;
31
+ for ( var q = nPoints - 1 ; q > 0 && id > 0 ; q -= step ) {
32
+ id -- ;
33
+ var min = Math . min ( arr [ q ] , arr [ q - step ] ) ;
34
+ var max = Math . max ( arr [ q ] , arr [ q - step ] ) ;
33
35
if ( max > min && min < w && w <= max ) {
34
36
return {
35
- id : q ,
37
+ id : id ,
36
38
distRatio : ( max - w ) / ( max - min )
37
39
} ;
38
40
}
@@ -52,14 +54,16 @@ proto.handlePick = function(selection) {
52
54
var y = this . data . y [ rawId ] ;
53
55
var z = this . data . z [ rawId ] ;
54
56
55
- var i = findNearestOnAxis ( x , this . data . _Xs ) . id ;
56
- var j = findNearestOnAxis ( y , this . data . _Ys ) . id ;
57
- var k = findNearestOnAxis ( z , this . data . _Zs ) . id ;
57
+ var width = this . data . width ;
58
+ var height = this . data . height ;
59
+ var depth = this . data . depth ;
60
+ var nPoints = width * height * depth ;
58
61
59
- var width = this . data . _Xs . length ;
60
- var height = this . data . _Ys . length ;
62
+ var i = findNearestOnAxis ( x , this . data . x , nPoints , width , 1 + depth * height ) . id ;
63
+ var j = findNearestOnAxis ( y , this . data . y , nPoints , height , 1 + depth ) . id ;
64
+ var k = findNearestOnAxis ( z , this . data . z , nPoints , depth , 1 ) . id ;
61
65
62
- var selectIndex = selection . index = i + width * j + width * height * k ;
66
+ var selectIndex = selection . index = k + depth * j + depth * height * i ;
63
67
64
68
selection . traceCoordinate = [
65
69
this . data . x [ selectIndex ] ,
@@ -150,26 +154,14 @@ function generateIsosurfaceMesh(data) {
150
154
var numVertices ;
151
155
var beginVertextLength ;
152
156
153
- var width = data . x . length ;
154
- var height = data . y . length ;
155
- var depth = data . z . length ;
157
+ var width = data . width ;
158
+ var height = data . height ;
159
+ var depth = data . depth ;
156
160
157
161
function getIndex ( i , j , k ) {
158
- return i + width * j + width * height * k ;
162
+ return k + depth * j + depth * height * i ;
159
163
}
160
164
161
- function copyElements ( src ) {
162
- var dst = [ ] ;
163
- for ( var i = 0 ; i < src . length ; i ++ ) {
164
- dst [ i ] = src [ i ] ;
165
- }
166
- return dst ;
167
- }
168
-
169
- var Xs = copyElements ( data . x ) ;
170
- var Ys = copyElements ( data . y ) ;
171
- var Zs = copyElements ( data . z ) ;
172
-
173
165
var minValues = data . _minValues ;
174
166
var maxValues = data . _maxValues ;
175
167
@@ -384,16 +376,11 @@ function generateIsosurfaceMesh(data) {
384
376
var xyzv = [ ] ;
385
377
for ( var q = 0 ; q < 4 ; q ++ ) {
386
378
var index = indecies [ q ] ;
387
-
388
- var k = Math . floor ( index / ( width * height ) ) ;
389
- var j = Math . floor ( ( index - k * width * height ) / width ) ;
390
- var i = Math . floor ( index - k * width * height - j * width ) ;
391
-
392
379
xyzv . push (
393
380
[
394
- Xs [ i ] ,
395
- Ys [ j ] ,
396
- Zs [ k ] ,
381
+ data . x [ index ] ,
382
+ data . y [ index ] ,
383
+ data . z [ index ] ,
397
384
data . value [ index ]
398
385
]
399
386
) ;
@@ -816,10 +803,16 @@ function generateIsosurfaceMesh(data) {
816
803
}
817
804
818
805
function insertGridPoints ( ) {
819
- for ( var k = 0 ; k < depth ; k ++ ) {
806
+ for ( var i = 0 ; i < width ; i ++ ) {
820
807
for ( var j = 0 ; j < height ; j ++ ) {
821
- for ( var i = 0 ; i < width ; i ++ ) {
822
- addVertex ( Xs [ i ] , Ys [ j ] , Zs [ k ] , data . value [ getIndex ( i , j , k ) ] ) ;
808
+ for ( var k = 0 ; k < depth ; k ++ ) {
809
+ var index = getIndex ( i , j , k ) ;
810
+ addVertex (
811
+ data . x [ index ] ,
812
+ data . y [ index ] ,
813
+ data . z [ index ] ,
814
+ data . value [ index ]
815
+ ) ;
823
816
}
824
817
}
825
818
}
@@ -883,13 +876,19 @@ function generateIsosurfaceMesh(data) {
883
876
var ceilIndices = [ ] ;
884
877
var distRatios = [ ] ;
885
878
if ( slice . locations . length ) {
879
+
886
880
for ( var q = 0 ; q < slice . locations . length ; q ++ ) {
887
881
888
- var near = findNearestOnAxis (
889
- slice . locations [ q ] ,
890
- ( e === 'x' ) ? Xs :
891
- ( e === 'y' ) ? Ys : Zs
892
- ) ;
882
+ var location = slice . locations [ q ] ;
883
+
884
+ var near ;
885
+ if ( e === 'x' ) {
886
+ near = findNearestOnAxis ( location , data . x , width * height * depth , width , 1 + depth * height ) ;
887
+ } else if ( e === 'y' ) {
888
+ near = findNearestOnAxis ( location , data . y , width * height * depth , height , 1 + depth ) ;
889
+ } else {
890
+ near = findNearestOnAxis ( location , data . z , width * height * depth , depth , 1 ) ;
891
+ }
893
892
894
893
if ( near . distRatio === 0 ) {
895
894
exactIndices . push ( near . id ) ;
@@ -955,10 +954,6 @@ function generateIsosurfaceMesh(data) {
955
954
emptyVertices ( ) ;
956
955
}
957
956
958
- data . _Xs = Xs ;
959
- data . _Ys = Ys ;
960
- data . _Zs = Zs ;
961
-
962
957
data . x = allXs ;
963
958
data . y = allYs ;
964
959
data . z = allZs ;
0 commit comments