Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / CONVERTOR / VISU_Convertor.hxx
index 65d2d6a32288896fc05027f94f4db47c488048f7..4a5ac9938b7fbae890518416cf237ed3be38c058 100644 (file)
 #ifndef VISU_Convertor_HeaderFile
 #define VISU_Convertor_HeaderFile
 
-#include <stdio.h>
+/*! 
+  \file VISU_Convertor.hxx
+  \brief The file contains definitions for basic classes of the VISU CONVERTER package
+*/
+
+#include "VISU_IDMapper.hxx"
+#include "VISU_ConvertorDef.hxx"
+
+#include "MED_Vector.hxx"
 
-#include <algorithm>
-#include <iterator>
-#include <list>
 #include <map>
-#include <numeric>
 #include <set>
 #include <utility>
-#include <vector>
 #include <string>
 #include <stdexcept>
 
-#include <vtkPoints.h>
-#include <vtkSystemIncludes.h>
-#include <vtkUnstructuredGrid.h>
-#include <vtkMergeDataObjectFilter.h>
-#include <vtkFieldDataToAttributeDataFilter.h>
+namespace VISU
+{
+  using MED::TVector;
 
-#include "VISU_ExtractUnstructuredGrid.hxx"
+  //---------------------------------------------------------------
+  typedef std::string TName;
 
-#include <vtkSmartPointer.h>
+  typedef TVector<TName> TNames;
 
-namespace VISU{
-  enum  TEntity {NODE_ENTITY, EDGE_ENTITY, FACE_ENTITY, CELL_ENTITY};
+  //---------------------------------------------------------------
+  //! Define a basic class for all MED entites which can be identified by its number
+  struct TIntId: virtual TBaseStructure
+  {
+    vtkIdType myId;
 
-  typedef vtkSmartPointer<vtkPoints> TVTKPoints;
-  typedef vtkSmartPointer<vtkUnstructuredGrid> TVTKSource;
-  typedef vtkSmartPointer<vtkMergeDataObjectFilter> TVTKMergetFilter;
-  typedef vtkSmartPointer<VISU_ExtractUnstructuredGrid> TVTKExtractFilter;
-  typedef vtkSmartPointer<vtkFieldDataToAttributeDataFilter> TVTKAttribyteFilter;
-  typedef std::set<std::string> TBindGroups;
+    TIntId(): myId(0)
+    {}
+  };
 
-  struct TFamily{
-    TVTKSource myStorage;
-    vtkIdType myId;
-    std::string myName;
-    TEntity myEntity;
-    TBindGroups myGroups;
-    vtkIdType myNbCells, myCellsSize;
-    typedef std::set<vtkIdType> TSubMeshOnCellType;
-    typedef std::map<vtkIdType,TSubMeshOnCellType> TSubMesh;
-    TSubMesh mySubMesh;
-    TFamily() : myNbCells(0), myCellsSize(0) {}
+
+  //---------------------------------------------------------------
+  typedef std::map<TEntity,PMeshOnEntity> TMeshOnEntityMap;
+  typedef std::map<TName,PGroup> TGroupMap;
+
+  //! Define a basic class which corresponds to MED MESH entity
+  /*!
+    This class in its turn contains map of TMeshOnEntity and TGroup substructures,
+    also it keeps name and dimention of corresponding MED MESH entity.
+  */
+  struct TMesh: virtual TBaseStructure
+  {
+    TMeshOnEntityMap myMeshOnEntityMap; //!< Contains corresponding meshes for MED ENTITIES
+    TGroupMap myGroupMap; //!< Contains map of bounded MED GROUPS
+    TName myName; //! Name of the corresponding MED MESH
+    int myDim; //! Dimension of the corresponding MED MESH
+
+    TMesh(): myDim(0)
+    {}
   };
-  typedef std::map<std::string,TFamily> TFamilyMap;
+  typedef std::map<std::string,PMesh> TMeshMap;
 
-  struct TField{
-    TVTKExtractFilter myExtractFilter;
-    vtkIdType myId;
-    std::string myName;
-    TEntity myEntity;
-    std::string myMeshName;
-    vtkIdType myNbComp, myNbValField, myDataSize, myIsTrimmed;
-    typedef std::vector<float> TValForCellsWithType;
-    typedef std::map<vtkIdType,TValForCellsWithType> TValForCells;
-    typedef std::pair<double,std::string> TTime;
-    typedef std::vector<std::string> TCompNames;
-    typedef std::vector<std::string> TUnitNames;
-    struct TValForTime{
-      TVTKAttribyteFilter myAttribyteFilter;
-      TVTKMergetFilter myMergeFilter;
-      TVTKSource myStorage;
-      vtkIdType myId;
-      std::string myMeshName;
-      TEntity myEntity;
-      std::string myFieldName;
-      vtkIdType myNbComp;
-      TTime myTime;
-      TValForCells myValForCells;
-      TValForTime() : myNbComp(0) {}
-      ~TValForTime() { 
-       if(myMergeFilter.GetPointer())
-         myMergeFilter->UnRegisterAllOutputs();
-       if(myAttribyteFilter.GetPointer())
-         myAttribyteFilter->UnRegisterAllOutputs();
-      }
-    };
-    typedef std::map<vtkIdType,TValForTime> TValField;
-    TValField myValField;
-    TCompNames myCompNames;
-    TUnitNames myUnitNames;
-    TField() : myNbComp(0), myNbValField(0), myDataSize(0), myIsTrimmed(0) {}
-    void ShallowCopy(const TField& aField);
-    ~TField() { 
-      if(myExtractFilter.GetPointer())
-       myExtractFilter->UnRegisterAllOutputs();
-    }
+
+  //---------------------------------------------------------------
+  //! Define a basic class which corresponds to MED PROFILE entity
+  struct TSubProfile: virtual TBaseStructure
+  {};
+
+
+  //---------------------------------------------------------------
+  //! Define a containerfor MED PROFILE entities which belongs to the same MED ENTITY
+  struct TProfile: virtual TNamedIDMapper
+  {};
+
+
+  //---------------------------------------------------------------
+  bool
+  operator<(const PSubProfile& theLeft, const PSubProfile& theRight);
+
+  typedef std::set<PSubProfile> TProfileKey;
+  typedef std::map<TProfileKey,PProfile> TProfileMap;
+
+
+  //---------------------------------------------------------------
+  //! Define a basic class for MED GAUSS entity
+  struct TGauss: virtual TBaseStructure
+  {};
+
+
+  //---------------------------------------------------------------
+  //! Define a container for mesh generated from MED GAUSS and corresponding MED PROFILE
+  struct TGaussSubMesh: virtual TBaseStructure
+  {
+    PSubProfile mySubProfile; //!< Keeps reference on what submesh the Gauss Points are located
   };
-  typedef std::map<std::string,TField> TFieldMap;
-  struct TMeshOnEntity{
-    TVTKSource myStorage;
-    std::string myMeshName;
-    TEntity myEntity;
-    vtkIdType myNbCells, myCellsSize;
-    typedef std::vector<vtkIdType> TConnect;
-    typedef std::vector<TConnect> TConnForCellType;
-    typedef std::map<vtkIdType,TConnForCellType> TCellsConn;
-    TCellsConn myCellsConn;
-    TFamilyMap myFamilyMap;
-    TFieldMap myFieldMap;
-    TMeshOnEntity() : myNbCells(0), myCellsSize(0) {}
-    std::pair<vtkIdType,vtkIdType> GetCellsDims(const std::string& theFamilyName = "") const
-      throw(std::runtime_error&); 
+
+  
+  //---------------------------------------------------------------
+  //! Define a container for all TGaussSubMesh that belongs to the same MED ENTITY
+  struct TGaussMesh: virtual TGaussPtsIDMapper
+  {};
+
+
+  //---------------------------------------------------------------
+  bool
+  operator<(const PGaussSubMesh& theLeft, const PGaussSubMesh& theRight);
+
+  typedef std::set<PGaussSubMesh> TGaussKey;
+  typedef std::map<TGaussKey,PGaussMesh> TGaussMeshMap;
+
+
+  //---------------------------------------------------------------
+
+  typedef std::map<TName,PFamily> TFamilyMap;
+  typedef std::map<TName,PField> TFieldMap;
+
+  //! Define a basic class which corresponds to MED ENTITY
+  /*!
+    This class in its turn contains map of TGaussMesh and TProfile substructures,
+    also it keeps corresponding map of MED FAMILIES and FIELDS.
+  */
+  struct TMeshOnEntity: virtual TNamedIDMapper
+  {
+    TGaussMeshMap myGaussMeshMap; //!< Contains map of Gauss mesh which exist on it
+    TProfileMap myProfileMap; //!< Contains map of Profile mesh which exist on it
+
+    TFamilyMap myFamilyMap; //!< Contains map of MED FAMILIES which belongs to it
+    TFieldMap myFieldMap; //!< Contains map of MED FIELDS which belongs to it
+
+    TName myMeshName; //!< Contains name of the MED MESH where the it belongs to.
+    TEntity myEntity; //!< Referes to MED ENTITY where the it belongs to.
+  };
+
+
+  //---------------------------------------------------------------
+  //! Define a basic class for MED FAMILY entity
+  struct TFamily: virtual TIntId,
+                 virtual TIDMapper
+  {
+    TEntity myEntity; //!< Referes to MED ENTITY where the TFamily belongs to.
+    TName myName; //!< Contains name of the corresponding MED FAMILY
+  };
+
+
+  //---------------------------------------------------------------
+  typedef std::set<PFamily> TFamilySet;
+
+  //! Define a basic class for MED GROUP entity
+  struct TGroup: virtual TIDMapper
+  {
+    TFamilySet myFamilySet;
   };
-  typedef std::map<TEntity,TMeshOnEntity> TMeshOnEntityMap;
-  const TFamily* GetFamily(const VISU::TMeshOnEntity& theMeshOnEntity, 
-                    const std::string& theFamilyName)
-    throw(std::runtime_error&); 
-  TFamily* GetFamily(VISU::TMeshOnEntity& theMeshOnEntity, 
-                    const std::string& theFamilyName)
-    throw(std::runtime_error&); 
-
-  typedef std::pair<std::string,TEntity> TFamilyAndEntity;
-  typedef std::set<TFamilyAndEntity> TFamilyAndEntitySet;
-  struct TGroup{
-    TVTKSource myStorage;
-    std::string myName;
-    std::string myMeshName;
-    vtkIdType myNbCells, myCellsSize;
-    TGroup() : myNbCells(0), myCellsSize(0) {}
-    TFamilyAndEntitySet myFamilyAndEntitySet;
+
+
+  //---------------------------------------------------------------
+  typedef std::map<vtkIdType,PValForTime> TValField;
+  typedef std::pair<float,float> TMinMax;
+
+  //! Define a basic class for MED FIELD entity
+  struct TField: virtual TIntId
+  {
+    TEntity myEntity; //!< Referes to MED ENTITY where it belongs to.
+    TName myName; //!< Contains name of the corresponding MED FIELD
+    TName myMeshName; //!< Contains name of the MED MESH where it belongs to.
+    TValField myValField; //!< Contains sequence of values for corresponding MED TIMESTAMPS
+    TNames myCompNames; //!< Contains names of components of the MED FIELD
+    TNames myUnitNames; //!< Contains names of units of the MED FIELD
+    vtkIdType myNbComp; //!< Keeps number of components for the MED FIELD
+
+    //! Calculate min/max values for each of the MED FIELD components among all its timestamps
+    /*!
+      Numeration of the components starts from 1.
+      Zero component contains min/max value for modulus of corresponding vector
+    */
+    virtual
+    TMinMax 
+    GetMinMax(vtkIdType theCompID) = 0;
+    
+    bool myIsMinMaxInitilized; //!< Is the min / max values are calculated
+
+    TField(): 
+      myNbComp(0),
+      myIsMinMaxInitilized(false)
+    {}
   };
-  typedef std::map<std::string,TGroup> TGroupMap;
-
-  struct TMesh{
-    TVTKPoints myPoints;
-    vtkIdType myDim, myNbPoints;
-    std::string myName;
-    typedef float TCoord;
-    typedef std::vector<TCoord> TPointsCoord;
-    TPointsCoord myPointsCoord;
-    TMeshOnEntityMap myMeshOnEntityMap;
-    TGroupMap myGroupMap;
-    TMesh() : myDim(0), myNbPoints(0) {}
-    const TField* GetField(const std::string& theFieldName) const;
+
+  //---------------------------------------------------------------
+  typedef std::pair<double,std::string> TTime;
+
+  //! Define a basic class for MED TIMESTAMP entity
+  struct TValForTime: virtual TIntId
+  {
+    TEntity myEntity; //!< Referes to MED ENTITY where it belongs to.
+    TName myMeshName; //!< Contains name of the MED MESH where it belongs to.
+    TName myFieldName; //!< Contains name of the MED FIELD where it belongs to.
+    TTime myTime;
+
+    PProfile myProfile; //!< Contains corresponding MED PROFILE where the MED TIEMSTMAP attached to
+    PGaussMesh myGaussMesh;
   };
-  typedef std::map<std::string,TMesh> TMeshMap;
-  void WriteToFile(vtkUnstructuredGrid* theDataSet, const std::string& theFileName);
+
+
+  //---------------------------------------------------------------
+  //! The utility function allows to write vtkUnstructuredGrid to a file with defined name
+  void 
+  WriteToFile(vtkUnstructuredGrid* theDataSet, 
+             const std::string& theFileName);
 };
 
-class VISU_Convertor{
+
+//---------------------------------------------------------------
+//! This class defines interface to read VTK interpretation of MED entities
+/*!
+  It is the main class of the VISU CONVERTER package.
+  Following MED entities can be retrived from any MED file:
+  - mesh from corresponding MED ENTITIES;
+  - MED TIMESTAMPS;
+  - MED FAMILIES;
+  - MED GROUPS.
+  The class produce its work in two main steps:
+  1. Perfrom parsing of MED file to get known what MED entities are pressent in it
+  2. Get VTK representation for any existing MED entity
+  Also, it can perform some additional work to calculate expected amount of memory to build defined VTK representation
+  
+*/
+class VISU_Convertor
+{
 protected:
   std::string myName;
   VISU::TMeshMap myMeshMap;
   int myIsDone;
+
 public:
-  virtual ~VISU_Convertor(){};
-  virtual const std::string& GetName() { return myName;}
-  virtual int IsDone() const { return myIsDone;}
-  typedef vtkUnstructuredGrid TOutput;
-
-  virtual VISU_Convertor* Build() throw (std::runtime_error&) = 0;
-  virtual const VISU::TMeshMap& GetMeshMap() throw(std::runtime_error&);
-  virtual float GetSize() throw (std::runtime_error&) = 0;
-
-  virtual TOutput* GetMeshOnEntity(const std::string& theMeshName, 
-                                  const VISU::TEntity& theEntity,
-                                  const std::string& theFamilyName = "")
-    throw(std::runtime_error&) = 0;
-  virtual float GetMeshOnEntitySize(const std::string& theMeshName, 
-                                   const VISU::TEntity& theEntity,
-                                   const std::string& theFamilyName = "")
-    throw (std::runtime_error&) = 0;
+  virtual 
+  ~VISU_Convertor()
+  {};
   
+  //! Get brief name of the corresponding source MED file
+  virtual
+  const std::string& 
+  GetName(){ return myName;}
+
+  //! Let known whether the source MED file parsed or not
+  virtual
+  int
+  IsDone() const { return myIsDone; }
+
+  //! Defines what subtype of vtkDataSet is used for MED to VTK mapping
+  typedef VISU::TVTKOutput TOutput;
+
+  //! This method perform first parsing of MED file to get known what MED entities are pressent in it
+  virtual
+  VISU_Convertor* 
+  Build() = 0;
+
+  //! This method perform first parsing of MED file to get known what MED mesh entities are pressent in it
+  virtual
+  VISU_Convertor* 
+  BuildEntities() = 0;
+
+  //! This method perform first parsing of MED file to get known what MED fields are pressent in it
+  virtual
+  VISU_Convertor* 
+  BuildFields() = 0;
+
+  //! This min /max calculation over existing MED fields
+  virtual
+  VISU_Convertor* 
+  BuildMinMax() = 0;
+
+  //! This method perform first parsing of MED file to get known what MED groups are pressent in it
+  virtual
+  VISU_Convertor* 
+  BuildGroups() = 0;
+
+  //! This method allow to get known what MED entities are present is the MED file
+  virtual
+  const VISU::TMeshMap& 
+  GetMeshMap();
+
+  //! Get amount of memory to build VTK representations for all existing MED entities
+  virtual
+  float
+  GetSize() = 0;
+
+  //! Get mesh for corresponding MED ENTITY
+  virtual
+  VISU::PNamedIDMapper 
+  GetMeshOnEntity(const std::string& theMeshName, 
+                 const VISU::TEntity& theEntity) = 0;
   
-  virtual TOutput* GetMeshOnGroup(const std::string& theMeshName, 
-                                 const std::string& theGroupName)
-    throw(std::runtime_error&) = 0;
-  virtual float GetMeshOnGroupSize(const std::string& theMeshName, 
-                                  const std::string& theGroupName)
-    throw(std::runtime_error&) = 0;
+  //! Get amount of memory to build mesh for corresponding MED ENTITY
+  virtual
+  float
+  GetMeshOnEntitySize(const std::string& theMeshName, 
+                     const VISU::TEntity& theEntity) = 0;
   
+  //! Get mesh for corresponding MED FAMILY
+  virtual 
+  VISU::PIDMapper 
+  GetFamilyOnEntity(const std::string& theMeshName, 
+                   const VISU::TEntity& theEntity,
+                   const std::string& theFamilyName) = 0;
 
-  virtual TOutput* GetTimeStampOnMesh(const std::string& theMeshName, 
-                                     const VISU::TEntity& theEntity,
-                                     const std::string& theFieldName,
-                                     int theStampsNum)
-    throw(std::runtime_error&) = 0;
-  virtual float GetTimeStampSize(const std::string& theMeshName, 
-                                const VISU::TEntity& theEntity,
-                                const std::string& theFieldName,
-                                int theStampsNum)
-    throw(std::runtime_error&) = 0;
-  virtual float GetFieldOnMeshSize(const std::string& theMeshName, 
-                                  const VISU::TEntity& theEntity,
-                                  const std::string& theFieldName)
-    throw(std::runtime_error&) = 0;
-  virtual const VISU::TField& GetField(const std::string& theMeshName, 
-                                      VISU::TEntity theEntity, 
-                                      const std::string& theFieldName)
-    throw(std::runtime_error&) = 0;
-  virtual const VISU::TField::TValForTime& GetTimeStamp(const std::string& theMeshName, 
-                                                       const VISU::TEntity& theEntity,
-                                                       const std::string& theFieldName,
-                                                       int theStampsNum)
-    throw(std::runtime_error&) = 0;
-
-  static std::string GenerateName(const VISU::TField::TTime& aTime);
-  static std::string GenerateName(const std::string& theName, unsigned int theTimeId);
-  static void WriteToFile(vtkUnstructuredGrid* theDataSet, const std::string& theFileName);
+  //! Get amount of memory to build mesh for corresponding MED FAMILY
+  virtual 
+  float 
+  GetFamilyOnEntitySize(const std::string& theMeshName, 
+                       const VISU::TEntity& theEntity,
+                       const std::string& theFamilyName) = 0;
+
+  //! Get mesh for corresponding MED GROUP
+  virtual
+  VISU::PIDMapper
+  GetMeshOnGroup(const std::string& theMeshName, 
+                const std::string& theGroupName) = 0;
+  
+  //! Get amount of memory to build mesh for corresponding MED GROUP
+  virtual
+  float
+  GetMeshOnGroupSize(const std::string& theMeshName, 
+                    const std::string& theGroupName) = 0;
+  
+  //! Get mesh with attached values for corresponding MED TIMESTAMP
+  virtual
+  VISU::PIDMapper 
+  GetTimeStampOnMesh(const std::string& theMeshName, 
+                    const VISU::TEntity& theEntity,
+                    const std::string& theFieldName,
+                    int theStampsNum) = 0;
+
+  //! Get Gauss Points mesh with attached values for corresponding MED TIMESTAMP
+  virtual
+  VISU::PGaussPtsIDMapper 
+  GetTimeStampOnGaussPts(const std::string& theMeshName, 
+                        const VISU::TEntity& theEntity,
+                        const std::string& theFieldName,
+                        int theStampsNum) = 0;
+   
+  //! Get amount of memory to build mesh for corresponding MED TIMESTAMP
+  virtual 
+  float
+  GetTimeStampSize(const std::string& theMeshName, 
+                  const VISU::TEntity& theEntity,
+                  const std::string& theFieldName,
+                  int theStampsNum) = 0;
+    
+  //! Get amount of memory to build all MED TIMESTAMPS for corresponding MED FIELD
+  virtual 
+  float
+  GetFieldOnMeshSize(const std::string& theMeshName, 
+                    const VISU::TEntity& theEntity,
+                    const std::string& theFieldName) = 0;
+  
+  //! Find MED FIELD container
+  virtual
+  const VISU::PField 
+  GetField(const std::string& theMeshName, 
+          VISU::TEntity theEntity, 
+          const std::string& theFieldName) = 0;
+  
+  //! Find MED TIMESTAMP container
+  virtual
+  const VISU::PValForTime 
+  GetTimeStamp(const std::string& theMeshName, 
+              const VISU::TEntity& theEntity,
+              const std::string& theFieldName,
+              int theStampsNum) = 0;
+    
+  //! Allow to generate pretty name for MED TIMESTAMP
+  static 
+  std::string 
+  GenerateName(const VISU::TTime& aTime);
+
+  static 
+  std::string 
+  GenerateName(const std::string& theName, unsigned int theTimeId);
 };
 
-extern "C"{
-  VISU_Convertor* CreateMedConvertor(const std::string& theFileName) throw(std::runtime_error&);
-  VISU_Convertor* CreateDatConvertor(const std::string& theFileName) throw(std::runtime_error&);
-  VISU_Convertor* CreateConvertor(const std::string& theFileName) throw(std::runtime_error&);
+extern "C"
+{
+  //! Instatiate proper VISU_Convertor subclass
+  VISU_Convertor* 
+  CreateConvertor(const std::string& theFileName);
 };
 
+
 #endif