Skip to content

Commit

Permalink
Merge pull request #1054 from K-Meech/update_project_creator_javadoc
Browse files Browse the repository at this point in the history
Fix display of project creator ui on high dpi screens
  • Loading branch information
tischi authored Aug 11, 2023
2 parents 5e9646d + f4ca9ce commit fea2f33
Show file tree
Hide file tree
Showing 10 changed files with 475 additions and 58 deletions.
47 changes: 47 additions & 0 deletions src/main/java/org/embl/mobie/lib/create/DatasetJsonCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,46 @@

import static org.embl.mobie.lib.create.ProjectCreatorHelper.imageFormatToFolderName;

/**
* Class to create and modify the metadata stored in dataset Json files
*/
public class DatasetJsonCreator {

ProjectCreator projectCreator;

/**
* Make a datasetJsonCreator - includes all functions for creating and modifying metadata
* stored in dataset Json files
* @param projectCreator projectCreator
*/
public DatasetJsonCreator( ProjectCreator projectCreator ) {
this.projectCreator = projectCreator;
}

/**
* Create dataset Json for new dataset
* @param datasetName dataset name
* @param is2D whether dataset only contains 2D images
*/
public void addDataset( String datasetName, boolean is2D ) {
Dataset dataset = new Dataset();
dataset.is2D( is2D );
writeDatasetJson( datasetName, dataset );
}

/**
* Add named image to dataset Json (including a view with the image name and sensible defaults)
* @param imageName image name
* @param datasetName dataset name
* @param uiSelectionGroup name of ui selection group to add image view to i.e. the name of the MoBIE dropdown
* menu it will appear in
* @param imageDataFormat image data format
* @param contrastLimits contrast limits for image view
* @param colour colour for image view
* @param exclusive whether the image view is exclusive or not i.e. when viewed, does it first remove all current
* images from the viewer?
* @param sourceTransform affine transform of image view
*/
public void addImage(String imageName, String datasetName,
String uiSelectionGroup,
ImageDataFormat imageDataFormat, double[] contrastLimits, String colour, boolean exclusive, AffineTransform3D sourceTransform ) {
Expand All @@ -87,6 +113,17 @@ public void addImage(String imageName, String datasetName,
writeDatasetJson( datasetName, dataset );
}

/**
* Add named segmentation to dataset Json (including a view with the segmentation name and sensible defaults)
* @param imageName segmentation name
* @param datasetName dataset name
* @param uiSelectionGroup name of ui selection group to add segmentation view to i.e. the name of the MoBIE
* dropdown menu it will appear in
* @param imageDataFormat segmentation image data format
* @param exclusive whether the segmentation view is exclusive or not i.e. when viewed, does it first
* remove all current images from the viewer?
* @param sourceTransform affine transform of segmentation view
*/
public void addSegmentation(String imageName, String datasetName, String uiSelectionGroup, ImageDataFormat imageDataFormat, boolean exclusive, AffineTransform3D sourceTransform ) {
Dataset dataset = fetchDataset( datasetName );

Expand All @@ -104,6 +141,11 @@ public void addSegmentation(String imageName, String datasetName, String uiSelec
writeDatasetJson( datasetName, dataset );
}

/**
* Make named dataset 2D in the dataset Json
* @param datasetName dataset name
* @param is2D whether dataset only contains 2D images
*/
public void makeDataset2D( String datasetName, boolean is2D ) {
Dataset dataset = projectCreator.getDataset( datasetName );
dataset.is2D( is2D );
Expand Down Expand Up @@ -222,6 +264,11 @@ private View createSegmentationView( String imageName, String uiSelectionGroup,
}
}

/**
* Write the provided dataset to a dataset Json file
* @param datasetName dataset name
* @param dataset dataset
*/
public void writeDatasetJson ( String datasetName, Dataset dataset ) {
try {
String datasetJsonPath = IOHelper.combinePath( projectCreator.getProjectLocation().getAbsolutePath(),
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/embl/mobie/lib/create/DatasetsCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import java.io.File;
import java.util.List;

/**
* Class to create and modify MoBIE datasets
*/
public class DatasetsCreator {

static { net.imagej.patcher.LegacyInjector.preinit(); }
Expand Down
141 changes: 141 additions & 0 deletions src/main/java/org/embl/mobie/lib/create/ImagesCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,19 @@
import static org.embl.mobie.lib.create.ProjectCreatorHelper.isImageValid;
import static org.embl.mobie.lib.create.ProjectCreatorHelper.isSpimData2D;

/**
* Class to add images and segmentations to MoBIE projects in the correct file formats
*/
public class ImagesCreator {

static { net.imagej.patcher.LegacyInjector.preinit(); }

ProjectCreator projectCreator;

/**
* Make an imagesCreator - includes all functions for adding images and segmentations to MoBIE projects
* @param projectCreator projectCreator
*/
public ImagesCreator( ProjectCreator projectCreator ) {
this.projectCreator = projectCreator;
}
Expand Down Expand Up @@ -125,32 +132,129 @@ private String getDefaultTablePath( String datasetName, String imageName ) {
return IOHelper.combinePath( getDefaultTableDirPath(datasetName, imageName), "default.tsv" );
}

/**
* Check if named image exists within dataset
* @param datasetName dataset name
* @param imageName image name
* @param imageDataFormat image data format - ImageDataFormat.BdvN5 or ImageDataFormat.OmeZarr
* @return whether the image exists or not
*/
public boolean imageExists( String datasetName, String imageName, ImageDataFormat imageDataFormat ) {
// either xml file path or zarr file path depending on imageDataFormat
String filePath = getDefaultLocalImagePath( datasetName, imageName, imageDataFormat );
return new File (filePath).exists();
}

/**
* Add ImagePlus image to MoBIE project. Resolutions, subdivisions and compression of converted image will be
* set to sensible defaults.
* @param imp ImagePlus image
* @param imageName image name
* @param datasetName dataset name
* @param imageDataFormat image data format to convert to - ImageDataFormat.BdvN5 or ImageDataFormat.OmeZarr
* @param imageType image type i.e. image or segmentation
* @param sourceTransform Affine transform of image
* @param uiSelectionGroup name of ui selection group to add image view to i.e. the name of the MoBIE dropdown
* menu it will appear in
* @throws SpimDataException
* @throws IOException
*/
public void addImage ( ImagePlus imp, String imageName, String datasetName, ImageDataFormat imageDataFormat, ProjectCreator.ImageType imageType, AffineTransform3D sourceTransform, String uiSelectionGroup ) throws SpimDataException, IOException
{
addImage( imp, imageName, datasetName, imageDataFormat, imageType, sourceTransform, uiSelectionGroup, false, null, null, null );
}

/**
* Add ImagePlus image to MoBIE project. Resolutions, subdivisions and compression of converted image will be
* set to sensible defaults.
* @param imp ImagePlus image
* @param imageName image name
* @param datasetName dataset name
* @param imageDataFormat image data format to convert to - ImageDataFormat.BdvN5 or ImageDataFormat.OmeZarr
* @param imageType image type i.e. image or segmentation
* @param sourceTransform Affine transform of image
* @param uiSelectionGroup name of ui selection group to add image view to i.e. the name of the MoBIE dropdown
* menu it will appear in
* @param exclusive whether the image view is exclusive or not i.e. when viewed, does it first remove all current
* images from the viewer?
* @throws SpimDataException
* @throws IOException
*/
public void addImage ( ImagePlus imp, String imageName, String datasetName, ImageDataFormat imageDataFormat, ProjectCreator.ImageType imageType, AffineTransform3D sourceTransform, String uiSelectionGroup, boolean exclusive ) throws SpimDataException, IOException
{
addImage( imp, imageName, datasetName, imageDataFormat, imageType, sourceTransform, uiSelectionGroup, exclusive, null, null, null );
}

/**
* Add ImagePlus image to MoBIE project. Resolutions, subdivisions and compression of converted image will be
* set to sensible defaults.
* @param imp ImagePlus image
* @param imageName image name
* @param datasetName dataset name
* @param imageDataFormat image data format to convert to - ImageDataFormat.BdvN5 or ImageDataFormat.OmeZarr
* @param imageType image type i.e. image or segmentation
* @param uiSelectionGroup name of ui selection group to add image view to i.e. the name of the MoBIE dropdown
* menu it will appear in
* @param exclusive whether the image view is exclusive or not i.e. when viewed, does it first remove all current
* images from the viewer?
* @throws SpimDataException
* @throws IOException
*/
public void addImage ( ImagePlus imp, String imageName, String datasetName, ImageDataFormat imageDataFormat, ProjectCreator.ImageType imageType, String uiSelectionGroup, boolean exclusive ) throws SpimDataException, IOException
{
addImage( imp, imageName, datasetName, imageDataFormat, imageType, new AffineTransform3D(), uiSelectionGroup, exclusive, null, null, null );
}

/**
* Add ImagePlus image to MoBIE project. Resolutions, subdivisions and compression of converted image must be
* provided directly.
* @param imp ImagePlus image
* @param imageName image name
* @param datasetName dataset name
* @param imageDataFormat image data format to convert to - ImageDataFormat.BdvN5 or ImageDataFormat.OmeZarr
* @param imageType image type i.e. image or segmentation
* @param uiSelectionGroup name of ui selection group to add image view to i.e. the name of the MoBIE dropdown
* menu it will appear in
* @param exclusive whether the image view is exclusive or not i.e. when viewed, does it first remove all current
* images from the viewer?
* @param resolutions Resolution levels to use for converted image e.g. [ [1,1,1], [2,2,2], [4,4,4] ] will
* write one full resolution level, then one 2x downsampled, and one 4x downsampled.
* The order is [x, y, z].
* @param subdivisions Subdivisions/chunk size to use for converted image. This must have the same number of
* entries as 'resolutions'. e.g. [ [64,64,64], [64,64,64], [64,64,64] ] will use a chunk size
* of (64, 64, 64) for all levels. The order is [x, y, z].
* @param compression Type of compression to use for converted image.
* @throws SpimDataException
* @throws IOException
*/
public void addImage ( ImagePlus imp, String imageName, String datasetName, ImageDataFormat imageDataFormat, ProjectCreator.ImageType imageType, String uiSelectionGroup, boolean exclusive, int[][] resolutions, int[][] subdivisions, Compression compression ) throws SpimDataException, IOException
{
addImage( imp, imageName, datasetName, imageDataFormat, imageType, new AffineTransform3D(), uiSelectionGroup, exclusive, resolutions, subdivisions, compression );
}

/**
* Add ImagePlus image to MoBIE project. Resolutions, subdivisions and compression of converted image must be
* provided directly.
* @param imp ImagePlus image
* @param imageName image name
* @param datasetName dataset name
* @param imageDataFormat image data format to convert to - ImageDataFormat.BdvN5 or ImageDataFormat.OmeZarr
* @param imageType image type i.e. image or segmentation
* @param sourceTransform Affine transform of image
* @param uiSelectionGroup name of ui selection group to add image view to i.e. the name of the MoBIE dropdown
* menu it will appear in
* @param exclusive whether the image view is exclusive or not i.e. when viewed, does it first remove all current
* images from the viewer?
* @param resolutions Resolution levels to use for converted image e.g. [ [1,1,1], [2,2,2], [4,4,4] ] will
* write one full resolution level, then one 2x downsampled, and one 4x downsampled.
* The order is [x, y, z].
* @param subdivisions Subdivisions/chunk size to use for converted image. This must have the same number of
* entries as 'resolutions'. e.g. [ [64,64,64], [64,64,64], [64,64,64] ] will use a chunk size
* of (64, 64, 64) for all levels. The order is [x, y, z].
* @param compression Type of compression to use for converted image.
* @throws IOException
* @throws SpimDataException
*/
public void addImage( ImagePlus imp, String imageName, String datasetName, ImageDataFormat imageDataFormat, ProjectCreator.ImageType imageType, AffineTransform3D sourceTransform, String uiSelectionGroup, boolean exclusive, int[][] resolutions, int[][] subdivisions, Compression compression ) throws IOException, SpimDataException
{
// either xml file path or zarr file path depending on imageDataFormat
Expand Down Expand Up @@ -310,6 +414,25 @@ private void deleteImageFiles( String datasetName, String imageName, ImageDataFo
}
}

/**
* Add BigDataViewer (Bdv) format image to MoBIE project e.g. one already in n5/ome-zarr.
* @param fileLocation image file location - for n5, location of the xml, for ome-zarr,
* location of the .ome.zarr directory.
* @param imageName image name
* @param datasetName dataset name
* @param imageType image type i.e. image or segmentation
* @param addMethod link, copy or move the image - link (leave image as-is, and link to this location. Only
* supported for N5 and local projects), copy (copy image into project),
* or move (move image into project - be careful as this will delete the image
* from its original location!)
* @param uiSelectionGroup name of ui selection group to add image view to i.e. the name of the MoBIE dropdown
* menu it will appear in
* @param imageDataFormat image data format of image - ImageDataFormat.BdvN5 or ImageDataFormat.OmeZarr
* @param exclusive whether the image view is exclusive or not i.e. when viewed, does it first remove all current
* images from the viewer?
* @throws SpimDataException
* @throws IOException
*/
public void addBdvFormatImage ( File fileLocation, String imageName, String datasetName, ProjectCreator.ImageType imageType, ProjectCreator.AddMethod addMethod, String uiSelectionGroup, ImageDataFormat imageDataFormat, boolean exclusive ) throws SpimDataException, IOException {

if ( fileLocation.exists() ) {
Expand All @@ -321,6 +444,24 @@ public void addBdvFormatImage ( File fileLocation, String imageName, String data
}
}

/**
* Add BigDataViewer (Bdv) format image to MoBIE project e.g. one already in n5/ome-zarr.
* @param spimData spim data object for image
* @param imageName image name
* @param datasetName dataset name
* @param imageType image type i.e. image or segmentation
* @param addMethod link, copy or move the image - link (leave image as-is, and link to this location. Only
* supported for N5 and local projects), copy (copy image into project),
* or move (move image into project - be careful as this will delete the image
* from its original location!)
* @param uiSelectionGroup name of ui selection group to add image view to i.e. the name of the MoBIE dropdown
* menu it will appear in
* @param imageDataFormat image data format of image - ImageDataFormat.BdvN5 or ImageDataFormat.OmeZarr
* @param exclusive whether the image view is exclusive or not i.e. when viewed, does it first remove all current
* images from the viewer?
* @throws SpimDataException
* @throws IOException
*/
public void addBdvFormatImage ( SpimData spimData, String imageName, String datasetName,
ProjectCreator.ImageType imageType, ProjectCreator.AddMethod addMethod, String uiSelectionGroup, ImageDataFormat imageDataFormat, boolean exclusive ) throws SpimDataException, IOException {

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/org/embl/mobie/lib/create/ProjectCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@

import static org.embl.mobie.lib.create.ProjectCreatorHelper.getGroupToViewsMap;

/**
* Class to create and edit MoBIE projects.
*/
public class ProjectCreator {

static { LegacyInjector.preinit(); }
Expand Down Expand Up @@ -80,6 +83,12 @@ public enum AddMethod {
move
}

/**
* Make a projectCreator - main entry point to create + edit MoBIE projects.
* This will create the project directory (if it doesn't exist).
* @param projectLocation Filepath of project directory
* @throws IOException
*/
public ProjectCreator( File projectLocation ) throws IOException {
this.projectLocation = projectLocation;
if ( ! projectLocation.exists() )
Expand Down Expand Up @@ -114,6 +123,10 @@ public Project getProject() {

public File getProjectJson() { return projectJson; }

/**
* Reload project by directly reading the project json
* @throws IOException
*/
public void reloadProject() throws IOException {
this.project = new ProjectJsonParser().parseProject( projectJson.getAbsolutePath() );
}
Expand All @@ -139,6 +152,11 @@ public Dataset getDataset( String datasetName ) {
}
}

/**
* Get all ui selection groups (i.e. MoBIE dropdown menu names) used by views in the named dataset
* @param datasetName dataset name
* @return array of ui selection group names
*/
public String[] getGroups( String datasetName ) {
if ( !datasetName.equals(currentDatasetName) ) {
getDataset( datasetName );
Expand All @@ -152,6 +170,12 @@ public String[] getGroups( String datasetName ) {
return groups;
}

/**
* Get all view names within the given dataset and ui selection group (i.e. MoBIE dropdown menu)
* @param datasetName dataset name
* @param uiSelectionGroup ui selection group name
* @return array of view names
*/
public String[] getViews( String datasetName, String uiSelectionGroup ) {
if ( !datasetName.equals(currentDatasetName) ) {
getDataset( datasetName );
Expand All @@ -164,6 +188,7 @@ public String[] getViews( String datasetName, String uiSelectionGroup ) {

return views;
}

public String getVoxelUnit() {
return voxelUnit;
}
Expand All @@ -172,6 +197,10 @@ public void setVoxelUnit(String voxelUnit) {
this.voxelUnit = voxelUnit;
}

/**
* Reload dataset by directly reading the dataset json
* @throws IOException
*/
public void reloadCurrentDataset() throws IOException {
if ( currentDatasetName != null ) {
this.currentDataset = new DatasetJsonParser().parseDataset(currentDatasetJson.getAbsolutePath());
Expand Down
Loading

0 comments on commit fea2f33

Please sign in to comment.