Skip to content
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
5 changes: 4 additions & 1 deletion src/main/java/bvv/core/render/MultiVolumeShaderMip.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public static Map< SegmentType, SegmentTemplate > getDefaultSegments( boolean us
"lutSampler", "blockScales", "lutSize", "lutOffset", "sampleVolume" ) );
segments.put( SegmentType.SampleVolume, new SegmentTemplate(
"sample_volume_simple.frag",
"im", "sourcemax", "intersectBoundingBox",
"im", "sourcemin", "sourcemax", "intersectBoundingBox",
"volume", "sampleVolume" ) );
segments.put( SegmentType.SampleRGBAVolume, new SegmentTemplate(
"sample_volume_simple_rgba.frag",
Expand Down Expand Up @@ -632,20 +632,23 @@ static class VolumeSimpleSegment extends VolumeSegment
{
private final UniformSampler uniformVolumeSampler;
private final UniformMatrix4f uniformIm;
private final Uniform3f uniformSourcemin;
private final Uniform3f uniformSourcemax;

public VolumeSimpleSegment( final SegmentedShader prog, final Segment volume )
{
super( volume );
uniformVolumeSampler = prog.getUniformSampler( volume, "volume" );
uniformIm = prog.getUniformMatrix4f( volume, "im" );
uniformSourcemin = prog.getUniform3f( volume, "sourcemin" );
uniformSourcemax = prog.getUniform3f( volume, "sourcemax" );
}

public void setData( SimpleVolume volume )
{
uniformVolumeSampler.set( volume.getVolumeTexture() );
uniformIm.set( volume.getIms() );
uniformSourcemin.set( volume.getSourceMin() );
uniformSourcemax.set( volume.getSourceMax() );
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/bvv/core/render/SimpleVolume.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public SimpleVolume( final Texture3D texture, final AffineTransform3D sourceTran
this.texture = texture;
this.sourceToWorld = sourceTransform;
this.sourceMax = sourceMax.sub( sourceMin, new Vector3f() );

this.sourceMax.add( 0.5f, 0.5f, 0.5f );
AffineTransform3D t = new AffineTransform3D();
t.translate( sourceMin.x(), sourceMin.y(), sourceMin.z() );
t.preConcatenate( sourceTransform );
Expand Down Expand Up @@ -101,6 +101,11 @@ public double getVoxelSizeInWorldCoordinates()
}
return voxelSize;
}

public Vector3f getSourceMin()
{
return new Vector3f(-0.5f, -0.5f, -0.5f);
}

public Vector3f getSourceMax()
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/bvv/core/render/VolumeBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,15 @@ public Matrix4f getIms()
public Vector3f getSourceLevelMin()
{
final Interval lbb = multiResolutionStack.resolutions().get( baseLevel ).getImage();
final Vector3f sourceLevelMin = new Vector3f( lbb.min( 0 ), lbb.min( 1 ), lbb.min( 2 ) );
final Vector3f sourceLevelMin = new Vector3f( lbb.min( 0 ) - 0.5f, lbb.min( 1 ) - 0.5f, lbb.min( 2 ) - 0.5f );
return sourceLevelMin;
}

// TODO: revise / remove
public Vector3f getSourceLevelMax()
{
final Interval lbb = multiResolutionStack.resolutions().get( baseLevel ).getImage();
final Vector3f sourceLevelMax = new Vector3f( lbb.max( 0 ), lbb.max( 1 ), lbb.max( 2 ) );
final Vector3f sourceLevelMax = new Vector3f( lbb.max( 0 ) + 0.5f, lbb.max( 1 ) + 0.5f, lbb.max( 2 ) + 0.5f );
return sourceLevelMax;
}

Expand Down
5 changes: 2 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 @@ -36,8 +36,7 @@ float sampleVolume( vec4 wpos )
vec3 B0 = lutv.xyz * paddedBlockSize + cachePadOffset;
vec3 sj = blockScales[ lutv.w ];

vec3 c0 = B0 + mod( pos * sj, blockSize ) + 0.5 * sj;
// + 0.5 ( sj - 1 ) + 0.5 for tex coord offset
vec3 c0 = B0 + mod( pos * sj, blockSize );

return texture( volumeCache, c0 / cacheSize ).r;
}
}
3 changes: 2 additions & 1 deletion src/main/resources/bvv/core/render/sample_volume_simple.frag
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
uniform mat4 im;
uniform vec3 sourcemin;
uniform vec3 sourcemax;

void intersectBoundingBox( vec4 wfront, vec4 wback, out float tnear, out float tfar )
{
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, sourcemin, sourcemax, tnear, tfar );
}

