diff --git a/pom.xml b/pom.xml index 3a93736c9e08f7cf4f137c5b1ff124c35e6cadc0..61a58cf8dc9130da00dfc48ee6daa3b8c9243ea7 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ <!-- Project Information --> <artifactId>3d-spheres-vtk</artifactId> - <version>1.0.1</version> + <version>2.0.0</version> <packaging>jar</packaging> diff --git a/src/main/java/plugins/lagache/spherevtk/DrawSpheresVTK.java b/src/main/java/plugins/lagache/spherevtk/DrawSpheresVTK.java index 5347509d4b748190c25b60c880b1528ce03c7b1d..b20e0efcd68fc541e42f8f2b3d4080da1f241cc9 100644 --- a/src/main/java/plugins/lagache/spherevtk/DrawSpheresVTK.java +++ b/src/main/java/plugins/lagache/spherevtk/DrawSpheresVTK.java @@ -1,59 +1,67 @@ -package plugins.lagache.spherevtk; +/* + * Copyright (c) 2010-2023. Institut Pasteur. + * + * This file is part of Icy. + * Icy 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. + * + * Icy 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 Icy. If not, see <https://www.gnu.org/licenses/>. + */ -import java.awt.Color; -import java.awt.geom.Point2D; -import java.util.ArrayList; +package plugins.lagache.spherevtk; import icy.plugin.abstract_.Plugin; -import icy.roi.BooleanMask2D; -import icy.roi.ROI; -import icy.roi.ROI2D; import plugins.adufour.blocks.lang.Block; import plugins.adufour.blocks.util.VarList; -import plugins.adufour.vars.lang.VarColor; -import plugins.adufour.vars.lang.VarDouble; -import plugins.adufour.vars.lang.VarDoubleArrayNative; -import plugins.adufour.vars.lang.VarROIArray; -import plugins.adufour.vars.lang.VarSequence; -import plugins.adufour.vars.lang.VarString; -import plugins.kernel.roi.roi2d.ROI2DPoint; +import plugins.adufour.vars.lang.*; -// Colocalisation with Ripley function K -// Significant +import java.awt.*; +/** + * Colocalisation with Ripley function K Significant + */ public class DrawSpheresVTK extends Plugin implements Block { - VarSequence input_sequence = new VarSequence("Input sequence", null); - VarDoubleArrayNative x= new VarDoubleArrayNative("x", null); - VarDoubleArrayNative y= new VarDoubleArrayNative("y", null); - VarDoubleArrayNative z= new VarDoubleArrayNative("z", null); - VarString name = new VarString("Name of the overlay", "detections"); - VarColor color = new VarColor("Color", Color.blue); - VarDouble size = new VarDouble("Size", 1.0); - @Override - public void declareInput(VarList inputMap) { - - inputMap.add("Input Sequence", input_sequence); - inputMap.add("x",x); - inputMap.add("y",y); - inputMap.add("z",z); - inputMap.add("Size",size); - inputMap.add("Color",color); - inputMap.add("Name of the overlay",name); - } - - @Override - public void declareOutput(VarList outputMap) { - } - - @Override - public void run() { - - // Add the cross overlay, it becomes active after being added. - input_sequence.getValue().addOverlay(new SphereVTK(x.getValue(),y.getValue(),z.getValue(),size.getValue(),color.getValue(),name.getValue())); - } - - } + VarSequence input_sequence = new VarSequence("Input sequence", null); + VarDoubleArrayNative x = new VarDoubleArrayNative("x", null); + VarDoubleArrayNative y = new VarDoubleArrayNative("y", null); + VarDoubleArrayNative z = new VarDoubleArrayNative("z", null); + VarString name = new VarString("Name of the overlay", "detections"); + VarColor color = new VarColor("Color", Color.blue); + VarDouble size = new VarDouble("Size", 1.0); + + @Override + public void declareInput(final VarList inputMap) { + + inputMap.add("Input Sequence", input_sequence); + inputMap.add("x", x); + inputMap.add("y", y); + inputMap.add("z", z); + inputMap.add("Size", size); + inputMap.add("Color", color); + inputMap.add("Name of the overlay", name); + } + + @Override + public void declareOutput(final VarList outputMap) { + } + + @Override + public void run() { + + // Add the cross overlay, it becomes active after being added. + input_sequence.getValue().addOverlay(new SphereVTK(x.getValue(), y.getValue(), z.getValue(), size.getValue(), color.getValue(), name.getValue())); + } + +} diff --git a/src/main/java/plugins/lagache/spherevtk/SphereVTK.java b/src/main/java/plugins/lagache/spherevtk/SphereVTK.java index 1f038980d4c36d1dfedd41268da1da62b3f7ed60..639a95a20ace5baf1465b644629e705a798596ab 100644 --- a/src/main/java/plugins/lagache/spherevtk/SphereVTK.java +++ b/src/main/java/plugins/lagache/spherevtk/SphereVTK.java @@ -1,59 +1,43 @@ /* - * Copyright 2010, 2011 Institut Pasteur. - * - * This file is part of ICY. - * - * ICY is free software: you can redistribute it and/or modify + * Copyright (c) 2010-2023. Institut Pasteur. + * + * This file is part of Icy. + * Icy 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. - * - * ICY is distributed in the hope that it will be useful, + * + * Icy 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 ICY. If not, see <http://www.gnu.org/licenses/>. + * along with Icy. If not, see <https://www.gnu.org/licenses/>. */ + package plugins.lagache.spherevtk; import icy.canvas.IcyCanvas; import icy.painter.Overlay; import icy.painter.VtkPainter; import icy.sequence.Sequence; -import icy.vtk.VtkUtil; - -import java.awt.Color; -import java.awt.Graphics2D; - import plugins.kernel.canvas.VtkCanvas; -import vtk.vtkActor; -import vtk.vtkFloatArray; -import vtk.vtkGlyph3D; -import vtk.vtkLookupTable; -import vtk.vtkMolecule; -import vtk.vtkMoleculeMapper; -import vtk.vtkPoints; -import vtk.vtkPolyDataMapper; -import vtk.vtkProp; -import vtk.vtkSphereSource; -import vtk.vtkUnsignedShortArray; -import vtk.vtkUnstructuredGrid; +import vtk.*; + +import java.awt.*; /** * @author stephane */ -public class SphereVTK extends Overlay implements VtkPainter -{ +public class SphereVTK extends Overlay implements VtkPainter { double[] x, y, z; double size; Color color; private vtkActor[] sphere_ens; - public SphereVTK(double[] x, double[] y, double[] z, double size, Color color, String name) - { + public SphereVTK(final double[] x, final double[] y, final double[] z, final double size, final Color color, final String name) { super(name); this.x = x; @@ -65,8 +49,7 @@ public class SphereVTK extends Overlay implements VtkPainter init(); } - private void init() - { + private void init() { // create points final vtkPoints points = new vtkPoints(); // setup scales @@ -82,8 +65,7 @@ public class SphereVTK extends Overlay implements VtkPainter // index, R, G, B, A colors.SetTableValue(0, color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1.0); - for (int i = 0; i < x.length; i++) - { + for (int i = 0; i < x.length; i++) { points.InsertNextPoint(x[i], y[i], z[i]); scales.InsertNextValue(1); col.InsertNextValue(0); // first color @@ -91,12 +73,12 @@ public class SphereVTK extends Overlay implements VtkPainter // grid structured to append center, radius and color label final vtkUnstructuredGrid grid = new vtkUnstructuredGrid(); - + grid.SetPoints(points); grid.GetPointData().AddArray(scales); grid.GetPointData().SetActiveScalars("scales"); // !!!to set radius first grid.GetPointData().AddArray(col); - + points.Delete(); scales.Delete(); col.Delete(); @@ -109,8 +91,8 @@ public class SphereVTK extends Overlay implements VtkPainter sphere.SetPhiResolution(6); // object to group sphere and grid and keep smooth interaction - final vtkGlyph3D glyph3D = new vtkGlyph3D(); - + final vtkGlyph3D glyph3D = new vtkGlyph3D(); + glyph3D.SetInputData(grid); glyph3D.SetSourceConnection(sphere.GetOutputPort()); @@ -130,95 +112,18 @@ public class SphereVTK extends Overlay implements VtkPainter sphere_ens[0] = actor; } - // init vtk objects - private void init_2() - { - final double[] pts = new double[x.length * 3]; - - // convert to single array - for (int i = 0; i < x.length; i++) - { - pts[(i * 3) + 0] = x[i]; - pts[(i * 3) + 1] = y[i]; - pts[(i * 3) + 2] = z[i]; - } - - final vtkPoints vtkPts = VtkUtil.getPoints(pts); - - sphere_ens = new vtkActor[1]; - final vtkMolecule mol = new vtkMolecule(); - - mol.SetPoints(vtkPts); - vtkPts.Delete(); - - final vtkUnsignedShortArray atomicNums = (vtkUnsignedShortArray) mol.GetVertexData().GetScalars(); - - // set atomic num - for (int i = 0; i < x.length; i++) - atomicNums.InsertValue(i, 0); - - // mapper - final vtkMoleculeMapper molMapper = new vtkMoleculeMapper(); - - molMapper.SetInputData(mol); - molMapper.UseFastSettings(); - - // molMapper.SetRenderAtoms(true); - // molMapper.SetRenderBonds(false); - - // actor - final vtkActor molActor = new vtkActor(); - molActor.SetMapper(molMapper); - - sphere_ens[0] = molActor; - } - - // init vtk objects - private void init_old() - { - sphere_ens = new vtkActor[x.length]; - for (int i = 0; i < x.length; i++) - { - // source - final vtkSphereSource sphere = new vtkSphereSource(); - sphere.SetRadius(size); - sphere.SetThetaResolution(6); - sphere.SetPhiResolution(6); - - sphere.SetCenter(x[i], y[i], z[i]); - - // mapper - final vtkPolyDataMapper map = new vtkPolyDataMapper(); - map.SetInputConnection(sphere.GetOutputPort()); - - // actor - vtkActor aSphere = new vtkActor(); - aSphere.SetMapper(map); - // double total = color.getRed()+ color.getGreen()+ color.getBlue(); - double red = color.getRed() / 255.; - double green = color.getGreen() / 255.; - double blue = color.getBlue() / 255.; - - aSphere.GetProperty().SetColor(red, green, blue); - sphere_ens[i] = aSphere; - } - } - @Override - public void paint(Graphics2D g, Sequence sequence, IcyCanvas canvas) - { + public void paint(final Graphics2D g, final Sequence sequence, final IcyCanvas canvas) { super.paint(g, sequence, canvas); - if (canvas instanceof VtkCanvas) - { + if (canvas instanceof VtkCanvas) { // disable picking by using this property ((VtkCanvas) canvas).getPicker().PickFromListOn(); } } @Override - public vtkProp[] getProps() - { + public vtkProp[] getProps() { return sphere_ens; } } \ No newline at end of file