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