From c5a5f3e5b304034391ac97263accbb6fb2ba9d75 Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@orfeo-toolbox.org>
Date: Tue, 10 Mar 2009 18:16:00 +0100
Subject: [PATCH] ENH: (Visu Refactoring) Adding a class to render vector data
 to screen

---
 Code/VisuRefac/otbVectorDataGlComponent.h     | 125 ++++++++++++++++++
 Code/VisuRefac/otbVectorDataGlComponent.txx   | 111 ++++++++++++++++
 Testing/Code/VisuRefac/CMakeLists.txt         |   7 +
 .../VisuRefac/otbVectorDataGlComponentNew.cxx |  30 +++++
 Testing/Code/VisuRefac/otbVisuRefacTests1.cxx |   1 +
 5 files changed, 274 insertions(+)
 create mode 100644 Code/VisuRefac/otbVectorDataGlComponent.h
 create mode 100644 Code/VisuRefac/otbVectorDataGlComponent.txx
 create mode 100644 Testing/Code/VisuRefac/otbVectorDataGlComponentNew.cxx

diff --git a/Code/VisuRefac/otbVectorDataGlComponent.h b/Code/VisuRefac/otbVectorDataGlComponent.h
new file mode 100644
index 0000000000..e0b7463eef
--- /dev/null
+++ b/Code/VisuRefac/otbVectorDataGlComponent.h
@@ -0,0 +1,125 @@
+/*=========================================================================
+
+  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.
+
+=========================================================================*/
+#ifndef __otbVectorDataGlComponent_h
+#define __otbVectorDataGlComponent_h
+
+#include "otbGlComponent.h"
+#include "itkPreOrderTreeIterator.h"
+
+namespace otb
+{
+/** \class VectorDataGlComponent
+*   \brief This Gl Component to render a VectorData.
+*   No checking is done upon the adequation between the VectorData
+*   projection and the underlying image projection.
+*  
+*   Origin and Spacing allows to fit to the image axis.
+*/
+
+template <class TVectorData> 
+class VectorDataGlComponent
+  : public GlComponent
+{
+public:
+  /** Standard class typedefs */
+  typedef VectorDataGlComponent                 Self;
+  typedef GlComponent                           Superclass;
+  typedef itk::SmartPointer<Self>               Pointer;
+  typedef itk::SmartPointer<const Self>         ConstPointer;
+  typedef typename Superclass::RegionType       RegionType;
+ 
+  // affine transform
+  typedef Superclass::AffineTransformType       AffineTransformType;
+  typedef AffineTransformType::InputPointType   PointType;
+  typedef AffineTransformType::InputVectorType  VectorType;
+  typedef Superclass::ColorType                 ColorType;
+
+  /** VectorData typedef */
+  typedef TVectorData                             VectorDataType;
+  typedef typename VectorDataType::Pointer        VectorDataPointerType;
+  typedef typename VectorDataType::DataNodeType   DataNodeType;
+  typedef typename DataNodeType::Pointer          DataNodePointerType;
+  typedef typename VectorDataType::DataTreeType   DataTreeType;
+  typedef itk::PreOrderTreeIterator<DataTreeType> TreeIteratorType;
+  typedef typename DataNodeType::LineType         LineType;
+  typedef typename DataNodeType::PolygonType      PolygonType;
+  typedef typename DataNodeType::PolygonListType  PolygonListType;
+
+  /** Runtime information */
+  itkTypeMacro(VectorDataGlComponent,GlComponent);
+
+  /** New macro */
+  itkNewMacro(Self);
+
+  /// Render the vector data
+  virtual void  Render(const RegionType& extent,const AffineTransformType * space2ScreenTransform);
+   
+  /** Set/Get the grid spacing */
+  itkSetMacro(Spacing,VectorType);
+  itkGetConstReferenceMacro(Spacing,VectorType);
+  
+  /** Set/Get the grid origin */
+  itkSetMacro(Origin,PointType);
+  itkGetConstReferenceMacro(Origin,PointType);
+
+  /** Set/Get the VectorData to render */
+  itkSetObjectMacro(VectorData,VectorDataType);
+  itkGetObjectMacro(VectorData,VectorDataType);
+
+protected:
+  /** Constructor */
+  VectorDataGlComponent();
+  /** Destructor */
+  virtual ~VectorDataGlComponent(){}
+  /** Printself method */
+  void PrintSelf(std::ostream& os, itk::Indent indent) const
+  {
+    Superclass::PrintSelf(os,indent);
+  }
+  
+  // Render a point
+  void RenderPoint(const PointType & p, const RegionType & extent, const AffineTransformType * transform);
+  // Render a polyline
+  void RenderLine(const LineType * l, const RegionType & extent, const AffineTransformType * transform);
+  // Render a complex polygon (with holes)
+  void RenderPolygon(const PolygonType * extRing, const PolygonListType * intRings, const RegionType & extent, const AffineTransformType * transform);
+
+private:
+  VectorDataGlComponent(const Self&); // purposely not implemented
+  void operator=(const Self&);        // purposely not implemented
+
+  /// Pointer to the vector data to render
+  VectorDataPointerType m_VectorData;
+
+  /// Spacing of the image grid
+  VectorType m_Spacing;
+  
+  /// Origin of the image
+  PointType  m_Origin;
+
+}; // end class 
+} // end namespace otb
+
+#ifndef OTB_MANUAL_INSTANTIATION
+#include "otbVectorDataGlComponent.txx" 
+#endif
+
+#endif
+
+
+
diff --git a/Code/VisuRefac/otbVectorDataGlComponent.txx b/Code/VisuRefac/otbVectorDataGlComponent.txx
new file mode 100644
index 0000000000..f3ef91fada
--- /dev/null
+++ b/Code/VisuRefac/otbVectorDataGlComponent.txx
@@ -0,0 +1,111 @@
+/*=========================================================================
+
+  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.
+
+=========================================================================*/
+#ifndef __otbVectorDataGlComponent_txx
+#define __otbVectorDataGlComponent_txx
+
+#include "otbVectorDataGlComponent.h"
+
+namespace otb
+{
+template <class TVectorData> 
+VectorDataGlComponent<TVectorData>
+::VectorDataGlComponent() : m_VectorData(),m_Spacing(), m_Origin()
+{
+  m_Origin.Fill(0.);
+  m_Spacing.Fill(1.);
+}
+
+template <class TVectorData>   
+void 
+VectorDataGlComponent<TVectorData>
+::Render(const RegionType& extent,const AffineTransformType * space2ScreenTransform)
+{
+  if(m_VectorData.IsNull())
+    {
+    // nothing to render, return
+    return;
+    }
+
+  // Iterate on the data tree
+  TreeIteratorType it(m_VectorData->GetDataTree());
+  
+  it.GoToBegin();
+
+  while(!it.IsAtEnd())
+    {
+    DataNodePointerType node = it.Get();
+
+    switch(node->GetNodeType())
+      {
+      case FEATURE_POINT:
+      {
+      this->RenderPoint(node->GetPoint(),extent,space2ScreenTransform);
+	break;
+
+      }
+      case FEATURE_LINE:
+      {
+      this->RenderLine(node->GetLine(),extent,space2ScreenTransform);
+      break;
+      }
+      case FEATURE_POLYGON:
+      {
+      this->RenderPolygon(node->GetPolygonExteriorRing(),node->GetPolygonInteriorRings(),
+			  extent,space2ScreenTransform);
+      break;
+      }
+      default:
+      {
+      // discard
+      break;
+      }
+      }
+    ++it;
+    }
+}
+   template <class TVectorData>   
+void 
+VectorDataGlComponent<TVectorData>
+::RenderPoint(const PointType & p, const RegionType & extent, const AffineTransformType * transform)
+{
+
+
+}
+
+template <class TVectorData>   
+void 
+VectorDataGlComponent<TVectorData>
+::RenderLine(const LineType * l, const RegionType & extent, const AffineTransformType * transform)
+{
+
+
+}
+
+template <class TVectorData>   
+void 
+VectorDataGlComponent<TVectorData>
+::RenderPolygon(const PolygonType * extRing, const PolygonListType * intRings, const RegionType & extent, const AffineTransformType * transform)
+{
+
+
+}
+
+}
+#endif
+
+
diff --git a/Testing/Code/VisuRefac/CMakeLists.txt b/Testing/Code/VisuRefac/CMakeLists.txt
index 32cf29c43d..a8003e6e9a 100644
--- a/Testing/Code/VisuRefac/CMakeLists.txt
+++ b/Testing/Code/VisuRefac/CMakeLists.txt
@@ -250,6 +250,12 @@ ${INPUTDATA}/poupees.png
 0
 )
 
+#------------ otb::VectorDataGlComponent ------------
+ADD_TEST(vrTuVectorDataGlComponentNew ${VISUREFAC_TESTS1}
+vrTuVectorDataGlComponentNew
+)
+
+
 # Testing srcs
 SET(VisuRefac_SRCS1
 otbImageWidgetNew.cxx
@@ -284,6 +290,7 @@ otbCurves2DWidgetNew.cxx
 otbCurves2DWidget.cxx
 otbHistogramCurveNew.cxx
 otbCurves2DWidgetWithHistogram.cxx
+otbVectorDataGlComponentNew.cxx
 )
 
 # Building testing executables
diff --git a/Testing/Code/VisuRefac/otbVectorDataGlComponentNew.cxx b/Testing/Code/VisuRefac/otbVectorDataGlComponentNew.cxx
new file mode 100644
index 0000000000..bfa407e882
--- /dev/null
+++ b/Testing/Code/VisuRefac/otbVectorDataGlComponentNew.cxx
@@ -0,0 +1,30 @@
+/*=========================================================================
+
+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 "otbVectorData.h"
+#include "otbVectorDataGlComponent.h"
+
+int otbVectorDataGlComponentNew(int argc, char * argv[])
+{
+  typedef otb::VectorData<double,2> VectorDataType;
+  typedef otb::VectorDataGlComponent<VectorDataType> VectorDataGlComponentType;
+
+  // Instanatiation
+  VectorDataGlComponentType::Pointer comp = VectorDataGlComponentType::New();
+
+  return EXIT_SUCCESS;
+}
diff --git a/Testing/Code/VisuRefac/otbVisuRefacTests1.cxx b/Testing/Code/VisuRefac/otbVisuRefacTests1.cxx
index 78befedfdb..85ec130986 100644
--- a/Testing/Code/VisuRefac/otbVisuRefacTests1.cxx
+++ b/Testing/Code/VisuRefac/otbVisuRefacTests1.cxx
@@ -58,4 +58,5 @@ void RegisterTests()
   REGISTER_TEST(otbCurves2DWidgetNew);
   REGISTER_TEST(otbCurves2DWidget);
   REGISTER_TEST(otbCurves2DWidgetWithHistogram);
+  REGISTER_TEST(otbVectorDataGlComponentNew);
 }
-- 
GitLab