initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / postProcessing / graphics / PV3FoamReader / vtkPV3Foam / vtkPV3FoamPatchField.H
blob7b7de4d022ffd4a02beb60fc0d2666785d8054c6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 InClass
26     vtkPV3Foam
28 \*---------------------------------------------------------------------------*/
30 #ifndef vtkPV3FoamPatchField_H
31 #define vtkPV3FoamPatchField_H
33 // VTK includes
34 #include "vtkCellData.h"
35 #include "vtkFloatArray.h"
36 #include "vtkMultiBlockDataSet.h"
37 #include "vtkPointData.h"
38 #include "vtkPolyData.h"
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 template<class Type>
43 void Foam::vtkPV3Foam::convertPatchField
45     const word& name,
46     const Field<Type>& ptf,
47     vtkMultiBlockDataSet* output,
48     const partInfo& selector,
49     const label datasetNo
52     const label nComp = pTraits<Type>::nComponents;
54     vtkFloatArray* cellData = vtkFloatArray::New();
55     cellData->SetNumberOfTuples( ptf.size() );
56     cellData->SetNumberOfComponents( nComp );
57     cellData->Allocate( nComp*ptf.size() );
58     cellData->SetName( name.c_str() );
60     float vec[nComp];
61     forAll(ptf, i)
62     {
63         const Type& t = ptf[i];
64         for (direction d=0; d<nComp; d++)
65         {
66             vec[d] = component(t, d);
67         }
68         cellData->InsertTuple(i, vec);
69     }
71     vtkPolyData::SafeDownCast
72     (
73         GetDataSetFromBlock(output, selector, datasetNo)
74     )   ->GetCellData()
75         ->AddArray(cellData);
77     cellData->Delete();
81 // as above, but with PointData()
82 template<class Type>
83 void Foam::vtkPV3Foam::convertPatchPointField
85     const word& name,
86     const Field<Type>& pptf,
87     vtkMultiBlockDataSet* output,
88     const partInfo& selector,
89     const label datasetNo
92     const label nComp = pTraits<Type>::nComponents;
94     vtkFloatArray *pointData = vtkFloatArray::New();
95     pointData->SetNumberOfTuples( pptf.size() );
96     pointData->SetNumberOfComponents( nComp );
97     pointData->Allocate( nComp*pptf.size() );
98     pointData->SetName( name.c_str() );
100     float vec[nComp];
101     forAll(pptf, i)
102     {
103         const Type& t = pptf[i];
104         for (direction d=0; d<nComp; d++)
105         {
106             vec[d] = component(t, d);
107         }
109         pointData->InsertTuple(i, vec);
110     }
112     vtkPolyData::SafeDownCast
113     (
114         GetDataSetFromBlock(output, selector, datasetNo)
115     )   ->GetPointData()
116         ->AddArray(pointData);
118     pointData->Delete();
121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
123 #endif
125 // ************************************************************************* //