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