From 57ce96768e7af7dfaed8a7f97bf0a89c404d107c Mon Sep 17 00:00:00 2001
From: Otmane Lahlou <otmane.lahlou@c-s.fr>
Date: Thu, 10 Nov 2011 16:55:44 +0100
Subject: [PATCH] ENH: rename application name

---
 Applications/Utils/otbVectorDataTransform.cxx | 154 +++++++++++++++++
 ...tbVectorDataTransformFilterApplication.cxx | 157 ------------------
 2 files changed, 154 insertions(+), 157 deletions(-)
 create mode 100644 Applications/Utils/otbVectorDataTransform.cxx
 delete mode 100644 Applications/Utils/otbVectorDataTransformFilterApplication.cxx

diff --git a/Applications/Utils/otbVectorDataTransform.cxx b/Applications/Utils/otbVectorDataTransform.cxx
new file mode 100644
index 0000000000..5659ba4db1
--- /dev/null
+++ b/Applications/Utils/otbVectorDataTransform.cxx
@@ -0,0 +1,154 @@
+/*=========================================================================
+
+ Program:   ORFEO Toolbox
+ Language:  C++
+ Date:      $Date$
+ Version:   $Revision$
+
+
+ Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
+ See OTBCopyright.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.
+
+ =========================================================================*/
+#include "otbWrapperApplication.h"
+#include "otbWrapperApplicationFactory.h"
+
+#include "otbVectorDataTransformFilter.h"
+#include "otbVectorDataProjectionFilter.h"
+#include "itkCenteredSimilarity2DTransform.h"
+#include "otbMath.h"
+
+namespace otb
+{
+
+namespace Wrapper
+{
+
+class VectorDataTransform : public Application
+{
+public:
+/** Standard class typedefs. */
+  typedef VectorDataTransform           Self;
+  typedef Application                   Superclass;
+  typedef itk::SmartPointer<Self>       Pointer;
+  typedef itk::SmartPointer<const Self> ConstPointer;
+
+  /** Standard macro */
+  itkNewMacro(Self);
+
+  itkTypeMacro(VectorDataTransform, otb::Application);
+
+  /** Convenient typedefs */
+  typedef otb::VectorDataTransformFilter<VectorDataType,
+                                         VectorDataType>   VectorDataTransformFilterType;
+  typedef otb::VectorDataProjectionFilter<VectorDataType,
+                                          VectorDataType>  VectorDataProjectionFilterType;
+  typedef itk::CenteredSimilarity2DTransform<double>       TransformType;
+
+private:
+  VectorDataTransform()
+  {
+    SetName("VectorDataTransform");
+    SetDescription("Apply a transform to each vertex of the input VectorData");
+  }
+
+  void DoCreateParameters()
+  {
+    AddParameter(ParameterType_InputVectorData, "vd", "Input Vector data");
+    AddParameter(ParameterType_OutputVectorData,"out","Output Vector data");
+
+    AddParameter(ParameterType_InputImage, "in", "Support image");
+    SetParameterDescription("in","Image needed as a support of the VectorData");
+  
+    // Transform Group
+    AddParameter(ParameterType_Group, "transform", "Transform parameters");
+    MandatoryOff("transform");
+
+    AddParameter(ParameterType_Float, "transform.tx", "Translation X");
+    SetParameterDescription("transform.tx","Translation in the X direction");
+    AddParameter(ParameterType_Float, "transform.ty", "Translation Y");
+    SetParameterDescription("transform.ty","Translation in the Y direction");
+    SetDefaultParameterFloat("transform.tx",0.);
+    SetDefaultParameterFloat("transform.ty",0.);
+      
+    AddParameter(ParameterType_Float, "transform.ro", "Rotation Angle");  
+    SetParameterDescription("transform.ro","Angle of the rotation to apply in degrees");
+    SetDefaultParameterFloat("transform.ro",0.);
+
+    AddParameter(ParameterType_Float, "transform.centerx", "Center X");
+    SetParameterDescription("transform.centerx","The first coordinate of the rotation center");
+    AddParameter(ParameterType_Float, "transform.centery", "Center Y");
+    SetParameterDescription("transform.centery","The second coordinate of the rotation center");
+    SetDefaultParameterFloat("transform.centerx",0.);
+    SetDefaultParameterFloat("transform.centery",0.);
+
+    AddParameter(ParameterType_Float, "transform.scale", "Scale");
+    SetParameterDescription("transform.scale","The scale to apply");
+    SetDefaultParameterFloat("transform.scale",1.);
+  }
+
+  void DoUpdateParameters()
+  {
+    // nothing to update
+  }
+
+  void DoExecute()
+  {
+    // Get the support image
+    FloatVectorImageType*  inImage = GetParameterImage("in");
+    
+    // Get the VectorData to apply the transform on
+    VectorDataType*        vd      = GetParameterVectorData("vd");
+      
+    // Reproject the VectorData in the image coordinate system
+    m_VectorDataProj = VectorDataProjectionFilterType::New();
+    m_VectorDataProj->SetInput(vd);
+    m_VectorDataProj->SetInputProjectionRef(inImage->GetProjectionRef());
+    m_VectorDataProj->SetOutputKeywordList(inImage->GetImageKeywordlist());
+    m_VectorDataProj->SetOutputProjectionRef(inImage->GetProjectionRef());
+    
+    // Set up the transform 
+    m_Transform = TransformType::New();
+    TransformType::ParametersType parameters(6);
+
+    // Get parameters if any
+    parameters[0] = GetParameterFloat("transform.scale");
+    parameters[1] = CONST_PI * GetParameterFloat("transform.ro")/180.;
+    parameters[2] = GetParameterFloat("transform.centerx");
+    parameters[3] = GetParameterFloat("transform.centery");
+    parameters[4] = inImage->GetSpacing()[0] * GetParameterFloat("transform.tx");
+    parameters[5] = vcl_abs(inImage->GetSpacing()[1]) * GetParameterFloat("transform.ty");
+    
+    // Set the parameters to the transform
+    m_Transform->SetParameters(parameters);
+    
+    m_TransformFilter = VectorDataTransformFilterType::New();
+    m_TransformFilter->SetInput(vd);
+    m_TransformFilter->SetTransform(m_Transform);
+  
+    // retransform int the input vector projection
+    m_ReverseVectorDataProj = VectorDataProjectionFilterType::New();
+    m_ReverseVectorDataProj->SetInput(m_TransformFilter->GetOutput());
+    m_ReverseVectorDataProj->SetOutputProjectionRef(inImage->GetProjectionRef());
+    m_ReverseVectorDataProj->SetInputKeywordList(inImage->GetImageKeywordlist());
+    m_ReverseVectorDataProj->SetInputProjectionRef(inImage->GetProjectionRef());
+
+    // Set the output image
+    SetParameterOutputVectorData("out", m_ReverseVectorDataProj->GetOutput());
+  }
+
+  VectorDataTransformFilterType::Pointer   m_TransformFilter;
+  VectorDataProjectionFilterType::Pointer  m_VectorDataProj;
+  VectorDataProjectionFilterType::Pointer  m_ReverseVectorDataProj;
+  TransformType::Pointer                   m_Transform;
+};
+
+}
+}
+
+OTB_APPLICATION_EXPORT(otb::Wrapper::VectorDataTransform)
diff --git a/Applications/Utils/otbVectorDataTransformFilterApplication.cxx b/Applications/Utils/otbVectorDataTransformFilterApplication.cxx
deleted file mode 100644
index 39be0e7e9c..0000000000
--- a/Applications/Utils/otbVectorDataTransformFilterApplication.cxx
+++ /dev/null
@@ -1,157 +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.
-
-
- 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.
-
- =========================================================================*/
-#include "otbVectorDataTransformFilterApplication.h"
-
-#include <iostream>
-#include "otbVectorImage.h"
-#include "otbImageFileReader.h"
-#include "otbVectorDataTransformFilter.h"
-#include "otbVectorData.h"
-#include "otbVectorDataFileWriter.h"
-#include "otbVectorDataFileReader.h"
-#include "otbVectorDataProjectionFilter.h"
-#include "itkCenteredSimilarity2DTransform.h"
-#include "otbMath.h"
-
-namespace otb
-{
-
-int VectorDataTransformFilterApplication::Describe(ApplicationDescriptor* descriptor)
-{
-  descriptor->SetName("VectorDataTransformFilterApplication");
-  descriptor->SetDescription("Apply a transform to each vertex of the input VectorData");
-  descriptor->AddOption("Input","Support image","in", 1, true, ApplicationDescriptor::FileName);
-  descriptor->AddOption("InputVectorData","Input vector data","vd", 1, true, ApplicationDescriptor::FileName);
-  descriptor->AddOption("Output","Output vector data","out", 1, true, ApplicationDescriptor::FileName);
-  descriptor->AddOption("TanslationX","Translation in the X direction","tx", 1, false, ApplicationDescriptor::Real);
-  descriptor->AddOption("TanslationY","Translation in the Y direction","ty", 1, false, ApplicationDescriptor::Real);
-  descriptor->AddOption("Angle",
-                        "Angle of the rotation to apply in degrees","rot",
-                        1, false, ApplicationDescriptor::Real);
-  descriptor->AddOption("CenterX","The first coordinate of the rotation center","cx", 1,
-                        false, ApplicationDescriptor::Real);
-  descriptor->AddOption("CenterY","The second coordinate of the rotation center","cy", 1,
-                        false, ApplicationDescriptor::Real);
-  descriptor->AddOption("Scale","The scale to apply ","sc", 1, false, ApplicationDescriptor::Real);
-  
-  return EXIT_SUCCESS;
-}
-
-int VectorDataTransformFilterApplication::Execute(otb::ApplicationOptionsResult* parseResult)
-{
-  try
-    {
-    typedef otb::VectorData<>                         VectorDataType;
-    typedef otb::VectorDataFileReader<VectorDataType> VectorDataFileReaderType;
-    typedef otb::VectorDataFileWriter<VectorDataType> VectorDataFileWriterType;
-    typedef otb::VectorDataTransformFilter
-      <VectorDataType, VectorDataType>                VectorDataTransformType;
-    typedef otb::VectorDataProjectionFilter<VectorDataType,
-      VectorDataType>                                 VDProjectionFilterType;
-
-    typedef otb::VectorImage<double, 2>               ImageType;
-    typedef otb::ImageFileReader<ImageType>           ReaderType;
-    
-    // Instanciate the image reader
-    ReaderType::Pointer      reader = ReaderType::New();
-    reader->SetFileName(parseResult->GetParameterString("Input"));
-    reader->UpdateOutputInformation();
-
-    VectorDataFileReaderType::Pointer  vdreader = VectorDataFileReaderType::New();
-    vdreader->SetFileName(parseResult->GetParameterString("InputVectorData"));
-    vdreader->Update();
-  
-    // Reproject the VectorData In the image coordinate system
-    VDProjectionFilterType::Pointer  vdproj = VDProjectionFilterType::New();
-    vdproj->SetInput(vdreader->GetOutput());
-    vdproj->SetInputProjectionRef(vdreader->GetOutput()->GetProjectionRef());
-    vdproj->SetOutputKeywordList(reader->GetOutput()->GetImageKeywordlist());
-    vdproj->SetOutputProjectionRef(reader->GetOutput()->GetProjectionRef());
-    
-    // Set up the transform (Apply a translation of 8 pixels in the y
-    // direction)
-    typedef itk::CenteredSimilarity2DTransform<double> TransformType;
-    TransformType::Pointer transform = TransformType::New();
-    
-    TransformType::ParametersType parameters(6);
-    parameters[0] = 1;                  // Scale
-    parameters[1] = 0.;                 // Rotation Angle in radian
-    parameters[2] = 0;          // Center of the rotation (X)
-    parameters[3] = 0;          // Center of the rotation (Y)
-    parameters[4] = 0;                  // Translation (X)
-    parameters[5] = 0;                  // Translation (Y)
-
-    // Get parameters if any
-    if(parseResult->IsOptionPresent("Scale"))
-      parameters[0] = parseResult->GetParameterFloat("Scale");
-
-    if(parseResult->IsOptionPresent("Angle"))
-      parameters[1] = CONST_PI*parseResult->GetParameterFloat("Angle")/180.;
-
-    if(parseResult->IsOptionPresent("CenterX"))
-      parameters[2] = parseResult->GetParameterFloat("CenterX");
-    
-    if(parseResult->IsOptionPresent("CenterY"))
-      parameters[3] = parseResult->GetParameterFloat("CenterY");
-    
-    if(parseResult->IsOptionPresent("TanslationX"))
-      parameters[4] = reader->GetOutput()->GetSpacing()[0] * parseResult->GetParameterFloat("TanslationX");
-
-    if(parseResult->IsOptionPresent("TanslationY"))
-      parameters[5] = vcl_abs(reader->GetOutput()->GetSpacing()[1]) * parseResult->GetParameterFloat("TanslationY");
-    
-    // Set the parameters to the transform
-    transform->SetParameters(parameters);
-    
-    VectorDataTransformType::Pointer transformFilter = VectorDataTransformType::New();
-    transformFilter->SetInput(vdproj->GetOutput());
-    transformFilter->SetTransform(transform);
-  
-    // retransform int the input vector projection
-    VDProjectionFilterType::Pointer  reverseVdProj = VDProjectionFilterType::New();
-    reverseVdProj->SetInput(transformFilter->GetOutput());
-    reverseVdProj->SetOutputProjectionRef(vdreader->GetOutput()->GetProjectionRef());
-    reverseVdProj->SetInputKeywordList(reader->GetOutput()->GetImageKeywordlist());
-    reverseVdProj->SetInputProjectionRef(reader->GetOutput()->GetProjectionRef());
-
-    //Write the vectordata
-    VectorDataFileWriterType::Pointer vdwriter = VectorDataFileWriterType::New();
-    vdwriter->SetInput(reverseVdProj->GetOutput());
-    vdwriter->SetFileName(parseResult->GetParameterString("Output"));
-    vdwriter->Update();
-  
-    }
-  catch ( itk::ExceptionObject & err )
-    {
-    std::cout << "Following otbException caught :" << std::endl;
-    std::cout << err << std::endl;
-    return EXIT_FAILURE;
-    }
-  catch ( std::bad_alloc & err )
-    {
-    std::cout << "Exception bad_alloc : "<<(char*)err.what()<< std::endl;
-    return EXIT_FAILURE;
-    }
-  catch ( ... )
-    {
-    std::cout << "Unknown Exception found !" << std::endl;
-    return EXIT_FAILURE;
-    }
-  return EXIT_SUCCESS;
-}
-}
-- 
GitLab