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

vtkPV3FoamMeshSet.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 "vtkPV3Foam.H"
00030 
00031 // Foam includes
00032 #include "faceSet.H"
00033 #include "pointSet.H"
00034 #include "vtkPV3FoamPoints.H"
00035 
00036 // VTK includes
00037 #include "vtkPoints.h"
00038 #include "vtkPolyData.h"
00039 #include "vtkCellArray.h"
00040 
00041 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00042 
00043 vtkPolyData* Foam::vtkPV3Foam::faceSetVTKMesh
00044 (
00045     const fvMesh& mesh,
00046     const faceSet& fSet
00047 )
00048 {
00049     vtkPolyData* vtkmesh = vtkPolyData::New();
00050 
00051     if (debug)
00052     {
00053         Info<< "<beg> Foam::vtkPV3Foam::faceSetVTKMesh" << endl;
00054         printMemory();
00055     }
00056 
00057     // Construct primitivePatch of faces in fSet.
00058 
00059     const faceList& meshFaces = mesh.faces();
00060     faceList patchFaces(fSet.size());
00061     label faceI = 0;
00062     forAllConstIter(faceSet, fSet, iter)
00063     {
00064         patchFaces[faceI++] = meshFaces[iter.key()];
00065     }
00066     primitiveFacePatch p(patchFaces, mesh.points());
00067 
00068 
00069     // The balance of this routine should be identical to patchVTKMesh
00070 
00071     // Convert Foam mesh vertices to VTK
00072     const pointField& points = p.localPoints();
00073 
00074     vtkPoints *vtkpoints = vtkPoints::New();
00075     vtkpoints->Allocate( points.size() );
00076     forAll(points, i)
00077     {
00078         vtkPV3FoamInsertNextPoint(vtkpoints, points[i]);
00079     }
00080     vtkmesh->SetPoints(vtkpoints);
00081     vtkpoints->Delete();
00082 
00083     // Add faces as polygons
00084     const faceList& faces = p.localFaces();
00085 
00086     vtkCellArray* vtkcells = vtkCellArray::New();
00087     vtkcells->Allocate( faces.size() );
00088 
00089     forAll(faces, faceI)
00090     {
00091         const face& f = faces[faceI];
00092         vtkIdType nodeIds[f.size()];
00093 
00094         forAll(f, fp)
00095         {
00096             nodeIds[fp] = f[fp];
00097         }
00098         vtkcells->InsertNextCell(f.size(), nodeIds);
00099     }
00100 
00101     vtkmesh->SetPolys(vtkcells);
00102     vtkcells->Delete();
00103 
00104     if (debug)
00105     {
00106         Info<< "<end> Foam::vtkPV3Foam::faceSetVTKMesh" << endl;
00107         printMemory();
00108     }
00109 
00110     return vtkmesh;
00111 }
00112 
00113 
00114 vtkPolyData* Foam::vtkPV3Foam::pointSetVTKMesh
00115 (
00116     const fvMesh& mesh,
00117     const pointSet& pSet
00118 )
00119 {
00120     vtkPolyData* vtkmesh = vtkPolyData::New();
00121 
00122     if (debug)
00123     {
00124         Info<< "<beg> Foam::vtkPV3Foam::pointSetVTKMesh" << endl;
00125         printMemory();
00126     }
00127 
00128     const pointField& meshPoints = mesh.points();
00129 
00130     vtkPoints *vtkpoints = vtkPoints::New();
00131     vtkpoints->Allocate( pSet.size() );
00132 
00133     forAllConstIter(pointSet, pSet, iter)
00134     {
00135         vtkPV3FoamInsertNextPoint(vtkpoints, meshPoints[iter.key()]);
00136     }
00137 
00138     vtkmesh->SetPoints(vtkpoints);
00139     vtkpoints->Delete();
00140 
00141     if (debug)
00142     {
00143         Info<< "<end> Foam::vtkPV3Foam::pointSetVTKMesh" << endl;
00144         printMemory();
00145     }
00146 
00147     return vtkmesh;
00148 }
00149 
00150 
00151 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd