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

vtkFoamConvertPatchPointField.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     Foam::vtkFoam
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #ifndef vtkFoamConvertPatchPointField_H
00031 #define vtkFoamConvertPatchPointField_H
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 template<class Type>
00036 void Foam::vtkFoam::convertPatchPointField
00037 (
00038     const word& name,
00039     const Field<Type>& pptf,
00040     const label regioni
00041 )
00042 {
00043     vtkUnstructuredGrid *vtkMesh =
00044         vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(regioni));
00045 
00046     vtkFloatArray *pointTypes = vtkFloatArray::New();
00047     pointTypes->SetNumberOfTuples(pptf.size());
00048     pointTypes->SetNumberOfComponents(Type::nComponents);
00049     pointTypes->Allocate(Type::nComponents*pptf.size());
00050     pointTypes->SetName(name.c_str());
00051 
00052     float vec[Type::nComponents];
00053 
00054     forAll(pptf, i)
00055     {
00056         for (direction d=0; d<Type::nComponents; d++)
00057         {
00058             vec[d] = pptf[i][d];
00059         }
00060 
00061         pointTypes->InsertTuple(i, vec);
00062     }
00063 
00064     vtkMesh->GetPointData()->AddArray(pointTypes);
00065     pointTypes->Delete();
00066 }
00067 
00068 
00069 template<>
00070 void Foam::vtkFoam::convertPatchPointField
00071 (
00072     const word& name,
00073     const Field<scalar>& ppsf,
00074     const label regioni
00075 )
00076 {
00077     vtkUnstructuredGrid *vtkMesh =
00078         vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(regioni));
00079 
00080     vtkFloatArray *pointScalars = vtkFloatArray::New();
00081     pointScalars->SetNumberOfTuples(ppsf.size());
00082     pointScalars->SetNumberOfComponents(1);
00083     pointScalars->Allocate(ppsf.size());
00084     pointScalars->SetName(name.c_str());
00085 
00086     for (int i=0; i<ppsf.size(); i++)
00087     {
00088         pointScalars->InsertComponent(i, 0, ppsf[i]);
00089     }
00090 
00091     vtkMesh->GetPointData()->AddArray(pointScalars);
00092     if (!vtkMesh->GetPointData()->GetScalars())
00093     {
00094         vtkMesh->GetPointData()->SetScalars(pointScalars);
00095     }
00096 
00097     pointScalars->Delete();
00098 }
00099 
00100 
00101 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00102 
00103 #endif
00104 
00105 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd