Commit d0197052 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Renamed VTKEntityType to EntityShape

parent 458d536f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
SET( headers NetgenReader.h
SET( headers EntityShape.h
             NetgenReader.h
             TNLReader.h
             VTKEntityType.h
             VTKReader.h
)

+133 −0
Original line number Diff line number Diff line
/***************************************************************************
                          MeshTypeResolver_impl.h  -  description
                          EntityShape.h  -  description
                             -------------------
    begin                : Nov 22, 2016
    copyright            : (C) 2016 by Tomas Oberhuber et al.
@@ -23,10 +23,9 @@ namespace Meshes {
namespace Readers {

/*
 * Entity types used in the VTK library. For convenience, we use them also in
 * our Mesh readers.
 * Enumeration of entity shapes, inspired by the VTK library.
 */
enum class VTKEntityType
enum class EntityShape
{
   Vertex = 1,
   PolyVertex = 2,
@@ -44,51 +43,51 @@ enum class VTKEntityType
   Pyramid = 14
};

static std::ostream& operator<<( std::ostream& str, VTKEntityType type )
static std::ostream& operator<<( std::ostream& str, EntityShape shape )
{
   switch( type )
   switch( shape )
   {
      case VTKEntityType::Vertex:
         str << "VTK::Vertex";
      case EntityShape::Vertex:
         str << "Entity::Vertex";
         break;
      case VTKEntityType::PolyVertex:
         str << "VTK::PolyVertex";
      case EntityShape::PolyVertex:
         str << "Entity::PolyVertex";
         break;
      case VTKEntityType::Line:
         str << "VTK::Line";
      case EntityShape::Line:
         str << "Entity::Line";
         break;
      case VTKEntityType::PolyLine:
         str << "VTK::PolyLine";
      case EntityShape::PolyLine:
         str << "Entity::PolyLine";
         break;
      case VTKEntityType::Triangle:
         str << "VTK::Triangle";
      case EntityShape::Triangle:
         str << "Entity::Triangle";
         break;
      case VTKEntityType::TriangleStrip:
         str << "VTK::TriangleStrip";
      case EntityShape::TriangleStrip:
         str << "Entity::TriangleStrip";
         break;
      case VTKEntityType::Polygon:
         str << "VTK::Polygon";
      case EntityShape::Polygon:
         str << "Entity::Polygon";
         break;
      case VTKEntityType::Pixel:
         str << "VTK::Pixel";
      case EntityShape::Pixel:
         str << "Entity::Pixel";
         break;
      case VTKEntityType::Quad:
         str << "VTK::Quad";
      case EntityShape::Quad:
         str << "Entity::Quad";
         break;
      case VTKEntityType::Tetra:
         str << "VTK::Tetra";
      case EntityShape::Tetra:
         str << "Entity::Tetra";
         break;
      case VTKEntityType::Voxel:
         str << "VTK::Voxel";
      case EntityShape::Voxel:
         str << "Entity::Voxel";
         break;
      case VTKEntityType::Hexahedron:
         str << "VTK::Hexahedron";
      case EntityShape::Hexahedron:
         str << "Entity::Hexahedron";
         break;
      case VTKEntityType::Wedge:
         str << "VTK::Wedge";
      case EntityShape::Wedge:
         str << "Entity::Wedge";
         break;
      case VTKEntityType::Pyramid:
         str << "VTK::Pyramid";
      case EntityShape::Pyramid:
         str << "Entity::Pyramid";
         break;
      default:
         str << "<unknown entity>";
@@ -96,38 +95,38 @@ static std::ostream& operator<<( std::ostream& str, VTKEntityType type )
   return str;
}

static int getVTKEntityDimension( VTKEntityType type )
static int getEntityDimension( EntityShape shape )
{
   switch( type )
   switch( shape )
   {
      case VTKEntityType::Vertex:         return 0;
      case VTKEntityType::PolyVertex:     return 0;
      case VTKEntityType::Line:           return 1;
      case VTKEntityType::PolyLine:       return 1;
      case VTKEntityType::Triangle:       return 2;
      case VTKEntityType::TriangleStrip:  return 2;
      case VTKEntityType::Polygon:        return 2;
      case VTKEntityType::Pixel:          return 2;
      case VTKEntityType::Quad:           return 2;
      case VTKEntityType::Tetra:          return 3;
      case VTKEntityType::Voxel:          return 3;
      case VTKEntityType::Hexahedron:     return 3;
      case VTKEntityType::Wedge:          return 3;
      case VTKEntityType::Pyramid:        return 3;
      case EntityShape::Vertex:         return 0;
      case EntityShape::PolyVertex:     return 0;
      case EntityShape::Line:           return 1;
      case EntityShape::PolyLine:       return 1;
      case EntityShape::Triangle:       return 2;
      case EntityShape::TriangleStrip:  return 2;
      case EntityShape::Polygon:        return 2;
      case EntityShape::Pixel:          return 2;
      case EntityShape::Quad:           return 2;
      case EntityShape::Tetra:          return 3;
      case EntityShape::Voxel:          return 3;
      case EntityShape::Hexahedron:     return 3;
      case EntityShape::Wedge:          return 3;
      case EntityShape::Pyramid:        return 3;
   }
   // this just avoids a compiler warning in GCC and nvcc (clang actually knows if the
   // switch above covers all cases, and print a warning only when it does not)
   throw 1;
}

// static mapping of TNL entity topologies to VTK types
template< typename Topology > struct TopologyToVTKMap {};
template<> struct TopologyToVTKMap< Meshes::Topologies::Vertex >         { static constexpr VTKEntityType type = VTKEntityType::Vertex; };
template<> struct TopologyToVTKMap< Meshes::Topologies::Edge >           { static constexpr VTKEntityType type = VTKEntityType::Line; };
template<> struct TopologyToVTKMap< Meshes::Topologies::Triangle >       { static constexpr VTKEntityType type = VTKEntityType::Triangle; };
template<> struct TopologyToVTKMap< Meshes::Topologies::Quadrilateral >  { static constexpr VTKEntityType type = VTKEntityType::Quad; };
template<> struct TopologyToVTKMap< Meshes::Topologies::Tetrahedron >    { static constexpr VTKEntityType type = VTKEntityType::Tetra; };
template<> struct TopologyToVTKMap< Meshes::Topologies::Hexahedron >     { static constexpr VTKEntityType type = VTKEntityType::Hexahedron; };
// static mapping of TNL entity topologies to EntityShape
template< typename Topology > struct TopologyToEntityShape {};
template<> struct TopologyToEntityShape< Topologies::Vertex >         { static constexpr EntityShape shape = EntityShape::Vertex; };
template<> struct TopologyToEntityShape< Topologies::Edge >           { static constexpr EntityShape shape = EntityShape::Line; };
template<> struct TopologyToEntityShape< Topologies::Triangle >       { static constexpr EntityShape shape = EntityShape::Triangle; };
template<> struct TopologyToEntityShape< Topologies::Quadrilateral >  { static constexpr EntityShape shape = EntityShape::Quad; };
template<> struct TopologyToEntityShape< Topologies::Tetrahedron >    { static constexpr EntityShape shape = EntityShape::Tetra; };
template<> struct TopologyToEntityShape< Topologies::Hexahedron >     { static constexpr EntityShape shape = EntityShape::Hexahedron; };

} // namespace Readers
} // namespace Meshes
+12 −12
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@
#include <sstream>

#include <TNL/Meshes/MeshBuilder.h>
#include <TNL/Meshes/Readers/VTKEntityType.h>
#include <TNL/Meshes/Readers/EntityShape.h>

namespace TNL {
namespace Meshes {
@@ -124,20 +124,20 @@ public:
      //cout << "There are " << verticesInCell << " vertices in cell ..." << std::endl;
      
      if( meshDimension == 1 && verticesInCell == 2 )
         cellVTKType = VTKEntityType::Line;
         cellShape = EntityShape::Line;
      else if( meshDimension == 2 ) {
         if( verticesInCell == 3 )
            cellVTKType = VTKEntityType::Triangle;
            cellShape = EntityShape::Triangle;
         else if( verticesInCell == 4 )
            cellVTKType = VTKEntityType::Quad;
            cellShape = EntityShape::Quad;
      }
      else if( meshDimension == 3 ) {
         if( verticesInCell == 4 )
            cellVTKType = VTKEntityType::Tetra;
            cellShape = EntityShape::Tetra;
         else if( verticesInCell == 8 )
            cellVTKType = VTKEntityType::Hexahedron;
            cellShape = EntityShape::Hexahedron;
      }
      if( cellVTKType == VTKEntityType::Vertex ) {
      if( cellShape == EntityShape::Vertex ) {
         std::cerr << "Unknown cell topology: mesh dimension is " << meshDimension << ", number of vertices in cells is " << verticesInCell << "." << std::endl;
         return false;
      }
@@ -251,10 +251,10 @@ public:
      return worldDimension;
   }

