1 // Copyright (C) 2010-2014 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay
21 #ifndef __MEDFILEFIELDREPRESENTATIONTREE_HXX__
22 #define __MEDFILEFIELDREPRESENTATIONTREE_HXX__
24 #include "MEDFileMesh.hxx"
25 #include "MEDFileField.hxx"
31 class vtkQuadratureSchemeDefinition;
32 class vtkMutableDirectedGraph;
33 class vtkUnstructuredGrid;
34 class vtkRectilinearGrid;
35 class vtkStructuredGrid;
36 class vtkVariantArray;
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;
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;
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;
62 class MEDFileFieldRepresentationLeavesArrays : public ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileAnyTypeFieldMultiTS>
65 MEDFileFieldRepresentationLeavesArrays();
66 MEDFileFieldRepresentationLeavesArrays(const ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileAnyTypeFieldMultiTS>& arr);
67 MEDFileFieldRepresentationLeavesArrays& operator=(const MEDFileFieldRepresentationLeavesArrays& other);
69 void setId(int& id) const;
70 void feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
71 void computeFullNameInLeaves(const std::string& tsName, const std::string& meshName, const std::string& comSupStr) const;
72 bool getStatus() const;
73 bool setStatus(bool status) const;
74 std::string getZeName() const;
75 void appendFields(const MEDTimeReq *tr, const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const ParaMEDMEM::MEDMeshMultiLev *mml, const ParaMEDMEM::MEDFileMeshStruct *mst, vtkDataSet *ds) const;
76 void appendELGAIfAny(vtkDataSet *ds) const;
78 static const char ZE_SEP[];
79 static const char TS_STR[];
80 static const char COM_SUP_STR[];
81 static const char FAMILY_ID_CELL_NAME[];
82 static const char NUM_ID_CELL_NAME[];
83 static const char FAMILY_ID_NODE_NAME[];
84 static const char NUM_ID_NODE_NAME[];
86 mutable bool _activated;
88 mutable std::string _ze_name;
89 mutable std::string _ze_full_name;
93 class MEDFileFieldRepresentationLeaves
96 MEDFileFieldRepresentationLeaves();
97 MEDFileFieldRepresentationLeaves(const std::vector< ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileAnyTypeFieldMultiTS> >& arr,
98 const ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileFastCellSupportComparator>& fsp);
99 ~MEDFileFieldRepresentationLeaves();
101 void setId(int& id) const;
102 std::string getMeshName() const;
103 int getNumberOfArrays() const;
104 int getNumberOfTS() const;
105 void feedSIL(const ParaMEDMEM::MEDFileMeshes *ms, const std::string& meshName, vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
106 void computeFullNameInLeaves(const std::string& tsName, const std::string& meshName, const std::string& comSupStr) const;
107 bool containId(int id) const;
108 bool containZeName(const char *name, int& id) const;
109 bool isActivated() const;
110 void printMySelf(std::ostream& os) const;
111 void activateAllArrays() const;
112 const MEDFileFieldRepresentationLeavesArrays& getLeafArr(int id) const;
113 std::vector<double> getTimeSteps(const TimeKeeper& tk) const;
114 std::vector< std::pair<int,int> > getTimeStepsInCoarseMEDFileFormat(std::vector<double>& ts) const;
115 std::string getHumanReadableOverviewOfTS() const;
116 vtkDataSet *buildVTKInstanceNoTimeInterpolation(const MEDTimeReq *tr, const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const ParaMEDMEM::MEDFileMeshes *meshes) const;
118 vtkUnstructuredGrid *buildVTKInstanceNoTimeInterpolationUnstructured(ParaMEDMEM::MEDUMeshMultiLev *mm) const;
119 vtkRectilinearGrid *buildVTKInstanceNoTimeInterpolationCartesian(ParaMEDMEM::MEDCMeshMultiLev *mm) const;
120 vtkStructuredGrid *buildVTKInstanceNoTimeInterpolationCurveLinear(ParaMEDMEM::MEDCurveLinearMeshMultiLev *mm) const;
121 void appendFields(const MEDTimeReq *tr, const ParaMEDMEM::MEDFileFieldGlobsReal *globs, const ParaMEDMEM::MEDMeshMultiLev *mml, const ParaMEDMEM::MEDFileMeshes *meshes, vtkDataSet *ds) const;
123 std::vector<MEDFileFieldRepresentationLeavesArrays> _arrays;
124 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileFastCellSupportComparator> _fsp;
125 mutable vtkDataSet *_cached_ds;
128 class MEDFileFieldRepresentationTree
131 MEDFileFieldRepresentationTree();
132 int getNumberOfLeavesArrays() const;
133 void assignIds() const;
134 void activateTheFirst() const;
135 void computeFullNameInLeaves() const;
136 void feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
137 std::string feedSILForFamsAndGrps(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
138 std::string getNameOf(int id) const;
139 bool getStatusOf(int id) const;
140 int getIdHavingZeName(const char *name) const;
141 bool changeStatusOfAndUpdateToHaveCoherentVTKDataSet(int id, bool status) const;
142 int getMaxNumberOfTimeSteps() const;
144 std::string getDftMeshName() const;
145 std::vector<double> getTimeSteps(int& lev0, const TimeKeeper& tk) const;
146 vtkDataSet *buildVTKInstance(bool isStdOrMode, double timeReq, std::string& meshName, const TimeKeeper& tk) const;
147 void printMySelf(std::ostream& os) const;
149 void loadMainStructureOfFile(const char *fileName, bool isMEDOrSauv);
150 void removeEmptyLeaves();
152 static bool IsFieldMeshRegardingInfo(const std::vector<std::string>& compInfos);
153 static std::string PostProcessFieldName(const std::string& fullFieldName);
155 static const char ROOT_OF_GRPS_IN_TREE[];
156 static const char ROOT_OF_FAM_IDS_IN_TREE[];
157 static const char COMPO_STR_TO_LOCATE_MESH_DA[];
159 const MEDFileFieldRepresentationLeavesArrays& getLeafArr(int id) const;
160 const MEDFileFieldRepresentationLeaves& getTheSingleActivated(int& lev0, int& lev1, int& lev2) const;
161 static ParaMEDMEM::MEDFileFields *BuildFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms);
162 static void AppendFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms, ParaMEDMEM::MEDFileFields *ret);
163 static std::vector<std::string> SplitFieldNameIntoParts(const std::string& fullFieldName, char sep);
165 // 1st : timesteps, 2nd : meshName, 3rd : common support
166 std::vector< std::vector< std::vector< MEDFileFieldRepresentationLeaves > > > _data_structure;
167 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileMeshes> _ms;
168 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDFileFields> _fields;
174 TimeKeeper(int policy);
175 int getPolicy() const { return _policy; }
176 void setPolicy(int policy) { _policy=policy; }
177 std::vector<double> getTimeStepsRegardingPolicy(const std::vector< std::pair<int,int> >& tsPairs, const std::vector<double>& ts) const;
178 int getTimeStepIdFrom(double timeReq) const;
179 std::vector<double> getPostProcessedTime() const { return _postprocessed_time; }
180 void printSelf(std::ostream& oss) const;
181 std::vector<bool> getTheVectOfBool() const;
182 std::vector< std::pair<bool,std::string> >& getTimesFlagArray() { return _activated_ts; }
183 void setMaxNumberOfTimeSteps(int maxNumberOfTS);
185 std::vector<double> getTimeStepsRegardingPolicy0(const std::vector< std::pair<int,int> >& tsPairs, const std::vector<double>& ts) const;
186 std::vector<double> getTimeStepsRegardingPolicy1(const std::vector< std::pair<int,int> >& tsPairs, const std::vector<double>& ts) const;
187 std::vector<double> processedUsingPairOfIds(const std::vector< std::pair<int,int> >& tsPairs) const;
190 mutable std::vector<double> _postprocessed_time;
191 std::vector< std::pair<bool,std::string> > _activated_ts;