Skip to content

Commit

Permalink
Merge pull request KitwareMedical#2 from thewtex/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
thewtex authored Mar 21, 2017
2 parents 82e5645 + 794e86d commit c7c8fad
Show file tree
Hide file tree
Showing 11 changed files with 877 additions and 53 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
cmake_minimum_required(VERSION 2.8.9)
project(Strain)
itk_module_impl()

if(NOT ITK_SOURCE_DIR)
find_package(ITK REQUIRED)
list(APPEND CMAKE_MODULE_PATH ${ITK_CMAKE_DIR})
include(ITKModuleExternal)
else()
itk_module_impl()
endif()
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 Strain
*
* \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
42 changes: 29 additions & 13 deletions include/itkStrainImageFilter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
#ifndef __itkStrainImageFilter_h
#define __itkStrainImageFilter_h
/*=========================================================================
*
* 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 itkStrainImageFilter_h
#define itkStrainImageFilter_h

#include "itkCovariantVector.h"
#include "itkImageToImageFilter.h"
Expand All @@ -11,7 +28,7 @@ namespace itk

/** \class StrainImageFilter
*
* \brief Generate a strain image from a displacement image.
* \brief Generate a strain field image from a displacement field image.
*
* Internally, a gradient filter (see SetGradientFilter()) is used to calculate
* deformation gradient tensors. This filter is used by default on each displacement Vector
Expand All @@ -37,6 +54,8 @@ namespace itk
* which uses a material reference system, and Eulerian-Almansi, which uses a
* spatial reference system. This is set with SetStrainForm().
*
* \sa TransformToStrainFilter
*
* \ingroup Strain
*
*/
Expand All @@ -50,10 +69,10 @@ class StrainImageFilter : public
/** ImageDimension enumeration. */
itkStaticConstMacro(ImageDimension, unsigned int, TInputImage::ImageDimension);

typedef TInputImage InputImageType;
typedef Image< SymmetricSecondRankTensor< TOutputValueType, ImageDimension >, ImageDimension >
OutputImageType;
typedef Image< TOperatorValueType, ImageDimension > OperatorImageType;
typedef TInputImage InputImageType;
typedef SymmetricSecondRankTensor< TOutputValueType, ImageDimension > OutputPixelType;
typedef Image< OutputPixelType, ImageDimension > OutputImageType;
typedef Image< TOperatorValueType, ImageDimension > OperatorImageType;

/** Standard class typedefs. */
typedef StrainImageFilter Self;
Expand Down Expand Up @@ -103,10 +122,9 @@ class StrainImageFilter : public

StrainImageFilter();

virtual void BeforeThreadedGenerateData();
virtual void BeforeThreadedGenerateData() ITK_OVERRIDE;

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

typedef itk::SplitComponentsImageFilter< InputImageType, OperatorImageType >
InputComponentsImageFilterType;
Expand All @@ -119,8 +137,7 @@ class StrainImageFilter : public
StrainFormType m_StrainForm;

private:
StrainImageFilter( const Self & );
void operator=( const Self & );
ITK_DISALLOW_COPY_AND_ASSIGN(StrainImageFilter);
};

} // end namespace itk
Expand All @@ -130,4 +147,3 @@ class StrainImageFilter : public
#endif

#endif

Loading

0 comments on commit c7c8fad

Please sign in to comment.