In January 2021 we will introduce a 10 GB quota for project repositories. Higher limits for individual projects will be available on request. Please see https://doku.lrz.de/display/PUBLIC/GitLab for more information.

Renamed CampvisPainter to PipelinePainter. The PipelinePainter now directly...

Renamed CampvisPainter to PipelinePainter. The PipelinePainter now directly belongs to the corresponding AbstractPipeline, which also owns the pointer and takes care of creating, (de-)initializing and destroying it.
parent a916097f
......@@ -35,7 +35,6 @@
#include "cgt/texturereadertga.h"
#include "cgt/qt/qtthreadedcanvas.h"
#include "application/campvispainter.h"
#include "application/gui/properties/propertywidgetfactory.h"
#include "application/gui/mainwindow.h"
#include "application/gui/mdi/mdidockablewindow.h"
......@@ -45,6 +44,7 @@
#include "core/tools/quadrenderer.h"
#include "core/pipeline/abstractpipeline.h"
#include "core/pipeline/abstractworkflow.h"
#include "core/pipeline/pipelinepainter.h"
#include "core/datastructures/imagerepresentationconverter.h"
#include "core/pipeline/visualizationprocessor.h"
......@@ -218,8 +218,8 @@ namespace campvis {
cgtAssert(_initialized, "Tried to deinitialize uninitialized CampVisApplication.");
// Stop all pipeline threads.
for (std::vector<PipelineRecord>::iterator it = _pipelines.begin(); it != _pipelines.end(); ++it) {
it->_pipeline->stop();
for (auto it = _pipelines.begin(); it != _pipelines.end(); ++it) {
(*it)->stop();
}
for (auto it = _workflows.begin(); it != _workflows.end(); ++it)
......@@ -232,9 +232,8 @@ namespace campvis {
delete _errorTexture;
// Deinit pipeline and painter first
for (std::vector<PipelineRecord>::iterator it = _pipelines.begin(); it != _pipelines.end(); ++it) {
it->_pipeline->deinit();
it->_painter->deinit();
for (auto it = _pipelines.begin(); it != _pipelines.end(); ++it) {
(*it)->deinit();
}
_mainWindow->deinit();
......@@ -242,11 +241,10 @@ namespace campvis {
}
// now delete everything in the right order:
for (std::vector<PipelineRecord>::iterator it = _pipelines.begin(); it != _pipelines.end(); ++it) {
delete it->_painter;
delete it->_pipeline;
for (auto it = _pipelines.begin(); it != _pipelines.end(); ++it) {
delete *it;
}
for (std::vector<DataContainer*>::iterator it = _dataContainers.begin(); it != _dataContainers.end(); ++it) {
for (auto it = _dataContainers.begin(); it != _dataContainers.end(); ++it) {
delete *it;
}
......@@ -291,14 +289,10 @@ namespace campvis {
cgt::QtThreadedCanvas* canvas = new cgt::QtThreadedCanvas("CAMPVis", cgt::ivec2(512, 512));
canvas->init();
CampVisPainter* painter = new CampVisPainter(canvas, pipeline);
canvas->setPainter(painter, false);
pipeline->setCanvas(canvas);
painter->setErrorTexture(_errorTexture);
PipelineRecord pr = { pipeline, painter };
_pipelines.push_back(pr);
pipeline->getPipelinePainter()->setErrorTexture(_errorTexture);
_pipelines.push_back(pipeline);
_pipelineWindows[pipeline] = _mainWindow->addVisualizationPipelineWidget(name, canvas);
// initialize context (GLEW) and pipeline in OpenGL thread)
......@@ -362,8 +356,8 @@ namespace campvis {
LINFO("Rebuilding shaders from file successful.");
}
for (std::vector<PipelineRecord>::iterator it = _pipelines.begin(); it != _pipelines.end(); ++it) {
for (std::vector<AbstractProcessor*>::const_iterator pit = it->_pipeline->getProcessors().begin(); pit != it->_pipeline->getProcessors().end(); ++pit) {
for (auto it = _pipelines.begin(); it != _pipelines.end(); ++it) {
for (auto pit = (*it)->getProcessors().cbegin(); pit != (*it)->getProcessors().cend(); ++pit) {
if (VisualizationProcessor* tester = dynamic_cast<VisualizationProcessor*>(*pit)) {
tester->invalidate(AbstractProcessor::INVALID_RESULT);
}
......
......@@ -50,7 +50,6 @@ namespace campvis {
class AbstractPipeline;
class AbstractWorkflow;
class MainWindow;
class CampVisPainter;
class MdiDockableWindow;
class LuaVmState;
......@@ -70,12 +69,6 @@ namespace campvis {
friend class MainWindow;
public:
/// Record storing a pipeline together with its painter and Lua VM state.
struct PipelineRecord {
AbstractPipeline* _pipeline;
CampVisPainter* _painter;
};
/**
* Creates a new CampVisApplication.
* \param argc number of passed arguments
......@@ -167,7 +160,7 @@ namespace campvis {
std::vector<AbstractWorkflow*> _workflows;
/// All pipelines
std::vector<PipelineRecord> _pipelines;
std::vector<AbstractPipeline*> _pipelines;
/// Map of all pipelines with their MDI windows
std::map<AbstractPipeline*, MdiDockableWindow*> _pipelineWindows;
......
......@@ -114,7 +114,7 @@ namespace campvis {
createQuad();
// set this as painter to get notified when window size changes
setPainter(this, false);
setPainter(this);
getEventHandler()->addEventListenerToFront(this);
_geometryRenderer.init();
......
......@@ -239,17 +239,11 @@ namespace campvis {
}
void MainWindow::onPipelinesChanged() {
std::vector<AbstractPipeline*> pipelines;
std::for_each(_application->_pipelines.begin(), _application->_pipelines.end(), [&] (const CampVisApplication::PipelineRecord& pr) { pipelines.push_back(pr._pipeline); });
emit updatePipelineWidget(_application->_dataContainers, pipelines);
emit updatePipelineWidget(_application->_dataContainers, _application->_pipelines);
}
void MainWindow::onDataContainersChanged() {
std::vector<AbstractPipeline*> pipelines;
std::for_each(_application->_pipelines.begin(), _application->_pipelines.end(), [&] (const CampVisApplication::PipelineRecord& pr) { pipelines.push_back(pr._pipeline); });
emit updatePipelineWidget(_application->_dataContainers, pipelines);
emit updatePipelineWidget(_application->_dataContainers, _application->_pipelines);
}
void MainWindow::onPipelineWidgetItemChanged(const QModelIndex& index) {
......@@ -439,10 +433,7 @@ namespace campvis {
p->init();
_selectedPipeline->addProcessor(p);
std::vector<AbstractPipeline*> pipelines;
std::for_each(_application->_pipelines.begin(), _application->_pipelines.end(), [&] (const CampVisApplication::PipelineRecord& pr) { pipelines.push_back(pr._pipeline); });
emit updatePipelineWidget(_application->_dataContainers, pipelines);
emit updatePipelineWidget(_application->_dataContainers, _application->_pipelines);
}
void MainWindow::onRebuildShadersClicked() {
......
......@@ -232,7 +232,7 @@ namespace campvis {
GLCtxtMgr.registerContextAndInitGlew(_canvas, "Geometry1DTransferFunctionEditor");
GLCtxtMgr.releaseContext(_canvas, false);
_canvas->setPainter(this, false);
_canvas->setPainter(this);
_layout->addWidget(_canvas, 1, 1, 3, 3);
_lblIntensityLeft = new QLabel(QString::number(gtf->getIntensityDomain().x), this);
......
......@@ -219,7 +219,7 @@ namespace campvis {
GLCtxtMgr.registerContextAndInitGlew(_canvas, "Geometry2DTransferFunctionEditor");
GLCtxtMgr.releaseContext(_canvas, false);
_canvas->setPainter(this, false);
_canvas->setPainter(this);
_layout->addWidget(_canvas, 1, 1, 3, 3);
_lblIntensityLeft = new QLabel(QString::number(gtf->getIntensityDomain().x), this);
......
......@@ -52,6 +52,8 @@ namespace campvis {
{
cgtAssert(_data != 0, "Pointer to the DataContainer for this pipeline must not be 0!");
_painter.reset(new PipelinePainter(nullptr, this));
_enabled = false;
_pipelineDirty = true;
......@@ -60,12 +62,12 @@ namespace campvis {
}
AbstractPipeline::~AbstractPipeline() {
}
void AbstractPipeline::init() {
_data->s_dataAdded.connect(this, &AbstractPipeline::onDataContainerDataAdded);
_painter->init();
initAllProperties();
// initialize all processors:
......@@ -89,6 +91,7 @@ namespace campvis {
s_deinit.triggerSignal();
deinitAllProperties();
_painter->deinit();
// deinitialize all processors:
for (std::vector<AbstractProcessor*>::iterator it = _processors.begin(); it != _processors.end(); ++it) {
......@@ -240,7 +243,13 @@ namespace campvis {
}
void AbstractPipeline::setCanvas(cgt::GLCanvas* canvas) {
if (_canvas != nullptr)
_canvas->setPainter(nullptr);
_canvas = canvas;
if (_canvas != nullptr)
_canvas->setPainter(_painter.get());
}
void AbstractPipeline::setRenderTargetSize(const cgt::ivec2& size) {
......@@ -297,5 +306,10 @@ namespace campvis {
processor->setEnabled(enabledState);
}
const std::unique_ptr<PipelinePainter>& AbstractPipeline::getPipelinePainter() const {
return _painter;
}
}
......@@ -38,11 +38,13 @@
#include "core/coreapi.h"
#include "core/datastructures/datacontainer.h"
#include "core/pipeline/pipelinepainter.h"
#include "core/properties/datanameproperty.h"
#include "core/properties/floatingpointproperty.h"
#include "core/properties/propertycollection.h"
#include <map>
#include <memory>
#include <vector>
namespace cgt {
......@@ -126,6 +128,11 @@ namespace campvis {
* To be implemented in the subclass.
*/
virtual void executePipeline() = 0;
/**
* Sets the resultDirty flag of this pipeline and starts its execution if necessary.
*/
void setPipelineDirty();
/**
* Paints an additional overlay directly onto the frame buffer.
......@@ -208,17 +215,18 @@ namespace campvis {
*/
IVec2Property& getCanvasSize() {return _canvasSize;}
/**
* Returns this pipelines PipelinePainter.
* \return _painter
*/
const std::unique_ptr<PipelinePainter>& getPipelinePainter() const;
/// Signal emitted at the end of AbstractPipeline::init()
sigslot::signal0 s_init;
/// Signal emitted at the beginning of AbstractPipeline::deinit()
sigslot::signal0 s_deinit;
protected:
/**
* Sets the resultDirty flag of this pipeline and starts its execution if necessary.
*/
void setPipelineDirty();
/**
* Forces the execution of the given processor regardless of its invalidation or enabled state.
* \param processor Processor to execute.
......@@ -259,7 +267,8 @@ namespace campvis {
std::vector<AbstractProcessor*> _processors; ///< List of all processors of this pipeline
cgt::GLCanvas* _canvas; ///< Canvas hosting the OpenGL context for this pipeline.
cgt::GLCanvas* _canvas; ///< Canvas hosting the OpenGL context for this pipeline. We do *not* own this pointer.
std::unique_ptr<PipelinePainter> _painter; ///< PipelinePainter used to paint this pipeline's result onto the canvas.
IVec2Property _canvasSize; ///< original canvas size
bool _ignoreCanvasSizeUpdate;
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#ifndef CAMPVISPAINTER_H__
#define CAMPVISPAINTER_H__
#include "sigslot/sigslot.h"
#include <ext/threading.h>
#include <tbb/atomic.h>
#include "cgt/logmanager.h"
#include "cgt/painter.h"
namespace cgt {
class Shader;
class QtThreadedCanvas;
class Texture;
}
namespace campvis {
class AbstractPipeline;
/**
* Painter class for CAMPVis, rendering the render target of an AbstractPipeline.
*/
class CampVisPainter : public cgt::Painter, public sigslot::has_slots {
public:
/**
* Creates a new CampVisPainter rendering the render target of \a pipeline on \a canvas.
* \param canvas Canvas to render on
* \param pipeline Pipeline to render
*/
CampVisPainter(cgt::GLCanvas* canvas, AbstractPipeline* pipeline);
/**
* Destructor, stops and waits for the rendering thread if it's still running.
*/
virtual ~CampVisPainter();
/**
* Schedule a repaint job for the pipeline's render target
*/
virtual void repaint();
/// \see cgt::Painter::sizeChanged
virtual void sizeChanged(const cgt::ivec2& size);
/**
* Initializes the painter, i.e. loads the OpenGL shader.
*/
virtual void init();
/**
* Deinitializes the painter, i.e. disposes its shader.
*/
virtual void deinit();
/**
* Sets the target canvas for rendering
* \param canvas Canvas to render on, must be of type QtThreadedCanvas
*/
virtual void setCanvas(cgt::GLCanvas* canvas);
/**
* Pipeline with the render target to render.
* \param pipeline Pipeline to render
*/
void setPipeline(AbstractPipeline* pipeline);
void setErrorTexture(cgt::Texture* texture);
private:
/**
* Performs the actual rendering of the pipeline's render target
*/
virtual void paint();
static const std::string loggerCat_;
AbstractPipeline* _pipeline; ///< Pipeline to render
cgt::Shader* _copyShader; ///< Shader for copying the render target to the framebuffer.
cgt::Texture* _errorTexture; ///< Pointer to error texture
};
}
#endif // CAMPVISPAINTER_H__
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#ifndef CAMPVISPAINTER_H__
#define CAMPVISPAINTER_H__
#include "sigslot/sigslot.h"
#include "cgt/glcanvas.h"
#include "cgt/painter.h"
#include "core/coreapi.h"
namespace cgt {
class GLCanvas;
class Shader;
class Texture;
}
namespace campvis {
class AbstractPipeline;
/**
* Painter class for CAMPVis, rendering the render target of an AbstractPipeline.
*/
class CAMPVIS_CORE_API PipelinePainter : public cgt::Painter, public sigslot::has_slots {
public:
/**
* Creates a new PipelinePainter rendering the render target of \a pipeline on \a canvas.
* \param canvas Canvas to render on
* \param pipeline Pipeline to render
*/
PipelinePainter(cgt::GLCanvas* canvas, AbstractPipeline* pipeline);
/**
* Schedule a repaint job for the pipeline's render target
*/
virtual void repaint();
/// \see cgt::Painter::sizeChanged
virtual void sizeChanged(const cgt::ivec2& size);
/**
* Initializes the painter, i.e. loads the OpenGL shader.
*/
virtual void init();
/**
* Deinitializes the painter, i.e. disposes its shader.
*/
virtual void deinit();
virtual void setCanvas(cgt::GLCanvas* canvas) override;
/**
* Sets the error texture to \a texture.
* \param texture The new error texture to display when no rendering can be shown, must not be 0.
*/
void setErrorTexture(cgt::Texture* texture);
private:
/**
* Performs the actual rendering of the pipeline's render target
*/
virtual void paint();
static const std::string loggerCat_;
AbstractPipeline* _pipeline; ///< Pipeline to render
cgt::Shader* _copyShader; ///< Shader for copying the render target to the framebuffer.
cgt::Texture* _errorTexture; ///< Pointer to error texture
};
}
#endif // CAMPVISPAINTER_H__
......@@ -80,27 +80,15 @@ void GLCanvas::init() {
// nothing here, may be implemented in sub classes.
}
void GLCanvas::setPainter(Painter* p, bool initP) {
void GLCanvas::setPainter(Painter* p) {
painter_ = p;
painter_->setCanvas(this);
if (initP)
initPainter();
}
Painter* GLCanvas::getPainter() const {
return painter_;
}
void GLCanvas::initPainter() {
if (painter_) {
{
GLContextScopedLock lock(this);
painter_->init();
}
painter_->sizeChanged(size_);
}
}
EventHandler* GLCanvas::getEventHandler() const {
return eventHandler_;
}
......
......@@ -132,18 +132,10 @@ public:
/// Set the painter the Canvas will use to draw it's content
/// @param p the Painter
/// @initPainter wheather to initialize the painter, @see GLCanvas::initPainter()
void setPainter(Painter* p, bool initPainter = true);
void setPainter(Painter* p);
Painter* getPainter() const;
/// Calls init()- and sizeChanged()-method of the canvas' painter. These methods shall
/// initializes OpenGL context (and maybe some user dependant stuff of the painter) and
/// make the painter adapt to the current width and height of the canvas.
/// @see Painter::init()
/// @see Painter::sizeChanged()
void initPainter();
EventHandler* getEventHandler() const;
void setEventHandler(EventHandler* handler);
......
......@@ -73,7 +73,7 @@ public:
virtual void init() {};
/// Set the Canvas on which painter will draw
void setCanvas(GLCanvas* canvas);
virtual void setCanvas(GLCanvas* canvas);
/// Get the associated Canvas
GLCanvas* getCanvas() const;
......
......@@ -51,7 +51,8 @@ namespace cgt {
}
void QtThreadedCanvas::paintEvent(QPaintEvent* /* event */) {
painter_->repaint();
if (painter_ != nullptr)
painter_->repaint();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment