Salome HOME
Merge branch 'V7_main' of ssh://git.salome-platform.org/modules/paravis into V7_main
[modules/paravis.git] / src / Plugins / MEDReader / IO / MEDFileFieldRepresentationTree.hxx
1 // Copyright (C) 2010-2014  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay
20
21 #ifndef __MEDFILEFIELDREPRESENTATIONTREE_HXX__
22 #define __MEDFILEFIELDREPRESENTATIONTREE_HXX__
23
24 #include "MEDFileMesh.hxx"
25 #include "MEDFileField.hxx"
26
27 #include "vtkType.h"
28
29 #include <vector>
30
31 class vtkQuadratureSchemeDefinition;
32 class vtkMutableDirectedGraph;
33 class vtkUnstructuredGrid;
34 class vtkRectilinearGrid;
35 class vtkStructuredGrid;
36 class vtkVariantArray;
37 class vtkIdTypeArray;
38 class vtkDoubleArray;
39 class vtkDataSet;
40
41 class TimeKeeper;
42 class MEDTimeReq;
43
44 class ELGACmp
45 {
46 public:
47   vtkIdTypeArray *findOrCreate(const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const std::vector<std::string>& locsReallyUsed, vtkDoubleArray *vtkd, vtkDataSet *ds, bool& isNew) const;
48   void appendELGAIfAny(vtkDataSet *ds) const;
49   ~ELGACmp();
50 private:
51   vtkIdTypeArray *isExisting(const std::vector<std::string>& locsReallyUsed, vtkDoubleArray *vtkd) const;
52   vtkIdTypeArray *createNew(const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const std::vector<std::string>& locsReallyUsed, vtkDoubleArray *vtkd, vtkDataSet *ds) const;
53 private:
54   //! size of _loc_names is equal to _elgas.
55   mutable std::vector< std::vector<std::string> > _loc_names;
56   //! size of _elgas is equal to _loc_names. All instances in _elgas are \b not null.
57   mutable std::vector<vtkIdTypeArray *> _elgas;
58   //! same size than _loc_names and _elgas.
59   mutable std::vector< std::vector< std::pair< vtkQuadratureSchemeDefinition *, unsigned char > > > _defs;
60 };
61
62 class MEDFileFieldRepresentationLeavesArrays : public ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileAnyTypeFieldMultiTS>
63 {
64 public:
65   MEDFileFieldRepresentationLeavesArrays();
66   MEDFileFieldRepresentationLeavesArrays(const ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileAnyTypeFieldMultiTS>& arr);
67   MEDFileFieldRepresentationLeavesArrays& operator=(const MEDFileFieldRepresentationLeavesArrays& other);
68   int getId() const;
69   void setId(int& id) const;
70   void feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, const std::string& tsName, const std::string& meshName, const std::string& comSupStr, std::vector<std::string>& names) const;
71   bool getStatus() const;
72   bool setStatus(bool status) const;
73   std::string getZeName() const;
74   void appendFields(const MEDTimeReq *tr, const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const ParaMEDMEM::MEDMeshMultiLev *mml, const ParaMEDMEM::MEDFileMeshStruct *mst, vtkDataSet *ds) const;
75   void appendELGAIfAny(vtkDataSet *ds) const;
76 public:
77   static const char ZE_SEP[];
78   static const char TS_STR[];
79   static const char COM_SUP_STR[];
80   static const char FAMILY_ID_CELL_NAME[];
81   static const char NUM_ID_CELL_NAME[];
82   static const char FAMILY_ID_NODE_NAME[];
83   static const char NUM_ID_NODE_NAME[];
84 private:
85   mutable bool _activated;
86   mutable int _id;
87   mutable std::string _ze_name;
88   mutable std::string _ze_full_name;
89   ELGACmp _elga_cmp;
90 };
91
92 class MEDFileFieldRepresentationLeaves
93 {
94 public:
95   MEDFileFieldRepresentationLeaves();
96   MEDFileFieldRepresentationLeaves(const std::vector< ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileAnyTypeFieldMultiTS> >& arr,
97                                    const ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileFastCellSupportComparator>& fsp);
98   ~MEDFileFieldRepresentationLeaves();
99   bool empty() const;
100   void setId(int& id) const;
101   std::string getMeshName() const;
102   int getNumberOfArrays() const;
103   int getNumberOfTS() const;
104   void feedSIL(const ParaMEDMEM::MEDFileMeshes *ms, vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, const std::string& tsName, const std::string& meshName, const std::string& compSupStr, std::vector<std::string>& names) const;
105   bool containId(int id) const;
106   bool containZeName(const char *name, int& id) const;
107   bool isActivated() const;
108   void printMySelf(std::ostream& os) const;
109   void activateAllArrays() const;
110   const MEDFileFieldRepresentationLeavesArrays& getLeafArr(int id) const;
111   std::vector<double> getTimeSteps(const TimeKeeper& tk) const;
112   std::vector< std::pair<int,int> > getTimeStepsInCoarseMEDFileFormat(std::vector<double>& ts) const;
113   std::string getHumanReadableOverviewOfTS() const;
114   vtkDataSet *buildVTKInstanceNoTimeInterpolation(const MEDTimeReq *tr, const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const ParaMEDMEM::MEDFileMeshes *meshes) const;
115 private:
116   vtkUnstructuredGrid *buildVTKInstanceNoTimeInterpolationUnstructured(ParaMEDMEM::MEDUMeshMultiLev *mm) const;
117   vtkRectilinearGrid *buildVTKInstanceNoTimeInterpolationCartesian(ParaMEDMEM::MEDCMeshMultiLev *mm) const;
118   vtkStructuredGrid *buildVTKInstanceNoTimeInterpolationCurveLinear(ParaMEDMEM::MEDCurveLinearMeshMultiLev *mm) const;
119   void appendFields(const MEDTimeReq *tr, const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const ParaMEDMEM::MEDMeshMultiLev *mml, const ParaMEDMEM::MEDFileMeshes *meshes, vtkDataSet *ds) const;
120 private:
121   std::vector<MEDFileFieldRepresentationLeavesArrays> _arrays;
122   ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileFastCellSupportComparator> _fsp;
123   mutable vtkDataSet *_cached_ds;
124 };
125
126 class MEDFileFieldRepresentationTree
127 {
128 public:
129   MEDFileFieldRepresentationTree();
130   int getNumberOfLeavesArrays() const;
131   void assignIds() const;
132   void activateTheFirst() const;
133   void feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
134   std::string feedSILForFamsAndGrps(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
135   std::string getNameOf(int id) const;
136   bool getStatusOf(int id) const;
137   int getIdHavingZeName(const char *name) const;
138   bool changeStatusOfAndUpdateToHaveCoherentVTKDataSet(int id, bool status) const;
139   int getMaxNumberOfTimeSteps() const;
140   //
141   std::string getDftMeshName() const;
142   std::vector<double> getTimeSteps(int& lev0, const TimeKeeper& tk) const;
143   vtkDataSet *buildVTKInstance(bool isStdOrMode, double timeReq, std::string& meshName, const TimeKeeper& tk) const;
144   void printMySelf(std::ostream& os) const;
145   //non const methods
146   void loadMainStructureOfFile(const char *fileName, bool isMEDOrSauv);
147   void removeEmptyLeaves();
148   // static methods
149   static bool IsFieldMeshRegardingInfo(const std::vector<std::string>& compInfos);
150 public:
151   static const char ROOT_OF_GRPS_IN_TREE[];
152   static const char ROOT_OF_FAM_IDS_IN_TREE[];
153   static const char COMPO_STR_TO_LOCATE_MESH_DA[];
154 private:
155   const MEDFileFieldRepresentationLeavesArrays& getLeafArr(int id) const;
156   const MEDFileFieldRepresentationLeaves& getTheSingleActivated(int& lev0, int& lev1, int& lev2) const;
157   static ParaMEDMEM::MEDFileFields *BuildFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms);
158   static void AppendFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms, ParaMEDMEM::MEDFileFields *ret);
159 private:
160   // 1st : timesteps, 2nd : meshName, 3rd : common support
161   std::vector< std::vector< std::vector< MEDFileFieldRepresentationLeaves > > > _data_structure;
162   ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileMeshes> _ms;
163   ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileFields> _fields;
164 };
165
166 class TimeKeeper
167 {
168 public:
169   TimeKeeper(int policy);
170   int getPolicy() const { return _policy; }
171   void setPolicy(int policy) { _policy=policy; }
172   std::vector<double> getTimeStepsRegardingPolicy(const std::vector< std::pair<int,int> >& tsPairs, const std::vector<double>& ts) const;
173   int getTimeStepIdFrom(double timeReq) const;
174   std::vector<double> getPostProcessedTime() const { return _postprocessed_time; }
175   void printSelf(std::ostream& oss) const;
176   std::vector<bool> getTheVectOfBool() const;
177   std::vector< std::pair<bool,std::string> >& getTimesFlagArray() { return _activated_ts; }
178   void setMaxNumberOfTimeSteps(int maxNumberOfTS);
179 private:
180   std::vector<double> getTimeStepsRegardingPolicy0(const std::vector< std::pair<int,int> >& tsPairs, const std::vector<double>& ts) const;
181   std::vector<double> getTimeStepsRegardingPolicy1(const std::vector< std::pair<int,int> >& tsPairs, const std::vector<double>& ts) const;
182   std::vector<double> processedUsingPairOfIds(const std::vector< std::pair<int,int> >& tsPairs) const;
183 private:
184   int _policy;
185   mutable std::vector<double> _postprocessed_time;
186   std::vector< std::pair<bool,std::string> > _activated_ts;
187 };
188
189 #endif