vtkPolyData* Foam::vtkPV4Foam::lagrangianVTKMesh
(
    const fvMesh& mesh,
    const word& cloudName
)
{
    vtkPolyData* vtkmesh = NULL;

    if (debug)
    {
        Info<< "<beg> Foam::vtkPV4Foam::lagrangianVTKMesh - timePath "
            << mesh.time().timePath()/cloud::prefix/cloudName << endl;
        printMemory();
    }


    // the region name is already in the mesh db
    IOobjectList sprayObjs
    (
        mesh,
        mesh.time().timeName(),
        cloud::prefix/cloudName
    );

    IOobject* positionsPtr = sprayObjs.lookup(word("positions"));
    if (positionsPtr)
    {
        Cloud<passiveParticle> parcels(mesh, cloudName, false);

        if (debug)
        {
            Info<< "cloud with " << parcels.size() << " parcels" << endl;
        }

        vtkmesh = vtkPolyData::New();
        vtkPoints* vtkpoints = vtkPoints::New();
        vtkCellArray* vtkcells = vtkCellArray::New();

        vtkpoints->Allocate(parcels.size());
        vtkcells->Allocate(parcels.size());

        vtkIdType particleId = 0;
        forAllConstIter(Cloud<passiveParticle>, parcels, iter)
        {
            vtkInsertNextOpenFOAMPoint(vtkpoints, iter().position());

            vtkcells->InsertNextCell(1, &particleId);
            particleId++;
        }

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

        vtkmesh->SetVerts(vtkcells);
        vtkcells->Delete();
    }
vtkPolyData* Foam::vtkPV4Foam::patchVTKMesh
(
    const word& name,
    const PatchType& p
)
{
    vtkPolyData* vtkmesh = vtkPolyData::New();

    if (debug)
    {
        Info<< "<beg> Foam::vtkPV4Foam::patchVTKMesh - " << name << endl;
        printMemory();
    }

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

    vtkPoints* vtkpoints = vtkPoints::New();
    vtkpoints->Allocate(points.size());
    forAll(points, i)
    {
        vtkInsertNextOpenFOAMPoint(vtkpoints, points[i]);
    }
vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
(
    const fvMesh& mesh,
    polyDecomp& decompInfo
)
{
    const cellModel& tet = *(cellModeller::lookup("tet"));
    const cellModel& pyr = *(cellModeller::lookup("pyr"));
    const cellModel& prism = *(cellModeller::lookup("prism"));
    const cellModel& wedge = *(cellModeller::lookup("wedge"));
    const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
    const cellModel& hex = *(cellModeller::lookup("hex"));

    vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New();

    if (debug)
    {
        Info<< "<beg> Foam::vtkPV3Foam::volumeVTKMesh" << endl;
        printMemory();
    }

    const cellShapeList& cellShapes = mesh.cellShapes();

    // Number of additional points needed by the decomposition of polyhedra
    label nAddPoints = 0;

    // Number of additional cells generated by the decomposition of polyhedra
    label nAddCells = 0;

    // face owner is needed to determine the face orientation
    const labelList& owner = mesh.faceOwner();

    labelList& superCells = decompInfo.superCells();
    labelList& addPointCellLabels = decompInfo.addPointCellLabels();

    // Scan for cells which need to be decomposed and count additional points
    // and cells
    if (!reader_->GetUseVTKPolyhedron())
    {
        if (debug)
        {
            Info<< "... scanning for polyhedra" << endl;
        }

        forAll(cellShapes, cellI)
        {
            const cellModel& model = cellShapes[cellI].model();

            if
            (
                model != hex
             && model != wedge
             && model != prism
             && model != pyr
             && model != tet
             && model != tetWedge
            )
            {
                const cell& cFaces = mesh.cells()[cellI];

                forAll(cFaces, cFaceI)
                {
                    const face& f = mesh.faces()[cFaces[cFaceI]];

                    label nQuads = 0;
                    label nTris = 0;
                    f.nTrianglesQuads(mesh.points(), nTris, nQuads);

                    nAddCells += nQuads + nTris;
                }

                nAddCells--;
                nAddPoints++;
            }
        }
    }

    // Set size of additional point addressing array
    // (from added point to original cell)
    addPointCellLabels.setSize(nAddPoints);

    // Set size of additional cells mapping array
    // (from added cell to original cell)

    if (debug)
    {
        Info<<" mesh nCells     = " << mesh.nCells() << nl
            <<"      nPoints    = " << mesh.nPoints() << nl
            <<"      nAddCells  = " << nAddCells << nl
            <<"      nAddPoints = " << nAddPoints << endl;
    }

    superCells.setSize(mesh.nCells() + nAddCells);

    if (debug)
    {
        Info<< "... converting points" << endl;
    }

    // Convert OpenFOAM mesh vertices to VTK
    vtkPoints* vtkpoints = vtkPoints::New();
    vtkpoints->Allocate(mesh.nPoints() + nAddPoints);

    const Foam::pointField& points = mesh.points();

    forAll(points, i)
    {
        vtkInsertNextOpenFOAMPoint(vtkpoints, points[i]);
    }
void Foam::vtkPVblockMesh::convertMeshBlocks
(
    vtkMultiBlockDataSet* output,
    int& blockNo
)
{
    vtkDataArraySelection* selection = reader_->GetBlockSelection();
    arrayRange& range = arrayRangeBlocks_;
    range.block(blockNo);   // set output block
    label datasetNo = 0;       // restart at dataset 0

    const blockMesh& blkMesh = *meshPtr_;
    const Foam::pointField& blockPoints = blkMesh.vertices();

    if (debug)
    {
        Info<< "<beg> Foam::vtkPVblockMesh::convertMeshBlocks" << endl;
    }

    int blockI = 0;
    const scalar scaleFactor = blkMesh.scaleFactor();

    for
    (
        int partId = range.start();
        partId < range.end();
        ++partId, ++blockI
    )
    {
        if (!blockStatus_[partId])
        {
            continue;
        }

        const blockDescriptor& blockDef = blkMesh[blockI];

        vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New();

        // Convert OpenFOAM mesh vertices to VTK
        vtkPoints *vtkpoints = vtkPoints::New();
        vtkpoints->Allocate( blockDef.nPoints() );
        const labelList& blockLabels = blockDef.blockShape();

        vtkmesh->Allocate(1);
        vtkIdType nodeIds[8];

        forAll(blockLabels, ptI)
        {
            vtkInsertNextOpenFOAMPoint
            (
                vtkpoints,
                blockPoints[blockLabels[ptI]],
                scaleFactor
            );

            nodeIds[ptI] = ptI;
        }

        vtkmesh->InsertNextCell
        (
            VTK_HEXAHEDRON,
            8,
            nodeIds
        );

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

        AddToBlock
        (
            output, vtkmesh, range, datasetNo,
            selection->GetArrayName(partId)
        );

        vtkmesh->Delete();
        datasetNo++;
    }