-
Notifications
You must be signed in to change notification settings - Fork 5
Registration of Two Lineages #10
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
Merged
Merged
Changes from 35 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
299fe30
Add coding style
maarzt ad15427
Add a plugin for lineage registration based on spindle directions
maarzt 99974b7
LineageRegistrationAlgorithm: add getMapping() method
maarzt 96e16b2
Refactor EstimateTransform & reduce dependencies
maarzt f0b4149
Rename RootsPairing.pairRoots
maarzt 9258efc
Improve and fix LineageRegistrationDialog
maarzt ca09963
Change LineageTreeUtils.getBranchEnd to not allocation memory
maarzt a50b0a6
Change test methods to meet reviewers comments
maarzt 2ad057e
Add and improve javadoc
maarzt eee66e5
Make the LineageRegistrationPlugin an independent MamutPlugin
maarzt 2a9ae00
LineageRegistrationDialog: allow selection of two open Mastodon projects
maarzt 14d654b
Add functionality for the coloring of lineages
maarzt 310b881
Extract method to sort TrackScheme from LineageRegistrationAlgorithm
maarzt bb00599
Add buttons for tagging unmatched and flipped branches
maarzt 2e7be5f
Implement tagging of unmatched and flipped branches
maarzt 742c109
Allow to copy tag set from one mastodon project to a registered project
maarzt f660888
Add code that allows to couple the focused spot etc. of two MastodonA…
maarzt d321f80
Add buttons to the LineageRegistrationDialog that allow to couple the…
maarzt a844f5b
LineageRegistrationAlgorithm: make run method public
maarzt 0b59966
Introduce class TagSetUtils
maarzt 1dc9b20
Remove LineageTreeUtils.getBranchEnd in favor of BranchGraphUtils.get…
maarzt 291f73e
LineageRegistrationAlgorithmTest: extract tests for LineageRegistrati…
maarzt 1769601
Acquire locks and set undo points for operations on the ModelGraph an…
maarzt 271dbf9
Update the description text in the lineage registration dialog
maarzt 4b08f00
Remove the incomplete "improve window titles" functionality
maarzt 03a9186
Improve the names of created tag sets in LineageRegistrationUtils
maarzt c2a1c62
LineageRegistrationDialog: add tool tip texts to the buttons
maarzt 3097071
LineageRegistrationDialog: use the lock icon for the sync group buttons
maarzt 39ec173
LineageRegistrationDialog: only enable buttons if two projects are se…
maarzt 5cce342
LineageRegistrationPlugin: rename the menu entry
maarzt 7fb432d
LineageRegistration: add javadoc
maarzt 6cabc68
LineageRegistrationControlService: bring dialog to the front when req…
maarzt 6fd49cc
LineageRegistrationDialog: let it extend JFrame instead of JDialog
maarzt 04dd5ce
LineageRegistrationFrame: Improve tool tip text
maarzt 8c723bf
LineageRegistration: update BranchGraph after sorting the TrackScheme
maarzt 0e406cd
LineageRegistrationPlugin: change which cells are tagges as flipped.
maarzt 4dcd974
LineageResgistration: add a log window to give the user more feedback
maarzt 38d6faa
RefMapUtils: update TODO comment
maarzt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
src/main/java/org/mastodon/mamut/tomancak/lineage_registration/BranchGraphUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| /*- | ||
| * #%L | ||
| * A Mastodon plugin data allows to show the embryo in Blender. | ||
| * %% | ||
| * Copyright (C) 2022 - 2023 Matthias Arzt | ||
| * %% | ||
| * 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 | ||
| * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS 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. | ||
| * #L% | ||
| */ | ||
| package org.mastodon.mamut.tomancak.lineage_registration; | ||
|
|
||
| import net.imglib2.util.Pair; | ||
| import net.imglib2.util.ValuePair; | ||
|
|
||
| import org.mastodon.collection.RefList; | ||
| import org.mastodon.collection.RefSet; | ||
| import org.mastodon.collection.ref.RefArrayList; | ||
| import org.mastodon.collection.ref.RefSetImp; | ||
| import org.mastodon.mamut.model.Link; | ||
| import org.mastodon.mamut.model.ModelGraph; | ||
| import org.mastodon.mamut.model.Spot; | ||
|
|
||
| public class BranchGraphUtils | ||
| { | ||
| private BranchGraphUtils() | ||
| { | ||
| // prevent instantiation | ||
| } | ||
|
|
||
| public static Spot getBranchStart( Spot spot, Spot ref ) | ||
| { | ||
| Spot s = spot; | ||
| while ( s.incomingEdges().size() == 1 ) | ||
| { | ||
| Link edge = s.incomingEdges().iterator().next(); | ||
| s = edge.getSource( ref ); | ||
| if ( s.outgoingEdges().size() != 1 ) | ||
| return edge.getTarget( ref ); | ||
| } | ||
| return s; | ||
| } | ||
|
|
||
| public static Spot getBranchEnd( Spot spot, Spot ref ) | ||
| { | ||
| Spot s = spot; | ||
| while ( s.outgoingEdges().size() == 1 ) | ||
| { | ||
| Link edge = s.outgoingEdges().iterator().next(); | ||
| s = edge.getTarget( ref ); | ||
| if ( s.incomingEdges().size() != 1 ) | ||
| return edge.getSource( ref ); | ||
| } | ||
| return s; | ||
| } | ||
|
|
||
| static Spot findVertexForTimePoint( Spot branchStart, int timePoint, Spot ref ) | ||
| { | ||
| Spot spot = branchStart; | ||
| if ( spot.getTimepoint() >= timePoint ) | ||
| return spot; | ||
| while ( spot.outgoingEdges().size() == 1 ) | ||
| { | ||
| spot = spot.outgoingEdges().iterator().next().getTarget( ref ); | ||
| if ( spot.getTimepoint() >= timePoint ) | ||
| return spot; | ||
| } | ||
| return spot; | ||
| } | ||
|
|
||
| static Pair< RefList< Spot >, RefList< Link > > getBranchSpotsAndLinks( ModelGraph graph, Spot branchStart ) | ||
| { | ||
| RefList< Link > links = new RefArrayList<>( graph.edges().getRefPool() ); | ||
| RefList< Spot > spots = new RefArrayList<>( graph.vertices().getRefPool() ); | ||
| spots.add( branchStart ); | ||
| Spot ref = graph.vertexRef(); | ||
| Spot spot = branchStart; | ||
| while ( spot.outgoingEdges().size() == 1 ) | ||
| { | ||
| Link link = spot.outgoingEdges().iterator().next(); | ||
| spot = link.getTarget( ref ); | ||
| if ( spot.incomingEdges().size() != 1 ) | ||
| break; | ||
| links.add( link ); | ||
| spots.add( spot ); | ||
| } | ||
| graph.releaseRef( ref ); | ||
| return new ValuePair<>( spots, links ); | ||
| } | ||
|
|
||
| static RefSet< Spot > getAllBranchStarts( ModelGraph graph ) | ||
| { | ||
| Spot ref = graph.vertexRef(); | ||
| try | ||
| { | ||
| RefSet< Spot > set = new RefSetImp<>( graph.vertices().getRefPool() ); | ||
| for ( Spot spot : graph.vertices() ) | ||
| { | ||
| if ( spot.incomingEdges().size() != 1 ) | ||
| set.add( spot ); | ||
| if ( spot.outgoingEdges().size() > 1 ) | ||
| for ( Link link : spot.outgoingEdges() ) | ||
| set.add( link.getTarget( ref ) ); | ||
| } | ||
| return set; | ||
| } | ||
| finally | ||
| { | ||
| graph.releaseRef( ref ); | ||
| } | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/mastodon/mamut/tomancak/lineage_registration/ClosableLock.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package org.mastodon.mamut.tomancak.lineage_registration; | ||
|
|
||
| /** | ||
| * Similar to {@link AutoCloseable}, but without the checked exception. | ||
| */ | ||
| interface ClosableLock extends AutoCloseable | ||
| { | ||
| void close(); | ||
| } |
57 changes: 57 additions & 0 deletions
57
src/main/java/org/mastodon/mamut/tomancak/lineage_registration/ComboBoxDialog.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package org.mastodon.mamut.tomancak.lineage_registration; | ||
|
|
||
| import java.awt.Component; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.function.Function; | ||
|
|
||
| import javax.swing.JOptionPane; | ||
|
|
||
| import net.imglib2.util.Cast; | ||
|
|
||
| public class ComboBoxDialog | ||
| { | ||
|
|
||
| public static < T > T showComboBoxDialog( Component parent, String title, String message, List< T > options, | ||
| Function< T, String > toString ) | ||
| { | ||
| Choice[] choices = options.stream() | ||
| .map( option -> new Choice( toString.apply( option ), option ) ) | ||
| .toArray( Choice[]::new ); | ||
| Choice choice = ( Choice ) JOptionPane.showInputDialog( parent, message, title, | ||
| JOptionPane.QUESTION_MESSAGE, null, choices, choices[ 0 ] ); | ||
| return choice != null ? Cast.unchecked( choice.getValue() ) : null; | ||
| } | ||
|
|
||
| private static class Choice | ||
| { | ||
| private final String name; | ||
|
|
||
| private final Object value; | ||
|
|
||
| public Choice( String name, Object value ) | ||
| { | ||
| this.name = name; | ||
| this.value = value; | ||
| } | ||
|
|
||
| public Object getValue() | ||
| { | ||
| return value; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() | ||
| { | ||
| return name; | ||
| } | ||
| } | ||
|
|
||
| public static void main( String... args ) | ||
| { | ||
| // NB: Small demo method | ||
| List< String > options = Arrays.asList( "a", "b", "c" ); | ||
| String choice = showComboBoxDialog( null, "title", "message", options, a -> "choose: " + a ); | ||
| System.out.println( choice ); | ||
| } | ||
| } |
83 changes: 83 additions & 0 deletions
83
src/main/java/org/mastodon/mamut/tomancak/lineage_registration/EstimateTransformation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package org.mastodon.mamut.tomancak.lineage_registration; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import mpicbg.models.IllDefinedDataPointsException; | ||
| import mpicbg.models.NotEnoughDataPointsException; | ||
| import mpicbg.models.Point; | ||
| import mpicbg.models.PointMatch; | ||
| import mpicbg.models.SimilarityModel3D; | ||
|
|
||
| import net.imglib2.realtransform.AffineTransform3D; | ||
|
|
||
| import org.mastodon.collection.RefRefMap; | ||
| import org.mastodon.mamut.model.Spot; | ||
|
|
||
| /** | ||
| * This class holds a function for estimating a 3d rigid transformation | ||
| * between two sets of points. | ||
| */ | ||
| class EstimateTransformation | ||
| { | ||
|
|
||
| private EstimateTransformation() | ||
| { | ||
| // prevent instantiation | ||
| } | ||
|
|
||
| /** | ||
| * <p> | ||
| * @return a 3d rigid transform (that is composed of scaling, rotation and translation). | ||
| * The returned transformation is the optimal transformation, that when applied on the "key" spots | ||
| * of the given "pairs" map minimizes the distance to the "value" spots. | ||
| * </p> | ||
| * <p> | ||
| * See "Closed-form solution of absolute orientation using unit quaternions", | ||
| * Horn, B. K. P., Journal of the Optical Society of America A, Vol. 4, page 629, April 1987 | ||
| * </p> | ||
| * @param pairs A map that serves as a list of pairs of spots. Each pair consists of a "key" spot | ||
| * and a "value" spot. The algorithm only uses the coordinates of the spots, all other | ||
| * properties are ignored. | ||
| * @see SimilarityModel3D | ||
| */ | ||
| public static AffineTransform3D estimateScaleRotationAndTranslation( RefRefMap< Spot, Spot > pairs ) | ||
| { | ||
| // NB: This method is not as memory efficient as it could be. | ||
| // It creates multiple objects (Point, PointMatch, arrays) per item in "pairs". | ||
| // Memory efficiency should be improved if performance problems arise. | ||
| Spot refB = pairs.createValueRef(); | ||
| try | ||
| { | ||
| List< PointMatch > matches = new ArrayList<>( pairs.size() ); | ||
| for ( Spot spotA : pairs.keySet() ) | ||
| { | ||
| Spot spotB = pairs.get( spotA ); | ||
| Point pointA = new Point( spotA.positionAsDoubleArray() ); | ||
| Point pointB = new Point( spotB.positionAsDoubleArray() ); | ||
| matches.add( new PointMatch( pointA, pointB, 1 ) ); | ||
| } | ||
| return fitTransform( matches ); | ||
| } | ||
| finally | ||
| { | ||
| pairs.releaseValueRef( refB ); | ||
| } | ||
| } | ||
|
|
||
| private static AffineTransform3D fitTransform( List< PointMatch > matches ) | ||
| { | ||
| try | ||
| { | ||
| SimilarityModel3D model = new SimilarityModel3D(); | ||
| model.fit( matches ); | ||
|
maarzt marked this conversation as resolved.
|
||
| AffineTransform3D transform = new AffineTransform3D(); | ||
| transform.set( model.getMatrix( null ) ); | ||
| return transform; | ||
| } | ||
| catch ( NotEnoughDataPointsException | IllDefinedDataPointsException e ) | ||
| { | ||
| throw new RuntimeException( e ); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.