From 8dc0e32c86fc943b4a69e1c3b45d36821b129e49 Mon Sep 17 00:00:00 2001 From: Stephane Albert <stephane.albert@c-s.fr> Date: Mon, 18 Aug 2014 12:32:30 +0200 Subject: [PATCH] ENH: Removed duplicate StreamingHistogramVectorImageFilter from MVD2 and used one from OTB. --- Code/Common/Core/mvdHistogramModel.h | 2 +- .../mvdStreamingHistogramVectorImageFilter.h | 280 -------------- ...mvdStreamingHistogramVectorImageFilter.txx | 341 ------------------ Code/Common/Gui/mvdTreeWidgetItem.cxx | 7 + 4 files changed, 8 insertions(+), 622 deletions(-) delete mode 100644 Code/Common/Core/mvdStreamingHistogramVectorImageFilter.h delete mode 100644 Code/Common/Core/mvdStreamingHistogramVectorImageFilter.txx diff --git a/Code/Common/Core/mvdHistogramModel.h b/Code/Common/Core/mvdHistogramModel.h index efa45868d4..a7a4f4903b 100644 --- a/Code/Common/Core/mvdHistogramModel.h +++ b/Code/Common/Core/mvdHistogramModel.h @@ -275,13 +275,13 @@ private slots: // // OTB includes (sorted by alphabetic order) +#include "otbStreamingHistogramVectorImageFilter.h" #include "otbStreamingMinMaxVectorImageFilter.h" #include "otbStreamingStatisticsVectorImageFilter.h" // // Monteverdi includes (sorted by alphabetic order) #include "Core/mvdAbstractImageModel.h" -#include "Core/mvdStreamingHistogramVectorImageFilter.h" namespace mvd { diff --git a/Code/Common/Core/mvdStreamingHistogramVectorImageFilter.h b/Code/Common/Core/mvdStreamingHistogramVectorImageFilter.h deleted file mode 100644 index f8a064c698..0000000000 --- a/Code/Common/Core/mvdStreamingHistogramVectorImageFilter.h +++ /dev/null @@ -1,280 +0,0 @@ -/*========================================================================= - - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - 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. - - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANT2ABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __otbStreamingHistogramVectorImageFilter_h -#define __otbStreamingHistogramVectorImageFilter_h - -#include "otbPersistentImageFilter.h" -#include "otbPersistentFilterStreamingDecorator.h" - -#include "otbObjectList.h" -#include "itkStatisticsAlgorithm.h" -#include "itkDenseFrequencyContainer2.h" -#include "itkNumericTraits.h" -#include "itkHistogram.h" - -namespace otb -{ - -/** \class PersistentHistogramVectorImageFilter - * \brief Compute the histogram of a large image using streaming - * - * This filter persists its temporary data. It means that if you Update it n times on n different - * requested regions, the output statistics will be the statitics of the whole set of n regions. - * - * To reset the temporary data, one should call the Reset() function. - * - * To get the statistics once the regions have been processed via the pipeline, use the Synthetize() method. - * - * \sa PersistentImageFilter - * \ingroup Streamed - * \ingroup Multithreaded - * \ingroup MathematicalStatisticsImageFilters - * - */ -template<class TInputImage> -class ITK_EXPORT PersistentHistogramVectorImageFilter : - public PersistentImageFilter<TInputImage, TInputImage> -{ -public: - /** Standard Self typedef */ - typedef PersistentHistogramVectorImageFilter Self; - typedef PersistentImageFilter<TInputImage, TInputImage> Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** Runtime information support. */ - itkTypeMacro(PersistentHistogramVectorImageFilter, PersistentImageFilter); - - /** Image related typedefs. */ - typedef TInputImage ImageType; - typedef typename TInputImage::Pointer InputImagePointer; - typedef typename TInputImage::RegionType RegionType; - typedef typename TInputImage::SizeType SizeType; - typedef typename TInputImage::IndexType IndexType; - typedef typename TInputImage::PixelType PixelType; - typedef typename TInputImage::InternalPixelType InternalPixelType; - - itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension); - - /** Image related typedefs. */ - itkStaticConstMacro(ImageDimension, unsigned int, TInputImage::ImageDimension); - - /** Type to use for computations. */ - typedef typename itk::NumericTraits<InternalPixelType>::RealType RealType; - typedef itk::VariableLengthVector<RealType> RealPixelType; - - /** Smart Pointer type to a DataObject. */ - typedef typename itk::DataObject::Pointer DataObjectPointer; - - /** Types for histogram */ - typedef itk::Statistics::DenseFrequencyContainer2 DFContainerType; - - typedef - typename itk::NumericTraits<InternalPixelType>::RealType - HistogramMeasurementRealType; - - typedef - itk::Statistics::Histogram<HistogramMeasurementRealType, DFContainerType> - HistogramType; - - typedef itk::VariableLengthVector< unsigned int > CountVectorType; - - typedef PixelType MeasurementVectorType; - typedef ObjectList<HistogramType> HistogramListType; - typedef typename HistogramListType::Pointer HistogramListPointerType; - typedef typename std::vector<HistogramListPointerType> ArrayHistogramListType; - - - /** Set the no data value. These value are ignored in histogram - * computation if NoDataFlag is On - */ - itkSetMacro(NoDataValue, InternalPixelType); - - /** Set the no data value. These value are ignored in histogram - * computation if NoDataFlag is On - */ - itkGetConstReferenceMacro(NoDataValue, InternalPixelType); - - /** Set the NoDataFlag. If set to true, samples with values equal to - * m_NoDataValue are ignored. - */ - itkSetMacro(NoDataFlag, bool); - - /** Get the NoDataFlag. If set to true, samples with values equal to - * m_NoDataValue are ignored. - */ - itkGetMacro(NoDataFlag, bool); - - /** Toggle the NoDataFlag. If set to true, samples with values equal to - * m_NoDataValue are ignored. - */ - itkBooleanMacro(NoDataFlag); - - inline void SetNumberOfBins( unsigned int i, CountVectorType::ValueType size ) - { - m_Size[ i ] = size; - } - - inline void SetNumberOfBins( const CountVectorType& size ) - { - m_Size = size; - } - - /** Return the computed histogram list */ - HistogramListType* GetHistogramListOutput(); - const HistogramListType* GetHistogramListOutput() const; - - /** Get the minimum values for histograms */ - itkGetConstReferenceMacro(HistogramMin,MeasurementVectorType); - - /** Set the minimum values for histograms */ - itkSetMacro(HistogramMin,MeasurementVectorType); - - /** Get the maximum values for histograms */ - itkGetConstReferenceMacro(HistogramMax,MeasurementVectorType); - - /** Set the maximum values for histograms */ - itkSetMacro(HistogramMax,MeasurementVectorType); - - /** Set the subsampling rate */ - itkSetMacro(SubSamplingRate, unsigned int); - - /** Get the subsampling rate */ - itkGetMacro(SubSamplingRate, unsigned int); - - /** Make a DataObject of the correct type to be used as the specified - * output. - */ - virtual DataObjectPointer MakeOutput(unsigned int idx); - - /** Pass the input through unmodified. Do this by Grafting in the - * AllocateOutputs method. - */ - virtual void AllocateOutputs(); - virtual void GenerateOutputInformation(); - virtual void Synthetize(void); - virtual void Reset(void); - -protected: - PersistentHistogramVectorImageFilter(); - virtual ~PersistentHistogramVectorImageFilter() {} - virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; - /** Multi-thread version GenerateData. */ - void ThreadedGenerateData(const RegionType& outputRegionForThread, itk::ThreadIdType threadId); - -private: - PersistentHistogramVectorImageFilter(const Self &); //purposely not implemented - void operator =(const Self&); //purposely not implemented - - ArrayHistogramListType m_ThreadHistogramList; - CountVectorType m_Size; - MeasurementVectorType m_HistogramMin; - MeasurementVectorType m_HistogramMax; - bool m_NoDataFlag; - InternalPixelType m_NoDataValue; - - /** Set the subsampling along each direction */ - unsigned int m_SubSamplingRate; - -}; // end of class PersistentStatisticsVectorImageFilter - -/**===========================================================================*/ - -/** \class StreamingHistogramVectorImageFilter - * \brief This class streams the whole input image through the PersistentHistogramVectorImageFilter. - * - * This way, it allows to compute the min/max of this image. It calls the - * Reset() method of the PersistentHistogramVectorImageFilter before streaming the image and the - * Synthetize() method of the PersistentHistogramVectorImageFilter after having streamed the image - * to compute the statistics. The accessor on the results are wrapping the accessors of the - * internal PersistentMinMaxImageFilter. - * - * \sa PersistentStatisticsVectorImageFilter - * \sa PersistentImageFilter - * \sa PersistentFilterStreamingDecorator - * \sa StreamingImageVirtualWriter - * \ingroup Streamed - * \ingroup Multithreaded - * \ingroup MathematicalStatisticsImageFilters - */ - -template<class TInputImage> -class ITK_EXPORT StreamingHistogramVectorImageFilter : - public PersistentFilterStreamingDecorator<PersistentHistogramVectorImageFilter<TInputImage> > -{ -public: - /** Standard Self typedef */ - typedef StreamingHistogramVectorImageFilter Self; - typedef PersistentFilterStreamingDecorator - <PersistentHistogramVectorImageFilter<TInputImage> > Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - /** Type macro */ - itkNewMacro(Self); - - /** Creation through object factory macro */ - itkTypeMacro(StreamingHistogramVectorImageFilter, PersistentFilterStreamingDecorator); - - typedef TInputImage InputImageType; - typedef typename Superclass::FilterType InternalFilterType; - - /** Types needed for histograms */ - typedef typename InternalFilterType::HistogramType HistogramType; - typedef typename InternalFilterType::HistogramListType HistogramListType; - - void SetInput(InputImageType * input) - { - this->GetFilter()->SetInput(input); - } - const InputImageType * GetInput() - { - return this->GetFilter()->GetInput(); - } - - /** Return the computed histogram */ - HistogramListType* GetHistogramList() - { - return this->GetFilter()->GetHistogramListOutput(); - } - - -protected: - /** Constructor */ - StreamingHistogramVectorImageFilter() {}; - /** Destructor */ - virtual ~StreamingHistogramVectorImageFilter() {} - -private: - StreamingHistogramVectorImageFilter(const Self &); //purposely not implemented - void operator =(const Self&); //purposely not implemented -}; - -} // end namespace otb - -#ifndef OTB_MANUAL_INSTANTIATION -#include "mvdStreamingHistogramVectorImageFilter.txx" -#endif - -#endif diff --git a/Code/Common/Core/mvdStreamingHistogramVectorImageFilter.txx b/Code/Common/Core/mvdStreamingHistogramVectorImageFilter.txx deleted file mode 100644 index fb069384e2..0000000000 --- a/Code/Common/Core/mvdStreamingHistogramVectorImageFilter.txx +++ /dev/null @@ -1,341 +0,0 @@ -/*========================================================================= - - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - 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. - - - 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 __otbStreamingHistogramVectorImageFilter_txx -#define __otbStreamingHistogramVectorImageFilter_txx -#include "Core/mvdStreamingHistogramVectorImageFilter.h" - -#include "itkImageRegionIterator.h" -#include "itkImageRegionConstIteratorWithIndex.h" -#include "itkNumericTraits.h" -#include "itkProgressReporter.h" -#include "otbMacro.h" - -namespace otb -{ - -template<class TInputImage> -PersistentHistogramVectorImageFilter<TInputImage> -::PersistentHistogramVectorImageFilter() : - m_ThreadHistogramList(), - m_Size(), - m_HistogramMin(), - m_HistogramMax(), - m_NoDataFlag(false), - m_NoDataValue(itk::NumericTraits<InternalPixelType>::Zero), - m_SubSamplingRate(1) -{ - // first output is a copy of the image, DataObject created by - // superclass - // - // allocate the data objects for the outputs which are - // just decorators around pixel types and histogram list - - m_Size.Fill(255); - - HistogramListPointerType output = static_cast<HistogramListType*>(this->MakeOutput(1).GetPointer()); - this->itk::ProcessObject::SetNthOutput(1, output.GetPointer()); -} - -template<class TInputImage> -itk::DataObject::Pointer -PersistentHistogramVectorImageFilter<TInputImage> -::MakeOutput(unsigned int output) -{ - itk::DataObject::Pointer ret; - switch (output) - { - case 0: - ret = static_cast<itk::DataObject*>(TInputImage::New().GetPointer()); - break; - case 1: - ret = static_cast<itk::DataObject*>(HistogramListType::New().GetPointer()); - break; - } - return ret; -} - -template<class TInputImage> -typename PersistentHistogramVectorImageFilter<TInputImage>::HistogramListType* -PersistentHistogramVectorImageFilter<TInputImage> -::GetHistogramListOutput() -{ - return static_cast<HistogramListType*>(this->itk::ProcessObject::GetOutput(1)); -} - -template<class TInputImage> -const typename PersistentHistogramVectorImageFilter<TInputImage>::HistogramListType* -PersistentHistogramVectorImageFilter<TInputImage> -::GetHistogramListOutput() const -{ - return static_cast<const HistogramListType*>(this->itk::ProcessObject::GetOutput(1)); -} - -template<class TInputImage> -void -PersistentHistogramVectorImageFilter<TInputImage> -::GenerateOutputInformation() -{ - Superclass::GenerateOutputInformation(); - if (this->GetInput()) - { - this->GetOutput()->CopyInformation(this->GetInput()); - this->GetOutput()->SetLargestPossibleRegion(this->GetInput()->GetLargestPossibleRegion()); - - if (this->GetOutput()->GetRequestedRegion().GetNumberOfPixels() == 0) - { - this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetLargestPossibleRegion()); - } - } -} - -template<class TInputImage> -void -PersistentHistogramVectorImageFilter<TInputImage> -::AllocateOutputs() -{ - // This is commented to prevent the streaming of the whole image for the first stream strip - // It shall not cause any problem because the output image of this filter is not intended to be used. - //InputImagePointer image = const_cast< TInputImage * >( this->GetInput() ); - //this->GraftOutput( image ); - // Nothing that needs to be allocated for the remaining outputs -} - -template<class TInputImage> -void -PersistentHistogramVectorImageFilter<TInputImage> -::Reset() -{ - TInputImage * inputPtr = const_cast<TInputImage *>(this->GetInput()); - inputPtr->UpdateOutputInformation(); - - unsigned int numberOfThreads = this->GetNumberOfThreads(); - unsigned int numberOfComponent = inputPtr->GetNumberOfComponentsPerPixel(); - - bool clipBins = false; - - // if histogram Min and Max have the wrong size : set to default [0, 255] - if (m_HistogramMin.Size() != numberOfComponent || - m_HistogramMax.Size() != numberOfComponent) - { - m_HistogramMin.SetSize(numberOfComponent); - m_HistogramMax.SetSize(numberOfComponent); - - m_HistogramMin.Fill(itk::NumericTraits<InternalPixelType>::Zero); - m_HistogramMax.Fill(255); - } - - // Setup output histogram - HistogramListType* outputHisto = this->GetHistogramListOutput(); - outputHisto->Clear(); - for (unsigned int k=0; k<numberOfComponent; ++k) - { - typename HistogramType::MeasurementVectorType bandMin, bandMax; - bandMin.SetSize(1); - bandMax.SetSize(1); - bandMin.Fill(m_HistogramMin[k]); - bandMax.Fill(m_HistogramMax[k]); - - typename HistogramType::Pointer histogram = HistogramType::New(); - histogram->SetClipBinsAtEnds(clipBins); - - typename HistogramType::SizeType size; - size.SetSize(1); - size.Fill( m_Size[ k ] ); - histogram->SetMeasurementVectorSize(1); - histogram->Initialize( size, bandMin, bandMax ); - - outputHisto->PushBack(histogram); - } - - - // Setup HistogramLists for each thread - m_ThreadHistogramList.clear(); - for (unsigned int i=0; i<numberOfThreads; ++i) - { - HistogramListPointerType histoList = HistogramListType::New(); - histoList->Clear(); - for (unsigned int k=0; k<numberOfComponent; ++k) - { - typename HistogramType::MeasurementVectorType bandMin, bandMax; - bandMin.SetSize(1); - bandMax.SetSize(1); - bandMin.Fill(m_HistogramMin[k]); - bandMax.Fill(m_HistogramMax[k]); - - typename HistogramType::Pointer histogram = HistogramType::New(); - histogram->SetClipBinsAtEnds(clipBins); - - typename HistogramType::SizeType size; - size.SetSize(1); - size.Fill( m_Size[ k ] ); - histogram->SetMeasurementVectorSize(1); - histogram->Initialize(size, bandMin, bandMax ); - - histoList->PushBack(histogram); - } - m_ThreadHistogramList.push_back(histoList); - } - -} - -template<class TInputImage> -void -PersistentHistogramVectorImageFilter<TInputImage> -::Synthetize() -{ - HistogramListType* outputHisto = this->GetHistogramListOutput(); - - int numberOfThreads = this->GetNumberOfThreads(); - unsigned int numberOfComponent = this->GetInput()->GetNumberOfComponentsPerPixel(); - - // copy histograms to output - for (int i = 0; i < numberOfThreads; ++i) - { - for (unsigned int j = 0; j < numberOfComponent; ++j) - { - HistogramType* outHisto = outputHisto->GetNthElement(j); - HistogramType* threadHisto = m_ThreadHistogramList[i]->GetNthElement(j); - - typename HistogramType::Iterator iterOutput = outHisto->Begin(); - typename HistogramType::Iterator iterThread = threadHisto->Begin(); - - while (iterOutput != outHisto->End() && iterThread != threadHisto->End()) - { - iterOutput.SetFrequency(iterOutput.GetFrequency()+iterThread.GetFrequency()); - - ++iterOutput; - ++iterThread; - } - } - } -} - -template<class TInputImage> -void -PersistentHistogramVectorImageFilter<TInputImage> -::ThreadedGenerateData(const RegionType& outputRegionForThread, itk::ThreadIdType threadId) -{ - /** - * Grab the input - */ - InputImagePointer inputPtr = const_cast<TInputImage *>(this->GetInput()); - // support progress methods/callbacks - itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels()); - - typename HistogramType::IndexType index; - - itk::ImageRegionConstIteratorWithIndex<TInputImage> it(inputPtr, outputRegionForThread); - it.GoToBegin(); - - bool skipSample = false; - - // do the work - while (!it.IsAtEnd()) - { - if (m_SubSamplingRate > 1) - { - skipSample = false; - for (unsigned int i=0; i<InputImageDimension; ++i) - { - if (it.GetIndex()[i] % m_SubSamplingRate != 0) - { - skipSample = true; - break; - } - } - if (skipSample) - { - ++it; - progress.CompletedPixel(); - continue; - } - } - - PixelType vectorValue = it.Get(); - - bool skipSampleNoData=false; - if(m_NoDataFlag) - { - unsigned int itComp=0; - while( itComp < vectorValue.GetSize() ) - { - if (vectorValue[itComp]==m_NoDataValue) - { - skipSampleNoData=true; - itComp++; - } - else - { - skipSampleNoData=false; - break; - } - } - } - - if( !skipSampleNoData ) - { - for (unsigned int j = 0; j < vectorValue.GetSize(); ++j) - { - typename HistogramType::MeasurementVectorType value; - value.SetSize(1); - value.Fill(vectorValue[j]); - - m_ThreadHistogramList[threadId]->GetNthElement(j)->GetIndex(value, index); - if (!m_ThreadHistogramList[threadId]->GetNthElement(j)->IsIndexOutOfBounds(index)) - { - // if the measurement vector is out of bound then - // the GetIndex method has returned an index set to the max size of - // the invalid dimension - even if the hvector is less than the minimum - // bin value. - // If the index isn't valid, we don't increase the frequency. - // See the comments in Histogram->GetIndex() for more info. - m_ThreadHistogramList[threadId]->GetNthElement(j)->IncreaseFrequencyOfIndex(index, 1); - } - } - } - ++it; - progress.CompletedPixel(); - } -} - -template <class TImage> -void -PersistentHistogramVectorImageFilter<TImage> -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); - - os << indent << "Histogram minimum: " << this->GetHistogramMin() << std::endl; - os << indent << "Histogram maximum: " << this->GetHistogramMax() << std::endl; - os << indent << "Number of bins: " << m_Size[0] << std::endl; - if (m_NoDataFlag) - { - os << indent << "Use NoData: true" << std::endl; - } - else - { - os << indent << "Use NoData: false" << std::endl; - } - os << indent << "NoData value: " << this->GetNoDataValue() << std::endl; -} - -} // end namespace otb -#endif diff --git a/Code/Common/Gui/mvdTreeWidgetItem.cxx b/Code/Common/Gui/mvdTreeWidgetItem.cxx index cd547986ab..c8d7b6d59c 100644 --- a/Code/Common/Gui/mvdTreeWidgetItem.cxx +++ b/Code/Common/Gui/mvdTreeWidgetItem.cxx @@ -72,8 +72,15 @@ TreeWidgetItem const QVariant& id, const QStringList& columns, TreeWidgetItem::ItemType type ) : +#if 1 + QTreeWidgetItem( QStringList( text ) << QString() << columns, type ) +#else QTreeWidgetItem( parent, QStringList( text ) << QString() << columns, type ) +#endif { + assert( parent!=NULL ); + parent->addChild( this ); + SetId( id ); switch( type ) -- GitLab