diff --git a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetToScaledDataSet.h b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetToScaledDataSet.h index e7b02efe328f7cfd049568dfe67e80018e81902d..d7d9e205f664c959ce640b250b1508a716188e4e 100644 --- a/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetToScaledDataSet.h +++ b/Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkDataSetToScaledDataSet.h @@ -43,21 +43,16 @@ namespace VATES vtkUnstructuredGrid *output); /// Destructor virtual ~vtkDataSetToScaledDataSet(); - /// Set the scaling factors - void initialize(double xScale, double yScale, double zScale); /// Apply the scaling and add metadata - void execute(); + void execute(double xScale, double yScale, double zScale); private: vtkDataSetToScaledDataSet& operator=(const vtkDataSetToScaledDataSet& other); /// Set metadata on the dataset to handle scaling - void updateMetaData(); + void updateMetaData(double xScale, double yScale, + double zScale); vtkUnstructuredGrid *m_inputData; ///< Data to scale vtkUnstructuredGrid *m_outputData; ///< Scaled data - double m_xScaling; ///< The scale factor in the X direction - double m_yScaling; ///< The scale factor in the Y direction - double m_zScaling; ///< The scale factor in the Z direction - bool m_isInitialised; ///< Flag to declare object initialised }; } // namespace VATES diff --git a/Code/Mantid/Vates/VatesAPI/src/vtkDataSetToScaledDataSet.cpp b/Code/Mantid/Vates/VatesAPI/src/vtkDataSetToScaledDataSet.cpp index c18bdf281068c0aab32fa1c9a8e2cd9b227b1fc3..d52ea8da7722bba70c218944192e7613ec8dd83b 100644 --- a/Code/Mantid/Vates/VatesAPI/src/vtkDataSetToScaledDataSet.cpp +++ b/Code/Mantid/Vates/VatesAPI/src/vtkDataSetToScaledDataSet.cpp @@ -27,8 +27,7 @@ namespace VATES { */ vtkDataSetToScaledDataSet::vtkDataSetToScaledDataSet( vtkUnstructuredGrid *input, vtkUnstructuredGrid *output) - : m_inputData(input), m_outputData(output), m_xScaling(1.0), - m_yScaling(1.0), m_zScaling(1.0), m_isInitialised(false) { + : m_inputData(input), m_outputData(output){ if (NULL == m_inputData) { throw std::runtime_error("Cannot construct vtkDataSetToScaledDataSet with " "NULL input vtkUnstructuredGrid"); @@ -42,29 +41,14 @@ vtkDataSetToScaledDataSet::vtkDataSetToScaledDataSet( vtkDataSetToScaledDataSet::~vtkDataSetToScaledDataSet() {} /** - * Set the scaling factors for the data, once run, the object is now - * initialised. + * Process the input data. First, scale a copy of the points and apply + * that to the output data. Next, update the metadata for range information. * @param xScale : Scale factor for the x direction * @param yScale : Scale factor for the y direction * @param zScale : Scale factor for the z direction */ -void vtkDataSetToScaledDataSet::initialize(double xScale, double yScale, - double zScale) { - m_xScaling = xScale; - m_yScaling = yScale; - m_zScaling = zScale; - m_isInitialised = true; -} - -/** - * Process the input data. First, scale a copy of the points and apply - * that to the output data. Next, update the metadata for range information. - */ -void vtkDataSetToScaledDataSet::execute() { - if (!m_isInitialised) { - throw std::runtime_error( - "vtkDataSetToScaledDataSet needs initialize run before executing"); - } +void vtkDataSetToScaledDataSet::execute(double xScale, double yScale, + double zScale) { vtkPoints *points = m_inputData->GetPoints(); @@ -73,16 +57,16 @@ void vtkDataSetToScaledDataSet::execute() { newPoints->Allocate(points->GetNumberOfPoints()); for (int i = 0; i < points->GetNumberOfPoints(); i++) { point = points->GetPoint(i); - point[0] *= m_xScaling; - point[1] *= m_yScaling; - point[2] *= m_zScaling; + point[0] *= xScale; + point[1] *= yScale; + point[2] *= zScale; newPoints->InsertNextPoint(point); } // Shallow copy the input. m_outputData->ShallowCopy(m_inputData); // Give the output dataset the scaled set of points. m_outputData->SetPoints(newPoints); - this->updateMetaData(); + this->updateMetaData(xScale, yScale, zScale); } /** @@ -94,16 +78,20 @@ void vtkDataSetToScaledDataSet::execute() { * and * http://www.paraview.org/ParaView/Doc/Nightly/www/cxx-doc/classvtkPVChangeOfBasisHelper.html * for a better understanding. + * @param xScale : Scale factor for the x direction + * @param yScale : Scale factor for the y direction + * @param zScale : Scale factor for the z direction */ -void vtkDataSetToScaledDataSet::updateMetaData() { +void vtkDataSetToScaledDataSet::updateMetaData(double xScale, double yScale, + double zScale) { // We need to put the scaling on the diagonal elements of the ChangeOfBasis // (COB) Matrix. vtkSmartPointer<vtkMatrix4x4> cobMatrix = vtkSmartPointer<vtkMatrix4x4>::New(); cobMatrix->Identity(); - cobMatrix->Element[0][0] *= m_xScaling; - cobMatrix->Element[1][1] *= m_yScaling; - cobMatrix->Element[2][2] *= m_zScaling; + cobMatrix->Element[0][0] *= xScale; + cobMatrix->Element[1][1] *= yScale; + cobMatrix->Element[2][2] *= zScale; if (!vtkPVChangeOfBasisHelper::AddChangeOfBasisMatrixToFieldData(m_outputData, cobMatrix)) { diff --git a/Code/Mantid/Vates/VatesAPI/test/vtkDataSetToScaledDataSetTest.h b/Code/Mantid/Vates/VatesAPI/test/vtkDataSetToScaledDataSetTest.h index 8235b3d61b2387f3b3fef24087a6a4c121fe31b5..ff26639200be1006e8be500f684773e5b528f52e 100644 --- a/Code/Mantid/Vates/VatesAPI/test/vtkDataSetToScaledDataSetTest.h +++ b/Code/Mantid/Vates/VatesAPI/test/vtkDataSetToScaledDataSetTest.h @@ -80,19 +80,11 @@ public: std::runtime_error); } - void testExecThrowIfNoInit() { - vtkUnstructuredGrid *in = vtkUnstructuredGrid::New(); - vtkUnstructuredGrid *out = vtkUnstructuredGrid::New(); - vtkDataSetToScaledDataSet scaler(in, out); - TS_ASSERT_THROWS(scaler.execute(), std::runtime_error); - } - void testExecution() { vtkUnstructuredGrid *in = makeDataSet(); vtkUnstructuredGrid *out = vtkUnstructuredGrid::New(); vtkDataSetToScaledDataSet scaler(in, out); - scaler.initialize(0.1, 0.5, 0.2); - TS_ASSERT_THROWS_NOTHING(scaler.execute()); + TS_ASSERT_THROWS_NOTHING(scaler.execute(0.1, 0.5, 0.2)); // Check bounds are scaled double *bb = out->GetBounds(); @@ -148,8 +140,7 @@ public: // Act vtkDataSetToScaledDataSet scaler(in, out); - scaler.initialize(0.1, 0.5, 0.2); - TS_ASSERT_THROWS_NOTHING(scaler.execute()); + TS_ASSERT_THROWS_NOTHING(scaler.execute(0.1, 0.5, 0.2)); vtkFieldData *fieldData = out->GetFieldData(); MetadataJsonManager manager;