[vtkusers] Proposed patch for vtkXdmfWriter.cxx

Federico Bonelli federico.bonelli at moxoff.com
Fri Oct 5 12:07:42 EDT 2012


Hi everybody,

I'm currently developing an application that needs to read and write
Xdmf files, and I found that the writer consistently failed to write
2D structured grids' cell attributes.
I think I found a fix for it, but I have not the necessary experience
on VTK to know if it makes sense or not.

Here is my proposed patch, against the nightly head:
<<<<<<<<<<<< CUT HERE >>>>>>>>>>>>>>>>>>>
diff --git a/IO/Xdmf2/vtkXdmfWriter.cxx b/IO/Xdmf2/vtkXdmfWriter.cxx
index 6c2f9d7..204e33a 100644
--- a/IO/Xdmf2/vtkXdmfWriter.cxx
+++ b/IO/Xdmf2/vtkXdmfWriter.cxx
@@ -577,9 +577,19 @@ void vtkXdmfWriter::CreateTopology(vtkDataSet
*ds, XdmfGrid *grid, vtkIdType PDi
     }
     break;
   case VTK_STRUCTURED_GRID:
-    {
-    t->SetTopologyType(XDMF_3DSMESH);
-    vtkStructuredGrid *sgrid = vtkStructuredGrid::SafeDownCast(ds);
+    {
+    vtkStructuredGrid *sgrid = vtkStructuredGrid::SafeDownCast(ds);
+    int rank = CRank = PRank = sgrid->GetDataDimension();
+    if( rank == 3 ){
+        t->SetTopologyType(XDMF_3DSMESH);
+    }
+    else if( rank == 2){
+        t->SetTopologyType(XDMF_2DSMESH);
+    }
+    else{
+        XdmfErrorMessage("Structured Grid Dimensions can be 2 or 3:
"<< rank << " found");
+    }
+
     int wExtent[6];
     sgrid->GetExtent(wExtent);
     XdmfInt64 Dims[3];
@@ -587,7 +597,7 @@ void vtkXdmfWriter::CreateTopology(vtkDataSet *ds,
XdmfGrid *grid, vtkIdType PDi
     Dims[1] = wExtent[3] - wExtent[2] + 1;
     Dims[0] = wExtent[5] - wExtent[4] + 1;
     XdmfDataDesc *dd = t->GetShapeDesc();
-    dd->SetShape(3, Dims);
+    dd->SetShape(rank, Dims);
     //TODO: verify row/column major ordering

     PDims[0] = Dims[0];
<<<<<<<<<<<< END CUT HERE >>>>>>>>>>>>>>

I hope it makes some sense.

bye,
Federico
-- 
Federico Bonelli

MOXOFF srl
Spinoff del Politecnico di Milano
P.zza Leonardo da Vinci, 32 - 20133 Milano (Italia)
tel (+39) 02.2399.4698, fax (+39) 02.2399.4557
web: <http://www.moxoff.com>
--
Sede legale in Milano,
Viale Vittorio Veneto 2/A - 20124 Milano (Italia)
CF/P.IVA 07015910966
Capitale sociale € 50000,00 i.v.
R.E.A.  N. 1929566 - MI



More information about the vtkusers mailing list