Salome HOME
Merge branch 'V7_5_BR'
[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, or (at your option) any later version.
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 #include "MEDLoaderForPV.h"
27
28 #include "vtkType.h"
29
30 #include <vector>
31
32 class vtkQuadratureSchemeDefinition;
33 class vtkMutableDirectedGraph;
34 class vtkUnstructuredGrid;
35 class vtkRectilinearGrid;
36 class vtkStructuredGrid;
37 class vtkVariantArray;
38 class vtkIdTypeArray;
39 class vtkDoubleArray;
40 class vtkDataSet;
41
42 class TimeKeeper;
43 class MEDTimeReq;
44
45 class ELGACmp
46 {
47 public:
48   vtkIdTypeArray *findOrCreate(const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const std::vector<std::string>& locsReallyUsed, vtkDoubleArray *vtkd, vtkDataSet *ds, bool& isNew) const;
49   void appendELGAIfAny(vtkDataSet *ds) const;
50   ~ELGACmp();
51 private:
52   vtkIdTypeArray *isExisting(const std::vector<std::string>& locsReallyUsed, vtkDoubleArray *vtkd) const;
53   vtkIdTypeArray *createNew(const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const std::vector<std::string>& locsReallyUsed, vtkDoubleArray *vtkd, vtkDataSet *ds) const;
54 private:
55   //! size of _loc_names is equal to _elgas.
56   mutable std::vector< std::vector<std::string> > _loc_names;
57   //! size of _elgas is equal to _loc_names. All instances in _elgas are \b not null.
58   mutable std::vector<vtkIdTypeArray *> _elgas;
59   //! same size than _loc_names and _elgas.
60   mutable std::vector< std::vector< std::pair< vtkQuadratureSchemeDefinition *, unsigned char > > > _defs;
61 };
62
63 class MEDLOADERFORPV_EXPORT MEDFileFieldRepresentationLeavesArrays : public ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileAnyTypeFieldMultiTS>
64 {
65 public:
66   MEDFileFieldRepresentationLeavesArrays();
67   MEDFileFieldRepresentationLeavesArrays(const ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileAnyTypeFieldMultiTS>& arr);
68   MEDFileFieldRepresentationLeavesArrays& operator=(const MEDFileFieldRepresentationLeavesArrays& other);
69   int getId() const;
70   void setId(int& id) const;
71   void feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
72   void computeFullNameInLeaves(const std::string& tsName, const std::string& meshName, const std::string& comSupStr) const;
73   bool getStatus() const;
74   bool setStatus(bool status) const;
75   std::string getZeName() const;
76   const char *getZeNameC() const;
77   void appendFields(const MEDTimeReq *tr, const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const ParaMEDMEM::MEDMeshMultiLev *mml, const ParaMEDMEM::MEDFileMeshStruct *mst, vtkDataSet *ds) const;
78   void appendELGAIfAny(vtkDataSet *ds) const;
79 public:
80   static const char ZE_SEP[];
81   static const char TS_STR[];
82   static const char COM_SUP_STR[];
83   static const char FAMILY_ID_CELL_NAME[];
84   static const char NUM_ID_CELL_NAME[];
85   static const char FAMILY_ID_NODE_NAME[];
86   static const char NUM_ID_NODE_NAME[];
87 private:
88   mutable bool _activated;
89   mutable int _id;
90   mutable std::string _ze_name;
91   mutable std::string _ze_full_name;
92   ELGACmp _elga_cmp;
93 };
94
95 class MEDLOADERFORPV_EXPORT MEDFileFieldRepresentationLeaves
96 {
97 public:
98   MEDFileFieldRepresentationLeaves();
99   MEDFileFieldRepresentationLeaves(const std::vector< ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileAnyTypeFieldMultiTS> >& arr,
100                                    const ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileFastCellSupportComparator>& fsp);
101   ~MEDFileFieldRepresentationLeaves();
102   bool empty() const;
103   void setId(int& id) const;
104   std::string getMeshName() const;
105   int getNumberOfArrays() const;
106   int getNumberOfTS() const;
107   void feedSIL(const ParaMEDMEM::MEDFileMeshes *ms, const std::string& meshName, vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
108   void computeFullNameInLeaves(const std::string& tsName, const std::string& meshName, const std::string& comSupStr) const;
109   bool containId(int id) const;
110   bool containZeName(const char *name, int& id) const;
111   bool isActivated() const;
112   void printMySelf(std::ostream& os) const;
113   void activateAllArrays() const;
114   const MEDFileFieldRepresentationLeavesArrays& getLeafArr(int id) const;
115   std::vector<double> getTimeSteps(const TimeKeeper& tk) const;
116   std::vector< std::pair<int,int> > getTimeStepsInCoarseMEDFileFormat(std::vector<double>& ts) const;
117   std::string getHumanReadableOverviewOfTS() const;
118   vtkDataSet *buildVTKInstanceNoTimeInterpolation(const MEDTimeReq *tr, const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const ParaMEDMEM::MEDFileMeshes *meshes) const;
119 private:
120   vtkUnstructuredGrid *buildVTKInstanceNoTimeInterpolationUnstructured(ParaMEDMEM::MEDUMeshMultiLev *mm) const;
121   vtkRectilinearGrid *buildVTKInstanceNoTimeInterpolationCartesian(ParaMEDMEM::MEDCMeshMultiLev *mm) const;
122   vtkStructuredGrid *buildVTKInstanceNoTimeInterpolationCurveLinear(ParaMEDMEM::MEDCurveLinearMeshMultiLev *mm) const;
123   void appendFields(const MEDTimeReq *tr, const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const ParaMEDMEM::MEDMeshMultiLev *mml, const ParaMEDMEM::MEDFileMeshes *meshes, vtkDataSet *ds) const;
124 private:
125   std::vector<MEDFileFieldRepresentationLeavesArrays> _arrays;
126   ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileFastCellSupportComparator> _fsp;
127   mutable vtkDataSet *_cached_ds;
128 };
129
130 class MEDLOADERFORPV_EXPORT MEDFileFieldRepresentationTree
131 {
132 public:
133   MEDFileFieldRepresentationTree();
134   int getNumberOfLeavesArrays() const;
135   void assignIds() const;
136   void activateTheFirst() const;
137   void computeFullNameInLeaves() const;
138   void feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
139   std::string feedSILForFamsAndGrps(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
140   std::string getNameOf(int id) const;
141   const char *getNameOfC(int id) const;
142   bool getStatusOf(int id) const;
143   int getIdHavingZeName(const char *name) const;
144   bool changeStatusOfAndUpdateToHaveCoherentVTKDataSet(int id, bool status) const;
145   int getMaxNumberOfTimeSteps() const;
146   //
147   std::string getDftMeshName() const;
148   std::vector<double> getTimeSteps(int& lev0, const TimeKeeper& tk) const;
149   vtkDataSet *buildVTKInstance(bool isStdOrMode, double timeReq, std::string& meshName, const TimeKeeper& tk) const;
150   void printMySelf(std::ostream& os) const;
151   //non const methods
152   void loadMainStructureOfFile(const char *fileName, bool isMEDOrSauv, int iPart, int nbOfParts);
153   void removeEmptyLeaves();
154   // static methods
155   static bool IsFieldMeshRegardingInfo(const std::vector<std::string>& compInfos);
156   static std::string PostProcessFieldName(const std::string& fullFieldName);
157 public:
158   static const char ROOT_OF_GRPS_IN_TREE[];
159   static const char ROOT_OF_FAM_IDS_IN_TREE[];
160   static const char COMPO_STR_TO_LOCATE_MESH_DA[];
161 private:
162   const MEDFileFieldRepresentationLeavesArrays& getLeafArr(int id) const;
163   const MEDFileFieldRepresentationLeaves& getTheSingleActivated(int& lev0, int& lev1, int& lev2) const;
164   static ParaMEDMEM::MEDFileFields *BuildFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms);
165   static void AppendFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms, ParaMEDMEM::MEDFileFields *ret);
166   static std::string BuildAUniqueArrayNameForMesh(const std::string& meshName, const ParaMEDMEM::MEDFileFields *ret);
167   static std::vector<std::string> SplitFieldNameIntoParts(const std::string& fullFieldName, char sep);
168 private:
169   // 1st : timesteps, 2nd : meshName, 3rd : common support
170   std::vector< std::vector< std::vector< MEDFileFieldRepresentationLeaves > > > _data_structure;
171   ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileMeshes> _ms;
172   ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileFields> _fields;
173 };
174
175 class MEDLOADERFORPV_EXPORT TimeKeeper
176 {
177 public:
178   TimeKeeper(int policy);
179   int getPolicy() const { return _policy; }
180   void setPolicy(int policy) { _policy=policy; }
181   std::vector<double> getTimeStepsRegardingPolicy(const std::vector< std::pair<int,int> >& tsPairs, const std::vector<double>& ts) const;
182   int getTimeStepIdFrom(double timeReq) const;
183   std::vector<double> getPostProcessedTime() const { return _postprocessed_time; }
184   void printSelf(std::ostream& oss) const;
185   std::vector<bool> getTheVectOfBool() const;
186   std::vector< std::pair<bool,std::string> >& getTimesFlagArray() { return _activated_ts; }
187   void setMaxNumberOfTimeSteps(int maxNumberOfTS);
188 private:
189   std::vector<double> getTimeStepsRegardingPolicy0(const std::vector< std::pair<int,int> >& tsPairs, const std::vector<double>& ts) const;
190   std::vector<double> getTimeStepsRegardingPolicy1(const std::vector< std::pair<int,int> >& tsPairs, const std::vector<double>& ts) const;
191   std::vector<double> processedUsingPairOfIds(const std::vector< std::pair<int,int> >& tsPairs) const;
192 private:
193   int _policy;
194   mutable std::vector<double> _postprocessed_time;
195   std::vector< std::pair<bool,std::string> > _activated_ts;
196 };
197
198 #endif