Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / CONVERTOR / VISU_Convertor.hxx
index bebb26f096e3f5f67ab41d21ed26f03d0741a983..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 <list>
 #include <map>
 #include <set>
 #include <utility>
-#include <vector>
 #include <string>
 #include <stdexcept>
 
-#include <boost/shared_ptr.hpp>
+namespace VISU
+{
+  using MED::TVector;
 
-class vtkUnstructuredGrid;
+  //---------------------------------------------------------------
+  typedef std::string TName;
 
-namespace VISU{
+  typedef TVector<TName> TNames;
 
-  template<class T> class shared_ptr: public boost::shared_ptr<T>
+  //---------------------------------------------------------------
+  //! Define a basic class for all MED entites which can be identified by its number
+  struct TIntId: virtual TBaseStructure
   {
-  public:
-    shared_ptr() {}
-
-    template<class Y>
-    explicit shared_ptr(Y * p)
-    {
-      reset(p);
-    }
-
-    template<class Y>
-    shared_ptr(shared_ptr<Y> const & r):
-      boost::shared_ptr<T>(r,boost::detail::dynamic_cast_tag())
+    vtkIdType myId;
+
+    TIntId(): myId(0)
     {}
+  };
 
-    template<class Y>
-    shared_ptr & operator=(shared_ptr<Y> const & r)
-    {
-      shared_ptr<T>(r).swap(*this);
-      return *this;
-    }
-
-    template<class Y> shared_ptr& operator()(Y * p) // Y must be complete
-    {
-      if(T* pt = dynamic_cast<T*>(p))
-       boost::shared_ptr<T>::reset(pt);
-      else
-       boost::throw_exception(std::bad_cast());
-      return *this;
-    }
 
+  //---------------------------------------------------------------
+  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,PMesh> TMeshMap;
 
 
-  enum  TEntity {NODE_ENTITY, EDGE_ENTITY, FACE_ENTITY, CELL_ENTITY};
+  //---------------------------------------------------------------
+  //! Define a basic class which corresponds to MED PROFILE entity
+  struct TSubProfile: virtual TBaseStructure
+  {};
 
-  typedef std::pair<std::string,TEntity> TFamilyAndEntity;
-  typedef std::set<TFamilyAndEntity> TFamilyAndEntitySet;
-  typedef std::set<std::string> TBindGroups;
 
-  typedef std::pair<double,std::string> TTime;
+  //---------------------------------------------------------------
+  //! Define a containerfor MED PROFILE entities which belongs to the same MED ENTITY
+  struct TProfile: virtual TNamedIDMapper
+  {};
 
-  struct TMesh;
-  typedef shared_ptr<TMesh> PMesh;
-  typedef std::map<std::string,PMesh> TMeshMap;
 
-  struct TMeshOnEntity;
-  typedef shared_ptr<TMeshOnEntity> PMeshOnEntity;
-  typedef std::map<TEntity,PMeshOnEntity> TMeshOnEntityMap;
+  //---------------------------------------------------------------
+  bool
+  operator<(const PSubProfile& theLeft, const PSubProfile& theRight);
 
-  struct TFamily;
-  typedef shared_ptr<TFamily> PFamily;
-  typedef std::map<std::string,PFamily> TFamilyMap;
+  typedef std::set<PSubProfile> TProfileKey;
+  typedef std::map<TProfileKey,PProfile> TProfileMap;
 
-  struct TGroup;
-  typedef shared_ptr<TGroup> PGroup;
-  typedef std::map<std::string,PGroup> TGroupMap;
 
-  struct TField;
-  typedef shared_ptr<TField> PField;
-  typedef std::map<std::string,PField> TFieldMap;
+  //---------------------------------------------------------------
+  //! Define a basic class for MED GAUSS entity
+  struct TGauss: virtual TBaseStructure
+  {};
 
-  struct TValForTime;
-  typedef shared_ptr<TValForTime> PValForTime;
-  typedef std::map<int,PValForTime> TValField;
 
-  struct TBaseStructure{
-    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::vector<std::string> TNames;
+  
+  //---------------------------------------------------------------
+  //! Define a container for all TGaussSubMesh that belongs to the same MED ENTITY
+  struct TGaussMesh: virtual TGaussPtsIDMapper
+  {};
 
-  struct TMesh: TBaseStructure{
-    int myDim, myNbPoints;
-    std::string myName;
 
-    TMeshOnEntityMap myMeshOnEntityMap;
-    TGroupMap myGroupMap;
+  //---------------------------------------------------------------
+  bool
+  operator<(const PGaussSubMesh& theLeft, const PGaussSubMesh& theRight);
 
-    TMesh() : myDim(0), myNbPoints(0) {}
-    const PField GetField(const std::string& theFieldName) const;
-  };
+  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
 
-  struct TMeshOnEntity: TBaseStructure{
-    std::string myMeshName;
-    TEntity myEntity;
-    int myNbCells, myCellsSize;
-    TFamilyMap myFamilyMap;
-    TFieldMap myFieldMap;
-    TMeshOnEntity() : myNbCells(0), myCellsSize(0) {}
+    TFamilyMap myFamilyMap; //!< Contains map of MED FAMILIES which belongs to it
+    TFieldMap myFieldMap; //!< Contains map of MED FIELDS which belongs to it
 
-    std::pair<int,int> 
-    GetCellsDims(const std::string& theFamilyName = "") const;
+    TName myMeshName; //!< Contains name of the MED MESH where the it belongs to.
+    TEntity myEntity; //!< Referes to MED ENTITY where the it belongs to.
   };
 
-  struct TFamily: TBaseStructure{
-    int myId;
-    std::string myName;
-    TEntity myEntity;
-    TBindGroups myGroups;
-    int myNbCells, myCellsSize;
-    TFamily() : myNbCells(0), myCellsSize(0) {}
+
+  //---------------------------------------------------------------
+  //! 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
   };
 
-  struct TGroup: TBaseStructure{
-    std::string myName;
-    std::string myMeshName;
-    int myNbCells, myCellsSize;
-    TFamilyAndEntitySet myFamilyAndEntitySet;
-    TGroup() : myNbCells(0), myCellsSize(0) {}
+
+  //---------------------------------------------------------------
+  typedef std::set<PFamily> TFamilySet;
+
+  //! Define a basic class for MED GROUP entity
+  struct TGroup: virtual TIDMapper
+  {
+    TFamilySet myFamilySet;
   };
 
-  struct TField: TBaseStructure{
-    int myId;
-    TEntity myEntity;
-    bool myIsTrimmed;
-    std::string myName;
-    std::string myMeshName;
-    int myNbComp, myDataSize;
-    TValField myValField;
-    TNames myCompNames;
-    TNames myUnitNames;
-    TField() : myNbComp(0), myDataSize(0), myIsTrimmed(0) {}
+
+  //---------------------------------------------------------------
+  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)
+    {}
   };
  
-  struct TValForTime: TBaseStructure{
-    int myId;
-    TEntity myEntity;
-    std::string myMeshName;
-    std::string myFieldName;
-    int myNbComp;
-    TTime myTime;
 
-    TValForTime() : myNbComp(0) {}
-  };
+  //---------------------------------------------------------------
+  typedef std::pair<double,std::string> TTime;
 
-  PFamily FindFamily(VISU::PMesh theMesh, 
-                    const std::string& theFamilyName);
+  //! 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;
 
-  PFamily GetFamily(VISU::PMeshOnEntity theMeshOnEntity, 
-                   const std::string& theFamilyName);
+    PProfile myProfile; //!< Contains corresponding MED PROFILE where the MED TIEMSTMAP attached to
+    PGaussMesh myGaussMesh;
+  };
 
-  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() = 0;
-  virtual const VISU::TMeshMap& GetMeshMap() ;
-  virtual float GetSize() = 0;
-
-  virtual TOutput* GetMeshOnEntity(const std::string& theMeshName, 
-                                  const VISU::TEntity& theEntity,
-                                  const std::string& theFamilyName = "") = 0;
-    
-  virtual float GetMeshOnEntitySize(const std::string& theMeshName, 
-                                   const VISU::TEntity& theEntity,
-                                   const std::string& theFamilyName = "") = 0;
+  virtual 
+  ~VISU_Convertor()
+  {};
   
-  virtual TOutput* GetMeshOnGroup(const std::string& theMeshName, 
-                                 const std::string& theGroupName) = 0;
-
-  virtual float GetMeshOnGroupSize(const std::string& theMeshName, 
-                                  const std::string& theGroupName) = 0;
-
-  virtual TOutput* GetTimeStampOnMesh(const std::string& theMeshName, 
-                                     const VISU::TEntity& theEntity,
-                                     const std::string& theFieldName,
-                                     int theStampsNum) = 0;
+  //! 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;
+  
+  //! 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;
+
+  //! 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;
    
-  virtual float GetTimeStampSize(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;
     
-  virtual float GetFieldOnMeshSize(const std::string& theMeshName, 
-                                  const VISU::TEntity& theEntity,
-                                  const std::string& theFieldName) = 0;
-  virtual const VISU::PField GetField(const std::string& theMeshName, 
-                                     VISU::TEntity theEntity, 
-                                     const std::string& theFieldName) = 0;
-
-  virtual const VISU::PValForTime GetTimeStamp(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;
     
-  static std::string GenerateName(const VISU::TTime& aTime);
-  static std::string GenerateName(const std::string& theName, unsigned int theTimeId);
+  //! 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* CreateConvertor(const std::string& theFileName) ;
+extern "C"
+{
+  //! Instatiate proper VISU_Convertor subclass
+  VISU_Convertor* 
+  CreateConvertor(const std::string& theFileName);
 };
 
+
 #endif