/usr/include/ITK-4.5/itkObjectToObjectOptimizerBase.hxx is in libinsighttoolkit4-dev 4.5.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | /*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef __itkObjectToObjectOptimizerBase_hxx
#define __itkObjectToObjectOptimizerBase_hxx
#include "itkObjectToObjectOptimizerBase.h"
#include "itkMultiThreader.h"
namespace itk
{
//-------------------------------------------------------------------
template<typename TInternalComputationValueType>
ObjectToObjectOptimizerBaseTemplate<TInternalComputationValueType>
::ObjectToObjectOptimizerBaseTemplate()
{
this->m_Metric = NULL;
this->m_CurrentMetricValue = 0;
// Initialize, but w/out calling SetNumberOfThreads, to avoid
// valgrind warning.
this->m_NumberOfThreads = MultiThreader::GetGlobalDefaultNumberOfThreads();
this->m_ScalesAreIdentity = false;
this->m_WeightsAreIdentity = true;
}
//-------------------------------------------------------------------
template<typename TInternalComputationValueType>
ObjectToObjectOptimizerBaseTemplate<TInternalComputationValueType>
::~ObjectToObjectOptimizerBaseTemplate()
{}
//-------------------------------------------------------------------
template<typename TInternalComputationValueType>
void
ObjectToObjectOptimizerBaseTemplate<TInternalComputationValueType>
::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "Number of threads: " << this->m_NumberOfThreads << std::endl;
os << indent << "Number of scales: " << this->m_Scales.Size() << std::endl;
if( this->m_Scales.Size() > 0 )
{
os << indent << "m_Scales: " << this->m_Scales << std::endl;
}
else
{
os << indent << "m_Scales is unset." << std::endl;
}
os << indent << "m_ScalesAreIdentity: " << this->GetScalesAreIdentity() << std::endl;
if( this->m_Weights.Size() > 0 )
{
os << indent << "m_Weights: " << this->m_Weights << std::endl;
}
else
{
os << indent << "m_Weights is unset. Treated as identity." << std::endl;
}
os << indent << "m_WeightsAreIdentity: " << this->GetWeightsAreIdentity() << std::endl;
os << indent << "Metric: " << std::endl;
m_Metric->Print( os, indent.GetNextIndent() );
}
//-------------------------------------------------------------------
template<typename TInternalComputationValueType>
void
ObjectToObjectOptimizerBaseTemplate<TInternalComputationValueType>
::SetNumberOfThreads( ThreadIdType number )
{
if( number < 1 )
{
itkExceptionMacro("Number of threads must be > 0");
}
if( number != this->m_NumberOfThreads )
{
this->m_NumberOfThreads = number;
this->Modified();
}
}
//-------------------------------------------------------------------
template<typename TInternalComputationValueType>
void
ObjectToObjectOptimizerBaseTemplate<TInternalComputationValueType>
::StartOptimization( bool itkNotUsed(doOnlyInitialization) )
{
/* Validate some settings */
if( this->m_Metric.IsNull() )
{
itkExceptionMacro("m_Metric must be set.");
return;
}
/* Verify m_Scales. If m_Scales hasn't been set, initialize to all 1's. */
typedef typename ScalesType::ValueType SValueType;
if( this->m_Scales.Size() > 0 )
{
if( this->m_Scales.Size() != this->m_Metric->GetNumberOfLocalParameters() )
{
itkExceptionMacro("Size of scales (" << this->m_Scales.Size()
<< ") must equal number of local parameters (" <<
this->m_Metric->GetNumberOfLocalParameters() << ").");
}
/* Check that all values in m_Scales are > machine epsilon, to avoid
* division by zero/epsilon.
* Also check if scales are identity. */
typedef typename ScalesType::size_type SizeType;
this->m_ScalesAreIdentity = true;
for( SizeType i=0; i < this->m_Scales.Size(); i++ )
{
if( this->m_Scales[i] <= NumericTraits<SValueType>::epsilon() )
{
itkExceptionMacro("m_Scales values must be > epsilon.");
}
/* Check if the scales are identity. Consider to be identity if
* within a tolerance, to allow for automatically estimated scales
* that may not be exactly 1.0 when in priciniple they should be. */
SValueType difference = vcl_fabs( NumericTraits<SValueType>::OneValue() - this->m_Scales[i] );
SValueType tolerance = static_cast<SValueType>( 0.01 );
if( difference > tolerance )
{
this->m_ScalesAreIdentity = false;
break;
}
}
}
else
{
//Initialize scales to identity
m_Scales.SetSize( this->m_Metric->GetNumberOfLocalParameters() );
m_Scales.Fill( NumericTraits<SValueType>::OneValue() );
this->m_ScalesAreIdentity = true;
}
/* Verify m_Weights. */
typedef typename ScalesType::ValueType SValueType;
if( this->m_Weights.Size() > 0 )
{
if( this->m_Weights.Size() != this->m_Metric->GetNumberOfLocalParameters() )
{
itkExceptionMacro("Size of weights (" << this->m_Weights.Size()
<< ") must equal number of local parameters (" << this->m_Metric->GetNumberOfLocalParameters() << ").");
}
/* Check if they are identity within tolerance. */
typedef typename ScalesType::size_type SizeType;
this->m_WeightsAreIdentity = true;
for( SizeType i=0; i < this->m_Weights.Size(); i++ )
{
SValueType difference = vcl_fabs( NumericTraits<SValueType>::OneValue() - this->m_Weights[i] );
SValueType tolerance = static_cast<SValueType>( 1e-4 );
if( difference > tolerance )
{
this->m_WeightsAreIdentity = false;
break;
}
}
}
else
{
// Set weights to identity. But leave the array empty.
this->m_WeightsAreIdentity = true;
}
}
//-------------------------------------------------------------------
template<typename TInternalComputationValueType>
const typename ObjectToObjectOptimizerBaseTemplate<TInternalComputationValueType>::ParametersType &
ObjectToObjectOptimizerBaseTemplate<TInternalComputationValueType>
::GetCurrentPosition() const
{
if( this->m_Metric.IsNull() )
{
itkExceptionMacro("m_Metric has not been assigned. Cannot get parameters.");
}
return this->m_Metric->GetParameters();
}
//-------------------------------------------------------------------
template<typename TInternalComputationValueType>
const typename ObjectToObjectOptimizerBaseTemplate<TInternalComputationValueType>::MeasureType &
ObjectToObjectOptimizerBaseTemplate<TInternalComputationValueType>
::GetValue() const
{
return this->GetCurrentMetricValue();
}
}//namespace itk
#endif
|