NIREP
|
00001 /*************************************************************************************** 00002 * Programmer: Gary E. Christensen 00003 * Date: 6/24/2010 00004 * Name: ResourceDescription 00005 * Purpose: This class holds information about the resources stored in the database. 00006 * Each resource must contain a unique resource id and a list of data descriptions 00007 * that describe the data (images, object maps, contours, landmarks, etc.) associated 00008 * with the resource. Optionally, a resource can contain a list of non-required user 00009 * defined attributes such as age, race, handeness, etc. 00010 ******************************************************************************************/ 00011 #pragma once 00012 #ifndef _RESOURCE_DESCRIPTION_H_ 00013 #define _RESOURCE_DESCRIPTION_H_ 00014 00015 #include <string> 00016 #include <vector> 00017 #include <map> 00018 #include <algorithm> 00019 #include <cstring> 00020 #include "tinyxml.h" 00021 00022 #include <wx/filename.h> 00023 00024 #include "NIREPDefinitions.h" 00025 #include "BasicDescription.h" 00026 00027 class ResourceDescription{ 00028 public: 00029 typedef struct { 00030 std::string index; // index of coordinate system when there are multiple coordinate systems 00031 // index = 0 corresponds to the source coordinate system 00032 std::string ns; // namespace of coordinate system 00033 std::string id; // coordinate system id 00034 } CoordinateSystem; 00035 00036 typedef std::map<std::string, CoordinateSystem> CSList; 00037 typedef std::map<std::string, std::string> AlgList; 00038 typedef std::map<std::string, std::string> FilenameList; 00039 typedef std::map<std::string, std::string> AttributeList; 00040 00043 ResourceDescription(std::string default_ns){ SetDefaultNS(default_ns);}; 00044 00048 ResourceDescription(TiXmlElement * descrip, std::string default_ns){ 00049 SetDefaultNS(default_ns); 00050 if (!FillUsingDom(descrip)){ 00051 Clear(); 00052 } 00053 }; 00054 00057 ~ResourceDescription(){ Clear(); }; 00058 00061 void Clear(); 00062 00064 std::string & GetDefaultNS(){ return m_default_ns;} 00065 void SetDefaultNS(std::string default_ns){ 00066 m_default_ns = default_ns; 00067 // convert m_default_ns to lower case for case insensitivity strin comparison 00068 std::transform(m_default_ns.begin(), m_default_ns.end(), m_default_ns.begin(), ::tolower); 00069 } 00070 00072 std::string & GetLabel(){ return m_label;} 00073 void SetLabel(std::string label){ 00074 m_label = label; 00075 // convert m_label to lower case for case insensitivity strin comparison 00076 std::transform(m_label.begin(), m_label.end(), m_label.begin(), ::tolower); 00077 } 00078 00080 std::string & GetDMID(){ return m_dmid;} 00081 void SetDMID(std::string dmid){ 00082 m_dmid = dmid; 00083 // convert m_dmid to lower case for case insensitivity strin comparison 00084 std::transform(m_dmid.begin(), m_dmid.end(), m_dmid.begin(), ::tolower); 00085 } 00086 00088 const CoordinateSystem * GetCS(std::string & index){ 00089 CSList::iterator iter = m_cs.find(index); 00090 if (iter != m_cs.end()){ 00091 return &iter->second; 00092 } else { 00093 return NULL; 00094 } 00095 } 00096 00098 //JAH added this in 00099 const CSList * GetCS(){ 00100 return &m_cs; 00101 } 00102 00103 void AddCS(std::string key, CoordinateSystem cs){ 00104 // convert key to lower case for case insensitivity strin comparison 00105 std::transform(key.begin(), key.end(), key.begin(), ::tolower); 00106 00107 m_cs[key] = cs; 00108 } 00109 void ClearCSList(){ m_cs.clear(); } 00110 00112 const size_t GetNumCS(){ return m_cs.size(); } 00113 00115 const size_t GetNumAlg(){ return m_alg.size(); } 00116 00119 const std::string CreateCSnsid(const std::string & index){ 00120 CSList::iterator iter = m_cs.find(index); 00121 if (iter != m_cs.end()){ 00122 // Use default namespace if coordinate system namespace missing 00123 std::string cs_namespace = iter->second.ns; 00124 if (cs_namespace.empty()){ 00125 return GetDefaultNS() + "|" + iter->second.id; 00126 } else { 00127 return cs_namespace + "|" + iter->second.id; 00128 } 00129 } else { 00130 return NULL; 00131 } 00132 } 00133 00136 const std::string CreateReferenceCSnsid(){ 00137 CSList::reverse_iterator riter = m_cs.rbegin(); // Get namespace of last/reference coordinate system 00138 if (!m_cs.empty()){ 00139 // Use default namespace if coordinate system namespace missing 00140 std::string cs_namespace = riter->second.ns; 00141 if (cs_namespace.empty()){ 00142 return GetDefaultNS() + "|" + riter->second.id; 00143 } else { 00144 return cs_namespace + "|" + riter->second.id; 00145 } 00146 } else { 00147 return ""; 00148 } 00149 } 00150 00152 std::string CreateLabelDMID(){ 00153 if ((GetNumCS() == 1) && !m_label.empty()){ 00154 std::string dmid; 00155 00156 dmid = EvalCmd["SpatialData"] + "(" + CreateReferenceCSnsid() + "," + GetLabel() + ")"; 00157 return dmid; 00158 } else { 00159 return ""; 00160 } 00161 } 00162 00164 std::string CreateTransformDMID(){ 00165 if ((GetNumCS() == 2) && (GetNumAlg() == 1)){ 00166 std::string dmid; 00167 00168 dmid = EvalCmd["Transformation"] + "(" + CreateCSnsid("0") + "," 00169 + CreateCSnsid("1") + "," + GetAlgorithm("0") + ")"; 00170 return dmid; 00171 } else { 00172 return ""; 00173 } 00174 } 00175 00179 std::string GetAlgorithm(std::string key){ 00180 // convert key to lower case for case insensitivity strin comparison 00181 std::transform(key.begin(), key.end(), key.begin(), ::tolower); 00182 00183 AlgList::iterator iter = m_alg.find(key); 00184 if (iter != m_alg.end()){ 00185 return iter->second; 00186 } else { 00187 return ""; 00188 } 00189 } 00190 void AddAlgorithm(std::string key, const std::string & algorithmID){ 00191 // convert key to lower case for case insensitivity strin comparison 00192 std::transform(key.begin(), key.end(), key.begin(), ::tolower); 00193 00194 m_alg[key] = algorithmID; 00195 } 00196 void ClearAlgorithms(){ m_alg.clear(); } 00197 00200 std::string & GetFormat(){ return m_format;} 00201 void SetFormat(const std::string & format){ 00202 m_format = format; 00203 // convert m_format to lower case for case insensitivity strin comparison 00204 std::transform(m_format.begin(), m_format.end(), m_format.begin(), ::tolower); 00205 } 00206 00209 std::string & GetDirectory(){ return m_directory;} 00210 void SetDirectory(const std::string & directory){ m_directory = directory; } 00211 00215 //JAH added in bool normalize, this way if we don't want the filename to be noramlized then 00216 //the filename won't be normalized 00217 std::string GetFilename(const std::string & index, bool normalize = true){ 00218 FilenameList::iterator iter = m_filename.find(index); 00219 if (iter != m_filename.end()){ 00220 // When we are passed the short form of a filename, normalize it and make the long form. 00221 // If path is missing, the code currently prepends the current working directory. 00222 // This is incorrect and should be changed to path of the rdl file that it came from. 00223 wxString s( iter->second.c_str(), wxConvUTF8 ); 00224 wxFileName fName(s); 00225 00226 // Use result of GetDirectory to set the directory. Use current working directory if GetDirectory returns an empty string. 00227 if(normalize) { 00228 fName.Normalize(wxPATH_NORM_LONG|wxPATH_NORM_DOTS|wxPATH_NORM_TILDE|wxPATH_NORM_ABSOLUTE,wxString(GetDirectory().c_str(), wxConvUTF8)); 00229 } 00230 std::string filename = std::string(fName.GetFullPath().mb_str()); 00231 //return std::string(fName.GetFullPath().mb_str()); 00232 return filename; 00233 } else { 00234 return ""; 00235 } 00236 } 00237 void AddFilename(const std::string & index, const std::string & filename){ m_filename[index] = filename; } 00238 void ClearFilenames(){ m_filename.clear(); } 00239 00242 std::string & GetTransformUnits(){ return m_transform_units;} 00243 void SetTransformUnits(const std::string & transform_units){ 00244 m_transform_units = transform_units; 00245 // convert m_transform_units to lower case for case insensitivity strin comparison 00246 std::transform(m_transform_units.begin(), m_transform_units.end(), m_transform_units.begin(), ::tolower); 00247 } 00248 00251 std::string & GetDataType(){ return m_datatype;} 00252 void SetDataType(const std::string & datatype){ 00253 m_datatype = datatype; 00254 // convert m_datatype to lower case for case insensitivity strin comparison 00255 std::transform(m_datatype.begin(), m_datatype.end(), m_datatype.begin(), ::tolower); 00256 } 00257 00259 std::string GetAttribute(std::string key){ 00260 // convert key to lower case for case insensitivity strin comparison 00261 std::transform(key.begin(), key.end(), key.begin(), ::tolower); 00262 00263 AttributeList::iterator iter = m_attribute.find(key); 00264 if (iter != m_attribute.end()){ 00265 return iter->second; 00266 } else { 00267 return ""; 00268 } 00269 } 00270 void AddAttribute(std::string key, const std::string & value){ 00271 // convert key to lower case for case insensitivity strin comparison 00272 std::transform(key.begin(), key.end(), key.begin(), ::tolower); 00273 00274 m_attribute[key] = value; 00275 } 00276 void ClearAttributes(){ m_attribute.clear(); } 00277 00278 // DOM = Document Object Model 00279 TiXmlElement * CreateDOM(const std::string & tag); 00280 bool FillUsingDom(TiXmlElement * descrip); 00281 00282 00283 private: 00284 std::string m_default_ns; // Default namespace 00285 std::string m_label; // User supplied label to denote data type 00286 std::string m_dmid; // data manager id, data manager uses this to reference data 00287 CSList m_cs; // List of coordinate systems 00288 00289 AlgList m_alg; // List of algorithms, one less than # of coordinate systems 00290 00291 std::string m_format; // Format of transformation files 00292 std::string m_directory; // Directory appended to relative filenames. 00293 FilenameList m_filename; // List of filenames 00294 std::string m_transform_units; // unit cube, physical, image 00295 std::string m_datatype; // Type of data stored in file 00296 00297 AttributeList m_attribute; // List of attributes associated with resource, 00298 // e.g., name, description, race, age, handedness 00299 00300 }; 00301 00302 #endif 00303 00304