ENH: extended runTimePostProcessing (#1206)

- Extended runTimePostProcessing to include access to "live"
  simulation objects such a geometry patches and sampled surfaces
  stored on the "functionObjectObjects" registry.

- Add 'live' runTimePostProcessing of cloud data.
  Extracts position and fields from the cloud via its objectRegistry writer

- For the "live" simulation objects, there are two new volume filters
  that work directly with the OpenFOAM volume fields:
      * iso-surface
      * cutting planes
  Both use the VTK algorithms directly and support multiple values.
  Eg, can make multiple iso-levels or multiple planes parallel to each
  other.

- When VTK has been compiled with MPI-support, parallel rendering will
  be used.

- Additional title text properties (shadow, italic etc)

- Simplified handling of scalar-bar and visibility switches

- Support multiple text positions. Eg, for adding watermark text.
This commit is contained in:
Mark Olesen
2019-02-13 11:22:46 +01:00
committed by Andrew Heather
parent 03e6aa1a6d
commit 42fbf6d38c
68 changed files with 7123 additions and 847 deletions

View File

@ -2,10 +2,8 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2015 OpenFOAM Foundation
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -33,11 +31,11 @@ License
// VTK includes
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkSmartPointer.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkSmartPointer.h"
// VTK Readers
#include "vtkPolyDataReader.h"
@ -51,13 +49,42 @@ namespace functionObjects
{
namespace runTimePostPro
{
defineTypeNameAndDebug(functionObjectCloud, 0);
defineTypeName(functionObjectCloud);
addToRunTimeSelectionTable(pointData, functionObjectCloud, dictionary);
}
}
}
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace
{
static vtkSmartPointer<vtkPolyData> getPolyDataFile(const Foam::fileName& fName)
{
// Very simple - we only support vtp files, which are expected to have
// the scaling and colouring fields.
vtkSmartPointer<vtkPolyData> dataset;
if (fName.ext() == "vtp")
{
auto reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(fName.c_str());
reader->Update();
dataset = reader->GetOutput();
return dataset;
}
return dataset;
}
} // End anonymous namespace
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::runTimePostPro::functionObjectCloud::functionObjectCloud
@ -73,9 +100,7 @@ Foam::functionObjects::runTimePostPro::functionObjectCloud::functionObjectCloud
inputFileName_(),
colourFieldName_(dict.get<word>("colourField")),
actor_()
{
actor_ = vtkSmartPointer<vtkActor>::New();
}
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
@ -87,8 +112,8 @@ Foam::functionObjects::runTimePostPro::functionObjectCloud::
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
void Foam::functionObjects::runTimePostPro::functionObjectCloud::
addGeometryToScene
bool Foam::functionObjects::runTimePostPro::functionObjectCloud::
addGeometryFromFile
(
const scalar position,
vtkRenderer* renderer
@ -96,72 +121,118 @@ addGeometryToScene
{
if (!visible_)
{
return;
return false;
}
vtkSmartPointer<vtkPolyData> polyData;
bool good = true;
// The vtkCloud stores 'file' via the stateFunctionObject
// (lookup by cloudName).
// It only generates VTP format, which means there is a single file
// containing all fields.
inputFileName_ = getFileName("file", cloudName_);
if (inputFileName_.empty())
if (Pstream::master())
{
WarningInFunction
<< "Unable to find function object " << functionObjectName_
<< " output for field " << fieldName_
<< ". Cloud will not be processed"
<< endl;
return;
}
inputFileName_ = getFileName("file", cloudName_);
if (inputFileName_.size())
{
polyData = getPolyDataFile(inputFileName_);
vtkSmartPointer<vtkPolyData> dataset;
if (!polyData || polyData->GetNumberOfPoints() == 0)
{
good = false;
if (inputFileName_.hasExt("vtp"))
{
auto reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
reader->SetFileName(inputFileName_.c_str());
reader->Update();
WarningInFunction
<< "Could not read "<< inputFileName_ << nl
<< "Only VTK (.vtp) files are supported"
<< endl;
}
else
{
DebugInfo
<< " Resolved cloud file "
<< inputFileName_ << endl;
}
}
else
{
good = false;
dataset = reader->GetOutput();
WarningInFunction
<< "Unable to find function object " << functionObjectName_
<< " output for field " << fieldName_
<< ". Cloud will not be processed"
<< endl;
}
}
else
{
// Invalid name - ignore.
// Don't support VTK legacy format at all - it is too wasteful
// and cumbersome.
WarningInFunction
<< "Could not read "<< inputFileName_ << nl
<< "Only VTK (.vtp) files are supported"
<< ". Cloud will not be processed"
<< endl;
inputFileName_.clear();
}
reduce(good, andOp<bool>());
if (dataset)
if (!good)
{
return false;
}
// Only render on master
if (!renderer || !Pstream::master())
{
return true;
}
// Rendering
actor_ = vtkSmartPointer<vtkActor>::New();
{
fieldSummary scaleFieldInfo =
queryFieldSummary(fieldName_, polyData);
fieldSummary colourFieldInfo =
queryFieldSummary(colourFieldName_, polyData);
// No reduction
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
actor_->SetMapper(mapper);
/// dataset->Print(std::cout);
addGlyphs
(
position,
fieldName_,
colourFieldName_,
fieldName_, scaleFieldInfo, // scaling
colourFieldName_, colourFieldInfo, // colour
maxGlyphLength_,
dataset,
polyData,
actor_,
renderer
);
renderer->AddActor(actor_);
}
return true;
}
void Foam::functionObjects::runTimePostPro::functionObjectCloud::
addGeometryToScene
(
const scalar position,
vtkRenderer* renderer
)
{
// File source
addGeometryFromFile(position, renderer);
}
@ -170,10 +241,16 @@ void Foam::functionObjects::runTimePostPro::functionObjectCloud::updateActors
const scalar position
)
{
actor_->GetProperty()->SetOpacity(opacity(position));
if (actor_)
{
const vector colour = pointColour_->value(position);
vector pc = pointColour_->value(position);
actor_->GetProperty()->SetColor(pc[0], pc[1], pc[2]);
vtkProperty* prop = actor_->GetProperty();
prop->SetOpacity(opacity(position));
prop->SetColor(colour[0], colour[1], colour[2]);
}
}