-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40ce2fc
commit 65b6ef9
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,62 @@ | ||
package org.mastodon.mamut.io; | ||
|
||
import ij.ImagePlus; | ||
import net.imagej.ImgPlus; | ||
import net.imagej.axis.Axes; | ||
import net.imagej.axis.AxisType; | ||
import net.imglib2.img.Img; | ||
import net.imglib2.img.array.ArrayImgs; | ||
import net.imglib2.img.display.imagej.ImgToVirtualStack; | ||
import net.imglib2.type.numeric.real.FloatType; | ||
import org.junit.Test; | ||
import org.mastodon.mamut.ProjectModel; | ||
import org.mastodon.mamut.io.project.MamutProject; | ||
import org.mastodon.mamut.model.Model; | ||
import org.mastodon.views.bdv.SharedBigDataViewerData; | ||
import org.scijava.Context; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class ProjectSaverTest | ||
{ | ||
@Test | ||
public void testSaveProject() throws IOException | ||
{ | ||
try (Context context = new Context()) | ||
{ | ||
Model model = new Model(); | ||
Img< FloatType > image = ArrayImgs.floats( 1, 1, 1 ); | ||
File mastodon = File.createTempFile( "test", ".mastodon" ); | ||
ProjectModel appModel = wrapAsAppModel( image, model, context, mastodon ); | ||
ProjectSaver.saveProject( mastodon, appModel ); | ||
assertNotNull( mastodon ); | ||
assertTrue( mastodon.exists() ); | ||
assertTrue( mastodon.isFile() ); | ||
assertTrue( mastodon.length() > 0 ); | ||
assertEquals( mastodon, appModel.getProject().getProjectRoot() ); | ||
} | ||
} | ||
|
||
private static ProjectModel wrapAsAppModel( final Img< FloatType > image, final Model model, final Context context, final File file ) | ||
throws IOException | ||
{ | ||
final SharedBigDataViewerData sharedBigDataViewerData = asSharedBdvDataXyz( image ); | ||
MamutProject mamutProject = new MamutProject( file ); | ||
File datasetXmlFile = File.createTempFile( "test", ".xml" ); | ||
mamutProject.setDatasetXmlFile( datasetXmlFile ); | ||
return ProjectModel.create( context, model, sharedBigDataViewerData, mamutProject ); | ||
} | ||
|
||
private static SharedBigDataViewerData asSharedBdvDataXyz( final Img< FloatType > image1 ) | ||
{ | ||
final ImagePlus image = | ||
ImgToVirtualStack.wrap( new ImgPlus<>( image1, "image", new AxisType[] { Axes.X, Axes.Y, Axes.Z, Axes.TIME } ) ); | ||
return Objects.requireNonNull( SharedBigDataViewerData.fromImagePlus( image ) ); | ||
} | ||
} |