   VTKEntityType
   getCellVTKType() const
   EntityShape
   getCellShape() const
   {
      return cellVTKType;
      return cellShape;
   }

   String
@@ -288,13 +288,13 @@ public:
protected:
   String fileName;
   int meshDimension, worldDimension;
   VTKEntityType cellVTKType = VTKEntityType::Vertex;
   EntityShape cellShape = EntityShape::Vertex;

   void reset()
   {
      fileName = "";
      meshDimension = worldDimension = 0;
      cellVTKType = VTKEntityType::Vertex;
      cellShape = EntityShape::Vertex;
   }
};

+14 −14
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
#include <TNL/String.h>
#include <TNL/Object.h>
#include <TNL/Containers/List.h>
#include <TNL/Meshes/Readers/VTKEntityType.h>
#include <TNL/Meshes/Readers/EntityShape.h>

namespace TNL {
namespace Meshes {
@@ -48,11 +48,11 @@ public:
         globalIndexType = localIndexType = idType = parsedMeshType[ 4 ];
         // populate entity types (not necessary for GridTypeResolver, but while we're at it...)
         if( meshDimension == 1 )
            cellVTKType = VTKEntityType::Line;
            cellShape = EntityShape::Line;
         else if( meshDimension == 2 )
            cellVTKType = VTKEntityType::Quad;
            cellShape = EntityShape::Quad;
         else if( meshDimension == 3 )
            cellVTKType = VTKEntityType::Hexahedron;
            cellShape = EntityShape::Hexahedron;
      }
      else if( meshType == "Meshes::Mesh" ) {
         Containers::List< String > parsedMeshConfig;
@@ -75,15 +75,15 @@ public:
         idType = parsedMeshConfig[ 6 ];

         if( topology == "MeshEdgeTopology" )
            cellVTKType = VTKEntityType::Line;
            cellShape = EntityShape::Line;
         else if( topology == "MeshTriangleTopology" )
            cellVTKType = VTKEntityType::Triangle;
            cellShape = EntityShape::Triangle;
         else if( topology == "MeshQuadrilateralTopology" )
            cellVTKType = VTKEntityType::Quad;
            cellShape = EntityShape::Quad;
         else if( topology == "MeshTetrahedronTopology" )
            cellVTKType = VTKEntityType::Tetra;
            cellShape = EntityShape::Tetra;
         else if( topology == "MeshHexahedronTopology" )
            cellVTKType = VTKEntityType::Hexahedron;
            cellShape = EntityShape::Hexahedron;
         else {
            std::cerr << "Detected topology '" << topology << "' is not supported." << std::endl;
            return false;
@@ -122,10 +122,10 @@ public:
      return worldDimension;
   }

   VTKEntityType
   getCellVTKType() const
   EntityShape
   getCellShape() const
   {
      return cellVTKType;
      return cellShape;
   }
 
   String
@@ -157,7 +157,7 @@ protected:
   String meshType;
   int meshDimension = 0;
   int worldDimension = 0;
   VTKEntityType cellVTKType = VTKEntityType::Vertex;
   EntityShape cellShape = EntityShape::Vertex;
   String realType;
   String globalIndexType;
   String localIndexType;
@@ -168,7 +168,7 @@ protected:
      fileName = "";
      meshType = "";
      meshDimension = worldDimension = 0;
      cellVTKType = VTKEntityType::Vertex;
      cellShape = EntityShape::Vertex;
      realType = localIndexType = globalIndexType = idType = "";
   }
};
+15 −15
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@
#include <vector>

#include <TNL/Meshes/MeshBuilder.h>
#include <TNL/Meshes/Readers/VTKEntityType.h>
#include <TNL/Meshes/Readers/EntityShape.h>

namespace TNL {
namespace Meshes {
@@ -107,7 +107,7 @@ public:

      // read entity types
      long int entitiesRead = 0;
      std::map< int, VTKEntityType > entityTypes;
      std::map< int, EntityShape > entityTypes;
      while( entitiesRead < numberOfEntities ) {
         if( ! inputFile ) {
            std::cerr << "VTKReader: unable to read enough entity types, the file may be invalid or corrupted." << std::endl;
@@ -120,8 +120,8 @@ public:
         iss.clear();
         iss.str( line );
         iss >> typeId;
         const VTKEntityType type = (VTKEntityType) typeId;
         const int dimension = getVTKEntityDimension( type );
         const EntityShape type = (EntityShape) typeId;
         const int dimension = getEntityDimension( type );

         // check entity type
         if( entityTypes.find( dimension ) == entityTypes.cend() )
@@ -137,12 +137,12 @@ public:
         entitiesRead++;
      }

      // set meshDimension and cellVTKType
      // set meshDimension and cellShape
      meshDimension = 0;
      for( auto it : entityTypes )
         if( it.first > meshDimension ) {
            meshDimension = it.first;
            cellVTKType = it.second;
            cellShape = it.second;
         }

      return true;
@@ -156,7 +156,7 @@ public:
      using PointType = typename MeshType::PointType;
      using CellSeedType = typename MeshBuilder::CellSeedType;

      const VTKEntityType cellType = TopologyToVTKMap< typename MeshType::template EntityTraits< MeshType::getMeshDimension() >::EntityTopology >::type;
      const EntityShape cellType = TopologyToEntityShape< typename MeshType::template EntityTraits< MeshType::getMeshDimension() >::EntityTopology >::shape;
      MeshBuilder meshBuilder;

      std::ifstream inputFile( fileName.getString() );
@@ -233,7 +233,7 @@ public:
      iss >> numberOfEntities;

      // read entity types, count cells
      std::vector< VTKEntityType > entityTypes;
      std::vector< EntityShape > entityTypes;
      entityTypes.resize( numberOfEntities );
      IndexType numberOfCells = 0;
      for( IndexType entityIndex = 0; entityIndex < numberOfEntities; entityIndex++ ) {
@@ -248,8 +248,8 @@ public:
         iss.clear();
         iss.str( line );
         iss >> typeId;
         entityTypes[ entityIndex ] = (VTKEntityType) typeId;
         const int dimension = getVTKEntityDimension( entityTypes[ entityIndex ] );
         entityTypes[ entityIndex ] = (EntityShape) typeId;
         const int dimension = getEntityDimension( entityTypes[ entityIndex ] );
         if( dimension == MeshType::getMeshDimension() )
            numberOfCells++;
      }
@@ -311,10 +311,10 @@ public:
      return worldDimension;
   }

   VTKEntityType
   getCellVTKType() const
   EntityShape
   getCellShape() const
   {
      return cellVTKType;
      return cellShape;
   }

   String
@@ -351,14 +351,14 @@ protected:

   String fileName;
   int meshDimension, worldDimension;
   VTKEntityType cellVTKType = VTKEntityType::Vertex;
   EntityShape cellShape = EntityShape::Vertex;
   std::string realType;

   void reset()
   {
      fileName = "";
      meshDimension = worldDimension = 0;
      cellVTKType = VTKEntityType::Vertex;
      cellShape = EntityShape::Vertex;
      realType = "";
   }

Loading