uniform sampler3D volume;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
uniform mat4 im;
uniform vec3 sourcemin;
uniform vec3 sourcemax;

void intersectBoundingBox( vec4 wfront, vec4 wback, out float tnear, out float tfar )
{
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, sourcemin, sourcemax, tnear, tfar );
}

uniform sampler3D volume;
Expand Down
36 changes: 36 additions & 0 deletions src/test/java/bvv/debug/DebugSpimData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package bvv.debug;

import java.util.List;

import bdv.spimdata.SpimDataMinimal;
import bdv.spimdata.XmlIoSpimDataMinimal;
import bvv.vistools.Bvv;
import bvv.vistools.BvvFunctions;
import bvv.vistools.BvvOptions;
import bvv.vistools.BvvStackSource;
import mpicbg.spim.data.SpimDataException;

public class DebugSpimData
{
public static void main( final String[] args )
{
final String xmlFilename8bit = "/home/eugene/Desktop/projects/BigTrace/BigTrace_data/t1-head_8bit.xml";
final String xmlFilename16bit = "/home/eugene/Desktop/projects/BVB/points/mastodon/datasethdf5.xml";

SpimDataMinimal spimData8bit = null;
SpimDataMinimal spimData16bit = null;

try {
spimData8bit = new XmlIoSpimDataMinimal().load( xmlFilename8bit );
spimData16bit = new XmlIoSpimDataMinimal().load( xmlFilename16bit );
} catch (SpimDataException e) {
e.printStackTrace();
}
final Bvv bvv = BvvFunctions.show(BvvOptions.options().frameTitle( "Test spimdata" ));
List< BvvStackSource< ? > > bvvSources8bit = BvvFunctions.show( spimData8bit, BvvOptions.options().addTo( bvv ) );
bvvSources8bit.get( 0 ).setDisplayRange( 0, 255 );
List< BvvStackSource< ? > > bvvSources16bit = BvvFunctions.show( spimData16bit, BvvOptions.options().addTo( bvv ) );
bvvSources16bit.get( 0 ).setDisplayRange( 0, 700 );

}
}
85 changes: 85 additions & 0 deletions src/test/java/bvv/debug/GenerateVolumes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package bvv.debug;

import net.imglib2.Cursor;
import net.imglib2.cache.img.ReadOnlyCachedCellImgFactory;
import net.imglib2.cache.img.ReadOnlyCachedCellImgOptions;
import net.imglib2.img.Img;
import net.imglib2.img.array.ArrayImg;
import net.imglib2.img.array.ArrayImgFactory;
import net.imglib2.img.array.ArrayLocalizingCursor;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;

