Skip to content

Commit

Permalink
ENH: Remove dependencies on the SplitComponents module.
Browse files Browse the repository at this point in the history
Currently, Remote modules cannot be dependent on each other.
  • Loading branch information
thewtex committed Sep 30, 2016
1 parent 7b31898 commit 4cc94fe
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 1 deletion.
107 changes: 107 additions & 0 deletions include/itkSplitComponentsImageFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*=========================================================================
*
* 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 itkSplitComponentsImageFilter_h
#define itkSplitComponentsImageFilter_h

#include "itkFixedArray.h"
#include "itkImageToImageFilter.h"

namespace itk
{

/** \class SplitComponentsImageFilter
*
* \brief Extract components of an Image with multi-component pixels.
*
* This class extracts components of itk::Image of itk::Vector's
* itk::CovariantVector, itk::SymmetricSecondRankTensor, or other classes that
* have the same interface. The interface must implement ValueType operator[] (
* unsigned int ).
*
* It puts an image on every output corresponding to each component.
*
* \ingroup SplitComponents
*
* \sa VectorImageToImageAdaptor
* \sa Vector
* \sa CovariantVector
* \sa SymmetricSecondRankTensor
* \sa DiffusionTensor3D
* \sa NthElementImageAdaptor
*/
template< class TInputImage, class TOutputImage, unsigned int TComponents = TInputImage::ImageDimension >
class SplitComponentsImageFilter:
public ImageToImageFilter< TInputImage, TOutputImage >
{
public:
/** ImageDimension enumeration. */
itkStaticConstMacro(ImageDimension, unsigned int,
TInputImage::ImageDimension);
/** Components enumeration. */
itkStaticConstMacro(Components, unsigned int,
TComponents);

/** Image types. */
typedef TInputImage InputImageType;
typedef TOutputImage OutputImageType;
typedef typename InputImageType::PixelType InputPixelType;
typedef typename OutputImageType::PixelType OutputPixelType;
typedef typename OutputImageType::RegionType OutputRegionType;

/** Standard class typedefs. */
typedef SplitComponentsImageFilter Self;
typedef ImageToImageFilter< InputImageType, OutputImageType > Superclass;
typedef SmartPointer< Self > Pointer;
typedef SmartPointer< const Self > ConstPointer;

typedef FixedArray< bool, TComponents > ComponentsMaskType;

/** Run-time type information (and related methods). */
itkTypeMacro( SplitComponentsImageFilter, ImageToImageFilter );

/** Method of creation through the object factory. */
itkNewMacro( Self );

/** Set/Get the components mask. The mask is as long as the number of
* components, and only values in the mask that evaluate are true will be
* populated in the output. The default is all true. */
itkSetMacro( ComponentsMask, ComponentsMaskType );
itkGetConstReferenceMacro( ComponentsMask, ComponentsMaskType );

protected:
SplitComponentsImageFilter();
virtual ~SplitComponentsImageFilter() {}

/** Do not allocate outputs that we will not populate. */
virtual void AllocateOutputs();

virtual void ThreadedGenerateData( const OutputRegionType& outputRegion, ThreadIdType threadId );

private:
ITK_DISALLOW_COPY_AND_ASSIGN(SplitComponentsImageFilter);

ComponentsMaskType m_ComponentsMask;
};

} // end namespace itk

#ifndef ITK_MANUAL_INSTANTIATION
#include "itkSplitComponentsImageFilter.hxx"
#endif

#endif
114 changes: 114 additions & 0 deletions include/itkSplitComponentsImageFilter.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*=========================================================================
*
* 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 itkSplitComponentsImageFilter_hxx
#define itkSplitComponentsImageFilter_hxx

#include "itkSplitComponentsImageFilter.h"

#include "itkImageRegionConstIterator.h"
#include "itkImageRegionIterator.h"

namespace itk
{

template< class TInputImage, class TOutputImage, unsigned int TComponents >
SplitComponentsImageFilter< TInputImage, TOutputImage, TComponents >
::SplitComponentsImageFilter()
{
this->m_ComponentsMask.Fill( true );

this->SetNumberOfIndexedOutputs( Components );

// ImageSource only does this for the first output.
for ( unsigned int i = 1; i < Components; i++ )
{
this->SetNthOutput( i, this->MakeOutput( i ) );
}
}


template< class TInputImage, class TOutputImage, unsigned int TComponents >
void
SplitComponentsImageFilter< TInputImage, TOutputImage, TComponents >
::AllocateOutputs()
{
typedef ImageBase< TOutputImage::ImageDimension > ImageBaseType;
typename ImageBaseType::Pointer outputPtr;

// Allocate the output memory as with ImageSource
unsigned int ii = 0;
for ( OutputDataObjectIterator it(this);
!it.IsAtEnd();
++it, ++ii )
{
// Check whether the output is an image of the appropriate
// dimension (use ProcessObject's version of the GetInput()
// method since it returns the input as a pointer to a
// DataObject as opposed to the subclass version which
// static_casts the input to an TInputImage).
outputPtr = dynamic_cast< ImageBaseType * >( it.GetOutput() );

if ( outputPtr && this->m_ComponentsMask[ii] )
{
outputPtr->SetBufferedRegion( outputPtr->GetRequestedRegion() );
outputPtr->Allocate();
}
}
}


template< class TInputImage, class TOutputImage, unsigned int TComponents >
void
SplitComponentsImageFilter< TInputImage, TOutputImage, TComponents >
::ThreadedGenerateData( const OutputRegionType& outputRegion, ThreadIdType itkNotUsed(threadId) )
{
typename InputImageType::ConstPointer input = this->GetInput();
ProcessObject::DataObjectPointerArray outputs = this->GetOutputs();
const ComponentsMaskType componentsMask = this->m_ComponentsMask;

typedef ImageRegionIterator< OutputImageType > OutputIteratorType;
ImageRegionConstIterator< InputImageType > inIt( input, outputRegion );
std::vector< OutputIteratorType > outIts( Components );
for ( unsigned int ii = 0; ii < Components; ++ii )
{
if( componentsMask[ii] )
{
OutputIteratorType outIt( dynamic_cast< OutputImageType* >
( outputs[ii].GetPointer() ), outputRegion );
outIt.GoToBegin();
outIts[ii] = outIt;
}
}
InputPixelType inputPixel;
for ( inIt.GoToBegin(); !inIt.IsAtEnd(); ++inIt )
{
inputPixel = inIt.Get();
for ( unsigned int ii = 0; ii < Components; ++ii )
{
if( componentsMask[ii] )
{
outIts[ii].Set( static_cast< OutputPixelType >( inputPixel[ii] ) );
++(outIts[ii]);
}
}
}
}

} // end namespace itk

#endif
1 change: 0 additions & 1 deletion itk-module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ itk_module(Strain
ITKCommon
ITKImageGradient
ITKImageSources
SplitComponents
TEST_DEPENDS
ITKTestKernel
ITKDisplacementField
Expand Down

0 comments on commit 4cc94fe

Please sign in to comment.