Commit 70ead432 authored by Kyle Lutz's avatar Kyle Lutz Committed by Code Review
Browse files

Merge topic 'data-array-asserts' into master

14c8487e Safer fake coordinates for structured from unstructured CF grids
bc424e27 Add asserts to vtkDataArrayTemplate Set/GetValue()
parents 46a51e1c 14c8487e
......@@ -23,6 +23,7 @@
#include "vtkCommonCoreModule.h" // For export macro
#include "vtkDataArray.h"
#include <cassert> // for assert()
template <class T>
class vtkDataArrayTemplateLookup;
......@@ -131,13 +132,14 @@ public:
// Description:
// Get the data at a particular index.
T GetValue(vtkIdType id) { return this->Array[id]; }
T GetValue(vtkIdType id)
{ assert(id >= 0 && id < this->Size); return this->Array[id]; }
// Description:
// Set the data at a particular index. Does not do range checking. Make sure
// you use the method SetNumberOfValues() before inserting data.
void SetValue(vtkIdType id, T value)
{ this->Array[id] = value;};
{ assert(id >= 0 && id < this->Size); this->Array[id] = value;};
// Description:
// Specify the number of values for this object to hold. Does an
......
......@@ -32,6 +32,7 @@
#include "vtkIntArray.h"
#include "vtkMath.h"
#include "vtkMergePoints.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPoints.h"
#include "vtkRectilinearGrid.h"
......@@ -1071,7 +1072,17 @@ int vtkNetCDFCFReader::RequestData(vtkInformation *request,
= vtkRectilinearGrid::GetData(outputVector);
if (rectilinearOutput)
{
this->AddRectilinearCoordinates(rectilinearOutput);
switch (this->CoordinateType(this->LoadingDimensions))
{
case COORDS_EUCLIDEAN_PSIDED_CELLS:
case COORDS_SPHERICAL_PSIDED_CELLS:
// There is no sensible way to store p-sided cells in a structured grid.
// Just fake some coordinates (related to ParaView bug #11543).
this->FakeRectilinearCoordinates(rectilinearOutput);
break;
default:
this->AddRectilinearCoordinates(rectilinearOutput);
}
}
vtkStructuredGrid *structuredOutput
......@@ -1098,9 +1109,8 @@ int vtkNetCDFCFReader::RequestData(vtkInformation *request,
case COORDS_EUCLIDEAN_PSIDED_CELLS:
case COORDS_SPHERICAL_PSIDED_CELLS:
// There is no sensible way to store p-sided cells in a structured grid.
// Just store them as a rectilinear grid, which should at least not
// crash (bug #11543).
this->Add1DRectilinearCoordinates(structuredOutput);
// Just fake some coordinates (ParaView bug #11543).
this->FakeStructuredCoordinates(structuredOutput);
break;
default:
vtkErrorMacro("Internal error: unknown coordinate type.");
......@@ -1244,6 +1254,34 @@ void vtkNetCDFCFReader::AddRectilinearCoordinates(
case 0: rectilinearOutput->SetXCoordinates(coords); break;
case 1: rectilinearOutput->SetYCoordinates(coords); break;
case 2: rectilinearOutput->SetZCoordinates(coords); break;
default: vtkErrorMacro("Sanity check failed!"); break;
}
}
}
//-----------------------------------------------------------------------------
void vtkNetCDFCFReader::FakeRectilinearCoordinates(
vtkRectilinearGrid *rectilinearOutput)
{
int dimensionSizes[3];
rectilinearOutput->GetDimensions(dimensionSizes);
for (int dim = 0; dim < 3; dim++)
{
vtkNew<vtkDoubleArray> coordinate;
coordinate->SetNumberOfComponents(1);
coordinate->SetNumberOfTuples(dimensionSizes[dim]);
for (int index = 0; index < dimensionSizes[dim]; index++)
{
coordinate->SetComponent(index, 0, static_cast<double>(index));
}
switch(dim)
{
case 0: rectilinearOutput->SetXCoordinates(coordinate.GetPointer());break;
case 1: rectilinearOutput->SetYCoordinates(coordinate.GetPointer());break;
case 2: rectilinearOutput->SetZCoordinates(coordinate.GetPointer());break;
default: vtkErrorMacro("Sanity check failed!"); break;
}
}
}
......@@ -1378,6 +1416,33 @@ void vtkNetCDFCFReader::Add2DRectilinearCoordinates(
structuredOutput->SetPoints(points);
}
//-----------------------------------------------------------------------------
void vtkNetCDFCFReader::FakeStructuredCoordinates(
vtkStructuredGrid *structuredOutput)
{
int extent[6];
structuredOutput->GetExtent(extent);
vtkNew<vtkPoints> points;
points->SetDataTypeToDouble();
points->Allocate( (extent[1]-extent[0]+1)
* (extent[3]-extent[2]+1)
* (extent[5]-extent[4]+1) );
for (int kIndex = extent[4]; kIndex <= extent[5]; kIndex++)
{
for (int jIndex = extent[2]; jIndex <= extent[3]; jIndex++)
{
for (int iIndex = extent[0]; iIndex <= extent[1]; iIndex++)
{
points->InsertNextPoint(iIndex, jIndex, kIndex);
}
}
}
structuredOutput->SetPoints(points.GetPointer());
}
//-----------------------------------------------------------------------------
void vtkNetCDFCFReader::Add1DRectilinearCoordinates(
vtkUnstructuredGrid *unstructuredOutput,
......
......@@ -252,10 +252,12 @@ protected:
// Internal methods for setting rectilinear coordinates.
void AddRectilinearCoordinates(vtkImageData *imageOutput);
void AddRectilinearCoordinates(vtkRectilinearGrid *rectilinearOutput);
void FakeRectilinearCoordinates(vtkRectilinearGrid *rectilinearOutput);
void Add1DRectilinearCoordinates(vtkPoints *points, const int extent[6]);
void Add2DRectilinearCoordinates(vtkPoints *points, const int extent[6]);
void Add1DRectilinearCoordinates(vtkStructuredGrid *structuredOutput);
void Add2DRectilinearCoordinates(vtkStructuredGrid *structuredOutput);
void FakeStructuredCoordinates(vtkStructuredGrid *structuredOutput);
void Add1DRectilinearCoordinates(vtkUnstructuredGrid *unstructuredOutput,
const int extent[6]);
void Add2DRectilinearCoordinates(vtkUnstructuredGrid *unstructuredOutput,
......
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