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 // nrroKind.cpp 00019 00020 // handles things related to the extended symantics of a nrro 00021 00022 // if you add a new kind, beware, this is used in many places 00023 // it is handled here, and in nrroExtended.cpp, but may also 00024 // play a role in other things, like position and pads, these 00025 // are affected by Ginsu, so check there too, to make sure 00026 // you get the desired behavior. 00027 00028 // Most likely you should have subclassed, but tried to 00029 // duplicate the "hacky" symantics provided here. 00030 00031 #include "nrro.h" 00032 #include <iostream> 00033 00034 using namespace gutz; 00035 using namespace std; 00036 00037 ///////////////////////////////////////////////////////////////////////// 00038 // printKind 00039 ///////////////////////////////////////////////////////////////////////// 00040 void Nrro::printKind() const 00041 { 00042 cerr << " Nrro::KIND = "; 00043 if(_kind == KIND_NOT_SET) 00044 cerr << " Not Set "; 00045 if(_kind & KIND_UNKNOWN) 00046 cerr << " Unknown "; 00047 if(_kind & IMAGE) 00048 cerr << " Image "; 00049 if(_kind & VOLUME) 00050 cerr << " Volume "; 00051 if(_kind & TIME_SERIES) 00052 cerr << " Time Series "; 00053 if(_kind & PROXY) 00054 cerr << " Proxy "; 00055 cerr << endl; 00056 } 00057 00058 ///////////////////////////////////////////////////////////////////////// 00059 // guessKind 00060 ///////////////////////////////////////////////////////////////////////// 00061 int Nrro::guessKind() const 00062 { 00063 //TODO: how do we differentiate a volume from a 00064 //image time series?? we can't, the user must tell us 00065 00066 int myKind = KIND_NOT_SET; 00067 00068 //must be a proxy if there is no data 00069 if(0 == _nrrd->data) 00070 { 00071 myKind |= PROXY; 00072 } 00073 00074 //2D data, must be an image 00075 if(dim() == 2) 00076 { 00077 //NrroDbg("guessKind(), IMAGE"); 00078 return (IMAGE | (myKind & PROXY)); 00079 } 00080 00081 //3D data, could be image+channels, or volume 00082 if(dim() == 3) 00083 { 00084 //ahh, probably a color or color+alpha image 00085 if(dim(0)<5) 00086 { 00087 //NrroDbg("guessKind(), IMAGE"); 00088 return ( IMAGE | (myKind & PROXY) ); 00089 } 00090 //ok, must be a volume 00091 //NrroDbg("guessKind(), VOLUME"); 00092 return ( VOLUME | (myKind & PROXY) ); 00093 } 00094 00095 //could be a multi-channel volume or a volume time series 00096 if(dim() == 4) 00097 { 00098 //we will assume for now that we have at most 4 channels 00099 //TODO: is this a good assumption???, who cares the 00100 //user really should be setting this, a guess is a guess 00101 if(dim(0)<5) 00102 { 00103 //NrroDbg("guessKind(), VOLUME"); 00104 return ( VOLUME | (myKind & PROXY) ); 00105 } 00106 //ok, must be a volume time series 00107 //NrroDbg("guessKind(), VOLUME_TIME"); 00108 return ( VOLUME | TIME_SERIES | (myKind & PROXY) ); 00109 } 00110 00111 //could only be a muti-channel time series volume 00112 if(dim() == 5) 00113 { 00114 //NrroDbg("guessKind(), VOLUME_TIME"); 00115 return ( VOLUME | TIME_SERIES | (myKind & PROXY) ); 00116 } 00117 //if we made it this far, we just dont know! 00118 NrroDbg("guessKind(), KIND_UNKNOWN"); 00119 return KIND_UNKNOWN; 00120 } 00121 00122 ///////////////////////////////////////////////////////////////////////// 00123 // force Multi Channel 00124 ///////////////////////////////////////////////////////////////////////// 00125 int Nrro::forceMultiChannel() //3 spatial axies and N channels 00126 { 00127 if((_kind & KIND_UNKNOWN) || (_kind == KIND_NOT_SET) || (_kind >= KIND_LAST)) 00128 { 00129 NrroDbg("forceMultiChannel(), can't force, don't know what kind of data we have"); 00130 return 1; //cant do it! 00131 } 00132 00133 //correct dimension for image 00134 if((IMAGE & _kind) && (!(_kind & TIME_SERIES)) && (dim() == 3)) 00135 return 0; //ay okay 00136 00137 //scalar image, up the dimension 00138 if((IMAGE & _kind) && (!(_kind & TIME_SERIES)) && (dim() == 2)) 00139 { 00140 //make it a 3D volume 00141 //NrroDbg("forceMultiChannel(), Image: forcing 3D"); 00142 insertAxis(0); 00143 return 0; //worked 00144 } 00145 00146 //correct dimension for volume and time images 00147 if(( (VOLUME & _kind) || ((IMAGE & _kind) && (TIME_SERIES & _kind)) ) 00148 && (dim() == 4)) 00149 return 0; //ay okay 00150 00151 //scalar volume or time images, up the dimension 00152 if( ( (VOLUME & _kind) || ((IMAGE & _kind) && (TIME_SERIES & _kind)) ) 00153 && (dim() == 3)) 00154 { 00155 //make it a 4D volume 00156 //NrroDbg("forceMultiChannel(), Time Series Image or Volume: forcing 4D"); 00157 insertAxis(0); 00158 return 0; //worked 00159 } 00160 00161 //correct dimension for time volumes 00162 if((VOLUME & _kind) && (TIME_SERIES & _kind) && (dim() ==5)) 00163 return 0; //ay okay 00164 00165 //scalar time volume up the dimension 00166 if((VOLUME & _kind) && (TIME_SERIES & _kind) && (dim() ==4)) 00167 { 00168 //make it a 5D volume 00169 //NrroDbg("forceMultiChannel(), Time Series Volume: forcing 5D"); 00170 insertAxis(0); 00171 return 0; 00172 } 00173 00174 //we don't have symantics for these dimensions 00175 if((dim() > 5) || (dim()<2)) 00176 { 00177 NrroDbg("forceMultiChannel(), WARNING: can't force volume to multi-channel"); 00178 return 1; 00179 } 00180 00181 //oh boy, how did we get here? 00182 NrroDbg("forceMultiChannel(), end: no action, no detection"); 00183 return 1; 00184 }