Go to the documentation of this file.
31 #include "vtkCamera.h"
32 #include "vtkCubeSource.h"
33 #include "vtkLightKit.h"
34 #include "vtkPolyDataMapper.h"
35 #include "vtkPNGWriter.h"
36 #include "vtkRenderer.h"
37 #include "vtkRendererCollection.h"
38 #include "vtkRenderWindow.h"
39 #include "vtkWindowToImageFilter.h"
65 <<
"nFrameTotal must be 1 or greater"
75 <<
"startPosition must be in the range 0-1"
85 scalar endPosition =
dict.lookupOrDefault<scalar>(
"endPosition", 1);
86 if ((endPosition < 0) || (endPosition > 1))
89 <<
"endPosition must be in the range 0-1"
137 if (
dict.found(
"zoom"))
146 if (
dict.found(
"viewAngle"))
162 const word&
c = colours[i];
172 outputName_ = outputName;
175 const vector backgroundColour = colours_[
"background"]->value(position());
176 renderer->SetBackground
178 backgroundColour.
x(),
179 backgroundColour.
y(),
184 if (colours_.found(
"background2"))
186 renderer->GradientBackgroundOn();
187 vector backgroundColour2 = colours_[
"background2"]->value(position());
189 renderer->SetBackground2
191 backgroundColour2.
x(),
192 backgroundColour2.
y(),
193 backgroundColour2.
z()
198 renderer->SetUseDepthPeeling(
true);
199 renderer->SetMaximumNumberOfPeels(4);
200 renderer->SetOcclusionRatio(0);
204 camera->SetParallelProjection(parallelProjection_);
205 renderer->SetActiveCamera(
camera);
207 setCamera(renderer,
true);
210 if (mode_ == mtStatic)
214 vtkSmartPointer<vtkCubeSource> clipBox =
216 clipBox->SetXLength(
max.x() -
min.x());
217 clipBox->SetYLength(
max.y() -
min.y());
218 clipBox->SetZLength(
max.z() -
min.z());
225 vtkSmartPointer<vtkPolyDataMapper> clipMapper =
227 clipMapper->SetInputConnection(clipBox->GetOutputPort());
230 clipActor->SetMapper(clipMapper);
231 clipActor->VisibilityOn();
232 renderer->AddActor(clipActor);
234 renderer->ResetCamera();
236 clipActor->VisibilityOff();
243 if (mode_ == mtFlightPath ||
override)
245 vtkCamera*
camera = renderer->GetActiveCamera();
247 if (!parallelProjection_)
249 camera->SetViewAngle(cameraViewAngle_->value(position()));
252 const vector up = cameraUp_->value(position());
254 const point focalPoint = cameraFocalPoint_->value(position());
256 camera->SetViewUp(up.
x(), up.
y(), up.
z());
258 camera->SetFocalPoint(focalPoint.
x(), focalPoint.
y(), focalPoint.
z());
261 vtkSmartPointer<vtkLightKit> lightKit =
263 lightKit->AddLightsToRenderer(renderer);
271 str.insert(0, 4 - str.length(),
'0');
285 cameraPosition_(NULL),
286 cameraFocalPoint_(NULL),
289 cameraViewAngle_(NULL),
291 parallelProjection_(true),
296 outputName_(
"unknown")
317 return currentFrameI_;
336 static bool initialised =
false;
338 setCamera(renderer,
false);
347 saveImage(renderer->GetRenderWindow());
351 position_ += currentFrameI_*dPosition_;
353 if (currentFrameI_ < nFrameTotal_)
371 fileName prefix(
"postProcessing"/name_/obr_.time().timeName());
374 renderWindow->Render();
377 vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter =
380 windowToImageFilter->SetInput(renderWindow);
384 windowToImageFilter->SetInputBufferTypeToRGB();
387 windowToImageFilter->Update();
391 fileName fName(prefix/outputName_ +
'.' + frameIndexStr() +
".png");
392 writer->SetFileName(fName.c_str());
393 writer->SetInputConnection(windowToImageFilter->GetOutputPort());
395 Info<<
" Generating image: " << fName <<
endl;
string frameIndexStr() const
NamedEnum< modeType, 2 > modeTypeNames_
scene(const scene &)
Disallow default bitwise copy construct.
autoPtr< DataEntry< scalar > > cameraViewAngle_
View angle.
virtual ~scene()
Destructor.
autoPtr< DataEntry< point > > cameraFocalPoint_
Focal point.
A class for handling words, derived from string.
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
A class for handling file names.
label nFrameTotal_
Number of frames.
scalar position_
Position [0-1].
#define forAll(list, i)
Loop across all elements in list.
bool parallelProjection_
Parallel projection flag.
void readCamera(const dictionary &dict)
Read camera properties.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
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.
scalar position() const
Return the current position (in range 0-1)
void initialise(vtkRenderer *renderer, const word &outputName)
Templated basic entry that holds a constant value.
const HashPtrTable< DataEntry< vector >, word > & colours() const
Return the colours.
Registry of regIOobjects.
const Foam::NamedEnum< Foam::scene::modeType, 2 > modeTypeNames_
void readColours(const dictionary &dict)
Read solour properties.
autoPtr< DataEntry< point > > cameraPosition_
Position.
void setCamera(vtkRenderer *renderer, const bool override) const
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
void read(const dictionary &dict)
bool loop(vtkRenderer *renderer)
Main control loop.
A list of keyword definitions, which are a keyword followed by any number of values (e....
label frameIndex() const
Return the current frame index.
Base class for graphics format writing. Entry points are.
errorManip< error > abort(error &err)
Vector< scalar > vector
A scalar version of the templated Vector.
autoPtr< DataEntry< vector > > cameraUp_
Up direction.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
scalar dPosition_
Change in position per frame.
Enum read(Istream &) const
Read a word from Istream and return the corresponding.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
void saveImage(vtkRenderWindow *renderWindow) const
Save image to file.
A HashTable specialization for hashing pointers.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
boundBox clipBox_
Clipping box.
autoPtr< DataEntry< scalar > > cameraZoom_
Zoom level.
A bounding box defined in terms of the points at its extremities.
const dimensionedScalar c
Speed of light in a vacuum.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
wordList toc() const
Return the table of contents.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
word name(const complex &)
Return a string representation of a complex.
Initialise the NamedEnum HashTable from the static list of names.
dimensionedScalar pos(const dimensionedScalar &ds)