From a04c5af67a52281b5f8fba16a83aa67ac78e251e Mon Sep 17 00:00:00 2001
From: Stephan Saalfeld <saalfelds@janelia.hhmi.org>
Date: Mon, 24 Apr 2017 18:56:26 -0400
Subject: [PATCH] min intensity hack hot-knife alignment

---
 pom.xml                                       |  4 ++
 src/main/java/bdv/BigDataViewer.java          | 12 +++--
 .../OpenConnectomeImageLoader.java            | 11 +++--
 .../java/bdv/spimdata/tools/MergeExample.java | 33 ++++++++++---
 .../render/AccumulateProjectorARGB.java       | 47 +++++++++++++------
 5 files changed, 79 insertions(+), 28 deletions(-)

diff --git a/pom.xml b/pom.xml
index d3873134..7db091a4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,6 +2,10 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
 
+	<properties>
+		<enforcer.skip>true</enforcer.skip>
+	</properties>
+	
 	<parent>
 		<groupId>sc.fiji</groupId>
 		<artifactId>pom-bigdataviewer</artifactId>
diff --git a/src/main/java/bdv/BigDataViewer.java b/src/main/java/bdv/BigDataViewer.java
index 94100142..2ca42107 100644
--- a/src/main/java/bdv/BigDataViewer.java
+++ b/src/main/java/bdv/BigDataViewer.java
@@ -7,13 +7,13 @@
  * %%
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
- * 
+ *
  * 1. Redistributions of source code must retain the above copyright notice,
  *    this list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright notice,
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -690,7 +690,8 @@ public class BigDataViewer
 //		final String fn = "/Users/Pietzsch/Desktop/bdv example/drosophila 2.xml";
 //		final String fn = "/Users/pietzsch/Desktop/data/clusterValia/140219-1/valia-140219-1.xml";
 //		final String fn = "/Users/Pietzsch/Desktop/data/catmaid.xml";
-		final String fn = "src/main/resources/openconnectome-bock11-neariso.xml";
+//		final String fn2 = "src/main/resources/openconnectome-bock11-neariso.xml";
+		final String fn1 = "/nrs/saalfeld/tomoko/24gb_n_10_l_9_tfac_m5_xlfac_0_ylfac_0_xfac_2_yfac_5_deg_2.xml";
 //		final String fn = "/home/saalfeld/catmaid.xml";
 //		final String fn = "/home/saalfeld/catmaid-fafb00-v9.xml";
 //		final String fn = "/home/saalfeld/catmaid-fafb00-sample_A_cutout_3k.xml";
@@ -712,7 +713,10 @@ public class BigDataViewer
 		{
 			System.setProperty( "apple.laf.useScreenMenuBar", "true" );
 
-			final BigDataViewer bdv = open( fn, new File( fn ).getName(), new ProgressWriterConsole(), ViewerOptions.options() );
+			final BigDataViewer bdv1 = open( fn1, new File( fn1 ).getName(), new ProgressWriterConsole(), ViewerOptions.options() );
+//			final BigDataViewer bdv2 = open( fn2, new File( fn2 ).getName(), new ProgressWriterConsole(), ViewerOptions.options() );
+
+			bdv1.getViewerFrame().setSize( 1248, 656 );
 
 //			DumpInputConfig.writeToYaml( System.getProperty( "user.home" ) + "/.bdv/bdvkeyconfig.yaml", bdv.getViewerFrame() );
 		}
diff --git a/src/main/java/bdv/img/openconnectome/OpenConnectomeImageLoader.java b/src/main/java/bdv/img/openconnectome/OpenConnectomeImageLoader.java
index 263c83fc..3195e850 100644
--- a/src/main/java/bdv/img/openconnectome/OpenConnectomeImageLoader.java
+++ b/src/main/java/bdv/img/openconnectome/OpenConnectomeImageLoader.java
@@ -7,13 +7,13 @@
  * %%
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
- * 
+ *
  * 1. Redistributions of source code must retain the above copyright notice,
  *    this list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright notice,
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -244,7 +244,12 @@ public class OpenConnectomeImageLoader extends AbstractViewerSetupImgLoader< Uns
 	 * Create a {@link VolatileCachedCellImg} backed by the cache. The type
 	 * should be either {@link ARGBType} and {@link VolatileARGBType}.
 	 */
