Version: 6.3.1

src/CONVERTOR/VISU_ElnoMeshValue.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  File   : VISU_ElnoMeshValue.hxx
00021 //  Author : Alexey PETROV
00022 //  Module : VISU
00023 //
00024 #ifndef VISU_ElnoMeshValue_HeaderFile
00025 #define VISU_ElnoMeshValue_HeaderFile
00026 
00027 #include "VISU_VTKTypeList.hxx"
00028 #include <vtkDataSetAttributes.h>
00029 
00030 
00036 namespace VISU
00037 {
00038   //---------------------------------------------------------------
00039   template< int elno_type >
00040   struct TGetElnoNodeData
00041   {
00042     typedef typename TL::TEnum2VTKArrayType< elno_type >::TResult TVTKDataArray;
00043     typedef typename TL::TEnum2VTKBasicType< elno_type >::TResult TDataType;
00044     TVTKDataArray *myElnoDataArray;
00045     vtkIntArray *myElnoDataMapper;
00046     int myElemInfo[3];
00047 
00048 
00049     //----------------------------------------------------------------------------
00050     TGetElnoNodeData( vtkDataArray *theElnoDataArray,
00051                       vtkDataArray *theElnoDataMapper )
00052       : myElnoDataArray( TVTKDataArray::SafeDownCast( theElnoDataArray ) )
00053       , myElnoDataMapper( vtkIntArray::SafeDownCast( theElnoDataMapper ) )
00054     {}
00055 
00056 
00057     //----------------------------------------------------------------------------
00058     TDataType*
00059     operator () ( vtkIdType theCellId, vtkIdType theLocalPntId )
00060     {
00061       myElnoDataMapper->GetTupleValue( theCellId, myElemInfo );
00062 
00063       vtkIdType aPos = myElemInfo[ 0 ] + theLocalPntId * myElemInfo[ 1 ];
00064 
00065       return myElnoDataArray->GetPointer( aPos );
00066     }
00067 
00068 
00069     //----------------------------------------------------------------------------
00070     int
00071     getNbComp()
00072     {
00073       myElnoDataMapper->GetTupleValue( 0, myElemInfo );
00074 
00075       return myElemInfo[ 1 ];
00076     }
00077   };
00078 
00079 
00080   //----------------------------------------------------------------------------------------------
00081   template< int elno_type >
00082   struct TSetElnoNodeData
00083   {
00084     typedef typename TL::TEnum2VTKArrayType< elno_type >::TResult TVTKDataArray;
00085     typedef typename TL::TEnum2VTKBasicType< elno_type >::TResult TDataType;
00086 
00087     //----------------------------------------------------------------------------------------------
00088     TSetElnoNodeData( vtkIdType theEffectNbComp,
00089                       vtkIdType theRealNbComp,
00090                       vtkIdType theNbTuples,
00091                       const char* theDataArrayName,
00092                       const char* theMapperArrayName )
00093       : myElnoDataArray( TVTKDataArray::New() )
00094       , myElnoDataMapper( vtkIntArray::New() )
00095     {
00096       myElnoDataArray->SetNumberOfComponents( theEffectNbComp );
00097       myElnoDataArray->SetNumberOfTuples( theNbTuples );
00098       myElnoDataArray->SetName( theDataArrayName );
00099 
00100       myElnoDataMapper->SetNumberOfComponents( 3 );
00101       myElnoDataMapper->Allocate( theNbTuples * 3 );
00102       myElnoDataMapper->SetName( theMapperArrayName );
00103 
00104       myElemInfo[ 0 ] = 0;
00105       myElemInfo[ 1 ] = theRealNbComp;
00106       myElemInfo[ 2 ] = 0;
00107     }
00108 
00109 
00110     //----------------------------------------------------------------------------------------------
00111     ~TSetElnoNodeData()
00112     {
00113       myElnoDataArray->Delete();
00114       myElnoDataMapper->Delete();
00115     }
00116 
00117 
00118     //----------------------------------------------------------------------------------------------
00119     int
00120     AddNextPointData( TDataType* theDataPtr )
00121     {
00122       vtkIdType aPos = myElemInfo[ 0 ] + myElemInfo[ 2 ] * myElemInfo[ 1 ];
00123 
00124       TDataType* aDataPtr = myElnoDataArray->GetPointer( aPos );
00125 
00126       for ( vtkIdType aCompId = 0; aCompId < myElemInfo[ 1 ]; aCompId++ )
00127         *aDataPtr++ = *theDataPtr++;
00128 
00129       return myElemInfo[ 2 ]++;
00130     }
00131 
00132 
00133     //----------------------------------------------------------------------------------------------
00134     void
00135     InsertNextCellData()
00136     {
00137       myElnoDataMapper->InsertNextTupleValue( myElemInfo );
00138       myElemInfo[ 0 ] += myElemInfo[ 2 ] * myElemInfo[ 1 ];
00139       myElemInfo[ 2 ] = 0;
00140     }
00141 
00142 
00143     //----------------------------------------------------------------------------------------------
00144     void
00145     AddData( vtkDataSetAttributes* theDataSetAttributes )
00146     {
00147       theDataSetAttributes->AddArray( myElnoDataArray );
00148       theDataSetAttributes->AddArray( myElnoDataMapper );
00149     }
00150 
00151   protected:
00152     TVTKDataArray *myElnoDataArray;
00153     vtkIntArray *myElnoDataMapper;
00154     int myElemInfo[ 3 ];
00155   };
00156 
00157 
00158   //---------------------------------------------------------------
00159 }
00160 
00161 #endif
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS