From f64ecb30f3abe8b980871f774aedc18ef92e7692 Mon Sep 17 00:00:00 2001
From: Owen Arnold <owen.arnold@stfc.ac.uk>
Date: Wed, 2 Sep 2015 14:15:24 +0100
Subject: [PATCH] refs #13523. vtkPointSet and Scale filter fix.

1) Scale filter fixed to set the representation to Surface. The change to StructuredGrid as the type for vtkasscicated with MDHistoWorkspaces seems to have broken this.

2) Scale filter fixed to work with vtkPointSets rather than vtkUnstructuredGrids. This makes the algorithm very generic, and removes the need to convert vtkPolyData sets into vtkUnstructuredGrids, as was happening previously.
---
 .../ScaleWorkspace/vtkScaleWorkspace.cxx      | 43 +++----------------
 .../ScaleWorkspace/vtkScaleWorkspace.h        |  8 ++--
 .../vtkDataSetToScaledDataSet.h               |  8 ++--
 .../src/vtkDataSetToScaledDataSet.cpp         | 18 ++++----
 .../test/vtkDataSetToScaledDataSetTest.h      |  5 ++-
 .../StandardView.h                            |  7 ++-
 .../ViewWidgets/src/StandardView.cpp          | 26 +++++++++--
 7 files changed, 56 insertions(+), 59 deletions(-)

diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/ScaleWorkspace/vtkScaleWorkspace.cxx b/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/ScaleWorkspace/vtkScaleWorkspace.cxx
index 101257eeb6f..6585dd02786 100644
--- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/ScaleWorkspace/vtkScaleWorkspace.cxx
+++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/ScaleWorkspace/vtkScaleWorkspace.cxx
@@ -10,10 +10,9 @@
 #include <vtkObjectFactory.h>
 #include <vtkUnstructuredGridAlgorithm.h>
 #include <vtkUnstructuredGrid.h>
-
 #include <vtkSmartPointer.h>
-#include <vtkPolyData.h>
-#include <vtkAppendFilter.h>
+
+
 
 vtkStandardNewMacro(vtkScaleWorkspace)
 
@@ -43,17 +42,7 @@ int vtkScaleWorkspace::RequestData(vtkInformation*, vtkInformationVector **input
   vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
   
   // Try to cast to vktUnstructuredGrid, if this fails then cast it to vtkPolyData
-  vtkUnstructuredGrid* inputDataSet = vtkUnstructuredGrid::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
-
-  // This follows the example given here:
-  // http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataToUnstructuredGrid
-  auto appendFilter = vtkSmartPointer<vtkAppendFilter>::New();
-  if (!inputDataSet) {
-    auto polyDataSet = vtkPolyData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
-    appendFilter->AddInputData(polyDataSet);
-    appendFilter->Update();
-    inputDataSet = appendFilter->GetOutput();
-  }
+ vtkSmartPointer<vtkPointSet> inputDataSet = vtkSmartPointer<vtkPointSet>(vtkPointSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT())));
 
   vtkInformation *outInfo = outputVector->GetInformationObject(0);
   vtkDataSetToScaledDataSet scaler;
@@ -69,16 +58,8 @@ int vtkScaleWorkspace::RequestInformation(vtkInformation*, vtkInformationVector*
 {
   // Set the meta data 
   vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
-  vtkSmartPointer<vtkUnstructuredGrid> inputDataSet = vtkSmartPointer<vtkUnstructuredGrid>(vtkUnstructuredGrid::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT())));
-  // This follows the example given here:
-  // http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataToUnstructuredGrid
-  auto appendFilter = vtkSmartPointer<vtkAppendFilter>::New();
-  if (!inputDataSet) {
-    auto polyDataSet = vtkPolyData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
-    appendFilter->AddInputData(polyDataSet);
-    appendFilter->Update();
-    inputDataSet = appendFilter->GetOutput();
-  }
+  vtkSmartPointer<vtkPointSet> inputDataSet = vtkSmartPointer<vtkPointSet>(vtkPointSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT())));
+
   updateMetaData(inputDataSet);
   return 1;
 }
@@ -165,7 +146,7 @@ int vtkScaleWorkspace::GetSpecialCoordinates()
  * Update the metadata fields of the plugin based on the information of the inputDataSet
  * @param inputDataSet :: the input data set.
  */
-void vtkScaleWorkspace::updateMetaData(vtkUnstructuredGrid *inputDataSet) {
+void vtkScaleWorkspace::updateMetaData(vtkPointSet *inputDataSet) {
   vtkFieldData* fieldData = inputDataSet->GetFieldData();
   
   // Extract information for meta data in Json format.
@@ -184,19 +165,9 @@ void vtkScaleWorkspace::updateMetaData(vtkUnstructuredGrid *inputDataSet) {
  * Set the input types that we expect for this algorithm. These are naturally
  * vtkUnstructredGrid data sets. In order to accomodate for the cut filter's
  * output we need to allow also for vtkPolyData data sets.
- * @param port: the input port
- * @param info: the information object
  * @retuns either success flag (1) or a failure flag (0)
  */
-int vtkScaleWorkspace::FillInputPortInformation (int port, vtkInformation *info) {
-    // We only have port 0 as an input
-    if (port == 0)
-    {
-      info->Remove(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE());
-      info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),"vtkUnstructuredGrid");
-      info->Append(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),"vtkPolyData");
-      return 1;
-    }
+int vtkScaleWorkspace::FillInputPortInformation (int, vtkInformation *) {
   return 0;
 }
 
diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/ScaleWorkspace/vtkScaleWorkspace.h b/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/ScaleWorkspace/vtkScaleWorkspace.h
index f47ce5ef03b..da7ab983c88 100644
--- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/ScaleWorkspace/vtkScaleWorkspace.h
+++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewFilters/ScaleWorkspace/vtkScaleWorkspace.h
@@ -1,16 +1,16 @@
 #ifndef _vtkScaleWorkspace_h
 #define _vtkScaleWorkspace_h
-#include "vtkUnstructuredGridAlgorithm.h"
+#include "vtkPointSetAlgorithm.h"
 #include "MantidVatesAPI/MetadataJsonManager.h"
 #include "MantidVatesAPI/VatesConfigurations.h"
 #include <boost/scoped_ptr.hpp>
 
 // cppcheck-suppress class_X_Y
-class VTK_EXPORT vtkScaleWorkspace : public vtkUnstructuredGridAlgorithm
+class VTK_EXPORT vtkScaleWorkspace : public vtkPointSetAlgorithm
 {
 public:
   static vtkScaleWorkspace *New();
-  vtkTypeMacro(vtkScaleWorkspace, vtkUnstructuredGridAlgorithm)
+  vtkTypeMacro(vtkScaleWorkspace, vtkPointSetAlgorithm)
   void PrintSelf(ostream& os, vtkIndent indent);
   void SetXScaling(double xScaling);
   void SetYScaling(double yScaling);
@@ -29,7 +29,7 @@ protected:
 private:
   vtkScaleWorkspace(const vtkScaleWorkspace&);
   void operator = (const vtkScaleWorkspace&);
-  void updateMetaData(vtkUnstructuredGrid *inputDataSet);
+  void updateMetaData(vtkPointSet *inputDataSet);
   double m_xScaling;
   double m_yScaling;
   double m_zScaling;
diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetToScaledDataSet.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetToScaledDataSet.h
index 5a99ba72873..e6929ef079a 100644
--- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetToScaledDataSet.h
+++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetToScaledDataSet.h
@@ -3,7 +3,7 @@
 
 #include "MantidKernel/System.h"
 
-class vtkUnstructuredGrid;
+class vtkPointSet;
 class vtkInformation;
 namespace Mantid
 {
@@ -44,14 +44,14 @@ namespace VATES
     /// Destructor
     virtual ~vtkDataSetToScaledDataSet();
     /// Apply the scaling and add metadata
-    vtkUnstructuredGrid* execute(double xScale, double yScale, double zScale, vtkUnstructuredGrid * inputData, vtkInformation* info);
+    vtkPointSet* execute(double xScale, double yScale, double zScale, vtkPointSet * inputData, vtkInformation* info);
     /// Apply the scaling and add metadata
-    vtkUnstructuredGrid* execute(double xScale, double yScale, double zScale, vtkUnstructuredGrid * inputData, vtkUnstructuredGrid * outputData = NULL);
+    vtkPointSet* execute(double xScale, double yScale, double zScale, vtkPointSet * inputData, vtkPointSet * outputData = NULL);
   private:
     vtkDataSetToScaledDataSet& operator=(const vtkDataSetToScaledDataSet& other);
     /// Set metadata on the dataset to handle scaling
     void updateMetaData(double xScale, double yScale,
-                        double zScale, vtkUnstructuredGrid* inputData, vtkUnstructuredGrid * outputData);
+                        double zScale, vtkPointSet* inputData, vtkPointSet * outputData);
   };
 
 } // namespace VATES
diff --git a/Code/Mantid/Vates/VatesAPI/src/vtkDataSetToScaledDataSet.cpp b/Code/Mantid/Vates/VatesAPI/src/vtkDataSetToScaledDataSet.cpp
index a5335067f20..ec1590cf4a6 100644
--- a/Code/Mantid/Vates/VatesAPI/src/vtkDataSetToScaledDataSet.cpp
+++ b/Code/Mantid/Vates/VatesAPI/src/vtkDataSetToScaledDataSet.cpp
@@ -6,7 +6,7 @@
 #include <vtkNew.h>
 #include <vtkPoints.h>
 #include <vtkUnsignedCharArray.h>
-#include <vtkUnstructuredGrid.h>
+#include <vtkPointSet.h>
 #include <vtkSmartPointer.h>
 #include <vtkMatrix4x4.h>
 #include <vtkPVChangeOfBasisHelper.h>
@@ -40,12 +40,12 @@ vtkDataSetToScaledDataSet::~vtkDataSetToScaledDataSet() {}
  * @param info : The dataset to scale
  * @return The resulting scaled dataset
  */
-vtkUnstructuredGrid *
+vtkPointSet *
 vtkDataSetToScaledDataSet::execute(double xScale, double yScale, double zScale,
-                                   vtkUnstructuredGrid *inputData, vtkInformation* info) {
+                                   vtkPointSet *inputData, vtkInformation* info) {
 
   // Extract output dataset from information.
-  vtkUnstructuredGrid *outputData = vtkUnstructuredGrid::SafeDownCast(info->Get(vtkDataObject::DATA_OBJECT()));
+  vtkPointSet *outputData = vtkPointSet::SafeDownCast(info->Get(vtkDataObject::DATA_OBJECT()));
 
   return execute(xScale, yScale, zScale, inputData, outputData);
 
@@ -67,17 +67,17 @@ vtkDataSetToScaledDataSet::execute(double xScale, double yScale, double zScale,
  * @param outputData : The output dataset. Optional. If not specified or null, new one created.
  * @return The resulting scaled dataset
  */
-vtkUnstructuredGrid *
+vtkPointSet *
 vtkDataSetToScaledDataSet::execute(double xScale, double yScale, double zScale,
-                                   vtkUnstructuredGrid *inputData, vtkUnstructuredGrid* outputData) {
+                                   vtkPointSet *inputData, vtkPointSet* outputData) {
 
   if (NULL == inputData) {
     throw std::runtime_error("Cannot construct vtkDataSetToScaledDataSet with "
-                             "NULL input vtkUnstructuredGrid");
+                             "NULL input vtkPointSet");
   }
 
   if(outputData == NULL){
-       outputData = vtkUnstructuredGrid::New();
+       outputData = inputData->NewInstance();
   }
 
   vtkPoints *points = inputData->GetPoints();
@@ -117,7 +117,7 @@ vtkDataSetToScaledDataSet::execute(double xScale, double yScale, double zScale,
  * @param outputData : Output dataset
  */
 void vtkDataSetToScaledDataSet::updateMetaData(double xScale, double yScale,
-                                               double zScale, vtkUnstructuredGrid *inputData, vtkUnstructuredGrid *outputData) {
+                                               double zScale, vtkPointSet *inputData, vtkPointSet *outputData) {
   // We need to put the scaling on the diagonal elements of the ChangeOfBasis
   // (COB) Matrix.
   vtkSmartPointer<vtkMatrix4x4> cobMatrix =
diff --git a/Code/Mantid/Vates/VatesAPI/test/vtkDataSetToScaledDataSetTest.h b/Code/Mantid/Vates/VatesAPI/test/vtkDataSetToScaledDataSetTest.h
index b7caf816535..c95a8310ad3 100644
--- a/Code/Mantid/Vates/VatesAPI/test/vtkDataSetToScaledDataSetTest.h
+++ b/Code/Mantid/Vates/VatesAPI/test/vtkDataSetToScaledDataSetTest.h
@@ -22,6 +22,7 @@
 #include <vtkSmartPointer.h>
 #include <vtkUnsignedCharArray.h>
 #include <vtkUnstructuredGrid.h>
+#include <vtkPointSet.h>
 
 using namespace Mantid::DataObjects;
 using namespace Mantid::VATES;
@@ -80,7 +81,7 @@ public:
 
     vtkDataSetToScaledDataSet scaler;
     vtkUnstructuredGrid *in = makeDataSet();
-    vtkUnstructuredGrid* out = scaler.execute(0.1, 0.5, 0.2, in);
+    vtkPointSet* out = scaler.execute(0.1, 0.5, 0.2, in);
 
     // Check bounds are scaled
     double *bb = out->GetBounds();
@@ -135,7 +136,7 @@ public:
 
     // Act
     vtkDataSetToScaledDataSet scaler;
-    vtkUnstructuredGrid* out = scaler.execute(0.1, 0.5, 0.2, in);
+    vtkPointSet* out = scaler.execute(0.1, 0.5, 0.2, in);
 
     vtkFieldData *fieldData = out->GetFieldData();
     MetadataJsonManager manager;
diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/StandardView.h b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/StandardView.h
index 39cbc4be2bb..dabe4519512 100644
--- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/StandardView.h
+++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/StandardView.h
@@ -91,6 +91,8 @@ protected slots:
   void onScaleButtonClicked();
   /// On BinMD button clicked
   void onRebin();
+  /// On scale completed
+  void onScaleRepresentationAdded(pqPipelineSource *, pqDataRepresentation* , int);
 
 private:
   Q_DISABLE_COPY(StandardView)
@@ -128,8 +130,11 @@ private:
   static QString g_binMDToolTipTxt;
   static QString g_sliceMDToolTipTxt;
   static QString g_cutMDToolTipTxt;
-
   static QMap<QString, QString> g_actionToAlgName;
+  /// wire frame representation key
+  static const std::string SurfaceRepresentation;
+  /// surface representation key
+  static const std::string WireFrameRepresentation;
 };
 
 } // SimpleGui
diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/StandardView.cpp b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/StandardView.cpp
index 56107ed6f41..07b671e33b1 100644
--- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/StandardView.cpp
+++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/StandardView.cpp
@@ -80,6 +80,8 @@ const QString tipAfter = " Mantid algorithm (the algorithm dialog will show up)"
 QString StandardView::g_binMDToolTipTxt = tipBefore + g_binMDName + tipAfter;
 QString StandardView::g_sliceMDToolTipTxt = tipBefore + g_sliceMDName + tipAfter;
 QString StandardView::g_cutMDToolTipTxt = tipBefore + g_cutMDName + tipAfter;
+const std::string StandardView::SurfaceRepresentation  = "Surface";
+const std::string StandardView::WireFrameRepresentation  = "Wireframe";
 
 // To map action labels to algorithm names
 QMap<QString, QString> StandardView::g_actionToAlgName;
@@ -206,12 +208,12 @@ void StandardView::render()
   // Show the data
   pqDataRepresentation *drep = builder->createDataRepresentation(\
         this->origSrc->getOutputPort(0), this->m_view);
-  QString reptype = "Surface";
+  std::string reptype = StandardView::SurfaceRepresentation;
   if (this->isPeaksWorkspace(this->origSrc))
   {
-    reptype = "Wireframe";
+    reptype = StandardView::WireFrameRepresentation;
   }
-  vtkSMPropertyHelper(drep->getProxy(), "Representation").Set(reptype.toStdString().c_str());
+  vtkSMPropertyHelper(drep->getProxy(), "Representation").Set(reptype.c_str());
   drep->getProxy()->UpdateVTKObjects();
   this->origRep = qobject_cast<pqPipelineRepresentation*>(drep);
   if (!this->isPeaksWorkspace(this->origSrc))
@@ -242,6 +244,15 @@ void StandardView::onScaleButtonClicked()
   this->m_scaler = builder->createFilter("filters",
                                        "MantidParaViewScaleWorkspace",
                                        this->getPvActiveSrc());
+
+  /*
+   Paraview will try to set the respresentation to Outline. This is not good. Instead we listen for the
+   represnetation added as a result of the filter completion, and change the representation to be
+   Surface instead.
+   */
+  QObject::connect(this->m_scaler, SIGNAL(representationAdded (pqPipelineSource *, pqDataRepresentation* , int)), this,
+                                          SLOT(onScaleRepresentationAdded(pqPipelineSource *, pqDataRepresentation* , int)));
+
 }
 
 /**
@@ -344,6 +355,15 @@ void StandardView::onRebin()
   }
 }
 
+/**
+ * react to the addition of the representation and change it's type to be Surface
+ * @param representation : representation to modify
+ */
+void StandardView::onScaleRepresentationAdded(pqPipelineSource *, pqDataRepresentation * representation, int)
+{
+    vtkSMPropertyHelper(representation->getProxy(), "Representation").Set(StandardView::SurfaceRepresentation.c_str());
+}
+
 /**
 Disable rebinning options
 */
-- 
GitLab