-	protected < T extends NativeType< T > > VolatileCachedCellImg< T, VolatileByteArray > prepareCachedImage( final int timepointId, final int setupId, final int level, final LoadingStrategy loadingStrategy, final T type )
+	protected < T extends NativeType< T > > VolatileCachedCellImg< T, VolatileByteArray > prepareCachedImage(
+			final int timepointId,
+			final int setupId,
+			final int level,
+			final LoadingStrategy loadingStrategy,
+			final T type )
 	{
 		final long[] dimensions = imageDimensions[ level ];
 		final int[] cellDimensions = blockDimensions[ level ];
diff --git a/src/main/java/bdv/spimdata/tools/MergeExample.java b/src/main/java/bdv/spimdata/tools/MergeExample.java
index b31019a3..9091b15b 100644
--- a/src/main/java/bdv/spimdata/tools/MergeExample.java
+++ b/src/main/java/bdv/spimdata/tools/MergeExample.java
@@ -7,13 +7,13 @@
  * %%
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
- * 
+ *
  * 1. Redistributions of source code must retain the above copyright notice,
  *    this list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright notice,
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -31,6 +31,7 @@ package bdv.spimdata.tools;
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -38,10 +39,6 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 
-import mpicbg.spim.data.SpimDataException;
-import mpicbg.spim.data.registration.ViewRegistration;
-import mpicbg.spim.data.registration.ViewRegistrations;
-import mpicbg.spim.data.registration.ViewTransform;
 import bdv.export.ExportMipmapInfo;
 import bdv.export.WriteSequenceToHdf5;
 import bdv.img.hdf5.Hdf5ImageLoader;
@@ -49,6 +46,12 @@ import bdv.img.hdf5.Partition;
 import bdv.spimdata.SequenceDescriptionMinimal;
 import bdv.spimdata.SpimDataMinimal;
 import bdv.spimdata.XmlIoSpimDataMinimal;
+import mpicbg.spim.data.SpimDataException;
+import mpicbg.spim.data.registration.ViewRegistration;
+import mpicbg.spim.data.registration.ViewRegistrations;
+import mpicbg.spim.data.registration.ViewTransform;
+import mpicbg.spim.data.registration.ViewTransformAffine;
+import net.imglib2.realtransform.AffineTransform3D;
 
 /**
  * @author Tobias Pietzsch &lt;tobias.pietzsch@gmail.com&gt;
@@ -136,4 +139,22 @@ public class MergeExample
 		WriteSequenceToHdf5.writeHdf5PartitionLinkFile( seq, newMipmapInfos );
 		io.save( spimData, xmlFilename );
 	}
+
+	public static void main( final String... args ) throws SpimDataException
+	{
+		final AffineTransform3D t1 = new AffineTransform3D();
+		final AffineTransform3D t2 = new AffineTransform3D();
+		t2.set( 70, 0, 3 );
+
+		mergeHdf5Views(
+				Arrays.asList( new String[]{
+					"/groups/saalfeld/home/saalfelds/tmp/dagmar/bdv-26.xml",
+					"/groups/saalfeld/home/saalfelds/tmp/dagmar/bdv-27.xml"
+				} ),
+				Arrays.asList( new ViewTransformAffine[]{
+						new ViewTransformAffine( "t1", t1 ),
+						new ViewTransformAffine( "t2", t2 )
+				} ),
+				"/groups/saalfeld/home/saalfelds/tmp/dagmar/bdv-26-27.xml" );
+	}
 }
diff --git a/src/main/java/bdv/viewer/render/AccumulateProjectorARGB.java b/src/main/java/bdv/viewer/render/AccumulateProjectorARGB.java
index 5d356014..fcc4cb79 100644
--- a/src/main/java/bdv/viewer/render/AccumulateProjectorARGB.java
+++ b/src/main/java/bdv/viewer/render/AccumulateProjectorARGB.java
@@ -7,13 +7,13 @@
  * %%
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
- * 
+ *
  * 1. Redistributions of source code must retain the above copyright notice,
  *    this list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright notice,
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -32,11 +32,11 @@ package bdv.viewer.render;
 import java.util.ArrayList;
 import java.util.concurrent.ExecutorService;
 
+import bdv.viewer.Source;
 import net.imglib2.Cursor;
 import net.imglib2.RandomAccessible;
 import net.imglib2.RandomAccessibleInterval;
 import net.imglib2.type.numeric.ARGBType;
-import bdv.viewer.Source;
 
 public class AccumulateProjectorARGB extends AccumulateProjector< ARGBType, ARGBType >
 {
@@ -68,7 +68,7 @@ public class AccumulateProjectorARGB extends AccumulateProjector< ARGBType, ARGB
 	@Override
 	protected void accumulate( final Cursor< ARGBType >[] accesses, final ARGBType target )
 	{
-		int aSum = 0, rSum = 0, gSum = 0, bSum = 0;
+		int aSum = 0, rSum = 255, gSum = 255, bSum = 255;
 		for ( final Cursor< ARGBType > access : accesses )
 		{
 			final int value = access.get().get();
@@ -76,19 +76,36 @@ public class AccumulateProjectorARGB extends AccumulateProjector< ARGBType, ARGB
 			final int r = ARGBType.red( value );
 			final int g = ARGBType.green( value );
 			final int b = ARGBType.blue( value );
-			aSum += a;
-			rSum += r;
-			gSum += g;
-			bSum += b;
+//			aSum += a;
+//			rSum += r;
+//			gSum += g;
+//			bSum += b;
+			if  (!(r == 0 && g == 0 && b == 0))
+			{
+				aSum = Math.max( aSum, a );
+				rSum = Math.min( rSum, r );
+				gSum = Math.min( gSum, g );
+				bSum = Math.min( bSum, b );
+			}
 		}
-		if ( aSum > 255 )
+		if ( aSum == 0 )
+		{
 			aSum = 255;
-		if ( rSum > 255 )
-			rSum = 255;
-		if ( gSum > 255 )
-			gSum = 255;
-		if ( bSum > 255 )
-			bSum = 255;
+			rSum = 0;
+			gSum = 0;
+			bSum = 0;
+		}
+		else
+		{
+			if ( aSum > 255 )
+				aSum = 255;
+			if ( rSum > 255 )
+				rSum = 255;
+			if ( gSum > 255 )
+				gSum = 255;
+			if ( bSum > 255 )
+				bSum = 255;
+		}
 		target.set( ARGBType.rgba( rSum, gSum, bSum, aSum ) );
 	}
 }
-- 
GitLab