1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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
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
27 \*---------------------------------------------------------------------------*/
29 #include "vtkPV3Foam.H"
32 #include "vtkPV3FoamPoints.H"
35 #include "vtkPoints.h"
36 #include "vtkPolyData.h"
37 #include "vtkCellArray.h"
39 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41 vtkPolyData* Foam::vtkPV3Foam::faceZoneVTKMesh
44 const labelList& faceLabels
47 vtkPolyData* vtkmesh = vtkPolyData::New();
51 Info<< "<beg> Foam::vtkPV3Foam::faceZoneVTKMesh" << endl;
55 // Construct primitivePatch of faces in faceZone
57 const faceList& meshFaces = mesh.allFaces();
58 faceList patchFaces(faceLabels.size());
61 // Filter faces that are not in live mesh
62 // Bug fix. HJ, 21/Mar/2011
63 forAll(faceLabels, faceI)
65 if (faceLabels[faceI] < mesh.nFaces())
67 patchFaces[npf] = meshFaces[faceLabels[faceI]];
71 patchFaces.setSize(npf);
73 primitiveFacePatch p(patchFaces, mesh.points());
76 // The balance of this routine should be identical to patchVTKMesh
78 // Convert Foam mesh vertices to VTK
79 const pointField& points = p.localPoints();
81 vtkPoints* vtkpoints = vtkPoints::New();
82 vtkpoints->Allocate(points.size());
85 vtkPV3FoamInsertNextPoint(vtkpoints, points[i]);
88 vtkmesh->SetPoints(vtkpoints);
92 // Add faces as polygons
93 const faceList& faces = p.localFaces();
95 vtkCellArray* vtkcells = vtkCellArray::New();
96 vtkcells->Allocate( faces.size() );
100 const face& f = faces[faceI];
101 vtkIdType nodeIds[f.size()];
107 vtkcells->InsertNextCell(f.size(), nodeIds);
110 vtkmesh->SetPolys(vtkcells);
115 Info<< "<end> Foam::vtkPV3Foam::faceZoneVTKMesh" << endl;
123 vtkPolyData* Foam::vtkPV3Foam::pointZoneVTKMesh
126 const labelList& pointLabels
129 vtkPolyData* vtkmesh = vtkPolyData::New();
133 Info<< "<beg> Foam::vtkPV3Foam::pointZoneVTKMesh" << endl;
137 const pointField& meshPoints = mesh.allPoints();
139 // Filter point labels to include only live points
140 labelList pl(pointLabels.size());
143 forAll (pointLabels, pointI)
145 if (pointLabels[pointI] < mesh.nPoints())
147 pl[npl] = pointLabels[pointI];
153 vtkPoints *vtkpoints = vtkPoints::New();
154 vtkpoints->Allocate( pl.size());
156 forAll(pointLabels, pointI)
158 vtkPV3FoamInsertNextPoint(vtkpoints, meshPoints[pl[pointI]]);
161 vtkmesh->SetPoints(vtkpoints);
166 Info<< "<beg> Foam::vtkPV3Foam::pointZoneVTKMesh" << endl;
174 // ************************************************************************* //