Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Philipp Bock
campvis-public
Commits
795b4856
Commit
795b4856
authored
Nov 18, 2013
by
Christian Schulte zu Berge
Browse files
Cleaned up CampcomMhdReceiver
parent
4c214bf8
Changes
3
Hide whitespace changes
Inline
Side-by-side
modules/campcom/campcom.cmake
View file @
795b4856
...
...
@@ -29,3 +29,4 @@ FILE(GLOB ThisModHeaders RELATIVE ${ModulesDir}
modules/campcom/processors/*.h
)
SET
(
ThisModDependencies vis
)
modules/campcom/processors/campcommhdreceiver.cpp
View file @
795b4856
...
...
@@ -77,10 +77,13 @@ namespace campvis {
void
CampcomMhdReceiver
::
process
(
DataContainer
&
data
)
{
validate
(
INVALID_RESULT
);
// Get the last received MHD file:
// Use atomic fetch and store because at the same time CAMPCom may receive another file!
campcom
::
MHDImageData
*
mid
=
_incomingMhd
.
fetch_and_store
(
0
);
if
(
mid
==
0
)
return
;
// Transform campcom::MHDImageData to campvis::ImageData
int
numChannels
=
1
;
size_t
dimensionality
=
mid
->
NDims
;
tgt
::
svec3
size
(
1
);
...
...
@@ -119,40 +122,49 @@ namespace campvis {
ImageRepresentationLocal
::
create
(
image
,
wtp
);
image
->
setMappingInformation
(
ImageMappingInformation
(
size
,
imageOffset
+
p_imageOffset
.
getValue
(),
voxelSize
*
p_voxelSize
.
getValue
()));
data
.
addData
(
p_targetImageID
.
getValue
(),
image
);
validate
(
INVALID_RESULT
);
}
void
CampcomMhdReceiver
::
onBtnConnectClicked
()
{
// CAMPComClient does not support dis-/reconnect. So we have to delete it and recreate it.
if
(
_ccclient
)
{
_ccclient
->
disconnect
();
delete
_ccclient
;
_ccclient
=
0
;
}
// create CAMPComClient and subscribe.
_ccclient
=
new
campcom
::
CAMPComClient
(
"Campvis"
,
campcom
::
Device_TestDevice
,
p_address
.
getValue
());
_ccclient
->
connect
();
if
(
_ccclient
->
isConnected
())
{
campcom
::
DataCallback
dc
;
dc
=
boost
::
bind
(
&
CampcomMhdReceiver
::
ccReceiveImage
,
this
,
_1
);
campcom
::
SuccessCallback
sc
=
std
::
bind1st
(
std
::
mem_fun
(
&
CampcomMhdReceiver
::
ccSuccessCalback
),
this
);
// use ugly boost magic to connect to member function (unfortunately CAMPCom only supports free functions...)
campcom
::
DataCallback
dc
=
boost
::
bind
(
&
CampcomMhdReceiver
::
ccReceiveImage
,
this
,
_1
);
campcom
::
SuccessCallback
sc
=
std
::
bind1st
(
std
::
mem_fun
(
&
CampcomMhdReceiver
::
ccSuccessCal
l
back
),
this
);
_ccclient
->
subscribe
(
campcom
::
Type_Image
,
dc
,
sc
);
}
else
{
LWARNING
(
"Could not connect to CAMPCom server."
);
//
delete _ccclient;
delete
_ccclient
;
_ccclient
=
0
;
}
}
void
CampcomMhdReceiver
::
ccReceiveImage
(
std
::
vector
<
campcom
::
Byte
>&
msg
)
{
// Deserialize payload
campcom
::
MHDImageData
return_payload
;
campcom
::
Header
header
;
campcom
::
TypeHandler
<
campcom
::
MHDImageData
>::
deserializePayload
(
&
msg
[
0
],
msg
.
size
(),
return_payload
);
if
(
campcom
::
MHDImageData
::
isValid
(
return_payload
))
{
LINFO
(
"New valid MHDImageData received! Pushing it to the DataContainer..."
);
// putting the image into the DataContainer has to be done asynchroneously, because we
// don't know the DataContainer here... :/
// So copy the image one more time, but it into _incomingMhd and invalidate the processor.
// Use atomic fetch and store because at the same time we may convert the last received image!
campcom
::
MHDImageData
*
copy
=
new
campcom
::
MHDImageData
(
return_payload
);
// delete old image not yet converted (if present)
campcom
::
MHDImageData
*
toDelete
=
_incomingMhd
.
fetch_and_store
(
copy
);
delete
toDelete
;
...
...
@@ -164,7 +176,7 @@ namespace campvis {
}
void
CampcomMhdReceiver
::
ccSuccessCalback
(
bool
b
)
{
void
CampcomMhdReceiver
::
ccSuccessCal
l
back
(
bool
b
)
{
LINFO
(
"CAMPCom subscribe callback: "
<<
b
);
}
...
...
modules/campcom/processors/campcommhdreceiver.h
View file @
795b4856
...
...
@@ -45,9 +45,8 @@
namespace
campvis
{
/**
* Reads a MHD image file into the pipeline.
*
* \note Full format specification at http://www.itk.org/Wiki/MetaIO/Documentation
* Experimental demo implementation how to receive MHD files via CAMPCom, convert it to
* CAMPVis ImageData and store it into the DataContainer.
*/
class
CampcomMhdReceiver
:
public
AbstractProcessor
{
public:
...
...
@@ -67,19 +66,20 @@ namespace campvis {
virtual
void
deinit
();
/**
* Reads the MHD file into an ImageRepresentationDisk representation
* \param data DataContainer to work on
* Transforms the last received MHD image (found in _incomingMhd) into CAMPVis ImageData
* and stores it in \a data.
* \param data DataContainer to work on
*/
virtual
void
process
(
DataContainer
&
data
);
/// \see AbstractProcessor::getName()
virtual
const
std
::
string
getName
()
const
{
return
"CampcomMhdReceiver"
;
};
/// \see AbstractProcessor::getDescription()
virtual
const
std
::
string
getDescription
()
const
{
return
"
Reads an MHD image into the pipeline
."
;
};
virtual
const
std
::
string
getDescription
()
const
{
return
"
Experimental demo implementation how to receive MHD files via CAMPCom
."
;
};
/// \see AbstractProcessor::getAuthor()
virtual
const
std
::
string
getAuthor
()
const
{
return
"Christian Schulte zu Berge <christian.szb@in.tum.de>"
;
};
/// \see AbstractProcessor::getProcessorState()
virtual
const
ProcessorState
getProcessorState
()
const
{
return
AbstractProcessor
::
TESTING
;
};
virtual
ProcessorState
getProcessorState
()
const
{
return
AbstractProcessor
::
EXPERIMENTAL
;
};
StringProperty
p_address
;
///< URL for file to read
ButtonProperty
p_connect
;
///<
...
...
@@ -89,15 +89,23 @@ namespace campvis {
Vec3Property
p_voxelSize
;
///< Voxel Size in mm
protected:
/// Callback slot for connect button
void
onBtnConnectClicked
();
/**
* Callback for CAMPCom when receiving an image.
* \param msg Received CAMPCom message
*/
void
ccReceiveImage
(
std
::
vector
<
campcom
::
Byte
>&
msg
);
void
ccSuccessCalback
(
bool
b
);
/**
* Callback for CAMPCom when connection/subscribtion was successful.
* \param b Flag whether subscription was successful.
*/
void
ccSuccessCallback
(
bool
b
);
campcom
::
CAMPComClient
*
_ccclient
;
tbb
::
atomic
<
campcom
::
MHDImageData
*>
_incomingMhd
;
campcom
::
CAMPComClient
*
_ccclient
;
///< Pointer to CAMPComClient (!=0 when connected)
tbb
::
atomic
<
campcom
::
MHDImageData
*>
_incomingMhd
;
///< Pointer to last received MHD file
static
const
std
::
string
loggerCat_
;
};
...
...
Write
Preview
Supports
Markdown
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