mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Initial commit of new runTimePostProcessing function object
- Allows generation of images (currently PNG files) during the run - ... or afterwards by invoking the execFlowFunctionObjects utility - Wrapper around VTK functionality - Support for objects: - text - points (glyphs: sphere, arrow) - lines (tubes) - surfaces (wireframe, shaded, combination) - Colour using: - user-defined - field values (several colour maps availale) - For image sequences: - dynamic views (camera movement) - objects can appear/disappear using opacity - Building - VTK dependency v6+ - satisfied using ParaView from ThirdParty directory - or separate VTK installation
This commit is contained in:
4
src/postProcessing/functionObjects/graphics/Allwmake
Executable file
4
src/postProcessing/functionObjects/graphics/Allwmake
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
cd ${0%/*} || exit 1 # Run from this directory
|
||||
|
||||
./runTimePostProcessing/Allwmake
|
||||
12
src/postProcessing/functionObjects/graphics/runTimePostProcessing/Allwclean
Executable file
12
src/postProcessing/functionObjects/graphics/runTimePostProcessing/Allwclean
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
cd ${0%/*} || exit 1 # Run from this directory
|
||||
|
||||
# Source the wmake functions
|
||||
. $WM_DIR/scripts/wmakeFunctions
|
||||
|
||||
(
|
||||
# Where are the generated files stored?
|
||||
findObjectDir dummy.C
|
||||
depDir="$objectsDir"
|
||||
rm -rf "$depDir" > /dev/null 2>&1
|
||||
)
|
||||
28
src/postProcessing/functionObjects/graphics/runTimePostProcessing/Allwmake
Executable file
28
src/postProcessing/functionObjects/graphics/runTimePostProcessing/Allwmake
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
cd ${0%/*} || exit 1 # Run from this directory
|
||||
|
||||
# Source the wmake functions
|
||||
. $WM_DIR/scripts/wmakeFunctions
|
||||
|
||||
# Store current directory
|
||||
sourceDir=$PWD
|
||||
|
||||
# Where are any generated files stored?
|
||||
findObjectDir dummy.C
|
||||
depDir="$objectsDir"
|
||||
|
||||
if [ -d "$VTK_DIR" -o -d "$ParaView_DIR" ]
|
||||
then
|
||||
# ensure CMake gets the correct C++ compiler
|
||||
[ -n "$WM_CXX" ] && export CXX="$WM_CXX"
|
||||
[ -n "$WM_CC" ] && export CC="$WM_CC"
|
||||
|
||||
(mkdir -p $depDir && cd $depDir && cmake $sourceDir && make)
|
||||
else
|
||||
echo "ERROR: Build of $PWD requires a valid VTK installation which"
|
||||
echo " can be supplied either by ParaView by VTK. In case of"
|
||||
echo " - ParaView : export the ParaView_DIR environment variable"
|
||||
echo " - VTK : export the VTK_DIR variable"
|
||||
fi
|
||||
|
||||
# ----------------------------------------------------------------- end-of-file
|
||||
@ -0,0 +1,84 @@
|
||||
include(${VTK_USE_FILE})
|
||||
|
||||
if(VTK_LIBRARIES)
|
||||
message("Found VTK LIBRARIES: " ${VTK_USE_FILE})
|
||||
endif()
|
||||
|
||||
if(${VTK_VERSION} VERSION_GREATER "6")
|
||||
message("VTK version: " ${VTK_VERSION})
|
||||
else()
|
||||
message(FATAL_ERROR " VTK6 required")
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
$ENV{WM_PROJECT_DIR}/src/OpenFOAM/lnInclude
|
||||
$ENV{WM_PROJECT_DIR}/src/OSspecific/$ENV{WM_OSTYPE}/lnInclude
|
||||
$ENV{WM_PROJECT_DIR}/src/triSurface/lnInclude
|
||||
$ENV{WM_PROJECT_DIR}/src/finiteVolume/lnInclude
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
link_directories(
|
||||
$ENV{FOAM_LIBBIN}
|
||||
$ENV{FOAM_EXT_LIBBIN}
|
||||
)
|
||||
|
||||
add_definitions(
|
||||
-DWM_$ENV{WM_PRECISION_OPTION} -DNoRepository
|
||||
-DWM_LABEL_SIZE=$ENV{WM_LABEL_SIZE}
|
||||
)
|
||||
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
|
||||
set(CMAKE_CXX_FLAGS_DEBUG
|
||||
"-g -O0 -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wno-overloaded-virtual"
|
||||
)
|
||||
set(CMAKE_C_FLAGS_DEBUG "-g -O0")
|
||||
|
||||
set(CMAKE_CXX_FLAGS_RELEASE
|
||||
"-O3 -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wno-overloaded-virtual")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O3")
|
||||
|
||||
# Set output library destination to plugin directory
|
||||
set(LIBRARY_OUTPUT_PATH $ENV{FOAM_LIBBIN}
|
||||
CACHE INTERNAL
|
||||
""
|
||||
)
|
||||
|
||||
file(GLOB SOURCE_FILES
|
||||
fieldVisualisationBase.C
|
||||
functionObjectCloud.C
|
||||
functionObjectLine.C
|
||||
functionObjectSurface.C
|
||||
geometryBase.C
|
||||
geometrySurface.C
|
||||
pathline.C
|
||||
pointData.C
|
||||
runTimePostProcessing.C
|
||||
runTimePostProcessingFunctionObject.C
|
||||
scene.C
|
||||
surface.C
|
||||
text.C
|
||||
)
|
||||
|
||||
set(OPENFOAM_LIBRARIES
|
||||
OpenFOAM
|
||||
triSurface
|
||||
finiteVolume
|
||||
)
|
||||
|
||||
add_library(
|
||||
runTimePostProcessing
|
||||
SHARED
|
||||
${SOURCE_FILES}
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
runTimePostProcessing
|
||||
${VTK_LIBRARIES}
|
||||
${OPENFOAM_LIBRARIES}
|
||||
)
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
@ -0,0 +1,23 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(runTimePostProcessing)
|
||||
|
||||
if (EXISTS $ENV{VTK_DIR})
|
||||
message("Building with VTK from $ENV{VTK_DIR}")
|
||||
find_package(VTK REQUIRED HINTS $ENV{VTK_DIR})
|
||||
include(${VTK_USE_FILE})
|
||||
|
||||
else (EXISTS $ENV{ParaView_DIR})
|
||||
message("Building with Paraview from $ENV{ParaView_DIR}")
|
||||
find_package(ParaView REQUIRED)
|
||||
include(${VTK_USE_FILE})
|
||||
|
||||
set(
|
||||
VTK_VERSION
|
||||
"${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}.${VTK_BUILD_VERSION}"
|
||||
)
|
||||
endif (EXISTS $ENV{VTK_DIR})
|
||||
|
||||
include(CMakeLists-Common.txt)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
@ -0,0 +1,49 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Typedef
|
||||
Foam::IOrunTimePostProcessing
|
||||
|
||||
Description
|
||||
Instance of the generic IOOutputFilter for runTimePostProcessing.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef IOrunTimePostProcessing_H
|
||||
#define IOrunTimePostProcessing_H
|
||||
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "IOOutputFilter.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
typedef IOOutputFilter<runTimePostProcessing> IOrunTimePostProcessing;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,517 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "fieldVisualisationBase.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkArrowSource.h"
|
||||
#include "vtkColorTransferFunction.h"
|
||||
#include "vtkFloatArray.h"
|
||||
#include "vtkGlyph3D.h"
|
||||
#include "vtkLookupTable.h"
|
||||
#include "vtkPointData.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkScalarBarActor.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
#include "vtkSphereSource.h"
|
||||
#include "vtkTextActor.h"
|
||||
#include "vtkTextProperty.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
template<>
|
||||
const char* NamedEnum<fieldVisualisationBase::colourByType, 2>::names[] =
|
||||
{
|
||||
"colour",
|
||||
"field"
|
||||
};
|
||||
|
||||
template<>
|
||||
const char* NamedEnum<fieldVisualisationBase::colourMapType, 4>::names[] =
|
||||
{
|
||||
"rainbow",
|
||||
"blueWhiteRed",
|
||||
"fire",
|
||||
"greyscale"
|
||||
};
|
||||
}
|
||||
|
||||
const Foam::NamedEnum<Foam::fieldVisualisationBase::colourByType, 2>
|
||||
Foam::fieldVisualisationBase::colourByTypeNames;
|
||||
|
||||
const Foam::NamedEnum<Foam::fieldVisualisationBase::colourMapType, 4>
|
||||
Foam::fieldVisualisationBase::colourMapTypeNames;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::fieldVisualisationBase::setColourMap(vtkLookupTable* lut) const
|
||||
{
|
||||
label nColours = 256;
|
||||
|
||||
lut->SetNumberOfColors(nColours);
|
||||
|
||||
vtkSmartPointer<vtkColorTransferFunction> ctf =
|
||||
vtkSmartPointer<vtkColorTransferFunction>::New();
|
||||
|
||||
switch (colourMap_)
|
||||
{
|
||||
case cmRainbow:
|
||||
{
|
||||
ctf->SetColorSpaceToHSV();
|
||||
ctf->AddRGBPoint(0, 0, 0, 1);
|
||||
ctf->AddRGBPoint(0.5, 0, 1, 0);
|
||||
ctf->AddRGBPoint(1, 1, 0, 0);
|
||||
break;
|
||||
}
|
||||
case cmBlueWhiteRed:
|
||||
{
|
||||
// Values taken from ParaView settings
|
||||
ctf->SetColorSpaceToDiverging();
|
||||
ctf->AddRGBPoint(0.0, 0.231373, 0.298039, 0.752941);
|
||||
ctf->AddRGBPoint(0.5, 0.865003, 0.865003, 0.865003);
|
||||
ctf->AddRGBPoint(1.0, 0.705882, 0.0156863, 0.14902);
|
||||
break;
|
||||
}
|
||||
case cmFire:
|
||||
{
|
||||
// Values taken from ParaView settings
|
||||
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);
|
||||
break;
|
||||
}
|
||||
case cmGreyscale:
|
||||
{
|
||||
ctf->SetColorSpaceToRGB();
|
||||
ctf->AddRGBPoint(0, 0, 0, 0);
|
||||
ctf->AddRGBPoint(1, 1, 1, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (label i = 0; i < nColours; i++)
|
||||
{
|
||||
double* c = ctf->GetColor(scalar(i)/scalar(nColours));
|
||||
lut->SetTableValue(i, c[0], c[1], c[2], 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::fieldVisualisationBase::addScalarBar
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer,
|
||||
vtkLookupTable* lut
|
||||
) const
|
||||
{
|
||||
// add scalar bar legend
|
||||
if (!scalarBar_.visible_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkScalarBarActor> sbar =
|
||||
vtkSmartPointer<vtkScalarBarActor>::New();
|
||||
sbar->SetLookupTable(lut);
|
||||
sbar->SetNumberOfLabels(scalarBar_.numberOfLabels_);
|
||||
|
||||
const vector textColour = colours_["text"]->value(position);
|
||||
|
||||
// workaround to supply our own scalarbar title
|
||||
vtkSmartPointer<vtkTextActor> titleActor =
|
||||
vtkSmartPointer<vtkTextActor>::New();
|
||||
sbar->SetTitle(" ");
|
||||
titleActor->SetInput(scalarBar_.title_.c_str());
|
||||
titleActor->GetTextProperty()->SetFontFamilyToArial();
|
||||
titleActor->GetTextProperty()->SetFontSize(3*scalarBar_.fontSize_);
|
||||
titleActor->GetTextProperty()->SetJustificationToCentered();
|
||||
titleActor->GetTextProperty()->SetVerticalJustificationToBottom();
|
||||
titleActor->GetTextProperty()->BoldOn();
|
||||
titleActor->GetTextProperty()->ItalicOff();
|
||||
titleActor->GetTextProperty()->SetColor
|
||||
(
|
||||
textColour[0],
|
||||
textColour[1],
|
||||
textColour[2]
|
||||
);
|
||||
titleActor->GetPositionCoordinate()->
|
||||
SetCoordinateSystemToNormalizedViewport();
|
||||
|
||||
/*
|
||||
sbar->SetTitle(scalarBar_.title_.c_str());
|
||||
sbar->GetTitleTextProperty()->SetColor
|
||||
(
|
||||
textColour[0],
|
||||
textColour[1],
|
||||
textColour[2]
|
||||
);
|
||||
sbar->GetTitleTextProperty()->SetFontSize(scalarBar_.fontSize_);
|
||||
sbar->GetTitleTextProperty()->ShadowOff();
|
||||
sbar->GetTitleTextProperty()->BoldOn();
|
||||
sbar->GetTitleTextProperty()->ItalicOff();
|
||||
*/
|
||||
|
||||
sbar->GetLabelTextProperty()->SetColor
|
||||
(
|
||||
textColour[0],
|
||||
textColour[1],
|
||||
textColour[2]
|
||||
);
|
||||
sbar->GetLabelTextProperty()->SetFontSize(scalarBar_.fontSize_);
|
||||
sbar->GetLabelTextProperty()->ShadowOff();
|
||||
sbar->GetLabelTextProperty()->BoldOff();
|
||||
sbar->GetLabelTextProperty()->ItalicOff();
|
||||
sbar->SetLabelFormat(scalarBar_.labelFormat_.c_str());
|
||||
|
||||
sbar->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
|
||||
sbar->GetPositionCoordinate()->SetValue
|
||||
(
|
||||
scalarBar_.position_.first(),
|
||||
scalarBar_.position_.second()
|
||||
);
|
||||
if (scalarBar_.vertical_)
|
||||
{
|
||||
sbar->SetOrientationToVertical();
|
||||
sbar->SetWidth(0.1);
|
||||
sbar->SetHeight(0.75);
|
||||
sbar->SetTextPositionToSucceedScalarBar();
|
||||
}
|
||||
else
|
||||
{
|
||||
sbar->SetOrientationToHorizontal();
|
||||
|
||||
// adjustments since not using scalarbar title property
|
||||
sbar->SetWidth(0.75);
|
||||
sbar->SetHeight(0.07);
|
||||
sbar->SetBarRatio(0.5);
|
||||
// sbar->SetHeight(0.1);
|
||||
// sbar->SetTitleRatio(0.01);
|
||||
sbar->SetTextPositionToPrecedeScalarBar();
|
||||
}
|
||||
|
||||
titleActor->GetPositionCoordinate()->SetValue
|
||||
(
|
||||
scalarBar_.position_.first() + 0.5*sbar->GetWidth(),
|
||||
scalarBar_.position_.second() + sbar->GetHeight()
|
||||
);
|
||||
|
||||
// sbar->DrawFrameOn();
|
||||
// sbar->DrawBackgroundOn();
|
||||
// sbar->UseOpacityOff();
|
||||
// sbar->VisibilityOff();
|
||||
sbar->VisibilityOn();
|
||||
|
||||
renderer->AddActor(sbar);
|
||||
renderer->AddActor2D(titleActor);
|
||||
}
|
||||
|
||||
|
||||
void Foam::fieldVisualisationBase::setField
|
||||
(
|
||||
const scalar position,
|
||||
const word& colourFieldName,
|
||||
vtkPolyDataMapper* mapper,
|
||||
vtkRenderer* renderer
|
||||
) const
|
||||
{
|
||||
mapper->InterpolateScalarsBeforeMappingOn();
|
||||
|
||||
switch (colourBy_)
|
||||
{
|
||||
case cbColour:
|
||||
{
|
||||
mapper->ScalarVisibilityOff();
|
||||
break;
|
||||
}
|
||||
case cbField:
|
||||
{
|
||||
// create look-up table for colours
|
||||
vtkSmartPointer<vtkLookupTable> lut =
|
||||
vtkSmartPointer<vtkLookupTable>::New();
|
||||
setColourMap(lut);
|
||||
lut->SetVectorMode(vtkScalarsToColors::MAGNITUDE);
|
||||
|
||||
// configure the mapper
|
||||
mapper->SelectColorArray(colourFieldName.c_str());
|
||||
mapper->SetScalarRange(range_.first(), range_.second());
|
||||
mapper->SetScalarModeToUsePointFieldData();
|
||||
|
||||
mapper->SetColorModeToMapScalars();
|
||||
mapper->SetLookupTable(lut);
|
||||
mapper->ScalarVisibilityOn();
|
||||
|
||||
// add the bar
|
||||
addScalarBar(position, renderer, lut);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mapper->Modified();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Foam::fieldVisualisationBase::addGlyphs
|
||||
(
|
||||
const scalar position,
|
||||
const word& scaleFieldName,
|
||||
const word& colourFieldName,
|
||||
const scalar maxGlyphLength,
|
||||
vtkPolyData* data,
|
||||
vtkActor* actor,
|
||||
vtkRenderer* renderer
|
||||
) const
|
||||
{
|
||||
vtkSmartPointer<vtkGlyph3D> glyph = vtkSmartPointer<vtkGlyph3D>::New();
|
||||
vtkSmartPointer<vtkPolyDataMapper> glyphMapper =
|
||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
glyphMapper->SetInputConnection(glyph->GetOutputPort());
|
||||
|
||||
glyph->SetInputData(data);
|
||||
glyph->ScalingOn();
|
||||
bool ok = true;
|
||||
|
||||
label nComponents =
|
||||
data->GetPointData()->GetArray(scaleFieldName.c_str())
|
||||
->GetNumberOfComponents();
|
||||
|
||||
if (nComponents == 1)
|
||||
{
|
||||
vtkSmartPointer<vtkSphereSource> 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)
|
||||
{
|
||||
double range[2];
|
||||
|
||||
// can use values to find range
|
||||
// vtkDataArray* values =
|
||||
// data->GetPointData()->GetScalars(scaleFieldName.c_str());
|
||||
// values->GetRange(range);
|
||||
|
||||
// set range accoding to user-supplied limits
|
||||
range[0] = range_.first();
|
||||
range[1] = range_.second();
|
||||
glyph->ClampingOn();
|
||||
glyph->SetRange(range);
|
||||
|
||||
// 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, // scalars
|
||||
0,
|
||||
0,
|
||||
vtkDataObject::FIELD_ASSOCIATION_POINTS,
|
||||
scaleFieldName.c_str()
|
||||
);
|
||||
}
|
||||
else if (nComponents == 3)
|
||||
{
|
||||
vtkSmartPointer<vtkArrowSource> 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)
|
||||
{
|
||||
vtkDataArray* values =
|
||||
data->GetPointData()->GetVectors(scaleFieldName.c_str());
|
||||
double range[6];
|
||||
values->GetRange(range);
|
||||
|
||||
/*
|
||||
// attempt to set range for vectors...
|
||||
scalar x0 = sqrt(sqr(range_.first())/3.0);
|
||||
scalar x1 = sqrt(sqr(range_.second())/3.0);
|
||||
range[0] = x0;
|
||||
range[1] = x0;
|
||||
range[2] = x0;
|
||||
range[3] = x1;
|
||||
range[4] = x1;
|
||||
range[5] = x1;
|
||||
*/
|
||||
glyph->ClampingOn();
|
||||
glyph->SetRange(range);
|
||||
glyph->SetScaleFactor(maxGlyphLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
glyph->SetScaleFactor(1);
|
||||
}
|
||||
glyph->SetScaleModeToScaleByVector();
|
||||
glyph->OrientOn();
|
||||
glyph->SetVectorModeToUseVector();
|
||||
glyph->SetColorModeToColorByVector();
|
||||
glyph->SetInputArrayToProcess
|
||||
(
|
||||
1, // vectors
|
||||
0,
|
||||
0,
|
||||
vtkDataObject::FIELD_ASSOCIATION_POINTS,
|
||||
scaleFieldName.c_str()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"void Foam::fieldVisualisationBase::addGlyphs"
|
||||
"("
|
||||
"const scalar, "
|
||||
"const word&, "
|
||||
"const word&, "
|
||||
"const scalar, "
|
||||
"vtkPolyData*, "
|
||||
"vtkActor*, "
|
||||
"vtkRenderer*"
|
||||
") const"
|
||||
)
|
||||
<< "Glyphs can only be added to " << pTraits<scalar>::typeName
|
||||
<< " and " << pTraits<vector>::typeName << " fields. "
|
||||
<< " Field " << scaleFieldName << " has " << nComponents
|
||||
<< " components" << endl;
|
||||
|
||||
ok = false;
|
||||
}
|
||||
|
||||
if (ok)
|
||||
{
|
||||
glyph->Update();
|
||||
|
||||
setField(position, colourFieldName, glyphMapper, renderer);
|
||||
|
||||
glyphMapper->Update();
|
||||
|
||||
actor->SetMapper(glyphMapper);
|
||||
|
||||
renderer->AddActor(actor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fieldVisualisationBase::fieldVisualisationBase
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
)
|
||||
:
|
||||
parent_(parent),
|
||||
colours_(colours),
|
||||
fieldName_(dict.lookup("fieldName")),
|
||||
colourBy_(cbColour),
|
||||
colourMap_(cmRainbow),
|
||||
range_()
|
||||
{
|
||||
colourBy_ = colourByTypeNames.read(dict.lookup("colourBy"));
|
||||
|
||||
switch (colourBy_)
|
||||
{
|
||||
case cbColour:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case cbField:
|
||||
{
|
||||
dict.lookup("range") >> range_;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (dict.found("colourMap"))
|
||||
{
|
||||
colourMap_ = colourMapTypeNames.read(dict.lookup("colourMap"));
|
||||
}
|
||||
|
||||
const dictionary& sbarDict = dict.subDict("scalarBar");
|
||||
sbarDict.lookup("visible") >> scalarBar_.visible_;
|
||||
if (scalarBar_.visible_)
|
||||
{
|
||||
sbarDict.lookup("vertical") >> scalarBar_.vertical_;
|
||||
sbarDict.lookup("position") >> scalarBar_.position_;
|
||||
sbarDict.lookup("title") >> scalarBar_.title_;
|
||||
sbarDict.lookup("fontSize") >> scalarBar_.fontSize_;
|
||||
sbarDict.lookup("labelFormat") >> scalarBar_.labelFormat_;
|
||||
sbarDict.lookup("numberOfLabels") >> scalarBar_.numberOfLabels_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fieldVisualisationBase::~fieldVisualisationBase()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::HashPtrTable<Foam::DataEntry<Foam::vector>, Foam::word>&
|
||||
Foam::fieldVisualisationBase::colours() const
|
||||
{
|
||||
return colours_;
|
||||
}
|
||||
|
||||
|
||||
const Foam::word& Foam::fieldVisualisationBase::fieldName() const
|
||||
{
|
||||
return fieldName_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,216 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::fieldVisualisationBase
|
||||
|
||||
Description
|
||||
|
||||
SourceFiles
|
||||
fieldVisualisationBase.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef fieldVisualisationBase_H
|
||||
#define fieldVisualisationBase_H
|
||||
|
||||
#include "dictionary.H"
|
||||
#include "Tuple2.H"
|
||||
#include "NamedEnum.H"
|
||||
#include "vector.H"
|
||||
#include "HashPtrTable.H"
|
||||
#include "DataEntry.H"
|
||||
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
class vtkActor;
|
||||
class vtkLookupTable;
|
||||
class vtkPolyData;
|
||||
class vtkPolyDataMapper;
|
||||
class vtkRenderer;
|
||||
|
||||
|
||||
class vtkMapper;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class runTimePostProcessing;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class fieldVisualisationBase Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class fieldVisualisationBase
|
||||
{
|
||||
public:
|
||||
|
||||
// Public enumerations
|
||||
|
||||
enum colourByType
|
||||
{
|
||||
cbColour,
|
||||
cbField
|
||||
};
|
||||
|
||||
static const NamedEnum<colourByType, 2> colourByTypeNames;
|
||||
|
||||
enum colourMapType
|
||||
{
|
||||
cmRainbow,
|
||||
cmBlueWhiteRed,
|
||||
cmFire,
|
||||
cmGreyscale
|
||||
};
|
||||
|
||||
static const NamedEnum<colourMapType, 4> colourMapTypeNames;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
|
||||
//- Reference to the parent function object
|
||||
const runTimePostProcessing& parent_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
fieldVisualisationBase(const fieldVisualisationBase&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const fieldVisualisationBase&);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
struct scalarBar
|
||||
{
|
||||
bool visible_;
|
||||
bool vertical_;
|
||||
Tuple2<scalar, scalar> position_;
|
||||
string title_;
|
||||
label fontSize_;
|
||||
string labelFormat_;
|
||||
label numberOfLabels_;
|
||||
};
|
||||
|
||||
//- Colours
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours_;
|
||||
|
||||
//- Field name
|
||||
word fieldName_;
|
||||
|
||||
//- Colour by type
|
||||
colourByType colourBy_;
|
||||
|
||||
//- Colour map type
|
||||
colourMapType colourMap_;
|
||||
|
||||
//- Range of values
|
||||
Tuple2<scalar, scalar> range_;
|
||||
|
||||
//- Scalar bar
|
||||
scalarBar scalarBar_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Set the colour map
|
||||
void setColourMap(vtkLookupTable* lut) const;
|
||||
|
||||
//- Add scalar bar 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,
|
||||
vtkPolyDataMapper* mapper,
|
||||
vtkRenderer* renderer
|
||||
) const;
|
||||
|
||||
//- Add glyphs
|
||||
void addGlyphs
|
||||
(
|
||||
const scalar position,
|
||||
const word& scaleFieldName,
|
||||
const word& colourFieldName,
|
||||
const scalar maxGlyphLength,
|
||||
vtkPolyData* data,
|
||||
vtkActor* actor,
|
||||
vtkRenderer* renderer
|
||||
) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
fieldVisualisationBase
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~fieldVisualisationBase();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- Return the colours
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours() const;
|
||||
|
||||
//- Return the field name
|
||||
const word& fieldName() const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,157 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "functionObjectCloud.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkPolyDataReader.h"
|
||||
#include "vtkProperty.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(functionObjectCloud, 0);
|
||||
addToRunTimeSelectionTable(pointData, functionObjectCloud, dictionary);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjectCloud::functionObjectCloud
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
)
|
||||
:
|
||||
pointData(parent, dict, colours),
|
||||
fieldVisualisationBase(parent, dict, colours),
|
||||
cloudName_(dict.lookup("cloudName")),
|
||||
functionObject_(dict.lookup("functionObject")),
|
||||
colourFieldName_(dict.lookup("colourFieldName")),
|
||||
actor_()
|
||||
{
|
||||
actor_ = vtkSmartPointer<vtkActor>::New();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjectCloud::~functionObjectCloud()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjectCloud::addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (!visible_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const dictionary& cloudDict =
|
||||
geometryBase::parent_.obr().lookupObject<IOdictionary>
|
||||
(
|
||||
cloudName_ + "OutputProperties"
|
||||
);
|
||||
|
||||
fileName fName;
|
||||
if (cloudDict.found("cloudFunctionObject"))
|
||||
{
|
||||
const dictionary& foDict = cloudDict.subDict("cloudFunctionObject");
|
||||
if (foDict.found(functionObject_))
|
||||
{
|
||||
foDict.subDict(functionObject_).readIfPresent("file", fName);
|
||||
}
|
||||
}
|
||||
|
||||
if (fName.empty())
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"void Foam::functionObjectCloud::addToScene"
|
||||
"("
|
||||
"const scalar, "
|
||||
"vtkRenderer*"
|
||||
")"
|
||||
)
|
||||
<< "Unable to find function object " << functionObject_
|
||||
<< " output for field " << fieldName_
|
||||
<< ". Line will not be processed"
|
||||
<< endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (fName.ext() == "vtk")
|
||||
{
|
||||
vtkSmartPointer<vtkPolyDataReader> points =
|
||||
vtkSmartPointer<vtkPolyDataReader>::New();
|
||||
points->SetFileName(fName.c_str());
|
||||
points->Update();
|
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
|
||||
actor_->SetMapper(mapper);
|
||||
|
||||
addGlyphs
|
||||
(
|
||||
position,
|
||||
fieldName_,
|
||||
colourFieldName_,
|
||||
maxGlyphLength_,
|
||||
points->GetOutput(),
|
||||
actor_,
|
||||
renderer
|
||||
);
|
||||
|
||||
renderer->AddActor(actor_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjectCloud::updateActors(const scalar position)
|
||||
{
|
||||
actor_->GetProperty()->SetOpacity(opacity(position));
|
||||
|
||||
vector pc = pointColour_->value(position);
|
||||
actor_->GetProperty()->SetColor(pc[0], pc[1], pc[2]);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,125 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjectCloud
|
||||
|
||||
Description
|
||||
|
||||
SourceFiles
|
||||
functionObjectCloud.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjectCloud_H
|
||||
#define functionObjectCloud_H
|
||||
|
||||
#include "pointData.H"
|
||||
#include "fieldVisualisationBase.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class functionObjectCloud Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class functionObjectCloud
|
||||
:
|
||||
public pointData,
|
||||
public fieldVisualisationBase
|
||||
{
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
functionObjectCloud(const functionObjectCloud&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const functionObjectCloud&);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Name of cloud
|
||||
word cloudName_;
|
||||
|
||||
//- Name of cloud function object result to render
|
||||
word functionObject_;
|
||||
|
||||
//- Name of field to colour by
|
||||
word colourFieldName_;
|
||||
|
||||
//- Actor
|
||||
vtkSmartPointer<vtkActor> actor_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeName("functionObjectCloud");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
functionObjectCloud
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~functionObjectCloud();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Add tube(s) to scene
|
||||
virtual void addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Update actors
|
||||
virtual void updateActors(const scalar position);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,138 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "functionObjectLine.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkPolyDataReader.h"
|
||||
#include "vtkProperty.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(functionObjectLine, 0);
|
||||
addToRunTimeSelectionTable(pathline, functionObjectLine, dictionary);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjectLine::functionObjectLine
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
)
|
||||
:
|
||||
pathline(parent, dict, colours),
|
||||
fieldVisualisationBase(parent, dict, colours),
|
||||
functionObject_(dict.lookup("functionObject")),
|
||||
actor_()
|
||||
{
|
||||
actor_ = vtkSmartPointer<vtkActor>::New();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjectLine::~functionObjectLine()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjectLine::addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (!visible_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const dictionary dict =
|
||||
geometryBase::parent_.getObjectProperty
|
||||
(
|
||||
functionObject_,
|
||||
fieldName_,
|
||||
dictionary::null
|
||||
);
|
||||
|
||||
fileName fName;
|
||||
if (!dict.readIfPresent("file", fName))
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"void Foam::functionObjectLine::addToScene"
|
||||
"("
|
||||
"const scalar, "
|
||||
"vtkRenderer*"
|
||||
")"
|
||||
)
|
||||
<< "Unable to find function object " << functionObject_
|
||||
<< " output for field " << fieldName_
|
||||
<< ". Line will not be processed"
|
||||
<< endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (fName.ext() == "vtk")
|
||||
{
|
||||
vtkSmartPointer<vtkPolyDataReader> lines =
|
||||
vtkSmartPointer<vtkPolyDataReader>::New();
|
||||
lines->SetFileName(fName.c_str());
|
||||
lines->Update();
|
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
setField(position, fieldName_, mapper, renderer);
|
||||
|
||||
actor_->SetMapper(mapper);
|
||||
|
||||
addLines(position, actor_, lines->GetOutput());
|
||||
|
||||
renderer->AddActor(actor_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjectLine::updateActors(const scalar position)
|
||||
{
|
||||
actor_->GetProperty()->SetLineWidth(2);
|
||||
actor_->GetProperty()->SetOpacity(opacity(position));
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,119 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjectLine
|
||||
|
||||
Description
|
||||
|
||||
SourceFiles
|
||||
functionObjectLine.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjectLine_H
|
||||
#define functionObjectLine_H
|
||||
|
||||
#include "pathline.H"
|
||||
#include "fieldVisualisationBase.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class functionObjectLine Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class functionObjectLine
|
||||
:
|
||||
public pathline,
|
||||
public fieldVisualisationBase
|
||||
{
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
functionObjectLine(const functionObjectLine&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const functionObjectLine&);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Name of function object result to render
|
||||
word functionObject_;
|
||||
|
||||
//- Actor
|
||||
vtkSmartPointer<vtkActor> actor_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeName("line");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
functionObjectLine
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& 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);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,163 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "functionObjectSurface.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkPolyDataReader.h"
|
||||
#include "vtkProperty.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(functionObjectSurface, 0);
|
||||
addToRunTimeSelectionTable(surface, functionObjectSurface, dictionary);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjectSurface::functionObjectSurface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
)
|
||||
:
|
||||
geometrySurface(parent, dict, colours, List<fileName>()),
|
||||
fieldVisualisationBase(parent, dict, colours),
|
||||
functionObject_("")
|
||||
{
|
||||
if (visible_)
|
||||
{
|
||||
dict.lookup("functionObject") >> functionObject_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjectSurface::~functionObjectSurface()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjectSurface::addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (!visible_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const dictionary dict =
|
||||
geometryBase::parent_.getObjectProperty
|
||||
(
|
||||
functionObject_,
|
||||
fieldName_,
|
||||
dictionary::null
|
||||
);
|
||||
|
||||
fileName fName;
|
||||
if (!dict.readIfPresent("file", fName))
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"void Foam::functionObjectSurface::addToScene"
|
||||
"("
|
||||
"const scalar, "
|
||||
"vtkRenderer*"
|
||||
")"
|
||||
)
|
||||
<< "Unable to find function object " << functionObject_
|
||||
<< " output for field " << fieldName_
|
||||
<< ". Surface will not be processed"
|
||||
<< endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (representation_ == rtGlyph)
|
||||
{
|
||||
vtkSmartPointer<vtkPolyDataReader> surf =
|
||||
vtkSmartPointer<vtkPolyDataReader>::New();
|
||||
surf->SetFileName(fName.c_str());
|
||||
surf->Update();
|
||||
|
||||
addGlyphs
|
||||
(
|
||||
position,
|
||||
fieldName_,
|
||||
fieldName_,
|
||||
maxGlyphLength_,
|
||||
surf->GetOutput(),
|
||||
surfaceActor_,
|
||||
renderer
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((colourBy_ == cbField) && (fName.ext() == "vtk"))
|
||||
{
|
||||
vtkSmartPointer<vtkPolyDataReader> surf =
|
||||
vtkSmartPointer<vtkPolyDataReader>::New();
|
||||
surf->SetFileName(fName.c_str());
|
||||
surf->Update();
|
||||
|
||||
addFeatureEdges(renderer, surf->GetOutput());
|
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputConnection(surf->GetOutputPort());
|
||||
|
||||
setField(position, fieldName_, mapper, renderer);
|
||||
|
||||
surfaceActor_->SetMapper(mapper);
|
||||
|
||||
setRepresentation(surfaceActor_);
|
||||
|
||||
renderer->AddActor(surfaceActor_);
|
||||
}
|
||||
else
|
||||
{
|
||||
geometrySurface::addGeometryToScene(position, renderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,115 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjectSurface
|
||||
|
||||
Description
|
||||
|
||||
SourceFiles
|
||||
functionObjectSurface.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjectSurface_H
|
||||
#define functionObjectSurface_H
|
||||
|
||||
#include "geometrySurface.H"
|
||||
#include "fieldVisualisationBase.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class functionObjectSurface Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class functionObjectSurface
|
||||
:
|
||||
public geometrySurface,
|
||||
public fieldVisualisationBase
|
||||
{
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
functionObjectSurface(const functionObjectSurface&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const functionObjectSurface&);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Name of function object result to render
|
||||
word functionObject_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeName("functionObject");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
functionObjectSurface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~functionObjectSurface();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Add surface(s) to scene
|
||||
virtual void addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,149 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "geometryBase.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "Constant.H"
|
||||
|
||||
#include "vtkActor.h"
|
||||
#include "vtkProperty.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
template<>
|
||||
const char* NamedEnum<geometryBase::renderModeType, 3>::names[] =
|
||||
{
|
||||
"flat",
|
||||
"gouraud",
|
||||
"phong"
|
||||
};
|
||||
}
|
||||
|
||||
const Foam::NamedEnum<Foam::geometryBase::renderModeType, 3>
|
||||
Foam::geometryBase::renderModeTypeNames;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::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::geometryBase::geometryBase
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
)
|
||||
:
|
||||
parent_(parent),
|
||||
name_(dict.dictName()),
|
||||
visible_(readBool(dict.lookup("visible"))),
|
||||
renderMode_(rmGouraud),
|
||||
opacity_(NULL),
|
||||
colours_(colours)
|
||||
{
|
||||
if (dict.found("renderMode"))
|
||||
{
|
||||
renderMode_ = renderModeTypeNames.read(dict.lookup("renderMode"));
|
||||
}
|
||||
|
||||
if (dict.found("opacity"))
|
||||
{
|
||||
opacity_.reset(DataEntry<scalar>::New("opacity", dict).ptr());
|
||||
}
|
||||
else
|
||||
{
|
||||
opacity_.reset(new Constant<scalar>("opacity", 1.0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::geometryBase::~geometryBase()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::runTimePostProcessing& Foam::geometryBase::parent() const
|
||||
{
|
||||
return parent_;
|
||||
}
|
||||
|
||||
|
||||
const Foam::word& Foam::geometryBase::name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::geometryBase::visible() const
|
||||
{
|
||||
return visible_;
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::geometryBase::opacity(const scalar position) const
|
||||
{
|
||||
return opacity_->value(position);
|
||||
}
|
||||
|
||||
|
||||
const Foam::HashPtrTable<Foam::DataEntry<Foam::vector>, Foam::word>&
|
||||
Foam::geometryBase::colours() const
|
||||
{
|
||||
return colours_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,171 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::geometryBase
|
||||
|
||||
Description
|
||||
|
||||
SourceFiles
|
||||
geometryBase.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef geometryBase_H
|
||||
#define geometryBase_H
|
||||
|
||||
#include "dictionary.H"
|
||||
#include "vector.H"
|
||||
#include "DataEntry.H"
|
||||
#include "HashPtrTable.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
class vtkRenderer;
|
||||
class vtkActor;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class runTimePostProcessing;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class geometryBase Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class geometryBase
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
// Public enumerations
|
||||
|
||||
enum renderModeType
|
||||
{
|
||||
rmFlat,
|
||||
rmGouraud,
|
||||
rmPhong
|
||||
};
|
||||
|
||||
static const NamedEnum<renderModeType, 3> renderModeTypeNames;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
geometryBase(const geometryBase&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const geometryBase&);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Reference to the parent function object
|
||||
const runTimePostProcessing& parent_;
|
||||
|
||||
//- Name
|
||||
word name_;
|
||||
|
||||
//- Visible flag
|
||||
bool visible_;
|
||||
|
||||
//- Render mode
|
||||
renderModeType renderMode_;
|
||||
|
||||
//- Opacity
|
||||
autoPtr<DataEntry<scalar> > opacity_;
|
||||
|
||||
//- Reference to the colours
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours_;
|
||||
|
||||
|
||||
// Protected functions
|
||||
|
||||
//- Initialse actor
|
||||
void initialiseActor(vtkActor* actor) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
geometryBase
|
||||
(
|
||||
const runTimePostProcessing& parent_,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~geometryBase();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- Return the reference to the parent function object
|
||||
const runTimePostProcessing& parent() const;
|
||||
|
||||
//- Return the name
|
||||
const word& name() const;
|
||||
|
||||
//- Return the visible flag
|
||||
bool visible() const;
|
||||
|
||||
//- Return the opacity
|
||||
scalar opacity(const scalar position) const;
|
||||
|
||||
//- Return reference to the colours
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours() const;
|
||||
|
||||
|
||||
//- Add geometry to scene
|
||||
virtual void addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
) = 0;
|
||||
|
||||
//- Update the actors
|
||||
virtual void updateActors(const scalar position) = 0;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,214 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "geometrySurface.H"
|
||||
#include "stringOps.H"
|
||||
#include "triSurface.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"
|
||||
#include "vtkTriangle.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(geometrySurface, 0);
|
||||
addToRunTimeSelectionTable(surface, geometrySurface, dictionary);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::geometrySurface::addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer,
|
||||
const fileName& fName
|
||||
) const
|
||||
{
|
||||
if (representation_ == rtGlyph)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"void Foam::geometrySurface::addGeometryToScene"
|
||||
"("
|
||||
"const label, "
|
||||
"vtkRenderer*, "
|
||||
"const fileName&"
|
||||
") const"
|
||||
)
|
||||
<< "Glyph representation not available for " << typeName
|
||||
<< "object" << exit(FatalError);
|
||||
}
|
||||
|
||||
triSurface surf(fName);
|
||||
|
||||
const Field<point>& surfPoints = surf.points();
|
||||
const Field<vector>& surfFaceNormals = surf.faceNormals();
|
||||
|
||||
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
|
||||
vtkSmartPointer<vtkCellArray> triangles =
|
||||
vtkSmartPointer<vtkCellArray>::New();
|
||||
vtkSmartPointer<vtkDoubleArray> faceNormals =
|
||||
vtkSmartPointer<vtkDoubleArray>::New();
|
||||
|
||||
faceNormals->SetNumberOfComponents(3);
|
||||
|
||||
forAll(surfPoints, i)
|
||||
{
|
||||
const point& pt = surfPoints[i];
|
||||
points->InsertNextPoint(pt.x(), pt.y(), pt.z());
|
||||
}
|
||||
|
||||
forAll(surf, i)
|
||||
{
|
||||
const Foam::face& f = surf[i];
|
||||
|
||||
vtkSmartPointer<vtkTriangle> triangle =
|
||||
vtkSmartPointer<vtkTriangle>::New();
|
||||
triangle->GetPointIds()->SetId(0, f[0]);
|
||||
triangle->GetPointIds()->SetId(1, f[1]);
|
||||
triangle->GetPointIds()->SetId(2, f[2]);
|
||||
triangles->InsertNextCell(triangle);
|
||||
|
||||
double n[3];
|
||||
n[0] = surfFaceNormals[i].x();
|
||||
n[1] = surfFaceNormals[i].y();
|
||||
n[2] = surfFaceNormals[i].z();
|
||||
|
||||
faceNormals->InsertNextTuple(n);
|
||||
}
|
||||
|
||||
surf.clearOut();
|
||||
|
||||
vtkSmartPointer<vtkPolyData> polyData =
|
||||
vtkSmartPointer<vtkPolyData>::New();
|
||||
polyData->SetPoints(points);
|
||||
polyData->SetPolys(triangles);
|
||||
polyData->GetCellData()->SetNormals(faceNormals);
|
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->ScalarVisibilityOff();
|
||||
mapper->SetInputData(polyData);
|
||||
|
||||
addFeatureEdges(renderer, polyData);
|
||||
|
||||
surfaceActor_->SetMapper(mapper);
|
||||
|
||||
setRepresentation(surfaceActor_);
|
||||
|
||||
renderer->AddActor(surfaceActor_);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::geometrySurface::geometrySurface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
)
|
||||
:
|
||||
surface(parent, dict, colours),
|
||||
fileNames_(dict.lookup("files"))
|
||||
{}
|
||||
|
||||
|
||||
Foam::geometrySurface::geometrySurface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours,
|
||||
const List<fileName>& fileNames
|
||||
)
|
||||
:
|
||||
surface(parent, dict, colours),
|
||||
fileNames_(fileNames)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::geometrySurface::~geometrySurface()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::geometrySurface::addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (!visible_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
forAll(fileNames_, i)
|
||||
{
|
||||
fileName fName = fileNames_[i].expand();
|
||||
addGeometryToScene(position, renderer, fName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::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]);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,136 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::geometrySurface
|
||||
|
||||
Description
|
||||
|
||||
SourceFiles
|
||||
geometrySurface.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef geometrySurface_H
|
||||
#define geometrySurface_H
|
||||
|
||||
#include "surface.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
class vtkPolyData;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class geometrySurface Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class geometrySurface
|
||||
:
|
||||
public surface
|
||||
{
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
geometrySurface(const geometrySurface&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const geometrySurface&);
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeName("geometry");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
geometrySurface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
);
|
||||
|
||||
//- Construct from components
|
||||
geometrySurface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours,
|
||||
const List<fileName>& fileNames
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~geometrySurface();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Add surface(s) to scene
|
||||
virtual void addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Update actors
|
||||
virtual void updateActors(const scalar position);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,211 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "pathline.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkProperty.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
#include "vtkTubeFilter.h"
|
||||
#include "vtkLookupTable.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
template<>
|
||||
const char* NamedEnum<pathline::representationType, 4>::names[] =
|
||||
{
|
||||
"none",
|
||||
"line",
|
||||
"tube",
|
||||
"vector"
|
||||
};
|
||||
|
||||
defineTypeNameAndDebug(pathline, 0);
|
||||
defineRunTimeSelectionTable(pathline, dictionary);
|
||||
}
|
||||
|
||||
const Foam::NamedEnum<Foam::pathline::representationType, 4>
|
||||
Foam::pathline::representationTypeNames;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::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:
|
||||
{
|
||||
vtkSmartPointer<vtkTubeFilter> 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::pathline::pathline
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
)
|
||||
:
|
||||
geometryBase(parent, dict, colours),
|
||||
representation_
|
||||
(
|
||||
representationTypeNames.read(dict.lookup("representation"))
|
||||
),
|
||||
tubeRadius_(0.0),
|
||||
lineColour_(NULL)
|
||||
{
|
||||
if (dict.found("lineColour"))
|
||||
{
|
||||
lineColour_.reset(DataEntry<vector>::New("lineColour", dict).ptr());
|
||||
}
|
||||
else
|
||||
{
|
||||
lineColour_.reset(colours["line"]->clone().ptr());
|
||||
}
|
||||
|
||||
switch (representation_)
|
||||
{
|
||||
case rtNone:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case rtLine:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case rtTube:
|
||||
{
|
||||
dict.lookup("tubeRadius") >> tubeRadius_;
|
||||
break;
|
||||
}
|
||||
case rtVector:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::autoPtr<Foam::pathline> Foam::pathline::New
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours,
|
||||
const word& pathlineType
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Info<< "Selecting pathline " << pathlineType << endl;
|
||||
}
|
||||
|
||||
dictionaryConstructorTable::iterator cstrIter =
|
||||
dictionaryConstructorTablePtr_->find(pathlineType);
|
||||
|
||||
if (cstrIter == dictionaryConstructorTablePtr_->end())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"Foam::autoPtr<Foam::pathline> Foam::pathline::New"
|
||||
"("
|
||||
"const runTimePostProcessing&, "
|
||||
"const dictionary&, "
|
||||
"const HashPtrTable<DataEntry<vector>, word>&, "
|
||||
"const word&"
|
||||
")"
|
||||
) << "Unknown pathline type "
|
||||
<< pathlineType << nl << nl
|
||||
<< "Valid pathline types are:" << endl
|
||||
<< dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return autoPtr<pathline>(cstrIter()(parent, dict, colours));
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pathline::~pathline()
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,167 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::pathline
|
||||
|
||||
Description
|
||||
|
||||
SourceFiles
|
||||
pathline.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef pathline_H
|
||||
#define pathline_H
|
||||
|
||||
#include "geometryBase.H"
|
||||
#include "NamedEnum.H"
|
||||
#include "runTimeSelectionTables.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
class vtkActor;
|
||||
class vtkPolyData;
|
||||
class vtkPolyDataMapper;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class pathline Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class pathline
|
||||
:
|
||||
public geometryBase
|
||||
{
|
||||
public:
|
||||
|
||||
// Public enumerations
|
||||
|
||||
enum representationType
|
||||
{
|
||||
rtNone,
|
||||
rtLine,
|
||||
rtTube,
|
||||
rtVector
|
||||
};
|
||||
|
||||
static const NamedEnum<representationType, 4> representationTypeNames;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
pathline(const pathline&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const pathline&);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Representation type
|
||||
representationType representation_;
|
||||
|
||||
//- Radius for the tube filter
|
||||
scalar tubeRadius_;
|
||||
|
||||
//- Line colour
|
||||
autoPtr<DataEntry<vector> > lineColour_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Add the pathlines to the renderer
|
||||
void addLines
|
||||
(
|
||||
const label frameI,
|
||||
vtkActor* actor,
|
||||
vtkPolyData* data
|
||||
) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeName("pathline");
|
||||
|
||||
|
||||
// Declare run-time constructor selection table
|
||||
|
||||
declareRunTimeSelectionTable
|
||||
(
|
||||
autoPtr,
|
||||
pathline,
|
||||
dictionary,
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
),
|
||||
(parent, dict, colours)
|
||||
);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
pathline
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
);
|
||||
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Return a reference to the selected RAS model
|
||||
static autoPtr<pathline> New
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours,
|
||||
const word& pathlineName
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~pathline();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,171 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "pointData.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
|
||||
{
|
||||
template<>
|
||||
const char* NamedEnum<pointData::representationType, 2>::names[] =
|
||||
{
|
||||
"sphere",
|
||||
"vector"
|
||||
};
|
||||
|
||||
defineTypeNameAndDebug(pointData, 0);
|
||||
defineRunTimeSelectionTable(pointData, dictionary);
|
||||
}
|
||||
|
||||
const Foam::NamedEnum<Foam::pointData::representationType, 2>
|
||||
Foam::pointData::representationTypeNames;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::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::pointData::pointData
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
)
|
||||
:
|
||||
geometryBase(parent, dict, colours),
|
||||
representation_
|
||||
(
|
||||
representationTypeNames.read(dict.lookup("representation"))
|
||||
),
|
||||
maxGlyphLength_(readScalar(dict.lookup("maxGlyphLength"))),
|
||||
pointColour_(NULL)
|
||||
{
|
||||
if (dict.found("pointColour"))
|
||||
{
|
||||
pointColour_.reset(DataEntry<vector>::New("pointColour", dict).ptr());
|
||||
}
|
||||
else
|
||||
{
|
||||
pointColour_.reset(colours["point"]->clone().ptr());
|
||||
}
|
||||
|
||||
switch (representation_)
|
||||
{
|
||||
case rtSphere:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case rtVector:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::autoPtr<Foam::pointData> Foam::pointData::New
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours,
|
||||
const word& pointDataType
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Info<< "Selecting pointData " << pointDataType << endl;
|
||||
}
|
||||
|
||||
dictionaryConstructorTable::iterator cstrIter =
|
||||
dictionaryConstructorTablePtr_->find(pointDataType);
|
||||
|
||||
if (cstrIter == dictionaryConstructorTablePtr_->end())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"Foam::autoPtr<Foam::pointData> Foam::pointData::New"
|
||||
"("
|
||||
"const runTimePostProcessing&, "
|
||||
"const dictionary&, "
|
||||
"const HashPtrTable<DataEntry<vector>, word>&, "
|
||||
"const word&"
|
||||
")"
|
||||
) << "Unknown pointData type "
|
||||
<< pointDataType << nl << nl
|
||||
<< "Valid pointData types are:" << endl
|
||||
<< dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return autoPtr<pointData>(cstrIter()(parent, dict, colours));
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pointData::~pointData()
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,166 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::pointData
|
||||
|
||||
Description
|
||||
|
||||
SourceFiles
|
||||
pointData.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef pointData_H
|
||||
#define pointData_H
|
||||
|
||||
#include "geometryBase.H"
|
||||
#include "NamedEnum.H"
|
||||
#include "runTimeSelectionTables.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
class vtkActor;
|
||||
class vtkPolyData;
|
||||
class vtkPolyDataMapper;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class pointData Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class pointData
|
||||
:
|
||||
public geometryBase
|
||||
{
|
||||
public:
|
||||
|
||||
// Public enumerations
|
||||
|
||||
enum representationType
|
||||
{
|
||||
rtSphere,
|
||||
rtVector
|
||||
};
|
||||
|
||||
static const NamedEnum<representationType, 2> representationTypeNames;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
pointData(const pointData&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const pointData&);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Representation type
|
||||
representationType representation_;
|
||||
|
||||
//- Max glyph length
|
||||
scalar maxGlyphLength_;
|
||||
|
||||
//- Point colour
|
||||
autoPtr<DataEntry<vector> > pointColour_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Add the point data to the renderer
|
||||
void addPoints
|
||||
(
|
||||
const label frameI,
|
||||
vtkActor* actor,
|
||||
vtkPolyDataMapper* mapper,
|
||||
vtkPolyData* data
|
||||
) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeName("pointData");
|
||||
|
||||
|
||||
// Declare run-time constructor selection table
|
||||
|
||||
declareRunTimeSelectionTable
|
||||
(
|
||||
autoPtr,
|
||||
pointData,
|
||||
dictionary,
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
),
|
||||
(parent, dict, colours)
|
||||
);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
pointData
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
);
|
||||
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Return a reference to the selected RAS model
|
||||
static autoPtr<pointData> New
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours,
|
||||
const word& pointDataName
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~pointData();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,210 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "dictionary.H"
|
||||
#include "pointData.H"
|
||||
#include "pathline.H"
|
||||
#include "surface.H"
|
||||
#include "text.H"
|
||||
#include "Time.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkRenderWindow.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
#include "vtkLight.h"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(runTimePostProcessing, 0);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::runTimePostProcessing::runTimePostProcessing
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
const bool loadFromFiles
|
||||
)
|
||||
:
|
||||
functionObjectState(obr, name),
|
||||
scene_(obr, name),
|
||||
points_(),
|
||||
lines_(),
|
||||
surfaces_(),
|
||||
text_(),
|
||||
obr_(obr),
|
||||
active_(true)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::runTimePostProcessing::~runTimePostProcessing()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::runTimePostProcessing::read(const dictionary& dict)
|
||||
{
|
||||
Info<< type() << " " << name_ << ": reading post-processing data" << endl;
|
||||
|
||||
scene_.read(dict);
|
||||
|
||||
const dictionary& outputDict = dict.subDict("output");
|
||||
outputDict.lookup("name") >> output_.name_;
|
||||
outputDict.lookup("width") >> output_.width_;
|
||||
outputDict.lookup("height") >> output_.height_;
|
||||
|
||||
|
||||
readObjects(dict.subOrEmptyDict("points"), points_);
|
||||
readObjects(dict.subOrEmptyDict("lines"), lines_);
|
||||
readObjects(dict.subOrEmptyDict("surfaces"), surfaces_);
|
||||
|
||||
|
||||
const dictionary& textDict = dict.subDict("text");
|
||||
forAllConstIter(dictionary, textDict, iter)
|
||||
{
|
||||
if (!iter().isDict())
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"void Foam::runTimePostProcessing::read(const dictionary&)",
|
||||
textDict
|
||||
)
|
||||
<< "text must be specified in dictionary format"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
text_.append(new text(*this, iter().dict(), scene_.colours()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::runTimePostProcessing::execute()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
||||
void Foam::runTimePostProcessing::end()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
||||
void Foam::runTimePostProcessing::timeSet()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
||||
void Foam::runTimePostProcessing::write()
|
||||
{
|
||||
if (!Pstream::master())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Info<< type() << " " << name_ << " output:" << nl
|
||||
<< " Constructing scene" << endl;
|
||||
|
||||
// Initialise render window
|
||||
vtkSmartPointer<vtkRenderWindow> renderWindow =
|
||||
vtkSmartPointer<vtkRenderWindow>::New();
|
||||
renderWindow->OffScreenRenderingOn();
|
||||
renderWindow->SetSize(output_.width_, output_.height_);
|
||||
renderWindow->SetAAFrames(10);
|
||||
renderWindow->SetAlphaBitPlanes(true);
|
||||
renderWindow->SetMultiSamples(0);
|
||||
// renderWindow->PolygonSmoothingOn();
|
||||
|
||||
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
|
||||
scene_.initialise(renderer, output_.name_);
|
||||
|
||||
renderWindow->AddRenderer(renderer);
|
||||
|
||||
// Add the points
|
||||
forAll(points_, i)
|
||||
{
|
||||
points_[i].addGeometryToScene(0, renderer);
|
||||
}
|
||||
|
||||
// Add the lines
|
||||
forAll(lines_, i)
|
||||
{
|
||||
lines_[i].addGeometryToScene(0, renderer);
|
||||
}
|
||||
|
||||
// Add the surfaces
|
||||
forAll(surfaces_, i)
|
||||
{
|
||||
surfaces_[i].addGeometryToScene(0, renderer);
|
||||
}
|
||||
|
||||
while (scene_.loop(renderer))
|
||||
{
|
||||
scalar position = scene_.position();
|
||||
|
||||
// Add the text
|
||||
forAll(text_, i)
|
||||
{
|
||||
text_[i].addGeometryToScene(position, renderer);
|
||||
}
|
||||
|
||||
// Update the points
|
||||
forAll(points_, i)
|
||||
{
|
||||
points_[i].updateActors(position);
|
||||
}
|
||||
|
||||
// Update the lines
|
||||
forAll(lines_, i)
|
||||
{
|
||||
lines_[i].updateActors(position);
|
||||
}
|
||||
|
||||
// Update the surfaces
|
||||
forAll(surfaces_, i)
|
||||
{
|
||||
surfaces_[i].updateActors(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,205 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::runTimePostProcessing
|
||||
|
||||
Description
|
||||
Function object to 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 e.gg triangulated surfaces and text. Current capabilities
|
||||
include support for:
|
||||
- Camera
|
||||
- Objects
|
||||
- Points
|
||||
- Lines
|
||||
- Surfaces
|
||||
- Scalar bars
|
||||
- Annotations
|
||||
- Selection of colour maps
|
||||
Scene configuration is performed using standard OpenFOAM dictionaries, using
|
||||
the main headings of: output=, camera, colours, points, lines,
|
||||
surfaces and text.
|
||||
|
||||
SourceFiles
|
||||
runTimePostProcessing.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef runTimePostProcessing_H
|
||||
#define runTimePostProcessing_H
|
||||
|
||||
#include "functionObjectState.H"
|
||||
#include "objectRegistry.H"
|
||||
#include "mapPolyMesh.H"
|
||||
#include "PtrList.H"
|
||||
#include "scene.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
class vtkRenderer;
|
||||
class vtkRenderWindow;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class dictionary;
|
||||
class pointData;
|
||||
class pathline;
|
||||
class surface;
|
||||
class text;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class runTimePostProcessing Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class runTimePostProcessing
|
||||
:
|
||||
public functionObjectState
|
||||
{
|
||||
private:
|
||||
|
||||
// Private data
|
||||
|
||||
// Output
|
||||
struct outputType
|
||||
{
|
||||
word name_;
|
||||
label width_;
|
||||
label height_;
|
||||
};
|
||||
|
||||
//- Output instance
|
||||
outputType output_;
|
||||
|
||||
//- Scene manager
|
||||
scene scene_;
|
||||
|
||||
//- List of points
|
||||
PtrList<pointData> points_;
|
||||
|
||||
//- List of lines
|
||||
PtrList<pathline> lines_;
|
||||
|
||||
//- List of surfaces
|
||||
PtrList<surface> surfaces_;
|
||||
|
||||
//- List of text
|
||||
PtrList<text> text_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Helper function to read scene objects
|
||||
template<class Type>
|
||||
void readObjects
|
||||
(
|
||||
const dictionary& dict,
|
||||
PtrList<Type>& objects
|
||||
) const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Reference to the database
|
||||
const objectRegistry& obr_;
|
||||
|
||||
//- on/off switch
|
||||
bool active_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("runTimePostProcessing");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
runTimePostProcessing
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry&,
|
||||
const dictionary&,
|
||||
const bool loadFromFiles = false
|
||||
);
|
||||
|
||||
//- Desructor
|
||||
virtual ~runTimePostProcessing();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
virtual const objectRegistry& obr() const
|
||||
{
|
||||
return obr_;
|
||||
}
|
||||
|
||||
//- Read the field min/max data
|
||||
virtual void read(const dictionary&);
|
||||
|
||||
//- Execute, currently does nothing
|
||||
virtual void execute();
|
||||
|
||||
//- Execute at the final time-loop, currently does nothing
|
||||
virtual void end();
|
||||
|
||||
//- Called when time was set at the end of the Time::operator++
|
||||
virtual void timeSet();
|
||||
|
||||
//- Write
|
||||
virtual void write();
|
||||
|
||||
//- Update for changes of mesh
|
||||
virtual void updateMesh(const mapPolyMesh&)
|
||||
{}
|
||||
|
||||
//- Update for changes of mesh
|
||||
virtual void movePoints(const polyMesh&)
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "runTimePostProcessingTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,42 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "runTimePostProcessingFunctionObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineNamedTemplateTypeNameAndDebug(runTimePostProcessingFunctionObject, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
runTimePostProcessingFunctionObject,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,54 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Typedef
|
||||
Foam::runTimePostProcessingFunctionObject
|
||||
|
||||
Description
|
||||
FunctionObject wrapper around runTimePostProcessing to allow them to be
|
||||
created via the functions entry within controlDict.
|
||||
|
||||
SourceFiles
|
||||
runTimePostProcessingFunctionObject.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef runTimePostProcessingFunctionObject_H
|
||||
#define runTimePostProcessingFunctionObject_H
|
||||
|
||||
#include "runTimePostProcessing.H"
|
||||
#include "OutputFilterFunctionObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
typedef OutputFilterFunctionObject<runTimePostProcessing>
|
||||
runTimePostProcessingFunctionObject;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,65 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::runTimePostProcessing::readObjects
|
||||
(
|
||||
const dictionary& dict,
|
||||
PtrList<Type>& objects
|
||||
) const
|
||||
{
|
||||
objects.clear();
|
||||
forAllConstIter(dictionary, dict, iter)
|
||||
{
|
||||
if (!iter().isDict())
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"void Foam::runTimePostProcessing::readObjects"
|
||||
"("
|
||||
"const dictionary&, "
|
||||
"PtrList<Type>&"
|
||||
")",
|
||||
dict
|
||||
)
|
||||
<< dict.dictName()
|
||||
<< " objects must be specified in dictionary format"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
const dictionary& objectDict(iter().dict());
|
||||
word objectType = objectDict.lookup("type");
|
||||
|
||||
objects.append
|
||||
(
|
||||
Type::New(*this, iter().dict(), scene_.colours(), objectType)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,410 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "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"
|
||||
|
||||
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
template<>
|
||||
const char* NamedEnum<scene::modeType, 2>::names[] =
|
||||
{
|
||||
"static",
|
||||
"flightPath"
|
||||
};
|
||||
}
|
||||
|
||||
const Foam::NamedEnum<Foam::scene::modeType, 2> modeTypeNames_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::scene::readCamera(const dictionary& dict)
|
||||
{
|
||||
if (dict.readIfPresent("nFrameTotal", nFrameTotal_))
|
||||
{
|
||||
if (nFrameTotal_ < 1)
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"void Foam::scene::readCamera(const dictionary&)",
|
||||
dict
|
||||
) << "nFrameTotal must be 1 or greater"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
if (dict.readIfPresent("startPosition", position_))
|
||||
{
|
||||
if ((position_ < 0) || (position_ > 1))
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"void Foam::scene::readCamera(const dictionary&)",
|
||||
dict
|
||||
) << "startPosition must be in the range 0-1"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
dict.lookup("parallelProjection") >> parallelProjection_;
|
||||
|
||||
if (nFrameTotal_ > 1)
|
||||
{
|
||||
scalar endPosition = dict.lookupOrDefault<scalar>("endPosition", 1);
|
||||
if ((endPosition < 0) || (endPosition > 1))
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"void Foam::scene::readCamera(const dictionary&)",
|
||||
dict
|
||||
) << "endPosition must be in the range 0-1"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
dPosition_ = (endPosition - position_)/scalar(nFrameTotal_ - 1);
|
||||
}
|
||||
|
||||
mode_ = modeTypeNames_.read(dict.lookup("mode"));
|
||||
|
||||
word coeffsName = modeTypeNames_[mode_] + word("Coeffs");
|
||||
const dictionary& coeffs = dict.subDict(coeffsName);
|
||||
|
||||
switch (mode_)
|
||||
{
|
||||
case mtStatic:
|
||||
{
|
||||
clipBox_ = boundBox(coeffs.lookup("clipBox"));
|
||||
const vector lookDir(vector(coeffs.lookup("lookDir")));
|
||||
cameraPosition_.reset(new Constant<point>("position", -lookDir));
|
||||
const vector focalPoint(coeffs.lookup("focalPoint"));
|
||||
cameraFocalPoint_.reset
|
||||
(
|
||||
new Constant<point>("focalPoint", focalPoint)
|
||||
);
|
||||
const vector up(coeffs.lookup("up"));
|
||||
cameraUp_.reset(new Constant<point>("up", up));
|
||||
break;
|
||||
}
|
||||
case mtFlightPath:
|
||||
{
|
||||
cameraPosition_.reset
|
||||
(
|
||||
DataEntry<vector>::New("position", coeffs).ptr()
|
||||
);
|
||||
cameraFocalPoint_.reset
|
||||
(
|
||||
DataEntry<point>::New("focalPoint", coeffs).ptr()
|
||||
);
|
||||
cameraUp_.reset(DataEntry<vector>::New("up", coeffs).ptr());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
FatalErrorIn("void Foam::scene::read(const dictionary&)")
|
||||
<< "Unhandled enumeration " << modeTypeNames_[mode_]
|
||||
<< abort(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
if (dict.found("zoom"))
|
||||
{
|
||||
cameraZoom_.reset(DataEntry<scalar>::New("zoom", dict).ptr());
|
||||
}
|
||||
else
|
||||
{
|
||||
cameraZoom_.reset(new Constant<scalar>("zoom", 1.0));
|
||||
}
|
||||
|
||||
if (dict.found("viewAngle"))
|
||||
{
|
||||
cameraViewAngle_.reset(DataEntry<scalar>::New("viewAngle", dict).ptr());
|
||||
}
|
||||
else
|
||||
{
|
||||
cameraViewAngle_.reset(new Constant<scalar>("viewAngle", 35.0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::scene::readColours(const dictionary& dict)
|
||||
{
|
||||
const wordList colours = dict.toc();
|
||||
forAll(colours, i)
|
||||
{
|
||||
const word& c = colours[i];
|
||||
colours_.insert(c, DataEntry<vector>::New(c, dict).ptr());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::scene::initialise(vtkRenderer* renderer, const word& outputName)
|
||||
{
|
||||
currentFrameI_ = 0;
|
||||
|
||||
outputName_ = outputName;
|
||||
|
||||
// Set the background
|
||||
const vector backgroundColour = colours_["background"]->value(position());
|
||||
renderer->SetBackground
|
||||
(
|
||||
backgroundColour.x(),
|
||||
backgroundColour.y(),
|
||||
backgroundColour.z()
|
||||
);
|
||||
|
||||
// Apply gradient background if "background2" defined
|
||||
if (colours_.found("background2"))
|
||||
{
|
||||
renderer->GradientBackgroundOn();
|
||||
vector backgroundColour2 = colours_["background2"]->value(position());
|
||||
|
||||
renderer->SetBackground2
|
||||
(
|
||||
backgroundColour2.x(),
|
||||
backgroundColour2.y(),
|
||||
backgroundColour2.z()
|
||||
);
|
||||
}
|
||||
|
||||
// Depth peeling
|
||||
renderer->SetUseDepthPeeling(true);
|
||||
renderer->SetMaximumNumberOfPeels(4);
|
||||
renderer->SetOcclusionRatio(0);
|
||||
|
||||
// Set the camera
|
||||
vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
|
||||
camera->SetParallelProjection(parallelProjection_);
|
||||
renderer->SetActiveCamera(camera);
|
||||
|
||||
setCamera(renderer, true);
|
||||
|
||||
// Initialise the extents
|
||||
if (mode_ == mtStatic)
|
||||
{
|
||||
const point& min = clipBox_.min();
|
||||
const point& max = clipBox_.max();
|
||||
vtkSmartPointer<vtkCubeSource> 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())
|
||||
);
|
||||
vtkSmartPointer<vtkPolyDataMapper> clipMapper =
|
||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
clipMapper->SetInputConnection(clipBox->GetOutputPort());
|
||||
|
||||
vtkSmartPointer<vtkActor> clipActor = vtkSmartPointer<vtkActor>::New();
|
||||
clipActor->SetMapper(clipMapper);
|
||||
clipActor->VisibilityOn();
|
||||
renderer->AddActor(clipActor);
|
||||
|
||||
renderer->ResetCamera();
|
||||
|
||||
clipActor->VisibilityOff();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::scene::setCamera(vtkRenderer* renderer, const bool override) const
|
||||
{
|
||||
if (mode_ == mtFlightPath || override)
|
||||
{
|
||||
vtkCamera* camera = renderer->GetActiveCamera();
|
||||
|
||||
if (!parallelProjection_)
|
||||
{
|
||||
camera->SetViewAngle(cameraViewAngle_->value(position()));
|
||||
}
|
||||
|
||||
const vector up = cameraUp_->value(position());
|
||||
const vector pos = cameraPosition_->value(position());
|
||||
const point focalPoint = cameraFocalPoint_->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());
|
||||
camera->Modified();
|
||||
|
||||
vtkSmartPointer<vtkLightKit> lightKit =
|
||||
vtkSmartPointer<vtkLightKit>::New();
|
||||
lightKit->AddLightsToRenderer(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::string Foam::scene::frameIndexStr() const
|
||||
{
|
||||
string str = Foam::name(currentFrameI_);
|
||||
str.insert(0, 4 - str.length(), '0');
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::scene::scene(const objectRegistry& obr, const word& name)
|
||||
:
|
||||
obr_(obr),
|
||||
name_(name),
|
||||
colours_(),
|
||||
mode_(mtStatic),
|
||||
cameraPosition_(NULL),
|
||||
cameraFocalPoint_(NULL),
|
||||
cameraUp_(NULL),
|
||||
cameraZoom_(NULL),
|
||||
cameraViewAngle_(NULL),
|
||||
clipBox_(),
|
||||
parallelProjection_(true),
|
||||
nFrameTotal_(1),
|
||||
position_(0),
|
||||
dPosition_(0),
|
||||
currentFrameI_(0),
|
||||
outputName_("unknown")
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::scene::~scene()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::HashPtrTable<Foam::DataEntry<Foam::vector>, Foam::word>&
|
||||
Foam::scene::colours() const
|
||||
{
|
||||
return colours_;
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::scene::frameIndex() const
|
||||
{
|
||||
return currentFrameI_;
|
||||
}
|
||||
|
||||
|
||||
Foam::scalar Foam::scene::position() const
|
||||
{
|
||||
return position_;
|
||||
}
|
||||
|
||||
|
||||
void Foam::scene::read(const dictionary& dict)
|
||||
{
|
||||
readCamera(dict.subDict("camera"));
|
||||
readColours(dict.subDict("colours"));
|
||||
}
|
||||
|
||||
|
||||
bool Foam::scene::loop(vtkRenderer* renderer)
|
||||
{
|
||||
static bool initialised = false;
|
||||
|
||||
setCamera(renderer, false);
|
||||
|
||||
if (!initialised)
|
||||
{
|
||||
initialised = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Save image from last iteration
|
||||
saveImage(renderer->GetRenderWindow());
|
||||
|
||||
currentFrameI_++;
|
||||
|
||||
position_ += currentFrameI_*dPosition_;
|
||||
|
||||
if (currentFrameI_ < nFrameTotal_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::scene::saveImage(vtkRenderWindow* renderWindow) const
|
||||
{
|
||||
if (!renderWindow)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
fileName prefix("postProcessing"/name_/obr_.time().timeName());
|
||||
mkDir(prefix);
|
||||
|
||||
renderWindow->Render();
|
||||
|
||||
// Set up off-screen rendering
|
||||
vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter =
|
||||
vtkSmartPointer<vtkWindowToImageFilter>::New();
|
||||
|
||||
windowToImageFilter->SetInput(renderWindow);
|
||||
|
||||
//// Add alpha channel for transparency
|
||||
// windowToImageFilter->SetInputBufferTypeToRGBA();
|
||||
windowToImageFilter->SetInputBufferTypeToRGB();
|
||||
|
||||
// windowToImageFilter->ReadFrontBufferOff();
|
||||
windowToImageFilter->Update();
|
||||
|
||||
// Save the image
|
||||
vtkSmartPointer<vtkPNGWriter> writer = vtkSmartPointer<vtkPNGWriter>::New();
|
||||
fileName fName(prefix/outputName_ + '.' + frameIndexStr() + ".png");
|
||||
writer->SetFileName(fName.c_str());
|
||||
writer->SetInputConnection(windowToImageFilter->GetOutputPort());
|
||||
|
||||
Info<< " Generating image: " << fName << endl;
|
||||
|
||||
writer->Write();
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,202 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::camera
|
||||
|
||||
Description
|
||||
|
||||
SourceFiles
|
||||
scene.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef scene_H
|
||||
#define scene_H
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "dictionary.H"
|
||||
#include "DataEntry.H"
|
||||
#include "vector.H"
|
||||
#include "point.H"
|
||||
#include "boundBox.H"
|
||||
#include "NamedEnum.H"
|
||||
#include "HashPtrTable.H"
|
||||
#include "vector.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
class vtkRenderer;
|
||||
class vtkRenderWindow;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class scene Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class scene
|
||||
{
|
||||
public:
|
||||
|
||||
enum modeType{mtStatic, mtFlightPath};
|
||||
|
||||
NamedEnum<modeType, 2> modeTypeNames_;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// 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 solour properties
|
||||
void readColours(const dictionary& dict);
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
scene(const scene&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const scene&);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Colours
|
||||
HashPtrTable<DataEntry<vector>, word> colours_;
|
||||
|
||||
|
||||
// Camera settings
|
||||
|
||||
//- Mode
|
||||
modeType mode_;
|
||||
|
||||
//- Position
|
||||
autoPtr<DataEntry<point> > cameraPosition_;
|
||||
|
||||
//- Focal point
|
||||
autoPtr<DataEntry<point> > cameraFocalPoint_;
|
||||
|
||||
//- Up direction
|
||||
autoPtr<DataEntry<vector> > cameraUp_;
|
||||
|
||||
//- Zoom level
|
||||
autoPtr<DataEntry<scalar> > cameraZoom_;
|
||||
|
||||
//- View angle
|
||||
autoPtr<DataEntry<scalar> > cameraViewAngle_;
|
||||
|
||||
|
||||
// Scene management
|
||||
|
||||
//- Clipping box
|
||||
boundBox clipBox_;
|
||||
|
||||
//- Parallel projection flag
|
||||
bool parallelProjection_;
|
||||
|
||||
//- Number of frames
|
||||
label nFrameTotal_;
|
||||
|
||||
//- 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 bool override) 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<DataEntry<vector>, word>& 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 Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,262 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "surface.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkActor.h"
|
||||
#include "vtkFeatureEdges.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkProperty.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
template<>
|
||||
const char* NamedEnum<surface::representationType, 5>::names[] =
|
||||
{
|
||||
"none",
|
||||
"wireframe",
|
||||
"surface",
|
||||
"surfaceWithEdges",
|
||||
"glyph"
|
||||
};
|
||||
|
||||
defineTypeNameAndDebug(surface, 0);
|
||||
defineRunTimeSelectionTable(surface, dictionary);
|
||||
}
|
||||
|
||||
const Foam::NamedEnum<Foam::surface::representationType, 5>
|
||||
Foam::surface::representationTypeNames;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::surface::setRepresentation(vtkActor* actor) const
|
||||
{
|
||||
geometryBase::initialiseActor(actor);
|
||||
|
||||
switch (representation_)
|
||||
{
|
||||
case rtNone:
|
||||
{
|
||||
actor->VisibilityOff();
|
||||
break;
|
||||
}
|
||||
case rtWireframe:
|
||||
{
|
||||
// note: colour is set using general SetColour, not setEdgeColor
|
||||
actor->GetProperty()->SetRepresentationToWireframe();
|
||||
break;
|
||||
}
|
||||
case rtGlyph:
|
||||
case rtSurface:
|
||||
{
|
||||
actor->GetProperty()->SetRepresentationToSurface();
|
||||
break;
|
||||
}
|
||||
case rtSurfaceWithEdges:
|
||||
{
|
||||
actor->GetProperty()->SetRepresentationToSurface();
|
||||
actor->GetProperty()->EdgeVisibilityOn();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::surface::addFeatureEdges
|
||||
(
|
||||
vtkRenderer* renderer,
|
||||
vtkPolyData* data
|
||||
) const
|
||||
{
|
||||
if (!featureEdges_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkFeatureEdges> featureEdges =
|
||||
vtkSmartPointer<vtkFeatureEdges>::New();
|
||||
featureEdges->SetInputData(data);
|
||||
featureEdges->BoundaryEdgesOn();
|
||||
featureEdges->FeatureEdgesOn();
|
||||
featureEdges->ManifoldEdgesOff();
|
||||
featureEdges->NonManifoldEdgesOff();
|
||||
// featureEdges->SetFeatureAngle(60);
|
||||
featureEdges->ColoringOff();
|
||||
featureEdges->Update();
|
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> 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_);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::surface::surface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
)
|
||||
:
|
||||
geometryBase(parent, dict, colours),
|
||||
representation_
|
||||
(
|
||||
representationTypeNames.read(dict.lookup("representation"))
|
||||
),
|
||||
featureEdges_(false),
|
||||
surfaceColour_(NULL),
|
||||
edgeColour_(NULL),
|
||||
surfaceActor_(),
|
||||
edgeActor_(),
|
||||
maxGlyphLength_(0.0)
|
||||
{
|
||||
surfaceActor_ = vtkSmartPointer<vtkActor>::New();
|
||||
edgeActor_ = vtkSmartPointer<vtkActor>::New();
|
||||
|
||||
if (dict.found("surfaceColour"))
|
||||
{
|
||||
surfaceColour_.reset
|
||||
(
|
||||
DataEntry<vector>::New("surfaceColour", dict).ptr()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
surfaceColour_.reset(colours["surface"]->clone().ptr());
|
||||
}
|
||||
|
||||
if (dict.found("edgeColour"))
|
||||
{
|
||||
edgeColour_.reset(DataEntry<vector>::New("edgeColour", dict).ptr());
|
||||
}
|
||||
else
|
||||
{
|
||||
edgeColour_.reset(colours["edge"]->clone().ptr());
|
||||
}
|
||||
|
||||
if (representation_ == rtGlyph)
|
||||
{
|
||||
dict.lookup("maxGlyphLength") >> maxGlyphLength_;
|
||||
}
|
||||
else
|
||||
{
|
||||
dict.lookup("featureEdges") >> featureEdges_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::autoPtr<Foam::surface> Foam::surface::New
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours,
|
||||
const word& surfaceType
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Info<< "Selecting surface " << surfaceType << endl;
|
||||
}
|
||||
|
||||
dictionaryConstructorTable::iterator cstrIter =
|
||||
dictionaryConstructorTablePtr_->find(surfaceType);
|
||||
|
||||
if (cstrIter == dictionaryConstructorTablePtr_->end())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"Foam::autoPtr<Foam::surface> Foam::surface::New"
|
||||
"("
|
||||
"const runTimePostProcessing&, "
|
||||
"const dictionary&, "
|
||||
"const HashPtrTable<DataEntry<vector>, word>&, "
|
||||
"const word&"
|
||||
")"
|
||||
) << "Unknown surface type "
|
||||
<< surfaceType << nl << nl
|
||||
<< "Valid surface types are:" << endl
|
||||
<< dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return autoPtr<surface>(cstrIter()(parent, dict, colours));
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::surface::~surface()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::surface::updateActors(const scalar position)
|
||||
{
|
||||
if (!featureEdges_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
edgeActor_->GetProperty()->SetLineWidth(2);
|
||||
edgeActor_->GetProperty()->SetOpacity(opacity(position));
|
||||
|
||||
const vector colour = edgeColour_->value(position);
|
||||
edgeActor_->GetProperty()->SetColor
|
||||
(
|
||||
colour[0],
|
||||
colour[1],
|
||||
colour[2]
|
||||
);
|
||||
edgeActor_->GetProperty()->SetEdgeColor
|
||||
(
|
||||
colour[0],
|
||||
colour[1],
|
||||
colour[2]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,190 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::surface
|
||||
|
||||
Description
|
||||
|
||||
SourceFiles
|
||||
surface.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef surface_H
|
||||
#define surface_H
|
||||
|
||||
#include "geometryBase.H"
|
||||
#include "NamedEnum.H"
|
||||
#include "runTimeSelectionTables.H"
|
||||
|
||||
#include "vtkSmartPointer.h"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
class vtkActor;
|
||||
class vtkRenderer;
|
||||
class vtkPolyData;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class surface Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class surface
|
||||
:
|
||||
public geometryBase
|
||||
{
|
||||
public:
|
||||
|
||||
// Public enumerations
|
||||
|
||||
enum representationType
|
||||
{
|
||||
rtNone,
|
||||
rtWireframe,
|
||||
rtSurface,
|
||||
rtSurfaceWithEdges,
|
||||
rtGlyph
|
||||
};
|
||||
|
||||
static const NamedEnum<representationType, 5> representationTypeNames;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
surface(const surface&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const surface&);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Representation type
|
||||
representationType representation_;
|
||||
|
||||
//- Activate feature edges
|
||||
bool featureEdges_;
|
||||
|
||||
//- Surface colour
|
||||
autoPtr<DataEntry<vector> > surfaceColour_;
|
||||
|
||||
//- Edge colour
|
||||
autoPtr<DataEntry<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,
|
||||
vtkPolyData* data
|
||||
) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Run-time type information
|
||||
TypeName("surface");
|
||||
|
||||
|
||||
// Declare run-time constructor selection table
|
||||
|
||||
declareRunTimeSelectionTable
|
||||
(
|
||||
autoPtr,
|
||||
surface,
|
||||
dictionary,
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
),
|
||||
(parent, dict, colours)
|
||||
);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
surface
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
);
|
||||
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Return a reference to the selected RAS model
|
||||
static autoPtr<surface> New
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours,
|
||||
const word& surfaceName
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~surface();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Update the actors
|
||||
virtual void updateActors(const scalar position);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,110 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// OpenFOAM includes
|
||||
#include "text.H"
|
||||
#include "runTimePostProcessing.H"
|
||||
|
||||
// VTK includes
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
#include "vtkTextActor.h"
|
||||
#include "vtkTextProperty.h"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::text::text
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
)
|
||||
:
|
||||
geometryBase(parent, dict, colours),
|
||||
string_(dict.lookup("string")),
|
||||
position_(dict.lookup("position")),
|
||||
size_(readScalar(dict.lookup("size"))),
|
||||
colour_(NULL),
|
||||
bold_(readBool(dict.lookup("bold")))
|
||||
{
|
||||
if (dict.found("colour"))
|
||||
{
|
||||
colour_.reset(DataEntry<vector>::New("colour", dict).ptr());
|
||||
}
|
||||
else
|
||||
{
|
||||
colour_.reset(colours["text"]->clone().ptr());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::text::~text()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::text::addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
)
|
||||
{
|
||||
if (!visible_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkTextActor> actor = vtkSmartPointer<vtkTextActor>::New();
|
||||
|
||||
actor->SetInput(string_.c_str());
|
||||
actor->GetTextProperty()->SetFontFamilyToArial();
|
||||
actor->GetTextProperty()->SetFontSize(size_);
|
||||
actor->GetTextProperty()->SetJustificationToLeft();
|
||||
actor->GetTextProperty()->SetVerticalJustificationToBottom();
|
||||
actor->GetTextProperty()->SetBold(bold_);
|
||||
|
||||
const vector colour = colour_->value(position);
|
||||
actor->GetTextProperty()->SetColor(colour[0], colour[1], colour[2]);
|
||||
actor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
|
||||
actor->GetPositionCoordinate()->SetValue
|
||||
(
|
||||
position_.first(),
|
||||
position_.second()
|
||||
);
|
||||
|
||||
renderer->AddActor2D(actor);
|
||||
}
|
||||
|
||||
|
||||
void Foam::text::updateActors(const scalar position)
|
||||
{
|
||||
// do nothing - all handled by addGeometryToScene
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,125 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::text
|
||||
|
||||
Description
|
||||
|
||||
SourceFiles
|
||||
text.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef text_H
|
||||
#define text_H
|
||||
|
||||
#include "geometryBase.H"
|
||||
#include "Tuple2.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
class vtkRenderer;
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class text Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class text
|
||||
:
|
||||
public geometryBase
|
||||
{
|
||||
private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
text(const text&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const text&);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Text
|
||||
string string_;
|
||||
|
||||
//- Position
|
||||
Tuple2<scalar, scalar> position_;
|
||||
|
||||
//- Size
|
||||
scalar size_;
|
||||
|
||||
//- Colour
|
||||
autoPtr<DataEntry<vector> > colour_;
|
||||
|
||||
//- Bold flag
|
||||
bool bold_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from dictionary
|
||||
text
|
||||
(
|
||||
const runTimePostProcessing& parent,
|
||||
const dictionary& dict,
|
||||
const HashPtrTable<DataEntry<vector>, word>& colours
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~text();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Add surface(s) to scene
|
||||
virtual void addGeometryToScene
|
||||
(
|
||||
const scalar position,
|
||||
vtkRenderer* renderer
|
||||
);
|
||||
|
||||
//- Update actors
|
||||
virtual void updateActors(const scalar position);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user