diff --git a/Code/BasicFilters/otbConnectedComponentMuParserFunctor.h b/Code/BasicFilters/otbConnectedComponentMuParserFunctor.h index 2c4b22cd8209d7122a5c592368f63abe63fbe3ff..51bb09e4301bc42f43d53ac0a092f3e84d96bbdb 100644 --- a/Code/BasicFilters/otbConnectedComponentMuParserFunctor.h +++ b/Code/BasicFilters/otbConnectedComponentMuParserFunctor.h @@ -193,7 +193,7 @@ public: return this->m_Parser->GetVar(); } - const mu::funmap_type &GetFunList() const + Parser::FunctionMapType GetFunList() const { return this->m_Parser->GetFunList(); } diff --git a/Code/BasicFilters/otbLabelObjectOpeningMuParserFilter.h b/Code/BasicFilters/otbLabelObjectOpeningMuParserFilter.h index 75c7a6d02ad00d4a8b211db6fa8e89b545e762f4..376b8b8509847e9d51c4d90576b003af68c6f81d 100644 --- a/Code/BasicFilters/otbLabelObjectOpeningMuParserFilter.h +++ b/Code/BasicFilters/otbLabelObjectOpeningMuParserFilter.h @@ -1,28 +1,27 @@ /*========================================================================= - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. - Some parts of this code are derived from ITK. See ITKCopyright.txt - for details. + Some parts of this code are derived from ITK. See ITKCopyright.txt + for details. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. -=========================================================================*/ + =========================================================================*/ #ifndef __otbLabelObjectOpeningMuParserFilter_h #define __otbLabelObjectOpeningMuParserFilter_h - #include "itkProgressReporter.h" #include <iostream> #include <string> @@ -41,6 +40,7 @@ namespace otb { + /** \class LabelObjectOpeningMuParserImageFilter * \brief Label Object opening using shape and radiometric attributes. Acception/rejection * criteria is user defined via MuParser function. @@ -59,83 +59,77 @@ namespace otb * \sa Parser * */ - - -template< class TImage, class TFunction=Functor::OBIAMuParserFunctor< - typename TImage::LabelObjectType > > -class ITK_EXPORT LabelObjectOpeningMuParserFilter : -public itk::InPlaceLabelMapFilter<TImage> +template<class TImage, class TFunction = Functor::OBIAMuParserFunctor<typename TImage::LabelObjectType> > +class ITK_EXPORT LabelObjectOpeningMuParserFilter: public itk::InPlaceLabelMapFilter<TImage> { public: -/** Standard class typedefs. */ -typedef LabelObjectOpeningMuParserFilter Self; -typedef itk::InPlaceLabelMapFilter<TImage> Superclass; -typedef itk::SmartPointer<Self> Pointer; -typedef itk::SmartPointer<const Self> ConstPointer; - -/** Some convenient typedefs. */ -typedef TImage ImageType; -typedef typename ImageType::Pointer ImagePointer; -typedef typename ImageType::ConstPointer ImageConstPointer; -typedef typename ImageType::PixelType PixelType; -typedef typename ImageType::IndexType IndexType; -typedef typename ImageType::RegionType InputImageRegionType; -typedef typename ImageType::LabelObjectType LabelObjectType; -typedef typename LabelObjectType::ConstPointer LabelObjectConstPointer; -typedef TFunction FunctorType; -typedef typename LabelObjectType::AttributeType AttributeType; - -/** ImageDimension constants */ -itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension); + /** Standard class typedefs. */ + typedef LabelObjectOpeningMuParserFilter Self; + typedef itk::InPlaceLabelMapFilter<TImage> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; -/** Standard New method. */ -itkNewMacro(Self); + /** Some convenient typedefs. */ + typedef TImage ImageType; + typedef typename ImageType::Pointer ImagePointer; + typedef typename ImageType::ConstPointer ImageConstPointer; + typedef typename ImageType::PixelType PixelType; + typedef typename ImageType::IndexType IndexType; + typedef typename ImageType::RegionType InputImageRegionType; + typedef typename ImageType::LabelObjectType LabelObjectType; + typedef typename LabelObjectType::ConstPointer LabelObjectConstPointer; + typedef TFunction FunctorType; + typedef typename LabelObjectType::AttributeType AttributeType; -/** Runtime information support. */ -itkTypeMacro(LabelObjectOpeningMuParserFilter, InPlaceLabelMapFilter); + /** ImageDimension constants */ + itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension); -/** Set the expression to be parsed */ -void SetExpression(const std::string expression); + /** Standard New method. */ + itkNewMacro(Self); -/** Return the expression to be parsed */ -std::string GetExpression() const; + /** Runtime information support. */ + itkTypeMacro(LabelObjectOpeningMuParserFilter, InPlaceLabelMapFilter); -/** Check expression to be parsed **/ -bool CheckExpression(); + /** Set the expression to be parsed */ + void SetExpression(const std::string expression); + /** Return the expression to be parsed */ + std::string GetExpression() const; -/** Manual variables setting **/ -void SetAttributes(std::vector<std::string> shapeAttributes, std::vector<std::string> statAttributes, int nbOfBands); + /** Check expression to be parsed **/ + bool CheckExpression(); -/** Display varname and address **/ -void DisplayVar() const; + /** Manual variables setting **/ + void SetAttributes(std::vector<std::string> shapeAttributes, std::vector<std::string> statAttributes, int nbOfBands); -/** return list of Mu Parser variables and address**/ -const std::map<std::string, double*>& GetVar() const; + /** Display varname and address **/ + void DisplayVar() const; -/** return list of Mu Parser functions**/ -const mu::funmap_type& GetFunList() const; + /** return list of Mu Parser variables and address**/ + const std::map<std::string, double*>& GetVar() const; -virtual void AllocateOutputs(); + /** return list of Mu Parser functions**/ + Parser::FunctionMapType GetFunList() const; -void GenerateInputRequestedRegion(); + virtual void AllocateOutputs(); -void EnlargeOutputRequestedRegion(itk::DataObject *){}; + void GenerateInputRequestedRegion(); -void GenerateData(); + void EnlargeOutputRequestedRegion(itk::DataObject *) {} -protected : -LabelObjectOpeningMuParserFilter(); -virtual ~LabelObjectOpeningMuParserFilter(); -virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; + void GenerateData(); +protected: + LabelObjectOpeningMuParserFilter(); + virtual ~LabelObjectOpeningMuParserFilter(); + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; -private : -LabelObjectOpeningMuParserFilter(const Self&); //purposely not implemented -void operator=(const Self&); //purposely not implemented +private: + LabelObjectOpeningMuParserFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented -FunctorType m_Functor; -std::string m_Expression; + FunctorType m_Functor; + std::string m_Expression; }; diff --git a/Code/BasicFilters/otbLabelObjectOpeningMuParserFilter.txx b/Code/BasicFilters/otbLabelObjectOpeningMuParserFilter.txx index 613185cdc0f3e7dab840595a0415ba73f95b1915..b4df469a7c424cb0fa831fbb42d01ff4097982ca 100644 --- a/Code/BasicFilters/otbLabelObjectOpeningMuParserFilter.txx +++ b/Code/BasicFilters/otbLabelObjectOpeningMuParserFilter.txx @@ -1,20 +1,20 @@ /*========================================================================= - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. -=========================================================================*/ + =========================================================================*/ #ifndef __otbLabelObjectOpeningMuParserFilter_txx #define __otbLabelObjectOpeningMuParserFilter_txx @@ -31,63 +31,54 @@ namespace otb { // constructor -template < class TImage, class TFunction> +template<class TImage, class TFunction> LabelObjectOpeningMuParserFilter<TImage, TFunction>::LabelObjectOpeningMuParserFilter() { - // create the output image for the removed objects this->SetNumberOfRequiredOutputs(2); - this->SetNthOutput( 1, static_cast<TImage*>( this->MakeOutput(1).GetPointer() ) ); + this->SetNthOutput(1, static_cast<TImage*> (this->MakeOutput(1).GetPointer())); } // Destructor -template < class TImage, class TFunction> +template<class TImage, class TFunction> LabelObjectOpeningMuParserFilter<TImage, TFunction>::~LabelObjectOpeningMuParserFilter() { - } -template < class TImage, class TFunction> +template<class TImage, class TFunction> void LabelObjectOpeningMuParserFilter<TImage, TFunction>::PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os, indent); - - os << indent << "Expression: " << m_Expression << std::endl; + os << indent << "Expression: " << m_Expression << std::endl; } - -template< class TImage, class TFunction> -void LabelObjectOpeningMuParserFilter<TImage, TFunction> -::SetExpression(const std::string expression) - { - if (m_Expression != expression) - m_Expression = expression; - m_Functor.SetExpression(m_Expression); +template<class TImage, class TFunction> +void LabelObjectOpeningMuParserFilter<TImage, TFunction>::SetExpression(const std::string expression) +{ + if (m_Expression != expression) m_Expression = expression; + m_Functor.SetExpression(m_Expression); this->Modified(); - } +} -template< class TImage, class TFunction> -std::string LabelObjectOpeningMuParserFilter<TImage, TFunction> -::GetExpression() const - { +template<class TImage, class TFunction> +std::string LabelObjectOpeningMuParserFilter<TImage, TFunction>::GetExpression() const +{ return m_Expression; - } - +} -template< class TImage, class TFunction> +template<class TImage, class TFunction> const std::map<std::string, double*>& LabelObjectOpeningMuParserFilter<TImage, TFunction>::GetVar() const { return this->m_Functor.GetVar(); } - -template< class TImage, class TFunction> -const mu::funmap_type& LabelObjectOpeningMuParserFilter<TImage, TFunction>::GetFunList() const +template<class TImage, class TFunction> +Parser::FunctionMapType LabelObjectOpeningMuParserFilter<TImage, TFunction>::GetFunList() const { return this->m_Functor.GetFunList(); } -template< class TImage, class TFunction> +template<class TImage, class TFunction> void LabelObjectOpeningMuParserFilter<TImage, TFunction>::DisplayVar() const { const std::map<std::string, double*>& variables = this->m_Functor.GetVar(); @@ -96,42 +87,43 @@ void LabelObjectOpeningMuParserFilter<TImage, TFunction>::DisplayVar() const std::map<std::string, double*>::const_iterator item = variables.begin(); // Query the variables - for (; item!=variables.end(); ++item) - { + for (; item != variables.end(); ++item) + { std::cout << "Name: " << item->first << " Address: [0x" << item->second << "]\n"; - } + } } -template< class TImage, class TFunction> +template<class TImage, class TFunction> bool LabelObjectOpeningMuParserFilter<TImage, TFunction>::CheckExpression() { return this->m_Functor.CheckExpression(); } -template< class TImage, class TFunction> -void LabelObjectOpeningMuParserFilter<TImage, TFunction>::SetAttributes(std::vector<std::string> shapeAttributes, std::vector<std::string> statAttributes, int nbOfBands) +template<class TImage, class TFunction> +void LabelObjectOpeningMuParserFilter<TImage, TFunction>::SetAttributes(std::vector<std::string> shapeAttributes, + std::vector<std::string> statAttributes, + int nbOfBands) { this->m_Functor.SetAttributes(shapeAttributes, statAttributes, nbOfBands); } /** Get the reduced attribute set */ -template < class TImage, class TFunction> -void LabelObjectOpeningMuParserFilter<TImage, TFunction> -::AllocateOutputs() - { - // if told to run in place and the types support it, - if( this->GetInPlace() && this->CanRunInPlace() ) +template<class TImage, class TFunction> +void LabelObjectOpeningMuParserFilter<TImage, TFunction>::AllocateOutputs() +{ + // if told to run in place and the types support it, + if (this->GetInPlace() && this->CanRunInPlace()) { // Graft this first input to the output. Later, we'll need to // remove the input's hold on the bulk data. // - ImagePointer inputAsOutput = dynamic_cast<TImage *>(const_cast<TImage *>(this->GetInput())); + ImagePointer inputAsOutput = dynamic_cast<TImage *> (const_cast<TImage *> (this->GetInput())); - if( inputAsOutput ) + if (inputAsOutput) { - this->GraftOutput( inputAsOutput ); + this->GraftOutput(inputAsOutput); this->GetOutput()->SetLargestPossibleRegion(this->GetOutput()->GetLargestPossibleRegion()); this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetRequestedRegion()); this->GetOutput()->SetBufferedRegion(this->GetOutput()->GetBufferedRegion()); @@ -139,7 +131,7 @@ void LabelObjectOpeningMuParserFilter<TImage, TFunction> } // If there are more than one outputs, allocate the remaining outputs - for (unsigned int i=1; i < this->GetNumberOfOutputs(); i++) + for (unsigned int i = 1; i < this->GetNumberOfOutputs(); i++) { ImagePointer outputPtr; @@ -157,59 +149,55 @@ void LabelObjectOpeningMuParserFilter<TImage, TFunction> } } - -template < class TImage, class TFunction> +template<class TImage, class TFunction> void LabelObjectOpeningMuParserFilter<TImage, TFunction>::GenerateInputRequestedRegion() { - itk::ImageToImageFilter<TImage, TImage>::GenerateInputRequestedRegion(); + itk::ImageToImageFilter<TImage, TImage>::GenerateInputRequestedRegion(); } - -template < class TImage, class TFunction> +template<class TImage, class TFunction> void LabelObjectOpeningMuParserFilter<TImage, TFunction>::GenerateData() - { - - ImageConstPointer inputPtr = this->GetInput(); - // Allocate the output - this->AllocateOutputs(); +{ - ImageType * output = this->GetOutput(); - ImageType * output2 = this->GetOutput( 1 ); - assert( this->GetNumberOfOutputs() == 2 ); - assert( output2 != NULL ); + ImageConstPointer inputPtr = this->GetInput(); + // Allocate the output + this->AllocateOutputs(); - // set the background value for the second output - this is not done in the superclasses - output2->SetBackgroundValue( output->GetBackgroundValue() ); + ImageType * output = this->GetOutput(); + ImageType * output2 = this->GetOutput(1); + assert( this->GetNumberOfOutputs() == 2 ); + assert( output2 != NULL ); - const typename ImageType::LabelObjectContainerType & labelObjectContainer = output->GetLabelObjectContainer(); + // set the background value for the second output - this is not done in the superclasses + output2->SetBackgroundValue(output->GetBackgroundValue()); - itk::ProgressReporter progress( this, 0, labelObjectContainer.size() ); + const typename ImageType::LabelObjectContainerType & labelObjectContainer = output->GetLabelObjectContainer(); - typename ImageType::LabelObjectContainerType::const_iterator it = labelObjectContainer.begin(); + itk::ProgressReporter progress(this, 0, labelObjectContainer.size()); - while( it != labelObjectContainer.end() ) - { - typename LabelObjectType::LabelType label = it->first; - LabelObjectType * labelObject = it->second; + typename ImageType::LabelObjectContainerType::const_iterator it = labelObjectContainer.begin(); - if( !m_Functor(*labelObject) ) - { - // must increment the iterator before removing the object to avoid invalidating the iterator - it++; - output2->AddLabelObject( labelObject ); - output->RemoveLabel( label ); - } - else - { - it++; - } + while (it != labelObjectContainer.end()) + { + typename LabelObjectType::LabelType label = it->first; + LabelObjectType * labelObject = it->second; - progress.CompletedPixel(); + if (!m_Functor(*labelObject)) + { + // must increment the iterator before removing the object to avoid invalidating the iterator + it++; + output2->AddLabelObject(labelObject); + output->RemoveLabel(label); } - - + else + { + it++; } + progress.CompletedPixel(); + } + +} } // end namespace otb diff --git a/Code/BasicFilters/otbMaskMuParserFilter.h b/Code/BasicFilters/otbMaskMuParserFilter.h index 4ac4f11f9011c7a6d96079aab8ca30d7e30785a0..a7e572289a7c94f419a948153fef9aff3f6f472d 100644 --- a/Code/BasicFilters/otbMaskMuParserFilter.h +++ b/Code/BasicFilters/otbMaskMuParserFilter.h @@ -115,7 +115,7 @@ public: std::vector<std::string> GetVar(); - const mu::funmap_type &GetFunList(); + Parser::FunctionMapType GetFunList(); protected: MaskMuParserFilter(); diff --git a/Code/BasicFilters/otbMaskMuParserFilter.txx b/Code/BasicFilters/otbMaskMuParserFilter.txx index d58ef262f4873f9173615c25b21a4b109dca91e5..9219308e36789f0fd36762c3e99d3c3ea15e31db 100644 --- a/Code/BasicFilters/otbMaskMuParserFilter.txx +++ b/Code/BasicFilters/otbMaskMuParserFilter.txx @@ -83,7 +83,6 @@ std::vector<std::string> MaskMuParserFilter<TInputImage, TOutputImage, TFunction // Run the functor to update the variable list functor(this->GetInput()->GetPixel(this->GetInput()->GetBufferedRegion().GetIndex())); - const std::map<std::string, double*>& varMap = functor.GetVar(); std::map<std::string, double*>::const_iterator it; for (it = varMap.begin(); it != varMap.end(); ++it) @@ -101,7 +100,7 @@ std::vector<std::string> MaskMuParserFilter<TInputImage, TOutputImage, TFunction template<class TInputImage, class TOutputImage, class TFunction> -const mu::funmap_type& MaskMuParserFilter<TInputImage, TOutputImage, TFunction>::GetFunList() +Parser::FunctionMapType MaskMuParserFilter<TInputImage, TOutputImage, TFunction>::GetFunList() { FunctorPointer tempFunctor = FunctorType::New(); tempFunctor->SetExpression(m_Expression); @@ -110,13 +109,11 @@ const mu::funmap_type& MaskMuParserFilter<TInputImage, TOutputImage, TFunction>: try { - functor(this->GetInput()->GetPixel(this->GetInput()->GetBufferedRegion().GetIndex())); - + functor(this->GetInput()->GetPixel(this->GetInput()->GetBufferedRegion().GetIndex())); } catch (itk::ExceptionObject& err) { itkDebugMacro(<< err); - } return functor.GetFunList(); @@ -133,7 +130,6 @@ bool MaskMuParserFilter<TInputImage, TOutputImage, TFunction>::CheckExpression() try { functor(this->GetInput()->GetPixel(this->GetInput()->GetBufferedRegion().GetIndex())); - } catch (itk::ExceptionObject& err) { diff --git a/Code/BasicFilters/otbMaskMuParserFunctor.h b/Code/BasicFilters/otbMaskMuParserFunctor.h index ce2999f8e493aa9b87cedb4c67ae22bf7cb42c94..c022ef5d54efb11b3ad4d10191c9d9f6de1f3c25 100644 --- a/Code/BasicFilters/otbMaskMuParserFunctor.h +++ b/Code/BasicFilters/otbMaskMuParserFunctor.h @@ -82,8 +82,7 @@ public: const std::map<std::string, Parser::ValueType*>& GetVar() const; - const mu::funmap_type& GetFunList() const; - + Parser::FunctionMapType GetFunList() const; void SetExpression(const std::string& expression); diff --git a/Code/BasicFilters/otbMaskMuParserFunctor.txx b/Code/BasicFilters/otbMaskMuParserFunctor.txx index 372a1a0d08b25ece21a2f7a1aa388ef2fd54024e..fd95725afb505b8c0fe1c26d02a18dea6a34d064 100644 --- a/Code/BasicFilters/otbMaskMuParserFunctor.txx +++ b/Code/BasicFilters/otbMaskMuParserFunctor.txx @@ -81,7 +81,7 @@ MaskMuParserFunctor<TInputPixel>::GetVar() const } template<class TInputPixel> -const mu::funmap_type& +Parser::FunctionMapType MaskMuParserFunctor<TInputPixel>::GetFunList() const { return this->m_Parser->GetFunList(); diff --git a/Code/BasicFilters/otbOBIAMuParserFunctor.h b/Code/BasicFilters/otbOBIAMuParserFunctor.h index 24365c276ed65d13d1b0ee3530b8bd8630586678..a3021c09efc02a408795787ed6b2524d837f2c27 100644 --- a/Code/BasicFilters/otbOBIAMuParserFunctor.h +++ b/Code/BasicFilters/otbOBIAMuParserFunctor.h @@ -187,12 +187,12 @@ public: return m_Parser->CheckExpr(); } - const std::map<std::string, Parser::ValueType*>& GetVar() const + const std::map<std::string, Parser::ValueType*>& GetVar() const { return this->m_Parser->GetVar(); } - const mu::funmap_type& GetFunList() const + Parser::FunctionMapType GetFunList() const { return this->m_Parser->GetFunList(); }