@@ -31,15 +31,13 @@ function IsosurfaceTrace(scene, mesh, uid) {
3131
3232var proto = IsosurfaceTrace . prototype ;
3333
34- function findNearestOnAxis ( w , arr , nPoints , nDim , step ) {
35- var id = nDim ;
36- for ( var q = nPoints - 1 ; q > 0 && id > 0 ; q -= step ) {
37- id -- ;
38- var min = Math . min ( arr [ q ] , arr [ q - step ] ) ;
39- var max = Math . max ( arr [ q ] , arr [ q - step ] ) ;
34+ function findNearestOnAxis ( w , arr ) {
35+ for ( var q = arr . length - 1 ; q > 0 ; q -- ) {
36+ var min = Math . min ( arr [ q ] , arr [ q - 1 ] ) ;
37+ var max = Math . max ( arr [ q ] , arr [ q - 1 ] ) ;
4038 if ( max > min && min < w && w <= max ) {
4139 return {
42- id : id ,
40+ id : q ,
4341 distRatio : ( max - w ) / ( max - min )
4442 } ;
4543 }
@@ -59,14 +57,12 @@ proto.handlePick = function(selection) {
5957 var y = this . data . y [ rawId ] ;
6058 var z = this . data . z [ rawId ] ;
6159
62- var width = this . data . width ;
63- var height = this . data . height ;
64- var depth = this . data . depth ;
65- var nPoints = width * height * depth ;
60+ var height = this . data . _Ys . length ;
61+ var depth = this . data . _Zs . length ;
6662
67- var i = findNearestOnAxis ( x , this . data . x , nPoints , width , 1 + depth * height ) . id ;
68- var j = findNearestOnAxis ( y , this . data . y , nPoints , height , 1 + depth ) . id ;
69- var k = findNearestOnAxis ( z , this . data . z , nPoints , depth , 1 ) . id ;
63+ var i = findNearestOnAxis ( x , this . data . _Xs ) . id ;
64+ var j = findNearestOnAxis ( y , this . data . _Ys ) . id ;
65+ var k = findNearestOnAxis ( z , this . data . _Zs ) . id ;
7066
7167 var selectIndex = selection . index = k + depth * j + depth * height * i ;
7268
@@ -888,16 +884,11 @@ function generateIsosurfaceMesh(data) {
888884
889885 for ( var q = 0 ; q < slice . locations . length ; q ++ ) {
890886
891- var location = slice . locations [ q ] ;
892-
893- var near ;
894- if ( e === 'x' ) {
895- near = findNearestOnAxis ( location , data . x , width * height * depth , width , 1 + depth * height ) ;
896- } else if ( e === 'y' ) {
897- near = findNearestOnAxis ( location , data . y , width * height * depth , height , 1 + depth ) ;
898- } else {
899- near = findNearestOnAxis ( location , data . z , width * height * depth , depth , 1 ) ;
900- }
887+ var near = findNearestOnAxis (
888+ slice . locations [ q ] ,
889+ ( e === 'x' ) ? Xs :
890+ ( e === 'y' ) ? Ys : Zs
891+ ) ;
901892
902893 if ( near . distRatio === 0 ) {
903894 exactIndices . push ( near . id ) ;
@@ -967,6 +958,10 @@ function generateIsosurfaceMesh(data) {
967958 data . y = allYs ;
968959 data . z = allZs ;
969960 data . intensity = allVs ;
961+
962+ data . _Xs = Xs ;
963+ data . _Ys = Ys ;
964+ data . _Zs = Zs ;
970965 }
971966
972967 drawAll ( ) ;
0 commit comments