/*

Description: 
             
Author:      Raimundo Sierra
             www.rsierra.com

Copyright:   Copyright (c) 2000 Raimundo Sierra. All rights reserved.
LICENSE:     This program 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 2 of the License, or
             (at your option) any later version.

             This program 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 this program; if not, write to the Free Software
             Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

Institution: Surgical Planning Laboratory
             Department of Radiology
             Brigham and Women's Hospital
             Harvard Medical School
             MA 02115
             USA

Date:        11.2000 - 3.2001

Modifications:
<Date>   <Init>    <Version>    <Description>

*/
#ifndef _mydisplayclass
#define _mydisplayclass 1
#include <stdlib.h>
#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include "tensorfield.h"
#include "eigenfield.h"
#include "background.h"

#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSphereSource.h"
#include "vtkTensors.h"
#include "vtkTensor.h"
#include "vtkStructuredPoints.h"
#include "vtkTensorGlyph.h"
#include "vtkPolyDataNormals.h"
#include "vtkLookupTable.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkScalars.h"

#include "vtkPolyDataCollection.h"
#include "vtkOutlineFilter.h"
#include "vtkHyperStreamline.h"

extern int imagecounter;                   // incremental counter to save temporary images

class display{
 private:
  int _dimx, _dimy, _dimz;                 // the dimensions of the tensorfield
  float _deltax, _deltay, _deltaz;         // the distance between voxels = voxelsize

                                           // display image in greylevels
                                           // will write tmpi_XXX.pic in current directory
  int greylevel(short *image, const int dim1=256, const int dim2=256) const;
  int greylevel(float *image, const int dim1=256, const int dim2=256) const;

                                           // display image in colors
                                           // image is therefore an array with 3*dim1*dim2 values
                                           // will write tmpi_XXX.ppm in current directory
  int color(short *image, const int dim1=256, const int dim2=256) const; 

  void colorlabels(short * image, int * label, int * offset, int * plane) const;
  void greylabels( short * image, int * label, int * offset, int * plane) const;

 public:
  // constructor
  display(tensorfield &t_field);
  display(eigenfield  &e_field);
  display(const int dimx=256, const int dimy=256, const int dimz=1, const float deltax=1.0, const float deltay=1.0, const float deltaz=1.0);

  // destructor
  ~display();

                                           // Display an array of float/ short as greylevels
  void greyarray(float *myarray, const int dim1=256, const int dim2=256, const int dim3=1);
  void greyarray(short *myarray, const int dim1=256, const int dim2=256, const int dim3=1);
  void greyarray(unsigned short *myarray, const int dim1=256, const int dim2=256, const int dim3=1);
  
  void greyarrayDifference(float *array1, float * array2, const int dim1=256, const int dim2=256, const int dim3=1);

                                           // offset from (0,0,0), default is (0,0,0)
                                           // window is size of image to display, 
                                           // finds smallest dimension and displays several
                                           // images for this dimension
  float backgd(     background &bac,      int offset[3], int window[3], const int selection, float thresh=0.0);
  
  void element(     tensorfield &t_field, int offset[3], int window[3], const int elementx, const int elementy) const;
  void det(         tensorfield &t_field, int offset[3], int window[3]) const;
  void trace(       tensorfield &t_field, int offset[3], int window[3]) const;
  void euclid(      tensorfield &t_field, int offset[3], int window[3]) const; 

  void lambda1(     eigenfield  &e_field, int offset[3], int window[3]) const;
  void lambda2(     eigenfield  &e_field, int offset[3], int window[3]) const;
  void lambda3(     eigenfield  &e_field, int offset[3], int window[3]) const;
 
  void vector1(     eigenfield  &e_field, int offset[3], int window[3], const int element=0) const;
  void vector2(     eigenfield  &e_field, int offset[3], int window[3], const int element=0) const;
  void vector3(     eigenfield  &e_field, int offset[3], int window[3], const int element=0) const;

  void max_eigenval(eigenfield  &e_field, int offset[3], int window[3]) const;
  void anisotropy(  eigenfield  &e_field, int offset[3], int window[3], float thresh=0.8, float tol=0.1) const;
  void closeLine(   eigenfield  &e_field, int offset[3], int window[3], float thresh=0.8, float tol=0.1) const;
  void closePlane(  eigenfield  &e_field, int offset[3], int window[3], float thresh=0.8, float tol=0.1) const;
  void closeSphere( eigenfield  &e_field, int offset[3], int window[3], float thresh=0.8, float tol=0.1) const;

  void classes_cl_cp_cs(eigenfield  &e_field, int offset[3], int window[3]);

  void labels(      eigenfield  &e_field, int offset[3], int window[3], float thresh=0.8, float tol=0.1, const int method=0, const int similarity=0, const int colors=0) const;

                                            // functions that display tensorfield throu the vtk-class
                                            // displays the tensors as single components
                                            // background=0 sets the background black and tensors lighter the more "important" they are
                                            // background=1 sets the background white and tensors darker ...
  void myVtkTensor( tensorfield &t_field, int offset[3], int window[3], vtkScalars *scalars=NULL, const int resolution=6, const int quality=0, const int background=0); 
                                            // displays the tensors as Hyperstreamlines; prototype function to display fibers
  void myVtkFibers( tensorfield &t_field, int offset[3], int window[3], const int maxNumberOfFibers=1); 
 
};
#endif

                                            // display specified function from tensorfield
  //void display(const char function[]="det", int slice_no=0) const;
