12 #ifndef itkMultiVariableFunctorVectorImageFilter_hxx 13 #define itkMultiVariableFunctorVectorImageFilter_hxx 23 template<
typename TInputImage,
typename TOutputImage,
typename TFunction,
class TMaskImage >
27 this->SetNumberOfRequiredInputs(1);
28 this->SetNumberOfRequiredOutputs(1);
31 template<
typename TInputImage,
typename TOutputImage,
typename TFunction,
class TMaskImage >
37 typename TInputImage::ConstPointer inputImage = this->GetInput();
38 typename TInputImage::Pointer inputTmp = TInputImage::New();
43 utlException(this->m_VectorAxis<0,
"need to set non-negative axis");
45 int numberOfInputs = this->GetNumberOfInputs();
47 std::vector<std::vector<int> > size4d;
48 std::vector<int> dimVec;
49 for (
int i = 0; i < numberOfInputs; ++i )
51 inputTmp->Graft(this->GetInput(i));
53 size4d.push_back(tmpVec);
54 dimVec.push_back(tmpVec[this->m_VectorAxis]);
58 for (
int kk = 0; kk < 4; ++kk )
61 (this->m_VectorAxis)(i)(kk).msg(
"wrong 4d size (x,y,z,t)");
66 std::vector<int> outSize4d = size4d[0];
67 outSize4d[this->m_VectorAxis] = this->m_Functor.GetOutputDimension(dimVec);
72 template<
typename TInputImage,
typename TOutputImage,
typename TFunction,
class TMaskImage >
79 this->VerifyInputParameters();
82 this->CreateLoggerVector();
84 typename TInputImage::ConstPointer inputImage = this->GetInput();
86 this->m_Functor.VerifyInputParameters(size[this->m_VectorAxis]);
87 this->m_Functor.Initialize();
93 template<
typename TInputImage,
typename TOutputImage,
typename TFunction,
class TMaskImage >
97 ThreadIdType threadId)
103 int numberOfInputs = this->GetNumberOfInputs();
107 Pointer selfClone = this->Clone();
108 selfClone->m_ThreadID = threadId;
109 std::string threadIDStr = selfClone->ThreadIDToString();
114 std::vector<VectorImageRegionIteratorWithIndex<InputImageType> > inputItVec;
115 for (
int i = 0; i < numberOfInputs; ++i )
120 inputItVec.push_back(it);
125 if (this->IsMaskUsed())
127 typename MaskImageType::RegionType regionTmp;
135 std::ostringstream msg;
136 msg << threadIDStr <<
"outputRegionForThread = " << outputRegionForThread << std::endl << std::flush;
137 msg << threadIDStr <<
"regionInput = " << regionInput << std::endl << std::flush;
138 this->WriteLogger(msg.str());
143 utlSAGlobalException(maskDim>1 && maskDim!=vecInputSize)(maskDim)(vecInputSize).msg(
"4D mask have a wrong 4-th dimension.");
149 VariableLengthVector<double> inPixel, outPixel, maskPixel;
150 std::vector<utl::Vector<double> > pixelVec(numberOfInputs);
152 outPixel.SetSize(outDim);
155 for (
int n = 0; n < numberOfInputs; n += 1 )
156 inputItVec[n].GoToBegin();
160 while ( !outIt.IsAtEnd() )
163 if (this->IsMaskUsed() && maskDim==1)
166 if (maskPixel.GetSquaredNorm()==0)
169 for (
int i = 0; i < (this->m_VectorAxis==3?1:vecInputSize); ++i )
173 for (
int n = 0; n < numberOfInputs; n += 1 )
181 index = outIt.GetIndex();
183 for (
int i = 0; i < (this->m_VectorAxis==3?1:vecInputSize); ++i )
186 if (this->IsMaskUsed() && maskDim>1)
189 if (maskPixel.GetSquaredNorm()==0)
193 for (
int n = 0; n < numberOfInputs; n += 1 )
201 for (
int n = 0; n < numberOfInputs; ++n )
203 inputItVec[n].GetVector(inPixel, i);
209 std::ostringstream msg;
210 msg <<
"\n" << threadIDStr <<
"index = " << index <<
", i=" << i << std::endl << std::flush;
211 for (
int n = 0; n < numberOfInputs; ++n )
213 this->WriteLogger(msg.str());
216 outVec = selfClone->m_Functor(pixelVec);
221 std::ostringstream msg;
223 this->WriteLogger(msg.str());
228 for (
int n = 0; n < numberOfInputs; n += 1 )
NDArray<T,1> is a vector class which uses blas mkl.
OutputImageType::IndexType OutputImageIndexType
void CopyImageRegion(const ImageRegion< dimIn > ®ionIn, ImageRegion< dimOut > ®ionOut, const int numberOfComponens=-1)
virtual void GenerateOutputInformation() ITK_OVERRIDE
void BeforeThreadedGenerateData() ITK_OVERRIDE
#define utlException(cond, expout)
#define utlSAGlobalException(expr)
void SetVectorImageFullSize(SmartPointer< ImageType > &image, const std::vector< int > &size)
MultiVariableFunctorVectorImageFilter()
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)
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
SmartPointer< Self > Pointer
void GetVector(PixelVectorType &vec, const int offIndex=0) const
int GetVectorImageVectorSize(const SmartPointer< ImageType > &image, const int axis=-1)
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, ThreadIdType threadId) ITK_OVERRIDE
#define itkShowPositionThreadedLogger(cond)
TInputImage InputImageType
void PrintUtlVector(const NDArray< T, 1 > &vec, const std::string &str="", const char *separate=" ", std::ostream &os=std::cout, bool showStats=true)
InputImageType::Pointer InputImagePointer
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