Go to the documentation of this file.
33 #include "vtkCamera.h"
34 #include "vtkCubeSource.h"
35 #include "vtkLightKit.h"
36 #include "vtkPolyDataMapper.h"
37 #include "vtkPNGWriter.h"
38 #include "vtkRenderer.h"
39 #include "vtkRendererCollection.h"
40 #include "vtkRenderWindow.h"
41 #include "vtkWindowToImageFilter.h"
45 void Foam::functionObjects::runTimePostPro::scene::readCamera
47 const dictionary&
dict
59 dict.readCheckIfPresent
72 scalar endPosition =
dict.getCheckOrDefault<scalar>
90 if (
dict.found(
"viewAngle"))
98 new Function1Types::Constant<scalar>(
"viewAngle", 35.0)
103 if (
dict.found(
"zoom"))
111 new Function1Types::Constant<scalar>(
"zoom", 1.0)
117 void Foam::functionObjects::runTimePostPro::scene::readColours
119 const dictionary&
dict
123 for (
const word&
c : colours)
130 void Foam::functionObjects::runTimePostPro::scene::setActorVisibility
132 vtkRenderer* renderer,
136 if (!renderer)
return;
138 vtkActorCollection *actors = renderer->GetActors();
139 for (
int i = 0; i < actors->GetNumberOfItems(); ++i)
141 vtkActor *actor = vtkActor::SafeDownCast(actors->GetItemAsObject(i));
142 actor->SetVisibility(visible);
149 vtkRenderer* renderer,
150 const word& outputName
154 position_ = startPosition_;
156 outputName_ = outputName;
158 if (!renderer)
return;
162 const vector bgColour = colours_[
"background"]->value(position_);
164 renderer->SetBackground(bgColour.
x(), bgColour.
y(), bgColour.
z());
167 if (colours_.found(
"background2"))
169 const vector bg2Colour = colours_[
"background2"]->value(position_);
171 renderer->GradientBackgroundOn();
172 renderer->SetBackground2(bg2Colour.
x(), bg2Colour.
y(), bg2Colour.
z());
180 renderer->GradientBackgroundOn();
181 renderer->SetBackground2(bgColour.
x(), bgColour.
y(), bgColour.
z());
185 renderer->SetUseDepthPeeling(
true);
186 renderer->SetMaximumNumberOfPeels(4);
187 renderer->SetOcclusionRatio(0);
191 camera->SetParallelProjection(parallelProjection_);
192 renderer->SetActiveCamera(camera);
196 lightKit->AddLightsToRenderer(renderer);
198 if (!clipBox_.empty())
203 clipBox->SetXLength(
max.x() -
min.x());
204 clipBox->SetYLength(
max.y() -
min.y());
205 clipBox->SetZLength(
max.z() -
min.z());
213 clipMapper->SetInputConnection(clipBox->GetOutputPort());
216 clipBoxActor_->SetMapper(clipMapper);
217 clipBoxActor_->VisibilityOff();
218 renderer->AddActor(clipBoxActor_);
225 vtkRenderer* renderer
228 if (!renderer)
return;
230 vtkCamera* camera = renderer->GetActiveCamera();
232 if (parallelProjection_)
235 camera->SetParallelScale(1);
240 camera->SetViewAngle(cameraViewAngle_->value(position_));
243 const vector up = cameraUp_->value(position_);
245 const point focalPoint = cameraFocalPoint_->value(position_);
246 const scalar zoom = cameraZoom_->value(position_);
248 camera->SetViewUp(up.
x(), up.
y(), up.
z());
249 camera->SetPosition(
pos.x(),
pos.y(),
pos.z());
250 camera->SetFocalPoint(focalPoint.
x(), focalPoint.
y(), focalPoint.
z());
256 if (!clipBox_.empty())
258 setActorVisibility(renderer,
false);
259 clipBoxActor_->VisibilityOn();
262 renderer->ResetCamera();
264 setActorVisibility(renderer,
true);
265 clipBoxActor_->VisibilityOff();
279 str.insert(0, 4 - str.length(),
'0');
287 Foam::functionObjects::runTimePostPro::scene::scene
296 cameraPosition_(
nullptr),
297 cameraFocalPoint_(
nullptr),
299 cameraViewAngle_(
nullptr),
300 cameraZoom_(
nullptr),
303 parallelProjection_(
true),
309 outputName_(
"unknown")
330 return currentFrameI_;
345 readCamera(
dict.subDict(
"camera"));
346 readColours(
dict.subDict(
"colours"));
352 static bool initialised =
false;
366 renderer->ResetCameraClippingRange();
369 saveImage(renderer->GetRenderWindow());
374 position_ = startPosition_ + currentFrameI_*dPosition_;
376 if (currentFrameI_ < nFrameTotal_)
390 vtkRenderWindow* renderWindow
406 / outputName_ +
'.' + frameIndexStr() +
".png"
409 renderWindow->Render();
414 windowToImageFilter->SetInput(renderWindow);
418 windowToImageFilter->SetInputBufferTypeToRGB();
421 windowToImageFilter->Update();
430 writer->SetFileName(fName.c_str());
431 writer->SetInputConnection(windowToImageFilter->GetOutputPort());
const Cmpt & x() const
Access to the vector x component.
bool parallelProjection_
Parallel projection flag.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
A class for handling words, derived from Foam::string.
A class for handling file names.
label frameIndex() const
Return the current frame index.
scalar dPosition_
Change in position per frame.
void read(const dictionary &dict)
static const boundBox invertedBox
A large inverted boundBox: min/max == +/- ROOTVGREAT.
static bool & parRun()
Is this a parallel run?
Ostream & endl(Ostream &os)
Add newline and flush stream.
const Type & value() const
Return const reference to value.
A class for handling character strings derived from std::string.
bool loop(vtkRenderer *renderer)
Main control loop.
autoPtr< Function1< scalar > > cameraZoom_
Zoom: 1 = do nothing, >1 = zoom in, <1 = zoom out.
const Cmpt & z() const
Access to the vector z component.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
string frameIndexStr() const
void saveImage(vtkRenderWindow *renderWindow) const
Save image to file.
List< word > wordList
A List of words.
Registry of regIOobjects.
void initialise(vtkRenderer *renderer, const word &outputName)
autoPtr< Function1< scalar > > cameraViewAngle_
View angle.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
scalar position_
Position [0-1].
autoPtr< Function1< point > > cameraPosition_
Position.
void setCamera(vtkRenderer *renderer) const
messageStream Info
Information stream (uses stdout - output is on the master only)
word name(const complex &c)
Return string representation of complex.
boundBox clipBox_
Clipping box.
static MinMax< scalar > zero_one()
A 0-1 range corresponding to the pTraits zero, one.
static word outputPrefix
Directory prefix.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
const HashPtrTable< Function1< vector > > & colours() const
Return the colours.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Base class for graphics format writing. Entry points are.
virtual ~scene()
Destructor.
static bool master(const label communicator=0)
Am I the master process.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
const Cmpt & y() const
Access to the vector y component.
label nFrameTotal_
Number of frames.
A HashTable of pointers to objects of type <T>.
static MinMax< T > ge(const T &minVal)
A semi-infinite range from minVal to the type max.
autoPtr< Function1< vector > > cameraUp_
Up direction.
autoPtr< Function1< point > > cameraFocalPoint_
Focal point.
scalar startPosition_
Start position [0-1].
scalar position() const
Return the current position (in range 0-1)
const dimensionedScalar c
Speed of light in a vacuum.
static autoPtr< Function1< Type > > New(const word &entryName, const dictionary &dict, const word &redirectType=word::null)
Selector.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
dimensionedScalar pos(const dimensionedScalar &ds)