From 15192e732b61b2832e2a025140c4d19c45e6f852 Mon Sep 17 00:00:00 2001 From: Prashant Date: Thu, 19 May 2016 18:00:58 +0530 Subject: [PATCH 1/5] BUG: -case argument support and nFrames > 1 warning for static mode --- .../graphics/runTimePostProcessing/scene.C | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.C b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.C index c96e36566c..86e577a47a 100644 --- a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.C +++ b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.C @@ -111,6 +111,12 @@ void Foam::scene::readCamera(const dictionary& dict) ); const vector up(coeffs.lookup("up")); cameraUp_.reset(new Constant("up", up)); + if (nFrameTotal_ > 1) + { + WarningInFunction + << "Static mode with nFrames > 1 - please check your setup" + << endl; + } break; } case mtFlightPath: @@ -375,7 +381,12 @@ void Foam::scene::saveImage(vtkRenderWindow* renderWindow) const return; } - fileName prefix("postProcessing"/name_/obr_.time().timeName()); + const Time& runTime = obr_.time(); + + fileName prefix(Pstream::parRun() + ? runTime.path()/".."/"postProcessing"/name_/obr_.time().timeName() + : runTime.path()/"postProcessing"/name_/obr_.time().timeName()); + mkDir(prefix); renderWindow->Render(); From 9b14a948983ec41fed81d70b88183296e7b6bb17 Mon Sep 17 00:00:00 2001 From: Prashant Date: Wed, 25 May 2016 14:54:31 +0530 Subject: [PATCH 2/5] Fixes #99 #127 #128 #138 --- .../runTimePostProcessing.C | 10 ++++++-- .../graphics/runTimePostProcessing/scene.C | 24 +++++++++---------- .../graphics/runTimePostProcessing/scene.H | 3 +++ .../graphics/runTimePostProcessing/text.C | 11 +++++++-- .../graphics/runTimePostProcessing/text.H | 20 ++++++++++++++++ 5 files changed, 52 insertions(+), 16 deletions(-) diff --git a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.C b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.C index 88857bf924..d31b5403d5 100644 --- a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.C +++ b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/runTimePostProcessing.C @@ -177,14 +177,20 @@ void Foam::runTimePostProcessing::write() surfaces_[i].addGeometryToScene(0, renderer); } + // Add the text + forAll(text_, i) + { + text_[i].addGeometryToScene(0, renderer); + } + while (scene_.loop(renderer)) { scalar position = scene_.position(); - // Add the text + // Update the text forAll(text_, i) { - text_[i].addGeometryToScene(position, renderer); + text_[i].updateActors(position); } // Update the points diff --git a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.C b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.C index 86e577a47a..727300d077 100644 --- a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.C +++ b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.C @@ -67,14 +67,18 @@ void Foam::scene::readCamera(const dictionary& dict) } } - if (dict.readIfPresent("startPosition", position_)) + if (dict.readIfPresent("startPosition", startPosition_)) { - if ((position_ < 0) || (position_ > 1)) + if ((startPosition_ < 0) || (startPosition_ > 1)) { FatalIOErrorInFunction(dict) << "startPosition must be in the range 0-1" << exit(FatalIOError); } + else + { + position_ = startPosition_; + } } @@ -89,7 +93,7 @@ void Foam::scene::readCamera(const dictionary& dict) << "endPosition must be in the range 0-1" << exit(FatalIOError); } - dPosition_ = (endPosition - position_)/scalar(nFrameTotal_ - 1); + dPosition_ = (endPosition - startPosition_)/scalar(nFrameTotal_ - 1); } mode_ = modeTypeNames_.read(dict.lookup("mode")); @@ -111,12 +115,6 @@ void Foam::scene::readCamera(const dictionary& dict) ); const vector up(coeffs.lookup("up")); cameraUp_.reset(new Constant("up", up)); - if (nFrameTotal_ > 1) - { - WarningInFunction - << "Static mode with nFrames > 1 - please check your setup" - << endl; - } break; } case mtFlightPath: @@ -296,6 +294,7 @@ Foam::scene::scene(const objectRegistry& obr, const word& name) clipBox_(), parallelProjection_(true), nFrameTotal_(1), + startPosition_(0), position_(0), dPosition_(0), currentFrameI_(0), @@ -354,14 +353,15 @@ bool Foam::scene::loop(vtkRenderer* renderer) currentFrameI_++; - if (position_ > (1 + 0.5*dPosition_)) + // Warning only if camera is in flight mode + if ((mode_ == mtFlightPath) && (position_ > (1 + 0.5*dPosition_))) { WarningInFunction - << "Current position exceeded 1 - please check your setup" + << "Current position "<< position_ <<" exceeded 1 - please check your setup" << endl; } - position_ += dPosition_; + position_ = startPosition_ + currentFrameI_*dPosition_; if (currentFrameI_ < nFrameTotal_) { diff --git a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.H b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.H index d3bd156e39..d5cf0661cc 100644 --- a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.H +++ b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.H @@ -134,6 +134,9 @@ protected: //- Number of frames label nFrameTotal_; + //- startPosition [0-1] + scalar startPosition_; + //- Position [0-1] scalar position_; diff --git a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/text.C b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/text.C index b4c1ff3f86..407083843e 100644 --- a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/text.C +++ b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/text.C @@ -47,7 +47,8 @@ Foam::text::text position_(dict.lookup("position")), size_(readScalar(dict.lookup("size"))), colour_(NULL), - bold_(readBool(dict.lookup("bold"))) + bold_(readBool(dict.lookup("bold"))), + timeStamp_(dict.lookupOrDefault("timeStamp", false)) { if (dict.found("colour")) { @@ -81,7 +82,13 @@ void Foam::text::addGeometryToScene vtkSmartPointer actor = vtkSmartPointer::New(); - actor->SetInput(string_.c_str()); + // Concatenate string with timeStamp if true + string textAndTime = string_; + if (timeStamp_) + { + textAndTime = textAndTime + " " + geometryBase::parent_.obr().time().timeName(); + } + actor->SetInput(textAndTime.c_str()); actor->GetTextProperty()->SetFontFamilyToArial(); actor->GetTextProperty()->SetFontSize(size_); actor->GetTextProperty()->SetJustificationToLeft(); diff --git a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/text.H b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/text.H index bee0020ef5..583268303c 100644 --- a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/text.H +++ b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/text.H @@ -25,6 +25,23 @@ Class Foam::text Description + Example of text object specification: + \verbatim + text1 + { + string "text to display"; + position (0.1 0.05); + size 18; + bold yes; + visible yes; + + // Optionally override default colour + // colour (0 1 1); + + // Optional entry + timeStamp yes; //Append solution time to string + } + \endverbatim SourceFiles text.C @@ -82,6 +99,9 @@ protected: //- Bold flag bool bold_; + //- Time stamp flag + bool timeStamp_; + public: From 47036d4fd4059b14dcf0e906656656f6074fc3de Mon Sep 17 00:00:00 2001 From: Prashant Date: Wed, 25 May 2016 18:09:13 +0530 Subject: [PATCH 3/5] BugFix: viewAngle reset in static camera mode --- .../graphics/runTimePostProcessing/scene.C | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.C b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.C index 727300d077..d471f7981e 100644 --- a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.C +++ b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.C @@ -237,6 +237,15 @@ void Foam::scene::initialise(vtkRenderer* renderer, const word& outputName) renderer->ResetCamera(); + // Restore viewAngle (it might be reset by clipping) + vtkCamera* camera = renderer->GetActiveCamera(); + + if (!parallelProjection_) + { + camera->SetViewAngle(cameraViewAngle_->value(position())); + } + camera->Modified(); + clipActor->VisibilityOff(); } } From 430b6208e6fe2b79e9241761d88b3a9bde0f1d3a Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Fri, 10 Jun 2016 15:21:48 +0100 Subject: [PATCH 4/5] BUG: Run time post-processing - corrected surfaces rendered by colour. Fixes #97 --- .../runTimePostProcessing/functionObjectSurface.C | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/functionObjectSurface.C b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/functionObjectSurface.C index e7c6c69176..2feb877193 100644 --- a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/functionObjectSurface.C +++ b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/functionObjectSurface.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -124,7 +124,7 @@ void Foam::functionObjectSurface::addGeometryToScene } else { - if ((colourBy_ == cbField) && (fName.ext() == "vtk")) + if (fName.ext() == "vtk") { vtkSmartPointer surf = vtkSmartPointer::New(); @@ -147,7 +147,9 @@ void Foam::functionObjectSurface::addGeometryToScene } else { - geometrySurface::addGeometryToScene(position, renderer); + WarningInFunction + << "Only VTK file types are supported" + << endl; } } } From 151bcc8018d5faf1ad0cb735ce071a6877255164 Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Fri, 10 Jun 2016 15:23:56 +0100 Subject: [PATCH 5/5] ENH: Run time post-processing updates and bug fixing. Fixes #128 #121 #99 --- .../fieldVisualisationBase.C | 37 +++---- .../graphics/runTimePostProcessing/scene.C | 98 +++++++++---------- .../graphics/runTimePostProcessing/scene.H | 11 +-- 3 files changed, 68 insertions(+), 78 deletions(-) diff --git a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/fieldVisualisationBase.C b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/fieldVisualisationBase.C index ed48eb60c0..ae440ca80c 100644 --- a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/fieldVisualisationBase.C +++ b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/fieldVisualisationBase.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -453,31 +453,32 @@ Foam::fieldVisualisationBase::fieldVisualisationBase { case cbColour: { + scalarBar_.visible_ = false; break; } case cbField: { dict.lookup("range") >> range_; + + 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_; + } 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_; - } } diff --git a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.C b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.C index d471f7981e..7808ed058f 100644 --- a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.C +++ b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.C @@ -138,15 +138,6 @@ void Foam::scene::readCamera(const dictionary& dict) } } - if (dict.found("zoom")) - { - cameraZoom_.reset(DataEntry::New("zoom", dict).ptr()); - } - else - { - cameraZoom_.reset(new Constant("zoom", 1.0)); - } - if (dict.found("viewAngle")) { cameraViewAngle_.reset(DataEntry::New("viewAngle", dict).ptr()); @@ -172,11 +163,12 @@ void Foam::scene::readColours(const dictionary& dict) void Foam::scene::initialise(vtkRenderer* renderer, const word& outputName) { currentFrameI_ = 0; + position_ = startPosition_; outputName_ = outputName; // Set the background - const vector backgroundColour = colours_["background"]->value(position()); + const vector backgroundColour = colours_["background"]->value(position_); renderer->SetBackground ( backgroundColour.x(), @@ -188,7 +180,7 @@ void Foam::scene::initialise(vtkRenderer* renderer, const word& outputName) if (colours_.found("background2")) { renderer->GradientBackgroundOn(); - vector backgroundColour2 = colours_["background2"]->value(position()); + vector backgroundColour2 = colours_["background2"]->value(position_); renderer->SetBackground2 ( @@ -208,9 +200,24 @@ void Foam::scene::initialise(vtkRenderer* renderer, const word& outputName) camera->SetParallelProjection(parallelProjection_); renderer->SetActiveCamera(camera); - setCamera(renderer, true); - // Initialise the extents + // 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 + vtkSmartPointer lightKit = vtkSmartPointer::New(); + lightKit->AddLightsToRenderer(renderer); + + + // For static mode initialise the clip box if (mode_ == mtStatic) { const point& min = clipBox_.min(); @@ -232,48 +239,38 @@ void Foam::scene::initialise(vtkRenderer* renderer, const word& outputName) vtkSmartPointer clipActor = vtkSmartPointer::New(); clipActor->SetMapper(clipMapper); - clipActor->VisibilityOn(); + clipActor->VisibilityOff(); renderer->AddActor(clipActor); + // Call resetCamera to fit clip box in view + clipActor->VisibilityOn(); renderer->ResetCamera(); - - // Restore viewAngle (it might be reset by clipping) - vtkCamera* camera = renderer->GetActiveCamera(); - - if (!parallelProjection_) - { - camera->SetViewAngle(cameraViewAngle_->value(position())); - } - camera->Modified(); - clipActor->VisibilityOff(); } } -void Foam::scene::setCamera(vtkRenderer* renderer, const bool override) const +void Foam::scene::setCamera(vtkRenderer* renderer) const { - if (mode_ == mtFlightPath || override) + if (mode_ == mtFlightPath) { + const vector up = cameraUp_->value(position_); + const vector pos = cameraPosition_->value(position_); + const point focalPoint = cameraFocalPoint_->value(position_); + 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 lightKit = - vtkSmartPointer::New(); - lightKit->AddLightsToRenderer(renderer); + if (!parallelProjection_) + { + // Restore viewAngle (it might be reset by clipping) + vtkCamera* camera = renderer->GetActiveCamera(); + camera->SetViewAngle(cameraViewAngle_->value(position_)); + camera->Modified(); } } @@ -298,7 +295,6 @@ Foam::scene::scene(const objectRegistry& obr, const word& name) cameraPosition_(NULL), cameraFocalPoint_(NULL), cameraUp_(NULL), - cameraZoom_(NULL), cameraViewAngle_(NULL), clipBox_(), parallelProjection_(true), @@ -348,8 +344,7 @@ void Foam::scene::read(const dictionary& dict) bool Foam::scene::loop(vtkRenderer* renderer) { static bool initialised = false; - - setCamera(renderer, false); + setCamera(renderer); if (!initialised) { @@ -357,19 +352,15 @@ bool Foam::scene::loop(vtkRenderer* renderer) return true; } + // Ensure that all objects can be seen without clipping + // Note: can only be done after all objects have been added! + renderer->ResetCameraClippingRange(); + // Save image from last iteration saveImage(renderer->GetRenderWindow()); currentFrameI_++; - // Warning only if camera is in flight mode - if ((mode_ == mtFlightPath) && (position_ > (1 + 0.5*dPosition_))) - { - WarningInFunction - << "Current position "<< position_ <<" exceeded 1 - please check your setup" - << endl; - } - position_ = startPosition_ + currentFrameI_*dPosition_; if (currentFrameI_ < nFrameTotal_) @@ -378,6 +369,7 @@ bool Foam::scene::loop(vtkRenderer* renderer) } else { + initialised = false; return false; } } @@ -392,9 +384,9 @@ void Foam::scene::saveImage(vtkRenderWindow* renderWindow) const const Time& runTime = obr_.time(); - fileName prefix(Pstream::parRun() - ? runTime.path()/".."/"postProcessing"/name_/obr_.time().timeName() - : runTime.path()/"postProcessing"/name_/obr_.time().timeName()); + fileName prefix(Pstream::parRun() ? + runTime.path()/".."/"postProcessing"/name_/obr_.time().timeName() : + runTime.path()/"postProcessing"/name_/obr_.time().timeName()); mkDir(prefix); diff --git a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.H b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.H index d5cf0661cc..afc40696c4 100644 --- a/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.H +++ b/src/postProcessing/functionObjects/graphics/runTimePostProcessing/scene.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -22,7 +22,7 @@ License along with OpenFOAM. If not, see . Class - Foam::camera + Foam::scene Description @@ -116,9 +116,6 @@ protected: //- Up direction autoPtr > cameraUp_; - //- Zoom level - autoPtr > cameraZoom_; - //- View angle autoPtr > cameraViewAngle_; @@ -134,7 +131,7 @@ protected: //- Number of frames label nFrameTotal_; - //- startPosition [0-1] + //- Start position [0-1] scalar startPosition_; //- Position [0-1] @@ -152,7 +149,7 @@ protected: // Protected Member Functions - void setCamera(vtkRenderer* renderer, const bool override) const; + void setCamera(vtkRenderer* renderer) const; string frameIndexStr() const;