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

vtkFoamAddPatch.C

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 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "vtkFoam.H"
00030 #include "polyPatch.H"
00031 
00032 #include "vtkUnstructuredGrid.h"
00033 #include "vtkCellArray.h"
00034 
00035 #include "vtkFoamInsertNextPoint.H"
00036 
00037 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00038 
00039 void Foam::vtkFoam::addPatch
00040 (
00041     const polyPatch& p,
00042     vtkUnstructuredGrid *vtkPatch
00043 )
00044 {
00045     if (debug)
00046     {
00047         Info<< "Adding patch " << p.name() << endl;
00048     }
00049 
00050     SetName(vtkPatch, p.name().c_str());
00051 
00052     if (debug)
00053     {
00054         Info<< "converting points" << endl;
00055     }
00056 
00057     const Foam::pointField& points = p.localPoints();
00058 
00059     // Convert Foam mesh vertices to VTK
00060     vtkPoints *vtkpoints = vtkPoints::New();
00061     vtkpoints->Allocate(points.size());
00062 
00063     forAll(points, i)
00064     {
00065         vtkFoamInsertNextPoint(vtkpoints, points[i]);
00066     }
00067 
00068     if (debug)
00069     {
00070         Info<< "converting faces" << endl;
00071     }
00072 
00073     const faceList& faces = p.localFaces();
00074 
00075     vtkPatch->Allocate(faces.size());
00076 
00077     forAll(faces, facei)
00078     {
00079         const face& f = faces[facei];
00080 
00081         if (f.size() == 3)
00082         {
00083             vtkPatch->InsertNextCell
00084             (
00085                 VTK_TRIANGLE,
00086                 3,
00087                 const_cast<int*>(f.begin())
00088             );
00089         }
00090         else if (f.size() == 4)
00091         {
00092             vtkPatch->InsertNextCell
00093             (
00094                 VTK_QUAD,
00095                 4,
00096                 const_cast<int*>(f.begin())
00097             );
00098         }
00099         else
00100         {
00101             vtkPatch->InsertNextCell
00102             (
00103                 VTK_POLYGON,
00104                 f.size(),
00105                 const_cast<int*>(f.begin())
00106             );
00107         }
00108     }
00109 
00110     vtkPatch->SetPoints(vtkpoints);
00111     vtkpoints->Delete();
00112 }
00113 
00114 
00115 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd