-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'JoinFilter' into master+gdWS
- Loading branch information
Showing
8 changed files
with
241 additions
and
67 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,76 @@ | ||
////image filter to set DrawingColor in output image if input pixel equals SeedValue | ||
|
||
#ifndef __itkJoinCopyFilter_cxx | ||
#define __itkJoinCopyFilter_cxx | ||
|
||
#include "itkJoinCopyFilter.h" | ||
#include <itkImageRegionIterator.h> | ||
#include <itkImageRegionConstIterator.h> | ||
#include <itkProgressReporter.h> | ||
|
||
namespace itk{ | ||
|
||
template<typename TInputImage1, typename TInputImage2> | ||
JoinCopyFilter<TInputImage1, TInputImage2> | ||
::JoinCopyFilter(){ | ||
m_SeedActive= false; | ||
m_SeedIndex.Fill(0); | ||
m_SeedValue= NumericTraits<typename TInputImage2::PixelType>::Zero; | ||
} | ||
|
||
template<typename TInputImage1, typename TInputImage2> | ||
void JoinCopyFilter<TInputImage1, TInputImage2> | ||
::SetJsrc(const TInputImage1 *image1){ | ||
this->SetNthInput( 0, const_cast< TInputImage1 * >( image1 ) ); | ||
} | ||
|
||
template<typename TInputImage1, typename TInputImage2> | ||
void JoinCopyFilter<TInputImage1, TInputImage2> | ||
::SetJdst(const TInputImage2 *image2){ | ||
this->SetNthInput( 1, const_cast< TInputImage2 * >( image2 ) ); | ||
} | ||
|
||
|
||
template<typename TInputImage1, typename TInputImage2> | ||
void JoinCopyFilter<TInputImage1, TInputImage2> | ||
::BeforeThreadedGenerateData(){ | ||
|
||
if(m_SeedActive){ | ||
typename TInputImage1::ConstPointer input = dynamic_cast<const TInputImage1 *>( ProcessObject::GetInput(0) ); | ||
m_SeedValue= input->GetPixel(m_SeedIndex); | ||
} | ||
m_UpdateFlag= false; | ||
} | ||
|
||
|
||
template<typename TInputImage1, typename TInputImage2> | ||
void JoinCopyFilter<TInputImage1, TInputImage2> | ||
::ThreadedGenerateData(const typename Superclass::OutputImageRegionType& outputRegionForThread, ThreadIdType threadId){ | ||
|
||
if(m_SeedActive){ | ||
typename TInputImage1::ConstPointer input = dynamic_cast<const TInputImage1 *>( ProcessObject::GetInput(0) ); | ||
typename TInputImage2::Pointer output = this->GetOutput(); | ||
|
||
itk::ImageRegionConstIterator<TInputImage1> iti(input, outputRegionForThread); | ||
itk::ImageRegionIterator<TInputImage2> ito(output, outputRegionForThread); | ||
|
||
// support progress methods/callbacks with 1000 updates | ||
ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels(), 1000); | ||
|
||
while(!iti.IsAtEnd()){ | ||
if(iti.Get() == m_SeedValue){ | ||
ito.Set(m_DrawingColor); | ||
} | ||
++iti; | ||
++ito; | ||
progress.CompletedPixel(); | ||
} | ||
|
||
m_UpdateFlag= true; | ||
m_SeedActive= false; | ||
//output->Modified(); | ||
} | ||
} | ||
}// end namespace | ||
|
||
#endif //__itkJoinCopyFilter_cxx |
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,73 @@ | ||
#ifndef __itkJoinCopyFilter_h | ||
#define __itkJoinCopyFilter_h | ||
|
||
#include <itkInPlaceImageFilter.h> | ||
|
||
namespace itk{ | ||
/** \class JoinCopyFilter | ||
* \brief: sets DrawingColor in output image if input pixel equals SeedValue | ||
* | ||
* \ingroup ImageFilters | ||
*/ | ||
template<typename TInputImage1, typename TInputImage2> | ||
class JoinCopyFilter: | ||
public InPlaceImageFilter<TInputImage2>{ | ||
public: | ||
/** Standard class typedefs. */ | ||
typedef JoinCopyFilter Self; | ||
typedef InPlaceImageFilter<TInputImage2> Superclass; | ||
typedef SmartPointer<Self> Pointer; | ||
typedef SmartPointer< const Self > ConstPointer; | ||
|
||
/** Method for creation through the object factory. */ | ||
itkNewMacro(Self); | ||
|
||
/** Run-time type information (and related methods). */ | ||
itkTypeMacro(JoinCopyFilter, InPlaceImageFilter); | ||
|
||
void SetJsrc(const TInputImage1 *image1); | ||
void SetJdst(const TInputImage2 *image2); | ||
|
||
/** Set/Get SeedIndex value */ | ||
itkSetMacro(SeedIndex, typename TInputImage1::IndexType); | ||
itkGetConstMacro(SeedIndex, typename TInputImage1::IndexType); | ||
|
||
/** Set/Get DrawingColor value */ | ||
itkSetMacro(DrawingColor, typename TInputImage2::ValueType); | ||
itkGetConstMacro(DrawingColor, typename TInputImage2::ValueType); | ||
|
||
/** Get UpdateFlag value */ | ||
itkGetConstMacro(UpdateFlag, bool); | ||
|
||
/** Get/Set SeedActive value */ | ||
itkSetMacro(SeedActive, bool); | ||
itkGetConstMacro(SeedActive, bool); | ||
|
||
protected: | ||
JoinCopyFilter(); | ||
~JoinCopyFilter(){} | ||
|
||
bool m_SeedActive; | ||
typename TInputImage1::IndexType m_SeedIndex; | ||
typename TInputImage1::ValueType m_SeedValue; | ||
typename TInputImage2::ValueType m_DrawingColor; | ||
bool m_UpdateFlag; | ||
|
||
|
||
virtual void BeforeThreadedGenerateData(); | ||
virtual void ThreadedGenerateData(const typename Superclass::OutputImageRegionType& outputRegionForThread, ThreadIdType threadId); | ||
|
||
private: | ||
JoinCopyFilter(const Self &); //purposely not implemented | ||
void operator=(const Self &); //purposely not implemented | ||
|
||
}; | ||
} //namespace ITK | ||
|
||
|
||
#ifndef ITK_MANUAL_INSTANTIATION | ||
#include "itkJoinCopyFilter.cxx" | ||
#endif | ||
|
||
#endif // __itkJoinCopyFilter_h | ||
|
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
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
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