Skip to content

Commit

Permalink
Merge origin/tuananh into new-feature
Browse files Browse the repository at this point in the history
Conflicts:
	src/main/java/ijfx/plugins/ImageJ1PluginAdapter.java
	src/main/java/ijfx/service/preview/PreviewService.java
	src/main/resources/ijfx/ui/main/flatterfx.css
	src/main/resources/ijfx/ui/menutoolbar/toolbarSettings.json
  • Loading branch information
cmongis committed May 25, 2016
2 parents 3042819 + ed7beee commit 6fc2c04
Show file tree
Hide file tree
Showing 33 changed files with 8,907 additions and 53 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ log-*.txt.lck
*.log
*.gz
package.sh
target/*
target/*
/nbproject/
12 changes: 11 additions & 1 deletion src/main/java/ijfx/bridge/FxUserInterfaceBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import ijfx.ui.datadisplay.image.ImageWindow;
import ijfx.ui.main.ImageJFX;
import ijfx.ui.datadisplay.table.TableWindow;
import ijfx.ui.datadisplay.text.TextWindow;
import java.io.File;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
Expand All @@ -47,6 +48,7 @@
import org.scijava.ui.UserInterface;
import org.scijava.ui.viewer.DisplayWindow;
import mongis.utils.FXUtilities;
import org.scijava.display.TextDisplay;

/**
* UI bridge between ImageJFX and ImageJ
Expand Down Expand Up @@ -204,7 +206,15 @@ public void show(final Display<?> dspl) {
ImageWindowContainer.getInstance().getChildren().add(new TableWindow((TableDisplay) dspl));
});

} else {
}
else if (dspl instanceof TextDisplay) {
Platform.runLater(() -> {

ImageWindowContainer.getInstance().getChildren().add(new TextWindow((TextDisplay) dspl));
});

}
else {
logger.warning("Cannot show display type :" + dspl.getClass().getSimpleName());
}
}
Expand Down
172 changes: 172 additions & 0 deletions src/main/java/ijfx/plugins/AbstractImageJ1PluginAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
* /*
* This file is part of ImageJ FX.
*
* ImageJ FX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ImageJ FX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ImageJ FX. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2015,2016 Cyril MONGIS, Michael Knop
*
*/
package ijfx.plugins;

import ij.ImagePlus;
import static java.lang.Math.toIntExact;
import java.util.stream.IntStream;
import net.imagej.Dataset;
import net.imagej.DatasetService;
import net.imagej.axis.Axes;
import net.imagej.axis.AxisType;
import net.imagej.axis.CalibratedAxis;
import net.imagej.display.ImageDisplay;
import net.imagej.display.ImageDisplayService;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.img.Img;
import net.imglib2.img.display.imagej.ImageJFunctions;

import net.imglib2.type.numeric.integer.UnsignedShortType;
import org.scijava.ItemIO;
import org.scijava.command.Command;
import org.scijava.event.EventService;
import org.scijava.plugin.Parameter;

/**
*
* @author Cyril MONGIS, 2015
* @author Tuan anh TRINH
*/
public abstract class AbstractImageJ1PluginAdapter implements Command {

@Parameter
DatasetService service;

@Parameter
ImageDisplayService imageDisplayService;

@Parameter
EventService eventService;

@Parameter
boolean createCopy;

boolean wholeWrap = false;

public abstract ImagePlus processImagePlus(ImagePlus input);

public ImagePlus getInput(Dataset dataset) {
return unwrapDataset(dataset);
}

public Dataset setOutput(ImagePlus imp, Dataset dataset) {
if (!wholeWrap) {
dataset = wrapDataset(imp);
} else {
ImagePlus resultCopy = imp.duplicate();
if (createCopy) {
dataset = emptyDataset(dataset, dataset.numDimensions());
}
Dataset dataset2 = wrapDataset(resultCopy);
for (int i = 0; i < getNumberOfSlices(dataset); i++) {
dataset.setPlane(i, dataset2.getPlane(i));
}

}
return dataset;
}

public static ImagePlus unwrapDataset(Dataset dataset) {
RandomAccessibleInterval<UnsignedShortType> r = (RandomAccessibleInterval<UnsignedShortType>) dataset.getImgPlus();
ImagePlus wrapImage = ImageJFunctions.wrap(r, "");
return wrapImage;
}

public Dataset wrapDataset(ImagePlus imp) {
Img img = ImageJFunctions.wrap(imp.duplicate());
return service.create(img);
}

public static void configureImagePlus(ImagePlus imp, ImageDisplay imageDisplay) {

imp.setC(imageDisplay.getIntPosition(Axes.CHANNEL));
imp.setZ(imageDisplay.getIntPosition(Axes.Z));
imp.setT(imageDisplay.getIntPosition(Axes.TIME));

}

private Dataset emptyDataset(Dataset input, int sizeDims) {
AxisType[] axisType = new AxisType[input.numDimensions()];
CalibratedAxis[] axeArray = new CalibratedAxis[input.numDimensions()];
input.axes(axeArray);

long[] dims = new long[sizeDims];
for (int i = 0; i < sizeDims; i++) {
axisType[i] = axeArray[i].type();
dims[i] = toIntExact(input.max(i) + 1);
}
return service.create(dims, input.getName(), axisType, input.getValidBits(), input.isSigned(), false);
}

private Dataset chooseDataset(Dataset dataset) {
if (createCopy) {
return dataset.duplicateBlank();
}
return dataset;
}

public int getNumberOfSlices(Dataset dataset) {

return (int) (dataset.getImgPlus().size() / (dataset.dimension(0) * dataset.dimension(1)));

}

public Dataset processDataset(Dataset dataset) {
Dataset datasetToModify = chooseDataset(dataset);

for (int i = 0; i < getNumberOfSlices(dataset); i++) {
Dataset datasetOnePlane = emptyDataset(dataset, 2);
datasetOnePlane.setPlane(0, dataset.getPlane(i));
ImagePlus result = processImagePlus(getInput(datasetOnePlane));
setOutput(result.duplicate(), datasetOnePlane);
datasetToModify.setPlane(i, datasetOnePlane.getPlane(0));
}
dataset = datasetToModify;
return dataset;
}
//
// /**
// * Wrap the whole Dataset. Use more memory
// *
// * @param dataset
// * @return
// */
// public Dataset processDatasetWholeWrap(Dataset dataset) {
// ImagePlus result = processImagePlus(getInput(dataset));
// ImagePlus resultCopy = result.duplicate();
// if (createCopy) {
// dataset = emptyDataset(dataset, dataset.numDimensions());
// }
// Dataset dataset2 = wrapDataset(resultCopy);
// for (int i = 0; i < getNumberOfSlices(dataset); i++) {
// dataset.setPlane(i, dataset2.getPlane(i));
// }
// return dataset;
// }

public boolean isWholeWrap() {
return wholeWrap;
}

public void setWholeWrap(boolean wholeWrap) {
this.wholeWrap = wholeWrap;
}
}
49 changes: 49 additions & 0 deletions src/main/java/ijfx/plugins/DefaultImageJ1PluginAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
This file is part of ImageJ FX.
ImageJ FX is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ImageJ FX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ImageJ FX. If not, see <http://www.gnu.org/licenses/>.
Copyright 2015,2016 Cyril MONGIS, Michael Knop
*/
package ijfx.plugins;

import ij.ImagePlus;
import net.imagej.Dataset;
import org.scijava.ItemIO;
import org.scijava.command.Command;
import org.scijava.plugin.Attr;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
/**
*
* @author Tuan anh TRINH
*/
@Plugin(type = Command.class, menuPath = "Plugins>DefaultAdapter")
public class DefaultImageJ1PluginAdapter extends AbstractImageJ1PluginAdapter {
@Parameter(type = ItemIO.BOTH)
protected Dataset dataset;
@Override
public ImagePlus processImagePlus(ImagePlus input) {
return input;
}

@Override
public void run() {
dataset = processDataset(dataset);
}



}
51 changes: 51 additions & 0 deletions src/main/java/ijfx/plugins/DefaultWholeWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
This file is part of ImageJ FX.
ImageJ FX is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ImageJ FX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ImageJ FX. If not, see <http://www.gnu.org/licenses/>.
Copyright 2015,2016 Cyril MONGIS, Michael Knop
*/
package ijfx.plugins;

import ij.ImagePlus;
import java.io.File;
import net.imagej.Dataset;
import org.scijava.ItemIO;
import org.scijava.command.Command;
import org.scijava.plugin.Attr;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
/**
*
* @author Tuan anh TRINH
*/
@Plugin(type = Command.class, menuPath = "Plugins>DefaultWholeAdapter")
public class DefaultWholeWrapper extends AbstractImageJ1PluginAdapter {
@Parameter(type = ItemIO.BOTH)
protected Dataset dataset;
@Parameter
File f;
@Override
public ImagePlus processImagePlus(ImagePlus input) {
return input;
}

@Override
public void run() {
setWholeWrap(true);
dataset = setOutput(getInput(dataset), dataset);
}

}
Loading

0 comments on commit 6fc2c04

Please sign in to comment.