Commit bb8dcbaf authored by T.J. Corona's avatar T.J. Corona
Browse files

Create a test array and test case for XML writer dispatch fallback.

parent c8771337
......@@ -316,6 +316,7 @@ set(${vtk-module}_HDRS
vtkSOADataArrayTemplate.h
vtkSOADataArrayTemplate.txx
vtkTemplateAliasMacro.h
vtkTestDataArray.h
vtkTypeList.h
vtkTypeList.txx
vtkTypeTraits.h
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSOADataArrayTemplate.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkTestDataArray - An implementation of vtkGenericDataArray for testing
// fallback algorithms.
//
// .SECTION Description
// vtkTestDataArray is derived from vtkGenericDataArray, and is deliberately
// omitted from VTK's whitelist of dispatchable data arrays. It is used to test
// the fallback mechanisms of algorithms in the case that array dispatch fails.
//
// .SECTION See Also
// vtkGenericDataArray
#ifndef vtkTestDataArray_h
#define vtkTestDataArray_h
#include "vtkCommonCoreModule.h" // For export macro
#include "vtkGenericDataArray.h"
template <class ArrayT>
class vtkTestDataArray : public vtkGenericDataArray<vtkTestDataArray<ArrayT>,
typename ArrayT::ValueType>
{
public:
typedef ArrayT ArrayType;
typedef typename ArrayType::ValueType ValueType;
typedef vtkTestDataArray<ArrayT> SelfType;
typedef vtkGenericDataArray<vtkTestDataArray<ArrayT>, ValueType>
GenericDataArrayType;
friend class vtkGenericDataArray<vtkTestDataArray<ArrayT>, ValueType>;
vtkAbstractTemplateTypeMacro(SelfType, GenericDataArrayType)
vtkAOSArrayNewInstanceMacro(SelfType)
static vtkTestDataArray<ArrayType>* New()
{ VTK_STANDARD_NEW_BODY(vtkTestDataArray<ArrayType>); }
virtual void PrintSelf(ostream &os, vtkIndent indent)
{ GenericDataArrayType::PrintSelf(os,indent); }
ValueType GetValue(vtkIdType valueIdx) const
{ return this->Array->GetValue(valueIdx); }
void SetValue(vtkIdType valueIdx, ValueType value)
{ this->Array->SetValue(valueIdx,value); }
void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
{ this->Array->SetTypedTuple(tupleIdx,tuple); }
void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
{ this->Array->SetTypedTuple(tupleIdx,tuple); }
ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
{ return this->Array->GetTypedComponent(tupleIdx,compIdx); }
void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value)
{ this->Array->SetTypedComponent(tupleIdx,compIdx,value); }
void *GetVoidPointer(vtkIdType valueIdx)
{ return this->Array->GetVoidPointer(valueIdx); }
protected:
vtkTestDataArray() { this->Array = ArrayType::New(); }
~vtkTestDataArray() { this->Array->Delete(); }
bool AllocateTuples(vtkIdType numTuples)
{ return this->Array->Allocate(numTuples) != 0; }
bool ReallocateTuples(vtkIdType numTuples)
{ return this->Array->Allocate(numTuples) != 0; }
private:
ArrayType* Array;
// Not implemented.
vtkTestDataArray(const vtkTestDataArray &); // Not implemented.
void operator=(const vtkTestDataArray &); // Not implemented.
};
#endif
// VTK-HeaderTest-Exclude: vtkTestDataArray.h
......@@ -7,6 +7,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestXMLUnstructuredGridReader.cxx
TestXML.cxx,NO_DATA,NO_VALID,NO_OUTPUT
TestXMLToString.cxx,NO_DATA,NO_VALID,NO_OUTPUT
TestXMLWriterWithDataArrayFallback.cxx,NO_VALID
TestDataObjectXMLIO.cxx,NO_VALID
)
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestXMLWriterWithDataArrayFallback.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME Test of vtkXMLWriter with data array dispatch fallback
// .SECTION Description
//
#include "vtkImageData.h"
#include "vtkIntArray.h"
#include "vtkNew.h"
#include "vtkPointData.h"
#include "vtkTestDataArray.h"
#include "vtkTestUtilities.h"
#include "vtkXMLImageDataReader.h"
#include "vtkXMLImageDataWriter.h"
#include <string>
int TestXMLWriterWithDataArrayFallback(int argc, char *argv[])
{
std::string temp_dir = std::string(vtkTestUtilities::GetArgOrEnvOrDefault(
"-T", argc, argv, "VTK_TEMP_DIR",
"Testing/Temporary"));
if (temp_dir.empty())
{
cerr << "Could not determine temporary directory." << endl;
return EXIT_FAILURE;
}
std::string filename = temp_dir + "/testXMLWriterWithDataArrayFallback.vti";
{
vtkNew<vtkImageData> imageData;
imageData->SetDimensions(2,3,1);
vtkNew<vtkTestDataArray<vtkIntArray> > data;
data->SetName("test_data");
data->SetNumberOfTuples(6);
for (vtkIdType i = 0; i < 6; i++)
{
data->SetValue(i,static_cast<int>(i));
}
imageData->GetPointData()->AddArray(data.GetPointer());
vtkNew<vtkXMLImageDataWriter> writer;
writer->SetFileName(filename.c_str());
writer->SetInputData(imageData.GetPointer());
writer->Write();
}
{
vtkNew<vtkXMLImageDataReader> reader;
reader->SetFileName(filename.c_str());
reader->Update();
vtkImageData* imageData = reader->GetOutput();
vtkIntArray* data = vtkIntArray::SafeDownCast(
imageData->GetPointData()->GetArray("test_data"));
if (!data || data->GetNumberOfTuples() != 6)
{
cerr << "Could not read data array." << endl;
return EXIT_FAILURE;
}
for (vtkIdType i = 0; i < data->GetNumberOfTuples(); i++)
{
if (data->GetValue(i) != i)
{
cerr << "Incorrect value from data array." << endl;
return EXIT_FAILURE;
}
}
}
return EXIT_SUCCESS;
}
......@@ -62,6 +62,7 @@
#include <locale> // C++ locale
//*****************************************************************************
// Friend class to enable access for template functions to the protected
// writer methods.
......@@ -1363,12 +1364,26 @@ int vtkXMLWriter::WriteBinaryDataInternal(vtkAbstractArray* a)
numValues);
if (!vtkArrayDispatch::Dispatch::Execute(da, worker))
{
size_t size = 1;
switch (wordType)
{
case VTK___INT64:
case VTK_UNSIGNED___INT64:
case VTK_LONG_LONG:
case VTK_UNSIGNED_LONG_LONG:
#ifdef VTK_USE_64BIT_IDS
case VTK_ID_TYPE:
#endif
vtkWarningMacro("Using legacy vtkDataArray API, which may result "
"in precision loss");
break;
default:
break;
}
switch (wordType)
{
vtkTemplateMacro(WriteDataArrayFallback(static_cast<VTK_TT*>(0),
da,worker));
default:
vtkWarningMacro("Unsupported data type: " << wordType);
break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment