/*commanlinetool for segmentation */
#include <fstream.h>
#include <stdio.h>
#include <time.h>

#include "../datalib/vector.h"
#include "../datalib/volume.h"
#include "../mathlib/statistic.h"
#include "../mathlib/transform.h"
#include "../mathlib/moments.h"

#include "../errorcode.h"

#include "../datalib/datacube.h"
#include "../datalib/cfddatacube.h"
#include "../datalib/testcubes.h"

#include "../reconstructionlib/reconstruction.h"
#include "../mathlib/nld.h"

#include "command_line_parser.h"

using namespace std;
using namespace pramodx;


int
main(int argc, char **argv)
{
    DataCube convert(3);
	char inputfile[80];
	char outputfile[80];
	Vector<int> size(3);
	Vector<double> d(3);
	size[1]=0;	size[3]=0;	size[3]=0;
	d[1]=1.0;d[2]=1.0;d[3]=1.0;
        int invert=0;
        command_line_parser parser(argc, argv);
    if (argc<2)
    {
        cout << "Usage: tifftodx inputfilename.dat outputfilename" << endl;
        return 0;
    };

    for (int i=0;i<parser.get_n_options();i++)
    {
        option o=parser.get_option(i);
        if (strcmp(o.get_option(),"h")==0 || parser.get_n_filenames()==0)
        {
            cout << "Usage: tifftodx inputfilename.dat outputfilename" << endl;
            cout << "Optional: -dx:(spaceingx) -dy:(spaceingy) -dz:(spaceingz)" << endl;
            cout << "-i Invert data" << endl;
            return 0;
        };

       
        


        
        if (strcmp(o.get_option(),"dx")==0)
        {
            float help;
            if (sscanf (o.get_value(),"%f",&(help))==EOF) continue;
            d[1]=help;
            cout << "dx=" << d[1] << endl;
        };


        if (strcmp(o.get_option(),"dy")==0)
        {
            float help;
            if (sscanf (o.get_value(),"%f",&(help))==EOF) continue;
            d[2]=help;
            cout << "dy=" << d[2] << endl;
        };

        if (strcmp(o.get_option(),"dz")==0)
        {
            float help;
            if (sscanf (o.get_value(),"%f",&(help))==EOF) continue;
            d[3]=help;
            cout << "dz=" << d[3] << endl;
        };
 


       
    };

sprintf(inputfile,parser.get_filename(0));
printf("Inputfile:");
printf(inputfile);
printf("\n");
sprintf(outputfile,parser.get_filename(1));
printf("Outputfile:");
printf(outputfile);
printf("\n");
int res=convert.ReadFromTIFF(inputfile);
if (res!=0 && res!=NO_SPACEINGS_TAGS) 
{
	cout << "Error durring read!" << endl;
	return 1;
};
convert.SetSpaceing(d);

convert.writeDataForDX(outputfile);

return 0;
}


