OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

vtkPV3FoamPatchField.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 InClass
00026     vtkPV3Foam
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #ifndef vtkPV3FoamPatchField_H
00031 #define vtkPV3FoamPatchField_H
00032 
00033 // VTK includes
00034 #include "vtkCellData.h"
00035 #include "vtkFloatArray.h"
00036 #include "vtkMultiBlockDataSet.h"
00037 #include "vtkPointData.h"
00038 #include "vtkPolyData.h"
00039 
00040 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00041 
00042 template<class Type>
00043 void Foam::vtkPV3Foam::convertPatchField
00044 (
00045     const word& name,
00046     const Field<Type>& ptf,
00047     vtkMultiBlockDataSet* output,
00048     const partInfo& selector,
00049     const label datasetNo
00050 )
00051 {
00052     const label nComp = pTraits<Type>::nComponents;
00053 
00054     vtkFloatArray* cellData = vtkFloatArray::New();
00055     cellData->SetNumberOfTuples( ptf.size() );
00056     cellData->SetNumberOfComponents( nComp );
00057     cellData->Allocate( nComp*ptf.size() );
00058     cellData->SetName( name.c_str() );
00059 
00060     float vec[nComp];
00061     forAll(ptf, i)
00062     {
00063         const Type& t = ptf[i];
00064         for (direction d=0; d<nComp; d++)
00065         {
00066             vec[d] = component(t, d);
00067         }
00068         cellData->InsertTuple(i, vec);
00069     }
00070 
00071     vtkPolyData::SafeDownCast
00072     (
00073         GetDataSetFromBlock(output, selector, datasetNo)
00074     )   ->GetCellData()
00075         ->AddArray(cellData);
00076 
00077     cellData->Delete();
00078 }
00079 
00080 
00081 // as above, but with PointData()
00082 template<class Type>
00083 void Foam::vtkPV3Foam::convertPatchPointField
00084 (
00085     const word& name,
00086     const Field<Type>& pptf,
00087     vtkMultiBlockDataSet* output,
00088     const partInfo& selector,
00089     const label datasetNo
00090 )
00091 {
00092     const label nComp = pTraits<Type>::nComponents;
00093 
00094     vtkFloatArray *pointData = vtkFloatArray::New();
00095     pointData->SetNumberOfTuples( pptf.size() );
00096     pointData->SetNumberOfComponents( nComp );
00097     pointData->Allocate( nComp*pptf.size() );
00098     pointData->SetName( name.c_str() );
00099 
00100     float vec[nComp];
00101     forAll(pptf, i)
00102     {
00103         const Type& t = pptf[i];
00104         for (direction d=0; d<nComp; d++)
00105         {
00106             vec[d] = component(t, d);
00107         }
00108 
00109         pointData->InsertTuple(i, vec);
00110     }
00111 
00112     vtkPolyData::SafeDownCast
00113     (
00114         GetDataSetFromBlock(output, selector, datasetNo)
00115     )   ->GetPointData()
00116         ->AddArray(pointData);
00117 
00118     pointData->Delete();
00119 }
00120 
00121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00122 
00123 #endif
00124 
00125 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd