forked from KitwareMedical/ITKStrain
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request KitwareMedical#2 from thewtex/updates
Updates
- Loading branch information
Showing
11 changed files
with
877 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.