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

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