public class GenerateVolumes
{

static < T extends RealType< T > & NativeType< T >> ArrayImg< T, ? > makeSimpleRAI(final T type, final int nEdge, final double minAmp, final double maxAmp, final boolean bConstantMax)
{
final long[] dims = new long[] {nEdge, nEdge, nEdge};
ArrayImgFactory<T> factoryImg = new ArrayImgFactory<>(type);
ArrayImg< T, ? > img = factoryImg.create( dims );
ArrayLocalizingCursor< T > cursor = img.localizingCursor();
double period = nEdge * 0.5 + Math.random() * nEdge * 0.5;

final double [] pos = new double[3];
while(cursor.hasNext())
{
cursor.fwd();
cursor.localize( pos );
if(bConstantMax)
{
cursor.get().setReal( maxAmp );
}
else
{
double val = gyroid(pos, period, minAmp, maxAmp);
cursor.get().setReal( val );
}
}
return img;
}

/** creates a 3D cube volume with nEdge size filled with gyroid in the range of minAmp and maxAmp.
* The period of gyroid randomly varies from 0.5 to 1.0 nEdge
* If bConstantMax is true, single values volume filled with maxAmp**/
static < T extends RealType< T > & NativeType< T >> Img< T > makeCachedCellImg(final T type, final int nEdge, final double minAmp, final double maxAmp, final boolean bConstantMax)
{
final long[] dims = new long[] {nEdge, nEdge, nEdge};
final ReadOnlyCachedCellImgFactory factory = new ReadOnlyCachedCellImgFactory(
ReadOnlyCachedCellImgOptions.options().cellDimensions( 32 ) );
double period = nEdge * 0.5 + Math.random() * nEdge * 0.5;
final Img< T > cellimg = factory.create( dims, type, cell -> {
Cursor< T > cursor = cell.localizingCursor();
final double [] pos = new double[3];
while(cursor.hasNext())
{
cursor.fwd();
cursor.localize( pos );
if( bConstantMax)
{
cursor.get().setReal( maxAmp );
}
else
{
final double val = gyroid(pos, period, minAmp, maxAmp);
cursor.get().setReal( val );
}
}
//Thread.sleep( 80 );
});

return cellimg;
}


static double gyroid(final double [] pos, final double period, final double minAmp, final double maxAmp)
{
double w = 2.0 * Math.PI / period;

double g = Math.sin(pos[0] * w ) * Math.cos(pos[1] * w)
+ Math.sin(pos[1] * w ) * Math.cos(pos[2] * w )
+ Math.sin(pos[2] * w ) * Math.cos(pos[0] * w );
g = Math.pow((Math.tanh( g ) + 1) * 0.5, 7);
return g * (maxAmp - minAmp) + minAmp;
}
}
45 changes: 45 additions & 0 deletions src/test/java/bvv/debug/TestHalfPixel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package bvv.debug;

import net.imglib2.RandomAccessibleInterval;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.type.numeric.integer.UnsignedByteType;
import net.imglib2.type.numeric.integer.UnsignedShortType;

import bdv.util.volatiles.VolatileViews;
import bvv.vistools.Bvv;
import bvv.vistools.BvvFunctions;
import bvv.vistools.BvvOptions;
import bvv.vistools.BvvStackSource;

public class TestHalfPixel
{
public static void main( final String[] args )
{
Bvv bvv = BvvFunctions.show( BvvOptions.options().frameTitle( "Test half pixel" ));
UnsignedByteType type = new UnsignedByteType();
final int nFillValue = 255;

//UnsignedShortType type = new UnsignedShortType();
//final int nFillValue = 65535;

int nEdge = 3;
//make a 5x5 constant intensity blocks
final RandomAccessibleInterval< ? > rai = GenerateVolumes.makeSimpleRAI(type, nEdge, 0, nFillValue, true );
final RandomAccessibleInterval< ? > cachedRai = GenerateVolumes.makeCachedCellImg(type, nEdge, 0, nFillValue, true );

BvvStackSource< ? > raiCS = BvvFunctions.show( rai,
"simple RAI",
BvvOptions.options().addTo( bvv ));
AffineTransform3D t = new AffineTransform3D();
t.translate( nEdge, 0.0, 0.0 );

BvvStackSource< ? > cachedRaiCS = BvvFunctions.show( VolatileViews.wrapAsVolatile(cachedRai),
"cached RAI",
BvvOptions.options().addTo( bvv ).sourceTransform( t ));
AffineTransform3D viewT = bvv.getBvvHandle().getViewerPanel().state().getViewerTransform();
viewT.scale( 0.5 );
viewT.translate( 80., 140.0, 0.0 );
bvv.getBvvHandle().getViewerPanel().state().setViewerTransform( viewT );

}
}
Loading