00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __freXMLValueSet_h
00023 #define __freXMLValueSet_h
00024
00025 #include "freElementals.h"
00026 #include "freXMLStreamObject.h"
00027 #include "freExceptions.h"
00028 #include "freConvert.h"
00029
00030 namespace FREE
00031 {
00032
00041 class XMLValueSet: public XMLStreamObject
00042 {
00043 public:
00044 typedef STLStringVector ValuesType;
00045 typedef unsigned long ValueCountType;
00046
00051 void Reset(const ValueCountType iValueCount, const std::string& sNewValue = "");
00052
00054 virtual void Reset();
00055
00060 void Resize(const ValueCountType iNewSize, const std::string& sNewValue = "");
00061
00064 ValueCountType Size() const;
00065
00072 bool GetValue(bool& value, ValueCountType iItemPos = 0) const;
00073
00076 bool GetValue(float& value, ValueCountType iItemPos = 0) const;
00077
00080 bool GetValue(double& value, ValueCountType iItemPos = 0) const;
00081
00084 bool GetValue(unsigned int& value, ValueCountType iItemPos = 0) const;
00085
00088 bool GetValue(int& value, ValueCountType iItemPos = 0) const;
00089
00092 bool GetValue(long& value, ValueCountType iItemPos = 0) const;
00093
00096 bool GetValue(unsigned long& value, ValueCountType iItemPos = 0) const;
00097
00100 bool GetValue(std::string& value, ValueCountType iItemPos = 0) const;
00101
00107 bool SetValue(const bool value, ValueCountType iItemPos = 0);
00108
00111 bool SetValue(const double value, ValueCountType iItemPos = 0);
00112
00115 bool SetValue(const float value, ValueCountType iItemPos = 0);
00116
00119 bool SetValue(const int value, ValueCountType iItemPos = 0);
00120
00123 bool SetValue(const unsigned int value, ValueCountType iItemPos = 0);
00124
00127 bool SetValue(const long value, ValueCountType iItemPos = 0);
00128
00131 bool SetValue(const unsigned long value, ValueCountType iItemPos = 0);
00132
00135 bool SetValue(const std::string& value, ValueCountType iItemPos = 0);
00136
00138 virtual XMLValueSet& operator = (const XMLValueSet& valueSet);
00139
00143 XMLValueSet(const ValueCountType iValueCount, const std::string& sNewValue = "");
00144
00146 XMLValueSet();
00147
00149 XMLValueSet( const XMLValueSet& valueSet);
00150
00151 virtual ~XMLValueSet();
00152
00153 protected:
00155 virtual void SubElementLoadProcessing(const std::string& rsXMLSubTag, const std::string& rsXMLSubElement, const std::string& rsXMLSubData);
00156
00158 virtual std::string SaveData(const unsigned int& iDepth, bool& bHasSubElements) const;
00159
00161 ValuesType m_Values;
00162 };
00163
00164 namespace Convert
00165 {
00166
00172 template <typename TFixedArray> static void ITKFixedArrayToValueSet(const TFixedArray& rArray, ::FREE::XMLValueSet& rSet)
00173 {
00174 rSet.Resize(rArray.Size());
00175 for (unsigned int iDim=0; iDim<rArray.Size(); iDim++)
00176 {
00177 rSet.SetValue(rArray.GetElement(iDim),iDim);
00178 };
00179 };
00180
00181 template <typename TIndex> static void ITKIndexToValueSet(const TIndex& rIndex, ::FREE::XMLValueSet& rSet)
00182 {
00183 rSet.Resize(TIndex::GetIndexDimension());
00184 for (unsigned int iDim=0; iDim<rSet.Size(); iDim++)
00185 {
00186 rSet.SetValue(rIndex.GetElement(iDim),iDim);
00187 };
00188 };
00189
00190 template <typename TSize> static void ITKSizeToValueSet(const TSize& rSize, ::FREE::XMLValueSet& rSet)
00191 {
00192 rSet.Resize(TSize::GetSizeDimension());
00193 for (unsigned int iDim=0; iDim<rSet.Size(); iDim++)
00194 {
00195 rSet.SetValue(rSize.GetElement(iDim),iDim);
00196 };
00197 };
00198
00199 template <typename TArray> static void ITKArrayToValueSet(const TArray& rArray, ::FREE::XMLValueSet& rSet)
00200 {
00201 ITKFixedArrayToValueSet(rArray,rSet);
00202 };
00203
00204 template <typename TFixedArray> static ::FREE::XMLValueSet ITKFixedArrayToValueSet(const TFixedArray& rArray)
00205 {
00206 XMLValueSet values;
00207 ITKFixedArrayToValueSet(rArray,values);
00208 return values;
00209 };
00210
00211 template <typename TIndex> static ::FREE::XMLValueSet ITKIndexToValueSet(const TIndex& rIndex)
00212 {
00213 XMLValueSet values;
00214 ITKIndexToValueSet(rIndex,values);
00215 return values;
00216 };
00217
00218 template <typename TSize> static ::FREE::XMLValueSet ITKSizeToValueSet(const TSize& rSize)
00219 {
00220 XMLValueSet values;
00221 ITKSizeToValueSet(rSize,values);
00222 return values;
00223 };
00224
00225 template <typename TArray> static ::FREE::XMLValueSet ITKArrayToValueSet(const TArray& rArray)
00226 {
00227 return ITKFixedArrayToValueSet(rArray);
00228 };
00229
00235 template <typename TFixedArray> static TFixedArray ValueSetToITKFixedArray(const ::FREE::XMLValueSet& rSet)
00236 {
00237 TFixedArray newArray;
00238 if (newArray.Size()!=rSet.Size())
00239 throwStaticExceptionMacro("Dimension of fixed array and size of parameter layer differ. Fixed array dim: " << Convert::ToStr(newArray.Size()) << "; layer dim: " << Convert::ToStr(rSet.Size()));
00240
00241 typename TFixedArray::ValueType value;
00242 for (int i=0; i<newArray.Size(); i++)
00243 {
00244 rSet.GetValue(value,i);
00245 newArray[i]=value;
00246 }
00247 return newArray;
00248 };
00249
00250 template <typename TIndex> static TIndex ValueSetToITKIndex(const ::FREE::XMLValueSet& rSet)
00251 {
00252 TIndex newIndex;
00253 if (rSet.Size()!=TIndex::GetIndexDimension()) throwStaticExceptionMacro("Dimension of index and size of parameter layer differ. Index dim: " << TIndex::GetIndexDimension() << "; layer dim: " << Convert::ToStr(rSet.Size()));
00254
00255 typename TIndex::IndexValueType value;
00256 for (int i=0; i<rSet.Size(); i++)
00257 {
00258 rSet.GetValue(value,i);
00259 newIndex.SetElement(i,value);
00260 }
00261 return newIndex;
00262 };
00263
00264 template <typename TSize> static TSize ValueSetToITKSize(const ::FREE::XMLValueSet& rSet)
00265 {
00266 TSize newSize;
00267 if (rSet.Size()!=TSize::GetSizeDimension()) throwStaticExceptionMacro("Dimension of itk::Size and size of parameter layer differ. Size dim: " << TSize::GetSizeDimension() << "; layer dim: " << Convert::ToStr(rSet.Size()));
00268
00269 typename TSize::SizeValueType value;
00270 for (int i=0; i<rSet.Size(); i++)
00271 {
00272 rSet.GetValue(value,i);
00273 newSize.SetElement(i,value);
00274 }
00275 return newSize;
00276 };
00277
00278 template <typename TArray> static TArray ValueSetToITKArray(const ::FREE::XMLValueSet& rSet)
00279 {
00280 TArray newArray(rSet.Size());
00281
00282 typename TArray::ValueType value;
00283 for (int i=0; i<newArray.Size(); i++)
00284 {
00285 rSet.GetValue(value,i);
00286 newArray[i]=value;
00287 }
00288 return newArray;
00289 };
00290 }
00291 }
00292
00293 #endif