Skip to content
Snippets Groups Projects
Commit afc7c6a2 authored by Owen Arnold's avatar Owen Arnold
Browse files

refs #13523. Fix bad class API.

Constructor or constructional objects for construction only! Looking at the use case for this, the initialize method servered no purpose other than to introduce more state, more sequential checks, and more lines of code.
parent 682a9de3
No related branches found
No related tags found
No related merge requests found
...@@ -43,21 +43,16 @@ namespace VATES ...@@ -43,21 +43,16 @@ namespace VATES
vtkUnstructuredGrid *output); vtkUnstructuredGrid *output);
/// Destructor /// Destructor
virtual ~vtkDataSetToScaledDataSet(); virtual ~vtkDataSetToScaledDataSet();
/// Set the scaling factors
void initialize(double xScale, double yScale, double zScale);
/// Apply the scaling and add metadata /// Apply the scaling and add metadata
void execute(); void execute(double xScale, double yScale, double zScale);
private: private:
vtkDataSetToScaledDataSet& operator=(const vtkDataSetToScaledDataSet& other); vtkDataSetToScaledDataSet& operator=(const vtkDataSetToScaledDataSet& other);
/// Set metadata on the dataset to handle scaling /// 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_inputData; ///< Data to scale
vtkUnstructuredGrid *m_outputData; ///< Scaled data 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 } // namespace VATES
......
...@@ -27,8 +27,7 @@ namespace VATES { ...@@ -27,8 +27,7 @@ namespace VATES {
*/ */
vtkDataSetToScaledDataSet::vtkDataSetToScaledDataSet( vtkDataSetToScaledDataSet::vtkDataSetToScaledDataSet(
vtkUnstructuredGrid *input, vtkUnstructuredGrid *output) vtkUnstructuredGrid *input, vtkUnstructuredGrid *output)
: m_inputData(input), m_outputData(output), m_xScaling(1.0), : m_inputData(input), m_outputData(output){
m_yScaling(1.0), m_zScaling(1.0), m_isInitialised(false) {
if (NULL == m_inputData) { if (NULL == m_inputData) {
throw std::runtime_error("Cannot construct vtkDataSetToScaledDataSet with " throw std::runtime_error("Cannot construct vtkDataSetToScaledDataSet with "
"NULL input vtkUnstructuredGrid"); "NULL input vtkUnstructuredGrid");
...@@ -42,29 +41,14 @@ vtkDataSetToScaledDataSet::vtkDataSetToScaledDataSet( ...@@ -42,29 +41,14 @@ vtkDataSetToScaledDataSet::vtkDataSetToScaledDataSet(
vtkDataSetToScaledDataSet::~vtkDataSetToScaledDataSet() {} vtkDataSetToScaledDataSet::~vtkDataSetToScaledDataSet() {}
/** /**
* Set the scaling factors for the data, once run, the object is now * Process the input data. First, scale a copy of the points and apply
* initialised. * that to the output data. Next, update the metadata for range information.
* @param xScale : Scale factor for the x direction * @param xScale : Scale factor for the x direction
* @param yScale : Scale factor for the y direction * @param yScale : Scale factor for the y direction
* @param zScale : Scale factor for the z direction * @param zScale : Scale factor for the z direction
*/ */
void vtkDataSetToScaledDataSet::initialize(double xScale, double yScale, void vtkDataSetToScaledDataSet::execute(double xScale, double yScale,
double zScale) { 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");
}
vtkPoints *points = m_inputData->GetPoints(); vtkPoints *points = m_inputData->GetPoints();
...@@ -73,16 +57,16 @@ void vtkDataSetToScaledDataSet::execute() { ...@@ -73,16 +57,16 @@ void vtkDataSetToScaledDataSet::execute() {
newPoints->Allocate(points->GetNumberOfPoints()); newPoints->Allocate(points->GetNumberOfPoints());
for (int i = 0; i < points->GetNumberOfPoints(); i++) { for (int i = 0; i < points->GetNumberOfPoints(); i++) {
point = points->GetPoint(i); point = points->GetPoint(i);
point[0] *= m_xScaling; point[0] *= xScale;
point[1] *= m_yScaling; point[1] *= yScale;
point[2] *= m_zScaling; point[2] *= zScale;
newPoints->InsertNextPoint(point); newPoints->InsertNextPoint(point);
} }
// Shallow copy the input. // Shallow copy the input.
m_outputData->ShallowCopy(m_inputData); m_outputData->ShallowCopy(m_inputData);
// Give the output dataset the scaled set of points. // Give the output dataset the scaled set of points.
m_outputData->SetPoints(newPoints); m_outputData->SetPoints(newPoints);
this->updateMetaData(); this->updateMetaData(xScale, yScale, zScale);
} }
/** /**
...@@ -94,16 +78,20 @@ void vtkDataSetToScaledDataSet::execute() { ...@@ -94,16 +78,20 @@ void vtkDataSetToScaledDataSet::execute() {
* and * and
* http://www.paraview.org/ParaView/Doc/Nightly/www/cxx-doc/classvtkPVChangeOfBasisHelper.html * http://www.paraview.org/ParaView/Doc/Nightly/www/cxx-doc/classvtkPVChangeOfBasisHelper.html
* for a better understanding. * 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 // We need to put the scaling on the diagonal elements of the ChangeOfBasis
// (COB) Matrix. // (COB) Matrix.
vtkSmartPointer<vtkMatrix4x4> cobMatrix = vtkSmartPointer<vtkMatrix4x4> cobMatrix =
vtkSmartPointer<vtkMatrix4x4>::New(); vtkSmartPointer<vtkMatrix4x4>::New();
cobMatrix->Identity(); cobMatrix->Identity();
cobMatrix->Element[0][0] *= m_xScaling; cobMatrix->Element[0][0] *= xScale;
cobMatrix->Element[1][1] *= m_yScaling; cobMatrix->Element[1][1] *= yScale;
cobMatrix->Element[2][2] *= m_zScaling; cobMatrix->Element[2][2] *= zScale;
if (!vtkPVChangeOfBasisHelper::AddChangeOfBasisMatrixToFieldData(m_outputData, if (!vtkPVChangeOfBasisHelper::AddChangeOfBasisMatrixToFieldData(m_outputData,
cobMatrix)) { cobMatrix)) {
......
...@@ -80,19 +80,11 @@ public: ...@@ -80,19 +80,11 @@ public:
std::runtime_error); 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() { void testExecution() {
vtkUnstructuredGrid *in = makeDataSet(); vtkUnstructuredGrid *in = makeDataSet();
vtkUnstructuredGrid *out = vtkUnstructuredGrid::New(); vtkUnstructuredGrid *out = vtkUnstructuredGrid::New();
vtkDataSetToScaledDataSet scaler(in, out); vtkDataSetToScaledDataSet scaler(in, out);
scaler.initialize(0.1, 0.5, 0.2); TS_ASSERT_THROWS_NOTHING(scaler.execute(0.1, 0.5, 0.2));
TS_ASSERT_THROWS_NOTHING(scaler.execute());
// Check bounds are scaled // Check bounds are scaled
double *bb = out->GetBounds(); double *bb = out->GetBounds();
...@@ -148,8 +140,7 @@ public: ...@@ -148,8 +140,7 @@ public:
// Act // Act
vtkDataSetToScaledDataSet scaler(in, out); vtkDataSetToScaledDataSet scaler(in, out);
scaler.initialize(0.1, 0.5, 0.2); TS_ASSERT_THROWS_NOTHING(scaler.execute(0.1, 0.5, 0.2));
TS_ASSERT_THROWS_NOTHING(scaler.execute());
vtkFieldData *fieldData = out->GetFieldData(); vtkFieldData *fieldData = out->GetFieldData();
MetadataJsonManager manager; MetadataJsonManager manager;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment