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
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
......
......@@ -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)) {
......
......@@ -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;
......
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