freSetupTransform.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: freSetupTransform.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 "freSetupTransform.h"
00024 #include "freExceptions.h"
00025 #include "freComponentSetupBrowser.h"
00026 #include "freControllerCentral.h"
00027 
00028 
00029 namespace FREE
00030 {
00031 
00035 
00036 
00037 unsigned int
00038 SetupTransform::
00039 GetNumberOfParameters(void) const
00040 {
00041         return m_ParameterIDs.size();
00042 };
00043 
00044 const SetupTransform::ParametersType&
00045 SetupTransform::
00046 GetParameters(void) const
00047 {
00048         return m_Parameters;
00049 };
00050 
00051 unsigned int
00052 SetupTransform::
00053 GetInputSpaceDimension(void) const
00054 {
00055         return 0;
00056 };
00057 
00058 unsigned int
00059 SetupTransform::
00060 GetOutputSpaceDimension(void) const
00061 {
00062         return 0;
00063 };
00064 
00065 void
00066 SetupTransform::
00067 SetParameters( const ParametersType & p)
00068 {
00069         if (GetNumberOfParameters() != p.size()) throwExceptionMacro("Error. Number of passed parameter values is not equal to the parameter size of the transform. Passed parameter count: "<< p.size() << "; tranform parameter count: "<<GetNumberOfParameters());
00070         m_ParameterTraits = ComputeParametersTraits(p,m_Parameters);
00071         m_bTraitsInitialized = true;
00072 };
00073 
00074 void
00075 SetupTransform::
00076 SetParametersDirectly( const ParametersType & p)
00077 {
00078         if (GetNumberOfParameters() != p.size()) throwExceptionMacro("Error. Number of passed parameter values is not equal to the parameter size of the transform. Passed parameter count: "<< p.size() << "; tranform parameter count: "<<GetNumberOfParameters());
00079         m_ParameterTraits = ComputeParametersTraits(p);
00080         m_Parameters = p;
00081         m_bTraitsInitialized = true;
00082 };
00083 
00084 void
00085 SetupTransform::
00086 SetParametersByValue ( const ParametersType & p )
00087 {
00088         SetParameters(p);
00089 };
00090 
00091 void
00092 SetupTransform::
00093 SetFixedParameters( const ParametersType & p)
00094 {
00095         if (GetNumberOfParameters() != p.size()) throwExceptionMacro("Error. Number of passed parameter values is not equal to the parameter size of the transform. Passed parameter count: "<< p.size() << "; tranform parameter count: "<<GetNumberOfParameters());
00096         m_ParameterTraits = ComputeParametersTraits(p,m_Parameters);
00097         m_bTraitsInitialized = true;
00098 };
00099 
00100 const SetupTransform::ParametersType&
00101 SetupTransform::
00102 GetFixedParameters( ) const
00103 {
00104         return m_Parameters;
00105 };
00106 
00107 SetupTransform::ParameterTraitsList
00108 SetupTransform::
00109 ComputeParametersTraits( const ParametersType & p) const
00110 {
00111         ParametersType temp;
00112         return ComputeParametersTraits(p,temp);
00113 };
00114 
00115 SetupTransform::ParameterTraitsList
00116 SetupTransform::
00117 ComputeParametersTraits( const ParametersType & p, ParametersType& validP) const
00118 {
00119         ParameterTraitsList result;
00120 
00121         if (!m_pReferenceSetup) throwExceptionMacro("Error: cannot compute traites. No reference setup defined to determine parameter value type.");
00122 
00123         validP = p;
00124 
00125         for (unsigned int i= 0; i<this->m_Parameters.Size(); i++)
00126         { //determine the parameter value type for every parameter 
00127                 Parameter::ParameterValueType pvt = this->GetParameterValueType(m_ParameterIDs[i]);
00128                 SetupParameterTraits paramTraits(p[i],pvt);
00129                 if ((pvt == Parameter::PVTInteger) || (pvt == Parameter::PVTLong)  || (pvt == Parameter::PVTULong))
00130                 {
00131                         validP[i] = floor(p[i]);
00132                 }
00133 
00134                 result.push_back(paramTraits);
00135         }
00136 
00137         return result;
00138 };
00139 
00140 const SetupTransform::ParameterTraitsList&
00141 SetupTransform::
00142 GetParametersTraits(void)
00143 {
00144         if (!m_bTraitsInitialized)
00145         {
00146                 m_ParameterTraits = ComputeParametersTraits(m_Parameters);
00147     m_bTraitsInitialized = true;
00148         }
00149 
00150         return m_ParameterTraits;
00151 };
00152 
00153 std::string
00154 SetupTransform::
00155 GetTransformTypeAsString() const
00156 {
00157         return GetNameOfClass();
00158 };
00159 
00160 Setup::Pointer
00161 SetupTransform::
00162 GenerateTransformedSetup()
00163 {
00164         if (!m_pReferenceSetup) throwExceptionMacro("Error: cannot transform setup. No reference setup defined.");
00165         if (GetNumberOfParameters() != m_Parameters.size()) throwExceptionMacro("Error. Cannot transform setup, number of passed parameter values is not equal to the parameter size of the transform. Passed parameter count: "<< m_Parameters.size());
00166 
00167         TransformSetup();
00168   Setup::Pointer result = m_smpTransformedSetup;
00169   m_smpTransformedSetup = 0;
00170         return result;
00171 };
00172 
00173 void
00174 SetupTransform::
00175 SetAutoInitialValues(bool bAutoValues)
00176 {
00177         m_bAutoInitialValue = bAutoValues;
00178 };
00179 
00180 bool
00181 SetupTransform::
00182 GetAutoInitialValues()
00183 {
00184         return m_bAutoInitialValue;
00185 };
00186 
00187 void
00188 SetupTransform::
00189 SetReferenceSetup(Setup* pSetup)
00190 {
00191         m_pReferenceSetup = pSetup;
00192         if (m_bAutoInitialValue) GetInitialValues();
00193 };
00194 
00195 void
00196 SetupTransform::
00197 ResetParameterIDs()
00198 {
00199         m_ParameterIDs.clear();
00200         m_bTraitsInitialized = false;
00201         m_Parameters.SetSize(GetNumberOfParameters());
00202         m_Parameters.Fill(0);
00203 };
00204 
00205 void
00206 SetupTransform::
00207 AddParameterID(const IDPath& idPath)
00208 {
00209         m_ParameterIDs.push_back(idPath);
00210         m_bTraitsInitialized = false;
00211         m_Parameters.SetSize(GetNumberOfParameters());
00212         m_Parameters.Fill(0);
00213 
00214 };
00215 
00216 SetupTransform::
00217 SetupTransform()
00218 {
00219         m_pReferenceSetup = 0;
00220   m_smpTransformedSetup = 0;
00221         m_Parameters.Fill(0);
00222         m_bAutoInitialValue = true;
00223         m_bTraitsInitialized = false;
00224 }; 
00225 
00226 SetupTransform::
00227 ~SetupTransform() {};
00228 
00229 void
00230 SetupTransform::
00231 TransformSetup()
00232 {
00233 
00234   m_smpTransformedSetup = Setup::New();
00235 
00236   m_smpTransformedSetup->operator =(*m_pReferenceSetup);
00237 
00238         ComponentSetupBrowser search(m_smpTransformedSetup->GetComponentByIDPath(cIDPRoot));
00239 
00240         for (unsigned int iIndex=0; iIndex<m_ParameterIDs.size(); iIndex++)
00241         {
00242                 search.Reset();
00243                 search.SearchForComponents(m_ParameterIDs[iIndex]);
00244 
00245                 ComponentSetupBrowser::FindingsType::iterator it;
00246                 for (it = search.GetFindings().begin(); it != search.GetFindings().end(); it++)
00247                 {
00248       IDPath parameterID = m_ParameterIDs[iIndex].GetParameterIDPath();
00249 
00250                         (*it)->Parameters().SetParameterValueByIDPath(parameterID,m_Parameters[iIndex]);
00251                 }
00252         }
00253 };
00254 
00255 void
00256 SetupTransform::
00257 GetInitialValues()
00258 {
00259         ComponentSetupBrowser search(m_pReferenceSetup->GetComponentByIDPath(cIDPRoot));
00260 
00261         ParametersType  newParameters(m_ParameterIDs.size());
00262         newParameters.Fill(0.0);
00263 
00264         for (unsigned int iIndex=0; iIndex<m_ParameterIDs.size(); iIndex++)
00265         {
00266                 search.Reset();
00267                 search.SearchForComponents(m_ParameterIDs[iIndex]);
00268 
00269                 if (search.GetFindings().size()!=0)
00270                 {
00271                         double value;
00272       IDPath parameterID = m_ParameterIDs[iIndex].GetParameterIDPath();
00273 
00274                         search.GetFindings().at(0)->Parameters().GetParameterValueByIDPath(parameterID,value);
00275                         newParameters.SetElement(iIndex,value);
00276                 }
00277         }
00278 
00279         SetParameters(newParameters);
00280 };
00281 
00282 Parameter::ParameterValueType
00283 SetupTransform::
00284 GetParameterValueType(const IDPath& paramID) const
00285 {
00286         if (!m_pReferenceSetup) throwExceptionMacro("Error: cannot determine parameter value type; reference setup is NULL.");
00287 
00288         IDPath compID = paramID.GetParentComponentIDPath();
00289 
00290         ComponentSetup* pComp = m_pReferenceSetup->GetComponentByIDPath(compID);
00291 
00292         if (!pComp) throwExceptionMacro("Error: cannot find component of the specified parameter within setup. Parameter IDPath: "<<paramID.ToStr());
00293         if (!pComp->ControllerIsAssigned()) throwExceptionMacro("Error: cannot determine parameter value type; controller of component is not assigned. Please ensure a valid setup. Parameter IDPath: "<<paramID.ToStr());
00294 
00295         GenericComponentController* pController = ControllerCentral::GetController(pComp->GetControllerID());
00296 
00297         if (!pController) throwExceptionMacro("Error: cannot find controller specified be component. Parameter IDPath: "<<paramID.ToStr()<<"; ControllerID: "<<pComp->GetControllerID());
00298 
00299         CtrlProfile::Parameter* pParamProfile = pController->GetProfile(0)->Parameters().GetElement(paramID.GetParameterName());
00300         if (!pParamProfile) throwExceptionMacro("Error: cannot find parameter in the profile of the controller. Parameter IDPath: "<<paramID.ToStr()<<"; ControllerID: "<<pComp->GetControllerID());
00301 
00302         return pParamProfile->GetValueType();
00303 };
00304 
00305 }//End of Namespace free

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