Skip to content

Commit 6e62e54

Browse files
gselzerhinerm
authored andcommitted
Create module imagej2-legacy
This module will house components integrating SciJava3 with ImageJ2
1 parent 1bc51d4 commit 6e62e54

7 files changed

Lines changed: 315 additions & 0 deletions

File tree

imagej/imagej2-legacy/LICENSE.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright (c) 2016 - 2022, ImageJ2 developers.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24+
POSSIBILITY OF SUCH DAMAGE.

imagej/imagej2-legacy/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# ImageJ2 Legacy: An interface between SciJava 3 and ImageJ2
2+
3+
This library provides a bridge between SciJava 3 and ImageJ2.
4+
For Maven projects, this library can be used by adding to your `pom.xml`:
5+
6+
```java
7+
<dependency>
8+
<groupId>net.imagej</groupId>
9+
<artifactId>imagej2-legacy</artifactId>
10+
<version>0-SNAPSHOT</version>
11+
</dependency>
12+
```

imagej/imagej2-legacy/pom.xml

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.scijava</groupId>
7+
<artifactId>scijava-incubator</artifactId>
8+
<version>0-SNAPSHOT</version>
9+
<relativePath>../..</relativePath>
10+
</parent>
11+
12+
<groupId>net.imagej</groupId>
13+
<artifactId>imagej2-legacy</artifactId>
14+
15+
<name>ImageJ2 Legacy</name>
16+
<description>An interface between SciJava 3 and ImageJ2.</description>
17+
<url>https://github.com/scijava/scijava</url>
18+
<inceptionYear>2023</inceptionYear>
19+
<organization>
20+
<name>ImageJ</name>
21+
<url>https://imagej.net/</url>
22+
</organization>
23+
<licenses>
24+
<license>
25+
<name>Simplified BSD License</name>
26+
<distribution>repo</distribution>
27+
</license>
28+
</licenses>
29+
30+
<developers>
31+
<developer>
32+
<id>ctrueden</id>
33+
<name>Curtis Rueden</name>
34+
<url>https://imagej.net/people/ctrueden</url>
35+
<roles>
36+
<role>founder</role>
37+
<role>debugger</role>
38+
<role>reviewer</role>
39+
<role>maintainer</role>
40+
</roles>
41+
</developer>
42+
<developer>
43+
<id>gselzer</id>
44+
<name>Gabriel Selzer</name>
45+
<url>https://imagej.net/people/gselzer</url>
46+
<roles>
47+
<role>founder</role>
48+
<role>debugger</role>
49+
<role>reviewer</role>
50+
<role>maintainer</role>
51+
</roles>
52+
</developer>
53+
</developers>
54+
<contributors>
55+
<!--
56+
NB: Need at least one element to override the parent.
57+
See: https://issues.apache.org/jira/browse/MNG-5220
58+
-->
59+
<contributor>
60+
<name>None</name>
61+
</contributor>
62+
</contributors>
63+
64+
<mailingLists>
65+
<mailingList>
66+
<name>Image.sc Forum</name>
67+
<archive>https://forum.image.sc/tag/imagej2</archive>
68+
</mailingList>
69+
</mailingLists>
70+
71+
<scm>
72+
<connection>scm:git:git://github.com/scijava/incubator</connection>
73+
<developerConnection>scm:git:git@github.com:scijava/incubator</developerConnection>
74+
<tag>HEAD</tag>
75+
<url>https://github.com/scijava/incubator</url>
76+
</scm>
77+
<issueManagement>
78+
<system>GitHub Issues</system>
79+
<url>https://github.com/imagej/imagej-ops2/issues</url>
80+
</issueManagement>
81+
<ciManagement>
82+
<system>GitHub Actions</system>
83+
<url>https://github.com/scijava/incubator/actions</url>
84+
</ciManagement>
85+
86+
<properties>
87+
<package-name>net.imagej.legacy2</package-name>
88+
89+
<license.licenseName>bsd_2</license.licenseName>
90+
<license.copyrightOwners>ImageJ2 developers.</license.copyrightOwners>
91+
<license.projectName>ImageJ2 software for multidimensional image processing and analysis.</license.projectName>
92+
93+
<!-- NB: Deploy releases to the SciJava Maven repository. -->
94+
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>
95+
</properties>
96+
97+
<repositories>
98+
<repository>
99+
<id>scijava.public</id>
100+
<url>https://maven.scijava.org/content/groups/public</url>
101+
</repository>
102+
<repository>
103+
<id>imagej.snapshots</id>
104+
<url>https://maven.scijava.org/content/groups/snapshots</url>
105+
</repository>
106+
</repositories>
107+
108+
<dependencies>
109+
<!-- ImageJ2 dependencies -->
110+
<dependency>
111+
<groupId>net.imagej</groupId>
112+
<artifactId>imagej-common</artifactId>
113+
</dependency>
114+
<!-- SciJava dependencies -->
115+
<dependency>
116+
<groupId>org.scijava</groupId>
117+
<artifactId>scijava-collections</artifactId>
118+
<version>${project.version}</version>
119+
</dependency>
120+
<dependency>
121+
<groupId>org.scijava</groupId>
122+
<artifactId>scijava-priority</artifactId>
123+
<version>${project.version}</version>
124+
</dependency>
125+
<dependency>
126+
<groupId>org.scijava</groupId>
127+
<artifactId>scijava-types</artifactId>
128+
<version>${project.version}</version>
129+
</dependency>
130+
131+
<!-- ImgLib2 dependencies -->
132+
<dependency>
133+
<groupId>net.imglib2</groupId>
134+
<artifactId>imglib2</artifactId>
135+
</dependency>
136+
137+
<dependency>
138+
<groupId>org.apache.commons</groupId>
139+
<artifactId>commons-math3</artifactId>
140+
</dependency>
141+
142+
<!-- Test scope dependencies -->
143+
<dependency>
144+
<groupId>org.junit.jupiter</groupId>
145+
<artifactId>junit-jupiter-api</artifactId>
146+
<scope>test</scope>
147+
</dependency>
148+
<dependency>
149+
<groupId>org.junit.jupiter</groupId>
150+
<artifactId>junit-jupiter-engine</artifactId>
151+
<scope>test</scope>
152+
</dependency>
153+
<dependency>
154+
<groupId>net.imglib2</groupId>
155+
<artifactId>imglib2-roi</artifactId>
156+
<scope>test</scope>
157+
</dependency>
158+
<dependency>
159+
<groupId>org.scijava</groupId>
160+
<artifactId>scijava-testutil</artifactId>
161+
<version>${project.version}</version>
162+
<scope>test</scope>
163+
</dependency>
164+
</dependencies>
165+
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import net.imagej2.legacy.types.DatasetTypeExtractor;
2+
3+
/*-
4+
* #%L
5+
* ImageJ2 software for multidimensional image processing and analysis.
6+
* %%
7+
* Copyright (C) 2014 - 2022 ImageJ2 developers.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
module net.imagej2.legacy {
32+
33+
requires net.imagej;
34+
requires org.scijava.types;
35+
requires org.scijava.priority;
36+
37+
provides org.scijava.types.TypeExtractor with net.imagej2.legacy.types.DatasetTypeExtractor;
38+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
package net.imagej2.legacy.types;
3+
4+
import java.lang.reflect.Type;
5+
6+
import org.scijava.priority.Priority;
7+
import org.scijava.types.TypeExtractor;
8+
import org.scijava.types.TypeReifier;
9+
10+
import net.imagej.Dataset;
11+
12+
public class DatasetTypeExtractor implements TypeExtractor {
13+
14+
@Override
15+
public double getPriority() {
16+
return Priority.HIGH;
17+
}
18+
19+
@Override
20+
public boolean canReify(TypeReifier r, Class<?> object) {
21+
return Dataset.class.isAssignableFrom(object);
22+
}
23+
24+
@Override public Type reify(TypeReifier r, Object object) {
25+
if (!(object instanceof Dataset)) throw new IllegalArgumentException(object + " cannot be reified because it is not a Dataset!");
26+
return r.reify(((Dataset) object).getImgPlus());
27+
}
28+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
package net.imagej2.legacy.types;
3+
4+
import java.lang.reflect.Type;
5+
import java.util.ServiceLoader;
6+
7+
import org.junit.jupiter.api.Assertions;
8+
import org.junit.jupiter.api.Test;
9+
import org.scijava.Context;
10+
import org.scijava.discovery.Discoverer;
11+
import org.scijava.log2.StderrLoggerFactory;
12+
import org.scijava.types.Any;
13+
import org.scijava.types.DefaultTypeReifier;
14+
import org.scijava.types.Types;
15+
16+
import net.imagej.DefaultDataset;
17+
import net.imagej.ImgPlus;
18+
import net.imglib2.img.array.ArrayImgs;
19+
20+
/**
21+
* Tests {@link DatasetTypeExtractor}
22+
*
23+
* @author Gabriel Selzer
24+
*/
25+
public class DatasetTypeExtractorTest {
26+
27+
@Test
28+
public void testDatasetTypeExtractor() {
29+
// Create a TypeReifier
30+
var log = new StderrLoggerFactory().create();
31+
var reifier = new DefaultTypeReifier(log, Discoverer.all(
32+
ServiceLoader::load));
33+
// Create a Dataset
34+
var ctx = new Context();
35+
var img = ArrayImgs.unsignedBytes(10, 10);
36+
var imgPlus = new ImgPlus<>(img);
37+
var ds = new DefaultDataset(ctx, imgPlus);
38+
// Assert correct reification
39+
// NB without a dependency on imagej-ops2 we cannot reify
40+
// the ImgPlus, but asserting an ImgPlus is the reified type
41+
// is enough to unit test the TypeExtractor
42+
var actual = new DatasetTypeExtractor().reify(reifier, ds);
43+
var expected = Types.parameterize(ImgPlus.class, new Type[] { new Any() });
44+
Assertions.assertEquals(expected, actual);
45+
}
46+
47+
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<module>imagej/imagej-mesh2</module>
5050
<module>imagej/imagej-ops2</module>
5151
<module>imagej/imagej-testutil</module>
52+
<module>imagej/imagej2-legacy</module>
5253
<module>scijava/scijava-collections</module>
5354
<module>scijava/scijava-common3</module>
5455
<module>scijava/scijava-discovery</module>

0 commit comments

Comments
 (0)