Commit f18da390 authored by rhaase's avatar rhaase

initial version

parents
/.idea/
*.iml
/target/
mvn -Denforcer.skip install
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>net.imagej</groupId>
<artifactId>pom-imagej</artifactId>
<version>7.1.0</version>
</parent>
<groupId>mpicbg_scicomp_imgTools</groupId>
<artifactId>mpicbg_scicomp_surface_manager</artifactId>
<version>1.0.35s</version>
<name>SciComp_MPI-CBG_Common_Packages</name>
<description>
Reusable tools from BIIS
</description>
<dependencies>
<dependency>
<groupId>net.imagej</groupId>
<artifactId>ij</artifactId>
</dependency>
<dependency>
<groupId>net.imagej</groupId>
<artifactId>imagej</artifactId>
</dependency>
<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2-ij</artifactId>
</dependency>
<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2</artifactId>
</dependency>
<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2-algorithm</artifactId>
</dependency>
<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2-script</artifactId>
</dependency>
<!-- Dependencies for StackRotatePlugin (at least) -->
<dependency>
<groupId>mpicbg</groupId>
<artifactId>mpicbg</artifactId>
</dependency>
<!-- Dependency for running automated test -->
<dependency>
<groupId>org.kie.modules</groupId>
<artifactId>org-junit</artifactId>
<version>6.2.0.Final</version>
<type>pom</type>
</dependency>
<!-- Dependency for SurfaceManager and Label3DManager (Rather: String utilities) -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<!-- Dependency to use GenericDialogPlus -->
<dependency>
<groupId>sc.fiji</groupId>
<artifactId>Fiji_Plugins</artifactId>
<version>3.1.1</version>
</dependency>
<!-- Dependency for Surface Manager to get access to the 3D Viewer -->
<dependency>
<groupId>sc.fiji</groupId>
<artifactId>3D_Viewer</artifactId>
<version>3.1.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>java3d</groupId>
<artifactId>vecmath</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>java3d</groupId>
<artifactId>j3d-core-utils</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>java3d</groupId>
<artifactId>j3d-core</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.jogamp.joal</groupId>
<artifactId>joal-main</artifactId>
<version>2.3.1</version>
</dependency>
<!-- <dependency>
<groupId>org.python</groupId>
<artifactId>jython</artifactId>
<version>2.5.0</version>
</dependency> -->
<!-- Test dependency for UserInterface Stuff -->
<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2-ui</artifactId>
</dependency>
<!-- Dependency for univariate interpolator -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.4.1</version>
</dependency>
<!-- Dependency for working with the big data viewer -->
<dependency>
<groupId>sc.fiji</groupId>
<artifactId>bigdataviewer_fiji</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.scijava</groupId>
<artifactId>vecmath</artifactId>
<version>1.6.0-scijava-2</version>
</dependency>
</dependencies>
<developers>
<developer>
<id>haesleinhuepf</id>
<name>Robert Haase</name>
<email>rhaase@mpi-cbg.de</email>
<organization>Scientific Computing Facility, MPI CBG Dresden</organization>
<url>https://github.com/haesleinhuepf</url>
<roles>
<role>founder</role>
<role>developer</role>
<role>debugger</role>
<role>reviewer</role>
<role>support</role>
<role>maintainer</role>
</roles>
</developer>
<developer>
<name>Benoit Lombardot</name>
<url>http://imagej.net/User:Benoit</url>
<organization>Scientific Computing Facility, MPI CBG Dresden</organization>
<roles>
<role>lead</role>
<role>debugger</role>
<role>reviewer</role>
</roles>
<properties><id>Benoit</id></properties>
</developer>
</developers>
<repositories>
<!-- NB: for project parent -->
<repository>
<id>imagej.public</id>
<url>http://maven.imagej.net/content/groups/public</url>
</repository>
</repositories>
<!--
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
-->
</project>
package ij.plugin.frame;
/**
* This class is a workaround to get public access to the Roi managers open(filename) method.
* This was needed to allow SurfaceManager and Label3DManager to load ZIP files.
*
* Furthermore, this class implements a correct Singleton.
*
* @author Robert Haase, Scientific Computing Facility, MPI CBG, rhaase@mpi-cbg.de
* @version 1.0.1, 2015-08-26
*/
public class ModRoiManager extends RoiManager {
private static ModRoiManager instance = null;
/**
*
*/
private static final long serialVersionUID = 8262679514562244550L;
public void open(String path)
{
super.open(path);
}
/**
* Singleton implementation
* @return This function ALWAYS returns a ModRoiManager. If there is no instance, it will create one and return it.
*/
public static ModRoiManager getInstance()
{
synchronized (ModRoiManager.class)
{
if (instance == null)
{
instance = new ModRoiManager();
}
}
return instance;
}
public void close()
{
super.close();
if (instance == this)
{
instance = null;
}
}
}
package mpicbg_scicomp.imgTools.SandBox;
import java.util.ArrayList;
import mpicbg.models.InverseCoordinateTransform;
import mpicbg.models.NotEnoughDataPointsException;
import mpicbg.models.Point;
import mpicbg.models.PointMatch;
import mpicbg.models.RigidModel2D;
import mpicbg_scicomp.imgTools.core.util.DebugHelper;
/**
* Copyright 2018 Max Planck Institute of Molecular Cell Biology and Genetics,
* Dresden, Germany
*
* 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.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* 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
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
public class RigidPointListRegistrationDeterminer {
private RigidModel2D ict;
private ArrayList<Point> sourcePoints;
private ArrayList<Point> targetPoints;
boolean validResult = false;
public RigidPointListRegistrationDeterminer(ArrayList<Point> sourcePoints, ArrayList<Point> targetPoints, RigidModel2D ict)
{
this.ict = ict;
this.sourcePoints = sourcePoints;
this.targetPoints = targetPoints;
}
public RigidModel2D getTransformation()
{
if (!validResult)
{
ArrayList< PointMatch > matches = new ArrayList< PointMatch >();
for (int i = 0; i < sourcePoints.size(); i++)
{
matches.add(new PointMatch(sourcePoints.get(i), targetPoints.get(i)));
}
try
{
ict.fit( matches );
}
catch ( final NotEnoughDataPointsException e )
{
DebugHelper.print(this, "Not enough landmarks selected to find a transformation model." );
return null;
}
validResult = true;
}
//ict.preConcatenate(model);
return ict;
}
}
package mpicbg_scicomp.imgTools.SandBox;
import mpicbg.ij.InverseTransformMapping;
import mpicbg.ij.Mapping;
import mpicbg.models.InverseCoordinateTransform;
import mpicbg.models.RigidModel2D;
import ij.process.ImageProcessor;
/**
* Copyright 2018 Max Planck Institute of Molecular Cell Biology and Genetics,
* Dresden, Germany
*
* 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.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* 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
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
public class RigidRegistrationApplyer {
private ImageProcessor ip;
private RigidModel2D model;
private boolean interpolate;
ImageProcessor ipTarget = null;
public RigidRegistrationApplyer(ImageProcessor ip, RigidModel2D model, boolean interpolate)
{
this.ip = ip;
this.model = model;
this.interpolate = interpolate;
}
public ImageProcessor getTransformedImage()
{
if (ipTarget == null)
{
ImageProcessor ipSource = ip;
ipTarget = ipSource.createProcessor( ip.getWidth(), ip.getHeight() );
Mapping< InverseCoordinateTransform > mapping = new InverseTransformMapping< InverseCoordinateTransform >( model );
if ( interpolate ){
ipSource.setInterpolationMethod( ImageProcessor.BILINEAR );
mapping.mapInterpolated( ipSource, ipTarget );
}
else{
mapping.map( ipSource, ipTarget );
}
}
return ipTarget;
}
}
package mpicbg_scicomp.imgTools.analysis;
import mpicbg_scicomp.imgTools.core.PointN;
import mpicbg_scicomp.imgTools.core.util.ArrayUtilities;
/**
* The pointlist analyser is thought to deliver statistical information from point lists. Theoretically, Pearson coefficients are thinkable,
* but for the moment, just the distance between the points is analysed. Add whatever tools come to your mind.
*
*
*
* @author Robert Haase, Scientific Computing Facility, MPI CBG, rhaase@mpi-cbg.de
* @version 1.0.0, 2015-09-09
*
* Copyright 2018 Max Planck Institute of Molecular Cell Biology and Genetics,
* Dresden, Germany
*
* 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.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* 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
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
public class PointListAnalyser {
private PointN[] pointlist = null;
private float[][] distanceMatrix = null;
/**
* Constructor using an array in the form
* <pre>
* {
* {point1_x, point1_y, point1_z, ...},
* {point2_x, point2_y, point2_z, ...},
* ...
* }
* </pre>
* @param pointlist
*/
public PointListAnalyser(float[][] pointlist)
{
initialize(pointlist, true);
}
/**
* Constructor. If pointlistFirstDimensionsLast == true, then the constructor expects an array in the form
* <pre>
* {
* {point1_x, point1_y, point1_z, ...},
* {point2_x, point2_y, point2_z, ...},
* ...
* }
* </pre>
*
* If pointlistFirstDimensionsLast == false, the form of the array should be:
*
* <pre>
* {
* {point1_x, point2_x, point3_x, ...}
* {point1_y, point2_y, point3_y, ...}
* {point1_z, point2_z, point3_z, ...}
* ...
* }
* </pre>
*
*
* @param pointlist
*/
public PointListAnalyser(float[][] pointlist, boolean pointlistFirstDimensionsLast)
{
initialize(pointlist, pointlistFirstDimensionsLast);
}
/**
* Internal initialisation; handling point arrays
* @param pointlist
* @param pointlistFirstDimensionsLast
*/
private void initialize(float[][] pointlist, boolean pointlistFirstDimensionsLast)
{
if (pointlist.length == 0)
{
//Init failed: got an empty list :(
return;
}
int numPoints;
int dimensions;
if (pointlistFirstDimensionsLast)
{
numPoints = pointlist.length;
dimensions = pointlist[0].length;
}
else
{
numPoints = pointlist[0].length;
dimensions = pointlist.length;
}
this.pointlist = new PointN[numPoints];
for (int i = 0; i < numPoints; i++)
{
if (pointlistFirstDimensionsLast)
{
this.pointlist[i] = new PointN(ArrayUtilities.typeConvertToDouble(pointlist[i]));
}
else
{
double[] temp = new double[dimensions];
for (int j = 0; j < dimensions; j++)
{
temp[j] = pointlist[j][i];
}
this.pointlist[i] = new PointN(temp);
}
}
}
/**
* Internally built up a n*n matrix storing the distance between all of the points to each other. Of course, the diagonal in this matrix will be equal to zero.
*/
private void buildDistanceMatrix()
{
if (distanceMatrix == null)
{
distanceMatrix = new float[pointlist.length][pointlist.length];
for (int i = 0; i < pointlist.length; i++)
{
//DebugHelper.print(this, "" + pointlist[i].getPosition()[0] +" " + pointlist[i].getPosition()[1]);
for (int j = i; j < pointlist.length; j++)
{
if (i == j)
{
distanceMatrix[i][j] = 0;
}
else
{
distanceMatrix[i][j] = (float)pointlist[i].getDistanceTo(pointlist[j]);
distanceMatrix[j][i] = distanceMatrix[i][j];
}
}
}
}
}
/**
* calculate the average distance between each point and his n closest neighbors.
*
* @param n number of closest neighbors to be taken into account
* @return average distance to these neighbors
*/
public float[] getAverageDistanceOfNClosestPoints(int n)
{
buildDistanceMatrix();
float[] result = new float[pointlist.length];
float[] closestDistances = new float[n];
for (int i = 0; i < pointlist.length; i++)
{
for (int k = 0; k < n; k++)
{
closestDistances[k] = Float.MAX_VALUE;
}
for (int j = 0; j < pointlist.length; j++)
{
if (i != j)
{
for (int k = 0; k < n; k++)
{
if (closestDistances[k] > distanceMatrix[i][j])
{
ArrayUtilities.insertAndShiftBehind(closestDistances, k, distanceMatrix[i][j]);
break;
}
}
}
}
float sum = 0;
for (int k = 0; k < n; k++)
{
sum += closestDistances[k];
}
//DebugHelper.print(this, "" + sum);
result[i] = sum / n;
}
return result;
}
/**
* Returns an array which contains the number of points which are nearer than maximumDistance for every point given in the constructor.
* @param maximumDistance
* @return a long array containing point counts
*/
public long[] getNumberOfPointsNearerAs(double maximumDistance)
{
buildDistanceMatrix();
long[] result = new long[pointlist.length];
for (int i = 0; i < pointlist.length; i++)
{
result[i] = 0;
for (int j = 0; j < pointlist.length; j++)
{
if (i != j)
{
if (distanceMatrix[i][j] <= maximumDistance)
{
result[i] ++;
}
}
}
}
return result;
}
}
package mpicbg_scicomp.imgTools.analysis;
import ij.measure.Calibration;
import java.io.IOException;
import java.util.ArrayList;
import mpicbg_scicomp.imgTools.core.Point3D;
import mpicbg_scicomp.imgTools.core.PolylineSurface;
import mpicbg_scicomp.imgTools.core.Triangle3D;
import mpicbg_scicomp.imgTools.core.util.PointListToTriangleConverter;
/**
* This class allows calculation the area of a surface defined by polylines (class PolylineSurface).
*
* It goes through pairs for neighbouring polylines (e.g. one one slice 1 and the next one on slice 9),
* searches for triangles connecting the points of the polylines and calculates and sums up the
* area of these triangles.
*
* <b>Note:</b> While the class expects a PolylineSurface managing pixel-coordinates, it returns the area
* in physical units. To measure the area in pixel-units, hand over a Calibration with pixelWidth = pixelHeight = pixelDepth = 1.
*
*
* @author Robert Haase, Scientific Computing Facility, MPI CBG, rhaase@mpi-cbg.de
* @version 1.0.0, 2015-06-17
*
* Copyright 2018 Max Planck Institute of Molecular Cell Biology and Genetics,
* Dresden, Germany
*
* 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.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* 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
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)