initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / postProcessing / graphics / PVFoamReader / vtkFoam / vtkFoamConvertPatchPointField.H
blob911ec08d714caeed843bd295d27976d6cba84970
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     Foam::vtkFoam
28 \*---------------------------------------------------------------------------*/
30 #ifndef vtkFoamConvertPatchPointField_H
31 #define vtkFoamConvertPatchPointField_H
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 template<class Type>
36 void Foam::vtkFoam::convertPatchPointField
38     const word& name,
39     const Field<Type>& pptf,
40     const label regioni
43     vtkUnstructuredGrid *vtkMesh =
44         vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(regioni));
46     vtkFloatArray *pointTypes = vtkFloatArray::New();
47     pointTypes->SetNumberOfTuples(pptf.size());
48     pointTypes->SetNumberOfComponents(Type::nComponents);
49     pointTypes->Allocate(Type::nComponents*pptf.size());
50     pointTypes->SetName(name.c_str());
52     float vec[Type::nComponents];
54     forAll(pptf, i)
55     {
56         for (direction d=0; d<Type::nComponents; d++)
57         {
58             vec[d] = pptf[i][d];
59         }
61         pointTypes->InsertTuple(i, vec);
62     }
64     vtkMesh->GetPointData()->AddArray(pointTypes);
65     pointTypes->Delete();
69 template<>
70 void Foam::vtkFoam::convertPatchPointField
72     const word& name,
73     const Field<scalar>& ppsf,
74     const label regioni
77     vtkUnstructuredGrid *vtkMesh =
78         vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(regioni));
80     vtkFloatArray *pointScalars = vtkFloatArray::New();
81     pointScalars->SetNumberOfTuples(ppsf.size());
82     pointScalars->SetNumberOfComponents(1);
83     pointScalars->Allocate(ppsf.size());
84     pointScalars->SetName(name.c_str());
86     for (int i=0; i<ppsf.size(); i++)
87     {
88         pointScalars->InsertComponent(i, 0, ppsf[i]);
89     }
91     vtkMesh->GetPointData()->AddArray(pointScalars);
92     if (!vtkMesh->GetPointData()->GetScalars())
93     {
94         vtkMesh->GetPointData()->SetScalars(pointScalars);
95     }
97     pointScalars->Delete();
101 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
103 #endif
105 // ************************************************************************* //