/*
BSD 2-Clause License
Copyright (c) 2019, Michael Doube
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.bonej.utilities;

import java.util.ArrayList;
import java.util.List;

import org.joml.Vector3d;
import org.joml.Vector3dc;
import org.scijava.vecmath.Color3f;
import org.scijava.vecmath.Point3f;

import customnode.CustomPointMesh;
import ij3d.Image3DUniverse;

/**
 * Convenience methods for displaying data.
 * 
 * Helpful for debugging and for users to visualise their results.
 * 
 * @author Michael Doube
 *
 */
public class Visualiser {
	/**
	 * Plot a set of 3D coordinates in Benjamin Schmidt's ImageJ 3D Viewer
	 *
	 * @param points
	 *            float[][] n x 3 array of 3D (x,y,z) coordinates
	 * @param title
	 *            String name of the dataset
	 *
	 */
	public static void display3DPoints(final double[][] points, String title) {
		final int nPoints = points.length;
		// Create a CustomMesh from the coordinates
		final List<Point3f> mesh = new ArrayList<>();
		for (int i = 0; i < nPoints; i++) {
			mesh.add(new Point3f((float) points[i][0], (float) points[i][1], (float) points[i][2]));
		}

		final CustomPointMesh cm = new CustomPointMesh(mesh);
		final Color3f green = new Color3f(0.0f, 0.5f, 0.0f);
		cm.setColor(green);
		cm.setPointSize(1);

		// Create a universe
		final Image3DUniverse univ = new Image3DUniverse();
		
		// Add the points
		univ.addCustomMesh(cm, title).setLocked(true);
		
		//show the universe
		univ.show();
	}
	
	public static void display3DPoints(List<Vector3dc> vectors, String title) {
		double[][] points = new double[vectors.size()][3];
		int i = 0;
		for (Vector3dc v : vectors) {
			points[i][0] = v.x();
			points[i][1] = v.y();
			points[i][2] = v.z();
			i++;
		}
		display3DPoints(points, title);
	}
}

@@ -1359,25 +1359,26 @@
 va.util.
-ArrayList
+Collection
 ;%0Aimport
@@ -1399,34 +1399,8 @@
 t;%0A%0A
-import org.joml.Vector3d;%0A
 impo
@@ -1560,16 +1560,67 @@
 verse;%0A%0A
+import static java.util.stream.Collectors.toList;%0A%0A
 /**%0A * C
@@ -1888,51 +1888,28 @@
 ram 
-points%0A%09 *            float%5B%5D%5B%5D n x 3 array
+vectors a collection
  of 
@@ -1919,26 +1919,22 @@
 (x,y,z) 
-coordinate
+vector
 s%0A%09 * @p
@@ -1947,23 +1947,8 @@
 itle
-%0A%09 *           
  Str
@@ -1971,20 +1971,16 @@
 dataset%0A
-%09 *%0A
 %09 */%0A%09pu
@@ -2022,308 +2022,198 @@
 nal 
-double%5B%5D%5B%5D points, String title) %7B%0A%09%09final int nPoints = points.length;%0A%09%09// Create a CustomMesh from the coordinates%0A%09%09final List%3CPoint3f%3E mesh = new ArrayList%3C%3E();%0A%09%09for (int i = 0; i %3C nPoints; i++) %7B%0A%09%09%09mesh.add(new Point3f((float) points%5Bi%5D%5B0%5D, (float) points%5Bi%5D%5B1%5D, (float) points%5Bi%5D%5B2%5D));%0A%09%09%7D%0A
+Collection%3CVector3dc%3E vectors, final String title) %7B%0A%09%09// Create a CustomMesh from the coordinates%0A%09%09final List%3CPoint3f%3E points = vectors.stream().map(Visualiser::toPoint).collect(toList());
 %0A%09%09f
@@ -2262,12 +2262,14 @@
 esh(
-mesh
+points
 );%0A%09
@@ -2563,25 +2563,25 @@
 %0A%09%7D%0A
-%09
 %0A%09p
-ublic
+rivate
  static 
 void
@@ -2580,34 +2580,30 @@
 tic 
-void display3DPoints(List%3C
+Point3f toPoint(final 
 Vect
@@ -2611,251 +2611,78 @@
 r3dc
-%3E
  v
-ectors, String title) %7B%0A%09%09double%5B%5D%5B%5D points = new double%5Bvectors.size()%5D%5B3%5D;%0A%09%09int i = 0;%0A%09%09for (Vector3dc v : vectors) %7B%0A%09%09%09points%5Bi%5D%5B0%5D = v.x();%0A%09%09%09points%5Bi%5D%5B1%5D = v.y();%0A%09%09%09points%5Bi%5D%5B2%5D = v.z();%0A%09%09%09i++;%0A%09%09%7D%0A%09%09display3DPoints(points, title
+) %7B%0A%09%09return new Point3f((float) v.x(), (float) v.y(), (float) v.z()
 );%0A%09

Remove convenience method