From 05fa8a5a3d9c2fa674652a53a329e42a635eebde Mon Sep 17 00:00:00 2001
From: Cyrille Valladeau <cyrille.valladeau@c-s.fr>
Date: Mon, 9 May 2011 13:16:36 +0200
Subject: [PATCH] ENH: control if a point doesn't already exist before adding
 it to the lists

---
 .../otbDescriptorsListSampleGenerator.txx     | 31 ++++++++++++++++---
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/Code/ObjectDetection/otbDescriptorsListSampleGenerator.txx b/Code/ObjectDetection/otbDescriptorsListSampleGenerator.txx
index 1047020880..5e43108992 100644
--- a/Code/ObjectDetection/otbDescriptorsListSampleGenerator.txx
+++ b/Code/ObjectDetection/otbDescriptorsListSampleGenerator.txx
@@ -214,8 +214,25 @@ PersistentDescriptorsListSampleGenerator<TInputImage, TVectorData, TFunctionType
   ListSampleType* listSample = this->GetListSample();
   LabelListSampleType* labelListSample = this->GetLabelListSample();
   SamplesPositionType& samplesPosition = this->GetSamplesPositions();
+  VectorDataPointType ref;
 
-  for (int threadId = 0; threadId < this->GetNumberOfThreads(); ++threadId )
+  // Copy the first thread elements into lists
+  if( this->GetNumberOfThreads() > 1 )
+    {
+      ListSampleType* threadListSample = m_ThreadListSample[0];
+      LabelListSampleType* threadLabelListSample = m_ThreadLabelListSample[0];
+      SamplesPositionType& threadSamplesPosition = m_ThreadSamplesPosition[0];
+      
+      for (unsigned int i = 0; i < threadListSample->Size(); ++i)
+      {
+        listSample->PushBack( threadListSample->GetMeasurementVector(i) );
+        labelListSample->PushBack( threadLabelListSample->GetMeasurementVector(i) );
+        samplesPosition.push_back( threadSamplesPosition[i] );
+      }
+    }
+
+  // Add the other thread element checking if the point dosn't already exist
+  for (int threadId = 1; threadId < this->GetNumberOfThreads(); ++threadId )
     {
     ListSampleType* threadListSample = m_ThreadListSample[threadId];
     LabelListSampleType* threadLabelListSample = m_ThreadLabelListSample[threadId];
@@ -223,9 +240,13 @@ PersistentDescriptorsListSampleGenerator<TInputImage, TVectorData, TFunctionType
 
     for (unsigned int i = 0; i < threadListSample->Size(); ++i)
       {
-      listSample->PushBack( threadListSample->GetMeasurementVector(i) );
-      labelListSample->PushBack( threadLabelListSample->GetMeasurementVector(i) );
-      samplesPosition.push_back( threadSamplesPosition[i] );
+        const DescriptorsFunctionPointType & curSamplesPosition = threadSamplesPosition[i];
+        if( std::find(samplesPosition.begin(), samplesPosition.end(), curSamplesPosition) == samplesPosition.end() )
+          {
+            listSample->PushBack( threadListSample->GetMeasurementVector(i) );
+            labelListSample->PushBack( threadLabelListSample->GetMeasurementVector(i) );
+            samplesPosition.push_back( curSamplesPosition );
+          }
       }
     }
 }
@@ -261,7 +282,7 @@ PersistentDescriptorsListSampleGenerator<TInputImage, TVectorData, TFunctionType
   inputRequestedRegion = inputPtr->GetRequestedRegion();
 
   // pad the input requested region by the operator radius
-  inputRequestedRegion.PadByRadius( m_NeighborhoodRadius + 1 );
+  inputRequestedRegion.PadByRadius( m_NeighborhoodRadius + 5 );
 
   // crop the input requested region at the input's largest possible region
   if ( inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()) )
-- 
GitLab