diff --git a/Code/BasicFilters/otbImageToPointSetFilter.h b/Code/BasicFilters/otbImageToPointSetFilter.h index 06843f317008e9a498402b538244e79c6c499e7e..44437862379b972900d4d5095aa4097142d81cd8 100644 --- a/Code/BasicFilters/otbImageToPointSetFilter.h +++ b/Code/BasicFilters/otbImageToPointSetFilter.h @@ -57,10 +57,11 @@ public: TInputImage::ImageDimension); /** Some PointSet related typedefs. */ - typedef typename Superclass::OutputPointSetType OutputPointSetType; - typedef typename Superclass::OutputPointSetPointer OutputPointSetPointer; - typedef typename Superclass::PointsContainerType PointsContainerType; - typedef itk::ProcessObject ProcessObjectType; + typedef typename Superclass::OutputPointSetType OutputPointSetType; + typedef typename Superclass::OutputPointSetPointer OutputPointSetPointer; + typedef typename Superclass::PointsContainerType PointsContainerType; + typedef typename Superclass::PointDataContainerType PointDataContainerType; + typedef itk::ProcessObject ProcessObjectType; /** Set the input image of this process object. */ void SetInput(unsigned int idx, const InputImageType *input); @@ -82,7 +83,8 @@ protected: /** Multi-threading implementation */ - typedef std::vector<typename OutputPointSetType::PointsContainer::Pointer> OutputPointsContainerForThreadType; + typedef std::vector<typename OutputPointSetType::PointsContainer::Pointer> OutputPointsContainerForThreadType; + typedef std::vector<typename OutputPointSetType::PointDataContainer::Pointer> OutputPointDataContainerForThreadType; virtual void BeforeThreadedGenerateData(); @@ -103,7 +105,8 @@ protected: Pointer Filter; }; - OutputPointsContainerForThreadType m_PointsContainerPerThread; + OutputPointsContainerForThreadType m_PointsContainerPerThread; + OutputPointDataContainerForThreadType m_PointDataContainerPerThread; /** End Multi-threading implementation */ diff --git a/Code/BasicFilters/otbImageToPointSetFilter.txx b/Code/BasicFilters/otbImageToPointSetFilter.txx index 16d8baf457644c03988e02f83b4103414b38c324..56cb5ef0760e0cebb32ffcee44cc16b8ee9c45ad 100644 --- a/Code/BasicFilters/otbImageToPointSetFilter.txx +++ b/Code/BasicFilters/otbImageToPointSetFilter.txx @@ -38,6 +38,9 @@ ImageToPointSetFilter<TInputImage, TOutputPointSet> ProcessObjectType::SetNumberOfRequiredOutputs(1); ProcessObjectType::SetNthOutput(0, output.GetPointer()); + m_PointsContainerPerThread.clear(); + m_PointDataContainerPerThread.clear(); + // create default region splitter m_RegionSplitter = itk::ImageRegionSplitter<itkGetStaticConstMacro(InputImageDimension)>::New(); @@ -133,6 +136,9 @@ ImageToPointSetFilter<TInputImage, TOutputPointSet> PointsContainerType * outputPointsContainer = this->GetOutput()->GetPoints(); outputPointsContainer->Initialize(); + PointDataContainerType * outputPointDataContainer = this->GetOutput()->GetPointData(); + outputPointDataContainer->Initialize(); + typename TInputImage::RegionType inputRegion = this->GetInput()->GetLargestPossibleRegion(); unsigned int numDivisions; @@ -180,6 +186,10 @@ ImageToPointSetFilter<TInputImage, TOutputPointSet> this->m_PointsContainerPerThread = OutputPointsContainerForThreadType(this->GetNumberOfThreads(), defaultPointsContainer); + typename PointDataContainerType::Pointer defaultPointDataContainer = PointDataContainerType::New(); + this->m_PointDataContainerPerThread + = OutputPointDataContainerForThreadType(this->GetNumberOfThreads(), defaultPointDataContainer); + // Setting up multithreader this->GetMultiThreader()->SetNumberOfThreads(this->GetNumberOfThreads()); this->GetMultiThreader()->SetSingleMethod(this->ThreaderCallback, &str); @@ -224,6 +234,21 @@ ImageToPointSetFilter<TInputImage, TOutputPointSet> } } + PointDataContainerType * outputPointDataContainer = this->GetOutput()->GetPointData(); + + typedef typename PointDataContainerType::ConstIterator OutputPointDataContainerIterator; + for (unsigned int i = 0; i < this->m_PointDataContainerPerThread.size(); ++i) + { + if (this->m_PointDataContainerPerThread[i].IsNotNull()) + { + for (OutputPointDataContainerIterator it = this->m_PointDataContainerPerThread[i]->Begin(); + it != this->m_PointDataContainerPerThread[i]->End(); + ++it) + { + outputPointDataContainer->push_back(it.Value()); + } + } + } } template <class TInputImage, class TOutputPointSet> diff --git a/Code/Common/otbPointSetSource.h b/Code/Common/otbPointSetSource.h index f3b15a6e6bd6431e6c6b5d03abd0dae584c58cb4..a0157133fc37a1fa6ec27480abf56ba56877bc2e 100644 --- a/Code/Common/otbPointSetSource.h +++ b/Code/Common/otbPointSetSource.h @@ -55,10 +55,11 @@ public: itkTypeMacro(PointSetSource, itk::ProcessObject); /** Some convenient typedefs. */ - typedef itk::DataObject::Pointer DataObjectPointer; - typedef TOutputPointSet OutputPointSetType; - typedef typename OutputPointSetType::Pointer OutputPointSetPointer; - typedef typename OutputPointSetType::PointsContainer PointsContainerType; + typedef itk::DataObject::Pointer DataObjectPointer; + typedef TOutputPointSet OutputPointSetType; + typedef typename OutputPointSetType::Pointer OutputPointSetPointer; + typedef typename OutputPointSetType::PointsContainer PointsContainerType; + typedef typename OutputPointSetType::PointDataContainer PointDataContainerType; /** Get the point set output of this process object. */ OutputPointSetType * GetOutput(void); diff --git a/Code/FeatureExtraction/otbThresholdImageToPointSetFilter.h b/Code/FeatureExtraction/otbThresholdImageToPointSetFilter.h index acd3063b902f51a4e6209265b94038b2d97c8f8c..f39c25736465ede2e80a420cfe151e265255ed00 100644 --- a/Code/FeatureExtraction/otbThresholdImageToPointSetFilter.h +++ b/Code/FeatureExtraction/otbThresholdImageToPointSetFilter.h @@ -20,6 +20,7 @@ #include "otbImageToPointSetFilter.h" #include "itkPointSet.h" +#include "itkConceptChecking.h" namespace otb { @@ -62,6 +63,14 @@ public: typedef typename Superclass::OutputPointSetPointer OutputPointSetPointer; typedef typename Superclass::OutputPointSetType::PixelType OutputPointSetPixelType; typedef typename Superclass::PointsContainerType PointsContainerType; + typedef typename Superclass::PointDataContainerType PointDataContainerType; + +#ifdef ITK_USE_CONCEPT_CHECKING + /** Begin concept checking */ + itkConceptMacro(PixelConvertibleToPointSetDataType, + (itk::Concept::Convertible<InputPixelType, typename PointDataContainerType::Element>)); +#endif + itkSetMacro(LowerThreshold, InputPixelType); itkGetConstReferenceMacro(LowerThreshold, InputPixelType); diff --git a/Code/FeatureExtraction/otbThresholdImageToPointSetFilter.txx b/Code/FeatureExtraction/otbThresholdImageToPointSetFilter.txx index 2f8bb63b632214689b5d3b6e28b71d0047c653d4..3676b6404e3ec1828c8e55bc1b5dc7cd70ee8d7b 100644 --- a/Code/FeatureExtraction/otbThresholdImageToPointSetFilter.txx +++ b/Code/FeatureExtraction/otbThresholdImageToPointSetFilter.txx @@ -41,6 +41,7 @@ ThresholdImageToPointSetFilter<TInputImage, TOutputPointSet> ::ThreadedGenerateData(const InputImageRegionType& inputRegionForThread, int threadId) { this->m_PointsContainerPerThread[threadId] = PointsContainerType::New(); + this->m_PointDataContainerPerThread[threadId] = PointDataContainerType::New(); InputImageConstPointer inputPtr = this->GetInput(); // Define the iterators @@ -49,7 +50,6 @@ ThresholdImageToPointSetFilter<TInputImage, TOutputPointSet> itk::ProgressReporter progress(this, threadId, inputRegionForThread.GetNumberOfPixels()); typename OutputPointSetType::PointType position; - inputIt.GoToBegin(); while (!inputIt.IsAtEnd()) @@ -62,7 +62,7 @@ ThresholdImageToPointSetFilter<TInputImage, TOutputPointSet> position[0] = index[0]; position[1] = index[1]; this->m_PointsContainerPerThread[threadId]->push_back(position); - + this->m_PointDataContainerPerThread[threadId]->push_back(static_cast<typename PointDataContainerType::Element>(value)); } ++inputIt; progress.CompletedPixel(); // potential exception thrown here