vtkPV3FoamMeshPatch.C 2.75 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
32
33
     \\/     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
#include "polyPatch.H"
#include "primitivePatch.H"
Mark Olesen's avatar
Mark Olesen committed
34
#include "vtkOpenFOAMPoints.H"
35
36
37

// VTK includes
#include "vtkCellArray.h"
Mark Olesen's avatar
Mark Olesen committed
38
#include "vtkPoints.h"
39
40
41
42
#include "vtkPolyData.h"

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

Mark Olesen's avatar
Mark Olesen committed
43
vtkPolyData* Foam::vtkPV3Foam::patchVTKMesh
44
(
Mark Olesen's avatar
Mark Olesen committed
45
    const polyPatch& p
46
47
)
{
Mark Olesen's avatar
Mark Olesen committed
48
49
    vtkPolyData* vtkmesh = vtkPolyData::New();

50
51
    if (debug)
    {
Mark Olesen's avatar
Mark Olesen committed
52
        Info<< "<beg> Foam::vtkPV3Foam::patchVTKMesh - " << p.name() << endl;
Mark Olesen's avatar
Mark Olesen committed
53
        printMemory();
54
55
56
57
58
59
    }

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

    vtkPoints *vtkpoints = vtkPoints::New();
Mark Olesen's avatar
Mark Olesen committed
60
    vtkpoints->Allocate( points.size() );
61
62
    forAll(points, i)
    {
Mark Olesen's avatar
Mark Olesen committed
63
        vtkInsertNextOpenFOAMPoint(vtkpoints, points[i]);
64
65
66
67
68
69
70
71
72
    }

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


    // Add faces as polygons
    const faceList& faces = p.localFaces();

Mark Olesen's avatar
Mark Olesen committed
73
74
    vtkCellArray* vtkcells = vtkCellArray::New();
    vtkcells->Allocate( faces.size() );
75
76
77
78
79
    forAll(faces, faceI)
    {
        const face& f = faces[faceI];
        vtkIdType nodeIds[f.size()];

Mark Olesen's avatar
Mark Olesen committed
80
        forAll(f, fp)
81
82
83
84
85
86
87
88
        {
            nodeIds[fp] = f[fp];
        }
        vtkcells->InsertNextCell(f.size(), nodeIds);
    }

    vtkmesh->SetPolys(vtkcells);
    vtkcells->Delete();
89
90
91

    if (debug)
    {
Mark Olesen's avatar
Mark Olesen committed
92
        Info<< "<end> Foam::vtkPV3Foam::patchVTKMesh - " << p.name() << endl;
Mark Olesen's avatar
Mark Olesen committed
93
        printMemory();
94
    }
Mark Olesen's avatar
Mark Olesen committed
95
96

    return vtkmesh;
97
98
99
100
}


// ************************************************************************* //