Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / CONVERTOR / VISU_MeshValue.hxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU CONVERTOR :
24 //  File   : VISU_Convertor.hxx
25 //  Author : Alexey PETROV
26 //  Module : VISU
27 //
28 #ifndef VISU_MeshValue_HeaderFile
29 #define VISU_MeshValue_HeaderFile
30
31 /*! 
32   \file VISU_MeshValue.hxx
33   \brief The file contains declarations for basic interfaces that defines mesh value of mesh elements
34 */
35
36 #include "VISU_Convertor.hxx"
37 #include "VISU_ConvertorDef_impl.hxx"
38
39 #include "MED_SliceArray.hxx"
40 #include "MED_Vector.hxx"
41
42 namespace VISU
43 {
44   //---------------------------------------------------------------
45   //! Define a base class for the container to get access to data assigned to mesh
46   class VISU_CONVERTOR_EXPORT TMeshValueBase
47   {
48   public:
49     //! To intitilize the data strucutre
50     void
51     Init(vtkIdType theNbElem,
52          vtkIdType theNbGauss,
53          vtkIdType theNbComp);
54
55     //! Gets memory size used by the instance (bytes).
56     virtual
57     unsigned long int
58     GetMemorySize() const = 0;
59
60     //! Gets number of mesh elements where the data assigned to.
61     vtkIdType
62     GetNbElem() const;
63
64     //! Gets number of components of corresponding MED FIELD.
65     vtkIdType
66     GetNbComp() const;
67
68     //! Gets number of Gauss Points.
69     vtkIdType
70     GetNbGauss() const;
71
72     size_t
73     size() const;
74
75   protected:
76     vtkIdType myNbElem; //!< Defines number of mesh elements where the data assigned to
77     vtkIdType myNbComp; //!< Keeps number of components of corresponding MED FIELD
78     vtkIdType myNbGauss; //!< Defines number of Gauss Points
79     vtkIdType myStep; //!< Internal variable
80   };
81   typedef MED::SharedPtr<TMeshValueBase> PMeshValue;
82
83
84   //---------------------------------------------------------------
85   //! Define a container to get access to data assigned to mesh
86   template<class TValueType>
87   class VISU_CONVERTOR_EXPORT TTMeshValue: public virtual TMeshValueBase
88   {
89   public:
90     typedef MED::TSlice<TValueType> TValueSlice;
91     typedef MED::TCSlice<TValueType> TCValueSlice;
92     
93     typedef TVector<TCValueSlice> TCValueSliceArr;
94     typedef TVector<TValueSlice> TValueSliceArr;
95
96     virtual
97     const TValueType*
98     GetPointer() const = 0;
99
100     virtual
101     TValueType*
102     GetPointer() = 0;
103
104     //! To get assigned values first by Gauss Points and then by components (constant version)
105     TCValueSliceArr
106     GetGaussValueSliceArr(vtkIdType theElemId) const
107     {
108       TCValueSliceArr aValueSliceArr(this->myNbGauss);
109       vtkIdType anId = theElemId * this->myStep;
110       for(vtkIdType aGaussId = 0; aGaussId < this->myNbGauss; aGaussId++){
111         aValueSliceArr[aGaussId] =
112           TCValueSlice(this->GetPointer(), 
113                        this->size(),
114                        std::slice(anId, this->myNbComp, 1));
115         anId += this->myNbComp;
116       }
117       return aValueSliceArr;
118     }
119
120     //! To get assigned values first by Gauss Points and then by components
121     TValueSliceArr 
122     GetGaussValueSliceArr(vtkIdType theElemId)
123     {
124       TValueSliceArr aValueSliceArr(this->myNbGauss);
125       vtkIdType anId = theElemId * this->myStep;
126       for(vtkIdType aGaussId = 0; aGaussId < this->myNbGauss; aGaussId++){
127         aValueSliceArr[aGaussId] =
128           TValueSlice(this->GetPointer(), 
129                       this->size(),
130                       std::slice(anId, this->myNbComp, 1));
131         anId += this->myNbComp;
132       }
133       return aValueSliceArr;
134     }
135
136     //! To get assigned values first by components and then by Gauss Points (constant version)
137     TCValueSliceArr
138     GetCompValueSliceArr(vtkIdType theElemId) const
139     {
140       TCValueSliceArr aValueSliceArr(this->myNbComp);
141       vtkIdType anId = theElemId * this->myStep;
142       for(vtkIdType aCompId = 0; aCompId < this->myNbComp; aCompId++){
143         aValueSliceArr[aCompId] =
144           TCValueSlice(this->GetPointer(), 
145                        this->size(),
146                        std::slice(anId, this->myNbGauss, this->myNbComp));
147         anId += 1;
148       }
149       return aValueSliceArr;
150     }
151
152     //! To get assigned values first by components and then by Gauss Points
153     TValueSliceArr 
154     GetCompValueSliceArr(vtkIdType theElemId)
155     {
156       TValueSliceArr aValueSliceArr(this->myNbComp);
157       vtkIdType anId = theElemId * this->myStep;
158       for(vtkIdType aCompId = 0; aCompId < this->myNbComp; aCompId++){
159         aValueSliceArr[aCompId] =
160           TValueSlice(this->GetPointer(), 
161                       this->size(),
162                       std::slice(anId, this->myNbGauss, this->myNbComp));
163         anId += 1;
164       }
165       return aValueSliceArr;
166     }
167
168     //! Gets memory size used by the instance (bytes).
169     virtual
170     unsigned long int
171     GetMemorySize() const
172     {
173       return this->size() * sizeof(TValueType);
174     }
175   };
176   
177
178   //---------------------------------------------------------------
179   //! Define a container to get access to data assigned to mesh
180   template<class TValueType, class TContainerType>
181   class TTMeshValueHolder: public virtual TTMeshValue<TValueType>
182   {
183   public:
184     //! To initilize the class instance
185     void
186     Init(vtkIdType theNbElem,
187          vtkIdType theNbGauss,
188          vtkIdType theNbComp,
189          const TContainerType& theContainer)
190     {
191       TMeshValueBase::Init(theNbElem, theNbGauss, theNbComp);
192       myContainer = theContainer;
193     }
194
195   protected:
196     mutable TContainerType myContainer; //!< Keeps the mesh values container itself
197   };
198
199
200   //---------------------------------------------------------------
201   // Initilize corresponding vtkDataSetAttributes for TValForTime
202   void 
203   GetTimeStampOnProfile(const PUnstructuredGrid& theSource,
204                         const PFieldImpl& theField, 
205                         const PValForTimeImpl& theValForTime,
206                         const VISU::TEntity& theEntity);
207
208
209   //---------------------------------------------------------------
210   // Initilize corresponding vtkDataSetAttributes for TValForTime
211   void 
212   GetTimeStampOnGaussMesh(const PPolyData& theSource,
213                           const PFieldImpl& theField, 
214                           const PValForTimeImpl& theValForTime);
215
216   void 
217   InitMed2VisuArray(std::vector<int>& anArray, EGeometry aEGeom);
218
219
220   //---------------------------------------------------------------
221 }
222
223 #endif