diff --git a/src/main/java/fr/pasteur/ida/zellige/gui/ChannelPanel.java b/src/main/java/fr/pasteur/ida/zellige/gui/ChannelPanel.java index fe56e762b77f14337c88ebecf6e70d7f23a29f3f..5c17c399025d728e39eb97a3687b5a3f77f2b702 100644 --- a/src/main/java/fr/pasteur/ida/zellige/gui/ChannelPanel.java +++ b/src/main/java/fr/pasteur/ida/zellige/gui/ChannelPanel.java @@ -54,7 +54,7 @@ public class ChannelPanel extends Pane implements Initializable SpinnerValueFactory< Integer > valueFactory2 = new SpinnerValueFactory.IntegerSpinnerValueFactory( 0, 30, 0, 1 ); offset.setValueFactory( valueFactory2 ); -// view.setOnAction( actionEvent -> this. ); + } public Spinner< Integer > getDeltaZ() diff --git a/src/main/java/fr/pasteur/ida/zellige/gui/ProjectionProperties.java b/src/main/java/fr/pasteur/ida/zellige/gui/ProjectionProperties.java index ef2f9fc4599ffeb1550659475e33341957ded27d..d39a9807decb2c39ab743ce5b2b5a005425c4df4 100644 --- a/src/main/java/fr/pasteur/ida/zellige/gui/ProjectionProperties.java +++ b/src/main/java/fr/pasteur/ida/zellige/gui/ProjectionProperties.java @@ -13,7 +13,14 @@ public class ProjectionProperties< T extends RealType< T > & NativeType< T > > private final SimpleObjectProperty< ArrayList< ChannelToolProperty<T> > > properties = new SimpleObjectProperty<>(new ArrayList<>()); + public ProjectionProperties( int channels) + { + for ( int i = 0; i < channels; i++ ) + { + getProperties().get().add( new ChannelToolProperty<>() ); + } + } public SimpleObjectProperty< ArrayList< ChannelToolProperty <T>> > getProperties() { diff --git a/src/main/java/fr/pasteur/ida/zellige/gui/ReferenceSurfacePanel.java b/src/main/java/fr/pasteur/ida/zellige/gui/ReferenceSurfacePanel.java index 021a3c2dcebf1670ebbf1e1842a40a478691b1f0..d1ab05ec00eccd6ee59d35cab3bd7e4f9b4793f4 100644 --- a/src/main/java/fr/pasteur/ida/zellige/gui/ReferenceSurfacePanel.java +++ b/src/main/java/fr/pasteur/ida/zellige/gui/ReferenceSurfacePanel.java @@ -6,10 +6,12 @@ import javafx.scene.control.Button; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.scene.layout.Pane; +import net.imglib2.type.NativeType; +import net.imglib2.type.numeric.RealType; import java.io.IOException; -public class ReferenceSurfacePanel extends Pane +public class ReferenceSurfacePanel < T extends RealType< T > & NativeType< T > > extends Pane { @FXML @@ -20,6 +22,8 @@ public class ReferenceSurfacePanel extends Pane @FXML private Button run; + private final ProjectionProperties<T> projectionProperties; + public ReferenceSurfacePanel( int channels) { @@ -43,6 +47,7 @@ public class ReferenceSurfacePanel extends Pane getChannelTools().getTabs().add( tab ); } + projectionProperties =new ProjectionProperties<>( channels ); } public TabPane getChannelTools() @@ -54,4 +59,9 @@ public class ReferenceSurfacePanel extends Pane { return run; } + + public ProjectionProperties< T > getProjectionProperties() + { + return projectionProperties; + } } diff --git a/src/main/java/fr/pasteur/ida/zellige/gui/controller/ConstructionController.java b/src/main/java/fr/pasteur/ida/zellige/gui/controller/ConstructionController.java index 12f9ac7d777f02176b3cecb186fadf526c99c2ab..8a4ec1725a8ea95c649eefbbbaaf5557005cb432 100644 --- a/src/main/java/fr/pasteur/ida/zellige/gui/controller/ConstructionController.java +++ b/src/main/java/fr/pasteur/ida/zellige/gui/controller/ConstructionController.java @@ -150,7 +150,7 @@ public class ConstructionController< T extends RealType< T > & NativeType< T > > getModel().referenceSurfacesProperty().addListener( ( observableValue, surfaces, newValue ) -> { - if ( ! newValue.isEmpty() ) + if (newValue!= null && ! newValue.isEmpty() ) { computeImageFXDisplay(); } diff --git a/src/main/java/fr/pasteur/ida/zellige/gui/controller/ProjectionController.java b/src/main/java/fr/pasteur/ida/zellige/gui/controller/ProjectionController.java index 21460629ed420ae89c29d00b877b79245d185ffc..19dc5e04b64c4af2d185a3acddf012b96aac4216 100644 --- a/src/main/java/fr/pasteur/ida/zellige/gui/controller/ProjectionController.java +++ b/src/main/java/fr/pasteur/ida/zellige/gui/controller/ProjectionController.java @@ -87,16 +87,22 @@ public class ProjectionController< T extends RealType< T > & NativeType< T > > i public void initialize( URL url, ResourceBundle resourceBundle ) { getModel().getImageViews().addListener( ( observableValue, number, newValue ) -> - getModel().getReferenceSurfaces(). - set( parentController.getConstructionController().getModel().referenceSurfacesProperty().get() ) ); + { + if ( newValue != null ) + { + getModel().getReferenceSurfaces(). + set( parentController.getConstructionController().getModel().referenceSurfacesProperty().get() ); + } + } + ); // Listening of the reference surface choiceBox referenceSurfacesList.getSelectionModel().selectedIndexProperty().addListener( ( observableValue, number, newValue ) -> { - if ( newValue != null ) + if ( newValue.intValue() != -1 ) { - LOGGER.debug( "Checking Reference surface n°{}", newValue ); currentIndex.set( newValue.intValue() ); + LOGGER.debug( "Checking Reference surface n°{}", currentIndex.get() ); setDisplay(); setProjectionPane(); } @@ -104,46 +110,84 @@ public class ProjectionController< T extends RealType< T > & NativeType< T > > i getModel().getReferenceSurfaces().addListener( ( observableValue, number, newValue ) -> { - listsInitialization(); - stackPane.getChildren().clear(); - for ( int i = 0; i < getModel().getReferenceSurfaces().get().size(); i++ ) + if ( newValue != null ) { - // Adding properties to each reference surfaces - ProjectionProperties< T > projectionProperties = new ProjectionProperties<>(); - getModel().getListOfProperty().get().add( projectionProperties ); + listsInitialization(); + // Removes default projection pane + stackPane.getChildren().clear(); int channels = parentController.getPreprocessingController().getModel().getNbOfChannels().get(); - // sets the projection panel according to the input channel number. - ReferenceSurfacePanel panel = new ReferenceSurfacePanel( channels ); - stackPane.getChildren().add( panel ); - // Behaviour for each reference surface runProjection button - panel.getRun().setOnAction( actionEvent -> + for ( int i = 0; i < getModel().getReferenceSurfaces().get().size(); i++ ) { - LOGGER.debug( "The projection Run button has been clicked" ); - // Sets the parameters value for all channels - for ( int channel = 0; channel < panel.getChannelTools().getTabs().size(); channel++ ) + // sets a new projection panel according to the input channel number. + ReferenceSurfacePanel< T > panel = new ReferenceSurfacePanel<>( channels ); + // Adding properties to each reference surfaces + getModel().getProjectionProperties().get().add( panel.getProjectionProperties() ); + stackPane.getChildren().add( panel ); + panel.getRun().setOnAction( actionEvent -> { - ChannelPanel channelPanel = ( ChannelPanel ) panel.getChannelTools().getTabs().get( channel ).getContent(); - interactor.setParameters( currentIndex.get(), channel, channelPanel.getDeltaZ().getValue(), channelPanel.getOffset().getValue(), channelPanel.getMethod().getValue() ); - } - interactor.runProjection( currentIndex.get() ); - LOGGER.debug( "Running projection of reference surface n°{}", currentIndex.get() ); - } ); - for ( int j = 0; j < panel.getChannelTools().getTabs().size(); j++ ) - { - projectionProperties.getProperties().get().add( new ChannelToolProperty<>() ); - final int channel = j; - ChannelPanel channelPanel = ( ChannelPanel ) panel.getChannelTools().getTabs().get( j ).getContent(); - channelPanel.getView().setOnAction( actionEvent -> - { - LOGGER.debug( "The view button has been pressed" ); - interactor.setParameters( currentIndex.intValue(), - channel, channelPanel.getDeltaZ().getValue(), - channelPanel.getOffset().getValue(), channelPanel.getMethod().getValue() ); - interactor.run( currentIndex.intValue(), channel ); + interactor.setParameters( panel ); + interactor.runProjection( currentIndex.get() ); } ); + for ( int j = 0; j < panel.getChannelTools().getTabs().size(); j++ ) + { + final int channel = j; + ChannelPanel channelPanel = ( ChannelPanel ) panel.getChannelTools().getTabs().get( j ).getContent(); + channelPanel.getView().setOnAction( actionEvent -> + { + LOGGER.debug( "The view button has been pressed" ); + interactor.setParameters( currentIndex.intValue(), + channel, channelPanel.getDeltaZ().getValue(), + channelPanel.getOffset().getValue(), channelPanel.getMethod().getValue() ); + interactor.runSubVolume( currentIndex.intValue(), channel ); + } ); + } } + referenceSurfacesList.getSelectionModel().selectFirst(); } - } ); + }); + +// getModel().getReferenceSurfaces().addListener( ( observableValue, number, newValue ) -> +// { +// listsInitialization(); +// stackPane.getChildren().clear(); +// for ( int i = 0; i < getModel().getReferenceSurfaces().get().size(); i++ ) +// { +// int channels = parentController.getPreprocessingController().getModel().getNbOfChannels().get(); +// // Adding properties to each reference surfaces +// ProjectionProperties< T > projectionProperties = new ProjectionProperties<>( channels ); +// getModel().getProjectionProperties().get().add( projectionProperties ); +// // sets the projection panel according to the input channel number. +// ReferenceSurfacePanel panel = new ReferenceSurfacePanel( channels ); +// stackPane.getChildren().add( panel ); +// // Behaviour for each reference surface runProjection button +// panel.getRun().setOnAction( actionEvent -> +// { +// LOGGER.debug( "The projection Run button has been clicked" ); +// // Sets the parameters value for all channels +// for ( int channel = 0; channel < panel.getChannelTools().getTabs().size(); channel++ ) +// { +// ChannelPanel channelPanel = ( ChannelPanel ) panel.getChannelTools().getTabs().get( channel ).getContent(); +// interactor.setParameters( currentIndex.get(), channel, channelPanel.getDeltaZ().getValue(), channelPanel.getOffset().getValue(), channelPanel.getMethod().getValue() ); +// } +// interactor.runProjection( currentIndex.get() ); +// LOGGER.debug( "Running projection of reference surface n°{}", currentIndex.get() ); +// } ); +// for ( int j = 0; j < panel.getChannelTools().getTabs().size(); j++ ) +// { +// projectionProperties.getProperties().get().add( new ChannelToolProperty<>() ); +// final int channel = j; +// ChannelPanel channelPanel = ( ChannelPanel ) panel.getChannelTools().getTabs().get( j ).getContent(); +// channelPanel.getView().setOnAction( actionEvent -> +// { +// LOGGER.debug( "The view button has been pressed" ); +// interactor.setParameters( currentIndex.intValue(), +// channel, channelPanel.getDeltaZ().getValue(), +// channelPanel.getOffset().getValue(), channelPanel.getMethod().getValue() ); +// interactor.runSubVolume( currentIndex.intValue(), channel ); +// } ); +// } +// } +// } ); /* Components*/ displayRS.setOnAction( actionEvent -> interactor.displayHM( currentIndex.intValue() ) ); } @@ -159,12 +203,12 @@ public class ProjectionController< T extends RealType< T > & NativeType< T > > i public void setProjectionPane() { int length = stackPane.getChildren().size(); - LOGGER.debug( "Number of nodes = {}", length ); for ( int i = 0; i < length; i++ ) { Node node = stackPane.getChildren().get( i ); node.setVisible( i == currentIndex.get() ); } + LOGGER.debug( "Displaying channel panel n°{}\n", ( currentIndex.get() + 1 ) ); } @@ -183,10 +227,9 @@ public class ProjectionController< T extends RealType< T > & NativeType< T > > i // Fills the ChoiceBox referenceSurfacesList.getItems().addAll( names ); // Display the first reference surface - referenceSurfacesList.getSelectionModel().selectFirst(); - display.getChildren().clear(); - display.getChildren().add( getModel().getImageViews().get()[ 0 ] ); - stackPane.getChildren().clear(); +// display.getChildren().clear(); +// display.getChildren().add( getModel().getImageViews().get()[ 0 ] ); + } } diff --git a/src/main/java/fr/pasteur/ida/zellige/gui/interactor/ProjectionInteractor.java b/src/main/java/fr/pasteur/ida/zellige/gui/interactor/ProjectionInteractor.java index c400dd8a281e7f969298ca16c4b5da096b0aa887..7e2fde771e3894dde33d79bcc2e652cd2014eed5 100644 --- a/src/main/java/fr/pasteur/ida/zellige/gui/interactor/ProjectionInteractor.java +++ b/src/main/java/fr/pasteur/ida/zellige/gui/interactor/ProjectionInteractor.java @@ -1,8 +1,10 @@ package fr.pasteur.ida.zellige.gui.interactor; import fr.pasteur.ida.zellige.element.ReferenceSurface; +import fr.pasteur.ida.zellige.gui.ChannelPanel; import fr.pasteur.ida.zellige.gui.ChannelToolProperty; import fr.pasteur.ida.zellige.gui.ProjectionProperties; +import fr.pasteur.ida.zellige.gui.ReferenceSurfacePanel; import fr.pasteur.ida.zellige.gui.model.ProjectionModel; import fr.pasteur.ida.zellige.gui.task.ProjectionTask; import fr.pasteur.ida.zellige.gui.task.SubVolumeTask; @@ -10,6 +12,7 @@ import fr.pasteur.ida.zellige.steps.projection.ReferenceSurfaceProjection; import ij.IJ; import net.imagej.ImgPlus; import net.imglib2.RandomAccessibleInterval; +import net.imglib2.img.Img; import net.imglib2.img.display.imagej.ImageJFunctions; import net.imglib2.type.NativeType; import net.imglib2.type.numeric.RealType; @@ -31,30 +34,30 @@ public class ProjectionInteractor< T extends RealType< T > & NativeType< T > > public void runProjection( int index ) { ReferenceSurface< T > referenceSurface = model.getReferenceSurfaces().get().get( index ); - ProjectionProperties< T > properties = model.getListOfProperty().get().get( index ); - ProjectionTask<T> task = new ProjectionTask<>( referenceSurface, properties ); + ProjectionProperties< T > properties = model.getProjectionProperties().get().get( index ); + ProjectionTask< T > task = new ProjectionTask<>( referenceSurface, properties ); task.setOnSucceeded( workerStateEvent -> { - LOGGER.debug("The projection has succeed!" ); + LOGGER.debug( "The projection has succeed!" ); // Wraps the projection inside an ImgPlus to display the colors if necessary. - ImgPlus<T> imgPlus = ReferenceSurfaceProjection.setColors( task.getValue(), getModel().getColors().get() ); - Context context = (Context) IJ.runPlugIn("org.scijava.Context", ""); - net.imagej.ImageJ ij = new net.imagej.ImageJ(context); + ImgPlus< T > imgPlus = ReferenceSurfaceProjection.setColors( task.getValue(), getModel().getColors().get() ); + Context context = ( Context ) IJ.runPlugIn( "org.scijava.Context", "" ); + net.imagej.ImageJ ij = new net.imagej.ImageJ( context ); ij.ui().show( imgPlus ); //TODO find a way to retrieve ij instance - }); - task.setOnFailed( workerStateEvent -> LOGGER.debug("The projection has failed!" )); + } ); + task.setOnFailed( workerStateEvent -> LOGGER.debug( "The projection has failed!" ) ); task.start(); } - public void run(int index, int channel ) + public void runSubVolume( int index, int channel ) { // Selection of the reference surface ReferenceSurface< T > referenceSurface = model.getReferenceSurfaces().get().get( index ); // Selection of the properties associated - ProjectionProperties< T > properties = model.getListOfProperty().get().get( index ); - RandomAccessibleInterval< T > input = Views.hyperSlice( referenceSurface.getInput(), 2, channel ); - ChannelToolProperty< T > channelToolProperty = properties.getProperties().get().get( channel ); + ProjectionProperties< T > properties = model.getProjectionProperties().get().get( index ); + RandomAccessibleInterval< T > input = Views.hyperSlice( referenceSurface.getInput(), 2, channel ); + ChannelToolProperty< T > channelToolProperty = properties.getProperties().get().get( channel ); if ( channelToolProperty.getSubVolume().get() == null ) { int delta = channelToolProperty.getDeltaZ().get(); @@ -62,39 +65,58 @@ public class ProjectionInteractor< T extends RealType< T > & NativeType< T > > SubVolumeTask< T > task = new SubVolumeTask<>( input, referenceSurface.getFactory(), referenceSurface.getzMap(), delta, offset ); task.setOnSucceeded( workerStateEvent -> { - channelToolProperty.getSubVolume().set( task.getValue() ); - LOGGER.debug( "SubVolume dimensions:{}.", task.getValue().dimensionsAsLongArray()); + Img< T > subVolume = task.getValue(); + channelToolProperty.getSubVolume().set( subVolume ); + LOGGER.debug( "SubVolume dimensions:{}.", subVolume.dimensionsAsLongArray() ); + String title = String.format( "SubVolume_RS_%d_channel_%d", ( index + 1 ), ( channel + 1 ) ); + ImageJFunctions.show( subVolume, title ); } ); - task.setOnFailed( workerStateEvent -> LOGGER.debug("The subVolume task has failed!") ); + task.setOnFailed( workerStateEvent -> LOGGER.debug( "The subVolume task has failed!" ) ); task.start(); } } -// public void runProjection( ChannelToolProperty< T > channelToolProperty ) -// { -// if (channelToolProperty.getSubVolume().get().numDimensions() == 3) -// { -// ProjectionTask< T > projectionTask = new ProjectionTask<>( channelToolProperty.getSubVolume().get(), channelToolProperty.getMethod().get() ); -// projectionTask.setOnSucceeded( workerStateEvent2 -> -// { -// channelToolProperty.getProjection().set( projectionTask.getValue() ); -// ImageJFunctions.show( projectionTask.getValue(), "projection" ); -// } ); -// projectionTask.start(); -// }else { -// channelToolProperty.getProjection().set( channelToolProperty.getSubVolume().get() ); -// } -// } - public void displayHM( int index ) { ReferenceSurface< T > referenceSurface = model.getReferenceSurfaces().get().get( index ); ImageJFunctions.show( referenceSurface.getzMap() ); } + public void setParameters( ReferenceSurfacePanel< T > panel ) + { + for ( int channel = 0; channel < panel.getChannelTools().getTabs().size(); channel++ ) + { + ChannelPanel channelPanel = ( ChannelPanel ) panel.getChannelTools().getTabs().get( channel ).getContent(); + ChannelToolProperty< T > channelToolProperty = panel.getProjectionProperties().getProperties().get().get( channel ); + setParameters( channelToolProperty, channelPanel.getDeltaZ().getValue(), channelPanel.getOffset().getValue(), channelPanel.getMethod().getValue() ); + } + } + + public void setParameters( ChannelPanel channelPanel ) + { + + } + + public void setParameters( ChannelToolProperty< T > channelToolProperty, int delta, int offset, String method ) + { + + if ( delta != channelToolProperty.getDeltaZ().get() ) + { + channelToolProperty.getDeltaZ().set( delta ); + } + if ( offset != channelToolProperty.getOffset().get() ) + { + channelToolProperty.getOffset().set( offset ); + } + if ( ! method.equals( channelToolProperty.getMethod().get() ) ) + { + channelToolProperty.getMethod().set( method ); + } + } + public void setParameters( final int index, int channel, int delta, int offset, String method ) { - ProjectionProperties< T > projectionProperties = getModel().getListOfProperty().get().get( index ); + ProjectionProperties< T > projectionProperties = getModel().getProjectionProperties().get().get( index ); ChannelToolProperty< T > channelToolProperty = ( channel == - 1 ) ? projectionProperties.getProperties().get().get( 0 ) : projectionProperties.getProperties().get().get( channel ); if ( delta != channelToolProperty.getDeltaZ().get() ) { @@ -110,6 +132,7 @@ public class ProjectionInteractor< T extends RealType< T > & NativeType< T > > } } + public ProjectionModel< T > getModel() { return model; diff --git a/src/main/java/fr/pasteur/ida/zellige/gui/model/ProjectionModel.java b/src/main/java/fr/pasteur/ida/zellige/gui/model/ProjectionModel.java index 7c2fb65cecf7b7ce205add22ecef1059e68afa1c..b22dd857b60a34317c89e65c59431c6a65dd0656 100644 --- a/src/main/java/fr/pasteur/ida/zellige/gui/model/ProjectionModel.java +++ b/src/main/java/fr/pasteur/ida/zellige/gui/model/ProjectionModel.java @@ -28,7 +28,6 @@ */ package fr.pasteur.ida.zellige.gui.model; -import fr.pasteur.ida.zellige.element.Projection; import fr.pasteur.ida.zellige.element.ReferenceSurface; import fr.pasteur.ida.zellige.gui.ProjectionProperties; import javafx.beans.property.*; @@ -43,7 +42,7 @@ public class ProjectionModel< T extends RealType< T > & NativeType< T > > { private final SimpleObjectProperty< ArrayList< ReferenceSurface< T > > > referenceSurfaces = new SimpleObjectProperty<>( new ArrayList<>() ); - private final SimpleObjectProperty< ArrayList< ProjectionProperties< T > > > listOfProperty = new SimpleObjectProperty<>( new ArrayList<>() ); + private final SimpleObjectProperty< ArrayList< ProjectionProperties< T > > > projectionProperties = new SimpleObjectProperty<>( new ArrayList<>() ); private final SimpleObjectProperty< ImageView[] > imageViews = new SimpleObjectProperty<>(); private final SimpleIntegerProperty numberOfChannels = new SimpleIntegerProperty(); @@ -64,9 +63,9 @@ public class ProjectionModel< T extends RealType< T > & NativeType< T > > return numberOfChannels; } - public SimpleObjectProperty< ArrayList< ProjectionProperties< T > > > getListOfProperty() + public SimpleObjectProperty< ArrayList< ProjectionProperties< T > > > getProjectionProperties() { - return listOfProperty; + return projectionProperties; } public SimpleObjectProperty< ArrayList< ColorTable > > getColors() diff --git a/src/main/java/fr/pasteur/ida/zellige/steps/projection/ReferenceSurfaceProjection.java b/src/main/java/fr/pasteur/ida/zellige/steps/projection/ReferenceSurfaceProjection.java index 9b60719670889680909db26c93e5529bb8053e37..85aee090d81d5282ad8fe005a7f0e3540bff3ecf 100644 --- a/src/main/java/fr/pasteur/ida/zellige/steps/projection/ReferenceSurfaceProjection.java +++ b/src/main/java/fr/pasteur/ida/zellige/steps/projection/ReferenceSurfaceProjection.java @@ -104,6 +104,10 @@ public class ReferenceSurfaceProjection< T extends RealType< T > & NativeType< T public static < T extends RealType< T > & NativeType< T > > Img< T > run( Img< T > subVolume, String method ) { + if (subVolume.dimension( 2 ) == 1) + { + return subVolume; + } Img< T > projection; if ( method.equals( "Mean" ) ) { @@ -211,7 +215,7 @@ public class ReferenceSurfaceProjection< T extends RealType< T > & NativeType< T } } } - ImageJFunctions.show(subStack, "SubStack"); + return subStack; }