[MOAB-dev] r1759 - MOAB/trunk

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Fri Apr 11 14:41:37 CDT 2008


Author: kraftche
Date: 2008-04-11 14:41:37 -0500 (Fri, 11 Apr 2008)
New Revision: 1759

Modified:
   MOAB/trunk/ReadVtk.cpp
   MOAB/trunk/WriteVtk.cpp
   MOAB/trunk/WriteVtk.hpp
Log:
Fix handling of multivalue-tags in VTK files:
  - be more permissive in reader: we are capable of reading any number of values
     per entity for a scalar attribute, even though the spec says it should be 
     no more than 4.
  - be more restritive in writer: by default, don't write tags that have the
     number of values per entity something other than 1,2,3,4,or 9.  Any such
     tag does not map to a valid VTK attribute type.
  - add option "STRICT" corresponding to the above default writer behavior
  - add option "RELAXED" for which the writer will write tags with more than
    4 values per entity as scalar data attributes even though the spec says
    no more than 4.  This is the previous MOAB behavior and will read successfully
    into both MOAB and VTK5.
    



Modified: MOAB/trunk/ReadVtk.cpp
===================================================================
--- MOAB/trunk/ReadVtk.cpp	2008-04-11 19:34:29 UTC (rev 1758)
+++ MOAB/trunk/ReadVtk.cpp	2008-04-11 19:41:37 UTC (rev 1759)
@@ -1005,7 +1005,7 @@
   }
   
     // VTK spec says cannot be greater than 4--do we care?
-  if (size < 1 || size > 4)
+  if (size < 1) //|| size > 4)
   {
     readMeshIface->report_error(
                     "Scalar count out of range [1,4]" 

Modified: MOAB/trunk/WriteVtk.cpp
===================================================================
--- MOAB/trunk/WriteVtk.cpp	2008-04-11 19:34:29 UTC (rev 1758)
+++ MOAB/trunk/WriteVtk.cpp	2008-04-11 19:41:37 UTC (rev 1759)
@@ -46,12 +46,13 @@
 sprintf(stringvar, prefix, id)
 
 const int DEFAULT_PRECISION = 10;
+const bool DEFAULT_STRICT = true;
 
 MBWriterIface *WriteVtk::factory( MBInterface* iface )
   { return new WriteVtk( iface ); }
 
 WriteVtk::WriteVtk(MBInterface *impl) 
-    : mbImpl(impl), writeTool(0), globalId(0)
+    : mbImpl(impl), writeTool(0), globalId(0), mStrict(DEFAULT_STRICT)
 {
   assert(impl != NULL);
 
@@ -86,6 +87,13 @@
   if (MB_SUCCESS != opts.get_int_option( "PRECISION", precision ))
     precision = DEFAULT_PRECISION;
   
+  if (MB_SUCCESS == opts.get_null_option( "STRICT" ))
+    mStrict = true;
+  else if (MB_SUCCESS == opts.get_null_option( "RELAXED" ))
+    mStrict = false;
+  else
+    mStrict = DEFAULT_STRICT;
+  
     // Get entities to write
   MBRange nodes, elems;
   rval = gather_mesh( output_list, num_sets, nodes, elems );
@@ -374,6 +382,29 @@
     if (MB_VARIABLE_DATA_LENGTH == mbImpl->tag_get_size( *i, size ))
       continue;    
     
+      // If in strict mode, don't write tags that do not fit in any 
+      // attribute type (SCALAR : 1 to 4 values, VECTOR : 3 values, TENSOR : 9 values)
+    if (mStrict) {
+      int count = 0;
+      switch (type) {
+        case MB_TYPE_INTEGER:
+          count = size/sizeof(int);
+          break;
+        case MB_TYPE_DOUBLE:
+          count = size/sizeof(double);
+          break;
+        case MB_TYPE_BIT:
+        case MB_TYPE_OPAQUE:
+          count = size;
+          break;
+        default:
+          return MB_TYPE_OUT_OF_RANGE;
+      }
+      if (count < 1 || (count > 4 && count != 9))
+        continue;
+    }
+          
+    
       // Get subset of input entities that have the tag set
     MBRange tagged;
     for (MBEntityType type = low_type; type < high_type; ++type)

Modified: MOAB/trunk/WriteVtk.hpp
===================================================================
--- MOAB/trunk/WriteVtk.hpp	2008-04-11 19:34:29 UTC (rev 1758)
+++ MOAB/trunk/WriteVtk.hpp	2008-04-11 19:41:37 UTC (rev 1759)
@@ -84,6 +84,9 @@
   MBInterface* mbImpl;
   MBWriteUtilIface* writeTool;
   MBTag globalId;
+  
+  bool mStrict; // If true, do not write data that cannot fit in strict VTK file format.
+  
 };
 
 #endif




More information about the moab-dev mailing list