Commit 1db98987 authored by Mickael PHILIT's avatar Mickael PHILIT Committed by Kitware Robot

Merge topic 'cgns_writer_fix'

7addb3b3 Add braces
cc2331c1 init j just when needed
b8c4368a remove shadowing
facabbda fix typo
a3e22b72 CGNSWriter gets better CellDim for 2D StructuredGrid
3b38b9b3 Small fix to initialize CellDim
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Mathieu Westphal's avatarMathieu Westphal <mathieu.westphal@kitware.com>
Merge-request: !4399
parents 7e86fe01 7addb3b3
Pipeline #191540 failed with stages
in 73 minutes and 13 seconds
......@@ -363,6 +363,19 @@ bool vtkCGNSWriter::vtkPrivate::WritePointSet(vtkPointSet* grid, const char* fil
{
info.CellDim = 2;
}
else if (grid->IsA("vtkUnstructuredGrid"))
{
info.CellDim = 1;
for (int i = 0; i < grid->GetNumberOfCells(); ++i)
{
vtkCell* cell = grid->GetCell(i);
int cellDim = cell->GetCellDimension();
if (info.CellDim < cellDim)
{
info.CellDim = cellDim;
}
}
}
if (!InitCGNSFile(info, file, error))
{
......@@ -507,6 +520,8 @@ bool vtkCGNSWriter::vtkPrivate::WriteStructuredGrid(
// set the dimensions
int* pointDims = sg->GetDimensions();
int cellDims[3];
int j;
sg->GetCellDims(cellDims);
if (!pointDims)
......@@ -515,12 +530,25 @@ bool vtkCGNSWriter::vtkPrivate::WriteStructuredGrid(
return false;
}
// init dimensions
for (int i = 0; i < 3; ++i)
{
dim[0][i] = pointDims[i];
dim[1][i] = cellDims[i];
dim[0][i] = 1;
dim[1][i] = 0;
dim[2][i] = 0; // always 0 for structured
}
j = 0;
for (int i = 0; i < 3; ++i)
{
// skip unitary index dimension
if (pointDims[i] == 1)
{
continue;
}
dim[0][j] = pointDims[i];
dim[1][j] = cellDims[i];
j++;
}
// create the structured zone. Cells are implicit
cg_check_operation(
......@@ -549,6 +577,15 @@ bool vtkCGNSWriter::vtkPrivate::WriteStructuredGrid(
vtkStructuredGrid* sg, const char* file, string& error)
{
write_info info;
int* dims = sg->GetDimensions();
info.CellDim = 0;
for (int n = 0; n < 3; n++)
{
if (dims[n] > 1)
{
info.CellDim += 1;
}
}
if (!InitCGNSFile(info, file, error) || !WriteBase(info, "Base", error))
{
return false;
......@@ -629,7 +666,42 @@ void Flatten(vtkMultiBlockDataSet* mb, vector<entry>& o2d, vector<entry>& o3d, i
}
else if (block)
{
o3d.push_back(entry(block, zonename));
int CellDim = 3;
if (block->IsA("vtkStructuredGrid"))
{
vtkStructuredGrid* sg = vtkStructuredGrid::SafeDownCast(block);
int* dims = sg->GetDimensions();
CellDim = 0;
for (int n = 0; n < 3; n++)
{
if (dims[n] > 1)
{
CellDim += 1;
}
}
}
else if (block->IsA("vtkUnstructuredGrid"))
{
vtkUnstructuredGrid* ug = vtkUnstructuredGrid::SafeDownCast(block);
CellDim = 1;
for (int n = 0; n < ug->GetNumberOfCells(); ++n)
{
vtkCell* cell = ug->GetCell(n);
int curCellDim = cell->GetCellDimension();
if (CellDim < curCellDim)
{
CellDim = curCellDim;
}
}
}
if (CellDim == 3)
{
o3d.push_back(entry(block, zonename));
}
else
{
o2d.push_back(entry(block, zonename));
}
}
}
}
......@@ -687,10 +759,19 @@ bool vtkCGNSWriter::vtkPrivate::WriteMultiBlock(
for (auto& e : surfaceBlocks)
{
vtkPolyData* pd = vtkPolyData::SafeDownCast(e.obj);
if (pd)
vtkStructuredGrid* sg = vtkStructuredGrid::SafeDownCast(e.obj);
if (sg)
{
if (!WritePointSet(info, pd, e.name.c_str(), error))
if (!WriteStructuredGrid(info, sg, e.name.c_str(), error))
{
return false;
}
continue;
}
vtkPointSet* ps = vtkPointSet::SafeDownCast(e.obj);
if (ps)
{
if (!WritePointSet(info, ps, e.name.c_str(), error))
{
return false;
}
......
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