Skip to content

Commit

Permalink
Refs #12396. Switch points from double to float.
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumsteve committed Jul 17, 2015
1 parent f9364eb commit 7571013
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
44 changes: 25 additions & 19 deletions Code/Mantid/Vates/VatesAPI/inc/MantidVatesAPI/vtkMDHWPointsArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,13 @@ class vtkMDHWPointsArray : public vtkTypeTemplate<vtkMDHWPointsArray<Scalar>,
vtkMDHWPointsArray(const vtkMDHWPointsArray &); // Not implemented.
void operator=(const vtkMDHWPointsArray &); // Not implemented.

template <class otherScalar>
void GetAnyScalarTupleValue(vtkIdType idx, otherScalar *t);
vtkIdType Lookup(const Scalar &val, vtkIdType startIndex);
Scalar m_skewMatrix[9] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
vtkIdType m_dims[3];
Scalar m_TempScalarArray[3], m_origin[3], m_spacing[3];
double m_tempDoubleArray[3];
Mantid::DataObjects::MDHistoWorkspace *m_workspace;
};

Expand Down Expand Up @@ -222,7 +225,8 @@ void vtkMDHWPointsArray<Scalar>::GetTuples(vtkIdType p1, vtkIdType p2,
}

for (vtkIdType daTupleId = 0; p1 <= p2; ++p1) {
da->SetTuple(daTupleId++, this->GetTuple(p1));
da->SetTuple(daTupleId, this->GetTuple(p1));
++daTupleId;
}
}

