[MOAB-dev] r4321 - in MOAB/trunk: src/io test/io

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Fri Dec 3 13:13:08 CST 2010


Author: kraftche
Date: 2010-12-03 13:13:08 -0600 (Fri, 03 Dec 2010)
New Revision: 4321

Modified:
   MOAB/trunk/src/io/ReadVtk.cpp
   MOAB/trunk/test/io/VtkTest.cpp
Log:
fix PR#169: moab cannot read technically invalid but common FIELD datasets within UNSTRUCTURED_GRID datasets for VTK files

Modified: MOAB/trunk/src/io/ReadVtk.cpp
===================================================================
--- MOAB/trunk/src/io/ReadVtk.cpp	2010-12-03 18:56:49 UTC (rev 4320)
+++ MOAB/trunk/src/io/ReadVtk.cpp	2010-12-03 19:13:08 UTC (rev 4321)
@@ -713,8 +713,22 @@
   long i, num_verts, num_elems[2];
   EntityHandle tmp_conn_list[27];
 
-  if (!tokens.match_token( "POINTS" )        ||
-      !tokens.get_long_ints( 1, &num_verts ) ||
+    // Poorly formatted VTK legacy format document seems to
+    // lead many to think that a FIELD block can occur within
+    // an UNSTRUCTURED_GRID dataset rather than as its own data 
+    // set.  So allow for field data between other blocks of
+    // data.  
+    
+  const char* pts_str[] = { "FIELD", "POINTS", 0 };
+  while (1 == (i = tokens.match_token(pts_str))) {
+    result = vtk_read_field(tokens);
+    if (MB_SUCCESS != result)
+      return result;
+  }    
+  if (i != 2)
+    return MB_FAILURE;
+
+  if (!tokens.get_long_ints( 1, &num_verts ) ||
       !tokens.match_token( vtk_type_names)   ||
       !tokens.get_newline( ))
     return MB_FAILURE;
@@ -731,9 +745,17 @@
   if (MB_SUCCESS != result)
     return result;
   vertex_list.insert( first_vertex, first_vertex + num_verts - 1 );
+    
+  const char* cell_str[] = { "FIELD", "CELLS", 0 };
+  while (1 == (i = tokens.match_token(cell_str))) {
+    result = vtk_read_field(tokens);
+    if (MB_SUCCESS != result)
+      return result;
+  }    
+  if (i != 2)
+    return MB_FAILURE;
   
-  if (!tokens.match_token( "CELLS" )        ||
-      !tokens.get_long_ints( 2, num_elems ) ||
+  if (!tokens.get_long_ints( 2, num_elems ) ||
       !tokens.get_newline( ))
     return MB_FAILURE;
   
@@ -935,7 +957,8 @@
     // For now, read it and throw it out.


More information about the moab-dev mailing list