]> SALOME platform Git repositories - modules/visu.git/blob - src/CONVERTOR/VISU_MeshValue.hxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / CONVERTOR / VISU_MeshValue.hxx
1 //  VISU CONVERTOR :
2 //
3 //  Copyright (C) 2003  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 //  File   : VISU_Convertor.hxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #ifndef VISU_MeshValue_HeaderFile
28 #define VISU_MeshValue_HeaderFile
29
30 /*! 
31   \file VISU_MeshValue.hxx
32   \brief The file contains declarations for basic interfaces that defines mesh value of mesh elements
33 */
34
35 #include "VISU_Convertor.hxx"
36 #include "VISU_ConvertorDef_impl.hxx"
37
38 #include "MED_SliceArray.hxx"
39 #include "MED_Vector.hxx"
40
41 namespace VISU
42 {
43   //---------------------------------------------------------------
44   //! Define a base class for the container to get access to data assigned to mesh
45   class VISU_CONVERTOR_EXPORT TMeshValueBase
46   {
47   public:
48     //! To intitilize the data strucutre
49     void
50     Init(vtkIdType theNbElem,
51          vtkIdType theNbGauss,
52          vtkIdType theNbComp);
53
54     //! Gets memory size used by the instance (bytes).
55     virtual
56     unsigned long int
57     GetMemorySize() const = 0;
58
59     //! Gets number of mesh elements where the data assigned to.
60     vtkIdType
61     GetNbElem() const;
62
63     //! Gets number of components of corresponding MED FIELD.
64     vtkIdType
65     GetNbComp() const;
66
67     //! Gets number of Gauss Points.
68     vtkIdType
69     GetNbGauss() const;
70
71     size_t
72     size() const;
73
74   protected:
75     vtkIdType myNbElem; //!< Defines number of mesh elements where the data assigned to
76     vtkIdType myNbComp; //!< Keeps number of components of corresponding MED FIELD
77     vtkIdType myNbGauss; //!< Defines number of Gauss Points
78     vtkIdType myStep; //!< Internal variable
79   };
80   typedef MED::SharedPtr<TMeshValueBase> PMeshValue;
81
82
83   //---------------------------------------------------------------
84   //! Define a container to get access to data assigned to mesh
85   template<class TValueType>
86   class VISU_CONVERTOR_EXPORT TTMeshValue: public virtual TMeshValueBase
87   {
88   public:
89     typedef MED::TSlice<TValueType> TValueSlice;
90     typedef MED::TCSlice<TValueType> TCValueSlice;
91     
92     typedef TVector<TCValueSlice> TCValueSliceArr;
93     typedef TVector<TValueSlice> TValueSliceArr;
94
95     virtual
96     const TValueType*
97     GetPointer() const = 0;
98
99     virtual
100     TValueType*
101     GetPointer() = 0;
102
103     //! To get assigned values first by Gauss Points and then by components (constant version)
104     TCValueSliceArr
105     GetGaussValueSliceArr(vtkIdType theElemId) const
106     {
107       TCValueSliceArr aValueSliceArr(this->myNbGauss);
108       vtkIdType anId = theElemId * this->myStep;
109       for(vtkIdType aGaussId = 0; aGaussId < this->myNbGauss; aGaussId++){
110         aValueSliceArr[aGaussId] =
111           TCValueSlice(this->GetPointer(), 
112                        this->size(),
113                        std::slice(anId, this->myNbComp, 1));
114         anId += this->myNbComp;
115       }
116       return aValueSliceArr;
117     }
118
119     //! To get assigned values first by Gauss Points and then by components
120     TValueSliceArr 
121     GetGaussValueSliceArr(vtkIdType theElemId)
122     {
123       TValueSliceArr aValueSliceArr(this->myNbGauss);
124       vtkIdType anId = theElemId * this->myStep;
125       for(vtkIdType aGaussId = 0; aGaussId < this->myNbGauss; aGaussId++){
126         aValueSliceArr[aGaussId] =
127           TValueSlice(this->GetPointer(), 
128                       this->size(),
129                       std::slice(anId, this->myNbComp, 1));
130         anId += this->myNbComp;
131       }
132       return aValueSliceArr;
133     }
134
135     //! To get assigned values first by components and then by Gauss Points (constant version)
136     TCValueSliceArr
137     GetCompValueSliceArr(vtkIdType theElemId) const
138     {
139       TCValueSliceArr aValueSliceArr(this->myNbComp);
140       vtkIdType anId = theElemId * this->myStep;
141       for(vtkIdType aCompId = 0; aCompId < this->myNbComp; aCompId++){
142         aValueSliceArr[aCompId] =
143           TCValueSlice(this->GetPointer(), 
144                        this->size(),
145                        std::slice(anId, this->myNbGauss, this->myNbComp));
146         anId += 1;
147       }
148       return aValueSliceArr;
149     }
150
151     //! To get assigned values first by components and then by Gauss Points
152     TValueSliceArr 
153     GetCompValueSliceArr(vtkIdType theElemId)
154     {
155       TValueSliceArr aValueSliceArr(this->myNbComp);
156       vtkIdType anId = theElemId * this->myStep;
157       for(vtkIdType aCompId = 0; aCompId < this->myNbComp; aCompId++){
158         aValueSliceArr[aCompId] =
159           TValueSlice(this->GetPointer(), 
160                       this->size(),
161                       std::slice(anId, this->myNbGauss, this->myNbComp));
162         anId += 1;
163       }
164       return aValueSliceArr;
165     }
166
167     //! Gets memory size used by the instance (bytes).
168     virtual
169     unsigned long int
170     GetMemorySize() const
171     {
172       return this->size() * sizeof(TValueType);
173     }
174   };
175   
176
177   //---------------------------------------------------------------
178   //! Define a container to get access to data assigned to mesh
179   template<class TValueType, class TContainerType>
180   class TTMeshValueHolder: public virtual TTMeshValue<TValueType>
181   {
182   public:
183     //! To initilize the class instance
184     void
185     Init(vtkIdType theNbElem,
186          vtkIdType theNbGauss,
187          vtkIdType theNbComp,
188          const TContainerType& theContainer)
189     {
190       TMeshValueBase::Init(theNbElem, theNbGauss, theNbComp);
191       myContainer = theContainer;
192     }
193
194   protected:
195     mutable TContainerType myContainer; //!< Keeps the mesh values container itself
196   };
197
198
199   //---------------------------------------------------------------
200   // Initilize corresponding vtkDataSetAttributes for TValForTime
201   void 
202   GetTimeStampOnProfile(const PUnstructuredGrid& theSource,
203                         const PFieldImpl& theField, 
204                         const PValForTimeImpl& theValForTime,
205                         const VISU::TEntity& theEntity);
206
207
208   //---------------------------------------------------------------
209   // Initilize corresponding vtkDataSetAttributes for TValForTime
210   void 
211   GetTimeStampOnGaussMesh(const PPolyData& theSource,
212                           const PFieldImpl& theField, 
213                           const PValForTimeImpl& theValForTime);
214
215
216   //---------------------------------------------------------------
217 }
218
219 #endif