-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #12396. Add vtkNullStructuredGrid class and test.
- Loading branch information
1 parent
e23fab3
commit 88d2c1e
Showing
5 changed files
with
142 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkNullStructuredGrid.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
37
Code/Mantid/Vates/VatesAPI/test/vtkNullStructuredGridTest.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |