Commit 6c471c36 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Fixed and simplified types in mesh writers

parent 64eb38a3
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -29,8 +29,6 @@ class PVTIWriter
   // LOL, VTK does not support signed header types (but the GridTypeResolver maps unsigned types to signed, so we are good)
   using HeaderType = std::make_unsigned_t< typename Grid::GlobalIndexType >;
public:
   using MeshRealType = typename Grid::RealType;
   using IndexType = typename Grid::GlobalIndexType;

   PVTIWriter() = delete;

+8 −8
Original line number Diff line number Diff line
@@ -67,24 +67,24 @@ PVTIWriter< Grid >::writeImageData( const Grid& globalGrid,
   std::stringstream extent, origin, spacing;

   auto dims = globalGrid.getDimensions();
   for( IndexType j = 0; j < dims.getSize(); j++ )
   for( int j = 0; j < dims.getSize(); j++ )
      extent << "0 " << dims[ j ] << " ";
   // VTK knows only 3D grids
   for( IndexType j = dims.getSize(); j < 3; j++ )
   for( int j = dims.getSize(); j < 3; j++ )
      extent << "0 0 ";

   auto o = globalGrid.getOrigin();
   for( IndexType j = 0; j < o.getSize(); j++ )
   for( int j = 0; j < o.getSize(); j++ )
      origin << std::scientific << o[ j ] << " ";
   // VTK knows only 3D grids
   for( IndexType j = o.getSize(); j < 3; j++ )
   for( int j = o.getSize(); j < 3; j++ )
      origin << 0 << " ";

   auto h = globalGrid.getSpaceSteps();
   for( IndexType j = 0; j < h.getSize(); j++ )
   for( int j = 0; j < h.getSize(); j++ )
      spacing << std::scientific << h[ j ] << " ";
   // VTK knows only 3D grids
   for( IndexType j = h.getSize(); j < 3; j++ )
   for( int j = h.getSize(); j < 3; j++ )
      spacing << 0 << " ";

   str << "<PImageData"
@@ -177,10 +177,10 @@ PVTIWriter< Grid >::addPiece( const String& mainFileName,

   // prepare the extent
   std::stringstream extent;
   for( IndexType j = 0; j < Grid::getMeshDimension(); j++ )
   for( int j = 0; j < Grid::getMeshDimension(); j++ )
      extent << globalBegin[ j ] <<  " " << globalEnd[ j ] << " ";
   // VTK knows only 3D grids
   for( IndexType j = Grid::getMeshDimension(); j < 3; j++ )
   for( int j = Grid::getMeshDimension(); j < 3; j++ )
      extent << "0 0 ";

   namespace fs = std::experimental::filesystem;
+0 −2
Original line number Diff line number Diff line
@@ -25,8 +25,6 @@ class PVTUWriter
{
   using HeaderType = std::uint64_t;
public:
   using MeshRealType = typename Mesh::RealType;
   using IndexType = typename Mesh::GlobalIndexType;

   PVTUWriter() = delete;

+2 −4
Original line number Diff line number Diff line
@@ -30,8 +30,6 @@ class VTIWriter
   // LOL, VTK does not support signed header types (but the GridTypeResolver maps unsigned types to signed, so we are good)
   using HeaderType = std::make_unsigned_t< typename Mesh::GlobalIndexType >;
public:
   using MeshRealType = typename Mesh::RealType;
   using IndexType = typename Mesh::GlobalIndexType;

   VTIWriter() = delete;

@@ -82,10 +80,10 @@ protected:
   VTK::FileFormat format;

   // number of points written to the file
   IndexType pointsCount = 0;
   std::uint64_t pointsCount = 0;

   // number of cells (in the VTK sense) written to the file
   IndexType cellsCount = 0;
   std::uint64_t cellsCount = 0;

   // indicator if the <VTKFile> tag is open
   bool vtkfileOpen = false;
+9 −9
Original line number Diff line number Diff line
@@ -66,22 +66,22 @@ VTIWriter< Mesh >::writeImageData( const typename Mesh::PointType& gridOrigin,

   std::stringstream extent, origin, spacing;

   for( IndexType j = 0; j < Mesh::getMeshDimension(); j++ )
   for( int j = 0; j < Mesh::getMeshDimension(); j++ )
      extent << begin[ j ] <<  " " << end[ j ] << " ";
   // VTK knows only 3D grids
   for( IndexType j = Mesh::getMeshDimension(); j < 3; j++ )
   for( int j = Mesh::getMeshDimension(); j < 3; j++ )
      extent << "0 0 ";

   for( IndexType j = 0; j < Mesh::getMeshDimension(); j++ )
   for( int j = 0; j < Mesh::getMeshDimension(); j++ )
      origin << std::scientific << gridOrigin[ j ] << " ";
   // VTK knows only 3D grids
   for( IndexType j = Mesh::getMeshDimension(); j < 3; j++ )
   for( int j = Mesh::getMeshDimension(); j < 3; j++ )
      origin << 0 << " ";

   for( IndexType j = 0; j < Mesh::getMeshDimension(); j++ )
   for( int j = 0; j < Mesh::getMeshDimension(); j++ )
      spacing << std::scientific << spaceSteps[ j ] << " ";
   // VTK knows only 3D grids
   for( IndexType j = Mesh::getMeshDimension(); j < 3; j++ )
   for( int j = Mesh::getMeshDimension(); j < 3; j++ )
      spacing << 0 << " ";

   str << "<ImageData WholeExtent=\"" << extent.str() << "\" Origin=\"" << origin.str() << "\" Spacing=\"" << spacing.str() << "\">\n";
@@ -125,7 +125,7 @@ VTIWriter< Mesh >::writePointData( const Array& array,
{
   if( ! pieceOpen )
      throw std::logic_error("The <Piece> tag has not been opened yet - call writeEntities first.");
   if( array.getSize() / numberOfComponents != pointsCount )
   if( array.getSize() / numberOfComponents != typename Array::IndexType(pointsCount) )
      throw std::length_error("Mismatched array size for <PointData> section: " + std::to_string(array.getSize())
                              + " (there are " + std::to_string(pointsCount) + " points in the file)");
   openPointData();
@@ -141,7 +141,7 @@ VTIWriter< Mesh >::writeCellData( const Array& array,
{
   if( ! pieceOpen )
      throw std::logic_error("The <Piece> tag has not been opened yet - call writeEntities first.");
   if( array.getSize() / numberOfComponents != cellsCount )
   if( array.getSize() / numberOfComponents != typename Array::IndexType(cellsCount) )
      throw std::length_error("Mismatched array size for <CellData> section: " + std::to_string(array.getSize())
                              + " (there are " + std::to_string(cellsCount) + " cells in the file)");
   openCellData();
@@ -179,7 +179,7 @@ VTIWriter< Mesh >::writeDataArray( const Array& array,
   {
      case VTK::FileFormat::ascii:
         str.precision( std::numeric_limits< typename Array::ValueType >::digits10 );
         for( IndexType i = 0; i < array.getSize(); i++ )
         for( typename Array::IndexType i = 0; i < array.getSize(); i++ )
            // If Array::ValueType is uint8_t, it might be a typedef for unsigned char, which
            // would be normally printed as char rather than a number. Hence, we use the trick
            // with unary operator+, see https://stackoverflow.com/a/28414758
Loading