int main(int argc, char** argv)
{
    time_t start= time(NULL);

    FsSurfaceReader* fsr1 = new FsSurfaceReader(argv[1]);

    // the reader for the vtp files
/*    vtkXMLPolyDataReader* reader = vtkXMLPolyDataReader::New();
    reader->SetFileName(argv[1]);
    reader->Update();*/

    MeshAnalyser* ma = new MeshAnalyser(fsr1->GetVTKData());

//    MeshAnalyser* ma1 = new MeshAnalyser(fsr1->GetVTKData());
//    ma1->Simplify(20000);


//    MeshAnalyser* ma = new MeshAnalyser(argv[1]);


    ma->ComputeTravelDepth(false);

//    MeshAnalyser* ma = new MeshAnalyser(argv[1]);

//    ma->ComputeClosedMesh();

    //may be replaced by ComputeTravelDepthFromClosed
    //which is slower but does not allow to cross the surface
//    ma->ComputeEuclideanDepth(true);

//    ma->ComputeCurvature(0.7);

//    ma->WriteIntoFile((char*)"closed.vtk",(char*)"closed");

//    ma->ComputeMedialSurfaces();

    ma->WriteIntoFile(argv[2], (char*)"depth");

//    VtkFileEditor* vfe = new VtkFileEditor(argv[2]);
//    vfe->CreateField((char*)"DEPTH", ma->GetEuclideanDepth());
//    vfe->CreateField((char*)"CURVATURE", ma->GetCurvature());
//    delete vfe;

    delete ma;
//    delete fsr1;


    cout<<"Elapsed time (meshTest): "<<time(NULL)-start<<" s"<<endl;
    return 0;



}
int main(int argc, char** argv)
{
    cout<<endl;
    time_t start= time(NULL);

    if(argc < 3)
    {
        print_help();
        return -1;
    }

    /* Default values for options */
    int Method=0;  // using ComputePrincipalCurvatures()
    bool Gaussian=false, Max=false, Min=false, MinDir=false;  // whether output Gaussian, max and min curvatures, and directions of minimal curvature
    char * GaussianVTK, * MaxVTK, * MinVTK, * MinDirVTK; // files to save Gaussian, max and min curvatures, and directions of minimal curvature
    double NeighborhoodSize = 0.7; // default neighborhood size for computing curvature

    /*Check whether we have mandatory I/Os*/
    int Mandatory = 0; // number of mandatory I/O (input mesh and mean curvature VTK) available
    for (int i=1;i<argc;i++) // we may need to use getopt or getlongopt later - Forrest, 2012/05/29
    {
        if (argv[i][0] != '-')
        {
            Mandatory++;
        }
        else
            i++; // skip the value after a flag
    }
    if (Mandatory < 2)
        {
            cout<<"[ERROR] Not sufficient mandatory I/Os. Check usage please. "<<endl;
            print_help();
            return -4;
        }

    /* Processing options and arguments */
    for (int i=1;i<argc;i++) // we may need to use getopt or getlongopt later - Forrest, 2012/05/29
    {
        if (argv[i][0] != '-')
            continue; // no more options
        switch (argv[i][1])
        {
            case 'm' :  // select curvature computation method
                Method = atoi(argv[i+1]);
                cout<<"Using method "<<Method<<" to compute curvature(s)..."<<endl;
                break;

            case 'g' :  // whether output Gaussian curvature
                if (Method==2)
                {
                    cout<<"[ERROR]: Method 2 does NOT compute Gaussian curvature."<<endl;
                    return -2;
                }
                Gaussian = true;
                GaussianVTK = argv[i+1];
                break;

            case 'x' : // whether output max curvature
                Max = true;
                MaxVTK = argv[i+1];
                break;

            case 'i' : // whether output min curvature
                Min = true;
                MinVTK = argv[i+1];
                break;

            case 'n': //set neighborhood size for computing curvature
//                if (Method==0)
//                        cout <<"[Warning]: Method 0 does not need neighborhood size though you provided it."<<endl;
                NeighborhoodSize = atof(argv[i+1]);
                break;

            case 'd': // whether output directions of min curvature
                if ((Method==2) || (Method==1))
                {
                    cout<<"[ERROR]: Method 2 or 1 does NOT compute directions of minimal curvature. Remove flag -d and its argument please."<<endl;
                    return -3;
                }
                MinDir = true;
                MinDirVTK = argv[i+1];
                break;

            default:
                cout<<"[ERROR] Unrecognized argument flag or option. Check usage. ";
                print_help();
        } // end of switch
    } // end of looping thru arguments

    /*Compute curvatures*/
    MeshAnalyser* ma = new MeshAnalyser(argv[argc-2]); // the second last input is the inputVTK
    switch (Method)
    {
        case 2:
            ma->ComputeCurvature(NeighborhoodSize, 20);
            break;
        case 1:
            ma->ComputeBothCurvatures(NeighborhoodSize);
            break;
        default: // =0
            vtkDoubleArray* minDirections= ma->ComputePrincipalCurvatures(NeighborhoodSize);
            if(MinDir)
            {
                cout<<"Saving directions of minimal curvature into file "<<MinDirVTK<<endl;
                double dir[3];

                ofstream myfile(MinDirVTK);
                myfile.clear();


                for(int i = 0; i<minDirections->GetNumberOfTuples() ; i++)
                {
                    minDirections->GetTuple(i,dir);
                    myfile<<dir[0]<<" "<<dir[1]<<" "<<dir[2]<<endl;
                }
                myfile.close();
            }
            break;
    }
    /*Write results into VTK files*/
    ma->WriteIntoFile(argv[argc-1], (char*)"curv");  // the very last input is the VTK for mean curv
    if(Gaussian)
    {
        cout<<"Saving Gaussian curvature into file "<<GaussianVTK<<endl;
        ma->WriteIntoFile(GaussianVTK, (char*)"gCurv");
    }
    if(Max)
    {
        cout<<"Saving maximum curvature into file "<<MaxVTK<<endl;
        ma->WriteIntoFile(MaxVTK, (char*)"curv1");
    }

    if(Min)
    {
        cout<<"Saving minimum curvature into file "<<MinVTK<<endl;
        ma->WriteIntoFile(MinVTK, (char*)"curv2");
    }
    cout<<"Elapsed time: "<<time(NULL)-start<<" s"<<endl;
    return 0;
}