Expand Down Expand Up @@ -279,14 +283,14 @@ template <class Scalar> void vtkMDHWPointsArray<Scalar>::ClearLookup() {
//------------------------------------------------------------------------------
template <class Scalar>
double *vtkMDHWPointsArray<Scalar>::GetTuple(vtkIdType i) {
this->GetTuple(i, &m_TempScalarArray[0]);
return &m_TempScalarArray[0];
this->GetAnyScalarTupleValue(i, &m_tempDoubleArray[0]);
return &m_tempDoubleArray[0];
}

//------------------------------------------------------------------------------
template <class Scalar>
void vtkMDHWPointsArray<Scalar>::GetTuple(vtkIdType i, double *tuple) {
this->GetTupleValue(i, tuple);
this->GetAnyScalarTupleValue(i, tuple);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -326,26 +330,28 @@ Scalar &vtkMDHWPointsArray<Scalar>::GetValueReference(vtkIdType idx) {
template <class Scalar>
void vtkMDHWPointsArray<Scalar>::GetTupleValue(vtkIdType tupleId,
Scalar *tuple) {
// int loc[3];
// loc[0] = tupleId % m_dims[0];
// loc[1] = (tupleId / m_dims[0]) % m_dims[1];
// loc[2] = tupleId / (m_dims[0]*m_dims[1]);
this->GetAnyScalarTupleValue(tupleId, tuple);
}

template <class Scalar>
template <class otherScalar>
void vtkMDHWPointsArray<Scalar>::GetAnyScalarTupleValue(vtkIdType tupleId,
otherScalar *tuple) {

const auto tmp1 = std::div(tupleId, m_dims[0]);
const auto tmp2 = std::div(tmp1.quot, m_dims[1]);
const vtkIdType loc[3] = {tmp1.rem, tmp2.rem, tmp2.quot};
const Scalar loc[3] = {static_cast<Scalar>(tmp1.rem),
static_cast<Scalar>(tmp2.rem),
static_cast<Scalar>(tmp2.quot)};

Scalar v[3];
for (int i = 0; i < 3; i++) {
v[i] = m_origin[i] + loc[i] * m_spacing[i];
}
Scalar v0 = m_origin[0] + loc[0] * m_spacing[0];
Scalar v1 = m_origin[1] + loc[1] * m_spacing[1];
Scalar v2 = m_origin[2] + loc[2] * m_spacing[2];

// vtkMatrix3x3::MultiplyPoint(m_skewMatrix, v, tuple);
tuple[0] =
v[0] * m_skewMatrix[0] + v[1] * m_skewMatrix[1] + v[2] * m_skewMatrix[2];
tuple[1] =
v[0] * m_skewMatrix[3] + v[1] * m_skewMatrix[4] + v[2] * m_skewMatrix[5];
tuple[2] =
v[0] * m_skewMatrix[6] + v[1] * m_skewMatrix[7] + v[2] * m_skewMatrix[8];
tuple[0] = v0 * m_skewMatrix[0] + v1 * m_skewMatrix[1] + v2 * m_skewMatrix[2];
tuple[1] = v0 * m_skewMatrix[3] + v1 * m_skewMatrix[4] + v2 * m_skewMatrix[5];
tuple[2] = v0 * m_skewMatrix[6] + v1 * m_skewMatrix[7] + v2 * m_skewMatrix[8];
}

template <class Scalar>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void vtkDataSetToNonOrthogonalDataSet::execute() {
boost::dynamic_pointer_cast<Mantid::DataObjects::MDHistoWorkspace>(ws);

if (MDHws) {
vtkNew<vtkMDHWPointsArray<double>> implicitPoints;
vtkNew<vtkMDHWPointsArray<float>> implicitPoints;
implicitPoints->InitializeArray(MDHws.get(), skew);
newPoints->SetData(implicitPoints.GetPointer());
} else {
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Vates/VatesAPI/src/vtkMDHistoHexFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ vtkMDHistoHexFactory::create3Dor4D(size_t timestep,
}
}

vtkNew<vtkMDHWPointsArray<double>> implicitPoints;
vtkNew<vtkMDHWPointsArray<float>> implicitPoints;
implicitPoints->InitializeArray(m_workspace.get());
vtkNew<vtkPoints> newPoints;
newPoints->SetData(implicitPoints.GetPointer());
Expand Down
16 changes: 8 additions & 8 deletions Code/Mantid/Vates/VatesAPI/test/vtkMDHWPointsArrayTest.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef VTKNULLSTRUCTUREDPOINTSARRAY_TEST_H_
#define VTKNULLSTRUCTUREDPOINTSARRAY_TEST_H_
#ifndef VTKMDHWPOINTSARRAY_TEST_H_
#define VTKMDHWPOINTSARRAY_TEST_H_

#include "MantidDataObjects/MDHistoWorkspace.h"
#include "MantidTestHelpers/MDEventsTestHelper.h"
Expand Down Expand Up @@ -165,12 +165,12 @@ class vtkMDHWPointsArrayTest : public CxxTest::TestSuite {
vtkNew<vtkDoubleArray> doubleArray;
doubleArray->SetNumberOfComponents(3);
doubleArray->Allocate(100);
spa->GetTuples(0, 100, doubleArray.GetPointer());
spa->GetTuples(0, 99, doubleArray.GetPointer());

for (auto idx = 0; idx < 100; ++idx) {
double output1[3], output2[3];
spa->GetTupleValue(idx, output1);
doubleArray->GetTupleValue(idx, output2);
spa->GetTupleValue(idx, &output1[0]);
doubleArray->GetTupleValue(idx, &output2[0]);
TS_ASSERT_DELTA(output1[0], output2[0], 0.0001);
TS_ASSERT_DELTA(output1[1], output2[1], 0.0001);
TS_ASSERT_DELTA(output1[2], output2[2], 0.0001);
Expand Down Expand Up @@ -208,10 +208,10 @@ class vtkMDHWPointsArrayTestPerformance : public CxxTest::TestSuite {
public:
long long dims[3];
MDHistoWorkspace_sptr ws_sptr;
vtkNew<vtkMDHWPointsArray<double>> m_spa;
vtkNew<vtkMDHWPointsArray<float>> m_spa;

void setUp() {
ws_sptr = MDEventsTestHelper::makeFakeMDHistoWorkspace(1.0, 3, 200);
ws_sptr = MDEventsTestHelper::makeFakeMDHistoWorkspace(1.0, 3, 500);
m_spa->InitializeArray(ws_sptr.get());
dims[0] = ws_sptr->getXDimension()->getNBins() + 1;
dims[1] = ws_sptr->getYDimension()->getNBins() + 1;
Expand All @@ -226,7 +226,7 @@ class vtkMDHWPointsArrayTestPerformance : public CxxTest::TestSuite {
for (auto j = 0; j < dims[1]; ++j) {
for (auto i = 0; i < dims[0]; ++i) {
// test member function.
double output[3];
float output[3];
m_spa->GetTupleValue(index, output);
TS_ASSERT_DELTA(0.05 * double(i), output[0], 0.0001);
index++;
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Vates/VatesAPI/test/vtkMDHWSignalArrayTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class vtkMDHWSignalArrayTest : public CxxTest::TestSuite {
vtkNew<vtkDoubleArray> doubleArray;
doubleArray->SetNumberOfComponents(1);
doubleArray->Allocate(100);
signal->GetTuples(0, 100, doubleArray.GetPointer());
signal->GetTuples(0, 99, doubleArray.GetPointer());

for (auto idx = 0; idx < 100; ++idx) {
double output1[1], output2[1];
Expand Down

0 comments on commit 7571013

Please sign in to comment.