Skip to content

volume box boundary and half pixel multires shift #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/main/resources/bvv/core/render/sample_volume_blocks.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 );
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/bvv/debug/DebugHalfPixel.java
Original file line number Diff line number Diff line change
@@ -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) );
}
}
Binary file added src/test/resources/halfpixeltest/cliptest1ch.h5
Binary file not shown.
Binary file added src/test/resources/halfpixeltest/cliptest1ch.tif
Binary file not shown.
40 changes: 40 additions & 0 deletions src/test/resources/halfpixeltest/cliptest1ch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<SpimData version="0.2">
<BasePath type="relative">.</BasePath>
<SequenceDescription>
<ImageLoader format="bdv.hdf5">
<hdf5 type="relative">cliptest1ch.h5</hdf5>
</ImageLoader>
<ViewSetups>
<ViewSetup>
<id>0</id>
<name>channel 1</name>
<size>4 2 10</size>
<voxelSize>
<unit>micron</unit>
<size>1.0 1.0 1.0</size>
</voxelSize>
<attributes>
<channel>1</channel>
</attributes>
</ViewSetup>
<Attributes name="channel">
<Channel>
<id>1</id>
<name>1</name>
</Channel>
</Attributes>
</ViewSetups>
<Timepoints type="range">
<first>0</first>
<last>0</last>
</Timepoints>
</SequenceDescription>
<ViewRegistrations>
<ViewRegistration timepoint="0" setup="0">
<ViewTransform type="affine">
<affine>1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0</affine>
</ViewTransform>
</ViewRegistration>
</ViewRegistrations>
</SpimData>