From 841d4d6ea0fb064d10fc42f63ac69b9a06bcde3b Mon Sep 17 00:00:00 2001
From: Otmane Lahlou <otmane.lahlou@c-s.fr>
Date: Tue, 10 Mar 2009 15:24:06 +0100
Subject: [PATCH] TEST : Add tests for otb::Rectangle class

---
 Testing/Code/Common/CMakeLists.txt      | 15 ++++++
 Testing/Code/Common/otbCommonTests6.cxx |  2 +
 Testing/Code/Common/otbRectangle.cxx    | 72 +++++++++++++++++++++++++
 Testing/Code/Common/otbRectangleNew.cxx | 29 ++++++++++
 4 files changed, 118 insertions(+)
 create mode 100644 Testing/Code/Common/otbRectangle.cxx
 create mode 100644 Testing/Code/Common/otbRectangleNew.cxx

diff --git a/Testing/Code/Common/CMakeLists.txt b/Testing/Code/Common/CMakeLists.txt
index 7170f7c439..e033f6c331 100644
--- a/Testing/Code/Common/CMakeLists.txt
+++ b/Testing/Code/Common/CMakeLists.txt
@@ -503,7 +503,20 @@ ADD_TEST(coTvUnaryFunctorNeighborhoodImageFilter ${COMMON_TESTS6}
 	3
 )
 
+#--------------------otb::Rectangle
+ADD_TEST(coTuRectangleNew ${COMMON_TESTS6}
+          otbRectangleNew)
 
+ADD_TEST(coTvRectangle ${COMMON_TESTS6}
+--compare-ascii ${EPS}
+		${BASELINE_FILES}/otbRectangleTest.txt
+                ${TEMP}/otbRectangleTest.txt
+         otbRectangle
+	        ${TEMP}/otbRectangleTest.txt
+		2.12 2.35 12.54 2.45   3. 0.15  1. 1. 
+	
+	
+)
 
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbCommonTests7 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -663,6 +676,8 @@ otbPolygonNew.cxx
 otbPolygon.cxx
 otbUnaryFunctorNeighborhoodImageFilterNew.cxx
 otbUnaryFunctorNeighborhoodImageFilter.cxx
+otbRectangleNew.cxx
+otbRectangle.cxx	
 )
 
 SET(BasicCommon_SRCS7
diff --git a/Testing/Code/Common/otbCommonTests6.cxx b/Testing/Code/Common/otbCommonTests6.cxx
index 41ebe6c6c9..cf321e7878 100644
--- a/Testing/Code/Common/otbCommonTests6.cxx
+++ b/Testing/Code/Common/otbCommonTests6.cxx
@@ -37,4 +37,6 @@ void RegisterTests()
   REGISTER_TEST(otbPolygon);
   REGISTER_TEST(otbUnaryFunctorNeighborhoodImageFilterNew);
   REGISTER_TEST(otbUnaryFunctorNeighborhoodImageFilter);
+  REGISTER_TEST(otbRectangleNew);
+  REGISTER_TEST(otbRectangle);
 }
diff --git a/Testing/Code/Common/otbRectangle.cxx b/Testing/Code/Common/otbRectangle.cxx
new file mode 100644
index 0000000000..2d633e3163
--- /dev/null
+++ b/Testing/Code/Common/otbRectangle.cxx
@@ -0,0 +1,72 @@
+/*=========================================================================
+
+  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 "otbRectangle.h"
+
+#include <iostream>
+#include <fstream>
+
+int otbRectangle(int argc, char * argv[])
+{
+    const char * outfname = argv[1];
+  
+  typedef otb::Rectangle<>                   RectangleType;
+  typedef RectangleType::ContinuousIndexType ContinuousIndexType;
+  typedef RectangleType::VertexListType      VertexListType;
+  typedef VertexListType::ConstIterator      IteratorType;
+
+  // Instantiating object
+  RectangleType::Pointer rectangle1 = RectangleType::New();
+
+  ContinuousIndexType newVertex;
+  
+  newVertex[0]=atof(argv[2]);
+  newVertex[1]=atof(argv[3]);
+  rectangle1->AddVertex(newVertex);
+  
+  newVertex[0]=atof(argv[4]);
+  newVertex[1]=atof(argv[5]);
+  rectangle1->AddVertex(newVertex);
+  
+  rectangle1->SetWidth(atof(argv[6]));
+  rectangle1->SetOrientation(atof(argv[7]));
+
+
+  /** Inside the rectangle test*/
+  ContinuousIndexType InsideVertex;
+  InsideVertex[0] = atof(argv[8]);
+  InsideVertex[1] = atof(argv[9]);
+
+
+  std::ofstream outfile(outfname);
+
+  if(rectangle1->IsInside(InsideVertex))
+    outfile <<"The point " <<  InsideVertex << " Is Inside the rectangle"  << std::endl;
+  else
+    outfile <<"The point " <<  InsideVertex << " Is Outside the rectangle"  << std::endl;
+
+
+  
+  outfile<< "region Size" << rectangle1->GetBoundingRegion().GetSize()<<std::endl;
+  outfile<< "region Origin" << rectangle1->GetBoundingRegion().GetIndex()<<std::endl;
+  
+
+  outfile.close();
+
+
+  return EXIT_SUCCESS;
+}
diff --git a/Testing/Code/Common/otbRectangleNew.cxx b/Testing/Code/Common/otbRectangleNew.cxx
new file mode 100644
index 0000000000..a94cb60e92
--- /dev/null
+++ b/Testing/Code/Common/otbRectangleNew.cxx
@@ -0,0 +1,29 @@
+/*=========================================================================
+
+  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 "otbRectangle.h"
+
+int otbRectangleNew(int argc, char * argv[])
+{
+  typedef otb::Rectangle<> RectangleType;
+
+  //Instantiating object
+  RectangleType::Pointer polygon = RectangleType::New();
+
+  return EXIT_SUCCESS;
+}
-- 
GitLab