Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CAMP
campvis-public
Commits
66c8e970
Commit
66c8e970
authored
Feb 13, 2015
by
Hossain Mahmud
Browse files
manual process to handle processorfactory with two distinct ProcessorRegistrar
parent
497a9126
Changes
5
Hide whitespace changes
Inline
Side-by-side
modules/base/processors/lightsourceprovider.h
View file @
66c8e970
...
...
@@ -32,6 +32,7 @@
#include "core/properties/floatingpointproperty.h"
#include "modules/modulesapi.h"
#include "modules/processorfactory.h"
namespace
campvis
{
/**
...
...
@@ -49,9 +50,13 @@ namespace campvis {
* Destructor
**/
virtual
~
LightSourceProvider
();
/**
* To be used in ProcessorFactory static methods
*/
static
const
std
::
string
getId
()
{
return
"LightSourceProvider"
;
};
/// \see AbstractProcessor::getName()
virtual
const
std
::
string
getName
()
const
{
return
"LightSourceProvider"
;
};
virtual
const
std
::
string
getName
()
const
{
return
getId
()
;
};
/// \see AbstractProcessor::getDescription()
virtual
const
std
::
string
getDescription
()
const
{
return
"Creates LightSourceData and stores it in the DataContainer."
;
};
/// \see AbstractProcessor::getAuthor()
...
...
@@ -74,6 +79,8 @@ namespace campvis {
static
const
std
::
string
loggerCat_
;
};
// Instantiate template to register the pipelines.
template
class
ProcessorRegistrar
<
LightSourceProvider
>;
}
#endif // LIGHTSOURCEPROVIDER_H__
modules/processorfactory.cpp
View file @
66c8e970
...
...
@@ -53,7 +53,9 @@ namespace campvis {
tbb
::
spin_mutex
::
scoped_lock
lock
(
_mutex
);
std
::
vector
<
std
::
string
>
toReturn
;
toReturn
.
reserve
(
_processorMap
.
size
());
toReturn
.
reserve
(
_processorMap2
.
size
()
+
_processorMap
.
size
());
for
(
auto
it
=
_processorMap2
.
begin
();
it
!=
_processorMap2
.
end
();
++
it
)
toReturn
.
push_back
(
it
->
first
);
for
(
auto
it
=
_processorMap
.
begin
();
it
!=
_processorMap
.
end
();
++
it
)
toReturn
.
push_back
(
it
->
first
);
return
toReturn
;
...
...
@@ -61,12 +63,20 @@ namespace campvis {
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
)(
viewPortSizeProp
);
if
(
viewPortSizeProp
!=
nullptr
)
{
auto
it
=
_processorMap2
.
find
(
id
);
if
(
it
==
_processorMap2
.
end
())
return
nullptr
;
else
return
(
it
->
second
)(
viewPortSizeProp
);
}
else
{
auto
it
=
_processorMap
.
find
(
id
);
if
(
it
==
_processorMap
.
end
())
return
nullptr
;
else
return
(
it
->
second
)();
}
}
}
modules/processorfactory.h
View file @
66c8e970
...
...
@@ -63,7 +63,7 @@ namespace campvis {
std
::
vector
<
std
::
string
>
getRegisteredProcessors
()
const
;
AbstractProcessor
*
createProcessor
(
const
std
::
string
&
id
,
IVec2Property
*
viewPortSizeProp
)
const
;
AbstractProcessor
*
createProcessor
(
const
std
::
string
&
id
,
IVec2Property
*
viewPortSizeProp
=
0
)
const
;
/**
* Statically registers the processor of type T using \a callee as factory method.
...
...
@@ -72,7 +72,22 @@ namespace campvis {
* \return The registration index.
*/
template
<
typename
T
>
size_t
registerProcessor
(
std
::
function
<
AbstractProcessor
*
(
IVec2Property
*
)
>
callee
)
{
size_t
registerProcessor2
(
std
::
function
<
AbstractProcessor
*
(
IVec2Property
*
)
>
callee
)
{
tbb
::
spin_mutex
::
scoped_lock
lock
(
_mutex
);
auto
it
=
_processorMap2
.
lower_bound
(
T
::
getId
());
if
(
it
==
_processorMap2
.
end
()
||
it
->
first
!=
T
::
getId
())
{
_processorMap2
.
insert
(
it
,
std
::
make_pair
(
T
::
getId
(),
callee
));
}
else
{
cgtAssert
(
false
,
"Registered two processors with the same ID."
);
}
return
_processorMap2
.
size
();
}
template
<
typename
T
>
size_t
registerProcessor
(
std
::
function
<
AbstractProcessor
*
()
>
callee
)
{
tbb
::
spin_mutex
::
scoped_lock
lock
(
_mutex
);
auto
it
=
_processorMap
.
lower_bound
(
T
::
getId
());
...
...
@@ -85,14 +100,12 @@ namespace campvis {
return
_processorMap
.
size
();
}
private:
mutable
tbb
::
spin_mutex
_mutex
;
static
tbb
::
atomic
<
ProcessorFactory
*>
_singleton
;
///< the singleton object
std
::
map
<
std
::
string
,
std
::
function
<
AbstractProcessor
*
(
IVec2Property
*
)
>>
_processorMap
;
std
::
map
<
std
::
string
,
std
::
function
<
AbstractProcessor
*
()
>>
_processorMap
;
std
::
map
<
std
::
string
,
std
::
function
<
AbstractProcessor
*
(
IVec2Property
*
)
>>
_processorMap2
;
};
...
...
@@ -103,14 +116,25 @@ namespace campvis {
public:
/**
* Static factory method for creating the processor of type T.
* \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() {
// return new T();
//}
static
AbstractProcessor
*
create
()
{
return
new
T
();
}
private:
/// static helper field to ensure registration at static initialization time.
static
const
size_t
_factoryId
;
};
template
<
typename
T
>
class
ProcessorRegistrar2
{
public:
/**
* Static factory method for creating the processor of type T.
* \param viewPortSizeProp viewPortSizeProp 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
(
IVec2Property
*
viewPortSizeProp
)
{
return
new
T
(
viewPortSizeProp
);
}
...
...
@@ -122,6 +146,8 @@ namespace campvis {
template
<
typename
T
>
const
size_t
ProcessorRegistrar
<
T
>::
_factoryId
=
ProcessorFactory
::
getRef
().
registerProcessor
<
T
>
(
&
ProcessorRegistrar
<
T
>::
create
);
template
<
typename
T
>
const
size_t
ProcessorRegistrar2
<
T
>::
_factoryId
=
ProcessorFactory
::
getRef
().
registerProcessor2
<
T
>
(
&
ProcessorRegistrar2
<
T
>::
create
);
}
...
...
modules/vis/processors/volumeexplorer.h
View file @
66c8e970
...
...
@@ -184,7 +184,7 @@ namespace campvis {
};
// Instantiate template to register the pipelines.
template
class
ProcessorRegistrar
<
VolumeExplorer
>;
template
class
ProcessorRegistrar
2
<
VolumeExplorer
>;
}
#endif // VOLUMEEXPLORER_H__
modules/vis/processors/volumerenderer.h
View file @
66c8e970
...
...
@@ -131,7 +131,7 @@ namespace campvis {
};
// Instantiate template to register the pipelines.
template
class
ProcessorRegistrar
<
VolumeRenderer
>;
template
class
ProcessorRegistrar
2
<
VolumeRenderer
>;
}
#endif // VOLUMERENDERER_H__
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment