From 92ffd9b1b546cd5d192273d5fc83b048a1227bb1 Mon Sep 17 00:00:00 2001
From: Steven Hahn <hahnse@ornl.gov>
Date: Thu, 1 Dec 2016 18:44:49 -0500
Subject: [PATCH] Add makeNonOrthogonal to progress bar.

---
 .../MDHWNexusReader/vtkMDHWNexusReader.cxx    |  3 +-
 .../MDEWSource/vtkMDEWSource.cxx              |  3 +-
 .../MDHWSource/vtkMDHWSource.cxx              |  3 +-
 .../inc/MantidVatesAPI/MDLoadingPresenter.h   |  3 +-
 .../vtkDataSetToNonOrthogonalDataSet.h        | 11 +++----
 .../src/MDHWInMemoryLoadingPresenter.cpp      |  2 +-
 Vates/VatesAPI/src/MDLoadingPresenter.cpp     |  5 ++--
 Vates/VatesAPI/src/PresenterUtilities.cpp     |  3 +-
 .../src/vtkDataSetToNonOrthogonalDataSet.cpp  | 29 ++++++++-----------
 Vates/VatesAPI/src/vtkMDHistoHexFactory.cpp   |  2 +-
 .../vtkDataSetToNonOrthogonalDataSetTest.h    | 11 +------
 11 files changed, 34 insertions(+), 41 deletions(-)

