vtkPV3FoamMeshZone.C 3.8 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
Mark Olesen's avatar
Mark Olesen committed
5
    \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM; if not, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Description

\*---------------------------------------------------------------------------*/

#include "vtkPV3Foam.H"

// Foam includes
Mark Olesen's avatar
Mark Olesen committed
32
#include "vtkOpenFOAMPoints.H"
33
34
35
36
37
38
39
40

// VTK includes
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkCellArray.h"

// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

Mark Olesen's avatar
Mark Olesen committed
41
vtkPolyData* Foam::vtkPV3Foam::faceZoneVTKMesh
42
43
(
    const fvMesh& mesh,
Mark Olesen's avatar
Mark Olesen committed
44
    const labelList& faceLabels
45
46
)
{
Mark Olesen's avatar
Mark Olesen committed
47
48
    vtkPolyData* vtkmesh = vtkPolyData::New();

49
50
    if (debug)
    {
Mark Olesen's avatar
Mark Olesen committed
51
        Info<< "<beg> Foam::vtkPV3Foam::faceZoneVTKMesh" << endl;
Mark Olesen's avatar
Mark Olesen committed
52
        printMemory();
53
54
    }

Mark Olesen's avatar
Mark Olesen committed
55
    // Construct primitivePatch of faces in faceZone
56
57
58
59
60
61
62
63
64
65

    const faceList& meshFaces = mesh.faces();
    faceList patchFaces(faceLabels.size());
    forAll(faceLabels, faceI)
    {
        patchFaces[faceI] = meshFaces[faceLabels[faceI]];
    }
    primitiveFacePatch p(patchFaces, mesh.points());


Mark Olesen's avatar
Mark Olesen committed
66
    // The balance of this routine should be identical to patchVTKMesh
67
68
69
70

    // Convert Foam mesh vertices to VTK
    const pointField& points = p.localPoints();

Mark Olesen's avatar
Mark Olesen committed
71
72
    vtkPoints* vtkpoints = vtkPoints::New();
    vtkpoints->Allocate( points.size() );
73
74
    forAll(points, i)
    {
Mark Olesen's avatar
Mark Olesen committed
75
        vtkInsertNextOpenFOAMPoint(vtkpoints, points[i]);
76
    }
Mark Olesen's avatar
Mark Olesen committed
77

78
79
80
    vtkmesh->SetPoints(vtkpoints);
    vtkpoints->Delete();

Mark Olesen's avatar
Mark Olesen committed
81

82
83
84
85
    // Add faces as polygons
    const faceList& faces = p.localFaces();

    vtkCellArray* vtkcells = vtkCellArray::New();
Mark Olesen's avatar
Mark Olesen committed
86
87
    vtkcells->Allocate( faces.size() );

88
89
90
91
92
    forAll(faces, faceI)
    {
        const face& f = faces[faceI];
        vtkIdType nodeIds[f.size()];

Mark Olesen's avatar
Mark Olesen committed
93
        forAll(f, fp)
94
95
96
97
98
99
100
101
        {
            nodeIds[fp] = f[fp];
        }
        vtkcells->InsertNextCell(f.size(), nodeIds);
    }

    vtkmesh->SetPolys(vtkcells);
    vtkcells->Delete();
102
103
104

    if (debug)
    {
Mark Olesen's avatar
Mark Olesen committed
105
        Info<< "<end> Foam::vtkPV3Foam::faceZoneVTKMesh" << endl;
Mark Olesen's avatar
Mark Olesen committed
106
        printMemory();
107
    }
Mark Olesen's avatar
Mark Olesen committed
108
109

    return vtkmesh;
110
111
112
}


Mark Olesen's avatar
Mark Olesen committed
113
vtkPolyData* Foam::vtkPV3Foam::pointZoneVTKMesh
114
115
(
    const fvMesh& mesh,
Mark Olesen's avatar
Mark Olesen committed
116
    const labelList& pointLabels
117
118
)
{
Mark Olesen's avatar
Mark Olesen committed
119
120
    vtkPolyData* vtkmesh = vtkPolyData::New();

121
122
    if (debug)
    {
Mark Olesen's avatar
Mark Olesen committed
123
        Info<< "<beg> Foam::vtkPV3Foam::pointZoneVTKMesh" << endl;
Mark Olesen's avatar
Mark Olesen committed
124
        printMemory();
125
126
127
128
129
    }

    const pointField& meshPoints = mesh.points();

    vtkPoints *vtkpoints = vtkPoints::New();
Mark Olesen's avatar
Mark Olesen committed
130
    vtkpoints->Allocate( pointLabels.size() );
131
132
133

    forAll(pointLabels, pointI)
    {
Mark Olesen's avatar
Mark Olesen committed
134
        vtkInsertNextOpenFOAMPoint(vtkpoints, meshPoints[pointLabels[pointI]]);
135
136
137
138
139
140
141
    }

    vtkmesh->SetPoints(vtkpoints);
    vtkpoints->Delete();

    if (debug)
    {
Mark Olesen's avatar
Mark Olesen committed
142
        Info<< "<beg> Foam::vtkPV3Foam::pointZoneVTKMesh" << endl;
Mark Olesen's avatar
Mark Olesen committed
143
        printMemory();
144
    }
Mark Olesen's avatar
Mark Olesen committed
145
146

    return vtkmesh;
147
148
}

149

150
// ************************************************************************* //