/***
 *  PROJECT     :  Generation of Anatomical Models for Surgical Simulators (GAMSS)
 *  AUTHOR      :  Raimundo Sierra
 *  CONTACT     :  http://www.rsierra.com/?main=contact
 *  CREATED     :  01.12.2001
 *  CHANGED     :  
 *  DESCRIPTION :  Functions to store arrays as ppm images and display them
 * 
 *  TODO        :    
 */

#ifndef WRITE_PPM
#define WRITE_PPM

#include <stdlib.h>
#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include "scalefunctions.h"

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


/* additional memory needed */
                                           // save image in greylevels to disk,
                                           // save_write as the values are copied internally,
                                           // so that image remains unchanged
                                           // will write tmpi_XXXXX.ppm in current directory
                                           // values will be fit linearly into the range 0..255
int save_write_ppm_greylevel(const short *image, const int dim1=256, const int dim2=256);
int save_write_ppm_greylevel(const float *image, const int dim1=256, const int dim2=256);
int save_write_ppm_color(    const short *image, const int dim1=256, const int dim2=256);
int save_write_ppm_color(    const float *image, const int dim1=256, const int dim2=256);

                                           // same as above, but also open image with xv
int save_write_and_display_ppm_greylevel(const short *image, const int dim1=256, const int dim2=256);
int save_write_and_display_ppm_greylevel(const float *image, const int dim1=256, const int dim2=256);
int save_write_and_display_ppm_color(    const short *image, const int dim1=256, const int dim2=256);
int save_write_and_display_ppm_color(    const float *image, const int dim1=256, const int dim2=256);


/* Less memory, faster but not save:*/
                                           // save image in greylevels/colors to disk,
                                           // not save as the values are not copied internally,
                                           // so that image can change!!!
                                           // will write tmpi_XXXXX.ppm in current directory
                                           // values will be fit linearly into the range 0..255
int write_ppm_greylevel(short *image, const int dim1=256, const int dim2=256);
int write_ppm_greylevel(float *image, const int dim1=256, const int dim2=256);
int write_ppm_color(    short *image, const int dim1=256, const int dim2=256);
int write_ppm_color(    float *image, const int dim1=256, const int dim2=256);

                                           // same as above, but also open image with xv
int write_and_display_ppm_greylevel(short *image, const int dim1=256, const int dim2=256);
int write_and_display_ppm_greylevel(float *image, const int dim1=256, const int dim2=256);
int write_and_display_ppm_color(    short *image, const int dim1=256, const int dim2=256);
int write_and_display_ppm_color(    float *image, const int dim1=256, const int dim2=256);





//TODO:
void write_ppm_grey_difference(float *array1, float * array2, const int dim1=256, const int dim2=256, const int dim3=1);


#endif // WRITE_PPM
