/usr/include/ITK-4.5/itkLevelSetEvolutionComputeIterationThreader.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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | /*=========================================================================
*
* 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 __itkLevelSetEvolutionComputeIterationThreader_hxx
#define __itkLevelSetEvolutionComputeIterationThreader_hxx
#include "itkLevelSetEvolutionComputeIterationThreader.h"
#include "itkImageRegionConstIteratorWithIndex.h"
namespace itk
{
template< typename TImage, typename TLevelSetEvolution >
LevelSetEvolutionComputeIterationThreader< LevelSetDenseImage< TImage >, ThreadedImageRegionPartitioner< TImage::ImageDimension >, TLevelSetEvolution >
::LevelSetEvolutionComputeIterationThreader()
{
}
template< typename TImage, typename TLevelSetEvolution >
void
LevelSetEvolutionComputeIterationThreader< LevelSetDenseImage< TImage >, ThreadedImageRegionPartitioner< TImage::ImageDimension >, TLevelSetEvolution >
::ThreadedExecution( const DomainType & imageSubRegion,
const ThreadIdType itkNotUsed(threadId) )
{
typename LevelSetContainerType::Iterator levelSetContainerIt = this->m_Associate->m_LevelSetContainer->Begin();
typename LevelSetType::Pointer levelSet = levelSetContainerIt->GetLevelSet();
typename LevelSetImageType::ConstPointer levelSetImage = levelSet->GetImage();
// Identify the level-set region
OffsetType offset = levelSet->GetDomainOffset();
IndexType index = imageSubRegion.GetIndex() - offset;
RegionType subRegion;
subRegion.SetSize( imageSubRegion.GetSize() );
subRegion.SetIndex( index );
ImageRegionConstIteratorWithIndex< LevelSetImageType > imageIt( levelSetImage, subRegion );
imageIt.GoToBegin();
if( this->m_Associate->m_LevelSetContainer->HasDomainMap() )
{
const IdListType * idList = this->m_Associate->m_IdListToProcessWhenThreading;
// Avoid repeated map lookups.
const size_t numberOfLevelSets = idList->size();
std::vector< LevelSetImageType * > levelSetUpdateImages( numberOfLevelSets );
std::vector< TermContainerType * > termContainers( numberOfLevelSets );
IdListConstIterator idListIt = idList->begin();
unsigned int idListIdx = 0;
while( idListIt != idList->end() )
{
//! \todo Fix me for string identifiers
LevelSetType * levelSetUpdate = this->m_Associate->m_UpdateBuffer->GetLevelSet( *idListIt - 1 );
levelSetUpdateImages[idListIdx] = levelSetUpdate->GetModifiableImage();
termContainers[idListIdx] = this->m_Associate->m_EquationContainer->GetEquation( *idListIt - 1 );
++idListIt;
++idListIdx;
}
while( !imageIt.IsAtEnd() )
{
const IndexType levelSetIndex = imageIt.GetIndex();
const IndexType inputIndex = imageIt.GetIndex() + offset;
for( idListIdx = 0; idListIdx < numberOfLevelSets; ++idListIdx )
{
LevelSetDataType characteristics;
termContainers[idListIdx]->ComputeRequiredData( inputIndex, characteristics );
LevelSetOutputRealType temp_update = termContainers[idListIdx]->Evaluate( inputIndex, characteristics );
levelSetUpdateImages[idListIdx]->SetPixel( levelSetIndex, temp_update );
}
++imageIt;
}
}
else
{
// This is for single level set analysis, so we only process the first level
// set.
typename LevelSetContainerType::ConstIterator levelSetUpdateContainerIt = this->m_Associate->m_UpdateBuffer->Begin();
typename LevelSetType::Pointer levelSetUpdate = levelSetUpdateContainerIt->GetLevelSet();
typename LevelSetImageType::Pointer levelSetUpdateImage = levelSetUpdate->GetModifiableImage();
typename EquationContainerType::Iterator equationContainerIt = this->m_Associate->m_EquationContainer->Begin();
typename TermContainerType::Pointer termContainer = equationContainerIt->GetEquation();
imageIt.GoToBegin();
while( !imageIt.IsAtEnd() )
{
const IndexType levelSetIndex = imageIt.GetIndex();
const IndexType inputIndex = imageIt.GetIndex() + offset;
LevelSetDataType characteristics;
termContainer->ComputeRequiredData( inputIndex, characteristics );
LevelSetOutputRealType temp_update = termContainer->Evaluate( inputIndex, characteristics );
levelSetUpdateImage->SetPixel( levelSetIndex, temp_update );
++imageIt;
}
}
}
template< typename TImage, typename TLevelSetEvolution >
LevelSetEvolutionComputeIterationThreader<
LevelSetDenseImage< TImage >,
ThreadedIteratorRangePartitioner< typename TLevelSetEvolution::DomainMapImageFilterType::DomainMapType::const_iterator >,
TLevelSetEvolution >
::LevelSetEvolutionComputeIterationThreader()
{
}
template< typename TImage, typename TLevelSetEvolution >
void
LevelSetEvolutionComputeIterationThreader<
LevelSetDenseImage< TImage >,
ThreadedIteratorRangePartitioner< typename TLevelSetEvolution::DomainMapImageFilterType::DomainMapType::const_iterator >,
TLevelSetEvolution >
::ThreadedExecution( const DomainType & imageSubDomain,
const ThreadIdType itkNotUsed(threadId) )
{
typename InputImageType::ConstPointer inputImage = this->m_Associate->m_EquationContainer->GetInput();
typename DomainType::IteratorType mapIt = imageSubDomain.Begin();
while( mapIt != imageSubDomain.End() )
{
ImageRegionConstIteratorWithIndex< InputImageType > it( inputImage, *(mapIt->second.GetRegion()) );
it.GoToBegin();
while( !it.IsAtEnd() )
{
const IdListType idList = *(mapIt->second.GetIdList());
//itkAssertInDebugOrThrowInReleaseMacro( !idList.empty() );
for( IdListConstIterator idListIt = idList.begin(); idListIt != idList.end(); ++idListIt )
{
typename LevelSetType::Pointer levelSetUpdate = this->m_Associate->m_UpdateBuffer->GetLevelSet( *idListIt - 1 );
OffsetType offset = levelSetUpdate->GetDomainOffset();
IndexType levelSetIndex = it.GetIndex() - offset;
LevelSetDataType characteristics;
typename TermContainerType::Pointer termContainer = this->m_Associate->m_EquationContainer->GetEquation( *idListIt - 1 );
termContainer->ComputeRequiredData( it.GetIndex(), characteristics );
LevelSetOutputRealType tempUpdate = termContainer->Evaluate( it.GetIndex(), characteristics );
LevelSetImageType * levelSetImage = levelSetUpdate->GetModifiableImage();
levelSetImage->SetPixel( levelSetIndex, tempUpdate );
}
++it;
}
++mapIt;
}
}
template< typename TOutput, unsigned int VDimension, typename TLevelSetEvolution >
LevelSetEvolutionComputeIterationThreader<
WhitakerSparseLevelSetImage< TOutput, VDimension >,
ThreadedIteratorRangePartitioner< typename WhitakerSparseLevelSetImage< TOutput, VDimension >::LayerConstIterator >,
TLevelSetEvolution >
::LevelSetEvolutionComputeIterationThreader()
{
}
template< typename TOutput, unsigned int VDimension, typename TLevelSetEvolution >
void
LevelSetEvolutionComputeIterationThreader<
WhitakerSparseLevelSetImage< TOutput, VDimension >,
ThreadedIteratorRangePartitioner< typename WhitakerSparseLevelSetImage< TOutput, VDimension >::LayerConstIterator >,
TLevelSetEvolution >
::BeforeThreadedExecution()
{
const ThreadIdType numberOfThreads = this->GetNumberOfThreadsUsed();
this->m_NodePairsPerThread.resize( numberOfThreads );
for( ThreadIdType ii = 0; ii < numberOfThreads; ++ii )
{
this->m_NodePairsPerThread[ii].clear();
}
}
template< typename TOutput, unsigned int VDimension, typename TLevelSetEvolution >
void
LevelSetEvolutionComputeIterationThreader<
WhitakerSparseLevelSetImage< TOutput, VDimension >,
ThreadedIteratorRangePartitioner< typename WhitakerSparseLevelSetImage< TOutput, VDimension >::LayerConstIterator >,
TLevelSetEvolution >
::ThreadedExecution( const DomainType & iteratorSubRange,
const ThreadIdType threadId )
{
typename LevelSetContainerType::Iterator it = this->m_Associate->m_LevelSetContainerIteratorToProcessWhenThreading;
typename LevelSetType::ConstPointer levelSet = it->GetLevelSet();
LevelSetIdentifierType levelSetId = it->GetIdentifier();
OffsetType offset = levelSet->GetDomainOffset();
typename TermContainerType::Pointer termContainer = this->m_Associate->m_EquationContainer->GetEquation( levelSetId );
typename LevelSetType::LayerConstIterator listIt = iteratorSubRange.Begin();
while( listIt != iteratorSubRange.End() )
{
const LevelSetInputType levelsetIndex = listIt->first;
LevelSetInputType inputIndex = listIt->first + offset;
LevelSetDataType characteristics;
termContainer->ComputeRequiredData( inputIndex, characteristics );
const LevelSetOutputType temp_update =
static_cast< LevelSetOutputType >( termContainer->Evaluate( inputIndex, characteristics ) );
this->m_NodePairsPerThread[threadId].push_back( NodePairType( levelsetIndex, temp_update ) );
++listIt;
}
}
template< typename TOutput, unsigned int VDimension, typename TLevelSetEvolution >
void
LevelSetEvolutionComputeIterationThreader<
WhitakerSparseLevelSetImage< TOutput, VDimension >,
ThreadedIteratorRangePartitioner< typename WhitakerSparseLevelSetImage< TOutput, VDimension >::LayerConstIterator >,
TLevelSetEvolution >
::AfterThreadedExecution()
{
typename LevelSetContainerType::Iterator it = this->m_Associate->m_LevelSetContainerIteratorToProcessWhenThreading;
LevelSetIdentifierType levelSetId = it->GetIdentifier();
typename LevelSetEvolutionType::LevelSetLayerType * levelSetLayerUpdateBuffer = this->m_Associate->m_UpdateBuffer[ levelSetId ];
const ThreadIdType numberOfThreads = this->GetNumberOfThreadsUsed();
for( ThreadIdType ii = 0; ii < numberOfThreads; ++ii )
{
typename std::vector< NodePairType >::const_iterator pairIt = this->m_NodePairsPerThread[ii].begin();
while( pairIt != this->m_NodePairsPerThread[ii].end() )
{
levelSetLayerUpdateBuffer->insert( *pairIt );
++pairIt;
}
}
}
} // end namespace itk
#endif
|