Skip to content

Commit c486a51

Browse files
authored
Merge pull request #562 from bonej-org/rotate
JOML rotate ops
2 parents 2def69b + 25b3852 commit c486a51

File tree

8 files changed

+489
-1
lines changed

8 files changed

+489
-1
lines changed

pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>net.imagej</groupId>
1313
<artifactId>imagej-ops</artifactId>
14-
<version>0.41.2-SNAPSHOT</version>
14+
<version>0.42.0-SNAPSHOT</version>
1515

1616
<name>ImageJ Ops</name>
1717
<description>ImageJ Operations: a framework for reusable algorithms.</description>
@@ -266,6 +266,10 @@
266266
<groupId>org.apache.commons</groupId>
267267
<artifactId>commons-math3</artifactId>
268268
</dependency>
269+
<dependency>
270+
<groupId>org.joml</groupId>
271+
<artifactId>joml</artifactId>
272+
</dependency>
269273

270274
<!-- Test scope dependencies -->
271275
<dependency>

src/main/java/net/imagej/ops/OpEnvironment.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import net.imagej.ops.image.ImageNamespace;
5252
import net.imagej.ops.imagemoments.ImageMomentsNamespace;
5353
import net.imagej.ops.labeling.LabelingNamespace;
54+
import net.imagej.ops.linalg.LinAlgNamespace;
5455
import net.imagej.ops.logic.LogicNamespace;
5556
import net.imagej.ops.map.neighborhood.CenterAwareComputerOp;
5657
import net.imagej.ops.math.MathNamespace;
@@ -890,6 +891,11 @@ default LBPNamespace lbp() {
890891
return namespace(LBPNamespace.class);
891892
}
892893

