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

nrroExtended.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     6-25-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 //nrroExtended.cpp
00019 
00020 #include "nrro.h"
00021 #include <sstream>
00022 
00023 using namespace std;
00024 using namespace gutz;
00025 
00026 /////////////////////////////////////////////////////////////////////////
00027 //read Extended
00028 /////////////////////////////////////////////////////////////////////////
00029 void Nrro::readExtended()
00030 {
00031    readKind();
00032    readPos();
00033    readPads();
00034    readName();
00035 }
00036 
00037 /////////////////////////////////////////////////////////////////////////
00038 //write Extended
00039 /////////////////////////////////////////////////////////////////////////
00040 void Nrro::writeExtended()
00041 {
00042    writeKind();
00043    writePos();
00044    writePads();
00045    writeName();
00046 }
00047 
00048 /////////////////////////////////////////////////////////////////////////
00049 //kind
00050 /////////////////////////////////////////////////////////////////////////
00051 const std::string NRRO_KIND_KEY("kind_nrro");
00052 const std::string KIND_NOT_SET_STR("not_set");
00053 const std::string KIND_UNKNOWN_STR("unknown");
00054 const std::string KIND_IMAGE_STR("Image");
00055 const std::string KIND_TIME_STR("Time_series");
00056 const std::string KIND_VOLUME_STR("Volume");
00057 const std::string KIND_PROXY_STR("Proxy");
00058 
00059 /////////////////////////////////////////////////////////////////////////
00060 //write kind
00061 /////////////////////////////////////////////////////////////////////////
00062 void Nrro::writeKind()
00063 {
00064    string kstr("");
00065    
00066    if(_kind == KIND_NOT_SET)
00067    {
00068       kstr = KIND_NOT_SET_STR;     
00069    }
00070    if(_kind & IMAGE)
00071    {
00072       kstr += KIND_IMAGE_STR;
00073    }
00074    if(_kind & VOLUME)
00075    {
00076       kstr += KIND_VOLUME_STR;
00077    }
00078    if(_kind & TIME_SERIES)
00079    {
00080       kstr += KIND_TIME_STR;
00081    }
00082    if(_kind & PROXY)
00083    {
00084       kstr += KIND_PROXY_STR;
00085    }
00086    if(kstr.empty())
00087    {
00088       kstr = KIND_NOT_SET_STR;
00089    }
00090 
00091    setComment(NRRO_KIND_KEY, kstr);
00092 }
00093 /////////////////////////////////////////////////////////////////////////
00094 //read kind
00095 /////////////////////////////////////////////////////////////////////////
00096 void Nrro::readKind()
00097 {
00098    //PROXY kinds cannot be read from extended,
00099    //this is a runtime user feature, so we don't 
00100    //want to invalidate existing data, by marking
00101    //this guy as a proxy.  But, if already is 
00102    //a proxy, better keep it that way.
00103 
00104    string kstr = getComment(NRRO_KIND_KEY);
00105 
00106    if(kstr.empty())
00107    {
00108       //NrroDbg("readKind(), kind not set");
00109       _kind = KIND_NOT_SET | (_kind & PROXY);
00110       return;
00111    }
00112 
00113    _kind = KIND_NOT_SET | (_kind & PROXY);
00114 
00115    if(kstr.find(KIND_UNKNOWN_STR) != -1)
00116       _kind = KIND_UNKNOWN | (_kind & PROXY);
00117 
00118    if(kstr.find(KIND_IMAGE_STR) != -1)
00119    {
00120       _kind |= IMAGE;
00121    }
00122 
00123    if(kstr.find(KIND_VOLUME_STR) != -1)
00124       _kind = VOLUME;
00125 
00126    if(kstr.find(KIND_TIME_STR) != -1)
00127       _kind |= TIME_SERIES;
00128 
00129 }
00130 
00131 /////////////////////////////////////////////////////////////////////////
00132 //Pads
00133 /////////////////////////////////////////////////////////////////////////
00134 const std::string NRRO_PADS_KEY("unpadded_nrro");
00135 
00136 void Nrro::writePads()
00137 {
00138    ostringstream ss;
00139    for(int i=0; i<int(dim()); ++i)
00140    {
00141       ss << _pads[i] << ",";
00142    }
00143    string padsstr = ss.str();
00144    setComment(NRRO_PADS_KEY, padsstr);
00145 }
00146 
00147 void Nrro::readPads()
00148 {
00149    string padsstr = getComment(NRRO_PADS_KEY);
00150    if(padsstr.empty())
00151    {
00152       //NrroDbg("readPads(), padds not set");
00153       //for(int i=0; i<int(dim()); ++i)
00154       //{
00155       //        _pads[i] = vec2ui(0, dim(i));
00156       //}
00157       return;
00158    }
00159 
00160    int sidx = -1; //starting point for parsing string
00161    bool fail = false; //did we fail to read the pads
00162    for(int i=0; i<int(dim()); ++i)
00163    {
00164       fail = str2vec2<unsigned int>(padsstr.substr(padsstr.find_first_not_of(" ",sidx+1)), _pads[i]) || fail;   
00165       sidx = padsstr.find(",",sidx+1);
00166    }
00167    if(fail)
00168    {
00169       NrroDbg("readPads(), failed to read in padds correctly!");
00170       //for(int i=0; i<int(dim()); ++i)
00171       //{
00172       //        _pads[i] = vec2ui(0, dim(i));
00173       //}
00174       return;
00175    }
00176 }
00177 
00178 /////////////////////////////////////////////////////////////////////////
00179 //Position
00180 /////////////////////////////////////////////////////////////////////////
00181 const std::string NRRO_POS_KEY("position_nrro");
00182 
00183 void Nrro::writePos()
00184 {
00185    ostringstream ss;
00186    ss << _pos;
00187    string posstr = ss.str();
00188    setComment(NRRO_POS_KEY, posstr);
00189 }
00190 
00191 void Nrro::readPos()
00192 {
00193    string posstr = getComment(NRRO_POS_KEY);
00194    if(posstr.empty())
00195    {
00196       //NrroDbg("readPos(), pos not set");
00197       //_pos = vec3f_zero;
00198       return;
00199    }
00200    if(str2vec3<float>(posstr, _pos))
00201    {
00202       NrroDbg("readPos(), faild to read position");
00203       //_pos = vec3f_zero;
00204    }
00205 }
00206 
00207 /////////////////////////////////////////////////////////////////////////
00208 //Name
00209 /////////////////////////////////////////////////////////////////////////
00210 const std::string NRRO_NAME_KEY("name_nrro");
00211 
00212 void Nrro::writeName()
00213 {
00214    //nrrd key/values can't be empty
00215    if(_name.empty())
00216       _name = std::string("unnamed");
00217 
00218    setComment(NRRO_NAME_KEY, _name);
00219 }
00220 
00221 void Nrro::readName()
00222 {
00223    _name = getComment(NRRO_NAME_KEY);
00224 }
00225 

Send questions, comments, and bug reports to:
jmk