freSetupParameterConstraint.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freSetupParameterConstraint.cxx,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 
00023 #include "freSetupParameterConstraint.h"
00024 #include "freConvert.h"
00025 
00026 
00027 namespace FREE
00028 {
00029 
00033 
00034 
00035 
00036 SetupParameterConstraint::
00037 SetupParameterConstraint(ParameterIDType destinationID, RelationType relation,
00038                                                                                                          const std::string sTerm)
00039 {
00040         m_DestinationID = destinationID;
00041         m_RelationType = relation;
00042         m_sTerm = sTerm;
00043 
00044   m_ConstraintParameters = ParseTermForParameters(sTerm);
00045 };
00046 
00047 SetupParameterConstraint::
00048 SetupParameterConstraint()
00049 {
00050         m_DestinationID = -1;
00051         m_RelationType = RTEqual;
00052         m_sTerm = "";
00053 };
00054 
00055 SetupParameterConstraint&
00056 SetupParameterConstraint::
00057 operator = (const SetupParameterConstraint& constraint)
00058 {
00059         if (this == &constraint) return *this;
00060 
00061         m_DestinationID = constraint.GetDestinationID();
00062         m_RelationType = constraint.GetRelationType();
00063         m_sTerm = constraint.GetConstraintTerm();
00064 
00065   m_ConstraintParameters = ParseTermForParameters(m_sTerm);
00066 
00067   return *this;
00068 };
00069 
00070 SetupParameterConstraint::ParameterIDsType
00071 SetupParameterConstraint::
00072 ParseTermForParameters(const std::string& sTerm) const
00073 {
00074         ParameterIDsType result;
00075         //search for any parameters (begin with _)
00076         std::string::size_type index = sTerm.find("_");
00077         while (index != std::string::npos)
00078         {       //found a parameter;
00079 
00080                 //this cannot be a valid parameter name, because numbers are missing.
00081                 //And it is the find any parameter, so skip.
00082     if (index >= sTerm.size()) break;
00083 
00084                 //extract id. The parameter name always consists of _ and the ID number
00085     std::string::size_type indexNonID = sTerm.find_first_not_of("0123456789",index+1);
00086     std::string::size_type length = indexNonID;
00087                 if (length != std::string::npos) length = indexNonID-index;
00088 
00089                 std::string sParamID = sTerm.substr(index, length);
00090                 if (sParamID.size()>1)
00091                 { //Parameter really got an ID
00092                         result.push_back(Convert::ToInt(sParamID.substr(1)));
00093                 }
00094 
00095         if (indexNonID != std::string::npos)
00096                 {
00097                         index = sTerm.find("_",indexNonID);
00098                 }
00099                 else
00100                 {
00101                         index = std::string::npos;
00102                 }
00103         }
00104 
00105         return result;
00106 };
00107 
00108 SetupParameterConstraint::Pointer
00109 SetupParameterConstraint::
00110 New(ParameterIDType destinationID, RelationType relation,const std::string sTerm)
00111 {
00112   Pointer smartPtr;
00113   SetupParameterConstraint *rawPtr = ::itk::ObjectFactory<SetupParameterConstraint>::Create();
00114   if(rawPtr == NULL)
00115   {
00116     rawPtr = new SetupParameterConstraint(destinationID, relation, sTerm);
00117   }
00118   smartPtr = rawPtr;
00119   rawPtr->UnRegister();
00120 
00121   return smartPtr;
00122 };
00123 
00124 namespace Convert
00125 {
00126   SetupParameterConstraint::RelationType ToRelationType(const std::string& sValue)
00127   {
00128                 if (sValue=="1") return SetupParameterConstraint::RTLesserOrEqual;
00129                 if (sValue=="2") return SetupParameterConstraint::RTGreaterOrEqual;
00130 
00131     return SetupParameterConstraint::RTEqual;
00132   };
00133 
00134   SetupParameterConstraint::RelationType ToRelationType(const int& iValue)
00135   {
00136                 if (iValue==1) return SetupParameterConstraint::RTLesserOrEqual;
00137                 if (iValue==2) return SetupParameterConstraint::RTGreaterOrEqual;
00138 
00139     return SetupParameterConstraint::RTEqual;
00140   };
00141 
00142         std::string ToStr(const SetupParameterConstraint::RelationType& rt)
00143   {
00144     switch (rt)
00145     {
00146                 case SetupParameterConstraint::RTLesserOrEqual: return "1";
00147                 case SetupParameterConstraint::RTGreaterOrEqual: return "2";
00148     default: return "0";
00149     };
00150   };
00151 }
00152 
00153 }//End of Namespace free

Generated at Sat Oct 13 17:27:40 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000