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