894+
/** Gateway into ops of the "linalg" namespace */
895+
default LinAlgNamespace linalg() {
896+
return namespace(LinAlgNamespace.class);
897+
}
898+
893899
/** Gateway into ops of the "logic" namespace. */
894900
default LogicNamespace logic() {
895901
return namespace(LogicNamespace.class);
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*-
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
30+
package net.imagej.ops.linalg;
31+
32+
import net.imagej.ops.AbstractNamespace;
33+
import net.imagej.ops.Namespace;
34+
import net.imagej.ops.OpMethod;
35+
import net.imagej.ops.linalg.rotate.Rotate3d;
36+
import net.imagej.ops.linalg.rotate.Rotate3f;
37+
38+
import org.joml.AxisAngle4d;
39+
import org.joml.AxisAngle4f;
40+
import org.joml.Quaterniond;
41+
import org.joml.Quaterniondc;
42+
import org.joml.Quaternionf;
43+
import org.joml.Quaternionfc;
44+
import org.joml.Vector3d;
45+
import org.joml.Vector3f;
46+
import org.scijava.plugin.Plugin;
47+
48+
/**
49+
* The linear algebra namespace has ops for vectors and matrices.
50+
*
51+
* @author Richard Domander (Royal Veterinary College, London)
52+
*/
53+
@Plugin(type = Namespace.class)
54+
public class LinAlgNamespace extends AbstractNamespace {
55+
56+
@OpMethod(op = net.imagej.ops.linalg.rotate.Rotate3f.class)
57+
public Vector3f rotate(final Vector3f v, final Quaternionfc q) {
58+
return (Vector3f) ops().run(Rotate3f.class, v, q);
59+
}
60+
61+
@OpMethod(op = net.imagej.ops.linalg.rotate.Rotate3f.class)
62+
public Vector3f rotate(final Vector3f out, final Vector3f v,
63+
final Quaternionfc q)
64+
{
65+
return (Vector3f) ops().run(Rotate3f.class, out, v, q);
66+
}
67+
68+
@OpMethod(op = net.imagej.ops.linalg.rotate.Rotate3d.class)
69+
public Vector3d rotate(final Vector3d v, final Quaterniondc q) {
70+
return (Vector3d) ops().run(Rotate3d.class, v, q);
71+
}
72+
73+
@OpMethod(op = net.imagej.ops.linalg.rotate.Rotate3d.class)
74+
public Vector3d rotate(final Vector3d out, final Vector3d v,
75+
final Quaterniondc q)
76+
{
77+
return (Vector3d) ops().run(Rotate3d.class, out, v, q);
78+
}
79+
80+
@OpMethod(op = net.imagej.ops.linalg.rotate.Rotate3d.class)
81+
public Vector3d rotate(final Vector3d v, final AxisAngle4d axisAngle) {
82+
final Quaterniondc q = new Quaterniond(axisAngle);
83+
return (Vector3d) ops().run(Rotate3d.class, v, q);
84+
}
85+
86+
@OpMethod(op = net.imagej.ops.linalg.rotate.Rotate3f.class)
87+
public Vector3f rotate(final Vector3f v, final AxisAngle4f axisAngle) {
88+
final Quaternionfc q = new Quaternionf(axisAngle);
89+
return (Vector3f) ops().run(Rotate3f.class, v, q);
90+
}
91+
92+
@OpMethod(op = net.imagej.ops.linalg.rotate.Rotate3d.class)
93+
public Vector3d rotate(final Vector3d out, final Vector3d v,
94+
final AxisAngle4d axisAngle)
95+
{
96+
final Quaterniondc q = new Quaterniond(axisAngle);
97+
return (Vector3d) ops().run(Rotate3d.class, out, v, q);
98+
}
99+
100+
@OpMethod(op = net.imagej.ops.linalg.rotate.Rotate3f.class)
101+
public Vector3f rotate(final Vector3f out, final Vector3f v,
102+
final AxisAngle4f axisAngle)
103+
{
104+
final Quaternionfc q = new Quaternionf(axisAngle);
105+
return (Vector3f) ops().run(Rotate3f.class, out, v, q);
106+
}
107+
108+
@OpMethod(op = net.imagej.ops.linalg.rotate.Rotate3d.class)
109+
public Vector3d rotate1(final Vector3d v, final Quaterniondc q) {
110+
return (Vector3d) ops().run(Rotate3d.class, v, v, q);
111+
}
112+
113+
@OpMethod(op = net.imagej.ops.linalg.rotate.Rotate3f.class)
114+
public Vector3f rotate1(final Vector3f v, final Quaternionfc q) {
115+
return (Vector3f) ops().run(Rotate3f.class, v, v, q);
116+
}
117+
118+
@OpMethod(op = net.imagej.ops.linalg.rotate.Rotate3d.class)
119+
public Vector3d rotate1(final Vector3d v, final AxisAngle4d axisAngle) {
120+
final Quaterniondc q = new Quaterniond(axisAngle);
121+
return (Vector3d) ops().run(Rotate3d.class, v, v, q);
122+
}
123+
124+
@OpMethod(op = net.imagej.ops.linalg.rotate.Rotate3f.class)
125+
public Vector3f rotate1(final Vector3f v, final AxisAngle4f axisAngle) {
126+
final Quaternionfc q = new Quaternionf(axisAngle);
127+
return (Vector3f) ops().run(Rotate3f.class, v, v, q);
128+
}
129+
130+
@Override
131+
public String getName() {
132+
return "linalg";
133+
}
134+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*-
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
30+
package net.imagej.ops.linalg.rotate;
31+
32+
import net.imagej.ops.Ops;
33+
import net.imagej.ops.special.hybrid.AbstractBinaryHybridCFI1;
34+
35+
import org.joml.Quaterniondc;
36+
import org.joml.Vector3d;
37+
import org.scijava.plugin.Plugin;
38+
39+
/**
40+
* Rotates the vector by the quaternion.
41+
*
42+
* @author Richard Domander (Royal Veterinary College, London)
43+
*/
44+
@Plugin(type = Ops.LinAlg.Rotate.class)
45+
public class Rotate3d extends
46+
AbstractBinaryHybridCFI1<Vector3d, Quaterniondc, Vector3d> implements
47+
Ops.LinAlg.Rotate
48+
{
49+
50+
@Override
51+
public void compute(final Vector3d v, final Quaterniondc q,
52+
final Vector3d vDot)
53+
{
54+
vDot.set(v);
55+
vDot.rotate(q);
56+
}
57+
58+
@Override
59+
public Vector3d createOutput(final Vector3d input1,
60+
final Quaterniondc input2)
61+
{
62+
return new Vector3d();
63+
}
64+
65+
@Override
66+
public void mutate1(final Vector3d v, final Quaterniondc q) {
67+
v.rotate(q);
68+
}
69+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*-
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
30+
package net.imagej.ops.linalg.rotate;
31+
32+
import net.imagej.ops.Ops;
33+
import net.imagej.ops.special.hybrid.AbstractBinaryHybridCFI1;
34+
35+
import org.joml.Quaternionfc;
36+
import org.joml.Vector3f;
37+
import org.scijava.plugin.Plugin;
38+
39+
/**
40+
* Rotates the vector by the quaternion.
41+
*
42+
* @author Richard Domander (Royal Veterinary College, London)
43+
*/
44+
@Plugin(type = Ops.LinAlg.Rotate.class)
45+
public class Rotate3f extends
46+
AbstractBinaryHybridCFI1<Vector3f, Quaternionfc, Vector3f> implements
47+
Ops.LinAlg.Rotate
48+
{
49+
50+
@Override
51+
public void compute(final Vector3f v, final Quaternionfc q,
52+
final Vector3f vDot)
53+
{
54+
vDot.set(v);
55+
vDot.rotate(q);
56+
}
57+
58+
@Override
59+
public Vector3f createOutput(final Vector3f v, final Quaternionfc q) {
60+
return new Vector3f();
61+
}
62+
63+
@Override
64+
public void mutate1(final Vector3f v, final Quaternionfc q) {
65+
v.rotate(q);
66+
}
67+
}

src/main/templates/net/imagej/ops/Ops.list

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ namespaces = ```
240240
[name: "lbp", iface: "LBP", ops: [
241241
[name: "lbp2D", iface: "LBP2D"]
242242
]],
243+
[name: "linalg", iface: "LinAlg", ops: [
244+
[name: "rotate", iface: "Rotate"]
245+
]],
243246
[name: "logic", iface: "Logic", ops: [
244247
[name: "and", iface: "And"],
245248
[name: "bool", iface: "Bool"],

0 commit comments

Comments
 (0)