diff --git a/Vates/ParaviewPlugins/ParaViewReaders/MDHWNexusReader/vtkMDHWNexusReader.cxx b/Vates/ParaviewPlugins/ParaViewReaders/MDHWNexusReader/vtkMDHWNexusReader.cxx
index 41a42db9540..f3f12e33b0a 100644
--- a/Vates/ParaviewPlugins/ParaViewReaders/MDHWNexusReader/vtkMDHWNexusReader.cxx
+++ b/Vates/ParaviewPlugins/ParaViewReaders/MDHWNexusReader/vtkMDHWNexusReader.cxx
@@ -126,7 +126,8 @@ int vtkMDHWNexusReader::RequestData(
   try {
     auto workspaceProvider = Mantid::Kernel::make_unique<
         ADSWorkspaceProvider<Mantid::API::IMDWorkspace>>();
-    m_presenter->makeNonOrthogonal(output, std::move(workspaceProvider));
+    m_presenter->makeNonOrthogonal(output, std::move(workspaceProvider),
+                                   &drawingProgressAction);
   } catch (std::invalid_argument &e) {
     std::string error = e.what();
     vtkDebugMacro(<< "Workspace does not have correct information to "
diff --git a/Vates/ParaviewPlugins/ParaViewSources/MDEWSource/vtkMDEWSource.cxx b/Vates/ParaviewPlugins/ParaViewSources/MDEWSource/vtkMDEWSource.cxx
index e37faba2cf5..86c98e0ac9a 100644
--- a/Vates/ParaviewPlugins/ParaViewSources/MDEWSource/vtkMDEWSource.cxx
+++ b/Vates/ParaviewPlugins/ParaViewSources/MDEWSource/vtkMDEWSource.cxx
@@ -210,7 +210,8 @@ int vtkMDEWSource::RequestData(vtkInformation *, vtkInformationVector **, vtkInf
     try
     {
       auto workspaceProvider = Mantid::Kernel::make_unique<ADSWorkspaceProvider<Mantid::API::IMDWorkspace>>();
-      m_presenter->makeNonOrthogonal(output, std::move(workspaceProvider));
+      m_presenter->makeNonOrthogonal(output, std::move(workspaceProvider),
+                                     &drawingProgressUpdate);
     }
     catch (std::invalid_argument &e)
     {
diff --git a/Vates/ParaviewPlugins/ParaViewSources/MDHWSource/vtkMDHWSource.cxx b/Vates/ParaviewPlugins/ParaViewSources/MDHWSource/vtkMDHWSource.cxx
index aaa375173a8..22b43222196 100644
--- a/Vates/ParaviewPlugins/ParaViewSources/MDHWSource/vtkMDHWSource.cxx
+++ b/Vates/ParaviewPlugins/ParaViewSources/MDHWSource/vtkMDHWSource.cxx
@@ -181,7 +181,8 @@ int vtkMDHWSource::RequestData(vtkInformation *, vtkInformationVector **, vtkInf
     try
     {
       auto workspaceProvider = Mantid::Kernel::make_unique<ADSWorkspaceProvider<Mantid::API::IMDWorkspace>>();
-      m_presenter->makeNonOrthogonal(output, std::move(workspaceProvider));
+      m_presenter->makeNonOrthogonal(output, std::move(workspaceProvider),
+                                     &drawingProgressUpdate);
     }
     catch (std::invalid_argument &e)
     {
diff --git a/Vates/VatesAPI/inc/MantidVatesAPI/MDLoadingPresenter.h b/Vates/VatesAPI/inc/MantidVatesAPI/MDLoadingPresenter.h
index 5fafd8b5a61..4c783473bc7 100644
--- a/Vates/VatesAPI/inc/MantidVatesAPI/MDLoadingPresenter.h
+++ b/Vates/VatesAPI/inc/MantidVatesAPI/MDLoadingPresenter.h
@@ -57,7 +57,8 @@ public:
   virtual void setDefaultCOBandBoundaries(vtkDataSet *visualDataSet);
   virtual void makeNonOrthogonal(
       vtkDataSet *visualDataSet,
-      std::unique_ptr<Mantid::VATES::WorkspaceProvider> workspaceProvider);
+      std::unique_ptr<Mantid::VATES::WorkspaceProvider> workspaceProvider,
+      ProgressAction *progress);
   virtual bool canReadFile() const = 0;
   virtual const std::string &getGeometryXML() const = 0;
   virtual ~MDLoadingPresenter() {}
diff --git a/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetToNonOrthogonalDataSet.h b/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetToNonOrthogonalDataSet.h
index 908dfacf9d2..fc7a859d280 100644
--- a/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetToNonOrthogonalDataSet.h
+++ b/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetToNonOrthogonalDataSet.h
@@ -1,13 +1,14 @@
 #ifndef MANTID_VATES_VTKDATASETTONONORTHOGONALDATASET_H_
 #define MANTID_VATES_VTKDATASETTONONORTHOGONALDATASET_H_
 
-#include "MantidVatesAPI/WorkspaceProvider.h"
+#include "MantidGeometry/MDGeometry/MDTypes.h"
+#include "MantidKernel/Matrix.h"
 #include "MantidKernel/SpecialCoordinateSystem.h"
 #include "MantidKernel/System.h"
-#include "MantidKernel/cow_ptr.h"
-#include "MantidKernel/Matrix.h"
 #include "MantidKernel/V3D.h"
-#include "MantidGeometry/MDGeometry/MDTypes.h"
+#include "MantidKernel/cow_ptr.h"
+#include "MantidVatesAPI/ProgressAction.h"
+#include "MantidVatesAPI/WorkspaceProvider.h"
 
 #include <string>
 #include <array>
@@ -58,7 +59,7 @@ public:
       vtkDataSet *dataset, std::string name,
       std::unique_ptr<Mantid::VATES::WorkspaceProvider> workspaceProvider);
   /// Class execution method
-  void execute();
+  void execute(ProgressAction *progress = nullptr);
   /// Destructor
   virtual ~vtkDataSetToNonOrthogonalDataSet();
 
diff --git a/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp b/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp
index 0c029f0654b..d42ed6515e8 100644
--- a/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp
+++ b/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp
@@ -68,7 +68,7 @@ bool MDHWInMemoryLoadingPresenter::canReadFile() const {
 namespace {
 class CellVisibility {
 public:
-  CellVisibility(vtkStructuredGrid *structuredGrid)
+  explicit CellVisibility(vtkStructuredGrid *structuredGrid)
       : MASKED_CELL_VALUE(vtkDataSetAttributes::HIDDENCELL |
                           vtkDataSetAttributes::REFINEDCELL),
         InputCellGhostArray(
diff --git a/Vates/VatesAPI/src/MDLoadingPresenter.cpp b/Vates/VatesAPI/src/MDLoadingPresenter.cpp
index 90e45ff14b3..680554c7703 100644
--- a/Vates/VatesAPI/src/MDLoadingPresenter.cpp
+++ b/Vates/VatesAPI/src/MDLoadingPresenter.cpp
@@ -41,11 +41,12 @@ void MDLoadingPresenter::setDefaultCOBandBoundaries(vtkDataSet *visualDataSet) {
  */
 void MDLoadingPresenter::makeNonOrthogonal(
     vtkDataSet *visualDataSet,
-    std::unique_ptr<Mantid::VATES::WorkspaceProvider> workspaceProvider) {
+    std::unique_ptr<Mantid::VATES::WorkspaceProvider> workspaceProvider,
+    ProgressAction *progress) {
   std::string wsName = vtkDataSetToWsName::exec(visualDataSet);
   vtkDataSetToNonOrthogonalDataSet converter(visualDataSet, wsName,
                                              std::move(workspaceProvider));
-  converter.execute();
+  converter.execute(progress);
 }
 }
 }
diff --git a/Vates/VatesAPI/src/PresenterUtilities.cpp b/Vates/VatesAPI/src/PresenterUtilities.cpp
index 4062c83c404..6e6761abea5 100644
--- a/Vates/VatesAPI/src/PresenterUtilities.cpp
+++ b/Vates/VatesAPI/src/PresenterUtilities.cpp
@@ -56,7 +56,8 @@ void applyCOBMatrixSettingsToVtkDataSet(
     Mantid::VATES::MDLoadingPresenter *presenter, vtkDataSet *dataSet,
     std::unique_ptr<Mantid::VATES::WorkspaceProvider> workspaceProvider) {
   try {
-    presenter->makeNonOrthogonal(dataSet, std::move(workspaceProvider));
+    presenter->makeNonOrthogonal(dataSet, std::move(workspaceProvider),
+                                 nullptr);
   } catch (std::invalid_argument &e) {
     std::string error = e.what();
     g_log_presenter_utilities.warning()
diff --git a/Vates/VatesAPI/src/vtkDataSetToNonOrthogonalDataSet.cpp b/Vates/VatesAPI/src/vtkDataSetToNonOrthogonalDataSet.cpp
index 14217faf1e2..717e4dd7207 100644
--- a/Vates/VatesAPI/src/vtkDataSetToNonOrthogonalDataSet.cpp
+++ b/Vates/VatesAPI/src/vtkDataSetToNonOrthogonalDataSet.cpp
@@ -73,21 +73,6 @@ void addChangeOfBasisMatrixToFieldData(
 namespace Mantid {
 namespace VATES {
 
-/**
- * This function constructs and executes the helper class.
- * @param dataset : The VTK data to modify
- * @param name : The MDWorkspace containing the information to construct.
- * @param workspaceProvider: The provider of one or multiple workspaces.
-
- */
-void vtkDataSetToNonOrthogonalDataSet::exec(
-    vtkDataSet *dataset, std::string name,
-    std::unique_ptr<WorkspaceProvider> workspaceProvider) {
-  vtkDataSetToNonOrthogonalDataSet temp(dataset, name,
-                                        std::move(workspaceProvider));
-  temp.execute();
-}
-
 /**
  * This is the private class constructor.
  * @param dataset : The VTK data to modify
@@ -118,7 +103,7 @@ vtkDataSetToNonOrthogonalDataSet::vtkDataSetToNonOrthogonalDataSet(
  */
 vtkDataSetToNonOrthogonalDataSet::~vtkDataSetToNonOrthogonalDataSet() {}
 
-void vtkDataSetToNonOrthogonalDataSet::execute() {
+void vtkDataSetToNonOrthogonalDataSet::execute(ProgressAction *progress) {
   // Downcast to a vtkPointSet
   vtkPointSet *data = vtkPointSet::SafeDownCast(m_dataSet);
   if (NULL == data) {
@@ -234,9 +219,19 @@ void vtkDataSetToNonOrthogonalDataSet::execute() {
   } else if (points->GetNumberOfComponents() != 3) {
     throw std::runtime_error("points array must have 3 components.");
   }
+  float *end = points->GetPointer(points->GetNumberOfValues());
+
+  vtkIdType progressIncrement = points->GetNumberOfValues() / 25;
+
+  double progressFactor = 0.25 / points->GetNumberOfValues();
 
-  float *end = points->GetPointer(points->GetNumberOfTuples() * 3);
   for (float *it = points->GetPointer(0); it < end; std::advance(it, 3)) {
+    if (progress) {
+      vtkIdType index = std::distance(points->GetPointer(0), it);
+      if (index % progressIncrement == 0)
+        progress->eventRaised(0.75 +
+                              static_cast<double>(index) * progressFactor);
+    }
     float v1 = it[0];
     float v2 = it[1];
     float v3 = it[2];
diff --git a/Vates/VatesAPI/src/vtkMDHistoHexFactory.cpp b/Vates/VatesAPI/src/vtkMDHistoHexFactory.cpp
index 0ab69b0e10d..19a6cabfa64 100644
--- a/Vates/VatesAPI/src/vtkMDHistoHexFactory.cpp
+++ b/Vates/VatesAPI/src/vtkMDHistoHexFactory.cpp
@@ -171,7 +171,7 @@ vtkMDHistoHexFactory::create3Dor4D(size_t timestep,
   }
   float *it = pointsarray->WritePointer(0, nPointsX * nPointsY * nPointsZ * 3);
   // Array with the point IDs (only set where needed)
-  progressFactor = 0.5 / static_cast<double>(nPointsZ);
+  progressFactor = 0.25 / static_cast<double>(nPointsZ);
   double progressOffset = 0.5;
   for (int z = 0; z < nPointsZ; z++) {
     // Report progress updates for the last 50%
diff --git a/Vates/VatesAPI/test/vtkDataSetToNonOrthogonalDataSetTest.h b/Vates/VatesAPI/test/vtkDataSetToNonOrthogonalDataSetTest.h
index 53e882eefdd..64ef83f3759 100644
--- a/Vates/VatesAPI/test/vtkDataSetToNonOrthogonalDataSetTest.h
+++ b/Vates/VatesAPI/test/vtkDataSetToNonOrthogonalDataSetTest.h
@@ -33,6 +33,7 @@ using namespace Mantid::VATES;
 
 class vtkDataSetToNonOrthogonalDataSetTest : public CxxTest::TestSuite {
 private:
+  MockProgressAction progress;
   std::string
   createMantidWorkspace(bool nonUnityTransform, bool wrongCoords = false,
                         bool forgetUB = false, bool forgetWmat = false,
@@ -271,16 +272,6 @@ public:
     TS_ASSERT_THROWS_NOTHING(converter.execute());
   }
 
-  void testStaticUseForSimpleDataSet() {
-    std::string wsName = createMantidWorkspace(false);
-    vtkSmartPointer<vtkUnstructuredGrid> ds;
-    ds.TakeReference(createSingleVoxelPoints());
-    auto workspaceProvider = Mantid::Kernel::make_unique<
-        ADSWorkspaceProvider<Mantid::API::IMDWorkspace>>();
-    TS_ASSERT_THROWS_NOTHING(vtkDataSetToNonOrthogonalDataSet::exec(
-        ds, wsName, std::move(workspaceProvider)));
-  }
-
   void testNonUnitySimpleDataset() {
     std::string wsName = createMantidWorkspace(true);
     vtkSmartPointer<vtkUnstructuredGrid> ds;
-- 
GitLab