Commit 91f5fc1a authored by Berk Geveci's avatar Berk Geveci
Browse files

FIX: Reader should clear it's output if the read fails.

parent 5443555c
......@@ -73,9 +73,9 @@ vtkStructuredGrid::vtkStructuredGrid()
this->Hexahedron = vtkHexahedron::New();
this->EmptyCell = vtkEmptyCell::New();
this->Dimensions[0] = 1;
this->Dimensions[1] = 1;
this->Dimensions[2] = 1;
this->Dimensions[0] = 0;
this->Dimensions[1] = 0;
this->Dimensions[2] = 0;
this->DataDescription = VTK_SINGLE_POINT;
this->Blanking = 0;
......@@ -131,6 +131,7 @@ void vtkStructuredGrid::Initialize()
}
this->PointVisibility = NULL;
this->Blanking = 0;
this->SetDimensions(0,0,0);
}
//----------------------------------------------------------------------------
......@@ -183,6 +184,9 @@ vtkCell *vtkStructuredGrid::GetCell(vtkIdType cellId)
return this->EmptyCell;
}
// Update dimensions
this->GetDimensions();
switch (this->DataDescription)
{
case VTK_SINGLE_POINT: // cellId can only be = 0
......@@ -305,6 +309,9 @@ void vtkStructuredGrid::GetCell(vtkIdType cellId, vtkGenericCell *cell)
return;
}
// Update dimensions
this->GetDimensions();
switch (this->DataDescription)
{
case VTK_SINGLE_POINT: // cellId can only be = 0
......@@ -428,6 +435,9 @@ void vtkStructuredGrid::GetCellBounds(vtkIdType cellId, float bounds[6])
return;
}
// Update dimensions
this->GetDimensions();
switch (this->DataDescription)
{
case VTK_SINGLE_POINT: // cellId can only be = 0
......@@ -636,6 +646,9 @@ void vtkStructuredGrid::SetPointVisibility(vtkUnsignedCharArray *ptVis)
// Return non-zero if the specified cell is visible (i.e., not blanked)
unsigned char vtkStructuredGrid::IsCellVisible(vtkIdType cellId)
{
// Update dimensions
this->GetDimensions();
int numIds=0;
vtkIdType ptIds[8];
int iMin, iMax, jMin, jMax, kMin, kMax;
......@@ -757,6 +770,9 @@ void vtkStructuredGrid::SetDimensions(int dim[3])
// Get the points defining a cell. (See vtkDataSet for more info.)
void vtkStructuredGrid::GetCellPoints(vtkIdType cellId, vtkIdList *ptIds)
{
// Update dimensions
this->GetDimensions();
int iMin, iMax, jMin, jMax, kMin, kMax;
vtkIdType d01 = this->Dimensions[0]*this->Dimensions[1];
......@@ -911,6 +927,19 @@ void vtkStructuredGrid::SetExtent(int xMin, int xMax,
this->SetExtent(extent);
}
int *vtkStructuredGrid::GetDimensions ()
{
this->GetDimensions(this->Dimensions);
return this->Dimensions;
}
void vtkStructuredGrid::GetDimensions (int dim[3])
{
dim[0] = this->Extent[1] - this->Extent[0] + 1;
dim[1] = this->Extent[3] - this->Extent[2] + 1;
dim[2] = this->Extent[5] - this->Extent[4] + 1;
}
//----------------------------------------------------------------------------
void vtkStructuredGrid::GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
vtkIdList *cellIds)
......@@ -926,7 +955,7 @@ void vtkStructuredGrid::GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
case 1: case 2: case 4: //vertex, edge, face neighbors
vtkStructuredData::GetCellNeigbors(cellId, ptIds,
cellIds, this->Dimensions);
cellIds, this->GetDimensions());
break;
default:
......@@ -991,6 +1020,9 @@ void vtkStructuredGrid::InternalStructuredGridCopy(vtkStructuredGrid *src)
this->DataDescription = src->DataDescription;
this->Blanking = src->Blanking;
// Update dimensions
this->GetDimensions();
for (idx = 0; idx < 3; ++idx)
{
this->Dimensions[idx] = src->Dimensions[idx];
......@@ -1168,9 +1200,11 @@ void vtkStructuredGrid::PrintSelf(ostream& os, vtkIndent indent)
{
vtkPointSet::PrintSelf(os,indent);
os << indent << "Dimensions: (" << this->Dimensions[0] << ", "
<< this->Dimensions[1] << ", "
<< this->Dimensions[2] << ")\n";
int dim[3];
this->GetDimensions(dim);
os << indent << "Dimensions: (" << dim[0] << ", "
<< dim[1] << ", "
<< dim[2] << ")\n";
os << indent << "Blanking: " << (this->Blanking ? "On\n" : "Off\n");
......
......@@ -99,7 +99,9 @@ public:
vtkIdType GetNumberOfCells();
void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds);
void GetPointCells(vtkIdType ptId, vtkIdList *cellIds)
{vtkStructuredData::GetPointCells(ptId,cellIds,this->Dimensions);}
{
vtkStructuredData::GetPointCells(ptId,cellIds,this->GetDimensions());
}
void Initialize();
int GetMaxCellSize() {return 8;}; //hexahedron is the largest
void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
......@@ -114,7 +116,8 @@ public:
// Description:
// Get dimensions of this structured points dataset.
vtkGetVectorMacro(Dimensions,int,3);
virtual int *GetDimensions ();
virtual void GetDimensions (int dim[3]);
// Description:
// Return the dimensionality of the data.
......@@ -232,13 +235,15 @@ private:
inline vtkIdType vtkStructuredGrid::GetNumberOfCells()
{
int nCells=1;
int dims[3];
int i;
this->GetDimensions(dims);
for (i=0; i<3; i++)
{
if (this->Dimensions[i] > 1)
if (dims[i] > 1)
{
nCells *= (this->Dimensions[i]-1);
nCells *= (dims[i]-1);
}
}
......
......@@ -172,11 +172,13 @@ void vtkPLOT3DReader::Execute()
if ( this->XYZFileName == NULL )
{
output->Initialize();
vtkErrorMacro(<< "Must specify geometry file");
return;
}
if ( (xyzFp = fopen(this->XYZFileName, "r")) == NULL)
{
output->Initialize();
vtkErrorMacro(<< "File: " << this->XYZFileName << " not found");
return;
}
......@@ -195,6 +197,7 @@ void vtkPLOT3DReader::Execute()
if ( error )
{
output->Initialize();
vtkErrorMacro(<<"Error reading XYZ file");
return;
}
......@@ -207,6 +210,7 @@ void vtkPLOT3DReader::Execute()
{
if ( (QFp = fopen(this->QFileName, "r")) == NULL)
{
output->Initialize();
vtkErrorMacro(<< "File: " << this->QFileName << " not found");
return;
}
......@@ -226,6 +230,7 @@ void vtkPLOT3DReader::Execute()
if ( error )
{
output->Initialize();
vtkErrorMacro(<<"Error reading solution file");
return;
}
......@@ -239,6 +244,7 @@ void vtkPLOT3DReader::Execute()
{
if ( (funcFp = fopen(this->FunctionFileName, "r")) == NULL)
{
output->Initialize();
vtkErrorMacro(<< "File: " << this->FunctionFileName << " not found");
return;
}
......@@ -269,6 +275,7 @@ void vtkPLOT3DReader::Execute()
{
if ( (funcFp = fopen(this->VectorFunctionFileName, "r")) == NULL)
{
output->Initialize();
vtkErrorMacro(<< "File: " << this->VectorFunctionFileName << " not found");
return;
}
......@@ -288,6 +295,7 @@ void vtkPLOT3DReader::Execute()
if ( error )
{
output->Initialize();
vtkErrorMacro(<<"Error reading vector function file");
return;
}
......@@ -607,14 +615,17 @@ int vtkPLOT3DReader::ReadBinarySolution(FILE *fp,vtkStructuredGrid *output)
// Register data for use by computation functions
//
this->Density = newDensity;
this->Density->SetName("Density");
this->Density->Register(this);
newDensity->Delete();
this->Momentum = newMomentum;
this->Momentum->SetName("Momentum");
this->Momentum->Register(this);
newMomentum->Delete();
this->Energy = newEnergy;
this->Energy->SetName("Energy");
this->Energy->Register(this);
newEnergy->Delete();
......@@ -787,6 +798,7 @@ void vtkPLOT3DReader::ComputeTemperature(vtkPointData *outputPD)
p = (this->Gamma-1.) * (e - 0.5 * d * v2);
temperature->SetValue(i, p*rr*rrgas);
}
temperature->SetName("Temperature");
outputPD->SetScalars(temperature);
temperature->Delete();
vtkDebugMacro(<<"Created temperature scalar");
......@@ -826,6 +838,7 @@ void vtkPLOT3DReader::ComputePressure(vtkPointData *outputPD)
p = (this->Gamma-1.) * (e - 0.5 * d * v2);
pressure->SetValue(i, p);
}
pressure->SetName("Pressure");
outputPD->SetScalars(pressure);
pressure->Delete();
vtkDebugMacro(<<"Created pressure scalar");
......@@ -864,6 +877,7 @@ void vtkPLOT3DReader::ComputeEnthalpy(vtkPointData *outputPD)
v2 = u*u + v*v + w*w;
enthalpy->SetValue(i, this->Gamma*(e*rr - 0.5*v2));
}
enthalpy->SetName("Enthalpy");
outputPD->SetScalars(enthalpy);
enthalpy->Delete();
vtkDebugMacro(<<"Created enthalpy scalar");
......@@ -906,6 +920,7 @@ void vtkPLOT3DReader::ComputeKineticEnergy(vtkPointData *outputPD)
v2 = u*u + v*v + w*w;
kineticEnergy->SetValue(i, 0.5*v2);
}
kineticEnergy->SetName("Kinetic Energy");
outputPD->SetScalars(kineticEnergy);
kineticEnergy->Delete();
vtkDebugMacro(<<"Created kinetic energy scalar");
......@@ -943,6 +958,7 @@ void vtkPLOT3DReader::ComputeVelocityMagnitude(vtkPointData *outputPD)
v2 = u*u + v*v + w*w;
velocityMag->SetValue(i, sqrt((double)v2));
}
velocityMag->SetName("Velocity Magnitude");
outputPD->SetScalars(velocityMag);
velocityMag->Delete();
vtkDebugMacro(<<"Created velocity magnitude scalar");
......@@ -989,6 +1005,7 @@ void vtkPLOT3DReader::ComputeEntropy(vtkPointData *outputPD)
s = VTK_CV * log((p/VTK_PINF)/pow((double)d/VTK_RHOINF,(double)this->Gamma));
entropy->SetValue(i,s);
}
entropy->SetName("Entropy");
outputPD->SetScalars(entropy);
entropy->Delete();
vtkDebugMacro(<<"Created entropy scalar");
......@@ -1047,6 +1064,7 @@ void vtkPLOT3DReader::ComputeSwirl(vtkPointData *outputPD)
swirl->SetValue(i,s);
}
swirl->SetName("Swirl");
outputPD->SetScalars(swirl);
swirl->Delete();
vtkDebugMacro(<<"Created swirl scalar");
......@@ -1092,6 +1110,7 @@ void vtkPLOT3DReader::ComputeVelocity(vtkPointData *outputPD)
v[2] = m[2] * rr;
velocity->SetTuple(i, v);
}
velocity->SetName("Velocity");
outputPD->SetVectors(velocity);
velocity->Delete();
vtkDebugMacro(<<"Created velocity vector");
......@@ -1318,7 +1337,7 @@ void vtkPLOT3DReader::ComputeVorticity(vtkPointData *outputPD)
}
}
}
vorticity->SetName("Vorticity");
outputPD->SetVectors(vorticity);
vorticity->Delete();
vtkDebugMacro(<<"Created vorticity vector");
......@@ -1326,6 +1345,7 @@ void vtkPLOT3DReader::ComputeVorticity(vtkPointData *outputPD)
void vtkPLOT3DReader::ComputeMomentum(vtkPointData *outputPD)
{
this->Momentum->SetName("Momentum");
outputPD->SetVectors(this->Momentum);
vtkDebugMacro(<<"Created momentum vector");
}
......@@ -1558,7 +1578,7 @@ void vtkPLOT3DReader::ComputePressureGradient(vtkPointData *outputPD)
}
}
}
gradient->SetName("Gradient");
outputPD->SetVectors(gradient);
gradient->Delete();
vtkDebugMacro(<<"Created pressure gradient vector");
......
......@@ -125,6 +125,7 @@ vtkRecursiveSphereDirectionEncoder GetDecodedGradient 301 3
vtkScalars GetRange 301 2
vtkScalarsToColors GetColor 301 3
vtkStreamer GetStartPosition 301 3
vtkStructuredGrid GetDimensions 304 3
vtkStructuredGrid GetPoint 301 3
vtkStructuredGrid GetScalarRange 301 2
vtkStructuredPointsGeometryFilter GetExtent 304 6
......
Supports Markdown
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