src/CONVERTOR/VISU_Convertor.hxx

Go to the documentation of this file.
00001 //  VISU CONVERTOR :
00002 //
00003 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
00005 // 
00006 //  This library is free software; you can redistribute it and/or 
00007 //  modify it under the terms of the GNU Lesser General Public 
00008 //  License as published by the Free Software Foundation; either 
00009 //  version 2.1 of the License. 
00010 // 
00011 //  This library is distributed in the hope that it will be useful, 
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00014 //  Lesser General Public License for more details. 
00015 // 
00016 //  You should have received a copy of the GNU Lesser General Public 
00017 //  License along with this library; if not, write to the Free Software 
00018 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
00019 // 
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 //
00023 //  File   : VISU_Convertor.hxx
00024 //  Author : Alexey PETROV
00025 //  Module : VISU
00026 
00027 #ifndef VISU_Convertor_HeaderFile
00028 #define VISU_Convertor_HeaderFile
00029 
00035 #include "VISU_IDMapper.hxx"
00036 #include "VISU_ConvertorDef.hxx"
00037 
00038 #include "MED_Vector.hxx"
00039 
00040 #include <map>
00041 #include <set>
00042 #include <utility>
00043 #include <string>
00044 #include <stdexcept>
00045 
00046 namespace VISU
00047 {
00048   using MED::TVector;
00049 
00050   //---------------------------------------------------------------
00051   typedef std::string TName;
00052 
00053   typedef TVector<TName> TNames;
00054 
00055   //---------------------------------------------------------------
00057   struct TIntId: virtual TBaseStructure
00058   {
00059     vtkIdType myId;
00060 
00061     TIntId(): myId(0)
00062     {}
00063   };
00064 
00065 
00066   //---------------------------------------------------------------
00067   typedef std::map<TEntity,PMeshOnEntity> TMeshOnEntityMap;
00068   typedef std::map<TName,PGroup> TGroupMap;
00069 
00071 
00075   struct TMesh: virtual TBaseStructure
00076   {
00077     TMeshOnEntityMap myMeshOnEntityMap; 
00078     TGroupMap myGroupMap; 
00079     TName myName; 
00080     int myDim; 
00081 
00082     std::string myGroupsEntry; 
00083     std::string myFieldsEntry; 
00084 
00085     TMesh(): myDim(0)
00086     {}
00087   };
00088   typedef std::map<std::string,PMesh> TMeshMap;
00089 
00090 
00091   //---------------------------------------------------------------
00093   struct TSubProfile: virtual TBaseStructure
00094   {};
00095 
00096 
00097   //---------------------------------------------------------------
00099   struct TProfile: virtual TNamedIDMapper
00100   {};
00101 
00102 
00103   //---------------------------------------------------------------
00104   bool
00105   operator<(const PSubProfile& theLeft, const PSubProfile& theRight);
00106 
00107   typedef std::set<PSubProfile> TProfileKey;
00108   typedef std::map<TProfileKey,PProfile> TProfileMap;
00109 
00110 
00111   //---------------------------------------------------------------
00113   struct TGauss: virtual TBaseStructure
00114   {};
00115 
00116 
00117   //---------------------------------------------------------------
00119   struct TGaussSubMesh: virtual TBaseStructure
00120   {
00121     PSubProfile mySubProfile; 
00122   };
00123 
00124   
00125   //---------------------------------------------------------------
00127   struct TGaussMesh: virtual TGaussPtsIDMapper
00128   {};
00129 
00130 
00131   //---------------------------------------------------------------
00132   bool
00133   operator<(const PGaussSubMesh& theLeft, const PGaussSubMesh& theRight);
00134 
00135   typedef std::set<PGaussSubMesh> TGaussKey;
00136   typedef std::map<TGaussKey,PGaussMesh> TGaussMeshMap;
00137 
00138 
00139   //---------------------------------------------------------------
00140 
00141   typedef std::map<TName,PFamily> TFamilyMap;
00142   typedef std::map<TName,PField> TFieldMap;
00143 
00145 
00149   struct TMeshOnEntity: virtual TNamedIDMapper
00150   {
00151     TGaussMeshMap myGaussMeshMap; 
00152     TProfileMap myProfileMap; 
00153 
00154     TFamilyMap myFamilyMap; 
00155     TFieldMap myFieldMap; 
00156 
00157     TName myMeshName; 
00158     TEntity myEntity; 
00159   };
00160 
00161 
00162   //---------------------------------------------------------------
00164   struct TFamily: virtual TIntId,
00165             virtual TIDMapper
00166   {
00167     TEntity myEntity; 
00168     TName myName; 
00169   };
00170 
00171 
00172   //---------------------------------------------------------------
00173 
00174   class FamilyCmp {
00175    public:
00176     bool operator() (const PFamily& theFamily1, const PFamily& theFamily2) const {
00177        return (theFamily1->myName < theFamily2->myName);
00178     }
00179   };
00180 
00181   typedef std::set<PFamily, FamilyCmp> TFamilySet;
00182 
00184   struct TGroup: virtual TIDMapper
00185   {
00186     TFamilySet myFamilySet;
00187   };
00188 
00189 
00190   //---------------------------------------------------------------
00191   typedef std::map<vtkIdType,PValForTime> TValField;
00192   typedef std::pair<vtkFloatingPointType,vtkFloatingPointType> TMinMax;
00193 
00195   struct TField: virtual TIntId
00196   {
00197     TEntity myEntity; 
00198     TName myName; 
00199     TName myMeshName; 
00200     TValField myValField; 
00201     TNames myCompNames; 
00202     TNames myUnitNames; 
00203     vtkIdType myNbComp; 
00204 
00206 
00210     virtual
00211     TMinMax 
00212     GetMinMax(vtkIdType theCompID) = 0;
00213     
00214     bool myIsMinMaxInitilized; 
00215 
00216     TField(): 
00217       myNbComp(0),
00218       myIsMinMaxInitilized(false)
00219     {}
00220   };
00221  
00222 
00223   //---------------------------------------------------------------
00224   typedef std::pair<double,std::string> TTime;
00225 
00227   struct TValForTime: virtual TIntId
00228   {
00229     TEntity myEntity; 
00230     TName myMeshName; 
00231     TName myFieldName; 
00232     TTime myTime;
00233 
00234     PProfile myProfile; 
00235     PGaussMesh myGaussMesh;
00236   };
00237 
00238 
00239   //---------------------------------------------------------------
00241   void 
00242   WriteToFile(vtkUnstructuredGrid* theDataSet, 
00243            const std::string& theFileName);
00244 };
00245 
00246 
00247 //---------------------------------------------------------------
00249 
00262 class VISU_Convertor
00263 {
00264 protected:
00265   std::string myName;
00266   VISU::TMeshMap myMeshMap;
00267   int myIsDone;
00268 
00269 public:
00270   virtual 
00271   ~VISU_Convertor()
00272   {};
00273   
00275   virtual
00276   const std::string& 
00277   GetName(){ return myName;}
00278 
00280   virtual
00281   int
00282   IsDone() const { return myIsDone; }
00283 
00285   typedef VISU::TVTKOutput TOutput;
00286 
00288   virtual
00289   VISU_Convertor* 
00290   Build() = 0;
00291 
00293   virtual
00294   VISU_Convertor* 
00295   BuildEntities() = 0;
00296 
00298   virtual
00299   VISU_Convertor* 
00300   BuildFields() = 0;
00301 
00303   virtual
00304   VISU_Convertor* 
00305   BuildMinMax() = 0;
00306 
00308   virtual
00309   VISU_Convertor* 
00310   BuildGroups() = 0;
00311 
00313   virtual
00314   const VISU::TMeshMap& 
00315   GetMeshMap();
00316 
00318   virtual
00319   vtkFloatingPointType
00320   GetSize() = 0;
00321 
00323   virtual
00324   VISU::PNamedIDMapper 
00325   GetMeshOnEntity(const std::string& theMeshName, 
00326             const VISU::TEntity& theEntity) = 0;
00327   
00329   virtual
00330   vtkFloatingPointType
00331   GetMeshOnEntitySize(const std::string& theMeshName, 
00332                 const VISU::TEntity& theEntity) = 0;
00333   
00335   virtual 
00336   VISU::PIDMapper 
00337   GetFamilyOnEntity(const std::string& theMeshName, 
00338               const VISU::TEntity& theEntity,
00339               const std::string& theFamilyName) = 0;
00340 
00342   virtual 
00343   vtkFloatingPointType 
00344   GetFamilyOnEntitySize(const std::string& theMeshName, 
00345                const VISU::TEntity& theEntity,
00346                const std::string& theFamilyName) = 0;
00347 
00349   virtual
00350   VISU::PIDMapper
00351   GetMeshOnGroup(const std::string& theMeshName, 
00352            const std::string& theGroupName) = 0;
00353   
00355   virtual
00356   vtkFloatingPointType
00357   GetMeshOnGroupSize(const std::string& theMeshName, 
00358                const std::string& theGroupName) = 0;
00359   
00361   virtual
00362   VISU::PIDMapper 
00363   GetTimeStampOnMesh(const std::string& theMeshName, 
00364                const VISU::TEntity& theEntity,
00365                const std::string& theFieldName,
00366                int theStampsNum) = 0;
00367 
00369   virtual
00370   VISU::PGaussPtsIDMapper 
00371   GetTimeStampOnGaussPts(const std::string& theMeshName, 
00372                 const VISU::TEntity& theEntity,
00373                 const std::string& theFieldName,
00374                 int theStampsNum) = 0;
00375    
00377   virtual 
00378   vtkFloatingPointType
00379   GetTimeStampSize(const std::string& theMeshName, 
00380              const VISU::TEntity& theEntity,
00381              const std::string& theFieldName,
00382              int theStampsNum) = 0;
00383     
00385   virtual 
00386   vtkFloatingPointType
00387   GetFieldOnMeshSize(const std::string& theMeshName, 
00388                const VISU::TEntity& theEntity,
00389                const std::string& theFieldName) = 0;
00390   
00392   virtual
00393   const VISU::PField 
00394   GetField(const std::string& theMeshName, 
00395         VISU::TEntity theEntity, 
00396         const std::string& theFieldName) = 0;
00397   
00399   virtual
00400   const VISU::PValForTime 
00401   GetTimeStamp(const std::string& theMeshName, 
00402             const VISU::TEntity& theEntity,
00403             const std::string& theFieldName,
00404             int theStampsNum) = 0;
00405     
00407   static 
00408   std::string 
00409   GenerateName(const VISU::TTime& aTime);
00410 
00411   static 
00412   std::string 
00413   GenerateName(const std::string& theName, unsigned int theTimeId);
00414 };
00415 
00416 extern "C"
00417 {
00419   VISU_Convertor* 
00420   CreateConvertor(const std::string& theFileName);
00421 };
00422 
00423 
00424 #endif