-
Notifications
You must be signed in to change notification settings - Fork 7
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 #21 from dzenanz/master
Migrate LevelSetsv4Visualization into this module
- Loading branch information
Showing
38 changed files
with
5,083 additions
and
5 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
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,85 @@ | ||
/*========================================================================= | ||
* | ||
* 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 itkImageToRGBVTKImageFilter_h | ||
#define itkImageToRGBVTKImageFilter_h | ||
|
||
#include "itkProcessObject.h" | ||
#include "vtkSmartPointer.h" | ||
#include "vtkImageData.h" | ||
|
||
namespace itk | ||
{ | ||
/** \class ImageToRGBVTKImageFilter | ||
* \brief Converts an ITK image into a VTK image. | ||
* | ||
* \ingroup ITKLevelSetsv4Visualization | ||
*/ | ||
template< typename TInputImage > | ||
class ITK_TEMPLATE_EXPORT ImageToRGBVTKImageFilter:public ProcessObject | ||
{ | ||
public: | ||
ITK_DISALLOW_COPY_AND_ASSIGN(ImageToRGBVTKImageFilter); | ||
|
||
/** Standard class type aliases. */ | ||
using Self = ImageToRGBVTKImageFilter; | ||
using Superclass = ProcessObject; | ||
using Pointer = SmartPointer< Self >; | ||
using ConstPointer = SmartPointer< const Self >; | ||
|
||
/** Method for creation through the object factory. */ | ||
itkNewMacro(Self); | ||
|
||
/** Run-time type information (and related methods). */ | ||
itkTypeMacro(ImageToRGBVTKImageFilter, ProcessObject); | ||
|
||
/** Some type alias. */ | ||
using InputImageType = TInputImage; | ||
using InputImagePointer = typename InputImageType::ConstPointer; | ||
using InputRegionType = typename InputImageType::RegionType; | ||
using InputSpacingType = typename InputImageType::SpacingType; | ||
using InputSizeType = typename InputImageType::SizeType; | ||
using InputPixelType = typename InputImageType::PixelType; | ||
using InputIndexType = typename InputImageType::IndexType; | ||
|
||
/** Get the output in the form of a vtkImage. | ||
This call is delegated to the internal vtkImageImporter filter */ | ||
vtkSmartPointer< vtkImageData > GetOutput() const; | ||
|
||
/** Set the input in the form of an itk::Image */ | ||
using Superclass::SetInput; | ||
void SetInput(const InputImageType *); | ||
|
||
/** This call delegate the update to the importer */ | ||
void Update() override; | ||
|
||
protected: | ||
ImageToRGBVTKImageFilter(); | ||
~ImageToRGBVTKImageFilter() override; | ||
|
||
private: | ||
InputImagePointer m_Input; | ||
vtkSmartPointer< vtkImageData > m_Output; | ||
}; | ||
} // end namespace itk | ||
|
||
#ifndef ITK_MANUAL_INSTANTIATION | ||
#include "itkImageToRGBVTKImageFilter.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,149 @@ | ||
/*========================================================================= | ||
* | ||
* 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 itkImageToRGBVTKImageFilter_hxx | ||
#define itkImageToRGBVTKImageFilter_hxx | ||
|
||
#include "vtkVersion.h" | ||
|
||
#include "itkImageToRGBVTKImageFilter.h" | ||
|
||
namespace itk | ||
{ | ||
/** | ||
* Constructor | ||
*/ | ||
template< typename TInputImage > | ||
ImageToRGBVTKImageFilter< TInputImage > | ||
::ImageToRGBVTKImageFilter() | ||
{ | ||
m_Output = vtkSmartPointer< vtkImageData >::New(); | ||
} | ||
|
||
/** | ||
* Destructor | ||
*/ | ||
template< typename TInputImage > | ||
ImageToRGBVTKImageFilter< TInputImage > | ||
::~ImageToRGBVTKImageFilter() | ||
{} | ||
|
||
/** | ||
* Set an itk::Image as input | ||
*/ | ||
template< typename TInputImage > | ||
void | ||
ImageToRGBVTKImageFilter< TInputImage > | ||
::SetInput(const InputImageType *inputImage) | ||
{ | ||
m_Input = inputImage; | ||
this->Modified(); | ||
} | ||
|
||
/** | ||
* Get a vtkImage as output | ||
*/ | ||
template< typename TInputImage > | ||
vtkSmartPointer< vtkImageData > | ||
ImageToRGBVTKImageFilter< TInputImage > | ||
::GetOutput() const | ||
{ | ||
return m_Output; | ||
} | ||
|
||
/** | ||
* Delegate the Update to the importer | ||
*/ | ||
template< typename TInputImage > | ||
void | ||
ImageToRGBVTKImageFilter< TInputImage > | ||
::Update() | ||
{ | ||
int dimension[3]; | ||
dimension[0] = 0; | ||
dimension[1] = 0; | ||
dimension[2] = 0; | ||
|
||
double spacing[3]; | ||
spacing[0] = 0.; | ||
spacing[1] = 0.; | ||
spacing[2] = 0.; | ||
|
||
InputRegionType region = m_Input->GetLargestPossibleRegion(); | ||
InputSizeType itk_size = region.GetSize(); | ||
|
||
InputSpacingType itk_spacing = m_Input->GetSpacing(); | ||
|
||
for( unsigned int i = 0; i < TInputImage::ImageDimension; i++ ) | ||
{ | ||
dimension[i] = static_cast< int >( itk_size[i] ); | ||
spacing[i] = static_cast< double >( itk_spacing[i] ); | ||
} | ||
m_Output->SetDimensions( dimension ); | ||
m_Output->SetSpacing( spacing ); | ||
m_Output->SetExtent( 0, dimension[0], | ||
0, dimension[1], | ||
0, dimension[2] ); | ||
#if VTK_MAJOR_VERSION <= 5 | ||
m_Output->SetNumberOfScalarComponents( 3 ); | ||
|
||
// at first let's convert it to unsigned char | ||
m_Output->SetScalarTypeToUnsignedChar(); | ||
m_Output->AllocateScalars(); | ||
#else | ||
m_Output->AllocateScalars(VTK_UNSIGNED_CHAR,3); | ||
#endif | ||
//TODO: use itk iterators instead | ||
for( int x = 0; x < dimension[0]; x++ ) | ||
{ | ||
for( int y = 0; y < dimension[1]; y++ ) | ||
{ | ||
if( TInputImage::ImageDimension == 3 ) | ||
{ | ||
for( int z = 0; z < dimension[2]; z++ ) | ||
{ | ||
auto * vtkpixel = static_cast<InputPixelType*>(m_Output->GetScalarPointer(x,y,z)); | ||
InputIndexType index; | ||
index[0] = x; | ||
index[1] = y; | ||
index[2] = z; | ||
|
||
InputPixelType itkpixel = m_Input->GetPixel(index); | ||
vtkpixel[0] = itkpixel; | ||
vtkpixel[1] = itkpixel; | ||
vtkpixel[2] = itkpixel; | ||
} | ||
} | ||
else | ||
{ | ||
auto * vtkpixel = static_cast<InputPixelType*>(m_Output->GetScalarPointer(x,y,0)); | ||
InputIndexType index; | ||
index[0] = x; | ||
index[1] = y; | ||
|
||
InputPixelType itkpixel = m_Input->GetPixel(index); | ||
vtkpixel[0] = itkpixel; | ||
vtkpixel[1] = itkpixel; | ||
vtkpixel[2] = itkpixel; | ||
} | ||
} | ||
} | ||
} | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/*========================================================================= | ||
* | ||
* 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 itkLevelSetIterationUpdateCommand_h | ||
#define itkLevelSetIterationUpdateCommand_h | ||
|
||
#include "itkCommand.h" | ||
#include "itkWeakPointer.h" | ||
#include "itkIntTypes.h" | ||
|
||
namespace itk | ||
{ | ||
|
||
/** \class LevelSetIterationUpdateCommand | ||
* \brief Call update on one filter when another filter iterates. | ||
* | ||
* \tparam TIteratingFilter Filter that invokes iteration events. | ||
* \tparam TFilterToUpdate Filter to call update on when the iteration event | ||
* occurs. | ||
* | ||
* \ingroup ITKLevelSetsv4Visualization | ||
*/ | ||
template< typename TIteratingFilter, typename TFilterToUpdate > | ||
class ITK_TEMPLATE_EXPORT LevelSetIterationUpdateCommand : public Command | ||
{ | ||
public: | ||
ITK_DISALLOW_COPY_AND_ASSIGN(LevelSetIterationUpdateCommand); | ||
|
||
using Self = LevelSetIterationUpdateCommand; | ||
using Superclass = Command; | ||
using Pointer = SmartPointer< Self >; | ||
using ConstPointer = SmartPointer< const Self >; | ||
|
||
using IteratingFilterType = TIteratingFilter; | ||
using FilterToUpdateType = TFilterToUpdate; | ||
|
||
/** Run-time type information (and related methods). */ | ||
itkTypeMacro( LevelSetIterationUpdateCommand, Command ); | ||
|
||
itkNewMacro( Self ); | ||
|
||
void Execute( const Object* caller, const EventObject& event ) override; | ||
|
||
void Execute( Object* caller, const EventObject& event ) override; | ||
|
||
/** Set/Get the filter to call Update() on. */ | ||
itkSetObjectMacro( FilterToUpdate, FilterToUpdateType ); | ||
itkGetModifiableObjectMacro(FilterToUpdate, FilterToUpdateType ); | ||
|
||
/** Set/Get the period that Update() is called on the FilterToUpdate. It is | ||
* in units of iterations. */ | ||
itkSetMacro( UpdatePeriod, IdentifierType ); | ||
itkGetConstMacro( UpdatePeriod, IdentifierType ); | ||
|
||
protected: | ||
LevelSetIterationUpdateCommand(); | ||
~LevelSetIterationUpdateCommand() override; | ||
|
||
private: | ||
WeakPointer< FilterToUpdateType > m_FilterToUpdate; | ||
IdentifierType m_UpdatePeriod; | ||
}; | ||
|
||
} // end namespace itk | ||
|
||
#ifndef ITK_MANUAL_INSTANTIATION | ||
#include "itkLevelSetIterationUpdateCommand.hxx" | ||
#endif | ||
|
||
#endif |
Oops, something went wrong.