From 80f9d699f73591ac39229439c30462432d59051a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Traizet?= <traizetc@cesbio.cnes.fr>
Date: Thu, 13 Jul 2017 09:59:27 +0200
Subject: [PATCH] debugging the vector reduction app

---
 app/cbDimensionalityReduction.cxx             |  2 +-
 app/cbDimensionalityReductionTrainer.cxx      |  2 +
 app/cbDimensionalityReductionVector.cxx       | 48 ++++++++++++++-----
 .../ImageDimensionalityReductionFilter.txx    |  2 +-
 4 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/app/cbDimensionalityReduction.cxx b/app/cbDimensionalityReduction.cxx
index 6a8ed36866..bc9a5754fe 100644
--- a/app/cbDimensionalityReduction.cxx
+++ b/app/cbDimensionalityReduction.cxx
@@ -222,7 +222,7 @@ private:
         }
         
       // Rescale vector image
-      m_Rescaler->SetScale(stddevMeasurementVector*5);
+      m_Rescaler->SetScale(stddevMeasurementVector*3);
       m_Rescaler->SetShift(meanMeasurementVector);
       m_Rescaler->SetInput(inImage);
 
diff --git a/app/cbDimensionalityReductionTrainer.cxx b/app/cbDimensionalityReductionTrainer.cxx
index 1b273650c9..cde3bfd6d7 100644
--- a/app/cbDimensionalityReductionTrainer.cxx
+++ b/app/cbDimensionalityReductionTrainer.cxx
@@ -103,6 +103,8 @@ private:
 			}
 			input->PushBack(mv);
 		}
+		std::cout << GetParameterStringList("feat")[0] << std::endl;
+		std::cout << input->GetMeasurementVector(0) << std::endl;
 		
 		MeasurementType meanMeasurementVector;
 		MeasurementType stddevMeasurementVector;
diff --git a/app/cbDimensionalityReductionVector.cxx b/app/cbDimensionalityReductionVector.cxx
index b598a0310a..ec11ba8adc 100644
--- a/app/cbDimensionalityReductionVector.cxx
+++ b/app/cbDimensionalityReductionVector.cxx
@@ -57,7 +57,7 @@ class CbDimensionalityReductionVector : public Application
 		
 		/** Filters typedef */
 		
-		typedef double 															ValueType;
+		typedef float 															ValueType;
 		typedef itk::VariableLengthVector<ValueType> 							InputSampleType;
 		typedef itk::Statistics::ListSample<InputSampleType> 					ListSampleType;
 		typedef MachineLearningModel<itk::VariableLengthVector<ValueType>, itk::VariableLengthVector<ValueType>>	DimensionalityReductionModelType;
@@ -136,6 +136,7 @@ class CbDimensionalityReductionVector : public Application
 			
 			if ( HasValue("in") )
 			{
+				
 				std::string shapefile = GetParameterString("in");
 				otb::ogr::DataSource::Pointer ogrDS;
 				OGRSpatialReference oSRS("");
@@ -153,21 +154,32 @@ class CbDimensionalityReductionVector : public Application
 					key.erase( std::remove_if(key.begin(),key.end(),IsNotAlphaNum), key.end());
 					std::transform(key.begin(), key.end(), key.begin(), tolower);
 					OGRFieldType fieldType = layerDefn.GetFieldDefn(iField)->GetType();
-					
-					if(fieldType == OFTInteger || ogr::version_proxy::IsOFTInteger64(fieldType) || fieldType == OFTReal)
-					{
+					/*if(fieldType == OFTInteger || ogr::version_proxy::IsOFTInteger64(fieldType) || fieldType == OFTReal)
+					{*/
 						std::string tmpKey="feat."+key;
 						AddChoice(tmpKey,item);
-					}
-				
+					//}
 				}
+				
 			}
