mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge branch 'feature-runtime-post-pro-camera-update' into 'develop'
runTimePostProcessing FO camera update
- Removed the camera 'mode'
- The (old) static camera was only appropriate when parallel
projection was inactive, and the view was centred at (0 0 0)
- Camera input now always requires 'position' and 'focalPoint'
- Clip box is now optional. Note that this is applied after the
camera
set-up and so will override the camera position
- View angle is only appropriate when not using parallel projection
- Zoom now required, applied after all other operations
- 1 = do nothing, >1 = zoom in, <1 = zoom out
Example input:
```
camera
{
// Total number of frames to generate
nFrameTotal 1;
// Parallel projection flag
parallelProjection no;
focalPoint (0 0 0);
up (0 1 0);
position (0 0 1);
// Optional entries
clipBox (-0.0206 -0.0254 -0.0005) (0.29 0.0254 0.0005);
viewAngle 20;
zoom 1.1;
}
```
See merge request !81
This commit is contained in:
@ -38,28 +38,6 @@ License
|
|||||||
#include "vtkRenderWindow.h"
|
#include "vtkRenderWindow.h"
|
||||||
#include "vtkWindowToImageFilter.h"
|
#include "vtkWindowToImageFilter.h"
|
||||||
|
|
||||||
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
namespace Foam
|
|
||||||
{
|
|
||||||
template<>
|
|
||||||
const char* NamedEnum
|
|
||||||
<
|
|
||||||
functionObjects::runTimePostPro::scene::modeType,
|
|
||||||
2
|
|
||||||
>::names[] =
|
|
||||||
{
|
|
||||||
"static",
|
|
||||||
"flightPath"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const Foam::NamedEnum
|
|
||||||
<
|
|
||||||
Foam::functionObjects::runTimePostPro::scene::modeType,
|
|
||||||
2
|
|
||||||
> modeTypeNames_;
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -92,9 +70,6 @@ void Foam::functionObjects::runTimePostPro::scene::readCamera
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dict.lookup("parallelProjection") >> parallelProjection_;
|
|
||||||
|
|
||||||
if (nFrameTotal_ > 1)
|
if (nFrameTotal_ > 1)
|
||||||
{
|
{
|
||||||
scalar endPosition = dict.lookupOrDefault<scalar>("endPosition", 1);
|
scalar endPosition = dict.lookupOrDefault<scalar>("endPosition", 1);
|
||||||
@ -107,54 +82,17 @@ void Foam::functionObjects::runTimePostPro::scene::readCamera
|
|||||||
dPosition_ = (endPosition - startPosition_)/scalar(nFrameTotal_ - 1);
|
dPosition_ = (endPosition - startPosition_)/scalar(nFrameTotal_ - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
mode_ = modeTypeNames_.read(dict.lookup("mode"));
|
cameraPosition_ = Function1<vector>::New("position", dict);
|
||||||
|
cameraFocalPoint_ = Function1<point>::New("focalPoint", dict);
|
||||||
|
cameraUp_ = Function1<vector>::New("up", dict);
|
||||||
|
|
||||||
word coeffsName = modeTypeNames_[mode_] + word("Coeffs");
|
dict.readIfPresent("clipBox", clipBox_);
|
||||||
const dictionary& coeffs = dict.subDict(coeffsName);
|
dict.lookup("parallelProjection") >> parallelProjection_;
|
||||||
|
if (!parallelProjection_)
|
||||||
switch (mode_)
|
|
||||||
{
|
{
|
||||||
case mtStatic:
|
|
||||||
{
|
|
||||||
clipBox_ = boundBox(coeffs.lookup("clipBox"));
|
|
||||||
const vector lookDir(vector(coeffs.lookup("lookDir")));
|
|
||||||
cameraPosition_.reset
|
|
||||||
(
|
|
||||||
new Function1Types::Constant<point>("position", -lookDir)
|
|
||||||
);
|
|
||||||
const vector focalPoint(coeffs.lookup("focalPoint"));
|
|
||||||
cameraFocalPoint_.reset
|
|
||||||
(
|
|
||||||
new Function1Types::Constant<point>("focalPoint", focalPoint)
|
|
||||||
);
|
|
||||||
const vector up(coeffs.lookup("up"));
|
|
||||||
cameraUp_.reset(new Function1Types::Constant<point>("up", up));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case mtFlightPath:
|
|
||||||
{
|
|
||||||
cameraPosition_.reset
|
|
||||||
(
|
|
||||||
Function1<vector>::New("position", coeffs).ptr()
|
|
||||||
);
|
|
||||||
cameraFocalPoint_.reset
|
|
||||||
(
|
|
||||||
Function1<point>::New("focalPoint", coeffs).ptr()
|
|
||||||
);
|
|
||||||
cameraUp_.reset(Function1<vector>::New("up", coeffs).ptr());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
FatalErrorInFunction
|
|
||||||
<< "Unhandled enumeration " << modeTypeNames_[mode_]
|
|
||||||
<< abort(FatalError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dict.found("viewAngle"))
|
if (dict.found("viewAngle"))
|
||||||
{
|
{
|
||||||
cameraViewAngle_.reset(Function1<scalar>::New("viewAngle", dict).ptr());
|
cameraViewAngle_ = Function1<scalar>::New("viewAngle", dict);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -163,6 +101,19 @@ void Foam::functionObjects::runTimePostPro::scene::readCamera
|
|||||||
new Function1Types::Constant<scalar>("viewAngle", 35.0)
|
new Function1Types::Constant<scalar>("viewAngle", 35.0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dict.found("zoom"))
|
||||||
|
{
|
||||||
|
cameraZoom_ = Function1<scalar>::New("zoom", dict);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cameraZoom_.reset
|
||||||
|
(
|
||||||
|
new Function1Types::Constant<scalar>("zoom", 1.0)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -224,25 +175,11 @@ void Foam::functionObjects::runTimePostPro::scene::initialise
|
|||||||
camera->SetParallelProjection(parallelProjection_);
|
camera->SetParallelProjection(parallelProjection_);
|
||||||
renderer->SetActiveCamera(camera);
|
renderer->SetActiveCamera(camera);
|
||||||
|
|
||||||
|
|
||||||
// Initialise the camera
|
|
||||||
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();
|
|
||||||
|
|
||||||
|
|
||||||
// Add the lights
|
// Add the lights
|
||||||
vtkSmartPointer<vtkLightKit> lightKit = vtkSmartPointer<vtkLightKit>::New();
|
vtkSmartPointer<vtkLightKit> lightKit = vtkSmartPointer<vtkLightKit>::New();
|
||||||
lightKit->AddLightsToRenderer(renderer);
|
lightKit->AddLightsToRenderer(renderer);
|
||||||
|
|
||||||
|
if (clipBox_ != boundBox::greatBox)
|
||||||
// For static mode initialise the clip box
|
|
||||||
if (mode_ == mtStatic)
|
|
||||||
{
|
{
|
||||||
const point& min = clipBox_.min();
|
const point& min = clipBox_.min();
|
||||||
const point& max = clipBox_.max();
|
const point& max = clipBox_.max();
|
||||||
@ -261,15 +198,10 @@ void Foam::functionObjects::runTimePostPro::scene::initialise
|
|||||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
clipMapper->SetInputConnection(clipBox->GetOutputPort());
|
clipMapper->SetInputConnection(clipBox->GetOutputPort());
|
||||||
|
|
||||||
vtkSmartPointer<vtkActor> clipActor = vtkSmartPointer<vtkActor>::New();
|
clipBoxActor_ = vtkSmartPointer<vtkActor>::New();
|
||||||
clipActor->SetMapper(clipMapper);
|
clipBoxActor_->SetMapper(clipMapper);
|
||||||
clipActor->VisibilityOff();
|
clipBoxActor_->VisibilityOff();
|
||||||
renderer->AddActor(clipActor);
|
renderer->AddActor(clipBoxActor_);
|
||||||
|
|
||||||
// Call resetCamera to fit clip box in view
|
|
||||||
clipActor->VisibilityOn();
|
|
||||||
renderer->ResetCamera();
|
|
||||||
clipActor->VisibilityOff();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,26 +211,44 @@ void Foam::functionObjects::runTimePostPro::scene::setCamera
|
|||||||
vtkRenderer* renderer
|
vtkRenderer* renderer
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
if (mode_ == mtFlightPath)
|
vtkCamera* camera = renderer->GetActiveCamera();
|
||||||
|
|
||||||
|
if (parallelProjection_)
|
||||||
{
|
{
|
||||||
|
// Restore parallel scale to allow application of zoom (later)
|
||||||
|
camera->SetParallelScale(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Restore viewAngle (it might be reset by clipping)
|
||||||
|
camera->SetViewAngle(cameraViewAngle_->value(position_));
|
||||||
|
}
|
||||||
|
|
||||||
const vector up = cameraUp_->value(position_);
|
const vector up = cameraUp_->value(position_);
|
||||||
const vector pos = cameraPosition_->value(position_);
|
const vector pos = cameraPosition_->value(position_);
|
||||||
const point focalPoint = cameraFocalPoint_->value(position_);
|
const point focalPoint = cameraFocalPoint_->value(position_);
|
||||||
|
const scalar zoom = cameraZoom_->value(position_);
|
||||||
|
|
||||||
vtkCamera* camera = renderer->GetActiveCamera();
|
|
||||||
camera->SetViewUp(up.x(), up.y(), up.z());
|
camera->SetViewUp(up.x(), up.y(), up.z());
|
||||||
camera->SetPosition(pos.x(), pos.y(), pos.z());
|
camera->SetPosition(pos.x(), pos.y(), pos.z());
|
||||||
camera->SetFocalPoint(focalPoint.x(), focalPoint.y(), focalPoint.z());
|
camera->SetFocalPoint(focalPoint.x(), focalPoint.y(), focalPoint.z());
|
||||||
camera->Modified();
|
|
||||||
|
|
||||||
|
// Apply clipping if required
|
||||||
|
// Note: possible optimisation - if the camera is static, this only needs
|
||||||
|
// to be done once on initialisation
|
||||||
|
if (clipBox_ != boundBox::greatBox)
|
||||||
|
{
|
||||||
|
// Call ResetCamera() to fit clip box in view
|
||||||
|
clipBoxActor_->VisibilityOn();
|
||||||
|
renderer->ResetCamera();
|
||||||
|
clipBoxActor_->VisibilityOff();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parallelProjection_)
|
// Zoom applied after all other operations
|
||||||
{
|
camera->Zoom(zoom);
|
||||||
// Restore viewAngle (it might be reset by clipping)
|
|
||||||
vtkCamera* camera = renderer->GetActiveCamera();
|
|
||||||
camera->SetViewAngle(cameraViewAngle_->value(position_));
|
|
||||||
camera->Modified();
|
camera->Modified();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -323,12 +273,13 @@ Foam::functionObjects::runTimePostPro::scene::scene
|
|||||||
obr_(obr),
|
obr_(obr),
|
||||||
name_(name),
|
name_(name),
|
||||||
colours_(),
|
colours_(),
|
||||||
mode_(mtStatic),
|
|
||||||
cameraPosition_(nullptr),
|
cameraPosition_(nullptr),
|
||||||
cameraFocalPoint_(nullptr),
|
cameraFocalPoint_(nullptr),
|
||||||
cameraUp_(nullptr),
|
cameraUp_(nullptr),
|
||||||
cameraViewAngle_(nullptr),
|
cameraViewAngle_(nullptr),
|
||||||
clipBox_(),
|
cameraZoom_(nullptr),
|
||||||
|
clipBox_(boundBox::greatBox),
|
||||||
|
clipBoxActor_(),
|
||||||
parallelProjection_(true),
|
parallelProjection_(true),
|
||||||
nFrameTotal_(1),
|
nFrameTotal_(1),
|
||||||
startPosition_(0),
|
startPosition_(0),
|
||||||
@ -366,7 +317,10 @@ Foam::scalar Foam::functionObjects::runTimePostPro::scene::position() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::functionObjects::runTimePostPro::scene::read(const dictionary& dict)
|
void Foam::functionObjects::runTimePostPro::scene::read
|
||||||
|
(
|
||||||
|
const dictionary& dict
|
||||||
|
)
|
||||||
{
|
{
|
||||||
readCamera(dict.subDict("camera"));
|
readCamera(dict.subDict("camera"));
|
||||||
readColours(dict.subDict("colours"));
|
readColours(dict.subDict("colours"));
|
||||||
|
|||||||
@ -25,6 +25,28 @@ Class
|
|||||||
Foam::functionObjects::runTimePostPro::scene
|
Foam::functionObjects::runTimePostPro::scene
|
||||||
|
|
||||||
Description
|
Description
|
||||||
|
Class to control scene construction and provide main rendering loop
|
||||||
|
|
||||||
|
Usage
|
||||||
|
\verbatim
|
||||||
|
camera
|
||||||
|
{
|
||||||
|
// Total number of frames to generate
|
||||||
|
nFrameTotal 1;
|
||||||
|
|
||||||
|
// Parallel projection flag
|
||||||
|
parallelProjection no;
|
||||||
|
|
||||||
|
focalPoint (0 0 0);
|
||||||
|
up (0 1 0);
|
||||||
|
position (0 0 1);
|
||||||
|
|
||||||
|
// Optional entries
|
||||||
|
clipBox (-0.0206 -0.0254 -0.0005) (0.29 0.0254 0.0005);
|
||||||
|
viewAngle 20;
|
||||||
|
zoom 1.1;
|
||||||
|
}
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
scene.C
|
scene.C
|
||||||
@ -49,6 +71,7 @@ SourceFiles
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
class vtkActor;
|
||||||
class vtkRenderer;
|
class vtkRenderer;
|
||||||
class vtkRenderWindow;
|
class vtkRenderWindow;
|
||||||
|
|
||||||
@ -58,22 +81,12 @@ namespace functionObjects
|
|||||||
{
|
{
|
||||||
namespace runTimePostPro
|
namespace runTimePostPro
|
||||||
{
|
{
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class scene Declaration
|
Class scene Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class scene
|
class scene
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
|
|
||||||
enum modeType{mtStatic, mtFlightPath};
|
|
||||||
|
|
||||||
NamedEnum<modeType, 2> modeTypeNames_;
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
//- Reference to the object registry
|
//- Reference to the object registry
|
||||||
@ -88,7 +101,7 @@ private:
|
|||||||
//- Read camera properties
|
//- Read camera properties
|
||||||
void readCamera(const dictionary& dict);
|
void readCamera(const dictionary& dict);
|
||||||
|
|
||||||
//- Read solour properties
|
//- Read colour properties
|
||||||
void readColours(const dictionary& dict);
|
void readColours(const dictionary& dict);
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
@ -108,9 +121,6 @@ protected:
|
|||||||
|
|
||||||
// Camera settings
|
// Camera settings
|
||||||
|
|
||||||
//- Mode
|
|
||||||
modeType mode_;
|
|
||||||
|
|
||||||
//- Position
|
//- Position
|
||||||
autoPtr<Function1<point>> cameraPosition_;
|
autoPtr<Function1<point>> cameraPosition_;
|
||||||
|
|
||||||
@ -123,12 +133,20 @@ protected:
|
|||||||
//- View angle
|
//- View angle
|
||||||
autoPtr<Function1<scalar>> cameraViewAngle_;
|
autoPtr<Function1<scalar>> cameraViewAngle_;
|
||||||
|
|
||||||
|
//- Zoom: 1 = do nothing, >1 = zoom in, <1 = zoom out
|
||||||
|
// - perspective mode: reduces view angle
|
||||||
|
// - parallel mode: manipulate parallel scale
|
||||||
|
autoPtr<Function1<scalar>> cameraZoom_;
|
||||||
|
|
||||||
|
|
||||||
// Scene management
|
// Scene management
|
||||||
|
|
||||||
//- Clipping box
|
//- Clipping box
|
||||||
boundBox clipBox_;
|
boundBox clipBox_;
|
||||||
|
|
||||||
|
//- Clipping box actor
|
||||||
|
vtkSmartPointer<vtkActor> clipBoxActor_;
|
||||||
|
|
||||||
//- Parallel projection flag
|
//- Parallel projection flag
|
||||||
bool parallelProjection_;
|
bool parallelProjection_;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user