@@ -30,9 +30,17 @@ function findNearestOnAxis(w, arr) {
30
30
for ( var q = arr . length - 1 ; q > 0 ; q -- ) {
31
31
var min = Math . min ( arr [ q ] , arr [ q - 1 ] ) ;
32
32
var max = Math . max ( arr [ q ] , arr [ q - 1 ] ) ;
33
- if ( w <= max && w > min ) return q ;
33
+ if ( max > min && min < w && w <= max ) {
34
+ return {
35
+ id : q ,
36
+ distRatio : ( max - w ) / ( max - min )
37
+ } ;
38
+ }
34
39
}
35
- return 0 ;
40
+ return {
41
+ id : 0 ,
42
+ distRatio : 0
43
+ } ;
36
44
}
37
45
38
46
proto . handlePick = function ( selection ) {
@@ -44,9 +52,9 @@ proto.handlePick = function(selection) {
44
52
var y = this . data . y [ rawId ] ;
45
53
var z = this . data . z [ rawId ] ;
46
54
47
- var i = findNearestOnAxis ( x , this . data . _Xs ) ;
48
- var j = findNearestOnAxis ( y , this . data . _Ys ) ;
49
- var k = findNearestOnAxis ( z , this . data . _Zs ) ;
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 ;
50
58
51
59
var width = this . data . _Xs . length ;
52
60
var height = this . data . _Ys . length ;
@@ -615,14 +623,55 @@ function generateIsosurfaceMesh(data) {
615
623
}
616
624
617
625
function begin2dCell ( style , p00 , p01 , p10 , p11 , min , max , isEven ) {
626
+ // used to create caps and/or slices on exact axis points
618
627
if ( isEven ) {
619
628
addRect ( style , p00 , p01 , p11 , p10 , min , max ) ;
620
629
} else {
621
630
addRect ( style , p01 , p11 , p10 , p00 , min , max ) ;
622
631
}
623
632
}
624
633
634
+ function beginSection ( style , i , j , k , min , max , distRatios ) {
635
+ // used to create slices between axis points
636
+
637
+ var A , B , C , D ;
638
+
639
+ var makeSection = function ( ) {
640
+ tryCreateTri ( style , [ A , B , C ] , [ - 1 , - 1 , - 1 ] , min , max ) ;
641
+ tryCreateTri ( style , [ C , D , A ] , [ - 1 , - 1 , - 1 ] , min , max ) ;
642
+ } ;
643
+
644
+ var rX = distRatios [ 0 ] ;
645
+ var rY = distRatios [ 1 ] ;
646
+ var rZ = distRatios [ 2 ] ;
647
+
648
+ if ( rX ) {
649
+ A = getBetween ( getXYZV ( [ getIndex ( i , j - 0 , k - 0 ) ] ) [ 0 ] , getXYZV ( [ getIndex ( i + 1 , j - 0 , k - 0 ) ] ) [ 0 ] , rX ) ;
650
+ B = getBetween ( getXYZV ( [ getIndex ( i , j - 0 , k - 1 ) ] ) [ 0 ] , getXYZV ( [ getIndex ( i + 1 , j - 0 , k - 1 ) ] ) [ 0 ] , rX ) ;
651
+ C = getBetween ( getXYZV ( [ getIndex ( i , j - 1 , k - 1 ) ] ) [ 0 ] , getXYZV ( [ getIndex ( i + 1 , j - 1 , k - 1 ) ] ) [ 0 ] , rX ) ;
652
+ D = getBetween ( getXYZV ( [ getIndex ( i , j - 1 , k - 0 ) ] ) [ 0 ] , getXYZV ( [ getIndex ( i + 1 , j - 1 , k - 0 ) ] ) [ 0 ] , rX ) ;
653
+ makeSection ( ) ;
654
+ }
655
+
656
+ if ( rY ) {
657
+ A = getBetween ( getXYZV ( [ getIndex ( i - 0 , j , k - 0 ) ] ) [ 0 ] , getXYZV ( [ getIndex ( i - 0 , j + 1 , k - 0 ) ] ) [ 0 ] , rY ) ;
658
+ B = getBetween ( getXYZV ( [ getIndex ( i - 0 , j , k - 1 ) ] ) [ 0 ] , getXYZV ( [ getIndex ( i - 0 , j + 1 , k - 1 ) ] ) [ 0 ] , rY ) ;
659
+ C = getBetween ( getXYZV ( [ getIndex ( i - 1 , j , k - 1 ) ] ) [ 0 ] , getXYZV ( [ getIndex ( i - 1 , j + 1 , k - 1 ) ] ) [ 0 ] , rY ) ;
660
+ D = getBetween ( getXYZV ( [ getIndex ( i - 1 , j , k - 0 ) ] ) [ 0 ] , getXYZV ( [ getIndex ( i - 1 , j + 1 , k - 0 ) ] ) [ 0 ] , rY ) ;
661
+ makeSection ( ) ;
662
+ }
663
+
664
+ if ( rZ ) {
665
+ A = getBetween ( getXYZV ( [ getIndex ( i - 0 , j - 0 , k ) ] ) [ 0 ] , getXYZV ( [ getIndex ( i - 0 , j - 0 , k + 1 ) ] ) [ 0 ] , rZ ) ;
666
+ B = getBetween ( getXYZV ( [ getIndex ( i - 0 , j - 1 , k ) ] ) [ 0 ] , getXYZV ( [ getIndex ( i - 0 , j - 1 , k + 1 ) ] ) [ 0 ] , rZ ) ;
667
+ C = getBetween ( getXYZV ( [ getIndex ( i - 1 , j - 1 , k ) ] ) [ 0 ] , getXYZV ( [ getIndex ( i - 1 , j - 1 , k + 1 ) ] ) [ 0 ] , rZ ) ;
668
+ D = getBetween ( getXYZV ( [ getIndex ( i - 1 , j - 0 , k ) ] ) [ 0 ] , getXYZV ( [ getIndex ( i - 1 , j - 0 , k + 1 ) ] ) [ 0 ] , rZ ) ;
669
+ makeSection ( ) ;
670
+ }
671
+ }
672
+
625
673
function begin3dCell ( style , p000 , p001 , p010 , p011 , p100 , p101 , p110 , p111 , min , max , isEven ) {
674
+ // used to create spaceframe and/or iso-surfaces
626
675
var cellStyle = style ;
627
676
if ( isEven ) {
628
677
if ( drawingSurface && styleIncludes ( style , 'check2' ) ) cellStyle = null ;
@@ -634,7 +683,8 @@ function generateIsosurfaceMesh(data) {
634
683
}
635
684
636
685
function draw2dX ( style , items , min , max ) {
637
- items . forEach ( function ( i ) {
686
+ for ( var q = 0 ; q < items . length ; q ++ ) {
687
+ var i = items [ q ] ;
638
688
for ( var k = 1 ; k < depth ; k ++ ) {
639
689
for ( var j = 1 ; j < height ; j ++ ) {
640
690
begin2dCell ( style ,
@@ -648,11 +698,12 @@ function generateIsosurfaceMesh(data) {
648
698
) ;
649
699
}
650
700
}
651
- } ) ;
701
+ }
652
702
}
653
703
654
704
function draw2dY ( style , items , min , max ) {
655
- items . forEach ( function ( j ) {
705
+ for ( var q = 0 ; q < items . length ; q ++ ) {
706
+ var j = items [ q ] ;
656
707
for ( var i = 1 ; i < width ; i ++ ) {
657
708
for ( var k = 1 ; k < depth ; k ++ ) {
658
709
begin2dCell ( style ,
@@ -666,11 +717,12 @@ function generateIsosurfaceMesh(data) {
666
717
) ;
667
718
}
668
719
}
669
- } ) ;
720
+ }
670
721
}
671
722
672
723
function draw2dZ ( style , items , min , max ) {
673
- items . forEach ( function ( k ) {
724
+ for ( var q = 0 ; q < items . length ; q ++ ) {
725
+ var k = items [ q ] ;
674
726
for ( var j = 1 ; j < height ; j ++ ) {
675
727
for ( var i = 1 ; i < width ; i ++ ) {
676
728
begin2dCell ( style ,
@@ -684,7 +736,7 @@ function generateIsosurfaceMesh(data) {
684
736
) ;
685
737
}
686
738
}
687
- } ) ;
739
+ }
688
740
}
689
741
690
742
function draw3d ( style , min , max ) {
@@ -721,6 +773,39 @@ function generateIsosurfaceMesh(data) {
721
773
drawingSurface = false ;
722
774
}
723
775
776
+ function drawSectionX ( style , items , min , max , distRatios ) {
777
+ for ( var q = 0 ; q < items . length ; q ++ ) {
778
+ var i = items [ q ] ;
779
+ for ( var k = 1 ; k < depth ; k ++ ) {
780
+ for ( var j = 1 ; j < height ; j ++ ) {
781
+ beginSection ( style , i , j , k , min , max , distRatios [ q ] ) ;
782
+ }
783
+ }
784
+ }
785
+ }
786
+
787
+ function drawSectionY ( style , items , min , max , distRatios ) {
788
+ for ( var q = 0 ; q < items . length ; q ++ ) {
789
+ var j = items [ q ] ;
790
+ for ( var i = 1 ; i < width ; i ++ ) {
791
+ for ( var k = 1 ; k < depth ; k ++ ) {
792
+ beginSection ( style , i , j , k , min , max , distRatios [ q ] ) ;
793
+ }
794
+ }
795
+ }
796
+ }
797
+
798
+ function drawSectionZ ( style , items , min , max , distRatios ) {
799
+ for ( var q = 0 ; q < items . length ; q ++ ) {
800
+ var k = items [ q ] ;
801
+ for ( var j = 1 ; j < height ; j ++ ) {
802
+ for ( var i = 1 ; i < width ; i ++ ) {
803
+ beginSection ( style , i , j , k , min , max , distRatios [ q ] ) ;
804
+ }
805
+ }
806
+ }
807
+ }
808
+
724
809
function createRange ( a , b ) {
725
810
var range = [ ] ;
726
811
for ( var q = a ; q < b ; q ++ ) {
@@ -739,7 +824,7 @@ function generateIsosurfaceMesh(data) {
739
824
}
740
825
}
741
826
742
- function voidMain ( ) {
827
+ function drawAll ( ) {
743
828
744
829
emptyVertices ( ) ;
745
830
@@ -793,33 +878,59 @@ function generateIsosurfaceMesh(data) {
793
878
if ( slice . show && slice . fill ) {
794
879
setFill ( slice . fill ) ;
795
880
796
- var indices = [ ] ;
881
+ var exactIndices = [ ] ;
882
+ var ceilIndices = [ ] ;
883
+ var distRatios = [ ] ;
797
884
if ( slice . locations . length ) {
798
885
for ( var q = 0 ; q < slice . locations . length ; q ++ ) {
799
- indices . push (
800
- findNearestOnAxis (
801
- slice . locations [ q ] ,
802
- ( e === 'x' ) ? Xs :
803
- ( e === 'y' ) ? Ys : Zs
804
- )
886
+
887
+ var near = findNearestOnAxis (
888
+ slice . locations [ q ] ,
889
+ ( e === 'x' ) ? Xs :
890
+ ( e === 'y' ) ? Ys : Zs
805
891
) ;
892
+
893
+ if ( near . distRatio === 0 ) {
894
+ exactIndices . push ( near . id ) ;
895
+ } else {
896
+ ceilIndices . push ( near . id ) ;
897
+ if ( e === 'x' ) {
898
+ distRatios . push ( [ near . distRatio , 0 , 0 ] ) ;
899
+ } else if ( e === 'y' ) {
900
+ distRatios . push ( [ 0 , near . distRatio , 0 ] ) ;
901
+ } else {
902
+ distRatios . push ( [ 0 , 0 , near . distRatio ] ) ;
903
+ }
904
+ }
806
905
}
807
906
} else {
808
907
if ( e === 'x' ) {
809
- indices = createRange ( 1 , width - 1 ) ;
908
+ exactIndices = createRange ( 1 , width - 1 ) ;
810
909
} else if ( e === 'y' ) {
811
- indices = createRange ( 1 , height - 1 ) ;
910
+ exactIndices = createRange ( 1 , height - 1 ) ;
812
911
} else {
813
- indices = createRange ( 1 , depth - 1 ) ;
912
+ exactIndices = createRange ( 1 , depth - 1 ) ;
814
913
}
815
914
}
816
915
817
- if ( e === 'x' ) {
818
- draw2dX ( activeStyle , indices , activeMin , activeMax ) ;
819
- } else if ( e === 'y' ) {
820
- draw2dY ( activeStyle , indices , activeMin , activeMax ) ;
821
- } else {
822
- draw2dZ ( activeStyle , indices , activeMin , activeMax ) ;
916
+ if ( ceilIndices . length > 0 ) {
917
+ if ( e === 'x' ) {
918
+ drawSectionX ( activeStyle , ceilIndices , activeMin , activeMax , distRatios ) ;
919
+ } else if ( e === 'y' ) {
920
+ drawSectionY ( activeStyle , ceilIndices , activeMin , activeMax , distRatios ) ;
921
+ } else {
922
+ drawSectionZ ( activeStyle , ceilIndices , activeMin , activeMax , distRatios ) ;
923
+ }
924
+ }
925
+
926
+ if ( exactIndices . length > 0 ) {
927
+ if ( e === 'x' ) {
928
+ draw2dX ( activeStyle , exactIndices , activeMin , activeMax ) ;
929
+ } else if ( e === 'y' ) {
930
+ draw2dY ( activeStyle , exactIndices , activeMin , activeMax ) ;
931
+ } else {
932
+ draw2dZ ( activeStyle , exactIndices , activeMin , activeMax ) ;
933
+ }
823
934
}
824
935
}
825
936
@@ -853,7 +964,7 @@ function generateIsosurfaceMesh(data) {
853
964
data . intensity = allVs ;
854
965
}
855
966
856
- voidMain ( ) ;
967
+ drawAll ( ) ;
857
968
858
969
return data ;
859
970
}
0 commit comments