From cd1db5d8ba51a7e68dc928d9d9ebe9c697966b4b Mon Sep 17 00:00:00 2001
From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org>
Date: Thu, 14 Oct 2010 16:19:16 +0800
Subject: [PATCH] ENH: handle point set data in the PointSetSource hierarchy

---
 Code/BasicFilters/otbImageToPointSetFilter.h  | 15 ++++++-----
 .../BasicFilters/otbImageToPointSetFilter.txx | 25 +++++++++++++++++++
 Code/Common/otbPointSetSource.h               |  9 ++++---
 .../otbThresholdImageToPointSetFilter.h       |  9 +++++++
 .../otbThresholdImageToPointSetFilter.txx     |  4 +--
 5 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/Code/BasicFilters/otbImageToPointSetFilter.h b/Code/BasicFilters/otbImageToPointSetFilter.h
index 06843f3170..4443786237 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 16d8baf457..56cb5ef076 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 f3b15a6e6b..a0157133fc 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 acd3063b90..f39c257364 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 2f8bb63b63..3676b6404e 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
-- 
GitLab