Added a field _pipelineName to AutoEvaluationPipeline. This allows to...

Added a field _pipelineName to AutoEvaluationPipeline. This allows to implement AutoEvaluationPipeline::getName() so that AutoEvaluationPipeline is no longer abstract. Consequently, the LuaPipeline is no longer needed.

This change was also used to change the AbstractPipeline constructor signature to pass-by-reference instead of pass-by-pointer for the pipeline's DataContainer. This presents the semantics more clearly since the DataContainer must not be 0.
parent 50c0b05d
......@@ -159,7 +159,7 @@ namespace campvis {
}
else {
DataContainer* dc = createAndAddDataContainer("DataContainer #" + StringUtils::toString(_dataContainers.size() + 1));
AbstractPipeline* p = PipelineFactory::getRef().createPipeline(pipelinesToAdd[i].toStdString(), dc);
AbstractPipeline* p = PipelineFactory::getRef().createPipeline(pipelinesToAdd[i].toStdString(), *dc);
if (p != nullptr)
addPipeline(pipelinesToAdd[i].toStdString(), p);
}
......
......@@ -425,7 +425,7 @@ namespace campvis {
if (dc == 0) {
dc = _application->createAndAddDataContainer("DataContainer #" + StringUtils::toString(_application->_dataContainers.size() + 1));
}
AbstractPipeline* p = PipelineFactory::getRef().createPipeline(name, dc);
AbstractPipeline* p = PipelineFactory::getRef().createPipeline(name, *dc);
_application->addPipeline(name, p);
}
......
......@@ -13,7 +13,7 @@ LuaDemo = {}
-- create DataContainer and Pipeline
LuaDemo.dc = application:createAndAddDataContainer("This DataContainer was created by Lua.")
LuaDemo.pipeline = campvis.LuaPipeline("A pipeline created by Lua", LuaDemo.dc)
LuaDemo.pipeline = campvis.AutoEvaluationPipeline(LuaDemo.dc, "A pipeline created by Lua")
local pipeline = LuaDemo.pipeline;
-- create the processors we need
......@@ -51,7 +51,7 @@ local initCallback = function()
-- alternative 2 to automatically adjust the camera to the data
local callback = function(arg)
local data_container = LuaDemo.getDataContainer(instance)
local data_container = pipeline:getDataContainer()
local img_data = data_container:getData(LuaDemo.image_reader.p_targetImageID:getValue()):getData()
LuaDemo.tcp:reinitializeCamera(img_data:getWorldBounds())
end
......
......@@ -210,14 +210,6 @@ namespace campvis {
void selectById(const std::string& id);
};
/* Downcast the return value of selectById to appropriate subclass */
%factory(void campvis::AbstractOptionProperty::selectById,
campvis::GenericOptionProperty);
/* Downcast the return value of getOptionId to appropriate subclass */
%factory(void campvis::AbstractOptionProperty::getOptionId,
campvis::GenericOptionProperty);
/* TFGeometry1D */
%nodefaultctor TFGeometry1D;
......@@ -332,6 +324,9 @@ namespace campvis {
/* DataHandle */
/* Downcast the return value of DataHandle::getData to appropriate subclass */
%factory(const AbstractData* campvis::DataHandle::getData, const campvis::ImageData);
class DataHandle {
public:
explicit DataHandle(AbstractData* data = 0);
......@@ -371,9 +366,6 @@ namespace campvis {
virtual cgt::Bounds getWorldBounds() const;
};
/* Downcast the return value of DataHandle::getData to appropriate subclass */
%factory(AbstractData* campvis::DataHandle::getData, campvis::ImageData);
/* DataContainer */
class DataContainer {
......@@ -454,10 +446,10 @@ namespace campvis {
class AbstractPipeline : public HasPropertyCollection {
public:
AbstractPipeline(DataContainer* dc);
AbstractPipeline(DataContainer& dc);
virtual ~AbstractPipeline();
virtual const std::string getName() const = 0;
virtual std::string getName() const = 0;
const DataContainer& getDataContainer() const;
DataContainer& getDataContainer();
......@@ -475,6 +467,10 @@ namespace campvis {
class AutoEvaluationPipeline : public AbstractPipeline {
public:
AutoEvaluationPipeline(DataContainer& dataContainer, const std::string& pipelineName);
virtual ~AutoEvaluationPipeline();
std::string getName() const;
virtual void addProcessor(AbstractProcessor* processor);
void addEventListenerToBack(cgt::EventListener* e);
......@@ -512,23 +508,6 @@ namespace campvis {
};
}
%inline{
namespace campvis {
class LuaPipeline : public campvis::AutoEvaluationPipeline {
public:
const std::string _name;
LuaPipeline(const std::string& name, campvis::DataContainer* dc)
: campvis::AutoEvaluationPipeline(dc)
, _name(name)
{
};
virtual const std::string getName() const { return _name; };
};
}
}
%luacode {
function campvis.newPipeline (name, o)
if not name then
......@@ -542,3 +521,4 @@ namespace campvis {
print("Module campvis-core loaded")
}
......@@ -40,17 +40,17 @@
namespace campvis {
const std::string AbstractPipeline::loggerCat_ = "CAMPVis.core.datastructures.AbstractPipeline";
AbstractPipeline::AbstractPipeline(DataContainer* dc)
AbstractPipeline::AbstractPipeline(DataContainer& dc)
: HasPropertyCollection()
, cgt::EventHandler()
, cgt::EventListener()
, _data(dc)
, _dataContainer(&dc)
, _canvas(0)
, _canvasSize("CanvasSize", "Canvas Size", cgt::ivec2(128, 128), cgt::ivec2(1, 1), cgt::ivec2(4096, 4096))
, _ignoreCanvasSizeUpdate(false)
, _renderTargetID("renderTargetID", "Render Target ID", "AbstractPipeline.renderTarget", DataNameProperty::READ)
{
cgtAssert(_data != 0, "Pointer to the DataContainer for this pipeline must not be 0!");
cgtAssert(_dataContainer != nullptr, "Pointer to the DataContainer for this pipeline must not be 0!");
_painter.reset(new PipelinePainter(nullptr, this));
......@@ -65,7 +65,7 @@ namespace campvis {
}
void AbstractPipeline::init() {
_data->s_dataAdded.connect(this, &AbstractPipeline::onDataContainerDataAdded);
_dataContainer->s_dataAdded.connect(this, &AbstractPipeline::onDataContainerDataAdded);
_painter->init();
initAllProperties();
......@@ -85,7 +85,7 @@ namespace campvis {
}
void AbstractPipeline::deinit() {
_data->s_dataAdded.disconnect(this);
_dataContainer->s_dataAdded.disconnect(this);
// use trigger signal to enforce blocking call
s_deinit.triggerSignal();
......@@ -106,7 +106,7 @@ namespace campvis {
// clear DataContainer
_data->clear();
_dataContainer->clear();
}
void AbstractPipeline::run() {
......@@ -153,11 +153,11 @@ namespace campvis {
}
const DataContainer& AbstractPipeline::getDataContainer() const {
return *_data;
return *_dataContainer;
}
DataContainer& AbstractPipeline::getDataContainer() {
return *_data;
return *_dataContainer;
}
void AbstractPipeline::executeProcessor(AbstractProcessor* processor) {
......@@ -171,7 +171,7 @@ namespace campvis {
startTime = tbb::tick_count::now();
try {
processor->process(*_data);
processor->process(*_dataContainer);
}
catch (std::exception& e) {
LERROR("Caught unhandled exception while executing processor " << processor->getName() << ": " << e.what());
......
......@@ -64,10 +64,10 @@ namespace campvis {
* If you derive from AbstractPipeline, you will have to implement the pipeline evaluation
* logic yourself. You might want to have a look at AutoEvaluationPipeline.
*
* \param dc Pointer to the DataContainer containing local working set of data for this
* pipeline, must not be 0, must be valid the whole lifetime of this pipeline.
* \param dataContainer Reference to the DataContainer containing local working set of data
* for this pipeline, must be valid the whole lifetime of this pipeline.
*/
explicit AbstractPipeline(DataContainer* dc);
explicit AbstractPipeline(DataContainer& dataContainer);
/**
* Virtual Destructor
......@@ -78,7 +78,7 @@ namespace campvis {
* Gets the name of this very pipeline. To be defined by every subclass.
* \return The name of this pipeline.
*/
virtual const std::string getName() const = 0;
virtual std::string getName() const = 0;
/**
......@@ -143,13 +143,13 @@ namespace campvis {
/**
* Returns the DataContainer of this pipeline, const version.
* \return _data
* \return _dataContainer
*/
const DataContainer& getDataContainer() const;
/**
* Returns the DataContainer of this pipeline, non-const version.
* \return _data
* \return _dataContainer
*/
DataContainer& getDataContainer();
......@@ -213,7 +213,7 @@ namespace campvis {
* Returns the canvas size
* \return The IVec2Property with current canvas size on it
*/
IVec2Property& getCanvasSize() {return _canvasSize;}
IVec2Property& getCanvasSize() { return _canvasSize; }
/**
* Returns this pipelines PipelinePainter.
......@@ -263,7 +263,7 @@ namespace campvis {
/// Pointer to the DataContainer containing local working set of data for this Pipeline, must not be 0.
DataContainer* _data;
DataContainer* _dataContainer;
std::vector<AbstractProcessor*> _processors; ///< List of all processors of this pipeline
......
......@@ -34,14 +34,19 @@
namespace campvis {
const std::string AutoEvaluationPipeline::loggerCat_ = "CAMPVis.core.datastructures.AutoEvaluationPipeline";
AutoEvaluationPipeline::AutoEvaluationPipeline(DataContainer* dc)
: AbstractPipeline(dc)
AutoEvaluationPipeline::AutoEvaluationPipeline(DataContainer& dataContainer, const std::string& pipelineName)
: AbstractPipeline(dataContainer)
, _pipelineName(pipelineName)
{
}
AutoEvaluationPipeline::~AutoEvaluationPipeline() {
}
std::string AutoEvaluationPipeline::getName() const {
return _pipelineName;
}
void AutoEvaluationPipeline::init() {
AbstractPipeline::init();
}
......
......@@ -38,16 +38,17 @@ namespace campvis {
* Specializtaion of AbstractPipeline performing automatic execution of invalidated processors.
* AutoEvaluationPipeline connects to the s_(in)validated signals of all of its processors and
* executes processors with invalid results using the correct threads.
*
* \param dc Pointer to the DataContainer containing local working set of data for this
* pipeline, must not be 0, must be valid the whole lifetime of this pipeline.
*/
class CAMPVIS_CORE_API AutoEvaluationPipeline : public AbstractPipeline {
public:
/**
* Creates a AutoEvaluationPipeline.
*
* \param dataContainer Reference to the DataContainer containing local working set of data
* for this pipeline, must be valid the whole lifetime of this pipeline.
* \param pipelineName Name of this pipeline.
*/
explicit AutoEvaluationPipeline(DataContainer* dc);
AutoEvaluationPipeline(DataContainer& dataContainer, const std::string& pipelineName);
/**
* Virtual Destructor
......@@ -55,16 +56,18 @@ namespace campvis {
virtual ~AutoEvaluationPipeline();
/// \see AbstractPipeline::getName()
virtual std::string getName() const override;
/// \see AbstractPipeline::init()
virtual void init();
virtual void init() override;
/// \see AbstractPipeline::deinit()
virtual void deinit();
virtual void deinit() override;
/// \see AbstractPipeline::addProcessor()
virtual void addProcessor(AbstractProcessor* processor);
virtual void addProcessor(AbstractProcessor* processor) override;
/// \see AbstractPipeline::executePipeline()
virtual void executePipeline();
virtual void executePipeline() override;
protected:
......@@ -75,6 +78,8 @@ namespace campvis {
*/
virtual void onProcessorInvalidated(AbstractProcessor* processor);
std::string _pipelineName; ///< Name of this pipeline
static const std::string loggerCat_;
private:
......
......@@ -60,7 +60,7 @@ namespace campvis {
return toReturn;
}
AbstractPipeline* PipelineFactory::createPipeline(const std::string& id, DataContainer* dc) const {
AbstractPipeline* PipelineFactory::createPipeline(const std::string& id, DataContainer& dc) const {
tbb::spin_mutex::scoped_lock lock(_mutex);
auto it = _pipelineMap.find(id);
......
......@@ -62,7 +62,7 @@ namespace campvis {
std::vector<std::string> getRegisteredPipelines() const;
AbstractPipeline* createPipeline(const std::string& id, DataContainer* dc) const;
AbstractPipeline* createPipeline(const std::string& id, DataContainer& dc) const;
AbstractWorkflow* createWorkflow(const std::string& id) const;
......@@ -73,7 +73,7 @@ namespace campvis {
* \return The registration index.
*/
template<typename T>
size_t registerPipeline(std::function<AbstractPipeline*(DataContainer*)> callee) {
size_t registerPipeline(std::function<AbstractPipeline*(DataContainer&)> callee) {
tbb::spin_mutex::scoped_lock lock(_mutex);
auto it = _pipelineMap.lower_bound(T::getId());
......@@ -112,7 +112,7 @@ namespace campvis {
mutable tbb::spin_mutex _mutex;
static tbb::atomic<PipelineFactory*> _singleton; ///< the singleton object
std::map< std::string, std::function<AbstractPipeline*(DataContainer*)> > _pipelineMap;
std::map< std::string, std::function<AbstractPipeline*(DataContainer&)> > _pipelineMap;
std::map< std::string, std::function<AbstractWorkflow*()> > _workflowMap;
};
......@@ -128,7 +128,7 @@ namespace campvis {
* \param dc DataContainer for the created pipeline to work on.
* \return A newly created pipeline of type T. Caller has to take ownership of the pointer.
*/
static AbstractPipeline* create(DataContainer* dc) {
static AbstractPipeline* create(DataContainer& dc) {
return new T(dc);
}
......
......@@ -13,6 +13,7 @@
#include <cstdio>
#include <iostream>
#include "tbb/recursive_mutex.h"
#include "ext/cgt/logmanager.h"
#include "ext/sigslot/sigslot.h"
%}
......@@ -52,7 +53,7 @@ namespace sigslot {
swig_type_info* typeInfo = SWIG_TypeQuery(typeName);
if (typeInfo == nullptr) {
std::cerr << "SWIG wrapper for " << typeName << " not found" << std::endl;
LogMgr.log("Lua", cgt::LuaError, "SWIG wrapper for " + std::string(typeName) + " not found");
}
return std::make_pair(arg, typeInfo);
......@@ -232,9 +233,9 @@ namespace sigslot {
const char* errorMsg = lua_tostring(_slot_fn.L, -1);
if (errorMsg == nullptr)
std::cerr << "(error object is not a string)" << std::endl;
LogMgr.log("Lua", cgt::LuaError, "(error object is not a string)");
else
std::cerr << "An error occured while calling a Lua slot function: " << errorMsg << std::endl;
LogMgr.log("Lua", cgt::LuaError, "An error occured while calling a Lua slot function: " + std::string(errorMsg));
lua_pop(_slot_fn.L, 1);
}
......
......@@ -32,8 +32,8 @@
namespace campvis {
AdvancedUsVis::AdvancedUsVis(DataContainer* dc)
: AutoEvaluationPipeline(dc)
AdvancedUsVis::AdvancedUsVis(DataContainer& dc)
: AutoEvaluationPipeline(dc, getId())
, _usReader()
, _confidenceReader()
, _usFusion1(&_canvasSize)
......
......@@ -38,9 +38,11 @@ namespace campvis {
class CAMPVIS_MODULES_API AdvancedUsVis : public AutoEvaluationPipeline {
public:
/**
* Creates a VisualizationPipeline.
* Creates a AdvancedUsVis pipeline.
* \param dataContainer Reference to the DataContainer containing local working set of data
* for this pipeline, must be valid the whole lifetime of this pipeline.
*/
explicit AdvancedUsVis(DataContainer* dc);
explicit AdvancedUsVis(DataContainer& dataContainer);
/**
* Virtual Destructor
......@@ -49,13 +51,9 @@ namespace campvis {
/// \see VisualizationPipeline::init()
virtual void init();
/// \see VisualizationPipeline::deinit()
virtual void deinit();
/// \see AbstractPipeline::getName()
virtual const std::string getName() const { return getId(); };
/// \see AbstractPipeline::getId()
static const std::string getId() { return "AdvancedUsVis"; };
virtual void keyEvent(cgt::KeyEvent* e);
......
......@@ -43,8 +43,8 @@
namespace campvis {
CmBatchGeneration::CmBatchGeneration(DataContainer* dc)
: AutoEvaluationPipeline(dc)
CmBatchGeneration::CmBatchGeneration(DataContainer& dc)
: AutoEvaluationPipeline(dc, getId())
, _usReader()
, _confidenceGenerator()
, _usBlurFilter(&_canvasSize)
......@@ -160,7 +160,7 @@ namespace campvis {
forceExecuteProcessor(&_usReader);
DataHandle dh = _data->getData(_usReader.p_targetImageID.getValue());
DataHandle dh = _dataContainer->getData(_usReader.p_targetImageID.getValue());
if (dh.getData() != 0) {
if (const ImageData* tester = dynamic_cast<const ImageData*>(dh.getData())) {
_canvasSize.setValue(tester->getSize().xy());
......@@ -218,7 +218,7 @@ namespace campvis {
void CmBatchGeneration::save(int path, const std::string& basePath) {
// get result
ScopedTypedData<RenderData> rd(*_data, _usFusion.p_targetImageID.getValue());
ScopedTypedData<RenderData> rd(*_dataContainer, _usFusion.p_targetImageID.getValue());
const ImageRepresentationGL* rep = rd->getColorTexture()->getRepresentation<ImageRepresentationGL>(false);
if (rep != 0) {
#ifdef CAMPVIS_HAS_MODULE_DEVIL
......
......@@ -39,9 +39,11 @@ namespace campvis {
class CAMPVIS_MODULES_API CmBatchGeneration : public AutoEvaluationPipeline {
public:
/**
* Creates a AutoEvaluationPipeline.
* Creates a CmBatchGeneration pipeline.
* \param dataContainer Reference to the DataContainer containing local working set of data
* for this pipeline, must be valid the whole lifetime of this pipeline.
*/
explicit CmBatchGeneration(DataContainer* dc);
explicit CmBatchGeneration(DataContainer& dataContainer);
/**
* Virtual Destructor
......@@ -50,12 +52,9 @@ namespace campvis {
/// \see AutoEvaluationPipeline::init()
virtual void init();
/// \see AutoEvaluationPipeline::deinit()
virtual void deinit();
/// \see AbstractPipeline::getName()
virtual const std::string getName() const { return getId(); };
static const std::string getId() { return "CmBatchGeneration"; };
/**
......
......@@ -35,8 +35,8 @@
namespace campvis {
PredicateDemoAchilles::PredicateDemoAchilles(DataContainer* dc)
: AutoEvaluationPipeline(dc)
PredicateDemoAchilles::PredicateDemoAchilles(DataContainer& dc)
: AutoEvaluationPipeline(dc, getId())
, _lsp()
, _imageReader()
, _labelReader()
......
......@@ -48,9 +48,11 @@ namespace campvis {
class CAMPVIS_MODULES_API PredicateDemoAchilles : public AutoEvaluationPipeline {
public:
/**
* Creates a AutoEvaluationPipeline.
* Creates a PredicateDemoAchilles pipeline.
* \param dataContainer Reference to the DataContainer containing local working set of data
* for this pipeline, must be valid the whole lifetime of this pipeline.
*/
explicit PredicateDemoAchilles(DataContainer* dc);
explicit PredicateDemoAchilles(DataContainer& dataContainer);
/**
* Virtual Destructor
......@@ -59,12 +61,9 @@ namespace campvis {
/// \see AutoEvaluationPipeline::init()
virtual void init();
/// \see AutoEvaluationPipeline::deinit()
virtual void deinit();
/// \see AbstractPipeline::getName()
virtual const std::string getName() const { return getId(); };
static const std::string getId() { return "PredicateDemoAchilles"; };
void onRenderTargetSizeChanged(const AbstractProperty* prop);
......
......@@ -35,8 +35,8 @@
namespace campvis {
PredicateDemoCarotid::PredicateDemoCarotid(DataContainer* dc)
: AutoEvaluationPipeline(dc)
PredicateDemoCarotid::PredicateDemoCarotid(DataContainer& dc)
: AutoEvaluationPipeline(dc, getId())
, _lsp()
, _imageReader()
, _labelReader()
......
......@@ -49,9 +49,11 @@ namespace campvis {
class CAMPVIS_MODULES_API PredicateDemoCarotid : public AutoEvaluationPipeline {
public:
/**
* Creates a AutoEvaluationPipeline.
* Creates a PredicateDemoCarotid pipeline.
* \param dataContainer Reference to the DataContainer containing local working set of data
* for this pipeline, must be valid the whole lifetime of this pipeline.
*/
explicit PredicateDemoCarotid(DataContainer* dc);
explicit PredicateDemoCarotid(DataContainer& dataContainer);
/**
* Virtual Destructor
......@@ -60,12 +62,9 @@ namespace campvis {
/// \see AutoEvaluationPipeline::init()
virtual void init();
/// \see AutoEvaluationPipeline::deinit()
virtual void deinit();
/// \see AbstractPipeline::getName()
virtual const std::string getName() const { return getId(); };
static const std::string getId() { return "PredicateDemoCarotid"; };
void onRenderTargetSizeChanged(const AbstractProperty* prop);
......
......@@ -35,8 +35,8 @@
namespace campvis {
PredicateDemoCarotid2::PredicateDemoCarotid2(DataContainer* dc)
: AutoEvaluationPipeline(dc)
PredicateDemoCarotid2::PredicateDemoCarotid2(DataContainer& dc)
: AutoEvaluationPipeline(dc, getId())
, _lsp()
, _imageReader()
, _labelReader()
......
<
......@@ -49,9 +49,11 @@ namespace campvis {
class CAMPVIS_MODULES_API PredicateDemoCarotid2 : public AutoEvaluationPipeline {
public:
/**
* Creates a AutoEvaluationPipeline.
* Creates a PredicateDemoCarotid2 pipeline.
* \param dataContainer Reference to the DataContainer containing local working set of data
* for this pipeline, must be valid the whole lifetime of this pipeline.
*/
explicit PredicateDemoCarotid2(DataContainer* dc);
explicit PredicateDemoCarotid2(DataContainer& dataContainer);
/**
* Virtual Destructor
......@@ -60,12 +62,9 @@ namespace campvis {
/// \see AutoEvaluationPipeline::init()
virtual void init();
/// \see AutoEvaluationPipeline::deinit()
virtual void deinit();
/// \see AbstractPipeline::getName()
virtual const std::string getName() const { return getId(); };