mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
DEFEATURE: remove runTimePostProcessing (migrate to submodule)
This commit is contained in:
@ -11,8 +11,6 @@ wmake $targetType lagrangian
|
||||
wmake $targetType utilities
|
||||
wmake $targetType solvers
|
||||
|
||||
./graphics/Allwmake $targetType
|
||||
|
||||
./randomProcesses/Allwmake $targetType
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
#!/bin/sh
|
||||
cd "${0%/*}" || exit # Run from this directory
|
||||
. ${WM_PROJECT_DIR:?}/wmake/scripts/AllwmakeParseArguments
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
if [ "$targetType" != "objects" ]
|
||||
then
|
||||
runTimePostProcessing/Allwmake $*
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
@ -1,14 +0,0 @@
|
||||
#!/bin/sh
|
||||
cd "${0%/*}" || exit # Run from this directory
|
||||
. ${WM_PROJECT_DIR:?}/wmake/scripts/wmakeFunctions # Require wmake functions
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
# This cleanup handles both cmake runTimePostProcessing and the dummy version
|
||||
|
||||
# Cleanup library files with .so version endings
|
||||
rm -f $FOAM_LIBBIN/librunTimePostProcessing*
|
||||
|
||||
# Cleanup generated files - remove entire top-level
|
||||
removeObjectDir "$PWD"
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
@ -1,65 +0,0 @@
|
||||
#!/bin/sh
|
||||
cd "${0%/*}" || exit # Run from this directory
|
||||
. ${WM_PROJECT_DIR:?}/wmake/scripts/cmakeFunctions # Require cmake functions
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
echo "======================================================================"
|
||||
echo "${PWD##*/} : $PWD"
|
||||
|
||||
unset depend runTimePostProDebug
|
||||
|
||||
# If available, prefer use of ParaView MESA
|
||||
if [ -d "$ParaView_MESA_DIR" ]
|
||||
then
|
||||
export ParaView_DIR="$ParaView_MESA_DIR"
|
||||
fi
|
||||
|
||||
if [ -d "$VTK_DIR" ]
|
||||
then
|
||||
depend="VTK_DIR=$VTK_DIR"
|
||||
elif [ -d "$ParaView_DIR" ]
|
||||
then
|
||||
depend="ParaView_DIR=$ParaView_DIR"
|
||||
fi
|
||||
|
||||
# Force use of dummy only
|
||||
# unset depend
|
||||
|
||||
# For rebuilding (on error) instead of dropping back to dummy
|
||||
# runTimePostProDebug=true
|
||||
|
||||
if [ "$targetType" = objects ]
|
||||
then
|
||||
depend=ignore
|
||||
elif [ -n "$depend" ]
|
||||
then
|
||||
if command -v cmake >/dev/null
|
||||
then
|
||||
cmakeVersioned "$depend" $PWD || {
|
||||
echo
|
||||
echo " WARNING: incomplete build of VTK-based post-processing"
|
||||
echo
|
||||
if [ -z "$runTimePostProDebug" ]
|
||||
then
|
||||
depend="dummy"
|
||||
fi
|
||||
}
|
||||
else
|
||||
echo "==> skip runTimePostProcessing (needs cmake)"
|
||||
depend="dummy"
|
||||
fi
|
||||
else
|
||||
echo "WARNING: skip runTimePostProcessing (no VTK or ParaView)"
|
||||
echo " - ParaView : export the 'ParaView_DIR' variable"
|
||||
echo " - VTK : export the 'VTK_DIR' variable"
|
||||
fi
|
||||
|
||||
if [ "${depend:-dummy}" = dummy ]
|
||||
then
|
||||
echo "==> dummy runTimePostProcessing"
|
||||
wmakeVersioned "vtk=dummy" $PWD dummy
|
||||
fi
|
||||
|
||||
echo "======================================================================"
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
@ -1,32 +0,0 @@
|
||||
#-----------------------------------------------------------------------------
|
||||
# Standard definitions when using OpenFOAM
|
||||
|
||||
if (NOT EXISTS "$ENV{WM_PROJECT_DIR}")
|
||||
message(FATAL_ERROR "WM_PROJECT_DIR not set - no OpenFOAM??")
|
||||
endif()
|
||||
|
||||
# WM_OSTYPE env variable is optional (only POSIX anyhow)
|
||||
if (EXISTS "$ENV{WM_OSTYPE}")
|
||||
set(WM_OSTYPE "$ENV{WM_OSTYPE}")
|
||||
else()
|
||||
set(WM_OSTYPE "POSIX")
|
||||
endif()
|
||||
|
||||
# Convenience name, as per wmake internals
|
||||
set(LIB_SRC "$ENV{WM_PROJECT_DIR}/src")
|
||||
|
||||
# Needed for internal label-size, scalar-size, templates
|
||||
add_definitions(
|
||||
-DWM_$ENV{WM_PRECISION_OPTION}
|
||||
-DWM_LABEL_SIZE=$ENV{WM_LABEL_SIZE}
|
||||
-DNoRepository
|
||||
)
|
||||
|
||||
set(CMAKE_CXX_FLAGS_DEBUG
|
||||
"-g -O0 -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wno-overloaded-virtual"
|
||||
)
|
||||
set(CMAKE_CXX_FLAGS_RELEASE
|
||||
"-O3 -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wno-overloaded-virtual"
|
||||
)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
@ -1,127 +0,0 @@
|
||||
#-----------------------------------------------------------------------------
|
||||
project(runTimePostProcessing)
|
||||
|
||||
message("VTK version: " ${VTK_VERSION})
|
||||
|
||||
if(${VTK_VERSION_MAJOR} LESS 6)
|
||||
message(FATAL_ERROR " VTK version is too old - requires VTK6 or newer")
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Test some characteristics
|
||||
set(test_file ${CMAKE_CURRENT_BINARY_DIR}/check_mpi.cxx)
|
||||
file(WRITE ${test_file}
|
||||
"#include <vtkMPICommunicator.h>\n"
|
||||
"int main() {\n"
|
||||
" vtkMPICommunicator* p = vtkMPICommunicator::New();\n"
|
||||
" p->Delete();\n"
|
||||
" return 0;\n"
|
||||
"}"
|
||||
)
|
||||
try_compile(FOAM_USING_VTK_MPI
|
||||
${CMAKE_CURRENT_BINARY_DIR} ${test_file}
|
||||
LINK_LIBRARIES vtkParallelMPI
|
||||
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${VTK_INCLUDE_DIRS}"
|
||||
)
|
||||
if (FOAM_USING_VTK_MPI)
|
||||
add_definitions(-DFOAM_USING_VTK_MPI)
|
||||
message("Building with VTK MPI")
|
||||
include(vtkMPI)
|
||||
else()
|
||||
message(WARNING "==== Building without VTK MPI ====")
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
include_directories(
|
||||
${LIB_SRC}/OpenFOAM/include
|
||||
${LIB_SRC}/OpenFOAM/lnInclude
|
||||
${LIB_SRC}/OSspecific/${WM_OSTYPE}/lnInclude
|
||||
${LIB_SRC}/finiteVolume/lnInclude
|
||||
${LIB_SRC}/fileFormats/lnInclude
|
||||
${LIB_SRC}/conversion/lnInclude
|
||||
${LIB_SRC}/surfMesh/lnInclude
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
link_directories(
|
||||
$ENV{FOAM_LIBBIN}
|
||||
)
|
||||
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
|
||||
# Build intermediate (library) directly into the OpenFOAM libdir
|
||||
# - implies CMAKE_INSTALL_PREFIX is ignored and there is no 'install' phase
|
||||
set(LIBRARY_OUTPUT_PATH $ENV{FOAM_LIBBIN}
|
||||
CACHE INTERNAL
|
||||
""
|
||||
)
|
||||
|
||||
## Record VTK version for general bookkeeping
|
||||
# file(WRITE
|
||||
# ${CMAKE_BINARY_DIR}/version
|
||||
# "VTK_VERSION=${VTK_VERSION}\n"
|
||||
# )
|
||||
|
||||
file(GLOB SOURCE_FILES
|
||||
fieldVisualisationBase.C
|
||||
scalarBar.C
|
||||
functionObjectBase.C
|
||||
functionObjectCloud.C
|
||||
functionObjectLine.C
|
||||
functionObjectSurface.C
|
||||
geometryBase.C
|
||||
geometryCloud.C
|
||||
geometryCloudGather.C
|
||||
geometryPatches.C
|
||||
geometryPatchesGather.C
|
||||
geometrySurface.C
|
||||
pathline.C
|
||||
pointData.C
|
||||
runTimePostProcessing.C
|
||||
runTimePostProcessingFunctionObject.C
|
||||
scene.C
|
||||
surface.C
|
||||
surfaceGather.C
|
||||
text.C
|
||||
contourFilter.C
|
||||
cuttingPlaneFilter.C
|
||||
volumeFilter.C
|
||||
)
|
||||
|
||||
set(OPENFOAM_LIBRARIES
|
||||
OpenFOAM
|
||||
finiteVolume
|
||||
surfMesh
|
||||
fileFormats
|
||||
conversion
|
||||
)
|
||||
|
||||
if (FOAM_USING_VTK_MPI)
|
||||
set(LINK_LIBRARIES vtkParallelMPI)
|
||||
else()
|
||||
set(LINK_LIBRARIES)
|
||||
endif()
|
||||
|
||||
add_library(
|
||||
runTimePostProcessing
|
||||
SHARED
|
||||
${SOURCE_FILES}
|
||||
)
|
||||
|
||||
set_target_properties(
|
||||
runTimePostProcessing
|
||||
PROPERTIES
|
||||
VERSION ${VTK_VERSION}
|
||||
SOVERSION ${VTK_VERSION_MAJOR}
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
runTimePostProcessing
|
||||
${VTK_LIBRARIES}
|
||||
${LINK_LIBRARIES}
|
||||
${OPENFOAM_LIBRARIES}
|
||||
)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
@ -1,55 +0,0 @@
|
||||
#------------------------------------------------------------------------------
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
cmake_policy(SET CMP0002 NEW) # Policy CMP0002 required for for cmake >= 3
|
||||
|
||||
# Fail if not building out-of-source
|
||||
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
|
||||
message(FATAL_ERROR
|
||||
"In-source builds disallowed. Use a separate build directory")
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Simple discovery and sanity checks
|
||||
|
||||
unset(VTK_VERSION)
|
||||
unset(VTK_VERSION_MAJOR)
|
||||
|
||||
if (EXISTS "$ENV{VTK_DIR}")
|
||||
message("Building with VTK from $ENV{VTK_DIR}")
|
||||
find_package(VTK REQUIRED HINTS $ENV{VTK_DIR})
|
||||
elseif (EXISTS "$ENV{ParaView_DIR}")
|
||||
message("Building with Paraview from $ENV{ParaView_DIR}")
|
||||
find_package(ParaView REQUIRED HINTS $ENV{ParaView_DIR})
|
||||
else()
|
||||
message(FATAL_ERROR "VTK not found using VTK_DIR or ParaView_DIR")
|
||||
endif()
|
||||
|
||||
if (VTK_USE_FILE)
|
||||
message("VTK from ${VTK_USE_FILE}")
|
||||
include(${VTK_USE_FILE})
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Handle name changes (eg, VTK_MAJOR_VERSION to VTK_VERSION_MAJOR etc.)
|
||||
|
||||
if (VTK_MAJOR_VERSION AND NOT VTK_VERSION_MAJOR)
|
||||
message("Found older VTK version naming")
|
||||
set(VTK_VERSION_MAJOR ${VTK_MAJOR_VERSION})
|
||||
set(VTK_VERSION_MINOR ${VTK_MINOR_VERSION})
|
||||
set(VTK_VERSION_PATCH ${VTK_BUILD_VERSION})
|
||||
|
||||
if (NOT VTK_VERSION)
|
||||
set(
|
||||
VTK_VERSION
|
||||
"${VTK_VERSION_MAJOR}.${VTK_VERSION_MINOR}.${VTK_VERSION_PATCH}"
|
||||
)
|
||||
message("Synthesized VTK version: " ${VTK_VERSION})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
include(CMakeLists-OpenFOAM.txt)
|
||||
include(CMakeLists-Project.txt)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
@ -1,311 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "contourFilter.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkCellDataToPointData.h"
|
||||
#include "vtkCompositeDataGeometryFilter.h"
|
||||
#include "vtkCompositeDataSet.h"
|
||||
#include "vtkCompositePolyDataMapper.h"
|
||||
#include "vtkContourFilter.h"
|
||||
#include "vtkMultiPieceDataSet.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
defineTypeName(contourFilter);
|
||||
addToRunTimeSelectionTable(surface, contourFilter, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::contourFilter::contourFilter
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
volumeFilter(parent, dict, colours),
|
||||
fieldVisualisationBase(dict, colours),
|
||||
colourFieldName_(dict.get<word>("colourField")),
|
||||
values_()
|
||||
{
|
||||
dict.readEntry("values", values_);
|
||||
|
||||
// Extra safety
|
||||
if (values_.empty())
|
||||
{
|
||||
values_.resize(1);
|
||||
values_.first() = Zero;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::contourFilter::
|
||||
addGeometry
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (!visible_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (needsCollective())
|
||||
{
|
||||
Info<< type() << " : Not available for collective operation" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
DebugInfo << " Adding iso-surface" << endl;
|
||||
|
||||
// Bookkeeping for vtkUnstructuredGrid
|
||||
vtk::vtuAdaptor adaptor;
|
||||
vtkSmartPointer<vtkMultiPieceDataSet> multiPiece = mesh(adaptor);
|
||||
|
||||
|
||||
// Add (scalar/vector) field.
|
||||
// - always need field(s) for glyphs or colourByField:
|
||||
|
||||
int nCmpt = 0;
|
||||
{
|
||||
const auto* ioptr =
|
||||
parent().mesh().cfindObject<regIOobject>(fieldName_);
|
||||
|
||||
if (!nCmpt)
|
||||
{
|
||||
nCmpt = addDimField<scalar>
|
||||
(
|
||||
multiPiece, adaptor, ioptr, fieldName_
|
||||
);
|
||||
}
|
||||
if (!nCmpt)
|
||||
{
|
||||
nCmpt = addDimField<vector>
|
||||
(
|
||||
multiPiece, adaptor, ioptr, fieldName_
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If the input is vector, need magnitude
|
||||
|
||||
word magFieldName = fieldName_;
|
||||
|
||||
if (nCmpt == 3)
|
||||
{
|
||||
addMagField(fieldName_, multiPiece);
|
||||
magFieldName = "mag(" + fieldName_ + ")";
|
||||
}
|
||||
|
||||
// Colouring
|
||||
nCmpt = 0;
|
||||
if (colourBy_ == cbField && fieldName_ != colourFieldName_)
|
||||
{
|
||||
const auto* ioptr =
|
||||
parent().mesh().cfindObject<regIOobject>(fieldName_);
|
||||
|
||||
if (!nCmpt)
|
||||
{
|
||||
nCmpt = addDimField<scalar>
|
||||
(
|
||||
multiPiece, adaptor, ioptr, colourFieldName_
|
||||
);
|
||||
}
|
||||
if (!nCmpt)
|
||||
{
|
||||
nCmpt = addDimField<vector>
|
||||
(
|
||||
multiPiece, adaptor, ioptr, colourFieldName_
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Now have a multi-piece dataset that is one of the following:
|
||||
//
|
||||
// - one-piece per processor (OpenFOAM = parallel, VTK=parallel)
|
||||
|
||||
|
||||
// Re-query field information - we may have stored it differently
|
||||
// than the original source.
|
||||
|
||||
fieldSummary fieldInfo = queryFieldSummary(magFieldName, multiPiece);
|
||||
fieldInfo.reduce();
|
||||
|
||||
fieldSummary colourFieldInfo =
|
||||
queryFieldSummary(colourFieldName_, multiPiece);
|
||||
colourFieldInfo.reduce();
|
||||
|
||||
|
||||
DebugInfo
|
||||
<< " Field " << fieldName_ << ' ' << fieldInfo.info() << nl
|
||||
<< " Field " << colourFieldName_ << ' ' << colourFieldInfo.info()
|
||||
<< endl;
|
||||
|
||||
|
||||
// Not rendered on this processor?
|
||||
// This is where we stop, but could also have an MPI barrier
|
||||
if (!renderer)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Rendering
|
||||
{
|
||||
auto contour = vtkSmartPointer<vtkContourFilter>::New();
|
||||
|
||||
vtkSmartPointer<vtkCellDataToPointData> cellToPoint;
|
||||
|
||||
// CellData - Need a cell->point filter
|
||||
if (!fieldInfo.hasPointData() || !colourFieldInfo.hasPointData())
|
||||
{
|
||||
cellToPoint = vtkSmartPointer<vtkCellDataToPointData>::New();
|
||||
cellToPoint->SetInputData(multiPiece);
|
||||
|
||||
contour->SetInputConnection(cellToPoint->GetOutputPort());
|
||||
}
|
||||
else
|
||||
{
|
||||
contour->SetInputData(multiPiece);
|
||||
}
|
||||
|
||||
contour->SetNumberOfContours(values_.size());
|
||||
forAll(values_, valuei)
|
||||
{
|
||||
contour->SetValue(valuei, values_[valuei]);
|
||||
}
|
||||
|
||||
contour->SetInputArrayToProcess
|
||||
(
|
||||
0, // index: scalars(0)
|
||||
0, // port
|
||||
0, // connection
|
||||
vtkDataObject::FIELD_ASSOCIATION_POINTS,
|
||||
magFieldName.c_str()
|
||||
);
|
||||
|
||||
contour->Modified();
|
||||
contour->Update();
|
||||
|
||||
auto polyData = vtkSmartPointer<vtkCompositeDataGeometryFilter>::New();
|
||||
|
||||
polyData->SetInputConnection(contour->GetOutputPort());
|
||||
polyData->Update();
|
||||
|
||||
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputConnection(polyData->GetOutputPort());
|
||||
|
||||
if (representation_ == rtGlyph)
|
||||
{
|
||||
addGlyphs
|
||||
(
|
||||
position,
|
||||
colourFieldName_, colourFieldInfo, // scaling
|
||||
colourFieldName_, colourFieldInfo, // colouring
|
||||
maxGlyphLength_,
|
||||
polyData->GetOutput(),
|
||||
surfaceActor_,
|
||||
renderer
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
setField
|
||||
(
|
||||
position,
|
||||
colourFieldName_,
|
||||
FieldAssociation::POINT_DATA,
|
||||
mapper,
|
||||
renderer
|
||||
);
|
||||
|
||||
surfaceActor_->SetMapper(mapper);
|
||||
|
||||
setRepresentation(surfaceActor_);
|
||||
|
||||
renderer->AddActor(surfaceActor_);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::contourFilter::
|
||||
addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (visible_)
|
||||
{
|
||||
// Live source
|
||||
if (addGeometry(position, renderer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WarningInFunction
|
||||
<< "Unsupported for OpenFOAM parallel and VTK serial"
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::contourFilter::clear()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,142 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::contourFilter
|
||||
|
||||
Description
|
||||
Iso-surface contours of OpenFOAM volume fields.
|
||||
|
||||
Dictionary controls
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
type | The surface type: isoSurface | yes |
|
||||
field | The field defining the surface | yes |
|
||||
colourField | The field to display on the surface | yes |
|
||||
values | List of iso-values to define the surface(s) | yes |
|
||||
\endtable
|
||||
|
||||
SourceFiles
|
||||
contourFilter.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_contourFilter_H
|
||||
#define functionObjects_runTimePostPro_contourFilter_H
|
||||
|
||||
#include "volumeFilter.H"
|
||||
#include "fieldVisualisationBase.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class contourFilter Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class contourFilter
|
||||
:
|
||||
public volumeFilter,
|
||||
public fieldVisualisationBase
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- Name of field to colour by
|
||||
word colourFieldName_;
|
||||
|
||||
//- The iso values
|
||||
List<scalar> values_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- No copy construct
|
||||
contourFilter(const contourFilter&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const contourFilter&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeNameNoDebug("isoSurface");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
contourFilter
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~contourFilter() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Add cutting planes to scene (using simulation source)
|
||||
bool addGeometry
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Add cutting planes to scene (using simulation source)
|
||||
virtual void addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Add cutting planes to scene (using simulation source)
|
||||
virtual bool clear();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,294 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "cuttingPlaneFilter.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkCellDataToPointData.h"
|
||||
#include "vtkCompositeDataGeometryFilter.h"
|
||||
#include "vtkCompositeDataSet.h"
|
||||
#include "vtkCompositePolyDataMapper.h"
|
||||
#include "vtkCutter.h"
|
||||
#include "vtkMultiPieceDataSet.h"
|
||||
#include "vtkPlane.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
defineTypeName(cuttingPlaneFilter);
|
||||
addToRunTimeSelectionTable(surface, cuttingPlaneFilter, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::cuttingPlaneFilter::cuttingPlaneFilter
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
volumeFilter(parent, dict, colours),
|
||||
fieldVisualisationBase(dict, colours),
|
||||
plane_(dict),
|
||||
values_()
|
||||
{
|
||||
dict.readIfPresent("offsets", values_);
|
||||
|
||||
if (values_.empty())
|
||||
{
|
||||
values_.resize(1);
|
||||
values_.first() = Zero;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::cuttingPlaneFilter::
|
||||
addGeometry
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (!visible_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (needsCollective())
|
||||
{
|
||||
Info<< type() << " : Not available for collective operation" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
DebugInfo << " Adding cutting plane" << endl;
|
||||
|
||||
|
||||
// Bookkeeping for vtkUnstructuredGrid
|
||||
vtk::vtuAdaptor adaptor;
|
||||
vtkSmartPointer<vtkMultiPieceDataSet> multiPiece = mesh(adaptor);
|
||||
|
||||
|
||||
// Add (scalar/vector) field.
|
||||
// - Need field(s) for glyphs or colourByField:
|
||||
|
||||
int nCmpt = 0;
|
||||
if (representation_ == rtGlyph || colourBy_ == cbField)
|
||||
{
|
||||
const auto* ioptr =
|
||||
parent().mesh().cfindObject<regIOobject>(fieldName_);
|
||||
|
||||
if (!nCmpt)
|
||||
{
|
||||
nCmpt = addDimField<scalar>
|
||||
(
|
||||
multiPiece, adaptor, ioptr, fieldName_
|
||||
);
|
||||
}
|
||||
if (!nCmpt)
|
||||
{
|
||||
nCmpt = addDimField<vector>
|
||||
(
|
||||
multiPiece, adaptor, ioptr, fieldName_
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Now have a multi-piece dataset that is one of the following:
|
||||
//
|
||||
// - one-piece per processor (OpenFOAM = parallel, VTK=parallel)
|
||||
|
||||
|
||||
// Re-query field information - we may have stored it differently
|
||||
// than the original source.
|
||||
|
||||
fieldSummary fieldInfo = queryFieldSummary(fieldName_, multiPiece);
|
||||
fieldInfo.reduce();
|
||||
|
||||
|
||||
// Not rendered on this processor?
|
||||
// This is where we stop, but could also have an MPI barrier
|
||||
if (!renderer)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Rendering
|
||||
{
|
||||
// OpenFOAM plane -> vtkPlane definition
|
||||
|
||||
auto pln = vtkSmartPointer<vtkPlane>::New();
|
||||
|
||||
pln->SetNormal
|
||||
(
|
||||
plane_.normal().x(),
|
||||
plane_.normal().y(),
|
||||
plane_.normal().z()
|
||||
);
|
||||
pln->SetOrigin
|
||||
(
|
||||
plane_.origin().x(),
|
||||
plane_.origin().y(),
|
||||
plane_.origin().z()
|
||||
);
|
||||
|
||||
|
||||
// Plane cutting algorithm
|
||||
|
||||
auto cutter = vtkSmartPointer<vtkCutter>::New();
|
||||
|
||||
cutter->SetInputData(multiPiece);
|
||||
cutter->SetCutFunction(pln);
|
||||
|
||||
cutter->SetNumberOfContours(values_.size());
|
||||
|
||||
forAll(values_, pointi)
|
||||
{
|
||||
cutter->SetValue(pointi, values_[pointi]);
|
||||
}
|
||||
|
||||
cutter->SetInputArrayToProcess
|
||||
(
|
||||
(nCmpt == 3 ? 1 : 0), // index: scalars(0), vectors(1)
|
||||
0, // port
|
||||
0, // connection
|
||||
vtkDataObject::FIELD_ASSOCIATION_CELLS,
|
||||
fieldName_.c_str()
|
||||
);
|
||||
|
||||
cutter->Modified();
|
||||
cutter->Update();
|
||||
|
||||
auto polyData = vtkSmartPointer<vtkCompositeDataGeometryFilter>::New();
|
||||
|
||||
polyData->SetInputConnection(cutter->GetOutputPort());
|
||||
polyData->Update();
|
||||
|
||||
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputConnection(polyData->GetOutputPort());
|
||||
|
||||
if (representation_ == rtGlyph)
|
||||
{
|
||||
addGlyphs
|
||||
(
|
||||
position,
|
||||
fieldName_, fieldInfo, // scaling
|
||||
fieldName_, fieldInfo, // colouring
|
||||
maxGlyphLength_,
|
||||
polyData->GetOutput(),
|
||||
surfaceActor_,
|
||||
renderer
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
vtkSmartPointer<vtkCellDataToPointData> cellToPoint;
|
||||
|
||||
// CellData - Need a cell->point filter
|
||||
if (smooth_ && !fieldInfo.hasPointData())
|
||||
{
|
||||
cellToPoint = vtkSmartPointer<vtkCellDataToPointData>::New();
|
||||
cellToPoint->SetInputConnection(cutter->GetOutputPort());
|
||||
|
||||
polyData->SetInputConnection(cellToPoint->GetOutputPort());
|
||||
polyData->Update();
|
||||
}
|
||||
|
||||
setField
|
||||
(
|
||||
position,
|
||||
fieldName_,
|
||||
(
|
||||
smooth_
|
||||
? FieldAssociation::POINT_DATA
|
||||
: FieldAssociation(fieldInfo.association_)
|
||||
),
|
||||
mapper,
|
||||
renderer
|
||||
);
|
||||
|
||||
surfaceActor_->SetMapper(mapper);
|
||||
|
||||
setRepresentation(surfaceActor_);
|
||||
|
||||
renderer->AddActor(surfaceActor_);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::cuttingPlaneFilter::
|
||||
addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (visible_)
|
||||
{
|
||||
// Live source
|
||||
if (addGeometry(position, renderer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WarningInFunction
|
||||
<< "Unsupported for OpenFOAM parallel and VTK serial"
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::cuttingPlaneFilter::clear()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,162 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::cuttingPlaneFilter
|
||||
|
||||
Description
|
||||
Cutting planes of OpenFOAM volume fields.
|
||||
|
||||
Example of text object specification:
|
||||
\verbatim
|
||||
planes
|
||||
{
|
||||
type plane;
|
||||
planeType pointAndNormal;
|
||||
|
||||
pointAndNormalDict
|
||||
{
|
||||
point (0 0 0);
|
||||
normal (1 0 0);
|
||||
}
|
||||
|
||||
offsets (0 10 20);
|
||||
|
||||
field T;
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Dictionary controls
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
type | The surface type: plane | yes |
|
||||
planeType | Selector for plane description | yes |
|
||||
offsets | Offets of the origin in the normal direction | no | (0)
|
||||
field | The field to display | yes |
|
||||
\endtable
|
||||
|
||||
SourceFiles
|
||||
cuttingPlaneFilter.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_cuttingPlaneFilter_H
|
||||
#define functionObjects_runTimePostPro_cuttingPlaneFilter_H
|
||||
|
||||
#include "plane.H"
|
||||
#include "volumeFilter.H"
|
||||
#include "fieldVisualisationBase.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class cuttingPlaneFilter Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class cuttingPlaneFilter
|
||||
:
|
||||
public volumeFilter,
|
||||
public fieldVisualisationBase
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- The definition of the plane
|
||||
plane plane_;
|
||||
|
||||
//- The offsets to the plane - defaults to (0).
|
||||
List<scalar> values_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- No copy construct
|
||||
cuttingPlaneFilter(const cuttingPlaneFilter&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const cuttingPlaneFilter&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeNameNoDebug("plane");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
cuttingPlaneFilter
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~cuttingPlaneFilter() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Add cutting planes to scene (using simulation source)
|
||||
bool addGeometry
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Add cutting planes to scene (using simulation source)
|
||||
virtual void addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Cleanup files etc.
|
||||
virtual bool clear();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,3 +0,0 @@
|
||||
runTimePostProcessingDummy.C
|
||||
|
||||
LIB = $(FOAM_LIBBIN)/librunTimePostProcessing
|
||||
@ -1,3 +0,0 @@
|
||||
EXE_INC =
|
||||
|
||||
LIB_LIBS =
|
||||
@ -1,69 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "runTimePostProcessingDummy.H"
|
||||
#include "dictionary.H"
|
||||
#include "Time.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(runTimePostProcessingDummy, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
runTimePostProcessingDummy,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostProcessingDummy::runTimePostProcessingDummy
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
functionObject::unavailableFunctionObject(name)
|
||||
{
|
||||
carp
|
||||
(
|
||||
"VTK libraries were not available at compilation time"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,87 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostProcessingDummy
|
||||
|
||||
Group
|
||||
grpGraphicsFunctionObjects
|
||||
|
||||
Description
|
||||
Dummy implementation of Foam::functionObjects::runTimePostProcessing
|
||||
to report when the real version is unavailable.
|
||||
|
||||
SourceFiles
|
||||
runTimePostProcessingDummy.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostProcessingDummy_H
|
||||
#define functionObjects_runTimePostProcessingDummy_H
|
||||
|
||||
#include "functionObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class runTimePostProcessingDummy Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class runTimePostProcessingDummy
|
||||
:
|
||||
public functionObject::unavailableFunctionObject
|
||||
{
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("runTimePostProcessing");
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
runTimePostProcessingDummy
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,808 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "fieldVisualisationBase.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
|
||||
#include "doubleVector.H"
|
||||
#include "foamVtkTools.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkArrowSource.h"
|
||||
#include "vtkCellDataToPointData.h"
|
||||
#include "vtkCellData.h"
|
||||
#include "vtkColorTransferFunction.h"
|
||||
#include "vtkCompositeDataSet.h"
|
||||
#include "vtkDataObjectTreeIterator.h"
|
||||
#include "vtkFieldData.h"
|
||||
#include "vtkGlyph3D.h"
|
||||
#include "vtkLookupTable.h"
|
||||
#include "vtkPointData.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
#include "vtkSphereSource.h"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::Enum
|
||||
<
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
|
||||
colourByType
|
||||
>
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
|
||||
colourByTypeNames
|
||||
({
|
||||
{ colourByType::cbColour, "colour" },
|
||||
{ colourByType::cbField, "field" },
|
||||
});
|
||||
|
||||
const Foam::Enum
|
||||
<
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
|
||||
colourMapType
|
||||
>
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
|
||||
colourMapTypeNames
|
||||
({
|
||||
{ colourMapType::cmCoolToWarm, "coolToWarm" },
|
||||
{ colourMapType::cmCoolToWarm, "blueWhiteRed" },
|
||||
{ colourMapType::cmColdAndHot, "coldAndHot" },
|
||||
{ colourMapType::cmFire, "fire" },
|
||||
{ colourMapType::cmRainbow, "rainbow" },
|
||||
{ colourMapType::cmGreyscale, "greyscale" },
|
||||
{ colourMapType::cmGreyscale, "grayscale" },
|
||||
{ colourMapType::cmXray, "xray" },
|
||||
});
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::fieldSummary
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
|
||||
queryFieldSummary
|
||||
(
|
||||
const word& fieldName,
|
||||
vtkDataSet* dataset
|
||||
)
|
||||
{
|
||||
fieldSummary queried;
|
||||
|
||||
if (dataset)
|
||||
{
|
||||
vtkDataArray* array;
|
||||
|
||||
array = vtkDataArray::SafeDownCast
|
||||
(
|
||||
dataset->GetCellData()->GetAbstractArray(fieldName.c_str())
|
||||
);
|
||||
|
||||
if (array)
|
||||
{
|
||||
queried.nComponents_ = array->GetNumberOfComponents();
|
||||
queried.association_ |= FieldAssociation::CELL_DATA;
|
||||
queried.range_ += vtk::Tools::rangeOf(array);
|
||||
}
|
||||
|
||||
array = vtkDataArray::SafeDownCast
|
||||
(
|
||||
dataset->GetPointData()->GetAbstractArray(fieldName.c_str())
|
||||
);
|
||||
|
||||
if (array)
|
||||
{
|
||||
queried.nComponents_ = array->GetNumberOfComponents();
|
||||
queried.association_ |= FieldAssociation::POINT_DATA;
|
||||
queried.range_ += vtk::Tools::rangeOf(array);
|
||||
}
|
||||
}
|
||||
|
||||
return queried;
|
||||
}
|
||||
|
||||
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::fieldSummary
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
|
||||
queryFieldSummary
|
||||
(
|
||||
const word& fieldName,
|
||||
vtkCompositeDataSet* data
|
||||
)
|
||||
{
|
||||
fieldSummary queried;
|
||||
|
||||
auto iter = vtkSmartPointer<vtkDataObjectTreeIterator>::New();
|
||||
|
||||
iter->SetDataSet(data);
|
||||
iter->VisitOnlyLeavesOn();
|
||||
iter->SkipEmptyNodesOn();
|
||||
|
||||
for
|
||||
(
|
||||
iter->InitTraversal();
|
||||
!iter->IsDoneWithTraversal();
|
||||
iter->GoToNextItem()
|
||||
)
|
||||
{
|
||||
vtkDataSet* dataset = vtkDataSet::SafeDownCast
|
||||
(
|
||||
iter->GetCurrentDataObject()
|
||||
);
|
||||
|
||||
if (dataset)
|
||||
{
|
||||
fieldSummary local(queryFieldSummary(fieldName, dataset));
|
||||
|
||||
if (!queried.nComponents_)
|
||||
{
|
||||
queried.nComponents_ = local.nComponents_;
|
||||
}
|
||||
|
||||
queried.association_ |= local.association_;
|
||||
queried.range_ += local.range_;
|
||||
}
|
||||
}
|
||||
|
||||
return queried;
|
||||
}
|
||||
|
||||
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::FieldAssociation
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
|
||||
queryFieldAssociation
|
||||
(
|
||||
const word& fieldName,
|
||||
vtkDataSet* dataset
|
||||
)
|
||||
{
|
||||
unsigned where(FieldAssociation::NO_DATA);
|
||||
|
||||
if (dataset)
|
||||
{
|
||||
if (dataset->GetCellData()->HasArray(fieldName.c_str()))
|
||||
{
|
||||
where |= FieldAssociation::CELL_DATA;
|
||||
}
|
||||
if (dataset->GetPointData()->HasArray(fieldName.c_str()))
|
||||
{
|
||||
where |= FieldAssociation::POINT_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
return FieldAssociation(where);
|
||||
}
|
||||
|
||||
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::FieldAssociation
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
|
||||
queryFieldAssociation
|
||||
(
|
||||
const word& fieldName,
|
||||
vtkCompositeDataSet* data
|
||||
)
|
||||
{
|
||||
unsigned where(FieldAssociation::NO_DATA);
|
||||
|
||||
auto iter = vtkSmartPointer<vtkDataObjectTreeIterator>::New();
|
||||
|
||||
iter->SetDataSet(data);
|
||||
iter->VisitOnlyLeavesOn();
|
||||
iter->SkipEmptyNodesOn();
|
||||
|
||||
for
|
||||
(
|
||||
iter->InitTraversal();
|
||||
!iter->IsDoneWithTraversal();
|
||||
iter->GoToNextItem()
|
||||
)
|
||||
{
|
||||
vtkDataSet* dataset = vtkDataSet::SafeDownCast
|
||||
(
|
||||
iter->GetCurrentDataObject()
|
||||
);
|
||||
|
||||
where |= queryFieldAssociation(fieldName, dataset);
|
||||
}
|
||||
|
||||
return FieldAssociation(where);
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::fieldVisualisationBase::addMagField
|
||||
(
|
||||
const word& fieldName,
|
||||
vtkFieldData* fieldData
|
||||
)
|
||||
{
|
||||
if (!fieldData)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vtkDataArray* input = vtkDataArray::SafeDownCast
|
||||
(
|
||||
fieldData->GetAbstractArray(fieldName.c_str())
|
||||
);
|
||||
|
||||
if (!input)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const word magFieldName = "mag(" + fieldName + ")";
|
||||
|
||||
vtkDataArray* output = vtkDataArray::SafeDownCast
|
||||
(
|
||||
fieldData->GetAbstractArray(magFieldName.c_str())
|
||||
);
|
||||
|
||||
if (output)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Simplfy and only handle scalar/vector input
|
||||
|
||||
const int nCmpt = input->GetNumberOfComponents();
|
||||
const vtkIdType len = input->GetNumberOfTuples();
|
||||
|
||||
if (nCmpt == 1)
|
||||
{
|
||||
auto data = vtkSmartPointer<vtkFloatArray>::New();
|
||||
|
||||
data->SetName(magFieldName.c_str());
|
||||
data->SetNumberOfComponents(1);
|
||||
data->SetNumberOfTuples(len);
|
||||
|
||||
double scratch;
|
||||
for (vtkIdType i=0; i < len; ++i)
|
||||
{
|
||||
input->GetTuple(i, &scratch);
|
||||
|
||||
scratch = Foam::mag(scratch);
|
||||
data->SetTuple(i, &scratch);
|
||||
}
|
||||
|
||||
fieldData->AddArray(data);
|
||||
}
|
||||
else if (nCmpt == 3)
|
||||
{
|
||||
auto data = vtkSmartPointer<vtkFloatArray>::New();
|
||||
|
||||
data->SetName(magFieldName.c_str());
|
||||
data->SetNumberOfComponents(1);
|
||||
data->SetNumberOfTuples(len);
|
||||
|
||||
doubleVector scratch;
|
||||
for (vtkIdType i=0; i < len; ++i)
|
||||
{
|
||||
input->GetTuple(i, scratch.v_);
|
||||
|
||||
scratch.x() = Foam::mag(scratch);
|
||||
|
||||
data->SetTuple(i, scratch.v_);
|
||||
}
|
||||
|
||||
fieldData->AddArray(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::fieldVisualisationBase::addMagField
|
||||
(
|
||||
const word& fieldName,
|
||||
vtkDataSet* dataset
|
||||
)
|
||||
{
|
||||
if (dataset)
|
||||
{
|
||||
addMagField(fieldName, dataset->GetCellData());
|
||||
addMagField(fieldName, dataset->GetPointData());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::fieldVisualisationBase::addMagField
|
||||
(
|
||||
const word& fieldName,
|
||||
vtkCompositeDataSet* data
|
||||
)
|
||||
{
|
||||
auto iter = vtkSmartPointer<vtkDataObjectTreeIterator>::New();
|
||||
|
||||
iter->SetDataSet(data);
|
||||
iter->VisitOnlyLeavesOn();
|
||||
iter->SkipEmptyNodesOn();
|
||||
|
||||
for
|
||||
(
|
||||
iter->InitTraversal();
|
||||
!iter->IsDoneWithTraversal();
|
||||
iter->GoToNextItem()
|
||||
)
|
||||
{
|
||||
vtkDataSet* dataset = vtkDataSet::SafeDownCast
|
||||
(
|
||||
iter->GetCurrentDataObject()
|
||||
);
|
||||
addMagField(fieldName, dataset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
|
||||
fieldSummary::reduce()
|
||||
{
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
Foam::reduce(nComponents_, maxOp<int>());
|
||||
Foam::reduce(association_, bitOrOp<unsigned>());
|
||||
Foam::reduce(range_, minMaxOp<scalar>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::operator<<
|
||||
(
|
||||
Ostream& os,
|
||||
const InfoProxy
|
||||
<
|
||||
functionObjects::runTimePostPro::fieldVisualisationBase::fieldSummary
|
||||
>& proxy
|
||||
)
|
||||
{
|
||||
os << "nComponents:" << proxy.t_.nComponents_
|
||||
<< " association:" << label(proxy.t_.association_)
|
||||
<< " min/max:" << proxy.t_.range_;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
|
||||
setColourMap
|
||||
(
|
||||
vtkLookupTable* lut
|
||||
) const
|
||||
{
|
||||
constexpr label nColours = 256;
|
||||
|
||||
lut->SetNumberOfColors(nColours);
|
||||
|
||||
auto ctf = vtkSmartPointer<vtkColorTransferFunction>::New();
|
||||
|
||||
switch (colourMap_)
|
||||
{
|
||||
case cmCoolToWarm: // ParaView: "Cool To Warm"
|
||||
{
|
||||
ctf->SetColorSpaceToDiverging();
|
||||
ctf->AddRGBPoint(0.0, 0.231372, 0.298039, 0.752941);
|
||||
ctf->AddRGBPoint(0.5, 0.865003, 0.865003, 0.865003);
|
||||
ctf->AddRGBPoint(1.0, 0.705882, 0.0156863, 0.14902);
|
||||
// ctf->SetNanColor(1, 1, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
case cmColdAndHot: // ParaView : "Cold and Hot"
|
||||
{
|
||||
ctf->SetColorSpaceToRGB();
|
||||
ctf->AddRGBPoint(0, 0, 1, 1);
|
||||
ctf->AddRGBPoint(0.45, 0, 0, 1);
|
||||
ctf->AddRGBPoint(0.5, 0, 0, 0.5019608);
|
||||
ctf->AddRGBPoint(0.55, 1, 0, 0);
|
||||
ctf->AddRGBPoint(1, 1, 1, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
case cmFire: // ParaView: Black-Body Radiation
|
||||
{
|
||||
ctf->SetColorSpaceToRGB();
|
||||
ctf->AddRGBPoint(0, 0, 0, 0);
|
||||
ctf->AddRGBPoint(0.4, 0.901961, 0, 0);
|
||||
ctf->AddRGBPoint(0.8, 0.901961, 0.901961, 0);
|
||||
ctf->AddRGBPoint(1, 1, 1, 1);
|
||||
// ctf->SetNanColor(0, 0.49804, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
case cmRainbow:
|
||||
{
|
||||
ctf->SetColorSpaceToHSV();
|
||||
ctf->AddRGBPoint(0, 0, 0, 1);
|
||||
ctf->AddRGBPoint(0.5, 0, 1, 0);
|
||||
ctf->AddRGBPoint(1, 1, 0, 0);
|
||||
// ctf->SetNanColor(0.498039, 0.498039, 0.498039);
|
||||
break;
|
||||
}
|
||||
|
||||
case cmGreyscale: // ParaView: grayscale
|
||||
{
|
||||
ctf->SetColorSpaceToRGB();
|
||||
ctf->AddRGBPoint(0, 0, 0, 0);
|
||||
ctf->AddRGBPoint(1, 1, 1, 1);
|
||||
// ctf->SetNanColor(1, 0, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
case cmXray: // ParaView: "X ray"
|
||||
{
|
||||
ctf->SetColorSpaceToRGB();
|
||||
ctf->AddRGBPoint(0, 1, 1, 1);
|
||||
ctf->AddRGBPoint(1, 0, 0, 0);
|
||||
// ctf->SetNanColor(1, 0, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double rgba[4] = { 0, 0, 0, 1 };
|
||||
for (label i = 0; i < nColours; ++i)
|
||||
{
|
||||
ctf->GetColor(scalar(i)/scalar(nColours), rgba);
|
||||
lut->SetTableValue(i, rgba);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
|
||||
addScalarBar
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer,
|
||||
vtkLookupTable* lut
|
||||
) const
|
||||
{
|
||||
// Add the scalar bar - only once!
|
||||
if (renderer && Pstream::master())
|
||||
{
|
||||
scalarBar_.add(colours_["text"]->value(position), renderer, lut);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
|
||||
setField
|
||||
(
|
||||
const scalar position,
|
||||
const word& colourFieldName,
|
||||
const FieldAssociation fieldAssociation,
|
||||
vtkMapper* mapper,
|
||||
vtkRenderer* renderer
|
||||
) const
|
||||
{
|
||||
mapper->InterpolateScalarsBeforeMappingOn();
|
||||
|
||||
switch (colourBy_)
|
||||
{
|
||||
case cbColour:
|
||||
{
|
||||
mapper->ScalarVisibilityOff();
|
||||
break;
|
||||
}
|
||||
|
||||
case cbField:
|
||||
{
|
||||
// Create look-up table for colours
|
||||
auto lut = vtkSmartPointer<vtkLookupTable>::New();
|
||||
setColourMap(lut);
|
||||
lut->SetVectorMode(vtkScalarsToColors::MAGNITUDE);
|
||||
lut->SetTableRange(range_.first(), range_.second());
|
||||
|
||||
// Configure the mapper
|
||||
const char* fieldName = colourFieldName.c_str();
|
||||
mapper->SelectColorArray(fieldName);
|
||||
|
||||
// Use either point or cell data
|
||||
// - if both point and cell data exists, preferentially choose
|
||||
// point data. This is often the case when using glyphs.
|
||||
|
||||
if (fieldAssociation & FieldAssociation::POINT_DATA)
|
||||
{
|
||||
mapper->SetScalarModeToUsePointFieldData();
|
||||
}
|
||||
else if (fieldAssociation & FieldAssociation::CELL_DATA)
|
||||
{
|
||||
mapper->SetScalarModeToUseCellFieldData();
|
||||
}
|
||||
else
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Unable to determine cell or point data type "
|
||||
<< "- assuming point data";
|
||||
mapper->SetScalarModeToUsePointFieldData();
|
||||
}
|
||||
mapper->SetScalarRange(range_.first(), range_.second());
|
||||
mapper->SetColorModeToMapScalars();
|
||||
mapper->SetLookupTable(lut);
|
||||
mapper->ScalarVisibilityOn();
|
||||
|
||||
// Add the scalar bar
|
||||
addScalarBar(position, renderer, lut);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mapper->Modified();
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
|
||||
addGlyphs
|
||||
(
|
||||
const scalar position,
|
||||
const word& scaleFieldName,
|
||||
const fieldSummary& scaleFieldInfo,
|
||||
const word& colourFieldName,
|
||||
const fieldSummary& colourFieldInfo,
|
||||
const scalar maxGlyphLength,
|
||||
|
||||
vtkPolyData* data,
|
||||
vtkActor* actor,
|
||||
vtkRenderer* renderer
|
||||
) const
|
||||
{
|
||||
// Determine whether we have CellData/PointData and (scalar/vector)
|
||||
// or if we need to a cell->point data filter.
|
||||
|
||||
if (!scaleFieldInfo.exists())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Cannot add glyphs. No such cell or point field: "
|
||||
<< scaleFieldName << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!scaleFieldInfo.isScalar() && !scaleFieldInfo.isVector())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Glyphs can only be added to scalar or vector data. "
|
||||
<< "Unable to process field " << scaleFieldName << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Setup glyphs
|
||||
|
||||
// The min/max data range for the input data (cell or point),
|
||||
// which will be slightly less after using a cell->point filter
|
||||
// (since it averages), but is still essentially OK.
|
||||
|
||||
|
||||
auto glyph = vtkSmartPointer<vtkGlyph3D>::New();
|
||||
glyph->ScalingOn();
|
||||
|
||||
auto glyphMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
glyphMapper->SetInputConnection(glyph->GetOutputPort());
|
||||
|
||||
vtkSmartPointer<vtkCellDataToPointData> cellToPoint;
|
||||
|
||||
// The data source is filtered or original (PointData)
|
||||
if (!scaleFieldInfo.hasPointData() || !colourFieldInfo.hasPointData())
|
||||
{
|
||||
// CellData - Need a cell->point filter
|
||||
cellToPoint = vtkSmartPointer<vtkCellDataToPointData>::New();
|
||||
cellToPoint->SetInputData(data);
|
||||
|
||||
glyph->SetInputConnection(cellToPoint->GetOutputPort());
|
||||
}
|
||||
else
|
||||
{
|
||||
glyph->SetInputData(data);
|
||||
}
|
||||
|
||||
|
||||
if (scaleFieldInfo.nComponents_ == 1)
|
||||
{
|
||||
auto sphere = vtkSmartPointer<vtkSphereSource>::New();
|
||||
sphere->SetCenter(0, 0, 0);
|
||||
sphere->SetRadius(0.5);
|
||||
|
||||
// Setting higher resolution slows the rendering significantly
|
||||
// sphere->SetPhiResolution(20);
|
||||
// sphere->SetThetaResolution(20);
|
||||
|
||||
glyph->SetSourceConnection(sphere->GetOutputPort());
|
||||
|
||||
if (maxGlyphLength > 0)
|
||||
{
|
||||
// Using range from the data:
|
||||
// glyph->SetRange
|
||||
// (
|
||||
// scaleFieldInfo.range_.first(),
|
||||
// scaleFieldInfo.range_.second()
|
||||
// );
|
||||
|
||||
// Set range according to user-supplied limits
|
||||
glyph->ClampingOn();
|
||||
glyph->SetRange(range_.first(), range_.second());
|
||||
|
||||
// If range[0] != min(value), maxGlyphLength behaviour will not
|
||||
// be correct...
|
||||
glyph->SetScaleFactor(maxGlyphLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
glyph->SetScaleFactor(1);
|
||||
}
|
||||
glyph->SetScaleModeToScaleByScalar();
|
||||
glyph->OrientOff();
|
||||
glyph->SetColorModeToColorByScalar();
|
||||
glyph->SetInputArrayToProcess
|
||||
(
|
||||
0, // index (0) = scalars
|
||||
0, // port
|
||||
0, // connection
|
||||
vtkDataObject::FIELD_ASSOCIATION_POINTS,
|
||||
scaleFieldName.c_str()
|
||||
);
|
||||
}
|
||||
else if (scaleFieldInfo.nComponents_ == 3)
|
||||
{
|
||||
auto arrow = vtkSmartPointer<vtkArrowSource>::New();
|
||||
arrow->SetTipResolution(10);
|
||||
arrow->SetTipRadius(0.1);
|
||||
arrow->SetTipLength(0.35);
|
||||
arrow->SetShaftResolution(10);
|
||||
arrow->SetShaftRadius(0.03);
|
||||
|
||||
glyph->SetSourceConnection(arrow->GetOutputPort());
|
||||
|
||||
if (maxGlyphLength > 0)
|
||||
{
|
||||
// Set range according data limits
|
||||
glyph->ClampingOn();
|
||||
glyph->SetRange
|
||||
(
|
||||
scaleFieldInfo.range_.first(),
|
||||
scaleFieldInfo.range_.second()
|
||||
);
|
||||
glyph->SetScaleFactor(maxGlyphLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
glyph->SetScaleFactor(1);
|
||||
}
|
||||
glyph->SetScaleModeToScaleByVector();
|
||||
glyph->OrientOn();
|
||||
glyph->SetVectorModeToUseVector();
|
||||
glyph->SetColorModeToColorByVector();
|
||||
glyph->SetInputArrayToProcess
|
||||
(
|
||||
1, // index (1) = vectors
|
||||
0, // port
|
||||
0, // connection
|
||||
vtkDataObject::FIELD_ASSOCIATION_POINTS,
|
||||
scaleFieldName.c_str()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Apply colouring etc.
|
||||
// We already established PointData, which as either in the original,
|
||||
// or generated with vtkCellDataToPointData filter.
|
||||
|
||||
{
|
||||
glyph->Update();
|
||||
|
||||
setField
|
||||
(
|
||||
position,
|
||||
colourFieldName,
|
||||
FieldAssociation::POINT_DATA, // Original or after filter
|
||||
glyphMapper,
|
||||
renderer
|
||||
);
|
||||
|
||||
glyphMapper->Update();
|
||||
|
||||
actor->SetMapper(glyphMapper);
|
||||
|
||||
renderer->AddActor(actor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
|
||||
fieldVisualisationBase
|
||||
(
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
colours_(colours),
|
||||
fieldName_(dict.get<word>("field")),
|
||||
smooth_(dict.getOrDefault("smooth", false)),
|
||||
colourBy_(cbColour),
|
||||
colourMap_(cmRainbow),
|
||||
range_(),
|
||||
scalarBar_()
|
||||
{
|
||||
colourByTypeNames.readEntry("colourBy", dict, colourBy_);
|
||||
|
||||
switch (colourBy_)
|
||||
{
|
||||
case cbColour:
|
||||
{
|
||||
scalarBar_.hide();
|
||||
break;
|
||||
}
|
||||
|
||||
case cbField:
|
||||
{
|
||||
dict.readEntry("range", range_);
|
||||
colourMapTypeNames.readIfPresent("colourMap", dict, colourMap_);
|
||||
|
||||
const dictionary* sbar = dict.findDict("scalarBar");
|
||||
|
||||
if (sbar)
|
||||
{
|
||||
scalarBar_.read(*sbar);
|
||||
}
|
||||
else
|
||||
{
|
||||
scalarBar_.hide();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::
|
||||
~fieldVisualisationBase()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::HashPtrTable<Foam::Function1<Foam::vector>, Foam::word>&
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::colours() const
|
||||
{
|
||||
return colours_;
|
||||
}
|
||||
|
||||
|
||||
const Foam::word&
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::fieldName()
|
||||
const
|
||||
{
|
||||
return fieldName_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,367 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::fieldVisualisationBase
|
||||
|
||||
Description
|
||||
Base class for scene objects
|
||||
|
||||
Dictionary controls - colour by field
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
colourBy | Colouring type (color / field) | yes |
|
||||
range | Lower/upper range to display | yes |
|
||||
smooth | Request smoother output | no | false
|
||||
colourMap | Colour map for rendering | no | rainbow
|
||||
scalarBar | Scalar-bar sub-dictionary | yes |
|
||||
\endtable
|
||||
|
||||
Colour maps include "coolToWarm" ("blueWhiteRed"), "coldAndHot",
|
||||
"fire", "rainbow", "greyscale" ("grayscale"), "xray". For historical
|
||||
reasons, the default is still "rainbow".
|
||||
|
||||
SourceFiles
|
||||
fieldVisualisationBase.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_fieldVisualisationBase_H
|
||||
#define functionObjects_fieldVisualisationBase_H
|
||||
|
||||
#include "dictionary.H"
|
||||
#include "Tuple2.H"
|
||||
#include "Enum.H"
|
||||
#include "vector.H"
|
||||
#include "MinMax.H"
|
||||
#include "HashPtrTable.H"
|
||||
#include "scalarBar.H"
|
||||
#include "Function1.H"
|
||||
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Forward Declarations
|
||||
class vtkActor;
|
||||
class vtkCompositeDataSet;
|
||||
class vtkCompositeDataGeometryFilter;
|
||||
class vtkCompositePolyDataMapper;
|
||||
class vtkDataSet;
|
||||
class vtkDataSetAlgorithm;
|
||||
class vtkFieldData;
|
||||
class vtkLookupTable;
|
||||
class vtkMapper;
|
||||
class vtkPolyData;
|
||||
class vtkPolyDataMapper;
|
||||
class vtkRenderer;
|
||||
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
// Forward Declarations
|
||||
class runTimePostProcessing;
|
||||
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class fieldVisualisationBase Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class fieldVisualisationBase
|
||||
{
|
||||
public:
|
||||
|
||||
// Public Enumerations
|
||||
|
||||
//- Colouring type
|
||||
enum colourByType
|
||||
{
|
||||
cbColour, //!< "colour" : Use specified colour
|
||||
cbField //!< "field" : Use named field
|
||||
};
|
||||
|
||||
//- Enumeration names for colourByType
|
||||
static const Enum<colourByType> colourByTypeNames;
|
||||
|
||||
//- Colour map enumerations
|
||||
enum colourMapType
|
||||
{
|
||||
cmCoolToWarm, //!< ParaView "Cool To Warm" blue-white-read
|
||||
cmBlueWhiteRed = cmCoolToWarm,
|
||||
cmColdAndHot, //!< ParaView "Cold and Hot"
|
||||
cmFire, //!< ParaView "Black-Body Radiation"
|
||||
cmRainbow, //!< "rainbow"
|
||||
cmGreyscale, //!< ParaView "Grayscale"
|
||||
cmXray //!< ParaView "X Ray"
|
||||
};
|
||||
|
||||
//- Enumeration names for colourMapType
|
||||
static const Enum<colourMapType> colourMapTypeNames;
|
||||
|
||||
|
||||
//- Enumeration of the data field associations
|
||||
// These values are used internally and do NOT correspond to the
|
||||
// vtkDataObject::FieldAssociations enumeration.
|
||||
enum FieldAssociation
|
||||
{
|
||||
NO_DATA = 0, //!< No associated data
|
||||
CELL_DATA = 0x1, //!< Associated with cells (faces)
|
||||
POINT_DATA = 0x2, //!< Associated with points
|
||||
CELL_POINT_DATA = 0x3 //!< Associated with cells and/or points
|
||||
};
|
||||
|
||||
|
||||
//- General field characteristics.
|
||||
// For convenience, the interface is exposed but external use is
|
||||
// highly discouraged.
|
||||
struct fieldSummary
|
||||
{
|
||||
int nComponents_;
|
||||
unsigned association_;
|
||||
scalarMinMax range_;
|
||||
|
||||
//- Construct null
|
||||
fieldSummary()
|
||||
:
|
||||
nComponents_(0),
|
||||
association_(0u),
|
||||
range_()
|
||||
{}
|
||||
|
||||
//- Parallel reduction. A no-op if Pstream::parRun() is false
|
||||
void reduce();
|
||||
|
||||
//- True if nComponents_ == 1
|
||||
bool isScalar() const
|
||||
{
|
||||
return nComponents_ == 1;
|
||||
}
|
||||
|
||||
//- True if nComponents_ == 3
|
||||
bool isVector() const
|
||||
{
|
||||
return nComponents_ == 3;
|
||||
}
|
||||
|
||||
//- True if association_ is non-zero
|
||||
bool exists() const
|
||||
{
|
||||
return association_;
|
||||
}
|
||||
|
||||
//- True if there is a POINT_DATA association
|
||||
bool hasPointData() const
|
||||
{
|
||||
return (association_ & FieldAssociation::POINT_DATA);
|
||||
}
|
||||
|
||||
InfoProxy<fieldSummary> info() const
|
||||
{
|
||||
return InfoProxy<fieldSummary>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- Colours
|
||||
const HashPtrTable<Function1<vector>>& colours_;
|
||||
|
||||
//- Field name
|
||||
word fieldName_;
|
||||
|
||||
//- Requested smoother fields (eg, interpolate cell -> point values)
|
||||
bool smooth_;
|
||||
|
||||
//- Colour by type
|
||||
colourByType colourBy_;
|
||||
|
||||
//- Colour map type
|
||||
colourMapType colourMap_;
|
||||
|
||||
//- Range of values
|
||||
Tuple2<scalar, scalar> range_;
|
||||
|
||||
//- Scalar bar characteristics
|
||||
scalarBar scalarBar_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Query DataSet for field name and its field association
|
||||
static fieldSummary queryFieldSummary
|
||||
(
|
||||
const word& fieldName,
|
||||
vtkDataSet* dataset
|
||||
);
|
||||
|
||||
//- Query composite DataSet for field name and its FieldAssociation
|
||||
static fieldSummary queryFieldSummary
|
||||
(
|
||||
const word& fieldName,
|
||||
vtkCompositeDataSet* data
|
||||
);
|
||||
|
||||
//- Query DataSet for field name and its field association
|
||||
static FieldAssociation queryFieldAssociation
|
||||
(
|
||||
const word& fieldName,
|
||||
vtkDataSet* dataset
|
||||
);
|
||||
|
||||
//- Query composite DataSet for field name and its FieldAssociation
|
||||
static FieldAssociation queryFieldAssociation
|
||||
(
|
||||
const word& fieldName,
|
||||
vtkCompositeDataSet* data
|
||||
);
|
||||
|
||||
|
||||
//- Add "mag(..)" field for filters that only accept scalars
|
||||
static void addMagField
|
||||
(
|
||||
const word& fieldName,
|
||||
vtkFieldData* fieldData
|
||||
);
|
||||
|
||||
//- Add "mag(..)" field for filters that only accept scalars
|
||||
static void addMagField
|
||||
(
|
||||
const word& fieldName,
|
||||
vtkDataSet* dataset
|
||||
);
|
||||
|
||||
//- Add "mag(..)" field for filters that only accept scalars
|
||||
static void addMagField
|
||||
(
|
||||
const word& fieldName,
|
||||
vtkCompositeDataSet* data
|
||||
);
|
||||
|
||||
|
||||
//- Set the colour map
|
||||
void setColourMap(vtkLookupTable* lut) const;
|
||||
|
||||
//- Add scalar bar (if visible) to renderer
|
||||
void addScalarBar
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer,
|
||||
vtkLookupTable* lut
|
||||
) const;
|
||||
|
||||
//- Set field/configure mapper, add scalar bar
|
||||
void setField
|
||||
(
|
||||
const scalar position,
|
||||
const word& colourFieldName,
|
||||
const FieldAssociation fieldAssociation,
|
||||
vtkMapper* mapper,
|
||||
vtkRenderer* renderer
|
||||
) const;
|
||||
|
||||
//- Add glyphs
|
||||
void addGlyphs
|
||||
(
|
||||
const scalar position,
|
||||
const word& scaleFieldName,
|
||||
const fieldSummary& scaleFieldInfo,
|
||||
const word& colourFieldName,
|
||||
const fieldSummary& colourFieldInfo,
|
||||
const scalar maxGlyphLength,
|
||||
|
||||
vtkPolyData* data,
|
||||
vtkActor* actor,
|
||||
vtkRenderer* renderer
|
||||
) const;
|
||||
|
||||
|
||||
//- No copy construct
|
||||
fieldVisualisationBase(const fieldVisualisationBase&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const fieldVisualisationBase&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
fieldVisualisationBase
|
||||
(
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~fieldVisualisationBase();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- Return the colours
|
||||
const HashPtrTable<Function1<vector>>& colours() const;
|
||||
|
||||
//- Return the field name
|
||||
const word& fieldName() const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
|
||||
|
||||
// Ostream
|
||||
Ostream& operator<<
|
||||
(
|
||||
Ostream& os,
|
||||
const InfoProxy
|
||||
<
|
||||
functionObjects::runTimePostPro::fieldVisualisationBase::fieldSummary
|
||||
>& proxy
|
||||
);
|
||||
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,94 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "functionObjectBase.H"
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
Foam::fileName
|
||||
Foam::functionObjects::runTimePostPro::functionObjectBase::getFileName
|
||||
(
|
||||
const word& keyword,
|
||||
const word& subDictName
|
||||
) const
|
||||
{
|
||||
dictionary dict;
|
||||
state_.getObjectDict(functionObjectName_, subDictName, dict);
|
||||
|
||||
fileName f;
|
||||
if (dict.readIfPresent<fileName>(keyword, f))
|
||||
{
|
||||
f.expand();
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::functionObjectBase::removeFile
|
||||
(
|
||||
const word& keyword,
|
||||
const word& subDictName
|
||||
)
|
||||
{
|
||||
// Foam::rm() ignores empty names etc.
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
return Foam::rm(getFileName(keyword, subDictName));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::functionObjectBase::functionObjectBase
|
||||
(
|
||||
const stateFunctionObject& state,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
fieldVisualisationBase(dict, colours),
|
||||
state_(state),
|
||||
functionObjectName_(dict.get<word>("functionObject")),
|
||||
liveObject_(dict.getOrDefault("liveObject", true)),
|
||||
clearObjects_(dict.getOrDefault("clearObjects", false))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::functionObjectBase::clear()
|
||||
{
|
||||
return clearObjects_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,163 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::functionObjectBase
|
||||
|
||||
Description
|
||||
Base class for function object visualisation
|
||||
|
||||
Dictionary controls
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
functionObject | The data source | yes |
|
||||
clearObjects | Remove file after use | no | no
|
||||
liveObject | Prefer simulation data source | no | true
|
||||
\endtable
|
||||
|
||||
The "live" keyword indiates that from within the simulation (in memory)
|
||||
is preferred over data from disk (for example).
|
||||
|
||||
SourceFiles
|
||||
functionObjectBase.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_functionObjectBase_H
|
||||
#define functionObjects_runTimePostPro_functionObjectBase_H
|
||||
|
||||
#include "fieldVisualisationBase.H"
|
||||
#include "stateFunctionObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class functionObjectBase Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class functionObjectBase
|
||||
:
|
||||
public fieldVisualisationBase
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- Reference to the state
|
||||
const stateFunctionObject& state_;
|
||||
|
||||
//- The function object name that provides the source data
|
||||
word functionObjectName_;
|
||||
|
||||
//- Flag to indicate "live" (simulation) data source should be used
|
||||
bool liveObject_;
|
||||
|
||||
//- Flag to indicate that source data should be cleared after use
|
||||
bool clearObjects_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Retrieve the filename used to create the scene object
|
||||
//- using information stored via the stateFunctionObject.
|
||||
//
|
||||
// \param keyword is normally "file"
|
||||
// \param subDictName is the sub-dictionary name, which is often
|
||||
// the fieldName when one file is used per field.
|
||||
//
|
||||
// Eg,
|
||||
// \verbatim
|
||||
// T
|
||||
// {
|
||||
// file "<case>/relpath/T_object.vtk";
|
||||
// }
|
||||
// defaultCloud
|
||||
// {
|
||||
// file "<case>/relpath/cloud_0001.vtp";
|
||||
// fields (T U);
|
||||
// }
|
||||
// \endverbatim
|
||||
fileName getFileName
|
||||
(
|
||||
const word& keyword,
|
||||
const word& subDictName
|
||||
) const;
|
||||
|
||||
//- Remove file used to create the scene object.
|
||||
// Same naming semantics as getFileName.
|
||||
//
|
||||
// \note does not change the stateFunctionObject
|
||||
bool removeFile(const word& keyword, const word& subDictName);
|
||||
|
||||
|
||||
//- No copy construct
|
||||
functionObjectBase(const functionObjectBase&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const functionObjectBase&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
functionObjectBase
|
||||
(
|
||||
const stateFunctionObject& state,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~functionObjectBase() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Clear files used to create the object(s)
|
||||
virtual bool clear();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,279 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "functionObjectCloud.H"
|
||||
#include "fvMesh.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkProperty.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// VTK Readers
|
||||
#include "vtkPolyDataReader.h"
|
||||
#include "vtkXMLPolyDataReader.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
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
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
pointData(parent, dict, colours),
|
||||
functionObjectBase(parent, dict, colours),
|
||||
cloudName_(dict.get<word>("cloud")),
|
||||
inputFileName_(),
|
||||
colourFieldName_(dict.get<word>("colourField")),
|
||||
actor_()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::functionObjectCloud::
|
||||
~functionObjectCloud()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::functionObjectCloud::
|
||||
addGeometryFromFile
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (!visible_)
|
||||
{
|
||||
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.
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
inputFileName_ = getFileName("file", cloudName_);
|
||||
|
||||
if (inputFileName_.size())
|
||||
{
|
||||
polyData = getPolyDataFile(inputFileName_);
|
||||
|
||||
if (!polyData || polyData->GetNumberOfPoints() == 0)
|
||||
{
|
||||
good = false;
|
||||
|
||||
WarningInFunction
|
||||
<< "Could not read "<< inputFileName_ << nl
|
||||
<< "Only VTK (.vtp) files are supported"
|
||||
<< endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugInfo
|
||||
<< " Resolved cloud file " << inputFileName_ << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
good = false;
|
||||
|
||||
WarningInFunction
|
||||
<< "Unable to find function object " << functionObjectName_
|
||||
<< " output for field " << fieldName_
|
||||
<< ". Cloud will not be processed"
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
inputFileName_.clear();
|
||||
}
|
||||
|
||||
reduce(good, andOp<bool>());
|
||||
|
||||
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);
|
||||
|
||||
DebugInfo
|
||||
<< " Field " << fieldName_ << ' ' << scaleFieldInfo.info() << nl
|
||||
<< " Field " << colourFieldName_ << ' ' << colourFieldInfo.info()
|
||||
<< endl;
|
||||
|
||||
|
||||
// No reduction
|
||||
|
||||
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
|
||||
actor_->SetMapper(mapper);
|
||||
|
||||
/// dataset->Print(std::cout);
|
||||
|
||||
addGlyphs
|
||||
(
|
||||
position,
|
||||
fieldName_, scaleFieldInfo, // scaling
|
||||
colourFieldName_, colourFieldInfo, // colour
|
||||
maxGlyphLength_,
|
||||
polyData,
|
||||
actor_,
|
||||
renderer
|
||||
);
|
||||
|
||||
renderer->AddActor(actor_);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::functionObjectCloud::
|
||||
addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
// File source
|
||||
addGeometryFromFile(position, renderer);
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::functionObjectCloud::updateActors
|
||||
(
|
||||
const scalar position
|
||||
)
|
||||
{
|
||||
if (actor_)
|
||||
{
|
||||
const vector colour = pointColour_->value(position);
|
||||
|
||||
vtkProperty* prop = actor_->GetProperty();
|
||||
|
||||
prop->SetOpacity(opacity(position));
|
||||
|
||||
prop->SetColor(colour[0], colour[1], colour[2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::functionObjectCloud::clear()
|
||||
{
|
||||
if (functionObjectBase::clear())
|
||||
{
|
||||
if (inputFileName_.size() && Foam::rm(inputFileName_))
|
||||
{
|
||||
inputFileName_.clear();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,152 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::functionObjectCloud
|
||||
|
||||
Description
|
||||
Visualisation of cloud data from function object output (file-based only).
|
||||
|
||||
Dictionary controls
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
type | The point type: functionObjectCloud | yes |
|
||||
functionObject | The data source | yes |
|
||||
cloud | The cloud name | no |
|
||||
field | The field for glyphs scaling | no |
|
||||
colourField | The field to display | no |
|
||||
\endtable
|
||||
|
||||
SourceFiles
|
||||
functionObjectCloud.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_functionObjectCloud_H
|
||||
#define functionObjects_runTimePostPro_functionObjectCloud_H
|
||||
|
||||
#include "pointData.H"
|
||||
#include "functionObjectBase.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class functionObjectCloud Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class functionObjectCloud
|
||||
:
|
||||
public pointData,
|
||||
public functionObjectBase
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- Name of functionObjectCloud
|
||||
word cloudName_;
|
||||
|
||||
//- The input filename used
|
||||
fileName inputFileName_;
|
||||
|
||||
//- Name of field to colour by
|
||||
word colourFieldName_;
|
||||
|
||||
//- Actor
|
||||
vtkSmartPointer<vtkActor> actor_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- No copy construct
|
||||
functionObjectCloud(const functionObjectCloud&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const functionObjectCloud&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeNameNoDebug("functionObjectCloud");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
functionObjectCloud
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~functionObjectCloud();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Add cloud to scene (using file source)
|
||||
bool addGeometryFromFile
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Add cloud to scene
|
||||
virtual void addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Update actors
|
||||
virtual void updateActors(const scalar position);
|
||||
|
||||
//- Clear files used to create the object(s)
|
||||
virtual bool clear();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,202 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "functionObjectLine.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkProperty.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// VTK Readers
|
||||
#include "vtkPolyDataReader.h"
|
||||
#include "vtkXMLPolyDataReader.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
defineTypeName(functionObjectLine);
|
||||
addToRunTimeSelectionTable(pathline, functionObjectLine, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
static vtkSmartPointer<vtkPolyData> getPolyDataFile(const Foam::fileName& fName)
|
||||
{
|
||||
// Not extremely elegant...
|
||||
vtkSmartPointer<vtkPolyData> dataset;
|
||||
|
||||
if ("vtk" == fName.ext())
|
||||
{
|
||||
auto reader = vtkSmartPointer<vtkPolyDataReader>::New();
|
||||
|
||||
reader->SetFileName(fName.c_str());
|
||||
reader->Update();
|
||||
dataset = reader->GetOutput();
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
if ("vtp" == fName.ext())
|
||||
{
|
||||
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::functionObjectLine::functionObjectLine
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
pathline(parent, dict, colours),
|
||||
functionObjectBase(parent, dict, colours),
|
||||
actor_()
|
||||
{
|
||||
actor_ = vtkSmartPointer<vtkActor>::New();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::functionObjectLine::~functionObjectLine()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::functionObjectLine::
|
||||
addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
// Currently master-only
|
||||
if (!visible_ || !renderer || !Pstream::master())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
fileName fName = getFileName("file", fieldName_);
|
||||
if (fName.empty())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Unable to read file name from function object "
|
||||
<< functionObjectName_ << " for field " << fieldName_
|
||||
<< ". Line will not be processed"
|
||||
<< endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
auto polyData = getPolyDataFile(fName);
|
||||
|
||||
if (!polyData || polyData->GetNumberOfPoints() == 0)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Could not read "<< fName << nl
|
||||
<< "Only VTK (.vtp, .vtk) files are supported"
|
||||
<< endl;
|
||||
return;
|
||||
}
|
||||
|
||||
DebugInfo << " Resolved lines " << fName << endl;
|
||||
|
||||
|
||||
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
|
||||
setField
|
||||
(
|
||||
position,
|
||||
fieldName_,
|
||||
queryFieldAssociation(fieldName_, polyData),
|
||||
mapper,
|
||||
renderer
|
||||
);
|
||||
|
||||
actor_->SetMapper(mapper);
|
||||
|
||||
addLines(position, actor_, polyData);
|
||||
|
||||
renderer->AddActor(actor_);
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::functionObjectLine::updateActors
|
||||
(
|
||||
const scalar position
|
||||
)
|
||||
{
|
||||
actor_->GetProperty()->SetLineWidth(2);
|
||||
actor_->GetProperty()->SetOpacity(opacity(position));
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::functionObjectLine::clear()
|
||||
{
|
||||
if (functionObjectBase::clear())
|
||||
{
|
||||
return removeFile("file", fieldName_);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,132 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::functionObjectLine
|
||||
|
||||
Description
|
||||
Visualisation of line data from function object output (file-based only).
|
||||
|
||||
Dictionary controls
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
type | The line type: functionObjectLine | yes |
|
||||
\endtable
|
||||
|
||||
SourceFiles
|
||||
functionObjectLine.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_functionObjectLine_H
|
||||
#define functionObjects_runTimePostPro_functionObjectLine_H
|
||||
|
||||
#include "pathline.H"
|
||||
#include "functionObjectBase.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class functionObjectLine Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class functionObjectLine
|
||||
:
|
||||
public pathline,
|
||||
public functionObjectBase
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- Actor
|
||||
vtkSmartPointer<vtkActor> actor_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- No copy construct
|
||||
functionObjectLine(const functionObjectLine&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const functionObjectLine&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeNameNoDebug("functionObjectLine");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
functionObjectLine
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~functionObjectLine();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Add tube(s) to scene
|
||||
virtual void addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Update actors
|
||||
virtual void updateActors(const scalar position);
|
||||
|
||||
//- Clear files used to create the object(s)
|
||||
virtual bool clear();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,506 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "functionObjectSurface.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkCellData.h"
|
||||
#include "vtkCellDataToPointData.h"
|
||||
#include "vtkCompositeDataGeometryFilter.h"
|
||||
#include "vtkCompositeDataSet.h"
|
||||
#include "vtkCompositePolyDataMapper.h"
|
||||
#include "vtkMultiPieceDataSet.h"
|
||||
#include "vtkPointData.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkProperty.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// VTK Readers
|
||||
#include "vtkPolyDataReader.h"
|
||||
#include "vtkXMLPolyDataReader.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
defineTypeName(functionObjectSurface);
|
||||
addToRunTimeSelectionTable(surface, functionObjectSurface, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
static vtkSmartPointer<vtkPolyData> getPolyDataFile(const Foam::fileName& fName)
|
||||
{
|
||||
// Not extremely elegant...
|
||||
vtkSmartPointer<vtkPolyData> dataset;
|
||||
|
||||
if ("vtk" == fName.ext())
|
||||
{
|
||||
auto reader = vtkSmartPointer<vtkPolyDataReader>::New();
|
||||
|
||||
reader->SetFileName(fName.c_str());
|
||||
reader->Update();
|
||||
dataset = reader->GetOutput();
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
if ("vtp" == fName.ext())
|
||||
{
|
||||
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::functionObjectSurface::
|
||||
functionObjectSurface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
geometrySurface(parent, dict, colours, List<fileName>()),
|
||||
functionObjectBase(parent, dict, colours)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::functionObjectSurface::
|
||||
addGeometry
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (!visible_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DebugInfo
|
||||
<< " Find surface " << functionObjectName_ << endl;
|
||||
|
||||
const polySurface* surf =
|
||||
(
|
||||
geometryBase::parent_.storedObjects()
|
||||
.cfindObject<polySurface>(functionObjectName_)
|
||||
);
|
||||
|
||||
// Treat surface with no faces/points like a missing surface
|
||||
surf = ((surf && surf->nPoints()) ? surf : nullptr);
|
||||
|
||||
bool hasSurface = surf;
|
||||
|
||||
|
||||
// Retrieve the field association (CELL, POINT) for the given field
|
||||
|
||||
unsigned fieldAssociation(0u);
|
||||
if (surf)
|
||||
{
|
||||
unsigned queried = surf->queryFieldAssociation(fieldName_);
|
||||
|
||||
if (queried & polySurface::FACE_DATA)
|
||||
{
|
||||
fieldAssociation |= FieldAssociation::CELL_DATA;
|
||||
}
|
||||
if (queried & polySurface::POINT_DATA)
|
||||
{
|
||||
fieldAssociation |= FieldAssociation::POINT_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
// Reduce the information
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
if (!hasSurface)
|
||||
{
|
||||
// No geometry - set all field association bits ON to ensure
|
||||
// it does not affect bitwise reduction.
|
||||
fieldAssociation = (~0u);
|
||||
}
|
||||
|
||||
reduce(hasSurface, orOp<bool>());
|
||||
reduce(fieldAssociation, bitAndOp<unsigned>());
|
||||
}
|
||||
|
||||
if (!hasSurface)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "No functionObject surface, or has no faces: "
|
||||
<< functionObjectName_
|
||||
<< endl;
|
||||
|
||||
DebugInfo
|
||||
<< " Available surfaces:" << nl
|
||||
<< geometryBase::parent_.storedObjects()
|
||||
.sortedNames<polySurface>() << endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//// Pout<< "local surface = " << (surf ? surf->nFaces() : 0) << nl;
|
||||
|
||||
|
||||
// Create a vtkMultiPieceDataSet with vtkPolyData on the leaves
|
||||
vtkSmartPointer<vtkMultiPieceDataSet> multiPiece;
|
||||
|
||||
// Requesting glyphs on the surface AND only have face data?
|
||||
// - just use the faceCentres directly and attach fields as CellData
|
||||
// (not PointData).
|
||||
|
||||
if
|
||||
(
|
||||
representation_ == rtGlyph
|
||||
&& (fieldAssociation == FieldAssociation::CELL_DATA)
|
||||
)
|
||||
{
|
||||
multiPiece = gatherFaceCentres(surf);
|
||||
}
|
||||
else
|
||||
{
|
||||
multiPiece = gatherSurfacePieces(surf);
|
||||
}
|
||||
|
||||
|
||||
// Add the field (the information is consistent after last reduction).
|
||||
|
||||
// Need field(s) for glyphs or colourByField:
|
||||
|
||||
if (representation_ == rtGlyph || colourBy_ == cbField)
|
||||
{
|
||||
if (fieldAssociation == FieldAssociation::CELL_DATA)
|
||||
{
|
||||
addDimField<polySurfaceGeoMesh>
|
||||
(
|
||||
multiPiece,
|
||||
surf,
|
||||
fieldName_
|
||||
);
|
||||
}
|
||||
else if (fieldAssociation & FieldAssociation::POINT_DATA)
|
||||
{
|
||||
addDimField<polySurfacePointGeoMesh>
|
||||
(
|
||||
multiPiece,
|
||||
surf,
|
||||
fieldName_
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Now have a multi-piece dataset that is one of the following:
|
||||
//
|
||||
// - one-piece per processor (OpenFOAM = parallel, VTK=parallel)
|
||||
// - all pieces on master only (OpenFOAM = parallel, VTK=serial)
|
||||
|
||||
// Re-query field information - we may have stored it differently
|
||||
// than the original source.
|
||||
|
||||
fieldSummary fieldInfo = queryFieldSummary(fieldName_, multiPiece);
|
||||
fieldInfo.reduce();
|
||||
|
||||
DebugInfo
|
||||
<< " Field " << fieldName_ << ' ' << fieldInfo.info() << endl;
|
||||
|
||||
|
||||
// Not rendered on this processor?
|
||||
// This is where we stop, but could also have an MPI barrier
|
||||
if (!renderer)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Rendering
|
||||
|
||||
{
|
||||
auto polyData = vtkSmartPointer<vtkCompositeDataGeometryFilter>::New();
|
||||
|
||||
polyData->SetInputData(multiPiece);
|
||||
polyData->Update();
|
||||
|
||||
if (representation_ == rtGlyph)
|
||||
{
|
||||
addGlyphs
|
||||
(
|
||||
position,
|
||||
fieldName_, fieldInfo, // scaling
|
||||
fieldName_, fieldInfo, // colouring
|
||||
maxGlyphLength_,
|
||||
polyData->GetOutput(),
|
||||
surfaceActor_,
|
||||
renderer
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
vtkSmartPointer<vtkCellDataToPointData> cellToPoint;
|
||||
|
||||
// CellData - Need a cell->point filter
|
||||
if (smooth_ && !fieldInfo.hasPointData())
|
||||
{
|
||||
cellToPoint = vtkSmartPointer<vtkCellDataToPointData>::New();
|
||||
cellToPoint->SetInputData(multiPiece);
|
||||
|
||||
polyData->SetInputConnection(cellToPoint->GetOutputPort());
|
||||
}
|
||||
else
|
||||
{
|
||||
polyData->SetInputData(multiPiece);
|
||||
}
|
||||
polyData->Update();
|
||||
|
||||
|
||||
if (!smooth_)
|
||||
{
|
||||
addFeatureEdges(renderer, polyData);
|
||||
}
|
||||
|
||||
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputConnection(polyData->GetOutputPort());
|
||||
|
||||
setField
|
||||
(
|
||||
position,
|
||||
fieldName_,
|
||||
(
|
||||
smooth_
|
||||
? FieldAssociation::POINT_DATA
|
||||
: FieldAssociation(fieldInfo.association_)
|
||||
),
|
||||
mapper,
|
||||
renderer
|
||||
);
|
||||
|
||||
surfaceActor_->SetMapper(mapper);
|
||||
|
||||
setRepresentation(surfaceActor_);
|
||||
|
||||
renderer->AddActor(surfaceActor_);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::functionObjectSurface::
|
||||
addGeometryFromFile
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (!visible_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkPolyData> polyData;
|
||||
|
||||
bool good = true;
|
||||
|
||||
// File reading is serial (master only)
|
||||
if (Pstream::master())
|
||||
{
|
||||
fileName fName = getFileName("file", fieldName_);
|
||||
|
||||
if (fName.size())
|
||||
{
|
||||
polyData = getPolyDataFile(fName);
|
||||
|
||||
if (!polyData || polyData->GetNumberOfPoints() == 0)
|
||||
{
|
||||
good = false;
|
||||
|
||||
WarningInFunction
|
||||
<< "Could not read "<< fName << nl
|
||||
<< "Only VTK (.vtp, .vtk) files are supported"
|
||||
<< endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugInfo
|
||||
<< " Resolved surface " << fName << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
good = false;
|
||||
|
||||
WarningInFunction
|
||||
<< "Unable to read file name from function object "
|
||||
<< functionObjectName_ << " for field " << fieldName_
|
||||
<< ". Surface will not be processed"
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
reduce(good, andOp<bool>());
|
||||
|
||||
if (!good)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only render on master
|
||||
if (!renderer || !Pstream::master())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
fieldSummary fieldInfo = queryFieldSummary(fieldName_, polyData);
|
||||
// No reduction (serial)
|
||||
|
||||
DebugInfo
|
||||
<< " Field " << fieldName_ << ' ' << fieldInfo.info() << endl;
|
||||
|
||||
|
||||
// Render
|
||||
|
||||
if (representation_ == rtGlyph)
|
||||
{
|
||||
addGlyphs
|
||||
(
|
||||
position,
|
||||
fieldName_, fieldInfo, // scaling
|
||||
fieldName_, fieldInfo, // colouring
|
||||
maxGlyphLength_,
|
||||
polyData,
|
||||
surfaceActor_,
|
||||
renderer
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
addFeatureEdges(renderer, polyData);
|
||||
|
||||
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputData(polyData);
|
||||
|
||||
setField
|
||||
(
|
||||
position,
|
||||
fieldName_,
|
||||
queryFieldAssociation(fieldName_, polyData),
|
||||
mapper,
|
||||
renderer
|
||||
);
|
||||
|
||||
surfaceActor_->SetMapper(mapper);
|
||||
|
||||
setRepresentation(surfaceActor_);
|
||||
|
||||
renderer->AddActor(surfaceActor_);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::functionObjectSurface::
|
||||
addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (!visible_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (liveObject_)
|
||||
{
|
||||
// Live source
|
||||
if (addGeometry(position, renderer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WarningInFunction
|
||||
<< "No functionObject live source, or is empty: "
|
||||
<< functionObjectName_
|
||||
<< " ... attempting with file source"
|
||||
<< endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugInfo
|
||||
<< "Using file source only" << nl;
|
||||
}
|
||||
|
||||
// File source
|
||||
addGeometryFromFile(position, renderer);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::functionObjectSurface::clear()
|
||||
{
|
||||
if (functionObjectBase::clear())
|
||||
{
|
||||
// Even for a "live" data source we allow file cleanup
|
||||
// (eg, from a previous run, etc)
|
||||
return removeFile("file", fieldName_);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,146 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::functionObjectSurface
|
||||
|
||||
Description
|
||||
Visualisation of surface data from function object output,
|
||||
typically the result of a prior sampled surfaces operation.
|
||||
|
||||
Operates in a "live" mode, in which the previously sampled surfaces
|
||||
are retrieved from the functionObject registry.
|
||||
Or in the traditional file-based mode, in which the sampling is used
|
||||
to generate a file and its name is retrieved from the functionObject
|
||||
properties.
|
||||
|
||||
File-based import is restricted to "vtk" and "vtp" formats.
|
||||
|
||||
Dictionary controls
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
type | The type: functionObjectSurface | yes |
|
||||
\endtable
|
||||
|
||||
SourceFiles
|
||||
functionObjectfunctionObjectSurface.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_functionObjectSurface_H
|
||||
#define functionObjects_runTimePostPro_functionObjectSurface_H
|
||||
|
||||
#include "geometrySurface.H"
|
||||
#include "functionObjectBase.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class functionObjectSurface Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class functionObjectSurface
|
||||
:
|
||||
public geometrySurface,
|
||||
public functionObjectBase
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- No copy construct
|
||||
functionObjectSurface(const functionObjectSurface&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const functionObjectSurface&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeNameNoDebug("functionObjectSurface");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
functionObjectSurface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~functionObjectSurface() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Add functionObjectSurface to scene (using simulation source)
|
||||
bool addGeometry
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Add functionObjectSurface to scene (using file source)
|
||||
bool addGeometryFromFile
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Add functionObjectSurface(s) to scene
|
||||
virtual void addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Clear files used to create the object(s)
|
||||
virtual bool clear();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,177 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "geometryBase.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "Constant.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkProperty.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
defineDebugSwitchWithName(geometryBase, "runTimePostPro::geometryBase", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const Foam::Enum
|
||||
<
|
||||
Foam::functionObjects::runTimePostPro::geometryBase::renderModeType
|
||||
>
|
||||
Foam::functionObjects::runTimePostPro::geometryBase::renderModeTypeNames
|
||||
({
|
||||
{ renderModeType::rmFlat, "flat" },
|
||||
{ renderModeType::rmGouraud, "gouraud" },
|
||||
{ renderModeType::rmPhong, "phong" },
|
||||
});
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::geometryBase::initialiseActor
|
||||
(
|
||||
vtkActor* actor
|
||||
) const
|
||||
{
|
||||
actor->GetProperty()->SetSpecular(0);
|
||||
actor->GetProperty()->SetSpecularPower(20);
|
||||
|
||||
switch (renderMode_)
|
||||
{
|
||||
case rmFlat:
|
||||
{
|
||||
actor->GetProperty()->SetInterpolationToFlat();
|
||||
break;
|
||||
}
|
||||
case rmGouraud:
|
||||
{
|
||||
actor->GetProperty()->SetInterpolationToGouraud();
|
||||
break;
|
||||
}
|
||||
case rmPhong:
|
||||
{
|
||||
actor->GetProperty()->SetInterpolationToPhong();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::geometryBase::geometryBase
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
parent_(parent),
|
||||
name_(dict.dictName()),
|
||||
visible_(dict.getOrDefault("visible", true)),
|
||||
parallel_
|
||||
(
|
||||
// User input can only disable parallel here
|
||||
#ifdef FOAM_USING_VTK_MPI
|
||||
Pstream::parRun() && parent.parallel()
|
||||
&& dict.getOrDefault("parallel", parent.parallel())
|
||||
#else
|
||||
false
|
||||
#endif
|
||||
),
|
||||
renderMode_
|
||||
(
|
||||
renderModeTypeNames.getOrDefault("renderMode", dict, rmGouraud)
|
||||
),
|
||||
opacity_(nullptr),
|
||||
colours_(colours)
|
||||
{
|
||||
if (dict.found("opacity"))
|
||||
{
|
||||
opacity_.reset(Function1<scalar>::New("opacity", dict));
|
||||
}
|
||||
else
|
||||
{
|
||||
opacity_.reset(new Function1Types::Constant<scalar>("opacity", 1.0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::geometryBase::~geometryBase()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::functionObjects::runTimePostProcessing&
|
||||
Foam::functionObjects::runTimePostPro::geometryBase::parent() const
|
||||
{
|
||||
return parent_;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::geometryBase::
|
||||
needsCollective() const
|
||||
{
|
||||
return Pstream::parRun() && (!parent_.parallel() || !parallel_);
|
||||
}
|
||||
|
||||
|
||||
const Foam::word&
|
||||
Foam::functionObjects::runTimePostPro::geometryBase::name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::functionObjects::runTimePostPro::geometryBase::opacity
|
||||
(
|
||||
const scalar position
|
||||
) const
|
||||
{
|
||||
return opacity_->value(position);
|
||||
}
|
||||
|
||||
|
||||
const Foam::HashPtrTable<Foam::Function1<Foam::vector>, Foam::word>&
|
||||
Foam::functionObjects::runTimePostPro::geometryBase::colours() const
|
||||
{
|
||||
return colours_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,211 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::geometryBase
|
||||
|
||||
Description
|
||||
Base class for surface, text handling etc.
|
||||
|
||||
Dictionary controls
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
visible | Display the object | no | yes
|
||||
renderMode | Shading (flat/gouraud/phong) | no | gouraud
|
||||
opacity | Object opacity | no | 1.0
|
||||
parallel | Allow parallel rendering | no | true
|
||||
\endtable
|
||||
|
||||
SourceFiles
|
||||
geometryBase.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_geometryBase_H
|
||||
#define functionObjects_runTimePostPro_geometryBase_H
|
||||
|
||||
#include "dictionary.H"
|
||||
#include "vector.H"
|
||||
#include "Function1.H"
|
||||
#include "HashPtrTable.H"
|
||||
#include "Enum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Forward Declarations (VTK)
|
||||
class vtkRenderer;
|
||||
class vtkActor;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
// Forward Declarations
|
||||
class runTimePostProcessing;
|
||||
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class geometryBase Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class geometryBase
|
||||
{
|
||||
public:
|
||||
|
||||
// Public Enumerations
|
||||
|
||||
//- Surface shading types
|
||||
enum renderModeType
|
||||
{
|
||||
rmFlat, //!< Flat shading
|
||||
rmGouraud, //!< Gouraud shading
|
||||
rmPhong //!< Phong shading
|
||||
};
|
||||
|
||||
//- Names for surface shading types
|
||||
static const Enum<renderModeType> renderModeTypeNames;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Reference to the parent function object
|
||||
const runTimePostProcessing& parent_;
|
||||
|
||||
//- The surface name
|
||||
word name_;
|
||||
|
||||
//- Visible flag
|
||||
bool visible_;
|
||||
|
||||
//- Allow parallel rendering
|
||||
bool parallel_;
|
||||
|
||||
//- Render mode
|
||||
renderModeType renderMode_;
|
||||
|
||||
//- Opacity
|
||||
autoPtr<Function1<scalar>> opacity_;
|
||||
|
||||
//- Reference to the colours
|
||||
const HashPtrTable<Function1<vector>>& colours_;
|
||||
|
||||
|
||||
// Protected Functions
|
||||
|
||||
//- Initialise actor
|
||||
void initialiseActor(vtkActor* actor) const;
|
||||
|
||||
//- No copy construct
|
||||
geometryBase(const geometryBase&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const geometryBase&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Debug switch
|
||||
static int debug;
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
geometryBase
|
||||
(
|
||||
const runTimePostProcessing& parent_,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~geometryBase();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return the reference to the parent function object
|
||||
const runTimePostProcessing& parent() const;
|
||||
|
||||
//- May need to gather geometry parts to render on single-processor
|
||||
// True when OpenFOAM is running in parallel but VTK is not.
|
||||
bool needsCollective() const;
|
||||
|
||||
//- Return the name
|
||||
const word& name() const;
|
||||
|
||||
//- Return the visible flag
|
||||
bool visible() const
|
||||
{
|
||||
return visible_;
|
||||
}
|
||||
|
||||
//- Allow parallel rendering
|
||||
bool parallel() const
|
||||
{
|
||||
return parallel_;
|
||||
}
|
||||
|
||||
//- Return the opacity
|
||||
scalar opacity(const scalar position) const;
|
||||
|
||||
//- Return reference to the colours
|
||||
const HashPtrTable<Function1<vector>>& colours() const;
|
||||
|
||||
|
||||
// Scene Interaction
|
||||
|
||||
//- Add geometry to scene
|
||||
virtual void addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
) = 0;
|
||||
|
||||
//- Update the actors
|
||||
virtual void updateActors(const scalar position) = 0;
|
||||
|
||||
//- Clear any files used to create the object(s)
|
||||
virtual bool clear() = 0;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,268 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "geometryCloud.H"
|
||||
#include "cloud.H"
|
||||
#include "fvMesh.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkCompositeDataGeometryFilter.h"
|
||||
#include "vtkCompositeDataSet.h"
|
||||
#include "vtkCompositePolyDataMapper.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkProperty.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
defineTypeName(geometryCloud);
|
||||
addToRunTimeSelectionTable(pointData, geometryCloud, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::geometryCloud::addCloudField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const objectRegistry& obrTmp,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
const regIOobject* ioptr = obrTmp.cfindObject<regIOobject>(fieldName);
|
||||
|
||||
return (multiPiece) &&
|
||||
(
|
||||
addCloudField<label>
|
||||
(
|
||||
multiPiece, ioptr, fieldName
|
||||
)
|
||||
|| addCloudField<scalar>
|
||||
(
|
||||
multiPiece, ioptr, fieldName
|
||||
)
|
||||
|| addCloudField<vector>
|
||||
(
|
||||
multiPiece, ioptr, fieldName
|
||||
)
|
||||
|| addCloudField<sphericalTensor>
|
||||
(
|
||||
multiPiece, ioptr, fieldName
|
||||
)
|
||||
|| addCloudField<symmTensor>
|
||||
(
|
||||
multiPiece, ioptr, fieldName
|
||||
)
|
||||
|| addCloudField<tensor>
|
||||
(
|
||||
multiPiece, ioptr, fieldName
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::geometryCloud::geometryCloud
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
pointData(parent, dict, colours),
|
||||
fieldVisualisationBase(dict, colours),
|
||||
cloudName_(dict.get<word>("cloud")),
|
||||
colourFieldName_(dict.get<word>("colourField")),
|
||||
actor_()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::geometryCloud::
|
||||
~geometryCloud()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::geometryCloud::
|
||||
addGeometry
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (!visible_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// This is similar (almost identical) to vtkCloud
|
||||
|
||||
const auto* objPtr = parent().mesh().cfindObject<cloud>(cloudName_);
|
||||
if (!objPtr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
objectRegistry obrTmp
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"runTimePostPro::cloud::" + cloudName_,
|
||||
parent().mesh().time().constant(),
|
||||
parent().mesh(),
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
objPtr->writeObjects(obrTmp);
|
||||
|
||||
const auto* pointsPtr = cloud::findIOPosition(obrTmp);
|
||||
|
||||
if (!pointsPtr)
|
||||
{
|
||||
// This should be impossible
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Create a vtkMultiPieceDataSet with vtkPolyData on the leaves
|
||||
auto multiPiece = gatherCloud(obrTmp);
|
||||
|
||||
// Add in scaleField and colourField
|
||||
addCloudField(multiPiece, obrTmp, fieldName_);
|
||||
addCloudField(multiPiece, obrTmp, colourFieldName_);
|
||||
|
||||
|
||||
// Not rendered on this processor?
|
||||
// This is where we stop, but could also have an MPI barrier
|
||||
if (!renderer)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
DebugInfo
|
||||
<< " Render cloud " << cloudName_ << endl;
|
||||
|
||||
|
||||
// Rendering
|
||||
|
||||
actor_ = vtkSmartPointer<vtkActor>::New();
|
||||
|
||||
{
|
||||
fieldSummary scaleFieldInfo =
|
||||
queryFieldSummary(fieldName_, multiPiece);
|
||||
|
||||
fieldSummary colourFieldInfo =
|
||||
queryFieldSummary(colourFieldName_, multiPiece);
|
||||
|
||||
auto polyData = vtkSmartPointer<vtkCompositeDataGeometryFilter>::New();
|
||||
|
||||
polyData->SetInputData(multiPiece);
|
||||
polyData->Update();
|
||||
|
||||
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
|
||||
actor_->SetMapper(mapper);
|
||||
|
||||
/// dataset->Print(std::cout);
|
||||
|
||||
addGlyphs
|
||||
(
|
||||
position,
|
||||
fieldName_, scaleFieldInfo, // scaling
|
||||
colourFieldName_, colourFieldInfo, // colour
|
||||
maxGlyphLength_,
|
||||
polyData->GetOutput(),
|
||||
actor_,
|
||||
renderer
|
||||
);
|
||||
|
||||
renderer->AddActor(actor_);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::geometryCloud::
|
||||
addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
// Live source
|
||||
addGeometry(position, renderer);
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::geometryCloud::updateActors
|
||||
(
|
||||
const scalar position
|
||||
)
|
||||
{
|
||||
if (actor_)
|
||||
{
|
||||
const vector colour = pointColour_->value(position);
|
||||
|
||||
vtkProperty* prop = actor_->GetProperty();
|
||||
|
||||
prop->SetOpacity(opacity(position));
|
||||
|
||||
prop->SetColor(colour[0], colour[1], colour[2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::geometryCloud::clear()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,203 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::geometryCloud
|
||||
|
||||
Description
|
||||
Visualisation of cloud data from function object output (file-based only).
|
||||
|
||||
Dictionary controls
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
type | The point type: geometryCloud | yes |
|
||||
cloud | The cloud name | no |
|
||||
field | The field for glyphs scaling | no |
|
||||
colourField | The field to display | no |
|
||||
\endtable
|
||||
|
||||
SourceFiles
|
||||
geometryCloud.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_geometryCloud_H
|
||||
#define functionObjects_runTimePostPro_geometryCloud_H
|
||||
|
||||
#include "pointData.H"
|
||||
#include "functionObjectBase.H"
|
||||
#include "IOField.H"
|
||||
|
||||
#include "vtkSmartPointer.h"
|
||||
#include "vtkMultiPieceDataSet.h"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class geometryCloud Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class geometryCloud
|
||||
:
|
||||
public pointData,
|
||||
public fieldVisualisationBase
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- Name of geometryCloud
|
||||
word cloudName_;
|
||||
|
||||
//- Name of field to colour by
|
||||
word colourFieldName_;
|
||||
|
||||
//- Actor
|
||||
vtkSmartPointer<vtkActor> actor_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Gather and convert cloud positions with vtkPolyData for the leaves.
|
||||
// If VTK is also running in parallel, each cloud is left
|
||||
// as a processor-local piece. Otherwise all processor-local
|
||||
// parts are gathered onto the master in their correponding
|
||||
// slots.
|
||||
vtkSmartPointer<vtkMultiPieceDataSet>
|
||||
gatherCloud(const objectRegistry& obrTmp) const;
|
||||
|
||||
|
||||
//- Add field
|
||||
template<class Type>
|
||||
bool addField
|
||||
(
|
||||
vtkDataSet* piece,
|
||||
const Field<Type>& fld,
|
||||
const word& fieldName
|
||||
) const;
|
||||
|
||||
//- Add field
|
||||
template<class Type>
|
||||
bool addCloudField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const IOField<Type>* fldptr,
|
||||
const word& fieldName
|
||||
) const;
|
||||
|
||||
//- Add field
|
||||
template<class Type>
|
||||
bool addCloudField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const regIOobject* fieldPtr,
|
||||
const word& fieldName
|
||||
) const;
|
||||
|
||||
//- Add field
|
||||
bool addCloudField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const objectRegistry& obrTmp,
|
||||
const word& fieldName
|
||||
) const;
|
||||
|
||||
|
||||
//- No copy construct
|
||||
geometryCloud(const geometryCloud&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const geometryCloud&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeNameNoDebug("geometryCloud");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
geometryCloud
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~geometryCloud();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Add cloud to scene (from simulation)
|
||||
bool addGeometry
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Add cloud to scene
|
||||
virtual void addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Update actors
|
||||
virtual void updateActors(const scalar position);
|
||||
|
||||
//- No-op
|
||||
virtual bool clear();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "geometryCloudTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,131 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "geometryCloud.H"
|
||||
#include "cloud.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
|
||||
#include "foamVtkTools.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkMultiPieceDataSet.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
vtkSmartPointer<vtkMultiPieceDataSet>
|
||||
Foam::functionObjects::runTimePostPro::geometryCloud::gatherCloud
|
||||
(
|
||||
const objectRegistry& obrTmp
|
||||
) const
|
||||
{
|
||||
auto multiPiece = vtkSmartPointer<vtkMultiPieceDataSet>::New();
|
||||
multiPiece->SetNumberOfPieces(Pstream::nProcs());
|
||||
|
||||
const auto* pointsPtr = cloud::findIOPosition(obrTmp);
|
||||
|
||||
if (!needsCollective())
|
||||
{
|
||||
// Simple case (serial-serial, parallel-parallel)
|
||||
|
||||
if (pointsPtr && pointsPtr->size())
|
||||
{
|
||||
multiPiece->SetPiece
|
||||
(
|
||||
Pstream::myProcNo(),
|
||||
Foam::vtk::Tools::Vertices(*pointsPtr)
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (Pstream::master())
|
||||
{
|
||||
// Gather pieces on master
|
||||
|
||||
if (pointsPtr && pointsPtr->size())
|
||||
{
|
||||
// Add myself
|
||||
|
||||
multiPiece->SetPiece
|
||||
(
|
||||
Pstream::myProcNo(),
|
||||
Foam::vtk::Tools::Vertices(*pointsPtr)
|
||||
);
|
||||
}
|
||||
|
||||
// Receive points
|
||||
pointField points;
|
||||
|
||||
for
|
||||
(
|
||||
int slave=Pstream::firstSlave();
|
||||
slave<=Pstream::lastSlave();
|
||||
++slave
|
||||
)
|
||||
{
|
||||
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
|
||||
|
||||
points.clear();
|
||||
|
||||
fromSlave >> points;
|
||||
|
||||
if (points.size())
|
||||
{
|
||||
multiPiece->SetPiece
|
||||
(
|
||||
slave,
|
||||
Foam::vtk::Tools::Vertices(points)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Slave - send points
|
||||
|
||||
OPstream toMaster
|
||||
(
|
||||
Pstream::commsTypes::scheduled,
|
||||
Pstream::masterNo()
|
||||
);
|
||||
|
||||
if (pointsPtr)
|
||||
{
|
||||
toMaster << *pointsPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
toMaster << pointField();
|
||||
}
|
||||
}
|
||||
|
||||
return multiPiece;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,170 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "foamVtkTools.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
bool Foam::functionObjects::runTimePostPro::geometryCloud::addField
|
||||
(
|
||||
vtkDataSet* piece,
|
||||
const Field<Type>& fld,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
if (!piece) return false;
|
||||
|
||||
auto vtkfield = Foam::vtk::Tools::convertFieldToVTK<Type>(fieldName, fld);
|
||||
|
||||
// Only has verts
|
||||
piece->GetPointData()->AddArray(vtkfield);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
bool Foam::functionObjects::runTimePostPro::geometryCloud::addCloudField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const IOField<Type>* fldptr,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
if (!multiPiece)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!needsCollective())
|
||||
{
|
||||
// Simple case (serial-serial, parallel-parallel)
|
||||
|
||||
return fldptr &&
|
||||
addField<Type>
|
||||
(
|
||||
multiPiece->GetPiece(Pstream::myProcNo()),
|
||||
*fldptr,
|
||||
fieldName
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Gather fields
|
||||
const bool ok = returnReduce((fldptr != nullptr), orOp<bool>());
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
if (fldptr)
|
||||
{
|
||||
// My field data
|
||||
addField<Type>
|
||||
(
|
||||
multiPiece->GetPiece(Pstream::myProcNo()),
|
||||
*fldptr,
|
||||
fieldName
|
||||
);
|
||||
}
|
||||
|
||||
// Receive field data
|
||||
Field<Type> recv;
|
||||
|
||||
for
|
||||
(
|
||||
int slave=Pstream::firstSlave();
|
||||
slave<=Pstream::lastSlave();
|
||||
++slave
|
||||
)
|
||||
{
|
||||
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
|
||||
|
||||
recv.clear();
|
||||
|
||||
fromSlave
|
||||
>> recv;
|
||||
|
||||
if (recv.size())
|
||||
{
|
||||
addField<Type>
|
||||
(
|
||||
multiPiece->GetPiece(slave),
|
||||
recv,
|
||||
fieldName
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Slave - send field data
|
||||
|
||||
OPstream toMaster
|
||||
(
|
||||
Pstream::commsTypes::scheduled,
|
||||
Pstream::masterNo()
|
||||
);
|
||||
|
||||
if (fldptr)
|
||||
{
|
||||
toMaster
|
||||
<< *fldptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
toMaster
|
||||
<< List<Type>();
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
bool Foam::functionObjects::runTimePostPro::geometryCloud::addCloudField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const regIOobject* ioptr,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
return addCloudField<Type>
|
||||
(
|
||||
multiPiece,
|
||||
dynamic_cast<const IOField<Type>*>(ioptr),
|
||||
fieldName
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,319 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "geometryPatches.H"
|
||||
#include "fvMesh.H"
|
||||
#include "volFields.H"
|
||||
#include "emptyPolyPatch.H"
|
||||
#include "processorPolyPatch.H"
|
||||
#include "foamVtkTools.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkCellArray.h"
|
||||
#include "vtkCellData.h"
|
||||
#include "vtkCellDataToPointData.h"
|
||||
#include "vtkCompositeDataGeometryFilter.h"
|
||||
#include "vtkCompositeDataSet.h"
|
||||
#include "vtkCompositePolyDataMapper.h"
|
||||
#include "vtkMultiPieceDataSet.h"
|
||||
#include "vtkPointData.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkProperty.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
defineTypeName(geometryPatches);
|
||||
addToRunTimeSelectionTable(surface, geometryPatches, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::geometryPatches::geometryPatches
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
geometrySurface(parent, dict, colours, List<fileName>()),
|
||||
fieldVisualisationBase(dict, colours),
|
||||
selectPatches_(),
|
||||
nearCellValue_(dict.getOrDefault("nearCellValue", false))
|
||||
{
|
||||
dict.readEntry("patches", selectPatches_);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::geometryPatches::addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (!visible_ || selectPatches_.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const polyBoundaryMesh& patches = parent().mesh().boundaryMesh();
|
||||
|
||||
bitSet selectedPatchIds(patches.size());
|
||||
|
||||
for (const polyPatch& pp : patches)
|
||||
{
|
||||
if (isType<emptyPolyPatch>(pp) || pp.empty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (isA<processorPolyPatch>(pp))
|
||||
{
|
||||
break; // No processor patches
|
||||
}
|
||||
|
||||
if (selectPatches_.match(pp.name()))
|
||||
{
|
||||
selectedPatchIds.set(pp.index());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
labelListList patchIds(Pstream::nProcs());
|
||||
patchIds[Pstream::myProcNo()] = selectedPatchIds.sortedToc();
|
||||
|
||||
Pstream::gatherList(patchIds);
|
||||
Pstream::scatterList(patchIds);
|
||||
|
||||
label nPieces = 0;
|
||||
for (const labelList& ids : patchIds)
|
||||
{
|
||||
nPieces += ids.size();
|
||||
}
|
||||
|
||||
/// Pout<< "add patches: " << selectPatches_ << nl
|
||||
/// << " = " << patchIds << " == " << nPieces << " total" << nl;
|
||||
|
||||
if (!nPieces)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "No patches selected: " << flatOutput(selectPatches_)
|
||||
<< endl;
|
||||
return;
|
||||
}
|
||||
|
||||
DebugInfo << " Add geometry patches" << nl;
|
||||
|
||||
|
||||
// Create a vtkMultiPieceDataSet with vtkPolyData on the leaves
|
||||
|
||||
// When adding fields, only map scalar/vector fields.
|
||||
// - this is easier and all we mostly ever need
|
||||
|
||||
vtkSmartPointer<vtkMultiPieceDataSet> multiPiece;
|
||||
|
||||
// Requesting glyphs on the surface - just use the faceCentres directly
|
||||
// and attach fields as CellData (not PointData).
|
||||
|
||||
if (representation_ == rtGlyph)
|
||||
{
|
||||
multiPiece = gatherPatchFaceCentres(patchIds);
|
||||
}
|
||||
else
|
||||
{
|
||||
multiPiece = gatherPatchPieces(patchIds);
|
||||
}
|
||||
|
||||
|
||||
// Add (scalar/vector) field.
|
||||
// - Need field(s) for glyphs or colourByField:
|
||||
|
||||
int nCmpt = 0;
|
||||
if (representation_ == rtGlyph || colourBy_ == cbField)
|
||||
{
|
||||
if (!nCmpt)
|
||||
{
|
||||
nCmpt = addPatchField<scalar>
|
||||
(
|
||||
multiPiece,
|
||||
patchIds,
|
||||
parent().mesh().cfindObject<volScalarField>(fieldName_),
|
||||
fieldName_
|
||||
);
|
||||
}
|
||||
if (!nCmpt)
|
||||
{
|
||||
nCmpt = addPatchField<vector>
|
||||
(
|
||||
multiPiece,
|
||||
patchIds,
|
||||
parent().mesh().cfindObject<volVectorField>(fieldName_),
|
||||
fieldName_
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Now have a multi-piece dataset with
|
||||
// one piece per patch and processor.
|
||||
//
|
||||
// For VTK=parallel, these pieces reside on their original processors.
|
||||
// For VTK=serial, they are master only
|
||||
|
||||
// Re-query actually field information, since we may have stored it
|
||||
// somewhere slightly different than the original source.
|
||||
|
||||
fieldSummary fieldInfo = queryFieldSummary(fieldName_, multiPiece);
|
||||
fieldInfo.reduce();
|
||||
|
||||
DebugInfo
|
||||
<< " Field " << fieldName_ << ' ' << fieldInfo.info() << endl;
|
||||
|
||||
// Not rendering on this processor?
|
||||
// This is where we stop, but could also have a MPI barrier
|
||||
if (!renderer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Rendering
|
||||
|
||||
{
|
||||
auto polyData = vtkSmartPointer<vtkCompositeDataGeometryFilter>::New();
|
||||
|
||||
polyData->SetInputData(multiPiece);
|
||||
polyData->Update();
|
||||
|
||||
if (representation_ == rtGlyph)
|
||||
{
|
||||
addGlyphs
|
||||
(
|
||||
position,
|
||||
fieldName_, fieldInfo, // scaling
|
||||
fieldName_, fieldInfo, // colouring
|
||||
maxGlyphLength_,
|
||||
polyData->GetOutput(),
|
||||
surfaceActor_,
|
||||
renderer
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
vtkSmartPointer<vtkCellDataToPointData> cellToPoint;
|
||||
|
||||
// CellData - Need a cell->point filter
|
||||
if (smooth_ && !fieldInfo.hasPointData())
|
||||
{
|
||||
cellToPoint = vtkSmartPointer<vtkCellDataToPointData>::New();
|
||||
cellToPoint->SetInputData(multiPiece);
|
||||
|
||||
polyData->SetInputConnection(cellToPoint->GetOutputPort());
|
||||
}
|
||||
else
|
||||
{
|
||||
polyData->SetInputData(multiPiece);
|
||||
}
|
||||
polyData->Update();
|
||||
|
||||
|
||||
if (!smooth_)
|
||||
{
|
||||
addFeatureEdges(renderer, polyData);
|
||||
}
|
||||
|
||||
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputConnection(polyData->GetOutputPort());
|
||||
|
||||
setField
|
||||
(
|
||||
position,
|
||||
fieldName_,
|
||||
(
|
||||
smooth_
|
||||
? FieldAssociation::POINT_DATA
|
||||
: FieldAssociation::CELL_DATA
|
||||
),
|
||||
mapper,
|
||||
renderer
|
||||
);
|
||||
|
||||
surfaceActor_->SetMapper(mapper);
|
||||
|
||||
setRepresentation(surfaceActor_);
|
||||
|
||||
renderer->AddActor(surfaceActor_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::geometryPatches::updateActors
|
||||
(
|
||||
const scalar position
|
||||
)
|
||||
{
|
||||
if (!visible_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
surface::updateActors(position);
|
||||
|
||||
surfaceActor_->GetProperty()->SetOpacity(opacity(position));
|
||||
|
||||
vector sc = surfaceColour_->value(position);
|
||||
surfaceActor_->GetProperty()->SetColor(sc[0], sc[1], sc[2]);
|
||||
|
||||
vector ec = edgeColour_->value(position);
|
||||
surfaceActor_->GetProperty()->SetEdgeColor(ec[0], ec[1], ec[2]);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::geometryPatches::clear()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,173 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::geometryPatches
|
||||
|
||||
Description
|
||||
Visualisation of OpenFOAM patches and fields.
|
||||
|
||||
\heading Basic Usage
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
type | The surface type: patches | yes |
|
||||
patches | Patches to display (wordRe list) | yes |
|
||||
\endtable
|
||||
|
||||
SourceFiles
|
||||
geometryPatches.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_geometryPatches_H
|
||||
#define functionObjects_runTimePostPro_geometryPatches_H
|
||||
|
||||
#include "surface.H"
|
||||
#include "geometrySurface.H"
|
||||
#include "fieldVisualisationBase.H"
|
||||
#include "volFieldsFwd.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class geometryPatches Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class geometryPatches
|
||||
:
|
||||
public geometrySurface,
|
||||
public fieldVisualisationBase
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- Requested names of patches to process
|
||||
wordRes selectPatches_;
|
||||
|
||||
//- Use cell value on patches instead of patch value itself
|
||||
bool nearCellValue_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Gather and convert patches to multi-piece dataset with
|
||||
//- vtkPolyData for each patch/processor.
|
||||
// For serial, the pieces are gathered to the master.
|
||||
vtkSmartPointer<vtkMultiPieceDataSet>
|
||||
gatherPatchPieces(const labelListList& patchIds) const;
|
||||
|
||||
//- Gather and convert patch face centres to multi-piece dataset with
|
||||
//- vtkPolyData for each patch/processor.
|
||||
// For serial, the pieces are gathered to the master.
|
||||
vtkSmartPointer<vtkMultiPieceDataSet>
|
||||
gatherPatchFaceCentres(const labelListList& patchIds) const;
|
||||
|
||||
|
||||
// Adding Fields - multi-piece
|
||||
|
||||
//- Add patch values.
|
||||
// For nCells == nPoints (eg, only has face centres) add as PointData.
|
||||
// \return 0 on failure to map and nCmpt (eg, 1=scalar, 3=vector)
|
||||
// on success.
|
||||
template<class Type>
|
||||
int addPatchField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const labelListList& patchIds,
|
||||
const GeometricField<Type, fvPatchField, volMesh>* fldptr,
|
||||
const word& fieldName
|
||||
) const;
|
||||
|
||||
|
||||
//- No copy construct
|
||||
geometryPatches(const geometryPatches&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const geometryPatches&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeNameNoDebug("patches");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
geometryPatches
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~geometryPatches() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Add geometry surface(s) to scene
|
||||
virtual void addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Update actors
|
||||
virtual void updateActors(const scalar position);
|
||||
|
||||
//- Clear files used to create the object(s)
|
||||
virtual bool clear();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "geometryPatchesTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,295 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "geometryPatches.H"
|
||||
#include "fvMesh.H"
|
||||
#include "volFields.H"
|
||||
#include "emptyPolyPatch.H"
|
||||
#include "processorPolyPatch.H"
|
||||
#include "foamVtkTools.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkCellArray.h"
|
||||
#include "vtkCellData.h"
|
||||
#include "vtkCompositeDataSet.h"
|
||||
#include "vtkMultiPieceDataSet.h"
|
||||
#include "vtkPointData.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
vtkSmartPointer<vtkMultiPieceDataSet>
|
||||
Foam::functionObjects::runTimePostPro::geometryPatches::gatherPatchPieces
|
||||
(
|
||||
const labelListList& patchIds
|
||||
) const
|
||||
{
|
||||
const polyBoundaryMesh& patches = parent().mesh().boundaryMesh();
|
||||
|
||||
label nPieces = 0;
|
||||
for (const labelList& ids : patchIds)
|
||||
{
|
||||
nPieces += ids.size();
|
||||
}
|
||||
|
||||
auto multiPiece = vtkSmartPointer<vtkMultiPieceDataSet>::New();
|
||||
multiPiece->SetNumberOfPieces(nPieces);
|
||||
|
||||
label pieceId = 0;
|
||||
|
||||
if (!needsCollective())
|
||||
{
|
||||
// Simple case
|
||||
|
||||
for (int proci=0; proci < Pstream::myProcNo(); ++proci)
|
||||
{
|
||||
pieceId += patchIds[proci].size();
|
||||
}
|
||||
|
||||
for (const label patchId : patchIds[Pstream::myProcNo()])
|
||||
{
|
||||
const polyPatch& pp = patches[patchId];
|
||||
|
||||
multiPiece->SetPiece
|
||||
(
|
||||
pieceId,
|
||||
Foam::vtk::Tools::Patch::mesh(pp)
|
||||
);
|
||||
|
||||
++pieceId;
|
||||
}
|
||||
}
|
||||
else if (Pstream::master())
|
||||
{
|
||||
// Gather pieces on master
|
||||
|
||||
// Add myself
|
||||
for (const label patchId : patchIds[Pstream::myProcNo()])
|
||||
{
|
||||
const polyPatch& pp = patches[patchId];
|
||||
|
||||
multiPiece->SetPiece
|
||||
(
|
||||
pieceId,
|
||||
Foam::vtk::Tools::Patch::mesh(pp)
|
||||
);
|
||||
|
||||
++pieceId;
|
||||
}
|
||||
|
||||
// Receive surfaces
|
||||
pointField points;
|
||||
faceList faces;
|
||||
|
||||
for
|
||||
(
|
||||
int slave=Pstream::firstSlave();
|
||||
slave<=Pstream::lastSlave();
|
||||
++slave
|
||||
)
|
||||
{
|
||||
const label nSlavePatches = patchIds[slave].size();
|
||||
|
||||
if (!nSlavePatches)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
|
||||
|
||||
for (label recvi=0; recvi < nSlavePatches; ++recvi)
|
||||
{
|
||||
points.clear();
|
||||
faces.clear();
|
||||
|
||||
fromSlave
|
||||
>> points >> faces;
|
||||
|
||||
multiPiece->SetPiece
|
||||
(
|
||||
pieceId,
|
||||
Foam::vtk::Tools::Patch::mesh(points, faces)
|
||||
);
|
||||
|
||||
++pieceId;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Slave - send surfaces
|
||||
const labelList& slavePatchIds = patchIds[Pstream::myProcNo()];
|
||||
|
||||
if (slavePatchIds.size())
|
||||
{
|
||||
OPstream toMaster
|
||||
(
|
||||
Pstream::commsTypes::scheduled,
|
||||
Pstream::masterNo()
|
||||
);
|
||||
|
||||
for (const label patchId : patchIds[Pstream::myProcNo()])
|
||||
{
|
||||
const polyPatch& pp = patches[patchId];
|
||||
|
||||
toMaster
|
||||
<< pp.localPoints() << pp.localFaces();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return multiPiece;
|
||||
}
|
||||
|
||||
|
||||
vtkSmartPointer<vtkMultiPieceDataSet>
|
||||
Foam::functionObjects::runTimePostPro::geometryPatches::gatherPatchFaceCentres
|
||||
(
|
||||
const labelListList& patchIds
|
||||
) const
|
||||
{
|
||||
const polyBoundaryMesh& patches = parent().mesh().boundaryMesh();
|
||||
|
||||
label nPieces = 0;
|
||||
for (const labelList& ids : patchIds)
|
||||
{
|
||||
nPieces += ids.size();
|
||||
}
|
||||
|
||||
auto multiPiece = vtkSmartPointer<vtkMultiPieceDataSet>::New();
|
||||
multiPiece->SetNumberOfPieces(nPieces);
|
||||
|
||||
label pieceId = 0;
|
||||
|
||||
if (!needsCollective())
|
||||
{
|
||||
// Simple case
|
||||
|
||||
for (int proci=0; proci < Pstream::myProcNo(); ++proci)
|
||||
{
|
||||
pieceId += patchIds[proci].size();
|
||||
}
|
||||
|
||||
for (const label patchId : patchIds[Pstream::myProcNo()])
|
||||
{
|
||||
const polyPatch& pp = patches[patchId];
|
||||
|
||||
auto geom = vtkSmartPointer<vtkPolyData>::New();
|
||||
|
||||
geom->SetPoints(Foam::vtk::Tools::Patch::faceCentres(pp));
|
||||
geom->SetVerts(Foam::vtk::Tools::identityVertices(pp.size()));
|
||||
|
||||
multiPiece->SetPiece(pieceId, geom);
|
||||
|
||||
++pieceId;
|
||||
}
|
||||
}
|
||||
else if (Pstream::master())
|
||||
{
|
||||
// Gather pieces (face centres) on master
|
||||
|
||||
// Add myself
|
||||
for (const label patchId : patchIds[Pstream::myProcNo()])
|
||||
{
|
||||
const polyPatch& pp = patches[patchId];
|
||||
|
||||
auto geom = vtkSmartPointer<vtkPolyData>::New();
|
||||
|
||||
geom->SetPoints(Foam::vtk::Tools::Patch::faceCentres(pp));
|
||||
geom->SetVerts(Foam::vtk::Tools::identityVertices(pp.size()));
|
||||
|
||||
multiPiece->SetPiece(pieceId, geom);
|
||||
|
||||
++pieceId;
|
||||
}
|
||||
|
||||
// Receive points
|
||||
pointField points;
|
||||
|
||||
for
|
||||
(
|
||||
int slave=Pstream::firstSlave();
|
||||
slave<=Pstream::lastSlave();
|
||||
++slave
|
||||
)
|
||||
{
|
||||
const label nSlavePatches = patchIds[slave].size();
|
||||
|
||||
if (!nSlavePatches)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
|
||||
|
||||
for (label recvi=0; recvi < nSlavePatches; ++recvi)
|
||||
{
|
||||
points.clear();
|
||||
|
||||
fromSlave >> points;
|
||||
|
||||
multiPiece->SetPiece
|
||||
(
|
||||
pieceId,
|
||||
Foam::vtk::Tools::Vertices(points)
|
||||
);
|
||||
|
||||
++pieceId;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Slave - send face centres
|
||||
|
||||
const labelList& slavePatchIds = patchIds[Pstream::myProcNo()];
|
||||
|
||||
if (slavePatchIds.size())
|
||||
{
|
||||
OPstream toMaster
|
||||
(
|
||||
Pstream::commsTypes::scheduled,
|
||||
Pstream::masterNo()
|
||||
);
|
||||
|
||||
for (const label patchId : patchIds[Pstream::myProcNo()])
|
||||
{
|
||||
const polyPatch& pp = patches[patchId];
|
||||
|
||||
toMaster << pp.faceCentres();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return multiPiece;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,223 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "geometryPatches.H"
|
||||
#include "fvMesh.H"
|
||||
#include "volFields.H"
|
||||
#include "foamVtkTools.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkCellData.h"
|
||||
#include "vtkMultiPieceDataSet.h"
|
||||
#include "vtkPointData.h"
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
int Foam::functionObjects::runTimePostPro::geometryPatches::addPatchField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const labelListList& patchIds,
|
||||
const GeometricField<Type, fvPatchField, volMesh>* fldptr,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
if (!multiPiece || !fldptr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const int nCmpt(pTraits<Type>::nComponents);
|
||||
|
||||
const auto& bf = fldptr->boundaryField();
|
||||
|
||||
label pieceId = 0;
|
||||
|
||||
if (!needsCollective())
|
||||
{
|
||||
// Simple case (serial-serial, parallel-parallel)
|
||||
|
||||
for (int proci=0; proci < Pstream::myProcNo(); ++proci)
|
||||
{
|
||||
pieceId += patchIds[proci].size();
|
||||
}
|
||||
|
||||
for (const label patchId : patchIds[Pstream::myProcNo()])
|
||||
{
|
||||
const auto& pf = bf[patchId];
|
||||
|
||||
auto vtkfield =
|
||||
(
|
||||
nearCellValue_
|
||||
? Foam::vtk::Tools::convertFieldToVTK<Type>
|
||||
(
|
||||
fieldName,
|
||||
pf.patchInternalField()()
|
||||
)
|
||||
: Foam::vtk::Tools::convertFieldToVTK<Type>
|
||||
(
|
||||
fieldName,
|
||||
pf
|
||||
)
|
||||
);
|
||||
|
||||
auto piece = multiPiece->GetPiece(pieceId);
|
||||
|
||||
if (piece->GetNumberOfCells() == piece->GetNumberOfPoints())
|
||||
{
|
||||
// Only has verts
|
||||
piece->GetPointData()->AddArray(vtkfield);
|
||||
}
|
||||
else
|
||||
{
|
||||
piece->GetCellData()->AddArray(vtkfield);
|
||||
}
|
||||
|
||||
++pieceId;
|
||||
}
|
||||
}
|
||||
else if (Pstream::master())
|
||||
{
|
||||
// Gather pieces on master
|
||||
|
||||
// Add myself
|
||||
for (const label patchId : patchIds[Pstream::myProcNo()])
|
||||
{
|
||||
const auto& pf = bf[patchId];
|
||||
|
||||
auto vtkfield =
|
||||
(
|
||||
nearCellValue_
|
||||
? Foam::vtk::Tools::convertFieldToVTK<Type>
|
||||
(
|
||||
fieldName,
|
||||
pf.patchInternalField()()
|
||||
)
|
||||
: Foam::vtk::Tools::convertFieldToVTK<Type>
|
||||
(
|
||||
fieldName,
|
||||
pf
|
||||
)
|
||||
);
|
||||
|
||||
auto piece = multiPiece->GetPiece(pieceId);
|
||||
|
||||
if (piece->GetNumberOfCells() == piece->GetNumberOfPoints())
|
||||
{
|
||||
// Only has verts
|
||||
piece->GetPointData()->AddArray(vtkfield);
|
||||
}
|
||||
else
|
||||
{
|
||||
piece->GetCellData()->AddArray(vtkfield);
|
||||
}
|
||||
|
||||
++pieceId;
|
||||
}
|
||||
|
||||
// Receive field
|
||||
Field<Type> recv;
|
||||
|
||||
for
|
||||
(
|
||||
int slave=Pstream::firstSlave();
|
||||
slave<=Pstream::lastSlave();
|
||||
++slave
|
||||
)
|
||||
{
|
||||
const label nSlavePatches = patchIds[slave].size();
|
||||
|
||||
if (!nSlavePatches)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
|
||||
|
||||
for (label recvi=0; recvi < nSlavePatches; ++recvi)
|
||||
{
|
||||
recv.clear();
|
||||
|
||||
fromSlave >> recv;
|
||||
|
||||
auto vtkfield = Foam::vtk::Tools::convertFieldToVTK<Type>
|
||||
(
|
||||
fieldName,
|
||||
recv
|
||||
);
|
||||
|
||||
auto piece = multiPiece->GetPiece(pieceId);
|
||||
|
||||
if (piece->GetNumberOfCells() == piece->GetNumberOfPoints())
|
||||
{
|
||||
// Only has verts
|
||||
piece->GetPointData()->AddArray(vtkfield);
|
||||
}
|
||||
else
|
||||
{
|
||||
piece->GetCellData()->AddArray(vtkfield);
|
||||
}
|
||||
|
||||
++pieceId;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Slave - send fields
|
||||
const labelList& slavePatchIds = patchIds[Pstream::myProcNo()];
|
||||
|
||||
if (slavePatchIds.size())
|
||||
{
|
||||
OPstream toMaster
|
||||
(
|
||||
Pstream::commsTypes::scheduled,
|
||||
Pstream::masterNo()
|
||||
);
|
||||
|
||||
for (const label patchId : patchIds[Pstream::myProcNo()])
|
||||
{
|
||||
const auto& pf = bf[patchId];
|
||||
|
||||
if (nearCellValue_)
|
||||
{
|
||||
toMaster << pf.patchInternalField()();
|
||||
}
|
||||
else
|
||||
{
|
||||
toMaster << pf;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nCmpt;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,271 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "geometrySurface.H"
|
||||
#include "stringOps.H"
|
||||
#include "foamVtkTools.H"
|
||||
#include "MeshedSurfaces.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkCellArray.h"
|
||||
#include "vtkCellData.h"
|
||||
#include "vtkDoubleArray.h"
|
||||
#include "vtkPointData.h"
|
||||
#include "vtkPoints.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkProperty.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// VTK Readers
|
||||
#include "vtkOBJReader.h"
|
||||
#include "vtkSTLReader.h"
|
||||
#include "vtkPolyDataReader.h"
|
||||
#include "vtkXMLPolyDataReader.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
defineTypeNameAndDebug(geometrySurface, 0);
|
||||
addToRunTimeSelectionTable(surface, geometrySurface, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
static vtkSmartPointer<vtkPolyData> getPolyDataFile(const Foam::fileName& fName)
|
||||
{
|
||||
// Not extremely elegant...
|
||||
vtkSmartPointer<vtkPolyData> dataset;
|
||||
|
||||
if ("vtk" == fName.ext())
|
||||
{
|
||||
auto reader = vtkSmartPointer<vtkPolyDataReader>::New();
|
||||
|
||||
reader->SetFileName(fName.c_str());
|
||||
reader->Update();
|
||||
dataset = reader->GetOutput();
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
if ("vtp" == fName.ext())
|
||||
{
|
||||
auto reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
|
||||
|
||||
reader->SetFileName(fName.c_str());
|
||||
reader->Update();
|
||||
dataset = reader->GetOutput();
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
if ("obj" == fName.ext())
|
||||
{
|
||||
auto reader = vtkSmartPointer<vtkOBJReader>::New();
|
||||
|
||||
reader->SetFileName(fName.c_str());
|
||||
reader->Update();
|
||||
dataset = reader->GetOutput();
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
if ("stl" == fName.ext() || "stlb" == fName.ext())
|
||||
{
|
||||
auto reader = vtkSmartPointer<vtkSTLReader>::New();
|
||||
|
||||
reader->SetFileName(fName.c_str());
|
||||
reader->Update();
|
||||
dataset = reader->GetOutput();
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
|
||||
// Fallback to using OpenFOAM to read the surface and convert afterwards
|
||||
Foam::meshedSurface surf(fName);
|
||||
|
||||
dataset = Foam::vtk::Tools::Patch::mesh(surf);
|
||||
|
||||
dataset->GetCellData()->SetNormals
|
||||
(
|
||||
Foam::vtk::Tools::Patch::faceNormals(surf)
|
||||
);
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
} // End anonymous namespace
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::geometrySurface::addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer,
|
||||
const fileName& fName
|
||||
) const
|
||||
{
|
||||
// Master-only, since that is where the files are.
|
||||
if (!visible_ || !renderer || !Pstream::master())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (representation_ == rtGlyph)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Glyph representation not available for " << typeName
|
||||
<< " object" << exit(FatalError);
|
||||
}
|
||||
|
||||
DebugInfo << " Add geometry surface: " << fName << nl;
|
||||
|
||||
auto surf = getPolyDataFile(fName);
|
||||
|
||||
if (!surf || !surf->GetNumberOfPoints())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Could not read "<< fName << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
|
||||
mapper->ScalarVisibilityOff();
|
||||
|
||||
mapper->SetInputData(surf);
|
||||
|
||||
addFeatureEdges(renderer, surf);
|
||||
|
||||
surfaceActor_->SetMapper(mapper);
|
||||
|
||||
setRepresentation(surfaceActor_);
|
||||
|
||||
renderer->AddActor(surfaceActor_);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::geometrySurface::geometrySurface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
surface(parent, dict, colours),
|
||||
fileNames_()
|
||||
{
|
||||
dict.readEntry("files", fileNames_);
|
||||
}
|
||||
|
||||
|
||||
Foam::functionObjects::runTimePostPro::geometrySurface::geometrySurface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours,
|
||||
const List<fileName>& fileNames
|
||||
)
|
||||
:
|
||||
surface(parent, dict, colours),
|
||||
fileNames_(fileNames)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::geometrySurface::addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (!visible_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (fileName f : fileNames_) // Use a copy
|
||||
{
|
||||
f.expand();
|
||||
addGeometryToScene(position, renderer, f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::geometrySurface::updateActors
|
||||
(
|
||||
const scalar position
|
||||
)
|
||||
{
|
||||
if (!visible_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
surface::updateActors(position);
|
||||
|
||||
surfaceActor_->GetProperty()->SetOpacity(opacity(position));
|
||||
|
||||
vector sc = surfaceColour_->value(position);
|
||||
surfaceActor_->GetProperty()->SetColor(sc[0], sc[1], sc[2]);
|
||||
|
||||
vector ec = edgeColour_->value(position);
|
||||
surfaceActor_->GetProperty()->SetEdgeColor(ec[0], ec[1], ec[2]);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::geometrySurface::clear()
|
||||
{
|
||||
// Note: do not remove geometry files
|
||||
// - often static files used for other purposes as well (eg meshing)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,155 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::geometrySurface
|
||||
|
||||
Description
|
||||
Read and visualize surface geometry files.
|
||||
|
||||
Dictionary controls
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
type | The type: geometry | yes |
|
||||
files | The files to read | yes |
|
||||
\endtable
|
||||
|
||||
Standard file types (vtk, vtp, obj, stl, stlb) are read with the
|
||||
VTK-native readers. Other file types use the OpenFOAM surfMesh
|
||||
readers and convert to VTK.
|
||||
|
||||
SourceFiles
|
||||
geometrySurface.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_geometrySurface_H
|
||||
#define functionObjects_runTimePostPro_geometrySurface_H
|
||||
|
||||
#include "surface.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Forward Declarations
|
||||
class vtkPolyData;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class geometrySurface Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class geometrySurface
|
||||
:
|
||||
public surface
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- File names
|
||||
List<fileName> fileNames_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Add surface (file) to scene
|
||||
void addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer,
|
||||
const fileName& fName
|
||||
) const;
|
||||
|
||||
//- No copy construct
|
||||
geometrySurface(const geometrySurface&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const geometrySurface&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeName("geometry");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
geometrySurface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
);
|
||||
|
||||
//- Construct from components
|
||||
geometrySurface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours,
|
||||
const List<fileName>& fileNames
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~geometrySurface() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Add geometry surface(s) to scene
|
||||
virtual void addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Update actors
|
||||
virtual void updateActors(const scalar position);
|
||||
|
||||
//- Clear files used to create the object(s) - no-op
|
||||
virtual bool clear();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,204 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
defineTypeName(pathline);
|
||||
defineRunTimeSelectionTable(pathline, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const Foam::Enum
|
||||
<
|
||||
Foam::functionObjects::runTimePostPro::pathline::representationType
|
||||
>
|
||||
Foam::functionObjects::runTimePostPro::pathline::representationTypeNames
|
||||
({
|
||||
{ representationType::rtNone, "none" },
|
||||
{ representationType::rtLine, "line" },
|
||||
{ representationType::rtTube, "tube" },
|
||||
{ representationType::rtVector, "vector" },
|
||||
});
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::pathline::addLines
|
||||
(
|
||||
const label framei,
|
||||
vtkActor* actor,
|
||||
vtkPolyData* data
|
||||
) const
|
||||
{
|
||||
geometryBase::initialiseActor(actor);
|
||||
|
||||
vector colour = lineColour_->value(framei);
|
||||
actor->GetProperty()->SetColor(colour[0], colour[1], colour[2]);
|
||||
|
||||
vtkPolyDataMapper* mapper =
|
||||
vtkPolyDataMapper::SafeDownCast(actor->GetMapper());
|
||||
|
||||
switch (representation_)
|
||||
{
|
||||
case rtNone:
|
||||
{
|
||||
actor->VisibilityOff();
|
||||
break;
|
||||
}
|
||||
case rtLine:
|
||||
{
|
||||
mapper->SetInputData(data);
|
||||
mapper->Update();
|
||||
break;
|
||||
}
|
||||
case rtTube:
|
||||
{
|
||||
auto tubes = vtkSmartPointer<vtkTubeFilter>::New();
|
||||
tubes->SetInputData(data);
|
||||
tubes->SetRadius(tubeRadius_);
|
||||
tubes->SetNumberOfSides(20);
|
||||
tubes->CappingOn();
|
||||
tubes->Update();
|
||||
|
||||
mapper->SetInputConnection(tubes->GetOutputPort());
|
||||
mapper->Update();
|
||||
break;
|
||||
}
|
||||
case rtVector:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::pathline::pathline
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
geometryBase(parent, dict, colours),
|
||||
representation_
|
||||
(
|
||||
representationTypeNames.get("representation", dict)
|
||||
),
|
||||
tubeRadius_(0.001),
|
||||
lineColour_(nullptr)
|
||||
{
|
||||
if (dict.found("lineColour"))
|
||||
{
|
||||
lineColour_.reset(Function1<vector>::New("lineColour", dict));
|
||||
}
|
||||
else
|
||||
{
|
||||
lineColour_.reset(colours["line"]->clone().ptr());
|
||||
}
|
||||
|
||||
switch (representation_)
|
||||
{
|
||||
case rtNone:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case rtLine:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case rtTube:
|
||||
{
|
||||
dict.readEntry("tubeRadius", tubeRadius_);
|
||||
break;
|
||||
}
|
||||
case rtVector:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::autoPtr<Foam::functionObjects::runTimePostPro::pathline>
|
||||
Foam::functionObjects::runTimePostPro::pathline::New
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours,
|
||||
const word& pathlineType
|
||||
)
|
||||
{
|
||||
DebugInfo << "Selecting pathline " << pathlineType << endl;
|
||||
|
||||
auto cstrIter = dictionaryConstructorTablePtr_->cfind(pathlineType);
|
||||
|
||||
if (!cstrIter.found())
|
||||
{
|
||||
FatalIOErrorInLookup
|
||||
(
|
||||
dict,
|
||||
"pathline",
|
||||
pathlineType,
|
||||
*dictionaryConstructorTablePtr_
|
||||
) << exit(FatalIOError);
|
||||
}
|
||||
|
||||
return autoPtr<pathline>(cstrIter()(parent, dict, colours));
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::pathline::~pathline()
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,182 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::pathline
|
||||
|
||||
Description
|
||||
Visualisation of line data (eg, streamlines)
|
||||
|
||||
Dictionary controls
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
representation| none/line/tube/vector | yes |
|
||||
lineColour | Override line colour | no |
|
||||
tubeRadius | Radius for tube representation | yes |
|
||||
\endtable
|
||||
|
||||
SourceFiles
|
||||
pathline.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_pathline_H
|
||||
#define functionObjects_runTimePostPro_pathline_H
|
||||
|
||||
#include "geometryBase.H"
|
||||
#include "Enum.H"
|
||||
#include "runTimeSelectionTables.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Forward declarations
|
||||
class vtkActor;
|
||||
class vtkPolyData;
|
||||
class vtkPolyDataMapper;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class pathline Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class pathline
|
||||
:
|
||||
public geometryBase
|
||||
{
|
||||
public:
|
||||
|
||||
// Public Enumerations
|
||||
|
||||
//- Line representations
|
||||
enum representationType
|
||||
{
|
||||
rtNone, //!< "none"
|
||||
rtLine, //!< "line"
|
||||
rtTube, //!< "tube"
|
||||
rtVector //!< "vector"
|
||||
};
|
||||
|
||||
//- Names for line representations
|
||||
static const Enum<representationType> representationTypeNames;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Representation type
|
||||
representationType representation_;
|
||||
|
||||
//- Radius for the tube filter
|
||||
scalar tubeRadius_;
|
||||
|
||||
//- Line colour
|
||||
autoPtr<Function1<vector>> lineColour_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Add the pathlines to the renderer
|
||||
void addLines
|
||||
(
|
||||
const label framei,
|
||||
vtkActor* actor,
|
||||
vtkPolyData* data
|
||||
) const;
|
||||
|
||||
//- No copy construct
|
||||
pathline(const pathline&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const pathline&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeNameNoDebug("pathline");
|
||||
|
||||
|
||||
// Declare run-time constructor selection table
|
||||
|
||||
declareRunTimeSelectionTable
|
||||
(
|
||||
autoPtr,
|
||||
pathline,
|
||||
dictionary,
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
),
|
||||
(parent, dict, colours)
|
||||
);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
pathline
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
);
|
||||
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Return selected pathline
|
||||
static autoPtr<pathline> New
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours,
|
||||
const word& pathlineName
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~pathline();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,167 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "pointData.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkProperty.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
defineTypeName(pointData);
|
||||
defineRunTimeSelectionTable(pointData, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const Foam::Enum
|
||||
<
|
||||
Foam::functionObjects::runTimePostPro::pointData::representationType
|
||||
>
|
||||
Foam::functionObjects::runTimePostPro::pointData::representationTypeNames
|
||||
({
|
||||
{ representationType::rtSphere, "sphere" },
|
||||
{ representationType::rtVector, "vector" },
|
||||
});
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::pointData::addPoints
|
||||
(
|
||||
const label framei,
|
||||
vtkActor* actor,
|
||||
vtkPolyDataMapper* mapper,
|
||||
vtkPolyData* data
|
||||
) const
|
||||
{
|
||||
geometryBase::initialiseActor(actor);
|
||||
|
||||
vector colour = pointColour_->value(framei);
|
||||
actor->GetProperty()->SetColor(colour[0], colour[1], colour[2]);
|
||||
|
||||
switch (representation_)
|
||||
{
|
||||
case rtSphere:
|
||||
case rtVector:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::pointData::pointData
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
geometryBase(parent, dict, colours),
|
||||
representation_
|
||||
(
|
||||
representationTypeNames.get("representation", dict)
|
||||
),
|
||||
maxGlyphLength_(dict.get<scalar>("maxGlyphLength")),
|
||||
pointColour_(nullptr)
|
||||
{
|
||||
if (dict.found("pointColour"))
|
||||
{
|
||||
pointColour_.reset(Function1<vector>::New("pointColour", dict));
|
||||
}
|
||||
else
|
||||
{
|
||||
pointColour_.reset(colours["point"]->clone().ptr());
|
||||
}
|
||||
|
||||
switch (representation_)
|
||||
{
|
||||
case rtSphere:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case rtVector:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::autoPtr<Foam::functionObjects::runTimePostPro::pointData>
|
||||
Foam::functionObjects::runTimePostPro::pointData::New
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours,
|
||||
const word& pointDataType
|
||||
)
|
||||
{
|
||||
DebugInfo << "Selecting pointData " << pointDataType << endl;
|
||||
|
||||
auto cstrIter = dictionaryConstructorTablePtr_->cfind(pointDataType);
|
||||
|
||||
if (!cstrIter.found())
|
||||
{
|
||||
FatalIOErrorInLookup
|
||||
(
|
||||
dict,
|
||||
"pointData",
|
||||
pointDataType,
|
||||
*dictionaryConstructorTablePtr_
|
||||
) << exit(FatalIOError);
|
||||
}
|
||||
|
||||
return autoPtr<pointData>(cstrIter()(parent, dict, colours));
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::pointData::~pointData()
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,181 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::pointData
|
||||
|
||||
Description
|
||||
Visualisation of point data
|
||||
|
||||
Dictionary controls
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
representation| sphere/vector | yes |
|
||||
pointColour | Override point colour | no |
|
||||
maxGlyphLength | Limit for glyph representation | yes |
|
||||
\endtable
|
||||
|
||||
SourceFiles
|
||||
pointData.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_pointData_H
|
||||
#define functionObjects_runTimePostPro_pointData_H
|
||||
|
||||
#include "geometryBase.H"
|
||||
#include "Enum.H"
|
||||
#include "runTimeSelectionTables.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Forward Declarations
|
||||
class vtkActor;
|
||||
class vtkPolyData;
|
||||
class vtkPolyDataMapper;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class pointData Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class pointData
|
||||
:
|
||||
public geometryBase
|
||||
{
|
||||
public:
|
||||
|
||||
// Public Enumerations
|
||||
|
||||
//- Point representation types
|
||||
enum representationType
|
||||
{
|
||||
rtSphere, //!< "sphere"
|
||||
rtVector //!< "vector"
|
||||
};
|
||||
|
||||
//- Names for point representation types
|
||||
static const Enum<representationType> representationTypeNames;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- Representation type
|
||||
representationType representation_;
|
||||
|
||||
//- Max glyph length
|
||||
scalar maxGlyphLength_;
|
||||
|
||||
//- Point colour
|
||||
autoPtr<Function1<vector>> pointColour_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Add the point data to the renderer
|
||||
void addPoints
|
||||
(
|
||||
const label framei,
|
||||
vtkActor* actor,
|
||||
vtkPolyDataMapper* mapper,
|
||||
vtkPolyData* data
|
||||
) const;
|
||||
|
||||
//- No copy construct
|
||||
pointData(const pointData&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const pointData&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeNameNoDebug("pointData");
|
||||
|
||||
|
||||
// Declare run-time constructor selection table
|
||||
|
||||
declareRunTimeSelectionTable
|
||||
(
|
||||
autoPtr,
|
||||
pointData,
|
||||
dictionary,
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
),
|
||||
(parent, dict, colours)
|
||||
);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
pointData
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
);
|
||||
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Return selected pointData
|
||||
static autoPtr<pointData> New
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours,
|
||||
const word& pointDataName
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~pointData();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,382 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "runTimePostProcessing.H"
|
||||
#include "dictionary.H"
|
||||
#include "pointData.H"
|
||||
#include "pathline.H"
|
||||
#include "surface.H"
|
||||
#include "text.H"
|
||||
#include "Time.H"
|
||||
#include "sigFpe.H"
|
||||
#include "polySurfaceFields.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkRenderWindow.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
#include "vtkLight.h"
|
||||
|
||||
#include "vtkDummyController.h"
|
||||
|
||||
#ifdef FOAM_USING_VTK_MPI
|
||||
# include "vtkMPICommunicator.h"
|
||||
# include "vtkMPIController.h"
|
||||
# include "vtkCompositedSynchronizedRenderers.h"
|
||||
# include "vtkSynchronizedRenderWindows.h"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(runTimePostProcessing, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
runTimePostProcessing,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
template<class Type>
|
||||
static void addGeometryToScene
|
||||
(
|
||||
PtrList<Type>& objects,
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
for (Type& obj : objects)
|
||||
{
|
||||
if (Pstream::master() || obj.parallel())
|
||||
{
|
||||
obj.addGeometryToScene(position, renderer);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj.addGeometryToScene(position, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
static void updateActors(PtrList<Type>& objects, const scalar position)
|
||||
{
|
||||
for (Type& obj : objects)
|
||||
{
|
||||
obj.updateActors(position);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
static void cleanup(PtrList<Type>& objects)
|
||||
{
|
||||
for (Type& obj : objects)
|
||||
{
|
||||
obj.clear();
|
||||
}
|
||||
}
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::runTimePostProcessing::render
|
||||
(
|
||||
vtkMultiProcessController* controller
|
||||
)
|
||||
{
|
||||
// Some feedback
|
||||
if (controller)
|
||||
{
|
||||
Log << name() << " render (" << controller->GetNumberOfProcesses()
|
||||
<< " processes)" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log << name() << " render" << endl;
|
||||
}
|
||||
|
||||
// Disable any floating point trapping
|
||||
// (some low-level rendering functionality does not like it)
|
||||
|
||||
sigFpe::ignore sigFpeHandling; //<- disable in local scope
|
||||
|
||||
|
||||
// Normal rendering elements
|
||||
vtkSmartPointer<vtkRenderer> renderer;
|
||||
vtkSmartPointer<vtkRenderWindow> renderWindow;
|
||||
|
||||
// Initialise render window
|
||||
if (controller || Pstream::master())
|
||||
{
|
||||
renderer = vtkSmartPointer<vtkRenderer>::New();
|
||||
renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
|
||||
|
||||
renderWindow->OffScreenRenderingOn();
|
||||
renderWindow->SetSize(output_.width_, output_.height_);
|
||||
|
||||
// Legacy rendering - was deprecated for 8.1.0
|
||||
#if (VTK_MAJOR_VERSION < 8) || \
|
||||
((VTK_MAJOR_VERSION == 8) && (VTK_MINOR_VERSION < 2))
|
||||
renderWindow->SetAAFrames(10);
|
||||
#endif
|
||||
renderWindow->SetAlphaBitPlanes(true);
|
||||
renderWindow->SetMultiSamples(0);
|
||||
// renderWindow->PolygonSmoothingOn();
|
||||
|
||||
renderWindow->AddRenderer(renderer);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------
|
||||
#ifdef FOAM_USING_VTK_MPI
|
||||
|
||||
// Multi-process synchronization
|
||||
vtkSmartPointer<vtkCompositedSynchronizedRenderers> syncRenderers;
|
||||
vtkSmartPointer<vtkSynchronizedRenderWindows> syncWindows;
|
||||
|
||||
if (controller)
|
||||
{
|
||||
syncRenderers =
|
||||
vtkSmartPointer<vtkCompositedSynchronizedRenderers>::New();
|
||||
|
||||
syncWindows =
|
||||
vtkSmartPointer<vtkSynchronizedRenderWindows>::New();
|
||||
|
||||
syncWindows->SetRenderWindow(renderWindow);
|
||||
syncWindows->SetParallelController(controller);
|
||||
syncWindows->SetIdentifier(1);
|
||||
|
||||
// false = Call Render() manually on each process - don't use RMI
|
||||
syncWindows->SetParallelRendering(true);
|
||||
|
||||
syncRenderers->SetRenderer(renderer);
|
||||
syncRenderers->SetParallelController(controller);
|
||||
}
|
||||
#endif
|
||||
// ---------------------
|
||||
|
||||
scene_.initialise(renderer, output_.name_);
|
||||
|
||||
addGeometryToScene(points_, 0, renderer);
|
||||
addGeometryToScene(lines_, 0, renderer);
|
||||
addGeometryToScene(surfaces_, 0, renderer);
|
||||
addGeometryToScene(text_, 0, renderer);
|
||||
|
||||
while (scene_.loop(renderer))
|
||||
{
|
||||
const scalar position = scene_.position();
|
||||
|
||||
updateActors(text_, position);
|
||||
updateActors(points_, position);
|
||||
updateActors(lines_, position);
|
||||
updateActors(surfaces_, position);
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
cleanup(text_);
|
||||
cleanup(points_);
|
||||
cleanup(lines_);
|
||||
cleanup(surfaces_);
|
||||
|
||||
|
||||
// Instead of relying on the destructor, manually restore the previous
|
||||
// SIGFPE state.
|
||||
// This is only to avoid compiler complaints about unused variables.
|
||||
|
||||
sigFpeHandling.restore();
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostProcessing::render
|
||||
(
|
||||
vtkMultiProcessController* controller,
|
||||
void* processData
|
||||
)
|
||||
{
|
||||
reinterpret_cast<runTimePostProcessing*>(processData)->render(controller);
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostProcessing::render()
|
||||
{
|
||||
#ifdef FOAM_USING_VTK_MPI
|
||||
if (parallel_)
|
||||
{
|
||||
// Create vtkMPIController if MPI is configured,
|
||||
// vtkThreadedController otherwise.
|
||||
auto ctrl = vtkSmartPointer<vtkMPIController>::New();
|
||||
ctrl->Initialize(nullptr, nullptr, 1);
|
||||
|
||||
ctrl->SetSingleMethod(runTimePostProcessing::render, this);
|
||||
ctrl->SingleMethodExecute();
|
||||
|
||||
ctrl->Finalize(1);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
// Normally we would have a fallback controller like this:
|
||||
|
||||
// if (Pstream::master())
|
||||
// {
|
||||
// auto ctrl = vtkSmartPointer<vtkDummyController>::New();
|
||||
// ctrl->Initialize(nullptr, nullptr, 1);
|
||||
//
|
||||
// ctrl->SetSingleMethod(runTimePostProcessing::render, this);
|
||||
// ctrl->SingleMethodExecute();
|
||||
//
|
||||
// ctrl->Finalize(1);
|
||||
// }
|
||||
|
||||
// However, this would prevent us from doing any of our own MPI
|
||||
// since this would only be spawned the master.
|
||||
|
||||
// Instead pass in nullptr for the controller and handling
|
||||
// logic internally.
|
||||
|
||||
vtkDummyController* dummy = nullptr;
|
||||
render(dummy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostProcessing::runTimePostProcessing
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fvMeshFunctionObject(name, runTime, dict),
|
||||
output_(),
|
||||
parallel_(false),
|
||||
scene_(runTime, name),
|
||||
points_(),
|
||||
lines_(),
|
||||
surfaces_(),
|
||||
text_()
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimePostProcessing::read(const dictionary& dict)
|
||||
{
|
||||
fvMeshFunctionObject::read(dict);
|
||||
|
||||
#ifdef FOAM_USING_VTK_MPI
|
||||
parallel_ = (Pstream::parRun() && dict.getOrDefault("parallel", true));
|
||||
#else
|
||||
parallel_ = false;
|
||||
#endif
|
||||
|
||||
Info<< type() << " " << name() << ": reading post-processing data ("
|
||||
<< (parallel_ ? "parallel" : "serial") << " rendering)" << endl;
|
||||
|
||||
if (dict.getOrDefault("debug", false))
|
||||
{
|
||||
runTimePostPro::geometryBase::debug = 1;
|
||||
Info<< " debugging on" << endl;
|
||||
}
|
||||
|
||||
scene_.read(dict);
|
||||
|
||||
const dictionary& outputDict = dict.subDict("output");
|
||||
outputDict.readEntry("name", output_.name_);
|
||||
outputDict.readEntry("width", output_.width_);
|
||||
outputDict.readEntry("height", output_.height_);
|
||||
|
||||
readObjects(dict.subOrEmptyDict("points"), points_);
|
||||
readObjects(dict.subOrEmptyDict("lines"), lines_);
|
||||
readObjects(dict.subOrEmptyDict("surfaces"), surfaces_);
|
||||
|
||||
const dictionary& textDict = dict.subDict("text");
|
||||
|
||||
for (const entry& dEntry : textDict)
|
||||
{
|
||||
if (!dEntry.isDict())
|
||||
{
|
||||
FatalIOErrorInFunction(textDict)
|
||||
<< textDict.dictName()
|
||||
<< "text must be specified in dictionary format"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
const dictionary& objectDict = dEntry.dict();
|
||||
|
||||
text_.append
|
||||
(
|
||||
new runTimePostPro::text
|
||||
(
|
||||
*this,
|
||||
objectDict,
|
||||
scene_.colours()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostProcessing::execute()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostProcessing::write()
|
||||
{
|
||||
render();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,272 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Namespace
|
||||
Foam::functionObjects::runTimePostPro
|
||||
|
||||
Description
|
||||
Classes and objects used in the implementation of
|
||||
Foam::functionObjects::runTimePostProcessing
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostProcessing
|
||||
|
||||
Group
|
||||
grpGraphicsFunctionObjects
|
||||
|
||||
Description
|
||||
Generate images during run-time.
|
||||
|
||||
The functionality makes use of the VTK libraries (see http://www.vtk.org)
|
||||
which provide a broad set of functionality for scene composition and
|
||||
manipulation.
|
||||
|
||||
Images are generated using a combination of function object output
|
||||
and additional data - eg, surfaces and text.
|
||||
Current capabilities include support for:
|
||||
- Camera
|
||||
- Objects
|
||||
- Points
|
||||
- Lines
|
||||
- Surfaces
|
||||
- Scalar bars
|
||||
- Annotations
|
||||
- Selection of colour maps
|
||||
.
|
||||
|
||||
Mandatory entries:
|
||||
\verbatim
|
||||
output
|
||||
{
|
||||
name image;
|
||||
width 800;
|
||||
height 600;
|
||||
}
|
||||
|
||||
camera
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
colours
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
text
|
||||
{
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Optional entries:
|
||||
\verbatim
|
||||
points
|
||||
{
|
||||
}
|
||||
|
||||
lines
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
surfaces
|
||||
{
|
||||
...
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Dictionary controls
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
type | Type-name: runTimePostProcessing | yes |
|
||||
debug | Additional debug information | no | false
|
||||
parallel | Allow parallel rendering | no | true
|
||||
\endtable
|
||||
|
||||
SourceFiles
|
||||
runTimePostProcessing.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostProcessing_H
|
||||
#define functionObjects_runTimePostProcessing_H
|
||||
|
||||
#include "fvMeshFunctionObject.H"
|
||||
#include "objectRegistry.H"
|
||||
#include "mapPolyMesh.H"
|
||||
#include "PtrList.H"
|
||||
#include "scene.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Forward Declarations
|
||||
class vtkMultiPieceDataSet;
|
||||
class vtkMultiProcessController;
|
||||
class vtkRenderWindow;
|
||||
class vtkRenderer;
|
||||
template<class T> class vtkSmartPointer;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
// Forward declarations
|
||||
class runTimePostProcessing;
|
||||
|
||||
namespace runTimePostPro
|
||||
{
|
||||
// Forward declarations
|
||||
class pointData;
|
||||
class pathline;
|
||||
class surface;
|
||||
class text;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class runTimePostProcessing Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class runTimePostProcessing
|
||||
:
|
||||
public fvMeshFunctionObject
|
||||
{
|
||||
// Private Data
|
||||
|
||||
//- Output information
|
||||
struct outputType
|
||||
{
|
||||
word name_;
|
||||
label width_;
|
||||
label height_;
|
||||
};
|
||||
|
||||
//- Output instance
|
||||
outputType output_;
|
||||
|
||||
//- Allow parallel rendering
|
||||
bool parallel_;
|
||||
|
||||
//- Scene manager
|
||||
runTimePostPro::scene scene_;
|
||||
|
||||
//- List of points
|
||||
PtrList<runTimePostPro::pointData> points_;
|
||||
|
||||
//- List of lines
|
||||
PtrList<runTimePostPro::pathline> lines_;
|
||||
|
||||
//- List of surfaces
|
||||
PtrList<runTimePostPro::surface> surfaces_;
|
||||
|
||||
//- List of text
|
||||
PtrList<runTimePostPro::text> text_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Helper function to read scene objects
|
||||
template<class Type>
|
||||
void readObjects(const dictionary& dict, PtrList<Type>& objects) const;
|
||||
|
||||
//- Construct controller and dispatch to render
|
||||
void render();
|
||||
|
||||
//- Static function for SetSingleMethod binding
|
||||
static void render(vtkMultiProcessController* ctrl, void* data);
|
||||
|
||||
//- Render scene using given controller
|
||||
void render(vtkMultiProcessController* ctrl);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("runTimePostProcessing");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
runTimePostProcessing
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~runTimePostProcessing() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Allow parallel rendering
|
||||
bool parallel() const
|
||||
{
|
||||
return parallel_;
|
||||
}
|
||||
|
||||
//- May need to gather parts to render on single-processor
|
||||
// True when OpenFOAM is running in parallel but VTK is not.
|
||||
bool needsCollective() const
|
||||
{
|
||||
return Pstream::parRun() && !parallel_;
|
||||
}
|
||||
|
||||
//- Reference to the underlying OpenFOAM mesh
|
||||
const fvMesh& mesh() const
|
||||
{
|
||||
return mesh_;
|
||||
}
|
||||
|
||||
|
||||
//- Read the post-processing controls
|
||||
virtual bool read(const dictionary& dict);
|
||||
|
||||
//- Execute, currently does nothing
|
||||
virtual bool execute();
|
||||
|
||||
//- Write
|
||||
virtual bool write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "runTimePostProcessingTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,60 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::runTimePostProcessing::readObjects
|
||||
(
|
||||
const dictionary& dict,
|
||||
PtrList<Type>& objects
|
||||
) const
|
||||
{
|
||||
objects.clear();
|
||||
|
||||
for (const entry& dEntry : dict)
|
||||
{
|
||||
if (!dEntry.isDict())
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< dict.dictName()
|
||||
<< " objects must be specified in dictionary format"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
const dictionary& objectDict = dEntry.dict();
|
||||
const word objectType = objectDict.get<word>("type");
|
||||
|
||||
objects.append
|
||||
(
|
||||
Type::New(*this, objectDict, scene_.colours(), objectType)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,259 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "scalarBar.H"
|
||||
|
||||
// #include "doubleVector.H"
|
||||
// #include "foamVtkTools.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkCoordinate.h"
|
||||
#include "vtkLookupTable.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkScalarBarActor.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
#include "vtkTextActor.h"
|
||||
#include "vtkTextProperty.h"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::scalarBar::scalarBar()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::scalarBar::clear()
|
||||
{
|
||||
visible_ = true;
|
||||
vertical_ = true;
|
||||
bold_ = true;
|
||||
shadow_ = false;
|
||||
italic_ = false;
|
||||
titleHack_ = false;
|
||||
position_ = {0.8, 0.1};
|
||||
size_ = {0.1, 0.5};
|
||||
title_ = "";
|
||||
fontSize_ = 0; // 0 == Auto-sizing (defaultFontSize)
|
||||
titleSize_ = 0; // 0 == Auto-sizing (defaultTitleSizeFactor)
|
||||
nLabels_ = 5;
|
||||
labelFormat_ = "%f";
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::scalarBar::hide()
|
||||
{
|
||||
visible_ = false;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::scalarBar::read
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
clear();
|
||||
|
||||
dict.readIfPresent("visible", visible_);
|
||||
|
||||
if (visible_)
|
||||
{
|
||||
dict.readIfPresent("vertical", vertical_);
|
||||
dict.readIfPresent("bold", bold_);
|
||||
dict.readIfPresent("italic", italic_);
|
||||
dict.readIfPresent("shadow", shadow_);
|
||||
dict.readIfPresent("titleHack", titleHack_);
|
||||
|
||||
if (vertical_)
|
||||
{
|
||||
size_ = { 0.1, 0.75 };
|
||||
}
|
||||
else
|
||||
{
|
||||
size_ = { 0.75, 0.1 };
|
||||
}
|
||||
|
||||
dict.readEntry("position", position_);
|
||||
dict.readIfPresent("size", size_);
|
||||
dict.readEntry("title", title_);
|
||||
dict.readIfPresent("fontSize", fontSize_);
|
||||
dict.readIfPresent("titleSize", titleSize_);
|
||||
dict.readIfPresent("labelFormat", labelFormat_);
|
||||
dict.readIfPresent("numberOfLabels", nLabels_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::scalarBar::add
|
||||
(
|
||||
const vector& textColour,
|
||||
vtkRenderer* renderer,
|
||||
vtkLookupTable* lut
|
||||
) const
|
||||
{
|
||||
// Add scalar bar legend
|
||||
|
||||
if (!visible_ || !renderer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const label fontSizeValue = (fontSize_ ? fontSize_ : defaultFontSize);
|
||||
|
||||
auto sbar = vtkSmartPointer<vtkScalarBarActor>::New();
|
||||
sbar->SetLookupTable(lut);
|
||||
sbar->SetNumberOfLabels(nLabels_);
|
||||
sbar->SetLabelFormat(labelFormat_.c_str());
|
||||
|
||||
/// const vector textColour = colours_["text"]->value(position);
|
||||
|
||||
// Work-around to supply our own scalarbar title
|
||||
// - Default scalar bar title text is scales by the scalar bar box
|
||||
// dimensions so if the title is a long string, the text is shrunk to fit
|
||||
// Instead, suppress title and set the title using a vtkTextActor
|
||||
|
||||
vtkSmartPointer<vtkTextActor> titleActor;
|
||||
vtkTextProperty* titleProp;
|
||||
|
||||
if (titleHack_)
|
||||
{
|
||||
// Place the scalar bar title ourselves
|
||||
sbar->SetUnconstrainedFontSize(true);
|
||||
|
||||
titleActor = vtkSmartPointer<vtkTextActor>::New();
|
||||
titleActor->SetInput(title_.c_str());
|
||||
|
||||
titleProp = titleActor->GetTextProperty();
|
||||
titleProp->SetJustificationToCentered();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use the standard scalar bar title
|
||||
sbar->SetUnconstrainedFontSize(fontSize_ != 0);
|
||||
sbar->SetTitle(title_.c_str());
|
||||
titleProp = sbar->GetTitleTextProperty();
|
||||
}
|
||||
|
||||
titleProp->SetFontFamilyToArial();
|
||||
|
||||
// Title size was supplied by user (absolute size)
|
||||
// or use preset factor (3) of label font size
|
||||
|
||||
if (titleSize_)
|
||||
{
|
||||
titleProp->SetFontSize(titleSize_);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Auto
|
||||
titleProp->SetFontSize(defaultTitleSizeFactor*fontSizeValue);
|
||||
|
||||
// Or this??
|
||||
// if (!titleHack_) titleProp->SetFontSize(fontSizeValue);
|
||||
}
|
||||
|
||||
titleProp->SetJustificationToCentered();
|
||||
titleProp->SetVerticalJustificationToBottom();
|
||||
titleProp->SetBold(bold_);
|
||||
titleProp->SetItalic(italic_);
|
||||
titleProp->SetShadow(shadow_);
|
||||
|
||||
titleProp->SetColor(textColour[0], textColour[1], textColour[2]);
|
||||
|
||||
auto labProp = sbar->GetLabelTextProperty();
|
||||
|
||||
labProp->SetColor(textColour[0], textColour[1], textColour[2]);
|
||||
|
||||
if (titleHack_ || fontSize_)
|
||||
{
|
||||
labProp->SetFontSize(fontSizeValue);
|
||||
}
|
||||
labProp->ShadowOff();
|
||||
labProp->BoldOff(); // or: labProp->SetBold(bold_);
|
||||
labProp->ItalicOff();
|
||||
|
||||
// Positioning
|
||||
{
|
||||
vtkCoordinate* coord = sbar->GetPositionCoordinate();
|
||||
|
||||
coord->SetCoordinateSystemToNormalizedViewport();
|
||||
coord->SetValue(position_.first(), position_.second());
|
||||
}
|
||||
|
||||
if (vertical_)
|
||||
{
|
||||
sbar->SetOrientationToVertical();
|
||||
sbar->SetTextPositionToSucceedScalarBar();
|
||||
sbar->SetWidth(size_.first());
|
||||
sbar->SetHeight(size_.second());
|
||||
// Standard is sbar->SetBarRatio(0.375);
|
||||
}
|
||||
else
|
||||
{
|
||||
sbar->SetOrientationToHorizontal();
|
||||
sbar->SetTextPositionToPrecedeScalarBar();
|
||||
|
||||
// Adjustments since not using scalarbar title property
|
||||
sbar->SetWidth(size_.first());
|
||||
sbar->SetHeight(size_.second());
|
||||
// sbar->SetBarRatio(0.5);
|
||||
// Standard is sbar->SetBarRatio(0.375);
|
||||
// sbar->SetTitleRatio(0.01);
|
||||
}
|
||||
|
||||
if (titleActor)
|
||||
{
|
||||
vtkCoordinate* coord = titleActor->GetPositionCoordinate();
|
||||
|
||||
coord->SetCoordinateSystemToNormalizedViewport();
|
||||
|
||||
coord->SetValue
|
||||
(
|
||||
position_.first() + (0.5 * sbar->GetWidth()),
|
||||
position_.second() + (1.01 * sbar->GetHeight())
|
||||
);
|
||||
}
|
||||
|
||||
// sbar->DrawFrameOn();
|
||||
// sbar->DrawBackgroundOn();
|
||||
// sbar->UseOpacityOff();
|
||||
// sbar->VisibilityOff();
|
||||
sbar->VisibilityOn();
|
||||
|
||||
renderer->AddActor(sbar);
|
||||
|
||||
if (titleActor)
|
||||
{
|
||||
renderer->AddActor2D(titleActor);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,159 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::scalarBar
|
||||
|
||||
Description
|
||||
Handling of scalar bar setup.
|
||||
|
||||
Dictionary controls - scalar-bar entries (when \c visible is true)
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
visible | Display scalar bar | no | true
|
||||
title | The title for the scalar bar | yes |
|
||||
position | Viewport position (x y) of scalar bar | yes |
|
||||
vertical | Vertical scalar bar | no | true
|
||||
size | Viewport size (x y) of scalar bar | no | auto
|
||||
fontSize | Label size | no | 0 == auto
|
||||
titleSize | Title font size | no | 0 == auto
|
||||
labelFormat | Label format string (eg, "%f") | no | "%f"
|
||||
numberOfLabels | Total number of labels | no | 5
|
||||
bold | Title in bold | no | yes
|
||||
italic | Title in italic font | no | no
|
||||
shadow | Title with shadowont | no | no
|
||||
titleHack | Alternative placement strategy | no | no
|
||||
\endtable
|
||||
|
||||
Note
|
||||
The \c titleHack option is a leftover from much older VTK versions
|
||||
that had poor handling of the scalar bar text. When this is active,
|
||||
the normal scalar bar title is suppressed and placed manually
|
||||
(with a predefined ratio of the base font-size).
|
||||
|
||||
When the titleHack is off, the label and title font sizes are
|
||||
automatically defined by the scalar bar size but can be overridden with
|
||||
provided values.
|
||||
|
||||
The effect of fontSize and titleSize is unfortunately not consistent
|
||||
between titleHack on/off.
|
||||
|
||||
SourceFiles
|
||||
scalarBar.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_scalarBar_H
|
||||
#define functionObjects_runTimePostPro_scalarBar_H
|
||||
|
||||
#include "dictionary.H"
|
||||
#include "Tuple2.H"
|
||||
#include "vector.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Forward Declarations
|
||||
class vtkLookupTable;
|
||||
class vtkRenderer;
|
||||
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class scalarBar Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class scalarBar
|
||||
{
|
||||
//- The default font size when titleHack is on
|
||||
static constexpr const label defaultFontSize = 18;
|
||||
|
||||
//- The auto title/label ratio when titleHack is on
|
||||
static constexpr const float defaultTitleSizeFactor = 1.5;
|
||||
|
||||
bool visible_;
|
||||
bool vertical_;
|
||||
bool bold_;
|
||||
bool italic_;
|
||||
bool shadow_;
|
||||
bool titleHack_;
|
||||
|
||||
Tuple2<scalar, scalar> position_;
|
||||
|
||||
Tuple2<scalar, scalar> size_;
|
||||
|
||||
string title_;
|
||||
|
||||
label fontSize_;
|
||||
|
||||
label titleSize_;
|
||||
|
||||
label nLabels_;
|
||||
|
||||
string labelFormat_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Construct with sensible defaults
|
||||
scalarBar();
|
||||
|
||||
//- Reset to sensible defaults
|
||||
void clear();
|
||||
|
||||
//- Make non-visible
|
||||
void hide();
|
||||
|
||||
//- Read dictionary settings
|
||||
void read(const dictionary& dict);
|
||||
|
||||
//- Add colour bar, when visible.
|
||||
bool add
|
||||
(
|
||||
const vector& textColour,
|
||||
vtkRenderer* renderer,
|
||||
vtkLookupTable* lut
|
||||
) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,441 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "scene.H"
|
||||
#include "Constant.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkCamera.h"
|
||||
#include "vtkCubeSource.h"
|
||||
#include "vtkLightKit.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkPNGWriter.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkRendererCollection.h"
|
||||
#include "vtkRenderWindow.h"
|
||||
#include "vtkWindowToImageFilter.h"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::scene::readCamera
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
nFrameTotal_ = dict.getCheckOrDefault<label>
|
||||
(
|
||||
"nFrameTotal",
|
||||
1,
|
||||
labelMinMax::ge(1)
|
||||
);
|
||||
|
||||
if
|
||||
(
|
||||
dict.readCheckIfPresent
|
||||
(
|
||||
"startPosition",
|
||||
startPosition_,
|
||||
scalarMinMax::zero_one()
|
||||
)
|
||||
)
|
||||
{
|
||||
position_ = startPosition_;
|
||||
}
|
||||
|
||||
if (nFrameTotal_ > 1)
|
||||
{
|
||||
scalar endPosition = dict.getCheckOrDefault<scalar>
|
||||
(
|
||||
"endPosition",
|
||||
1,
|
||||
scalarMinMax::zero_one()
|
||||
);
|
||||
|
||||
dPosition_ = (endPosition - startPosition_)/scalar(nFrameTotal_ - 1);
|
||||
}
|
||||
|
||||
cameraPosition_ = Function1<vector>::New("position", dict);
|
||||
cameraFocalPoint_ = Function1<point>::New("focalPoint", dict);
|
||||
cameraUp_ = Function1<vector>::New("up", dict);
|
||||
|
||||
dict.readIfPresent("clipBox", clipBox_);
|
||||
parallelProjection_ = dict.getOrDefault("parallelProjection", true);
|
||||
if (!parallelProjection_)
|
||||
{
|
||||
if (dict.found("viewAngle"))
|
||||
{
|
||||
cameraViewAngle_ = Function1<scalar>::New("viewAngle", dict);
|
||||
}
|
||||
else
|
||||
{
|
||||
cameraViewAngle_.reset
|
||||
(
|
||||
new Function1Types::Constant<scalar>("viewAngle", 35.0)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (dict.found("zoom"))
|
||||
{
|
||||
cameraZoom_ = Function1<scalar>::New("zoom", dict);
|
||||
}
|
||||
else
|
||||
{
|
||||
cameraZoom_.reset
|
||||
(
|
||||
new Function1Types::Constant<scalar>("zoom", 1.0)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::scene::readColours
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
const wordList colours(dict.toc());
|
||||
for (const word& c : colours)
|
||||
{
|
||||
colours_.insert(c, Function1<vector>::New(c, dict));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::scene::setActorVisibility
|
||||
(
|
||||
vtkRenderer* renderer,
|
||||
const bool visible
|
||||
) const
|
||||
{
|
||||
if (!renderer) return;
|
||||
|
||||
vtkActorCollection *actors = renderer->GetActors();
|
||||
for (int i = 0; i < actors->GetNumberOfItems(); ++i)
|
||||
{
|
||||
vtkActor *actor = vtkActor::SafeDownCast(actors->GetItemAsObject(i));
|
||||
actor->SetVisibility(visible);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::scene::initialise
|
||||
(
|
||||
vtkRenderer* renderer,
|
||||
const word& outputName
|
||||
)
|
||||
{
|
||||
currentFrameI_ = 0;
|
||||
position_ = startPosition_;
|
||||
|
||||
outputName_ = outputName;
|
||||
|
||||
if (!renderer) return;
|
||||
|
||||
|
||||
// Set the background
|
||||
const vector bgColour = colours_["background"]->value(position_);
|
||||
|
||||
renderer->SetBackground(bgColour.x(), bgColour.y(), bgColour.z());
|
||||
|
||||
// Apply gradient background if "background2" defined
|
||||
if (colours_.found("background2"))
|
||||
{
|
||||
const vector bg2Colour = colours_["background2"]->value(position_);
|
||||
|
||||
renderer->GradientBackgroundOn();
|
||||
renderer->SetBackground2(bg2Colour.x(), bg2Colour.y(), bg2Colour.z());
|
||||
}
|
||||
else if (Pstream::parRun())
|
||||
{
|
||||
// Oddly enough we seem a gradient background for parallel rendering,
|
||||
// otherwise the colours look quite funny.
|
||||
// Doesn't seem to matter if we use SetBackground2() though
|
||||
|
||||
renderer->GradientBackgroundOn();
|
||||
renderer->SetBackground2(bgColour.x(), bgColour.y(), bgColour.z());
|
||||
}
|
||||
|
||||
// Depth peeling
|
||||
renderer->SetUseDepthPeeling(true);
|
||||
renderer->SetMaximumNumberOfPeels(4);
|
||||
renderer->SetOcclusionRatio(0);
|
||||
|
||||
// Set the camera
|
||||
auto camera = vtkSmartPointer<vtkCamera>::New();
|
||||
camera->SetParallelProjection(parallelProjection_);
|
||||
renderer->SetActiveCamera(camera);
|
||||
|
||||
// Add the lights
|
||||
auto lightKit = vtkSmartPointer<vtkLightKit>::New();
|
||||
lightKit->AddLightsToRenderer(renderer);
|
||||
|
||||
if (!clipBox_.empty())
|
||||
{
|
||||
const point& min = clipBox_.min();
|
||||
const point& max = clipBox_.max();
|
||||
auto clipBox = vtkSmartPointer<vtkCubeSource>::New();
|
||||
clipBox->SetXLength(max.x() - min.x());
|
||||
clipBox->SetYLength(max.y() - min.y());
|
||||
clipBox->SetZLength(max.z() - min.z());
|
||||
clipBox->SetCenter
|
||||
(
|
||||
min.x() + 0.5*(max.x() - min.x()),
|
||||
min.y() + 0.5*(max.y() - min.y()),
|
||||
min.z() + 0.5*(max.z() - min.z())
|
||||
);
|
||||
auto clipMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
clipMapper->SetInputConnection(clipBox->GetOutputPort());
|
||||
|
||||
clipBoxActor_ = vtkSmartPointer<vtkActor>::New();
|
||||
clipBoxActor_->SetMapper(clipMapper);
|
||||
clipBoxActor_->VisibilityOff();
|
||||
renderer->AddActor(clipBoxActor_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::scene::setCamera
|
||||
(
|
||||
vtkRenderer* renderer
|
||||
) const
|
||||
{
|
||||
if (!renderer) return;
|
||||
|
||||
vtkCamera* camera = renderer->GetActiveCamera();
|
||||
|
||||
if (parallelProjection_)
|
||||
{
|
||||
// Restore parallel scale to allow application of zoom (later)
|
||||
camera->SetParallelScale(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Restore viewAngle (it might be reset by clipping)
|
||||
camera->SetViewAngle(cameraViewAngle_->value(position_));
|
||||
}
|
||||
|
||||
const vector up = cameraUp_->value(position_);
|
||||
const vector pos = cameraPosition_->value(position_);
|
||||
const point focalPoint = cameraFocalPoint_->value(position_);
|
||||
const scalar zoom = cameraZoom_->value(position_);
|
||||
|
||||
camera->SetViewUp(up.x(), up.y(), up.z());
|
||||
camera->SetPosition(pos.x(), pos.y(), pos.z());
|
||||
camera->SetFocalPoint(focalPoint.x(), focalPoint.y(), focalPoint.z());
|
||||
|
||||
|
||||
// Apply clipping if required
|
||||
// Note: possible optimisation - if the camera is static, this only needs
|
||||
// to be done once on initialisation
|
||||
if (!clipBox_.empty())
|
||||
{
|
||||
setActorVisibility(renderer, false);
|
||||
clipBoxActor_->VisibilityOn();
|
||||
|
||||
// Call ResetCamera() to fit clip box in view
|
||||
renderer->ResetCamera();
|
||||
|
||||
setActorVisibility(renderer, true);
|
||||
clipBoxActor_->VisibilityOff();
|
||||
}
|
||||
|
||||
// Zoom applied after all other operations
|
||||
camera->Zoom(zoom);
|
||||
|
||||
camera->Modified();
|
||||
}
|
||||
|
||||
|
||||
Foam::string
|
||||
Foam::functionObjects::runTimePostPro::scene::frameIndexStr() const
|
||||
{
|
||||
string str = Foam::name(currentFrameI_);
|
||||
str.insert(0, 4 - str.length(), '0');
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::scene::scene
|
||||
(
|
||||
const objectRegistry& obr,
|
||||
const word& name
|
||||
)
|
||||
:
|
||||
obr_(obr),
|
||||
name_(name),
|
||||
colours_(),
|
||||
cameraPosition_(nullptr),
|
||||
cameraFocalPoint_(nullptr),
|
||||
cameraUp_(nullptr),
|
||||
cameraViewAngle_(nullptr),
|
||||
cameraZoom_(nullptr),
|
||||
clipBox_(boundBox::invertedBox),
|
||||
clipBoxActor_(),
|
||||
parallelProjection_(true),
|
||||
nFrameTotal_(1),
|
||||
startPosition_(0),
|
||||
position_(0),
|
||||
dPosition_(0),
|
||||
currentFrameI_(0),
|
||||
outputName_("unknown")
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::scene::~scene()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::HashPtrTable<Foam::Function1<Foam::vector>, Foam::word>&
|
||||
Foam::functionObjects::runTimePostPro::scene::colours() const
|
||||
{
|
||||
return colours_;
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::functionObjects::runTimePostPro::scene::frameIndex() const
|
||||
{
|
||||
return currentFrameI_;
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::functionObjects::runTimePostPro::scene::position() const
|
||||
{
|
||||
return position_;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::scene::read
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
readCamera(dict.subDict("camera"));
|
||||
readColours(dict.subDict("colours"));
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::scene::loop(vtkRenderer* renderer)
|
||||
{
|
||||
static bool initialised = false;
|
||||
setCamera(renderer);
|
||||
|
||||
if (!initialised)
|
||||
{
|
||||
initialised = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (renderer)
|
||||
{
|
||||
|
||||
// Ensure that all objects can be seen without clipping
|
||||
// Note: can only be done after all objects have been added!
|
||||
renderer->ResetCameraClippingRange();
|
||||
|
||||
// Save image from last iteration
|
||||
saveImage(renderer->GetRenderWindow());
|
||||
}
|
||||
|
||||
++currentFrameI_;
|
||||
|
||||
position_ = startPosition_ + currentFrameI_*dPosition_;
|
||||
|
||||
if (currentFrameI_ < nFrameTotal_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
initialised = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::scene::saveImage
|
||||
(
|
||||
vtkRenderWindow* renderWindow
|
||||
) const
|
||||
{
|
||||
if (!renderWindow)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const Time& runTime = obr_.time();
|
||||
|
||||
const fileName fName
|
||||
(
|
||||
runTime.globalPath()
|
||||
/ functionObject::outputPrefix
|
||||
/ name_
|
||||
/ runTime.timeName()
|
||||
/ outputName_ + '.' + frameIndexStr() + ".png"
|
||||
);
|
||||
|
||||
renderWindow->Render();
|
||||
|
||||
// Set up off-screen rendering
|
||||
auto windowToImageFilter = vtkSmartPointer<vtkWindowToImageFilter>::New();
|
||||
|
||||
windowToImageFilter->SetInput(renderWindow);
|
||||
|
||||
//// Add alpha channel for transparency
|
||||
// windowToImageFilter->SetInputBufferTypeToRGBA();
|
||||
windowToImageFilter->SetInputBufferTypeToRGB();
|
||||
|
||||
// windowToImageFilter->ReadFrontBufferOff();
|
||||
windowToImageFilter->Update();
|
||||
|
||||
// Save the image
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
mkDir(fName.path());
|
||||
|
||||
auto writer = vtkSmartPointer<vtkPNGWriter>::New();
|
||||
writer->SetFileName(fName.c_str());
|
||||
writer->SetInputConnection(windowToImageFilter->GetOutputPort());
|
||||
|
||||
Info<< " Generating image: " << runTime.relativePath(fName) << endl;
|
||||
|
||||
writer->Write();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,241 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::scene
|
||||
|
||||
Description
|
||||
Class to control scene construction and provide main rendering loop
|
||||
|
||||
Usage
|
||||
\verbatim
|
||||
camera
|
||||
{
|
||||
// Total number of frames to generate
|
||||
nFrameTotal 1;
|
||||
|
||||
// Parallel projection flag
|
||||
parallelProjection no;
|
||||
|
||||
focalPoint (0 0 0);
|
||||
up (0 1 0);
|
||||
position (0 0 1);
|
||||
|
||||
// Optional entries
|
||||
clipBox (-0.0206 -0.0254 -0.0005) (0.29 0.0254 0.0005);
|
||||
viewAngle 20;
|
||||
zoom 1.1;
|
||||
}
|
||||
|
||||
colours
|
||||
{
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
SourceFiles
|
||||
scene.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_scene_H
|
||||
#define functionObjects_runTimePostPro_scene_H
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "dictionary.H"
|
||||
#include "Function1.H"
|
||||
#include "vector.H"
|
||||
#include "point.H"
|
||||
#include "boundBox.H"
|
||||
#include "Enum.H"
|
||||
#include "HashPtrTable.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Forward declarations
|
||||
class vtkActor;
|
||||
class vtkRenderer;
|
||||
class vtkRenderWindow;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class scene Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class scene
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Reference to the object registry
|
||||
const objectRegistry& obr_;
|
||||
|
||||
//- Object name
|
||||
const word name_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Read camera properties
|
||||
void readCamera(const dictionary& dict);
|
||||
|
||||
//- Read colour properties
|
||||
void readColours(const dictionary& dict);
|
||||
|
||||
//- Set visibility of all actors on/off
|
||||
void setActorVisibility
|
||||
(
|
||||
vtkRenderer* renderer,
|
||||
const bool visible
|
||||
) const;
|
||||
|
||||
//- No copy construct
|
||||
scene(const scene&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const scene&) = delete;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Colours
|
||||
HashPtrTable<Function1<vector>> colours_;
|
||||
|
||||
|
||||
// Camera settings
|
||||
|
||||
//- Position
|
||||
autoPtr<Function1<point>> cameraPosition_;
|
||||
|
||||
//- Focal point
|
||||
autoPtr<Function1<point>> cameraFocalPoint_;
|
||||
|
||||
//- Up direction
|
||||
autoPtr<Function1<vector>> cameraUp_;
|
||||
|
||||
//- View angle
|
||||
autoPtr<Function1<scalar>> cameraViewAngle_;
|
||||
|
||||
//- Zoom: 1 = do nothing, >1 = zoom in, <1 = zoom out
|
||||
// - perspective mode: reduces view angle
|
||||
// - parallel mode: manipulate parallel scale
|
||||
autoPtr<Function1<scalar>> cameraZoom_;
|
||||
|
||||
|
||||
// Scene management
|
||||
|
||||
//- Clipping box
|
||||
boundBox clipBox_;
|
||||
|
||||
//- Clipping box actor
|
||||
vtkSmartPointer<vtkActor> clipBoxActor_;
|
||||
|
||||
//- Parallel projection flag
|
||||
bool parallelProjection_;
|
||||
|
||||
//- Number of frames
|
||||
label nFrameTotal_;
|
||||
|
||||
//- Start position [0-1]
|
||||
scalar startPosition_;
|
||||
|
||||
//- Position [0-1]
|
||||
scalar position_;
|
||||
|
||||
//- Change in position per frame
|
||||
scalar dPosition_;
|
||||
|
||||
//- Index of current frame
|
||||
label currentFrameI_;
|
||||
|
||||
//- Name prefix of output
|
||||
word outputName_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
void setCamera(vtkRenderer* renderer) const;
|
||||
|
||||
string frameIndexStr() const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
scene(const objectRegistry& obr, const word& name);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~scene();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- Return the colours
|
||||
const HashPtrTable<Function1<vector>>& colours() const;
|
||||
|
||||
//- Return the current frame index
|
||||
label frameIndex() const;
|
||||
|
||||
//- Return the current position (in range 0-1)
|
||||
scalar position() const;
|
||||
|
||||
|
||||
void read(const dictionary& dict);
|
||||
|
||||
void initialise(vtkRenderer* renderer, const word& outputName);
|
||||
|
||||
//- Main control loop
|
||||
bool loop(vtkRenderer* renderer);
|
||||
|
||||
//- Save image to file
|
||||
void saveImage(vtkRenderWindow* renderWindow) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,309 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "surface.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
|
||||
#include "foamVtkTools.H"
|
||||
#include "polySurfaceFields.H"
|
||||
#include "polySurfacePointFields.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkCompositeDataGeometryFilter.h"
|
||||
#include "vtkFeatureEdges.h"
|
||||
#include "vtkMultiPieceDataSet.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkProperty.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
defineTypeName(surface);
|
||||
defineRunTimeSelectionTable(surface, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const Foam::Enum
|
||||
<
|
||||
Foam::functionObjects::runTimePostPro::surface::representationType
|
||||
>
|
||||
Foam::functionObjects::runTimePostPro::surface::representationTypeNames
|
||||
({
|
||||
{ representationType::rtNone, "none" },
|
||||
{ representationType::rtGlyph, "glyph" },
|
||||
{ representationType::rtWireframe, "wireframe" },
|
||||
{ representationType::rtSurface, "surface" },
|
||||
{ representationType::rtSurfaceWithEdges, "surfaceWithEdges" },
|
||||
});
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Specializations * * * * * * * * * * * * * * //
|
||||
|
||||
// These need to shift elsewhere
|
||||
|
||||
vtkCellData* Foam::vtk::Tools::GetCellData(vtkDataSet* dataset)
|
||||
{
|
||||
if (dataset) return dataset->GetCellData();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
vtkPointData* Foam::vtk::Tools::GetPointData(vtkDataSet* dataset)
|
||||
{
|
||||
if (dataset) return dataset->GetPointData();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::surface::setRepresentation
|
||||
(
|
||||
vtkActor* actor
|
||||
) const
|
||||
{
|
||||
geometryBase::initialiseActor(actor);
|
||||
|
||||
switch (representation_)
|
||||
{
|
||||
case rtNone:
|
||||
{
|
||||
actor->VisibilityOff();
|
||||
break;
|
||||
}
|
||||
case rtWireframe:
|
||||
{
|
||||
// Note: colour is set using general SetColor, not SetEdgeColor
|
||||
actor->GetProperty()->SetRepresentationToWireframe();
|
||||
break;
|
||||
}
|
||||
case rtGlyph:
|
||||
case rtSurface:
|
||||
{
|
||||
actor->GetProperty()->SetBackfaceCulling(backFaceCulling_);
|
||||
actor->GetProperty()->SetFrontfaceCulling(frontFaceCulling_);
|
||||
actor->GetProperty()->SetRepresentationToSurface();
|
||||
break;
|
||||
}
|
||||
case rtSurfaceWithEdges:
|
||||
{
|
||||
actor->GetProperty()->SetBackfaceCulling(backFaceCulling_);
|
||||
actor->GetProperty()->SetFrontfaceCulling(frontFaceCulling_);
|
||||
actor->GetProperty()->SetRepresentationToSurface();
|
||||
actor->GetProperty()->EdgeVisibilityOn();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::surface::addFeatureEdges
|
||||
(
|
||||
vtkRenderer* renderer,
|
||||
vtkFeatureEdges* featureEdges
|
||||
) const
|
||||
{
|
||||
if (!featureEdges)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
featureEdges->BoundaryEdgesOn();
|
||||
featureEdges->FeatureEdgesOn();
|
||||
featureEdges->ManifoldEdgesOff();
|
||||
featureEdges->NonManifoldEdgesOff();
|
||||
/// featureEdges->SetFeatureAngle(60);
|
||||
featureEdges->ColoringOff();
|
||||
featureEdges->Update();
|
||||
|
||||
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputConnection(featureEdges->GetOutputPort());
|
||||
mapper->ScalarVisibilityOff();
|
||||
|
||||
edgeActor_->GetProperty()->SetSpecular(0);
|
||||
edgeActor_->GetProperty()->SetSpecularPower(20);
|
||||
edgeActor_->GetProperty()->SetRepresentationToWireframe();
|
||||
edgeActor_->SetMapper(mapper);
|
||||
|
||||
renderer->AddActor(edgeActor_);
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::surface::addFeatureEdges
|
||||
(
|
||||
vtkRenderer* renderer,
|
||||
vtkPolyData* data
|
||||
) const
|
||||
{
|
||||
if (featureEdges_)
|
||||
{
|
||||
auto featureEdges = vtkSmartPointer<vtkFeatureEdges>::New();
|
||||
featureEdges->SetInputData(data);
|
||||
|
||||
addFeatureEdges(renderer, featureEdges);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::surface::addFeatureEdges
|
||||
(
|
||||
vtkRenderer* renderer,
|
||||
vtkCompositeDataGeometryFilter* input
|
||||
) const
|
||||
{
|
||||
if (featureEdges_)
|
||||
{
|
||||
auto featureEdges = vtkSmartPointer<vtkFeatureEdges>::New();
|
||||
featureEdges->SetInputConnection(input->GetOutputPort());
|
||||
|
||||
addFeatureEdges(renderer, featureEdges);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::surface::surface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
geometryBase(parent, dict, colours),
|
||||
representation_
|
||||
(
|
||||
representationTypeNames.get("representation", dict)
|
||||
),
|
||||
featureEdges_(dict.getOrDefault("featureEdges", false)),
|
||||
backFaceCulling_(dict.getOrDefault("backFaceCulling", false)),
|
||||
frontFaceCulling_(dict.getOrDefault("frontFaceCulling", true)),
|
||||
surfaceColour_(nullptr),
|
||||
edgeColour_(nullptr),
|
||||
surfaceActor_(),
|
||||
edgeActor_(),
|
||||
maxGlyphLength_(0)
|
||||
{
|
||||
surfaceActor_ = vtkSmartPointer<vtkActor>::New();
|
||||
edgeActor_ = vtkSmartPointer<vtkActor>::New();
|
||||
|
||||
if (dict.found("surfaceColour"))
|
||||
{
|
||||
surfaceColour_.reset(Function1<vector>::New("surfaceColour", dict));
|
||||
}
|
||||
else
|
||||
{
|
||||
surfaceColour_.reset(colours["surface"]->clone().ptr());
|
||||
}
|
||||
|
||||
if (dict.found("edgeColour"))
|
||||
{
|
||||
edgeColour_.reset(Function1<vector>::New("edgeColour", dict));
|
||||
}
|
||||
else
|
||||
{
|
||||
edgeColour_.reset(colours["edge"]->clone().ptr());
|
||||
}
|
||||
|
||||
if (representation_ == rtGlyph)
|
||||
{
|
||||
dict.readEntry("maxGlyphLength", maxGlyphLength_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::autoPtr<Foam::functionObjects::runTimePostPro::surface>
|
||||
Foam::functionObjects::runTimePostPro::surface::New
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours,
|
||||
const word& surfaceType
|
||||
)
|
||||
{
|
||||
DebugInfo << "Selecting surface " << surfaceType << endl;
|
||||
|
||||
auto cstrIter = dictionaryConstructorTablePtr_->cfind(surfaceType);
|
||||
|
||||
if (!cstrIter.found())
|
||||
{
|
||||
FatalIOErrorInLookup
|
||||
(
|
||||
dict,
|
||||
"surface",
|
||||
surfaceType,
|
||||
*dictionaryConstructorTablePtr_
|
||||
) << exit(FatalIOError);
|
||||
}
|
||||
|
||||
return autoPtr<surface>(cstrIter()(parent, dict, colours));
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::surface::~surface()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::surface::updateActors
|
||||
(
|
||||
const scalar position
|
||||
)
|
||||
{
|
||||
if (!featureEdges_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vtkProperty* edgeProp = edgeActor_->GetProperty();
|
||||
|
||||
edgeProp->SetLineWidth(2);
|
||||
edgeProp->SetOpacity(opacity(position));
|
||||
|
||||
const vector ec = edgeColour_->value(position);
|
||||
edgeProp->SetColor(ec[0], ec[1], ec[2]);
|
||||
edgeProp->SetEdgeColor(ec[0], ec[1], ec[2]);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,397 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::surface
|
||||
|
||||
Description
|
||||
Visualisation of surface data with additional routines for handling
|
||||
parallel distributed data.
|
||||
|
||||
Dictionary controls
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
representation| none/glyph/wireframe/surface/surfaceWithEdges | yes |
|
||||
surfaceColour | Override surface colour | no |
|
||||
edgeColour | Override edge colour | no |
|
||||
featureEdges | Display surface feature edges | no | false
|
||||
maxGlyphLength | Limit for glyph representation | yes | 0
|
||||
backFaceCulling | Cull back face | no | false
|
||||
frontFaceCulling | Cull front face | no | true
|
||||
\endtable
|
||||
|
||||
SourceFiles
|
||||
surface.C
|
||||
surfaceGather.C
|
||||
surfaceTemplates.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_surface_H
|
||||
#define functionObjects_runTimePostPro_surface_H
|
||||
|
||||
#include "geometryBase.H"
|
||||
#include "DimensionedField.H"
|
||||
#include "Enum.H"
|
||||
#include "runTimeSelectionTables.H"
|
||||
|
||||
#include "vtkSmartPointer.h"
|
||||
#include "vtkMultiPieceDataSet.h"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Forward Declarations
|
||||
class vtkActor;
|
||||
class vtkRenderer;
|
||||
class vtkCellData;
|
||||
class vtkCompositeDataGeometryFilter;
|
||||
class vtkFeatureEdges;
|
||||
class vtkPointData;
|
||||
class vtkPolyData;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
// Forward Declarations
|
||||
class polySurface;
|
||||
class polySurfaceGeoMesh;
|
||||
class polySurfacePointGeoMesh;
|
||||
}
|
||||
|
||||
|
||||
// These need to shift elsewhere
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace vtk
|
||||
{
|
||||
namespace Tools
|
||||
{
|
||||
|
||||
//- Functional call with null-pointer check
|
||||
vtkCellData* GetCellData(vtkDataSet* dataset);
|
||||
|
||||
//- Functional call with null-pointer check
|
||||
vtkPointData* GetPointData(vtkDataSet* dataset);
|
||||
|
||||
|
||||
//- Default field access is vtkCellData
|
||||
template<class Type>
|
||||
struct FieldAccess
|
||||
{
|
||||
vtkCellData* operator()(vtkDataSet* dataset) const
|
||||
{
|
||||
return Tools::GetCellData(dataset);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Specializations on OpenFOAM type
|
||||
|
||||
//- PointAccess for point fields (on polySurfacePointGeoMesh)
|
||||
template<>
|
||||
struct FieldAccess<::Foam::polySurfacePointGeoMesh>
|
||||
{
|
||||
vtkPointData* operator()(vtkDataSet* dataset) const
|
||||
{
|
||||
return Tools::GetPointData(dataset);
|
||||
}
|
||||
};
|
||||
|
||||
} // End namespace Tools
|
||||
} // End namespace vtk
|
||||
} // End namespace Foam
|
||||
|
||||
|
||||
// More
|
||||
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class surface Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class surface
|
||||
:
|
||||
public geometryBase
|
||||
{
|
||||
public:
|
||||
|
||||
// Public enumerations
|
||||
|
||||
//- Surface representation types
|
||||
enum representationType
|
||||
{
|
||||
rtNone, //!< "none"
|
||||
rtGlyph, //!< "glyph"
|
||||
rtWireframe, //!< "wireframe"
|
||||
rtSurface, //!< "surface"
|
||||
rtSurfaceWithEdges //!< "surfaceWithEdges"
|
||||
};
|
||||
|
||||
//- Names for surface representation types
|
||||
static const Enum<representationType> representationTypeNames;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- Representation type
|
||||
representationType representation_;
|
||||
|
||||
//- Activate feature edges
|
||||
bool featureEdges_;
|
||||
|
||||
//- Back face culling option; default = off
|
||||
bool backFaceCulling_;
|
||||
|
||||
//- Front face culling option; default = on
|
||||
bool frontFaceCulling_;
|
||||
|
||||
//- Surface colour
|
||||
autoPtr<Function1<vector>> surfaceColour_;
|
||||
|
||||
//- Edge colour
|
||||
autoPtr<Function1<vector>> edgeColour_;
|
||||
|
||||
//- Surface actor
|
||||
vtkSmartPointer<vtkActor> surfaceActor_;
|
||||
|
||||
//- Edge actor
|
||||
vtkSmartPointer<vtkActor> edgeActor_;
|
||||
|
||||
//- Max glyph length for representation type rtGlyph
|
||||
scalar maxGlyphLength_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Set the representation
|
||||
void setRepresentation(vtkActor* actor) const;
|
||||
|
||||
//- Add feature edges to scene
|
||||
void addFeatureEdges
|
||||
(
|
||||
vtkRenderer* renderer,
|
||||
vtkFeatureEdges* featureEdges
|
||||
) const;
|
||||
|
||||
//- Add feature edges to scene
|
||||
void addFeatureEdges
|
||||
(
|
||||
vtkRenderer* renderer,
|
||||
vtkPolyData* data
|
||||
) const;
|
||||
|
||||
//- Add feature edges to scene
|
||||
void addFeatureEdges
|
||||
(
|
||||
vtkRenderer* renderer,
|
||||
vtkCompositeDataGeometryFilter* input
|
||||
) const;
|
||||
|
||||
|
||||
//- Gather and convert polySurface to multi-piece dataset with
|
||||
//- vtkPolyData for the leaves.
|
||||
// If VTK is also running in parallel, each surface is left
|
||||
// as a processor-local piece. Otherwise all processor-local
|
||||
// surfaces are gathered onto the master in their correponding
|
||||
// slots.
|
||||
vtkSmartPointer<vtkMultiPieceDataSet>
|
||||
gatherSurfacePieces(const polySurface* surf) const;
|
||||
|
||||
//- Gather and convert polySurface to multi-piece dataset with
|
||||
//- vtkPolyData for the leaves.
|
||||
// If VTK is also running in parallel, each surface is left
|
||||
// as a processor-local piece. Otherwise all processor-local
|
||||
// surfaces are gathered onto the master in their correponding
|
||||
// slots.
|
||||
vtkSmartPointer<vtkMultiPieceDataSet>
|
||||
gatherFaceCentres(const polySurface* surf) const;
|
||||
|
||||
|
||||
// Adding Fields - single-piece
|
||||
|
||||
//- Add field of Type to piece as VTK field data in GeoMeshType slot.
|
||||
// GeoMeshType distinguishes between vtkCellData and vtkPointData
|
||||
template<class Type, class GeoMeshType>
|
||||
bool addField
|
||||
(
|
||||
vtkDataSet* piece, //!< The VTK piece (null protected)
|
||||
const Field<Type>& fld, //!< The field values to add
|
||||
const word& fieldName //!< The field name to use
|
||||
) const;
|
||||
|
||||
//- Attempt cast of regIOobject to DimensionedField\<Type\> and
|
||||
//- add to piece as VTK field data in GeoMeshType slot.
|
||||
// GeoMeshType distinguishes between vtkCellData and vtkPointData
|
||||
template<class Type, class GeoMeshType>
|
||||
bool addDimField
|
||||
(
|
||||
vtkDataSet* piece, //!< The VTK piece (null protected)
|
||||
const regIOobject* ioptr, //!< The field values to add
|
||||
const word& fieldName //!< The field name to use
|
||||
) const;
|
||||
|
||||
//- Attempt cast of regIOobject to standard DimensionedField types
|
||||
//- and add to piece when possible
|
||||
template<class GeoMeshType>
|
||||
bool addDimField
|
||||
(
|
||||
vtkDataSet* piece, //!< The VTK piece (null protected)
|
||||
const regIOobject* ioptr, //!< The field values to add
|
||||
const word& fieldName //!< The field name to use
|
||||
) const;
|
||||
|
||||
|
||||
// Adding Fields - multi-piece
|
||||
|
||||
//- Add DimensionedField of Type to multi-piece as VTK field data in
|
||||
//- GeoMeshType slot (CELL | POINT).
|
||||
template<class Type, class GeoMeshType>
|
||||
bool addDimField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const DimensionedField<Type, GeoMeshType>* fldptr,
|
||||
const word& fieldName
|
||||
) const;
|
||||
|
||||
//- Attempt cast of regIOobject to DimensionedField\<Type\> and
|
||||
//- add in multi-piece as VTK field data in
|
||||
//- GeoMeshType slot (CELL | POINT).
|
||||
template<class Type, class GeoMeshType>
|
||||
bool addDimField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece, //!< The VTK pieces
|
||||
const regIOobject* ioptr, //!< The field values to add
|
||||
const word& fieldName //!< The field name to use
|
||||
) const;
|
||||
|
||||
//- Attempt cast of regIOobject to standard DimensionedField types
|
||||
//- and add when possible in GeoMeshType slot (CELL | POINT).
|
||||
template<class GeoMeshType>
|
||||
bool addDimField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece, //!< The VTK pieces
|
||||
const regIOobject* ioptr, //!< The field values to add
|
||||
const word& fieldName //!< The field name to use
|
||||
) const;
|
||||
|
||||
//- Add using regIOobject information obtained from surface
|
||||
template<class GeoMeshType>
|
||||
bool addDimField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const polySurface* surf,
|
||||
const word& fieldName
|
||||
) const;
|
||||
|
||||
|
||||
//- No copy construct
|
||||
surface(const surface&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const surface&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeNameNoDebug("surface");
|
||||
|
||||
|
||||
// Declare run-time constructor selection table
|
||||
|
||||
declareRunTimeSelectionTable
|
||||
(
|
||||
autoPtr,
|
||||
surface,
|
||||
dictionary,
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
),
|
||||
(parent, dict, colours)
|
||||
);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
surface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
);
|
||||
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Return selected surface
|
||||
static autoPtr<surface> New
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours,
|
||||
const word& surfaceName
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~surface();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Update the actors
|
||||
virtual void updateActors(const scalar position);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "surfaceTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,224 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "surface.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
|
||||
#include "foamVtkTools.H"
|
||||
#include "polySurface.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkMultiPieceDataSet.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
vtkSmartPointer<vtkMultiPieceDataSet>
|
||||
Foam::functionObjects::runTimePostPro::surface::gatherSurfacePieces
|
||||
(
|
||||
const polySurface* surf
|
||||
) const
|
||||
{
|
||||
auto multiPiece = vtkSmartPointer<vtkMultiPieceDataSet>::New();
|
||||
multiPiece->SetNumberOfPieces(Pstream::nProcs());
|
||||
|
||||
if (!needsCollective())
|
||||
{
|
||||
// Simple case (serial-serial, parallel-parallel)
|
||||
|
||||
if (surf)
|
||||
{
|
||||
multiPiece->SetPiece
|
||||
(
|
||||
Pstream::myProcNo(),
|
||||
Foam::vtk::Tools::Patch::mesh(*surf)
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (Pstream::master())
|
||||
{
|
||||
// Gather pieces on master
|
||||
|
||||
if (surf)
|
||||
{
|
||||
// Add myself
|
||||
|
||||
multiPiece->SetPiece
|
||||
(
|
||||
Pstream::myProcNo(),
|
||||
Foam::vtk::Tools::Patch::mesh(*surf)
|
||||
);
|
||||
}
|
||||
|
||||
// Receive surfaces
|
||||
pointField points;
|
||||
faceList faces;
|
||||
|
||||
for
|
||||
(
|
||||
int slave=Pstream::firstSlave();
|
||||
slave<=Pstream::lastSlave();
|
||||
++slave
|
||||
)
|
||||
{
|
||||
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
|
||||
|
||||
points.clear();
|
||||
faces.clear();
|
||||
|
||||
fromSlave >> points >> faces;
|
||||
|
||||
if (points.size())
|
||||
{
|
||||
multiPiece->SetPiece
|
||||
(
|
||||
slave,
|
||||
Foam::vtk::Tools::Patch::mesh(points, faces)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Slave - send surfaces
|
||||
|
||||
OPstream toMaster
|
||||
(
|
||||
Pstream::commsTypes::scheduled,
|
||||
Pstream::masterNo()
|
||||
);
|
||||
|
||||
if (surf)
|
||||
{
|
||||
toMaster
|
||||
<< surf->points() << surf->faces();
|
||||
}
|
||||
else
|
||||
{
|
||||
toMaster
|
||||
<< pointField() << faceList();
|
||||
}
|
||||
}
|
||||
|
||||
return multiPiece;
|
||||
}
|
||||
|
||||
|
||||
vtkSmartPointer<vtkMultiPieceDataSet>
|
||||
Foam::functionObjects::runTimePostPro::surface::gatherFaceCentres
|
||||
(
|
||||
const polySurface* surf
|
||||
) const
|
||||
{
|
||||
auto multiPiece = vtkSmartPointer<vtkMultiPieceDataSet>::New();
|
||||
multiPiece->SetNumberOfPieces(Pstream::nProcs());
|
||||
|
||||
if (!needsCollective())
|
||||
{
|
||||
// Simple case
|
||||
|
||||
if (surf)
|
||||
{
|
||||
auto dataset = vtkSmartPointer<vtkPolyData>::New();
|
||||
|
||||
auto geom = vtkSmartPointer<vtkPolyData>::New();
|
||||
|
||||
geom->SetPoints(Foam::vtk::Tools::Patch::faceCentres(*surf));
|
||||
geom->SetVerts(Foam::vtk::Tools::identityVertices(surf->nFaces()));
|
||||
|
||||
multiPiece->SetPiece(Pstream::myProcNo(), geom);
|
||||
}
|
||||
}
|
||||
else if (Pstream::master())
|
||||
{
|
||||
// Gather pieces (face centres) on master
|
||||
|
||||
if (surf)
|
||||
{
|
||||
// Add myself
|
||||
|
||||
auto geom = vtkSmartPointer<vtkPolyData>::New();
|
||||
|
||||
geom->SetPoints(Foam::vtk::Tools::Patch::faceCentres(*surf));
|
||||
geom->SetVerts(Foam::vtk::Tools::identityVertices(surf->nFaces()));
|
||||
|
||||
multiPiece->SetPiece(Pstream::myProcNo(), geom);
|
||||
}
|
||||
|
||||
// Receive points
|
||||
pointField points;
|
||||
|
||||
for
|
||||
(
|
||||
int slave=Pstream::firstSlave();
|
||||
slave<=Pstream::lastSlave();
|
||||
++slave
|
||||
)
|
||||
{
|
||||
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
|
||||
|
||||
points.clear();
|
||||
|
||||
fromSlave >> points;
|
||||
|
||||
if (points.size())
|
||||
{
|
||||
multiPiece->SetPiece
|
||||
(
|
||||
slave,
|
||||
Foam::vtk::Tools::Vertices(points)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Slave - send face centres
|
||||
|
||||
OPstream toMaster
|
||||
(
|
||||
Pstream::commsTypes::scheduled,
|
||||
Pstream::masterNo()
|
||||
);
|
||||
|
||||
if (surf)
|
||||
{
|
||||
toMaster << surf->faceCentres();
|
||||
}
|
||||
else
|
||||
{
|
||||
toMaster << pointField();
|
||||
}
|
||||
}
|
||||
|
||||
return multiPiece;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,291 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "foamVtkTools.H"
|
||||
#include "polySurfaceFields.H"
|
||||
#include "polySurfacePointFields.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type, class GeoMeshType>
|
||||
bool Foam::functionObjects::runTimePostPro::surface::addField
|
||||
(
|
||||
vtkDataSet* piece,
|
||||
const Field<Type>& fld,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
if (!piece) return false;
|
||||
|
||||
auto vtkfield = Foam::vtk::Tools::convertFieldToVTK<Type>(fieldName, fld);
|
||||
|
||||
if (piece->GetNumberOfCells() == piece->GetNumberOfPoints())
|
||||
{
|
||||
// Only has verts
|
||||
piece->GetPointData()->AddArray(vtkfield);
|
||||
}
|
||||
else
|
||||
{
|
||||
Foam::vtk::Tools::FieldAccess<GeoMeshType>()(piece)->AddArray(vtkfield);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class Type, class GeoMeshType>
|
||||
bool Foam::functionObjects::runTimePostPro::surface::addDimField
|
||||
(
|
||||
vtkDataSet* piece,
|
||||
const regIOobject* ioptr,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
const auto* fldptr =
|
||||
dynamic_cast<const DimensionedField<Type, GeoMeshType>*>(ioptr);
|
||||
|
||||
if (fldptr)
|
||||
{
|
||||
return addField<Type, GeoMeshType>
|
||||
(
|
||||
piece,
|
||||
fldptr->field(),
|
||||
fieldName
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template<class GeoMeshType>
|
||||
bool Foam::functionObjects::runTimePostPro::surface::addDimField
|
||||
(
|
||||
vtkDataSet* piece,
|
||||
const regIOobject* ioptr,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
return (piece && ioptr) &&
|
||||
(
|
||||
addDimField<scalar, GeoMeshType>
|
||||
(
|
||||
piece, ioptr, fieldName
|
||||
)
|
||||
|| addDimField<vector, GeoMeshType>
|
||||
(
|
||||
piece, ioptr, fieldName
|
||||
)
|
||||
|| addDimField<sphericalTensor, GeoMeshType>
|
||||
(
|
||||
piece, ioptr, fieldName
|
||||
)
|
||||
|| addDimField<symmTensor, GeoMeshType>
|
||||
(
|
||||
piece, ioptr, fieldName
|
||||
)
|
||||
|| addDimField<tensor, GeoMeshType>
|
||||
(
|
||||
piece, ioptr, fieldName
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
template<class Type, class GeoMeshType>
|
||||
bool Foam::functionObjects::runTimePostPro::surface::addDimField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const DimensionedField<Type, GeoMeshType>* fldptr,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
if (!multiPiece)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!needsCollective())
|
||||
{
|
||||
// Simple case (serial-serial, parallel-parallel)
|
||||
|
||||
return fldptr &&
|
||||
addField<Type, GeoMeshType>
|
||||
(
|
||||
multiPiece->GetPiece(Pstream::myProcNo()),
|
||||
fldptr->field(),
|
||||
fieldName
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Gather fields
|
||||
const bool ok = returnReduce((fldptr != nullptr), orOp<bool>());
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
if (fldptr)
|
||||
{
|
||||
// My field data
|
||||
addField<Type, GeoMeshType>
|
||||
(
|
||||
multiPiece->GetPiece(Pstream::myProcNo()),
|
||||
fldptr->field(),
|
||||
fieldName
|
||||
);
|
||||
}
|
||||
|
||||
// Receive field data
|
||||
Field<Type> recv;
|
||||
|
||||
for
|
||||
(
|
||||
int slave=Pstream::firstSlave();
|
||||
slave<=Pstream::lastSlave();
|
||||
++slave
|
||||
)
|
||||
{
|
||||
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
|
||||
|
||||
recv.clear();
|
||||
|
||||
fromSlave
|
||||
>> recv;
|
||||
|
||||
if (recv.size())
|
||||
{
|
||||
addField<Type, GeoMeshType>
|
||||
(
|
||||
multiPiece->GetPiece(slave),
|
||||
recv,
|
||||
fieldName
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Slave - send field data
|
||||
|
||||
OPstream toMaster
|
||||
(
|
||||
Pstream::commsTypes::scheduled,
|
||||
Pstream::masterNo()
|
||||
);
|
||||
|
||||
if (fldptr)
|
||||
{
|
||||
toMaster
|
||||
<< fldptr->field();
|
||||
}
|
||||
else
|
||||
{
|
||||
toMaster
|
||||
<< List<Type>();
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
template<class Type, class GeoMeshType>
|
||||
bool Foam::functionObjects::runTimePostPro::surface::addDimField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const regIOobject* ioptr,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
return addDimField<Type, GeoMeshType>
|
||||
(
|
||||
multiPiece,
|
||||
dynamic_cast<const DimensionedField<Type, GeoMeshType>*>(ioptr),
|
||||
fieldName
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
template<class GeoMeshType>
|
||||
bool Foam::functionObjects::runTimePostPro::surface::addDimField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const regIOobject* ioptr,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
return (multiPiece) &&
|
||||
(
|
||||
addDimField<scalar, GeoMeshType>
|
||||
(
|
||||
multiPiece, ioptr, fieldName
|
||||
)
|
||||
|| addDimField<vector, GeoMeshType>
|
||||
(
|
||||
multiPiece, ioptr, fieldName
|
||||
)
|
||||
|| addDimField<sphericalTensor, GeoMeshType>
|
||||
(
|
||||
multiPiece, ioptr, fieldName
|
||||
)
|
||||
|| addDimField<symmTensor, GeoMeshType>
|
||||
(
|
||||
multiPiece, ioptr, fieldName
|
||||
)
|
||||
|| addDimField<tensor, GeoMeshType>
|
||||
(
|
||||
multiPiece, ioptr, fieldName
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
template<class GeoMeshType>
|
||||
bool Foam::functionObjects::runTimePostPro::surface::addDimField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const polySurface* surf,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
const regIOobject* ioptr =
|
||||
(
|
||||
surf
|
||||
? surf->findFieldObject<GeoMeshType>(fieldName)
|
||||
: nullptr
|
||||
);
|
||||
|
||||
return addDimField<GeoMeshType>(multiPiece, ioptr, fieldName);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,185 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "text.H"
|
||||
#include "stringOps.H"
|
||||
#include "fvMesh.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkCoordinate.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
#include "vtkTextActor.h"
|
||||
#include "vtkTextProperty.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
const Foam::Enum
|
||||
<
|
||||
Foam::functionObjects::runTimePostPro::text::halignType
|
||||
>
|
||||
Foam::functionObjects::runTimePostPro::text::halignTypeNames
|
||||
({
|
||||
{ halignType::LEFT, "left" },
|
||||
{ halignType::CENTER, "center" },
|
||||
{ halignType::CENTER, "centre" },
|
||||
{ halignType::RIGHT, "right" },
|
||||
});
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::text::text
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
geometryBase(parent, dict, colours),
|
||||
string_(dict.get<string>("string")),
|
||||
positions_(),
|
||||
size_(dict.get<scalar>("size")),
|
||||
colour_(nullptr),
|
||||
halign_
|
||||
(
|
||||
halignTypeNames.getOrDefault("halign", dict, halignType::LEFT)
|
||||
),
|
||||
bold_(dict.get<bool>("bold")),
|
||||
italic_(dict.getOrDefault("italic", false)),
|
||||
shadow_(dict.getOrDefault("shadow", false)),
|
||||
timeStamp_(dict.getOrDefault("timeStamp", false))
|
||||
{
|
||||
if (!dict.readIfPresent("positions", positions_))
|
||||
{
|
||||
positions_.resize(1);
|
||||
dict.readEntry("position", positions_.first());
|
||||
}
|
||||
|
||||
// Additional safety
|
||||
if (positions_.empty())
|
||||
{
|
||||
positions_.resize(1);
|
||||
positions_.first() = {0, 0};
|
||||
}
|
||||
|
||||
stringOps::inplaceExpand(string_, dict, true, true);
|
||||
|
||||
if (dict.found("colour"))
|
||||
{
|
||||
colour_.reset(Function1<vector>::New("colour", dict));
|
||||
}
|
||||
else
|
||||
{
|
||||
colour_.reset(colours["text"]->clone().ptr());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::text::~text()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::text::addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (!visible_ || !renderer || !Pstream::master())
|
||||
{
|
||||
// Add text on master only!
|
||||
return;
|
||||
}
|
||||
|
||||
DebugInfo << " Add text: " << string_ << nl;
|
||||
|
||||
// Concatenate string with timeStamp if true
|
||||
string str = string_;
|
||||
if (timeStamp_)
|
||||
{
|
||||
str += " " + geometryBase::parent_.mesh().time().timeName();
|
||||
}
|
||||
|
||||
const vector textColour = colour_->value(position);
|
||||
|
||||
const scalar textOpacity = opacity(position);
|
||||
|
||||
for (const auto& textPosition : positions_)
|
||||
{
|
||||
auto actor = vtkSmartPointer<vtkTextActor>::New();
|
||||
|
||||
actor->SetInput(str.c_str());
|
||||
|
||||
vtkTextProperty* prop = actor->GetTextProperty();
|
||||
|
||||
prop->SetFontFamilyToArial();
|
||||
prop->SetFontSize(size_);
|
||||
prop->SetJustification(int(halign_));
|
||||
prop->SetVerticalJustificationToBottom();
|
||||
prop->SetBold(bold_);
|
||||
prop->SetItalic(italic_);
|
||||
prop->SetShadow(shadow_);
|
||||
|
||||
prop->SetColor(textColour[0], textColour[1], textColour[2]);
|
||||
prop->SetOpacity(textOpacity);
|
||||
|
||||
// Positioning
|
||||
{
|
||||
vtkCoordinate* coord = actor->GetPositionCoordinate();
|
||||
|
||||
coord->SetCoordinateSystemToNormalizedViewport();
|
||||
coord->SetValue(textPosition.first(), textPosition.second());
|
||||
}
|
||||
|
||||
renderer->AddActor2D(actor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimePostPro::text::updateActors
|
||||
(
|
||||
const scalar position
|
||||
)
|
||||
{
|
||||
// Do nothing - all handled by addGeometryToScene
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::text::clear()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,211 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::text
|
||||
|
||||
Description
|
||||
Define text element for runTimePostProcessing
|
||||
|
||||
Example of text object specification:
|
||||
\verbatim
|
||||
text1
|
||||
{
|
||||
string "text to display";
|
||||
position (0.1 0.05);
|
||||
size 18;
|
||||
// halign left; // (left | centre | right)
|
||||
bold yes;
|
||||
// Optional entry
|
||||
|
||||
shadow false;
|
||||
|
||||
// Optionally override default colour
|
||||
// colour (0 1 1);
|
||||
|
||||
// Optional entry
|
||||
timeStamp yes; // Append solution time to string
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Dictionary controls
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
string | Text to display | yes |
|
||||
position | The (x y) viewport position | yes |
|
||||
positions | Multiple (x y) viewport positions | no |
|
||||
size | The font size in points | yes |
|
||||
halign | Text justification (left/centre/ right) | no | left
|
||||
bold | Use bold font | yes |
|
||||
italic | Use italic font | no | false
|
||||
shadow | Add text shadow | no | false
|
||||
colour | Override default text colour | no |
|
||||
timeStamp | Append solution timeName to string | no | false
|
||||
\endtable
|
||||
|
||||
Inherited controls
|
||||
\table
|
||||
Property | Description | Required | Default
|
||||
visible | Display the object | no | true
|
||||
opacity | Object opacity | no | 1.0
|
||||
\endtable
|
||||
|
||||
Note
|
||||
The string text is expanded on input using stringOps::inplaceExpand()
|
||||
to expand dictionary and environment variable entries.
|
||||
|
||||
SourceFiles
|
||||
text.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_text_H
|
||||
#define functionObjects_runTimePostPro_text_H
|
||||
|
||||
#include "geometryBase.H"
|
||||
#include "Tuple2.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Forward Declarations
|
||||
class vtkRenderer;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class text Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class text
|
||||
:
|
||||
public geometryBase
|
||||
{
|
||||
public:
|
||||
|
||||
// Public Enumerations
|
||||
|
||||
//- Horizontal alignment type. Values to match VTK definitions
|
||||
enum halignType
|
||||
{
|
||||
LEFT = 0, //!< Left-justified text - default ("left")
|
||||
CENTER = 1, //!< Centred text ("center", "centre")
|
||||
RIGHT = 2 //!< Right-justified text ("right")
|
||||
};
|
||||
|
||||
//- Horizontal alignment names (includes "center" and "centre")
|
||||
static const Enum<halignType> halignTypeNames;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected Data
|
||||
|
||||
//- Text
|
||||
string string_;
|
||||
|
||||
//- Position(s)
|
||||
List<Tuple2<scalar, scalar>> positions_;
|
||||
|
||||
//- Font size
|
||||
scalar size_;
|
||||
|
||||
//- Text colour
|
||||
autoPtr<Function1<vector>> colour_;
|
||||
|
||||
//- Horizontal alignment
|
||||
halignType halign_;
|
||||
|
||||
//- Bold flag
|
||||
bool bold_;
|
||||
|
||||
//- Italic flag
|
||||
bool italic_;
|
||||
|
||||
//- Shadow flag
|
||||
bool shadow_;
|
||||
|
||||
//- Time stamp flag
|
||||
bool timeStamp_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- No copy construct
|
||||
text(const text&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const text&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
text
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~text();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Add text to scene
|
||||
virtual void addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Update actors
|
||||
virtual void updateActors(const scalar position);
|
||||
|
||||
//- Clear files used to create the object(s) - no-op
|
||||
virtual bool clear();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,146 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "volumeFilter.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkCellData.h"
|
||||
#include "vtkCellDataToPointData.h"
|
||||
#include "vtkCompositeDataGeometryFilter.h"
|
||||
#include "vtkCompositeDataSet.h"
|
||||
#include "vtkCompositePolyDataMapper.h"
|
||||
#include "vtkMultiPieceDataSet.h"
|
||||
#include "vtkPointData.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimePostPro::volumeFilter::volumeFilter
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
)
|
||||
:
|
||||
surface(parent, dict, colours)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
vtkSmartPointer<vtkMultiPieceDataSet>
|
||||
Foam::functionObjects::runTimePostPro::volumeFilter::mesh
|
||||
(
|
||||
Foam::vtk::vtuAdaptor& adaptor
|
||||
) const
|
||||
{
|
||||
auto multiPiece = vtkSmartPointer<vtkMultiPieceDataSet>::New();
|
||||
|
||||
multiPiece->SetNumberOfPieces(Pstream::nProcs());
|
||||
multiPiece->SetPiece
|
||||
(
|
||||
Pstream::myProcNo(),
|
||||
adaptor.internal(parent().mesh())
|
||||
);
|
||||
|
||||
return multiPiece;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimePostPro::volumeFilter::addDimField
|
||||
(
|
||||
vtkDataSet* piece,
|
||||
const vtk::vtuAdaptor& adaptor,
|
||||
const regIOobject* ioptr,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
return (piece && ioptr) &&
|
||||
(
|
||||
addDimField<scalar>
|
||||
(
|
||||
piece, adaptor, ioptr, fieldName
|
||||
)
|
||||
|| addDimField<vector>
|
||||
(
|
||||
piece, adaptor, ioptr, fieldName
|
||||
)
|
||||
|| addDimField<sphericalTensor>
|
||||
(
|
||||
piece, adaptor, ioptr, fieldName
|
||||
)
|
||||
|| addDimField<symmTensor>
|
||||
(
|
||||
piece, adaptor, ioptr, fieldName
|
||||
)
|
||||
|| addDimField<tensor>
|
||||
(
|
||||
piece, adaptor, ioptr, fieldName
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
int Foam::functionObjects::runTimePostPro::volumeFilter::addDimField
|
||||
(
|
||||
vtkMultiPieceDataSet* piece,
|
||||
const vtk::vtuAdaptor& adaptor,
|
||||
const regIOobject* ioptr,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
return (piece && ioptr) &&
|
||||
(
|
||||
addDimField<scalar>
|
||||
(
|
||||
piece, adaptor, ioptr, fieldName
|
||||
)
|
||||
|| addDimField<vector>
|
||||
(
|
||||
piece, adaptor, ioptr, fieldName
|
||||
)
|
||||
|| addDimField<sphericalTensor>
|
||||
(
|
||||
piece, adaptor, ioptr, fieldName
|
||||
)
|
||||
|| addDimField<symmTensor>
|
||||
(
|
||||
piece, adaptor, ioptr, fieldName
|
||||
)
|
||||
|| addDimField<tensor>
|
||||
(
|
||||
piece, adaptor, ioptr, fieldName
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,164 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimePostPro::volumeFilter
|
||||
|
||||
Description
|
||||
Visualisation of OpenFOAM volume fields as surface data using
|
||||
a VTK filter cascade.
|
||||
|
||||
Note
|
||||
Since this filter includes an OpenFOAM/VTK adaptor level,
|
||||
it is ill-suited to mismatches in data parallelization.
|
||||
If OpenFOAM is running in parallel but VTK is not, it would be rather
|
||||
expensive to collect all the data on the master node for this filter.
|
||||
That approach is acceptable for smaller amounts of data, but do not
|
||||
allow for volume meshes.
|
||||
|
||||
SourceFiles
|
||||
volumeFilter.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimePostPro_volumeFilter_H
|
||||
#define functionObjects_runTimePostPro_volumeFilter_H
|
||||
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "surface.H"
|
||||
#include "foamVtkVtuAdaptor.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
class vtkDataSet;
|
||||
class vtkMultiPieceDataSet;
|
||||
template<class T> class vtkSmartPointer;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace vtk
|
||||
{
|
||||
class vtuAdaptor;
|
||||
}
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimePostPro
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class volumeFilter Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class volumeFilter
|
||||
:
|
||||
public surface
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Return a vtu mesh with addressing information stored in adaptor
|
||||
vtkSmartPointer<vtkMultiPieceDataSet> mesh
|
||||
(
|
||||
Foam::vtk::vtuAdaptor& adaptor
|
||||
) const;
|
||||
|
||||
|
||||
bool addDimField
|
||||
(
|
||||
vtkDataSet* piece,
|
||||
const vtk::vtuAdaptor& adaptor,
|
||||
const regIOobject* ioptr,
|
||||
const word& fieldName
|
||||
) const;
|
||||
|
||||
int addDimField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const vtk::vtuAdaptor& adaptor,
|
||||
const regIOobject* ioptr,
|
||||
const word& fieldName
|
||||
) const;
|
||||
|
||||
template<class Type>
|
||||
bool addDimField
|
||||
(
|
||||
vtkDataSet* piece,
|
||||
const vtk::vtuAdaptor& adaptor,
|
||||
const regIOobject* ioptr,
|
||||
const word& fieldName
|
||||
) const;
|
||||
|
||||
template<class Type>
|
||||
int addDimField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const vtk::vtuAdaptor& adaptor,
|
||||
const regIOobject* ioptr,
|
||||
const word& fieldName
|
||||
) const;
|
||||
|
||||
|
||||
//- No copy construct
|
||||
volumeFilter(const volumeFilter&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const volumeFilter&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
volumeFilter
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<Function1<vector>>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~volumeFilter() = default;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimePostPro
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "volumeFilterTemplates.C"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,122 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "volumeFilter.H"
|
||||
#include "fvMesh.H"
|
||||
#include "volFields.H"
|
||||
#include "foamVtkTools.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkCellData.h"
|
||||
#include "vtkMultiPieceDataSet.h"
|
||||
#include "vtkPointData.h"
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
bool Foam::functionObjects::runTimePostPro::volumeFilter::addDimField
|
||||
(
|
||||
vtkDataSet* piece,
|
||||
const vtk::vtuAdaptor& adaptor,
|
||||
const regIOobject* ioptr,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
vtkSmartPointer<vtkFloatArray> vtkdata;
|
||||
|
||||
const auto* dimptr =
|
||||
dynamic_cast<const DimensionedField<Type, volMesh>*>(ioptr);
|
||||
|
||||
if (dimptr && !vtkdata)
|
||||
{
|
||||
vtkdata = adaptor.convertField(*dimptr);
|
||||
}
|
||||
|
||||
const auto* volptr =
|
||||
dynamic_cast<const GeometricField<Type, fvPatchField, volMesh>*>(ioptr);
|
||||
|
||||
if (volptr && !vtkdata)
|
||||
{
|
||||
vtkdata = adaptor.convertField(volptr->internalField());
|
||||
}
|
||||
|
||||
if (vtkdata)
|
||||
{
|
||||
piece->GetCellData()->AddArray(vtkdata);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
int Foam::functionObjects::runTimePostPro::volumeFilter::addDimField
|
||||
(
|
||||
vtkMultiPieceDataSet* multiPiece,
|
||||
const vtk::vtuAdaptor& adaptor,
|
||||
const regIOobject* ioptr,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
if (!multiPiece)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const int nCmpt(pTraits<Type>::nComponents);
|
||||
|
||||
if (!needsCollective())
|
||||
{
|
||||
// Simple case (serial-serial, parallel-parallel)
|
||||
|
||||
auto piece = multiPiece->GetPiece(Pstream::myProcNo());
|
||||
|
||||
if
|
||||
(
|
||||
addDimField<Type>
|
||||
(
|
||||
piece,
|
||||
adaptor,
|
||||
ioptr,
|
||||
fieldName
|
||||
)
|
||||
)
|
||||
{
|
||||
return nCmpt;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user