/***
 * Image/J Plugins
 * Copyright (C) 2002 Jarek Sacha
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Latest release available at http://sourceforge.net/projects/ij-plugins/
 */
package net.sf.ij.vtk;

import ij.ImagePlus;
import ij.process.ByteProcessor;
import ij.process.ImageProcessor;

import java.io.File;

import java.io.IOException;

import net.sf.ij.io.vtk.VtkDecoder;
import net.sf.ij.io.vtk.VtkEncoder;

import vtk.vtkImageData;
import vtk.vtkStructuredPointsReader;

/**
 *  Factory creating instances of class vtk.vtkImageData. In general performs
 *  translation of images from ImageJ representatin to VTK representation.
 *
 * @author     Jarek Sacha
 * @since    September 7, 2002
 * @version  $Revision: 1.4 $
 */

public class VtkImageDataFactory {

  /**  Constructor for the VtkImageDataFactory object */
  public VtkImageDataFactory() { }


  /**
   *  Create a vtkImageData object from ImageProcessor object.
   *
   * @param  ip               Description of the Parameter
   * @return                  Description of the Return Value
   * @exception  IOException  Description of the Exception
   */
  public static vtkImageData create(ImageProcessor ip) throws IOException {
    File tmpFile = File.createTempFile("ijImageData", ".vtk");
    String tmpFileName = tmpFile.getAbsolutePath();

    // Save ImagePlus in VTK format in a temporary file.
    VtkEncoder.save(tmpFileName, new ImagePlus(tmpFileName, ip));

    // Read the temporary file using VTK.
    vtkStructuredPointsReader reader = new vtkStructuredPointsReader();
    reader.SetFileName(tmpFileName);
    reader.Update();
    reader.CloseVTKFile();

    vtkImageData data = (vtkImageData) reader.GetOutput();

    // Remove the temporary file.
    tmpFile.delete();

    // Return reference to the VTK image.
    return data;
  }

    /**
     *  Create a vtkImageData object from ImagePlus object.
     *
     * @param imp
     * @return
     * @throws IOException
     */
    public static vtkImageData create(ImagePlus imp) throws IOException {
      File tmpFile = File.createTempFile("ijImageData", ".vtk");
      String tmpFileName = tmpFile.getAbsolutePath();

      // Save ImagePlus in VTK format in a temporary file.
      VtkEncoder.save(tmpFileName, imp);

      // Read the temporary file using VTK.
      vtkStructuredPointsReader reader = new vtkStructuredPointsReader();
      reader.SetFileName(tmpFileName);
      reader.Update();
      reader.CloseVTKFile();

      vtkImageData data = (vtkImageData) reader.GetOutput();

      // Remove the temporary file.
      tmpFile.delete();

      // Return reference to the VTK image.
      return data;
    }

}

@@ -939,11 +939,12 @@
 ess.
-Byt
+Imag
 ePro
@@ -962,32 +962,97 @@
 ort 
-ij.process.ImageProcesso
+net.sf.ij.io.vtk.VtkEncoder;%0Aimport vtk.vtkImageData;%0Aimport vtk.vtkStructuredPointsReade
 r;%0A%0A
@@ -1072,17 +1072,16 @@
 o.File;%0A
-%0A
 import j
@@ -1105,145 +1105,8 @@
 n;%0A%0A
-import net.sf.ij.io.vtk.VtkDecoder;%0Aimport net.sf.ij.io.vtk.VtkEncoder;%0A%0Aimport vtk.vtkImageData;%0Aimport vtk.vtkStructuredPointsReader;%0A%0A
 /**%0A
@@ -1274,18 +1274,16 @@
 uthor   
-  
 Jarek Sa
@@ -1290,39 +1290,8 @@
 cha%0A
- * @since    September 7, 2002%0A
  * @
@@ -1316,9 +1316,9 @@
 : 1.
-4
+5
  $%0A 
@@ -1446,16 +1446,18 @@
 tory() %7B
+%0A 
  %7D%0A%0A%0A  /
@@ -2414,18 +2414,14 @@
  %7D%0A%0A
-  
   /**%0A
-  
    *
@@ -2477,22 +2477,18 @@
 ect.%0A   
-  *%0A  
+*%0A
    * @pa
@@ -2498,18 +2498,16 @@
  imp%0A   
-  
 * @retur
@@ -2508,18 +2508,16 @@
 @return%0A
-  
    * @th
@@ -2536,23 +2536,19 @@
 tion%0A   
-  
 */%0A
-  
   public
@@ -2611,18 +2611,16 @@
 ption %7B%0A
-  
     File
@@ -2678,18 +2678,16 @@
 %22);%0A    
-  
 String t
@@ -2723,26 +2723,24 @@
 utePath();%0A%0A
-  
     // Save 
@@ -2788,18 +2788,16 @@
 le.%0A    
- 
- 
 VtkEncod
@@ -2820,26 +2820,24 @@
 ame, imp);%0A%0A
-  
     // Read 
@@ -2870,18 +2870,16 @@
 TK.%0A    
-  
 vtkStruc
@@ -2938,26 +2938,24 @@
 ader();%0A    
- 
- 
 reader.SetFi
@@ -2975,18 +2975,16 @@
 eName);%0A
-  
     read
@@ -3000,18 +3000,16 @@
 ();%0A    
-  
 reader.C
@@ -3028,18 +3028,16 @@
 );%0A%0A    
- 
- 
 vtkImage
@@ -3084,26 +3084,24 @@
 put();%0A%0A    
-  
 // Remove th
@@ -3122,18 +3122,16 @@
 le.%0A    
-  
 tmpFile.
@@ -3145,18 +3145,16 @@
 );%0A%0A    
- 
- 
 // Retur
@@ -3187,18 +3187,16 @@
 ge.%0A    
-  
 return d
@@ -3200,17 +3200,15 @@
 n data;%0A
-  
   %7D%0A%0A%7D%0A

Add method create(ImagePlus imp)