Salome HOME
74d1732b303b808e9962eed6afcabd839128bf39
[modules/visu.git] / src / CONVERTOR / VISU_ElnoMeshValue.hxx
1 //  Copyright (C) 2007-2008  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 //  File   : VISU_ElnoMeshValue.hxx
23 //  Author : Alexey PETROV
24 //  Module : VISU
25 //
26 #ifndef VISU_ElnoMeshValue_HeaderFile
27 #define VISU_ElnoMeshValue_HeaderFile
28
29 #include "VISU_VTKTypeList.hxx"
30 #include <vtkDataSetAttributes.h>
31
32
33 /*! 
34   \file VISU_ElnoMeshValue.hxx
35   \brief The file contains declarations for the acess to the specific ELNO MED data
36 */
37
38 namespace VISU
39 {
40   //---------------------------------------------------------------
41   template< int elno_type >
42   struct TGetElnoNodeData
43   {
44     typedef typename TL::TEnum2VTKArrayType< elno_type >::TResult TVTKDataArray;
45     typedef typename TL::TEnum2VTKBasicType< elno_type >::TResult TDataType;
46     TVTKDataArray *myElnoDataArray;
47     vtkIntArray *myElnoDataMapper;
48     int myElemInfo[3];
49
50
51     //----------------------------------------------------------------------------
52     TGetElnoNodeData( vtkDataArray *theElnoDataArray,
53                       vtkDataArray *theElnoDataMapper )
54       : myElnoDataArray( TVTKDataArray::SafeDownCast( theElnoDataArray ) )
55       , myElnoDataMapper( vtkIntArray::SafeDownCast( theElnoDataMapper ) )
56     {}
57
58
59     //----------------------------------------------------------------------------
60     TDataType*
61     operator () ( vtkIdType theCellId, vtkIdType theLocalPntId )
62     {
63       myElnoDataMapper->GetTupleValue( theCellId, myElemInfo );
64
65       vtkIdType aPos = myElemInfo[ 0 ] + theLocalPntId * myElemInfo[ 1 ];
66
67       return myElnoDataArray->GetPointer( aPos );
68     }
69
70
71     //----------------------------------------------------------------------------
72     int
73     getNbComp()
74     {
75       myElnoDataMapper->GetTupleValue( 0, myElemInfo );
76
77       return myElemInfo[ 1 ];
78     }
79   };
80
81
82   //----------------------------------------------------------------------------------------------
83   template< int elno_type >
84   struct TSetElnoNodeData
85   {
86     typedef typename TL::TEnum2VTKArrayType< elno_type >::TResult TVTKDataArray;
87     typedef typename TL::TEnum2VTKBasicType< elno_type >::TResult TDataType;
88
89     //----------------------------------------------------------------------------------------------
90     TSetElnoNodeData( vtkIdType theEffectNbComp,
91                       vtkIdType theRealNbComp,
92                       vtkIdType theNbTuples,
93                       const char* theDataArrayName,
94                       const char* theMapperArrayName )
95       : myElnoDataArray( TVTKDataArray::New() )
96       , myElnoDataMapper( vtkIntArray::New() )
97     {
98       myElnoDataArray->SetNumberOfComponents( theEffectNbComp );
99       myElnoDataArray->SetNumberOfTuples( theNbTuples );
100       myElnoDataArray->SetName( theDataArrayName );
101
102       myElnoDataMapper->SetNumberOfComponents( 3 );
103       myElnoDataMapper->Allocate( theNbTuples * 3 );
104       myElnoDataMapper->SetName( theMapperArrayName );
105
106       myElemInfo[ 0 ] = 0;
107       myElemInfo[ 1 ] = theRealNbComp;
108       myElemInfo[ 2 ] = 0;
109     }
110
111
112     //----------------------------------------------------------------------------------------------
113     ~TSetElnoNodeData()
114     {
115       myElnoDataArray->Delete();
116       myElnoDataMapper->Delete();
117     }
118
119
120     //----------------------------------------------------------------------------------------------
121     int
122     AddNextPointData( TDataType* theDataPtr )
123     {
124       vtkIdType aPos = myElemInfo[ 0 ] + myElemInfo[ 2 ] * myElemInfo[ 1 ];
125
126       TDataType* aDataPtr = myElnoDataArray->GetPointer( aPos );
127
128       for ( vtkIdType aCompId = 0; aCompId < myElemInfo[ 1 ]; aCompId++ )
129         *aDataPtr++ = *theDataPtr++;
130
131       return myElemInfo[ 2 ]++;
132     }
133
134
135     //----------------------------------------------------------------------------------------------
136     void
137     InsertNextCellData()
138     {
139       myElnoDataMapper->InsertNextTupleValue( myElemInfo );
140       myElemInfo[ 0 ] += myElemInfo[ 2 ] * myElemInfo[ 1 ];
141       myElemInfo[ 2 ] = 0;
142     }
143
144
145     //----------------------------------------------------------------------------------------------
146     void
147     AddData( vtkDataSetAttributes* theDataSetAttributes )
148     {
149       theDataSetAttributes->AddArray( myElnoDataArray );
150       theDataSetAttributes->AddArray( myElnoDataMapper );
151     }
152
153   protected:
154     TVTKDataArray *myElnoDataArray;
155     vtkIntArray *myElnoDataMapper;
156     int myElemInfo[ 3 ];
157   };
158
159
160   //---------------------------------------------------------------
161 }
162
163 #endif