Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / applications / utilities / postProcessing / graphics / PV3FoamReader / vtkPV3Foam / vtkPV3FoamMeshSet.C
blobd5a61e1df95e2b589e7042cf46c665f3fe42be47
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Description
26 \*---------------------------------------------------------------------------*/
28 #include "vtkPV3Foam.H"
30 // Foam includes
31 #include "faceSet.H"
32 #include "pointSet.H"
33 #include "vtkPV3FoamPoints.H"
35 // VTK includes
36 #include "vtkPoints.h"
37 #include "vtkPolyData.h"
38 #include "vtkCellArray.h"
40 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
42 vtkPolyData* Foam::vtkPV3Foam::faceSetVTKMesh
44     const fvMesh& mesh,
45     const faceSet& fSet
48     vtkPolyData* vtkmesh = vtkPolyData::New();
50     if (debug)
51     {
52         Info<< "<beg> Foam::vtkPV3Foam::faceSetVTKMesh" << endl;
53         printMemory();
54     }
56     // Construct primitivePatch of faces in fSet.
58     const faceList& meshFaces = mesh.faces();
59     faceList patchFaces(fSet.size());
60     label faceI = 0;
61     forAllConstIter(faceSet, fSet, iter)
62     {
63         patchFaces[faceI++] = meshFaces[iter.key()];
64     }
65     primitiveFacePatch p(patchFaces, mesh.points());
68     // The balance of this routine should be identical to patchVTKMesh
70     // Convert Foam mesh vertices to VTK
71     const pointField& points = p.localPoints();
73     vtkPoints *vtkpoints = vtkPoints::New();
74     vtkpoints->Allocate( points.size() );
75     forAll(points, i)
76     {
77         vtkPV3FoamInsertNextPoint(vtkpoints, points[i]);
78     }
79     vtkmesh->SetPoints(vtkpoints);
80     vtkpoints->Delete();
82     // Add faces as polygons
83     const faceList& faces = p.localFaces();
85     vtkCellArray* vtkcells = vtkCellArray::New();
86     vtkcells->Allocate( faces.size() );
88     forAll(faces, faceI)
89     {
90         const face& f = faces[faceI];
91         vtkIdType nodeIds[f.size()];
93         forAll(f, fp)
94         {
95             nodeIds[fp] = f[fp];
96         }
97         vtkcells->InsertNextCell(f.size(), nodeIds);
98     }
100     vtkmesh->SetPolys(vtkcells);
101     vtkcells->Delete();
103     if (debug)
104     {
105         Info<< "<end> Foam::vtkPV3Foam::faceSetVTKMesh" << endl;
106         printMemory();
107     }
109     return vtkmesh;
113 vtkPolyData* Foam::vtkPV3Foam::pointSetVTKMesh
115     const fvMesh& mesh,
116     const pointSet& pSet
119     vtkPolyData* vtkmesh = vtkPolyData::New();
121     if (debug)
122     {
123         Info<< "<beg> Foam::vtkPV3Foam::pointSetVTKMesh" << endl;
124         printMemory();
125     }
127     const pointField& meshPoints = mesh.points();
129     vtkPoints *vtkpoints = vtkPoints::New();
130     vtkpoints->Allocate( pSet.size() );
132     forAllConstIter(pointSet, pSet, iter)
133     {
134         vtkPV3FoamInsertNextPoint(vtkpoints, meshPoints[iter.key()]);
135     }
137     vtkmesh->SetPoints(vtkpoints);
138     vtkpoints->Delete();
140     if (debug)
141     {
142         Info<< "<end> Foam::vtkPV3Foam::pointSetVTKMesh" << endl;
143         printMemory();
144     }
146     return vtkmesh;
150 // ************************************************************************* //