+			
 		}
 		
 		void DoExecute() ITK_OVERRIDE
 		{
 			clock_t tic = clock();
 			
+			
+			std::cout << GetChoiceKeys("feat")[0] << std::endl;
+			std::cout << GetChoiceKeys("feat")[1] << std::endl;
+			std::cout << GetChoiceKeys("feat")[2] << std::endl;
+			std::cout << GetChoiceKeys("feat")[3] << std::endl;
+			std::cout << GetChoiceKeys("feat")[4] << std::endl;
+			std::cout << GetChoiceKeys("feat")[5] << std::endl;
+			std::cout << GetChoiceKeys("feat")[6] << std::endl;
+			std::cout << GetChoiceKeys("feat")[7] << std::endl;
+			std::cout << GetChoiceKeys("feat")[8] << std::endl;
+			
 			std::string shapefile = GetParameterString("in");
 			otb::ogr::DataSource::Pointer source = otb::ogr::DataSource::New(shapefile, otb::ogr::DataSource::Modes::Read);
 			otb::ogr::Layer layer = source->GetLayer(0);
@@ -177,18 +189,31 @@ class CbDimensionalityReductionVector : public Application
 			input->SetMeasurementVectorSize(nbFeatures);
 			otb::ogr::Layer::const_iterator it = layer.cbegin();
 			otb::ogr::Layer::const_iterator itEnd = layer.cend();
-			
+			std::cout << (*it)[GetSelectedItems("feat")[0]].GetValue<double>() << std::endl;
 			for( ; it!=itEnd ; ++it)
 			{
 				MeasurementType mv;
 				mv.SetSize(nbFeatures);
+				
 				for(int idx=0; idx < nbFeatures; ++idx)
 				{
-					mv[idx] = (*it)[GetSelectedItems("feat")[idx]].GetValue<double>();
+					mv[idx] = static_cast<float>( (*it)[GetSelectedItems("feat")[idx]].GetValue<double>() );
+					
 				}
 				input->PushBack(mv);
 				
 			}
+			std::cout << GetSelectedItems("feat")[0] << std::endl;
+			std::cout << input->GetMeasurementVector(0) << std::endl;
+			
+			
+			
+				
+			
+			
+			
+			
+			
 			/** Statistics for shift/scale */
 			
 			MeasurementType meanMeasurementVector;
@@ -242,8 +267,9 @@ class CbDimensionalityReductionVector : public Application
 			
 			ListSampleType::Pointer listSample = trainingShiftScaleFilter->GetOutput();
 			ListSampleType::Pointer target = m_Model->PredictBatch(listSample);
-			
-			
+			target = input;
+			std::cout << target->GetMeasurementVector(0) << std::endl;
+			std::cout << input->GetMeasurementVector(0) << std::endl;
 			/** Create/Update Output Shape file */
 			
 			std::cout << GetParameterStringList("featout").size() << std::endl;
@@ -350,7 +376,7 @@ class CbDimensionalityReductionVector : public Application
 				
 				
 				for (std::size_t i=0; i<classfieldname.size(); ++i){
-					dstFeature[classfieldname[i]].SetValue<ValueType>(target->GetMeasurementVector(count)[i]);
+					dstFeature[classfieldname[i]].SetValue<double>(target->GetMeasurementVector(count)[i]);
 				}
 				if (updateMode)
 				{
diff --git a/include/ImageDimensionalityReductionFilter.txx b/include/ImageDimensionalityReductionFilter.txx
index 53a1739bd2..7f7b70284c 100644
--- a/include/ImageDimensionalityReductionFilter.txx
+++ b/include/ImageDimensionalityReductionFilter.txx
@@ -189,7 +189,7 @@ ImageDimensionalityReductionFilter<TInputImage, TOutputImage, TMaskImage>
  
   // This call is threadsafe
   labels = m_Model->PredictBatch(samples);
-  
+  labels = samples;
   // Set the output values
  
   typename TargetListSampleType::ConstIterator labIt = labels->Begin();
-- 
GitLab