Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit e1d9072d authored by Hossain Mahmud's avatar Hossain Mahmud
Browse files

processor factory

Conflicts:
	application/gui/mainwindow.cpp
parent 591edec8
......@@ -49,7 +49,6 @@ namespace campvis {
_singleton = nullptr;
}
template<typename... Args>
std::vector<std::string> ProcessorFactory::getRegisteredProcessors() const {
tbb::spin_mutex::scoped_lock lock(_mutex);
......@@ -60,15 +59,14 @@ namespace campvis {
return toReturn;
}
template<typename... Args>
AbstractProcessor* ProcessorFactory::createProcessor(const std::string& id, Args... args) const {
AbstractProcessor* ProcessorFactory::createProcessor(const std::string& id, IVec2Property* viewPortSizeProp) const {
tbb::spin_mutex::scoped_lock lock(_mutex);
auto it = _processorMap.find(id);
if (it == _processorMap.end())
return nullptr;
else
return (it->second)._createFunction(args);
return (it->second)(viewPortSizeProp);
}
}
......@@ -37,36 +37,12 @@
#include <string>
#include <vector>
#include <functional>
#include "core/properties/numericproperty.h"
namespace campvis {
class AbstractProcessor;
class DataContainer;
//template<typename... Args>
class VArgs {
private:
public:
//std::string _processorName;
//Args*... type;
//void *func;
AbstractProcessor*(*_createFunction)(...);
template<typename... Args>
VArgs(std::function<AbstractProcessor*(Args...)> *_createFunction) {
//this->_processorName = _processorName;
this->_createFunction = _createFunction;
}
//template<typename... Args>
//VArgs(std::function < AbstractProcessor*(Args*...)> *create) {
// this->create = create;
//}
//template<typename... Args>
//std::function < AbstractProcessor*(Args*...)> *create;
//std::map< std::string, std::function < AbstractProcessor*(Args...)>> _processorMap;
};
/**
* Factory for creating processors by their name.
* Using some template-magic, ProcessorFactory is able to register processors during static
......@@ -85,11 +61,9 @@ namespace campvis {
static void deinit();
template<typename... Args>
std::vector<std::string> getRegisteredProcessors() const;
template<typename... Args>
AbstractProcessor* createProcessor(const std::string& id, Args... args) const;
AbstractProcessor* createProcessor(const std::string& id, IVec2Property* viewPortSizeProp) const;
/**
* Statically registers the processor of type T using \a callee as factory method.
......@@ -97,18 +71,33 @@ namespace campvis {
* \param callee Factory method to call to create an instance of type T
* \return The registration index.
*/
template<typename T, typename... Args>
size_t registerProcessor(AbstractProcessor*(callee)(Args...)) {
//template<typename T>
//size_t registerProcessor(std::function<AbstractProcessor*()> callee) {
// tbb::spin_mutex::scoped_lock lock(_mutex);
// auto it = _processorMap.lower_bound(T::getId());
// if (it == _processorMap.end() || it->first != T::getId()) {
// _processorMap.insert(it, std::make_pair(T::getId(), callee));
// }
// else {
// cgtAssert(false, "Registered two processors with the same ID.");
// }
// return _processorMap.size();
//}
template<typename T>
size_t registerProcessor(std::function<AbstractProcessor*(IVec2Property*)> callee) {
tbb::spin_mutex::scoped_lock lock(_mutex);
auto it = _processorMap.lower_bound(T::getId());
if (it == _processorMap.end() || it->first != T::getId()) {
_processorMap.insert(it, std::make_pair(T::getId(), VArgs(callee)));
_processorMap.insert(it, std::make_pair(T::getId(), callee));
}
else {
cgtAssert(false, "Registered two processors with the same ID.");
}
return _processorMap.size();
}
......@@ -116,7 +105,7 @@ namespace campvis {
mutable tbb::spin_mutex _mutex;
static tbb::atomic<ProcessorFactory*> _singleton; ///< the singleton object
std::map< std::string, VArgs> _processorMap;
std::map< std::string, std::function<AbstractProcessor*(IVec2Property*)>> _processorMap;
};
......@@ -124,7 +113,7 @@ namespace campvis {
// ================================================================================================
template<typename T, typename... Args>
template<typename T>
class ProcessorRegistrar {
public:
/**
......@@ -132,9 +121,13 @@ namespace campvis {
* \param args DataContainer for the created processor to work on.
* \return A newly created processor of type T. Caller has to take ownership of the pointer.
*/
static AbstractProcessor* create(Args... args) {
size_t argc = sizeof...(args);
//return new T(args);
//static AbstractProcessor* create() {
// return new T();
//}
static AbstractProcessor* create(IVec2Property* viewPortSizeProp) {
return new T(viewPortSizeProp);
}
private:
......@@ -142,8 +135,8 @@ namespace campvis {
static const size_t _factoryId;
};
template<typename T, typename... Args>
const size_t ProcessorRegistrar<T, Args...>::_factoryId = ProcessorFactory::getRef().registerProcessor<T, Args...>(&ProcessorRegistrar<T, Args...>::create);
template<typename T>
const size_t ProcessorRegistrar<T>::_factoryId = ProcessorFactory::getRef().registerProcessor<T>(&ProcessorRegistrar<T>::create);
}
......
......@@ -75,6 +75,8 @@ namespace campvis {
cgtAssert(_sliceRenderer != nullptr, "Slice Rendering Processor must not be 0.");
p_largeView.selectByOption(VOLUME);
VolumeRenderer* test = dynamic_cast<VolumeRenderer*> (ProcessorFactory::getRef().createProcessor("VolumeRenderer", viewportSizeProp));
addProperty(p_inputVolume, INVALID_PROPERTIES | CAMERA_INVALID);
addProperty(p_outputImage);
......
......@@ -38,6 +38,7 @@
#include "modules/modulesapi.h"
#include "modules/vis/processors/volumerenderer.h"
#include "modules/vis/processors/sliceextractor.h"
#include "../../processorfactory.h"
namespace cgt {
class Shader;
......@@ -77,8 +78,12 @@ namespace campvis {
/// \see AbstractProcessor::deinit
virtual void deinit();
/**
* To be used in ProcessorFactory static methods
*/
static const std::string getId() { return "VolumeExplorer"; };
/// \see AbstractProcessor::getName()
virtual const std::string getName() const { return "VolumeExplorer"; };
virtual const std::string getName() const { return getId(); };
/// \see AbstractProcessor::getDescription()
virtual const std::string getDescription() const { return "Combines a volume raycaster and 3 slice views for explorative volume visualization."; };
/// \see AbstractProcessor::getAuthor()
......@@ -178,6 +183,8 @@ namespace campvis {
static const std::string loggerCat_;
};
// Instantiate template to register the pipelines.
template class ProcessorRegistrar<VolumeExplorer>;
}
#endif // VOLUMEEXPLORER_H__
......@@ -33,6 +33,7 @@
#include "modules/vis/processors/eepgenerator.h"
#include "modules/vis/processors/proxygeometrygenerator.h"
#include "modules/vis/processors/simpleraycaster.h"
#include "../../processorfactory.h"
namespace cgt {
class Shader;
......@@ -70,9 +71,13 @@ namespace campvis {
/// \see AbstractProcessor::deinit
virtual void deinit();
/**
* To be used in ProcessorFactory static methods
*/
static const std::string getId() { return "VolumeRenderer"; };
/// \see AbstractProcessor::getName()
virtual const std::string getName() const { return "VolumeRenderer"; };
virtual const std::string getName() const { return getId(); };
/// \see AbstractProcessor::getDescription()
virtual const std::string getDescription() const { return "Combines proxy geometry generator, entry/exit point generator and raycasting into one easy-to-use volume renderer."; };
/// \see AbstractProcessor::getAuthor()
......@@ -125,6 +130,8 @@ namespace campvis {
static const std::string loggerCat_;
};
// Instantiate template to register the pipelines.
template class ProcessorRegistrar<VolumeRenderer>;
}
#endif // VOLUMERENDERER_H__
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