diff --git a/Modules/Bridge/VTK/include/itkVTKImageExport.h b/Modules/Bridge/VTK/include/itkVTKImageExport.h index 5b200ba38c7..5ffd45350dd 100644 --- a/Modules/Bridge/VTK/include/itkVTKImageExport.h +++ b/Modules/Bridge/VTK/include/itkVTKImageExport.h @@ -79,6 +79,7 @@ class ITK_EXPORT VTKImageExport:public VTKImageExportBase /** Set the input image of this image exporter. */ using Superclass::SetInput; void SetInput(const InputImageType *); + InputImageType * GetInput(void); protected: VTKImageExport(); @@ -89,7 +90,6 @@ class ITK_EXPORT VTKImageExport:public VTKImageExportBase typedef typename InputImageType::RegionType InputRegionType; typedef typename InputRegionType::SizeType InputSizeType; typedef typename InputRegionType::IndexType InputIndexType; - InputImageType * GetInput(void); int * WholeExtentCallback(); diff --git a/Modules/Bridge/VtkGlue/include/itkImageToVTKImageFilter.h b/Modules/Bridge/VtkGlue/include/itkImageToVTKImageFilter.h index df4a8e3d413..8c204a6e8d3 100644 --- a/Modules/Bridge/VtkGlue/include/itkImageToVTKImageFilter.h +++ b/Modules/Bridge/VtkGlue/include/itkImageToVTKImageFilter.h @@ -72,6 +72,7 @@ class ITK_EXPORT ImageToVTKImageFilter : public ProcessObject /** Set the input in the form of an itk::Image */ using Superclass::SetInput; void SetInput( const InputImageType * ); + InputImageType * GetInput(); /** Return the internal VTK image importer filter. This is intended to facilitate users the access diff --git a/Modules/Bridge/VtkGlue/include/itkImageToVTKImageFilter.hxx b/Modules/Bridge/VtkGlue/include/itkImageToVTKImageFilter.hxx index 761b988b5eb..ef39ce2badf 100644 --- a/Modules/Bridge/VtkGlue/include/itkImageToVTKImageFilter.hxx +++ b/Modules/Bridge/VtkGlue/include/itkImageToVTKImageFilter.hxx @@ -73,6 +73,14 @@ ImageToVTKImageFilter m_Exporter->SetInput( inputImage ); } +template +typename ImageToVTKImageFilter::InputImageType * +ImageToVTKImageFilter +::GetInput() +{ + return m_Exporter->GetInput(); +} + /** * Get a vtkImage as output */ diff --git a/Modules/Segmentation/LevelSetsv4Visualization/include/itkVTKVisualize2DLevelSetAsElevationMap.h b/Modules/Segmentation/LevelSetsv4Visualization/include/itkVTKVisualize2DLevelSetAsElevationMap.h new file mode 100644 index 00000000000..902cde76a67 --- /dev/null +++ b/Modules/Segmentation/LevelSetsv4Visualization/include/itkVTKVisualize2DLevelSetAsElevationMap.h @@ -0,0 +1,108 @@ +/*========================================================================= + * + * 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 __itkVTKVisualize2DLevelSetAsElevationMap_h +#define __itkVTKVisualize2DLevelSetAsElevationMap_h + +#include "itkVTKVisualizeImageLevelSet.h" + +#include "itkImageToVTKImageFilter.h" + +#include "vnl/vnl_math.h" + +#include "vtkCornerAnnotation.h" +#include "vtkImageData.h" +#include "vtkLookupTable.h" +#include "vtkMarchingSquares.h" +#include "vtkPolyDataMapper.h" +#include "vtkActor.h" +#include "vtkImageActor.h" +#include "vtkScalarBarActor.h" +#include "vtkProperty.h" +#include "vtkDoubleArray.h" +#include "vtkTextProperty.h" +#include "vtkRenderer.h" +#include "vtkRenderWindowInteractor.h" +#include "vtkRenderWindow.h" +#include "vtkImageShiftScale.h" +#include "vtkPointData.h" +#include "vtkCellArray.h" + +#include "vtkCaptureScreen.h" +#include "vtkPNGWriter.h" + +namespace itk +{ + +template< class TInputImage, class TLevelSet > +class VTKVisualize2DLevelSetAsElevationMap : public VTKVisualizeImageLevelSet< TInputImage, ImageToVTKImageFilter< TInputImage > > +{ +public: + typedef VTKVisualize2DLevelSetAsElevationMap Self; + typedef VTKVisualizeImageLevelSet< TInputImage, ImageToVTKImageFilter< TInputImage > > Superclass; + typedef SmartPointer< Self > Pointer; + typedef SmartPointer< const Self > ConstPointer; + + itkNewMacro( Self ); + + /** Run-time type information (and related methods). */ + itkTypeMacro(itkVTKVisualize2DLevelSetAsElevationMap, VTKVisualizeImageLevelSet); + + typedef typename Superclass::InputImageType InputImageType; + typedef typename InputImageType::SizeType InputImageSizeType; + typedef typename InputImageType::SizeValueType InputImageSizeValueType; + + typedef TLevelSet LevelSetType; + typedef typename LevelSetType::Pointer LevelSetPointer; + + void SetLevelSet( LevelSetType * levelSet ); + +protected: + VTKVisualize2DLevelSetAsElevationMap(); + virtual ~VTKVisualize2DLevelSetAsElevationMap(); + + virtual void PrepareVTKPipeline(); + + void GenerateElevationMap(); + +private: + VTKVisualize2DLevelSetAsElevationMap( const Self & ); // purposely not implemented + void operator=( const VTKVisualize2DLevelSetAsElevationMap & ); // purposely not implemented + + LevelSetPointer m_LevelSet; + + vtkSmartPointer< vtkPolyData > m_Mesh; + vtkSmartPointer< vtkCornerAnnotation > m_Annotation; + + InputImageSizeType m_NumberOfSamples; + + double m_Constant; + double m_MinValue; + double m_MaxValue; + + bool m_ColorValue; + +}; + +} // end namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itkVTKVisualize2DLevelSetAsElevationMap.hxx" +#endif + +#endif // itkVTKVisualize2DLevelSetAsElevationMap_H diff --git a/Modules/Segmentation/LevelSetsv4Visualization/include/itkVTKVisualize2DLevelSetAsElevationMap.hxx b/Modules/Segmentation/LevelSetsv4Visualization/include/itkVTKVisualize2DLevelSetAsElevationMap.hxx new file mode 100644 index 00000000000..1d6364257fe --- /dev/null +++ b/Modules/Segmentation/LevelSetsv4Visualization/include/itkVTKVisualize2DLevelSetAsElevationMap.hxx @@ -0,0 +1,232 @@ +/*========================================================================= + * + * 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 __itkVTKVisualize2DLevelSetAsElevationMap_hxx +#define __itkVTKVisualize2DLevelSetAsElevationMap_hxx + +#include "itkVTKVisualize2DLevelSetAsElevationMap.h" + +namespace itk +{ + +template< class TInputImage, class TLevelSet > +VTKVisualize2DLevelSetAsElevationMap< TInputImage, TLevelSet > +::VTKVisualize2DLevelSetAsElevationMap() +{ + this->m_ColorValue = true; + this->m_MinValue = itk::NumericTraits< double >::max( ); + this->m_MaxValue = itk::NumericTraits< double >::min( ); + this->m_Constant = 0.1; + + this->m_Mesh = vtkSmartPointer< vtkPolyData >::New(); + + this->m_Annotation = vtkSmartPointer< vtkCornerAnnotation >::New(); + this->m_Renderer->AddActor2D( m_Annotation ); +} + +template< class TInputImage, class TLevelSet > +VTKVisualize2DLevelSetAsElevationMap< TInputImage, TLevelSet > +::~VTKVisualize2DLevelSetAsElevationMap() +{ +} + +template< class TInputImage, class TLevelSet > +void +VTKVisualize2DLevelSetAsElevationMap< TInputImage, TLevelSet > +::SetLevelSet( LevelSetType * levelSet ) +{ + this->m_LevelSet = levelSet; +} + +template< class TInputImage, class TLevelSet > +void +VTKVisualize2DLevelSetAsElevationMap< TInputImage, TLevelSet > +::PrepareVTKPipeline() +{ + vtkSmartPointer< vtkImageShiftScale > shift = + vtkSmartPointer< vtkImageShiftScale >::New(); + shift->SetInput( this->m_InputImageConverter->GetOutput() ); + shift->SetOutputScalarTypeToUnsignedChar(); + shift->Update(); + + vtkSmartPointer< vtkImageActor > input_Actor = + vtkSmartPointer< vtkImageActor >::New(); + input_Actor->SetInput( shift->GetOutput() ); + + this->GenerateElevationMap(); + + vtkPolyDataMapper* meshmapper = vtkPolyDataMapper::New( ); + meshmapper->SetInput( this->m_Mesh ); + + if( !this->m_ColorValue ) + { + meshmapper->ScalarVisibilityOff( ); + } + else + { + meshmapper->SetScalarRange( this->m_MinValue, this->m_MaxValue ); + } + + vtkActor *SurfaceActor = vtkActor::New( ); + SurfaceActor->SetMapper( meshmapper ); + SurfaceActor->GetProperty( )->SetColor( 0.7, 0.7, 0.7 ); + + if( this->m_ColorValue ) + { + vtkSmartPointer< vtkScalarBarActor > scalarBar = + vtkSmartPointer< vtkScalarBarActor >::New( ); + scalarBar->SetLookupTable( meshmapper->GetLookupTable( ) ); + scalarBar->SetTitle( "Level Set" ); + scalarBar->GetPositionCoordinate( )->SetCoordinateSystemToNormalizedViewport( ); + scalarBar->GetPositionCoordinate( )->SetValue( 0.1, 0.01 ); + scalarBar->GetTitleTextProperty( )->SetColor( 0., 0., 0. ); + scalarBar->GetLabelTextProperty( )->SetColor( 0., 0., 0. ); + scalarBar->SetOrientationToHorizontal( ); + scalarBar->SetWidth( 0.8 ); + scalarBar->SetHeight( 0.17 ); + + this->m_Renderer->AddActor2D( scalarBar ); + } + + this->m_Renderer->AddActor ( input_Actor ); + this->m_Renderer->AddActor ( SurfaceActor ); + + std::stringstream counter; + counter << this->GetCurrentIteration(); + + m_Annotation->SetText( 0, counter.str().c_str() ); + + this->m_Renderer->AddActor2D( input_Actor ); + // m_Ren->AddActor2D( scalarbar ); +} + +template< class TInputImage, class TLevelSet > +void +VTKVisualize2DLevelSetAsElevationMap< TInputImage, TLevelSet > +::GenerateElevationMap() +{ + typename InputImageType::ConstPointer inputImage = this->m_InputImageConverter->GetInput(); + typename InputImageType::RegionType region = inputImage->GetLargestPossibleRegion(); + + typedef typename InputImageType::IndexType IndexType; + typedef typename InputImageType::PointType PointType; + + IndexType start = region.GetIndex(); + PointType itkPoint; + PointType itkPoint2; + + InputImageSizeType size = region.GetSize(); + + this->m_NumberOfSamples[0] = size[0] / 2; + this->m_NumberOfSamples[1] = size[1] / 2; + + IndexType dx; + dx[0] = static_cast< IndexValueType >( size[0] / this->m_NumberOfSamples[0] ); + dx[1] = static_cast< IndexValueType >( size[1] / this->m_NumberOfSamples[1] ); + + vtkSmartPointer< vtkPoints > vtkpoints = vtkSmartPointer< vtkPoints >::New( ); + vtkSmartPointer< vtkDoubleArray > vtkpointdata = vtkSmartPointer< vtkDoubleArray >::New( ); + vtkSmartPointer< vtkCellArray > cells = vtkSmartPointer< vtkCellArray >::New( ); + + this->m_Mesh->SetPoints( vtkpoints ); + this->m_Mesh->GetPointData( )->SetScalars( vtkpointdata ); + this->m_Mesh->SetPolys( cells ); + + InputImageSizeValueType k = 0; + + IndexType index; + double p[3]; + + for( InputImageSizeValueType i = 0; i < this->m_NumberOfSamples[0]; i++ ) + { + index[0] = start[0] + i * dx[0]; + + for( InputImageSizeValueType j = 0; j < this->m_NumberOfSamples[1]; j++ ) + { + index[1] = start[1] + j * dx[1]; + + inputImage->TransformIndexToPhysicalPoint( index, itkPoint ); + + p[0] = itkPoint[0]; + p[1] = itkPoint[1]; + p[2] = static_cast< double >( this->m_LevelSet->Evaluate( index ) ); + + vtkpointdata->InsertNextTuple1( p[2] ); + + if( p[2] < m_MinValue ) + { + m_MinValue = p[2]; + } + if( p[2] > m_MaxValue ) + { + m_MaxValue = p[2]; + } + + vtkpoints->InsertPoint( k++, p ); + } + } + + double den = vnl_math_max( vnl_math_abs( m_MinValue ), + vnl_math_abs( m_MaxValue ) ); + + inputImage->TransformIndexToPhysicalPoint( start, itkPoint ); + + index = start; + + index[0] += size[0] - 1; + index[1] += size[1] - 1; + + inputImage->TransformIndexToPhysicalPoint( index, itkPoint2 ); + + double ratio = m_Constant * + static_cast< double >( itkPoint.EuclideanDistanceTo( itkPoint2 ) ); + + if( den != 0. ) + { + ratio /= den; + } + + for( vtkIdType i = 0; i < vtkpoints->GetNumberOfPoints(); i++ ) + { + vtkpoints->GetPoint( i, p ); + p[2] *= ratio; + vtkpoints->SetPoint( i, p ); + } + + vtkIdType vtkId[3]; + + for( InputImageSizeValueType j = 0; j < ( this->m_NumberOfSamples[1] - 1 ); j++ ) + { + for( InputImageSizeValueType i = 0; i < ( this->m_NumberOfSamples[0] - 1 ); i++ ) + { + vtkId[0] = j * m_NumberOfSamples[0] + i; + vtkId[1] = vtkId[0] + 1; + vtkId[2] = vtkId[1] + m_NumberOfSamples[0]; + + this->m_Mesh->InsertNextCell( VTK_TRIANGLE, 3, static_cast< vtkIdType* >( vtkId ) ); + + vtkId[1] = vtkId[2]; + vtkId[2] = vtkId[1] - 1; + this->m_Mesh->InsertNextCell( VTK_TRIANGLE, 3, static_cast< vtkIdType* >( vtkId ) ); + } + } +} + + +} // end namespace itk + +#endif diff --git a/Modules/Segmentation/LevelSetsv4Visualization/include/vtkVisualize2DLevelSetAsElevationMap.h b/Modules/Segmentation/LevelSetsv4Visualization/include/vtkVisualize2DLevelSetAsElevationMap.h deleted file mode 100644 index bcb13669616..00000000000 --- a/Modules/Segmentation/LevelSetsv4Visualization/include/vtkVisualize2DLevelSetAsElevationMap.h +++ /dev/null @@ -1,351 +0,0 @@ -/*========================================================================= - * - * 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 __vtkVisualize2DLevelSetAsElevationMap_h -#define __vtkVisualize2DLevelSetAsElevationMap_h - -#include "itkLightObject.h" -#include "itkImageToVTKImageFilter.h" - -#include "vnl/vnl_math.h" - -#include "vtkCornerAnnotation.h" -#include "vtkImageData.h" -#include "vtkLookupTable.h" -#include "vtkMarchingSquares.h" -#include "vtkPolyDataMapper.h" -#include "vtkActor.h" -#include "vtkImageActor.h" -#include "vtkScalarBarActor.h" -#include "vtkProperty.h" -#include "vtkDoubleArray.h" -#include "vtkTextProperty.h" -#include "vtkRenderer.h" -#include "vtkRenderWindowInteractor.h" -#include "vtkRenderWindow.h" -#include "vtkImageShiftScale.h" -#include "vtkPointData.h" -#include "vtkCellArray.h" - -#include "vtkCaptureScreen.h" -#include "vtkPNGWriter.h" - - -template< class TImage, class TLevelSet > -class vtkVisualize2DLevelSetAsElevationMap : public itk::LightObject -{ -public: - typedef vtkVisualize2DLevelSetAsElevationMap Self; - typedef itk::LightObject Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - itkNewMacro( vtkVisualize2DLevelSetAsElevationMap ); - - /** Run-time type information (and related methods). */ - itkTypeMacro(vtkVisualize2DLevelSetAsElevationMap, - LightObject); - - typedef TImage ImageType; - typedef typename ImageType::ConstPointer ImageConstPointer; - typedef typename ImageType::SizeType ImageSizeType; - typedef typename ImageType::SizeValueType ImageSizeValueType; - - typedef TLevelSet LevelSetType; - typedef typename LevelSetType::Pointer LevelSetPointer; - - void SetInputImage( const ImageType * iImage ) - { - m_Image = iImage; - m_ImageConverter->SetInput( iImage ); - try - { - m_ImageConverter->Update(); - } - catch( itk::ExceptionObject& e ) - { - std::cout << e << std::endl; - return; - } - } - - void SetLevelSet( LevelSetType* f ) - { - if( !f ) - { - itkGenericExceptionMacro( << "Input Level Set is NULL" ); - } - m_LevelSet = f; - } - - void SetScreenCapture( const bool& iCapture ) - { - m_ScreenCapture = iCapture; - } - - void SetPeriod( const itk::IdentifierType& iPeriod ) - { - m_Period = iPeriod; - } - - void Update() - { - this->GenerateData(); - } - -protected: - vtkVisualize2DLevelSetAsElevationMap() - { - m_ColorValue = true; - m_MinValue = itk::NumericTraits< double >::max( ); - m_MaxValue = itk::NumericTraits< double >::min( ); - m_Constant = 0.1; - - m_Mesh = vtkSmartPointer< vtkPolyData >::New(); - - m_ImageConverter = ImageConverterType::New(); - - m_Renderer = vtkSmartPointer< vtkRenderer >::New(); - m_Renderer->SetBackground( 0.5, 0.5, 0.5 ); - - m_Annotation = vtkSmartPointer< vtkCornerAnnotation >::New(); - m_Renderer->AddActor2D( m_Annotation ); - - m_Iren = vtkSmartPointer< vtkRenderWindowInteractor >::New(); - - m_RenWin = vtkSmartPointer< vtkRenderWindow >::New(); - - m_RenWin->AddRenderer( m_Renderer ); - m_Iren->SetRenderWindow( m_RenWin ); - } - - ~vtkVisualize2DLevelSetAsElevationMap() {} - - void GenerateData() - { - vtkSmartPointer< vtkImageShiftScale > shift = - vtkSmartPointer< vtkImageShiftScale >::New(); - shift->SetInput( m_ImageConverter->GetOutput() ); - shift->SetOutputScalarTypeToUnsignedChar(); - shift->Update(); - - vtkSmartPointer< vtkImageActor > input_Actor = - vtkSmartPointer< vtkImageActor >::New(); - input_Actor->SetInput( shift->GetOutput() ); - - this->GenerateElevationMap(); - - vtkPolyDataMapper* meshmapper = vtkPolyDataMapper::New( ); - meshmapper->SetInput( m_Mesh ); - - if( !m_ColorValue ) - { - meshmapper->ScalarVisibilityOff( ); - } - else - { - meshmapper->SetScalarRange( m_MinValue, m_MaxValue ); - } - - vtkActor *SurfaceActor = vtkActor::New( ); - SurfaceActor->SetMapper( meshmapper ); - SurfaceActor->GetProperty( )->SetColor( 0.7, 0.7, 0.7 ); - - if( m_ColorValue ) - { - vtkSmartPointer< vtkScalarBarActor > scalarBar = - vtkSmartPointer< vtkScalarBarActor >::New( ); - scalarBar->SetLookupTable( meshmapper->GetLookupTable( ) ); - scalarBar->SetTitle( "Level Set" ); - scalarBar->GetPositionCoordinate( )->SetCoordinateSystemToNormalizedViewport( ); - scalarBar->GetPositionCoordinate( )->SetValue( 0.1, 0.01 ); - scalarBar->GetTitleTextProperty( )->SetColor( 0., 0., 0. ); - scalarBar->GetLabelTextProperty( )->SetColor( 0., 0., 0. ); - scalarBar->SetOrientationToHorizontal( ); - scalarBar->SetWidth( 0.8 ); - scalarBar->SetHeight( 0.17 ); - - m_Renderer->AddActor2D( scalarBar ); - } - - m_Renderer->AddActor ( input_Actor ); - m_Renderer->AddActor ( SurfaceActor ); - - std::stringstream counter; - counter << m_Count; - - m_Annotation->SetText( 0, counter.str().c_str() ); - - m_Renderer->AddActor2D( input_Actor ); - // m_Ren->AddActor2D( scalarbar ); - - m_RenWin->Render(); - - if( m_ScreenCapture ) - { - std::string filename; - std::stringstream yo; - yo << "snapshot_dense_" << std::setfill( '0' ) << std::setw( 5 ) << m_Count; - filename = yo.str(); - filename.append ( ".png" ); - - vtkCaptureScreen< vtkPNGWriter > capture ( m_RenWin ); - // begin mouse interaction - capture( filename ); - } - - ++m_Count; - } - - void GenerateElevationMap() - { - typename ImageType::RegionType region = m_Image->GetLargestPossibleRegion(); - - typedef typename ImageType::IndexType IndexType; - typedef typename ImageType::IndexValueType IndexValueType; - typedef typename ImageType::PointType PointType; - - IndexType start = region.GetIndex(); - PointType itkPoint, itkPoint2; - - ImageSizeType size = region.GetSize(); - - m_NumberOfSamples[0] = size[0] / 2; - m_NumberOfSamples[1] = size[1] / 2; - - IndexType dx; - dx[0] = static_cast< IndexValueType >( size[0] / m_NumberOfSamples[0] ); - dx[1] = static_cast< IndexValueType >( size[1] / m_NumberOfSamples[1] ); - - vtkSmartPointer< vtkPoints > vtkpoints = vtkSmartPointer< vtkPoints >::New( ); - vtkSmartPointer< vtkDoubleArray > vtkpointdata = vtkSmartPointer< vtkDoubleArray >::New( ); - vtkSmartPointer< vtkCellArray > cells = vtkSmartPointer< vtkCellArray >::New( ); - - m_Mesh->SetPoints( vtkpoints ); - m_Mesh->GetPointData( )->SetScalars( vtkpointdata ); - m_Mesh->SetPolys( cells ); - - ImageSizeValueType k = 0; - - IndexType index; - double p[3]; - - for( ImageSizeValueType i = 0; i < m_NumberOfSamples[0]; i++ ) - { - index[0] = start[0] + i * dx[0]; - - for( ImageSizeValueType j = 0; j < m_NumberOfSamples[1]; j++ ) - { - index[1] = start[1] + j * dx[1]; - - m_Image->TransformIndexToPhysicalPoint( index, itkPoint ); - - p[0] = itkPoint[0]; - p[1] = itkPoint[1]; - p[2] = static_cast< double >( this->m_LevelSet->Evaluate( index ) ); - - vtkpointdata->InsertNextTuple1( p[2] ); - - if( p[2] < m_MinValue ) - { - m_MinValue = p[2]; - } - if( p[2] > m_MaxValue ) - { - m_MaxValue = p[2]; - } - - vtkpoints->InsertPoint( k++, p ); - } - } - - double den = vnl_math_max( vnl_math_abs( m_MinValue ), - vnl_math_abs( m_MaxValue ) ); - - m_Image->TransformIndexToPhysicalPoint( start, itkPoint ); - - index = start; - - index[0] += size[0] - 1; - index[1] += size[1] - 1; - - m_Image->TransformIndexToPhysicalPoint( index, itkPoint2 ); - - double ratio = m_Constant * - static_cast< double >( itkPoint.EuclideanDistanceTo( itkPoint2 ) ); - - if( den != 0. ) - { - ratio /= den; - } - - for( vtkIdType i = 0; i < vtkpoints->GetNumberOfPoints(); i++ ) - { - vtkpoints->GetPoint( i, p ); - p[2] *= ratio; - vtkpoints->SetPoint( i, p ); - } - - vtkIdType vtkId[3]; - - for( ImageSizeValueType j = 0; j < ( m_NumberOfSamples[1] - 1 ); j++ ) - { - for( ImageSizeValueType i = 0; i < ( m_NumberOfSamples[0] - 1 ); i++ ) - { - vtkId[0] = j * m_NumberOfSamples[0] + i; - vtkId[1] = vtkId[0] + 1; - vtkId[2] = vtkId[1] + m_NumberOfSamples[0]; - - m_Mesh->InsertNextCell( VTK_TRIANGLE, 3, static_cast< vtkIdType* >( vtkId ) ); - - vtkId[1] = vtkId[2]; - vtkId[2] = vtkId[1] - 1; - m_Mesh->InsertNextCell( VTK_TRIANGLE, 3, static_cast< vtkIdType* >( vtkId ) ); - } - } - } - -private: - typedef itk::ImageToVTKImageFilter< ImageType > ImageConverterType; - typedef typename ImageConverterType::Pointer ImageConverterPointer; - - ImageConstPointer m_Image; - ImageConverterPointer m_ImageConverter; - LevelSetPointer m_LevelSet; - - vtkSmartPointer< vtkPolyData > m_Mesh; - vtkSmartPointer< vtkCornerAnnotation > m_Annotation; - vtkSmartPointer< vtkRenderer > m_Renderer; - vtkSmartPointer< vtkRenderWindow > m_RenWin; - vtkSmartPointer< vtkRenderWindowInteractor > m_Iren; - - ImageSizeType m_NumberOfSamples; - - itk::IdentifierType m_Count; - itk::IdentifierType m_Period; - - double m_Constant; - double m_MinValue; - double m_MaxValue; - - bool m_ScreenCapture; - bool m_ColorValue; - -}; - -#endif // vtkVisualize2DLevelSetAsElevationMap_H diff --git a/Modules/Segmentation/LevelSetsv4Visualization/test/vtkVisualize2DCellsLevelSetSurfaceTest.cxx b/Modules/Segmentation/LevelSetsv4Visualization/test/vtkVisualize2DCellsLevelSetSurfaceTest.cxx index 95786cd93f8..6674637dd1f 100644 --- a/Modules/Segmentation/LevelSetsv4Visualization/test/vtkVisualize2DCellsLevelSetSurfaceTest.cxx +++ b/Modules/Segmentation/LevelSetsv4Visualization/test/vtkVisualize2DCellsLevelSetSurfaceTest.cxx @@ -18,7 +18,7 @@ #include "itkBinaryImageToDenseLevelSetImageAdaptor.h" #include "itkImageFileReader.h" -#include "itkIterationUpdateCommand.h" +#include "itkLevelSetIterationUpdateCommand.h" #include "itkLevelSetContainer.h" #include "itkLevelSetEquationChanAndVeseInternalTerm.h" #include "itkLevelSetEquationChanAndVeseExternalTerm.h" @@ -27,7 +27,7 @@ #include "itkLevelSetEvolution.h" #include "itkLevelSetEvolutionNumberOfIterationsStoppingCriterion.h" #include "itkLevelSetDenseImageBase.h" -#include "vtkVisualize2DLevelSetAsElevationMap.h" +#include "itkVTKVisualize2DLevelSetAsElevationMap.h" #include "itkSinRegularizedHeavisideStepFunction.h" template< class TInputImage, class TLevelSetType > @@ -129,12 +129,11 @@ VisualizeLevelSetSurface( TInputImage * inputImage, const int numberOfIterations std::cout << "Stopping criteria created" << std::endl; // Create the visualizer - typedef vtkVisualize2DLevelSetAsElevationMap< InputImageType, LevelSetType > VisualizationType; + typedef itk::VTKVisualize2DLevelSetAsElevationMap< InputImageType, LevelSetType > VisualizationType; typename VisualizationType::Pointer visualizer = VisualizationType::New(); //! \todo the visualizer should get the input image from the level set visualizer->SetInputImage( inputImage ); visualizer->SetLevelSet( levelSet ); - visualizer->SetPeriod( 5 ); std::cout << "Visualizer created" << std::endl; // Create evolution class @@ -145,9 +144,10 @@ VisualizeLevelSetSurface( TInputImage * inputImage, const int numberOfIterations evolution->SetLevelSetContainer( levelSetContainer ); std::cout << "Evolution class created" << std::endl; - typedef typename itk::IterationUpdateCommand< LevelSetEvolutionType, VisualizationType > IterationUpdateCommandType; + typedef typename itk::LevelSetIterationUpdateCommand< LevelSetEvolutionType, VisualizationType > IterationUpdateCommandType; typename IterationUpdateCommandType::Pointer iterationUpdateCommand = IterationUpdateCommandType::New(); iterationUpdateCommand->SetFilterToUpdate( visualizer ); + iterationUpdateCommand->SetUpdatePeriod( 5 ); evolution->AddObserver( itk::IterationEvent(), iterationUpdateCommand ); std::cout << "Visualization IterationUpdateCommand created" << std::endl;