Skip to content

Commit

Permalink
Refs #12396. Add vtkNullStructuredGrid class and test.
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumsteve committed Jul 16, 2015
1 parent e23fab3 commit 88d2c1e
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Vates/VatesAPI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ src/vtkEllipsoidTransformer.cpp
src/vtkMDLineFactory.cpp
src/vtkMDQuadFactory.cpp
src/vtkMD0DFactory.cpp
src/vtkNullStructuredGrid.cpp
src/vtkNullUnstructuredGrid.cpp
src/vtkSplatterPlotFactory.cpp
src/vtkMDHexFactory.cpp
Expand Down Expand Up @@ -119,6 +120,7 @@ inc/MantidVatesAPI/vtkMDLineFactory.h
inc/MantidVatesAPI/vtkMDQuadFactory.h
inc/MantidVatesAPI/vtkMDHexFactory.h
inc/MantidVatesAPI/vtkMD0DFactory.h
inc/MantidVatesAPI/vtkNullStructuredGrid.h
inc/MantidVatesAPI/vtkNullUnstructuredGrid.h
inc/MantidVatesAPI/vtkSplatterPlotFactory.h
inc/MantidVatesAPI/vtkPeakMarkerFactory.h
Expand Down Expand Up @@ -180,6 +182,7 @@ test/vtkDataSetToScaledDataSetTest.h
test/vtkDataSetToPeaksFilteredDataSetTest.h
test/vtkDataSetToNonOrthogonalDataSetTest.h
test/vtkNullUnstructuredGridTest.h
test/vtkNullStructuredGridTest.h
test/vtkEllipsoidTransformerTest.h
test/NullPeaksPresenterVsiTest.h
test/ConcretePeaksPresenterVsiTest.h
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef VATES_VTK_STRUCTURED_GRID_NULL_DATA_SET
#define VATES_VTK_STRUCTURED_GRID_NULL_DATA_SET

#include "MantidKernel/System.h"

class vtkStructuredGrid;

namespace Mantid {
namespace VATES {

/** Generates a vtkStructuredGrid with a single point. Note that this is not a
Null Object for a vtkDataSet.
@date 15/07/2015
Copyright © 2012 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

class DLLExport vtkNullStructuredGrid {

public:
vtkNullStructuredGrid();

~vtkNullStructuredGrid();

vtkStructuredGrid *createNullData();
};
}
}
#endif
19 changes: 10 additions & 9 deletions Code/Mantid/Vates/VatesAPI/src/vtkMDHistoHexFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
#include "MantidVatesAPI/Common.h"
#include "MantidVatesAPI/Normalization.h"
#include "MantidVatesAPI/ProgressAction.h"
#include "MantidVatesAPI/vtkNullUnstructuredGrid.h"
#include "MantidVatesAPI/vtkNullStructuredGrid.h"
#include "MantidVatesAPI/vtkMDHistoHexFactory.h"
#include "MantidAPI/NullCoordTransform.h"
#include "MantidKernel/ReadLock.h"

#include "vtkNew.h"
#include "vtkSmartPointer.h"
#include "vtkStructuredGrid.h"
#include "vtkFloatArray.h"
#include "vtkDoubleArray.h"
Expand Down Expand Up @@ -108,8 +109,9 @@ vtkMDHistoHexFactory::create3Dor4D(size_t timestep,
const int nBinsZ = static_cast<int>(m_workspace->getZDimension()->getNBins());

const int imageSize = (nBinsX) * (nBinsY) * (nBinsZ);

vtkNew<vtkStructuredGrid> visualDataSet;

vtkSmartPointer<vtkStructuredGrid> visualDataSet =
vtkSmartPointer<vtkStructuredGrid>::New();
visualDataSet->SetDimensions(nBinsX+1,nBinsY+1,nBinsZ+1);

// Array with true where the voxel should be shown
Expand Down Expand Up @@ -150,13 +152,12 @@ vtkMDHistoHexFactory::create3Dor4D(size_t timestep,
visualDataSet->Register(NULL);
visualDataSet->Squeeze();

// TODO: fix for vtkStructuredGrid
// Hedge against empty data sets
//if (visualDataSet->GetNumberOfPoints() <= 0) {
// visualDataSet->Delete();
// vtkNullUnstructuredGrid nullGrid;
// visualDataSet = nullGrid.createNullData();
//}
if (visualDataSet->GetNumberOfPoints() <= 0) {
visualDataSet->Delete();
vtkNullStructuredGrid nullGrid;
visualDataSet = nullGrid.createNullData();
}

return visualDataSet.GetPointer();
}
Expand Down
43 changes: 43 additions & 0 deletions Code/Mantid/Vates/VatesAPI/src/vtkNullStructuredGrid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "MantidVatesAPI/vtkNullStructuredGrid.h"

#include <vtkNew.h>
#include <vtkIdList.h>
#include <vtkPoints.h>
#include <vtkPointData.h>
#include <vtkFloatArray.h>
#include <vtkSmartPointer.h>
#include <vtkStructuredGrid.h>
#include <iostream>
namespace Mantid {
namespace VATES {

/// Constructor
vtkNullStructuredGrid::vtkNullStructuredGrid() {}

/// Destructor
vtkNullStructuredGrid::~vtkNullStructuredGrid() {}

/**
* Creates a default vtkDataSet.
*@returns A pointer to the default vtkDataSet
*/
vtkStructuredGrid *vtkNullStructuredGrid::createNullData() {

vtkStructuredGrid *dataSet = vtkStructuredGrid::New();
dataSet->SetDimensions(1, 1, 1);
vtkNew<vtkPoints> points;
points->Allocate(1);
points->InsertNextPoint(0.0, 0.0, 0.0);
dataSet->SetPoints(points.GetPointer());

vtkNew<vtkFloatArray> signal;
signal->SetNumberOfComponents(1);
signal->InsertNextTuple1(0.0);
dataSet->GetPointData()->SetScalars(signal.GetPointer());

dataSet->Squeeze();

return dataSet;
}
}
}
37 changes: 37 additions & 0 deletions Code/Mantid/Vates/VatesAPI/test/vtkNullStructuredGridTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef VTKNULLSTRUCTUREDGRID_TEST_H_
#define VTKNULLSTRUCTUREDGRID_TEST_H_

#include "MantidVatesAPI/vtkNullStructuredGrid.h"
#include "MockObjects.h"
#include <cxxtest/TestSuite.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <vtkStructuredGrid.h>
#include <vtkPoints.h>
#include <iostream>

using namespace Mantid::VATES;

class vtkNullStructuredGridTest : public CxxTest::TestSuite {
public:
void testCorrectVtkDataSetIsReturned() {
vtkNullStructuredGrid grid;

vtkStructuredGrid *ugrid = NULL;

TSM_ASSERT_THROWS_NOTHING(
"Should create the unstructured grid without problems.",
ugrid = grid.createNullData());
TSM_ASSERT("Should have exactly one point",
ugrid->GetNumberOfPoints() == 1);
TSM_ASSERT("Should have exactly one cell", ugrid->GetNumberOfCells() == 1);
double coord[3];
ugrid->GetPoint(0, coord);
TSM_ASSERT("X should be in the center", coord[0] == 0.0);
TSM_ASSERT("X should be in the center", coord[1] == 0.0);
TSM_ASSERT("X should be in the center", coord[2] == 0.0);
ugrid->Delete();
}
};
#endif

0 comments on commit 88d2c1e

Please sign in to comment.