arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

nrroIO.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     6-27-03
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2003 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 
00018 ///nrroIO.cpp
00019 
00020 /// read, write, that kind of stuff
00021 
00022 #include "nrro.h"
00023 
00024 /////////////////////////////////////////////////////////////////////////
00025 // Read nrrd
00026 /////////////////////////////////////////////////////////////////////////
00027 
00028 int Nrro::readNrrd(const char *nrrdFileName, bool proxy)
00029 {
00030    if(!nrrdFileName){
00031       NrroErr(" readNrrd(), Null file name ");
00032       return 1;
00033    }
00034 
00035    NrroDbg(" loading nrrd : ", nrrdFileName);
00036    Nrrd *nin = nrrdNew();
00037    if(proxy)
00038    {
00039       NrrdIO *nio = nrrdIONew();
00040       FILE *file = fopen( nrrdFileName, "rb" );
00041       nio->skipData = 1;
00042       if (nrrdRead(nin, file, nio)) 
00043       {
00044          char *berr = biffGetDone(NRRD);
00045          NrroErr("nrrd proxy load failed : ",berr);
00046          _valid = false;
00047          return 1;
00048       }
00049       fclose(file);
00050       nrrdIONix(nio);
00051    }
00052    else
00053    {
00054       if( nrrdLoad(nin, nrrdFileName) )
00055       {
00056          char *berr = biffGetDone(NRRD);
00057          NrroErr("nrrd load failed : ",berr);
00058          _valid = false;
00059          return 1;
00060       }
00061    }
00062 
00063    _name = nrrdFileName;    
00064    setNrrd(nin);
00065    readExtended();
00066 
00067    if( KIND_NOT_SET == _kind )
00068    {
00069       _kind = guessKind();
00070    }
00071 
00072    writeExtended();
00073    NrroDbg(nrrdFileName,"Loaded sucessfully!!");
00074    return 0;
00075 }
00076 
00077 /////////////////////////////////////////////////////////////////////////
00078 // Save nrrd
00079 /////////////////////////////////////////////////////////////////////////
00080 int Nrro::saveNrrd(const char *nrrdFileName)
00081 {
00082    NrroDbg(" saving nrrd ", nrrdFileName);
00083 
00084    if(!nrrdFileName)
00085    {    
00086       return 1;
00087    }
00088    writeExtended();
00089    if( nrrdSave(nrrdFileName, _nrrd, 0) )
00090    {
00091       char *berr = biffGetDone(NRRD);
00092       NrroErr("nrrd save failed : ",berr);
00093       return 1;
00094    }
00095 
00096    NrroDbg(" nrrd save Succesfull ", nrrdFileName);
00097 
00098    return 0;
00099 }
00100 
00101 /////////////////////////////////////////////////////////
00102 // the bottom
00103 /////////////////////////////////////////////////////////

Send questions, comments, and bug reports to:
jmk