diff --git a/src/main/resources/bvv/core/render/sample_volume_blocks.frag b/src/main/resources/bvv/core/render/sample_volume_blocks.frag index 1348a386..8bc10262 100644 --- a/src/main/resources/bvv/core/render/sample_volume_blocks.frag +++ b/src/main/resources/bvv/core/render/sample_volume_blocks.frag @@ -8,7 +8,7 @@ void intersectBoundingBox( vec4 wfront, vec4 wback, out float tnear, out float t { vec4 mfront = im * wfront; vec4 mback = im * wback; - intersectBox( mfront.xyz, (mback - mfront).xyz, sourcemin, sourcemax, tnear, tfar ); + intersectBox( mfront.xyz, (mback - mfront).xyz, sourcemin-0.5, sourcemax+0.5, tnear, tfar ); } uniform usampler3D lutSampler; @@ -18,7 +18,11 @@ uniform vec3 lutOffset; float sampleVolume( vec4 wpos, sampler3D volumeCache, vec3 cacheSize, vec3 blockSize, vec3 paddedBlockSize, vec3 padOffset ) { - vec3 pos = (im * wpos).xyz + 0.5; + vec3 pos = (im * wpos).xyz ; + vec3 over = pos * step(0.0,pos) - pos; + float zerofade = 1.0; + pos = over + pos; + zerofade = (1.0-over.x)*(1.0-over.y)*(1-over.z); vec3 q = floor( pos / blockSize ) - lutOffset + 0.5; uvec4 lutv = texture( lutSampler, q / lutSize ); @@ -28,5 +32,5 @@ float sampleVolume( vec4 wpos, sampler3D volumeCache, vec3 cacheSize, vec3 block vec3 c0 = B0 + mod( pos * sj, blockSize ) + 0.5 * sj; // + 0.5 ( sj - 1 ) + 0.5 for tex coord offset - return texture( volumeCache, c0 / cacheSize ).r; + return zerofade*texture( volumeCache, c0 / cacheSize ).r; } diff --git a/src/main/resources/bvv/core/render/sample_volume_simple.frag b/src/main/resources/bvv/core/render/sample_volume_simple.frag index e277363e..1dadca3f 100644 --- a/src/main/resources/bvv/core/render/sample_volume_simple.frag +++ b/src/main/resources/bvv/core/render/sample_volume_simple.frag @@ -5,7 +5,7 @@ void intersectBoundingBox( vec4 wfront, vec4 wback, out float tnear, out float t { vec4 mfront = im * wfront; vec4 mback = im * wback; - intersectBox( mfront.xyz, (mback - mfront).xyz, vec3( 0, 0, 0 ), sourcemax, tnear, tfar ); + intersectBox( mfront.xyz, (mback - mfront).xyz, vec3( -0.5, -0.5, -0.5 ), sourcemax+0.5, tnear, tfar ); } uniform sampler3D volume; diff --git a/src/test/java/bvv/debug/DebugHalfPixel.java b/src/test/java/bvv/debug/DebugHalfPixel.java new file mode 100644 index 00000000..c9ffffb2 --- /dev/null +++ b/src/test/java/bvv/debug/DebugHalfPixel.java @@ -0,0 +1,43 @@ +package bvv.debug; + +import java.util.List; + +import net.imglib2.img.Img; +import net.imglib2.img.display.imagej.ImageJFunctions; +import net.imglib2.type.numeric.ARGBType; +import net.imglib2.type.numeric.integer.UnsignedShortType; + +import bdv.spimdata.SpimDataMinimal; +import bdv.spimdata.XmlIoSpimDataMinimal; +import bvv.vistools.Bvv; +import bvv.vistools.BvvFunctions; +import bvv.vistools.BvvHandle; +import bvv.vistools.BvvStackSource; + +import ij.IJ; +import ij.ImagePlus; +import mpicbg.spim.data.SpimDataException; + +public class DebugHalfPixel +{ + public static void main( final String[] args ) + { + //load multires + final String xmlFilename = "src/test/resources/halfpixeltest/cliptest1ch.xml"; + SpimDataMinimal spimData = null; + try { + spimData = new XmlIoSpimDataMinimal().load( xmlFilename ); + } catch (SpimDataException e) { + e.printStackTrace(); + } + List< BvvStackSource< ? > > sources = BvvFunctions.show( spimData ); + sources.get( 0 ).setColor( new ARGBType(0x0000FF00) ); + BvvHandle handle = sources.get( 0 ).getBvvHandle(); + + //load simple stack + final ImagePlus imp = IJ.openImage( "src/test/resources/halfpixeltest/cliptest1ch.tif" ); + final Img< UnsignedShortType > img = ImageJFunctions.wrapShort( imp ); + final BvvStackSource< UnsignedShortType > source = BvvFunctions.show( img, "SimpleStack", Bvv.options().addTo( handle ) ); + source.setColor( new ARGBType(0x00FF0000) ); + } +} diff --git a/src/test/resources/halfpixeltest/cliptest1ch.h5 b/src/test/resources/halfpixeltest/cliptest1ch.h5 new file mode 100644 index 00000000..62b52407 Binary files /dev/null and b/src/test/resources/halfpixeltest/cliptest1ch.h5 differ diff --git a/src/test/resources/halfpixeltest/cliptest1ch.tif b/src/test/resources/halfpixeltest/cliptest1ch.tif new file mode 100644 index 00000000..6e6d51bc Binary files /dev/null and b/src/test/resources/halfpixeltest/cliptest1ch.tif differ diff --git a/src/test/resources/halfpixeltest/cliptest1ch.xml b/src/test/resources/halfpixeltest/cliptest1ch.xml new file mode 100644 index 00000000..c438a6c4 --- /dev/null +++ b/src/test/resources/halfpixeltest/cliptest1ch.xml @@ -0,0 +1,40 @@ + + + . + + + cliptest1ch.h5 + + + + 0 + channel 1 + 4 2 10 + + micron + 1.0 1.0 1.0 + + + 1 + + + + + 1 + 1 + + + + + 0 + 0 + + + + + + 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 + + + +