11 #ifndef itkFunctorFromStringImageFilter_hxx 12 #define itkFunctorFromStringImageFilter_hxx 22 template<
typename TInputImage,
typename TOutputImage,
class TMaskImage >
26 this->SetNumberOfRequiredInputs(1);
27 this->SetNumberOfRequiredOutputs(1);
30 template<
typename TInputImage,
typename TOutputImage,
class TMaskImage >
36 typename TInputImage::ConstPointer inputImage = this->GetInput();
37 typename TInputImage::Pointer inputTmp = TInputImage::New();
43 int numberOfInputs = this->GetNumberOfInputs();
45 std::vector<std::vector<int> > size4d;
46 for (
int i = 0; i < numberOfInputs; ++i )
48 inputTmp->Graft(this->GetInput(i));
50 size4d.push_back(tmpVec);
54 for (
int kk = 0; kk < 4; ++kk )
57 (this->m_VectorAxis)(i)(kk).msg(
"wrong 4d size (x,y,z,t)");
63 template<
typename TInputImage,
typename TOutputImage,
class TMaskImage >
70 this->VerifyInputParameters();
73 this->CreateLoggerVector();
75 utlException(this->m_VectorAxis!=3,
"m_VectorAxis should be 3, for element-wise function");
86 template<
typename TInputImage,
typename TOutputImage,
class TMaskImage >
90 ThreadIdType threadId)
96 int numberOfInputs = this->GetNumberOfInputs();
100 Pointer selfClone = this->Clone();
101 selfClone->m_ThreadID = threadId;
102 std::string threadIDStr = selfClone->ThreadIDToString();
104 std::vector<double> x(numberOfInputs);
105 exprtk::symbol_table<double> symbol_table;
106 symbol_table.add_vector(
"x",x);
107 symbol_table.add_constants();
109 exprtk::expression<double> expression;
110 expression.register_symbol_table(symbol_table);
112 exprtk::parser<double> parser;
118 std::vector<VectorImageRegionIteratorWithIndex<InputImageType> > inputItVec;
119 for (
int i = 0; i < numberOfInputs; ++i )
124 inputItVec.push_back(it);
129 if (this->IsMaskUsed())
131 typename MaskImageType::RegionType regionTmp;
139 std::ostringstream msg;
140 msg << threadIDStr <<
"outputRegionForThread = " << outputRegionForThread << std::endl << std::flush;
141 msg << threadIDStr <<
"regionInput = " << regionInput << std::endl << std::flush;
142 this->WriteLogger(msg.str());
147 utlSAGlobalException(maskDim>1 && maskDim!=vecInputSize)(maskDim)(vecInputSize).msg(
"4D mask have a wrong 4-th dimension.");
153 VariableLengthVector<double> inPixel, outPixel, maskPixel;
154 std::vector<utl::Vector<double> > pixelVec(numberOfInputs);
155 std::vector<double> inStdVec(numberOfInputs);
157 outPixel.SetSize(outDim);
160 for (
int n = 0; n < numberOfInputs; n += 1 )
161 inputItVec[n].GoToBegin();
165 while ( !outIt.IsAtEnd() )
168 if (this->IsMaskUsed() && maskDim==1)
171 if (maskPixel.GetSquaredNorm()==0)
174 for (
int i = 0; i < (this->m_VectorAxis==3?1:vecInputSize); ++i )
178 for (
int n = 0; n < numberOfInputs; n += 1 )
186 index = outIt.GetIndex();
188 for (
int i = 0; i < (this->m_VectorAxis==3?1:vecInputSize); ++i )
191 if (this->IsMaskUsed() && maskDim>1)
194 if (maskPixel.GetSquaredNorm()==0)
198 for (
int n = 0; n < numberOfInputs; n += 1 )
206 for (
int n = 0; n < numberOfInputs; ++n )
208 inputItVec[n].GetVector(inPixel, i);
214 std::ostringstream msg;
215 msg <<
"\n" << threadIDStr <<
"index = " << index <<
", i=" << i << std::endl << std::flush;
216 for (
int n = 0; n < numberOfInputs; ++n )
218 this->WriteLogger(msg.str());
221 for (
int v = 0; v < inPixel.Size(); ++v )
223 for (
int n = 0; n < numberOfInputs; n += 1 )
225 inStdVec[n] = pixelVec[n][v];
227 symbol_table.get_vector(
"x")->operator=(inStdVec);
228 parser.compile(m_Expression,expression);
229 outVec[v] = expression.value();
237 std::ostringstream msg;
239 this->WriteLogger(msg.str());
244 for (
int n = 0; n < numberOfInputs; n += 1 )
NDArray<T,1> is a vector class which uses blas mkl.
virtual void GenerateOutputInformation() ITK_OVERRIDE
void CopyImageRegion(const ImageRegion< dimIn > ®ionIn, ImageRegion< dimOut > ®ionOut, const int numberOfComponens=-1)
FunctorFromStringImageFilter()
OutputImageType::IndexType OutputImageIndexType
#define utlException(cond, expout)
#define utlSAGlobalException(expr)
InputImageType::Pointer InputImagePointer
OutputImageType::Pointer OutputImagePointer
OutputImageType::RegionType OutputImageRegionType
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)
InputImageType::RegionType InputImageRegionType
bool IsLogDebug(const int level=utl::LogLevel)
TInputImage InputImageType
std::vector< int > GetVectorImageFullSize(const SmartPointer< ImageType > &image)
void CopyImageInformation(const SmartPointer< ImageWithInfoType > &imageFrom, SmartPointer< ImageType > &imageTo)
NDArray< T, 1 > VariableLengthVectorToUtlVector(const itk::VariableLengthVector< T > &vec)
SmartPointer< Self > Pointer
void BeforeThreadedGenerateData() ITK_OVERRIDE
void GetVector(PixelVectorType &vec, const int offIndex=0) const
int GetVectorImageVectorSize(const SmartPointer< ImageType > &image, const int axis=-1)
#define itkShowPositionThreadedLogger(cond)
void PrintUtlVector(const NDArray< T, 1 > &vec, const std::string &str="", const char *separate=" ", std::ostream &os=std::cout, bool showStats=true)
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
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, ThreadIdType threadId) ITK_OVERRIDE