12 #ifndef itkUnaryFunctorVectorImageFilter_hxx 13 #define itkUnaryFunctorVectorImageFilter_hxx 22 template<
typename TInputImage,
typename TOutputImage,
typename TFunction,
class TMaskImage >
26 this->SetNumberOfRequiredInputs(1);
27 this->SetNumberOfRequiredOutputs(1);
30 template<
typename TInputImage,
typename TOutputImage,
typename TFunction,
class TMaskImage >
36 typename TInputImage::ConstPointer inputImage = this->GetInput();
41 utlException(this->m_VectorAxis<0,
"need to set non-negative axis");
44 int outVectorSize = this->m_Functor.GetOutputDimension(vecInputSize);
45 int outDim= (this->m_VectorAxis==3) ? outVectorSize : vecInputSize;
46 if (this->m_VectorAxis!=3)
50 sizeTmp[this->m_VectorAxis] = this->m_Functor.GetOutputDimension(sizeTmp[this->m_VectorAxis]);
51 regionTmp.SetSize(sizeTmp);
52 outImage->SetRegions(regionTmp);
58 template<
typename TInputImage,
typename TOutputImage,
typename TFunction,
class TMaskImage >
65 this->VerifyInputParameters();
68 this->CreateLoggerVector();
70 typename TInputImage::ConstPointer inputImage = this->GetInput();
72 this->m_Functor.VerifyInputParameters(size[this->m_VectorAxis]);
73 this->m_Functor.Initialize();
79 template<
typename TInputImage,
typename TOutputImage,
typename TFunction,
class TMaskImage >
83 ThreadIdType threadId)
89 Pointer selfClone = this->Clone();
90 selfClone->m_ThreadID = threadId;
91 std::string threadIDStr = selfClone->ThreadIDToString();
100 std::ostringstream msg;
101 selfClone->Print(msg<< threadIDStr <<
"selfClone = \n");
102 this->WriteLogger(msg.str());
107 if (this->IsMaskUsed())
109 typename MaskImageType::RegionType regionTmp;
117 utlSAGlobalException(maskDim>1 && maskDim!=vecInputSize)(maskDim)(vecInputSize).msg(
"4D mask have a wrong 4-th dimension.");
122 VariableLengthVector<double> inPixel, outPixel, maskPixel;
124 outPixel.SetSize(outDim);
126 for (it.GoToBegin(), maskIt.GoToBegin(), outIt.GoToBegin();
128 ++it, ++maskIt, ++outIt)
131 if (this->IsMaskUsed() && maskDim==1)
133 maskIt.GetVector(maskPixel,0);
134 if (maskPixel.GetSquaredNorm()==0)
137 for (
int i = 0; i < (this->m_VectorAxis==3?1:vecInputSize); ++i )
145 index = it.GetIndex();
150 for (
int i = 0; i < (this->m_VectorAxis==3?1:vecInputSize); ++i )
153 if (this->IsMaskUsed() && maskDim>1)
156 if (maskPixel.GetSquaredNorm()==0)
169 std::ostringstream msg;
170 msg <<
"\n" << threadIDStr <<
"index = " << index << std::endl << std::flush;
172 this->WriteLogger(msg.str());
175 outVec = selfClone->m_Functor(inVec);
180 std::ostringstream msg;
182 this->WriteLogger(msg.str());
NDArray<T,1> is a vector class which uses blas mkl.
void CopyImageRegion(const ImageRegion< dimIn > ®ionIn, ImageRegion< dimOut > ®ionOut, const int numberOfComponens=-1)
void SetVectorImageVectorSize(const SmartPointer< ImageType > &image, const int vecsize)
UnaryFunctorVectorImageFilter()
used for debug information. this->GetDebug()
#define utlException(cond, expout)
#define utlSAGlobalException(expr)
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, ThreadIdType threadId) ITK_OVERRIDE
InputImageType::IndexType InputImageIndexType
itk::VariableLengthVector< T > UtlVectorToVariableLengthVector(const NDArray< T, 1 > &vec)
void PrintVariableLengthVector(const VariableLengthVector< T >vec, const std::string &str="", const char *separate=" ", std::ostream &os=std::cout)
void BeforeThreadedGenerateData() ITK_OVERRIDE
bool IsLogDebug(const int level=utl::LogLevel)
std::vector< int > GetVectorImageFullSize(const SmartPointer< ImageType > &image)
void CopyImageInformation(const SmartPointer< ImageWithInfoType > &imageFrom, SmartPointer< ImageType > &imageTo)
OutputImageType::RegionType OutputImageRegionType
NDArray< T, 1 > VariableLengthVectorToUtlVector(const itk::VariableLengthVector< T > &vec)
InputImageType::RegionType InputImageRegionType
#define utlSAException(expr)
SmartPointer< Self > Pointer
void GetVector(PixelVectorType &vec, const int offIndex=0) const
int GetVectorImageVectorSize(const SmartPointer< ImageType > &image, const int axis=-1)
#define utlVLogPosition(level)
#define itkShowPositionThreadedLogger(cond)
virtual void GenerateOutputInformation() ITK_OVERRIDE
TInputImage InputImageType
InputImageType::Pointer InputImagePointer
OutputImageType::SizeType OutputImageSizeType
A multi-dimensional iterator templated over image type. It provides the same interfaces for both itk:...
void SetVector(const PixelVectorType &value, const int offIndex=0) const
OutputImageType::Pointer OutputImagePointer