pathline.C 5.13 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2015-2019 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 34 35 36 37 38 39 40 41 42
     \\/     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 3 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, see <http://www.gnu.org/licenses/>.

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

// OpenFOAM includes
#include "pathline.H"
#include "runTimePostProcessing.H"

// VTK includes
#include "vtkActor.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkSmartPointer.h"
#include "vtkTubeFilter.h"
#include "vtkLookupTable.h"

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

namespace Foam
{
43 44 45 46
namespace functionObjects
{
namespace runTimePostPro
{
47
    defineTypeName(pathline);
48 49
    defineRunTimeSelectionTable(pathline, dictionary);
}
50 51
}
}
52

53
const Foam::Enum
54
<
55
    Foam::functionObjects::runTimePostPro::pathline::representationType
56
>
57
Foam::functionObjects::runTimePostPro::pathline::representationTypeNames
Mark Olesen's avatar
Mark Olesen committed
58
({
59 60 61 62
    { representationType::rtNone, "none" },
    { representationType::rtLine, "line" },
    { representationType::rtTube, "tube" },
    { representationType::rtVector, "vector" },
Mark Olesen's avatar
Mark Olesen committed
63
});
64 65 66 67


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

68
void Foam::functionObjects::runTimePostPro::pathline::addLines
69
(
Andrew Heather's avatar
Andrew Heather committed
70
    const label framei,
71 72 73 74 75 76
    vtkActor* actor,
    vtkPolyData* data
) const
{
    geometryBase::initialiseActor(actor);

Andrew Heather's avatar
Andrew Heather committed
77
    vector colour = lineColour_->value(framei);
78 79 80
    actor->GetProperty()->SetColor(colour[0], colour[1], colour[2]);

    vtkPolyDataMapper* mapper =
81
        vtkPolyDataMapper::SafeDownCast(actor->GetMapper());
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

    switch (representation_)
    {
        case rtNone:
        {
            actor->VisibilityOff();
            break;
        }
        case rtLine:
        {
            mapper->SetInputData(data);
            mapper->Update();
            break;
        }
        case rtTube:
        {
98
            auto tubes = vtkSmartPointer<vtkTubeFilter>::New();
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
            tubes->SetInputData(data);
            tubes->SetRadius(tubeRadius_);
            tubes->SetNumberOfSides(20);
            tubes->CappingOn();
            tubes->Update();

            mapper->SetInputConnection(tubes->GetOutputPort());
            mapper->Update();
            break;
        }
        case rtVector:
        {
            break;
        }
    }
}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

119
Foam::functionObjects::runTimePostPro::pathline::pathline
120 121 122
(
    const runTimePostProcessing& parent,
    const dictionary& dict,
123
    const HashPtrTable<Function1<vector>>& colours
124 125 126 127 128
)
:
    geometryBase(parent, dict, colours),
    representation_
    (
Mark Olesen's avatar
Mark Olesen committed
129
        representationTypeNames.get("representation", dict)
130
    ),
131
    tubeRadius_(0.001),
Andrew Heather's avatar
Andrew Heather committed
132
    lineColour_(nullptr)
133 134 135
{
    if (dict.found("lineColour"))
    {
136
        lineColour_.reset(Function1<vector>::New("lineColour", dict));
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    }
    else
    {
        lineColour_.reset(colours["line"]->clone().ptr());
    }

    switch (representation_)
    {
        case rtNone:
        {
            break;
        }
        case rtLine:
        {
            break;
        }
        case rtTube:
        {
155
            dict.readEntry("tubeRadius", tubeRadius_);
156 157 158 159 160 161 162 163 164 165 166 167
            break;
        }
        case rtVector:
        {
            break;
        }
    }
}


// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //

168 169
Foam::autoPtr<Foam::functionObjects::runTimePostPro::pathline>
Foam::functionObjects::runTimePostPro::pathline::New
170 171 172
(
    const runTimePostProcessing& parent,
    const dictionary& dict,
173
    const HashPtrTable<Function1<vector>>& colours,
174 175 176
    const word& pathlineType
)
{
177
    DebugInfo << "Selecting pathline " << pathlineType << endl;
178

179
    auto cstrIter = dictionaryConstructorTablePtr_->cfind(pathlineType);
180

181
    if (!cstrIter.found())
182
    {
183 184 185 186 187 188 189
        FatalIOErrorInLookup
        (
            dict,
            "pathline",
            pathlineType,
            *dictionaryConstructorTablePtr_
        ) << exit(FatalIOError);
190 191 192 193 194 195 196 197
    }

    return autoPtr<pathline>(cstrIter()(parent, dict, colours));
}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

198
Foam::functionObjects::runTimePostPro::pathline::~pathline()
199 200 201 202
{}


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