2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 4c214bf8 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

further work on CAMPCom module

parent 54537480
...@@ -66,7 +66,7 @@ namespace campvis { ...@@ -66,7 +66,7 @@ namespace campvis {
// test source image type via dynamic cast // test source image type via dynamic cast
if (const ImageRepresentationDisk* tester = dynamic_cast<const ImageRepresentationDisk*>(source)) { if (const ImageRepresentationDisk* tester = dynamic_cast<const ImageRepresentationDisk*>(source)) {
return convertToGenericLocal(tester, tester->getImageData()); return create(tester->getParent(), tester->getImageData());
} }
else if (const ImageRepresentationGL* tester = dynamic_cast<const ImageRepresentationGL*>(source)) { else if (const ImageRepresentationGL* tester = dynamic_cast<const ImageRepresentationGL*>(source)) {
// FIXME: this here deadlocks, if called from OpenGL context (GLJobProc)!!! // FIXME: this here deadlocks, if called from OpenGL context (GLJobProc)!!!
...@@ -76,7 +76,7 @@ namespace campvis { ...@@ -76,7 +76,7 @@ namespace campvis {
try { try {
tgt::GLContextScopedLock lock(context); tgt::GLContextScopedLock lock(context);
WeaklyTypedPointer wtp = tester->getWeaklyTypedPointer(); WeaklyTypedPointer wtp = tester->getWeaklyTypedPointer();
toReturn = convertToGenericLocal(source, wtp); toReturn = create(source->getParent(), wtp);
} }
catch (...) { catch (...) {
LERROR("An unknown error occured during conversion..."); LERROR("An unknown error occured during conversion...");
...@@ -186,14 +186,15 @@ namespace campvis { ...@@ -186,14 +186,15 @@ namespace campvis {
}); });
} }
ImageRepresentationLocal* ImageRepresentationLocal::convertToGenericLocal(const AbstractImageRepresentation* source, const WeaklyTypedPointer& wtp) {
ImageRepresentationLocal* ImageRepresentationLocal::create(const ImageData* parent, WeaklyTypedPointer wtp) {
#define CONVERT_DISK_TO_GENERIC_LOCAL(baseType,numChannels) \ #define CONVERT_DISK_TO_GENERIC_LOCAL(baseType,numChannels) \
return GenericImageRepresentationLocal<baseType, numChannels>::create( \ return GenericImageRepresentationLocal<baseType, numChannels>::create( \
const_cast<ImageData*>(source->getParent()), \ const_cast<ImageData*>(parent), \
reinterpret_cast< TypeTraits<baseType, numChannels>::ElementType*>(wtp._pointer)); reinterpret_cast< TypeTraits<baseType, numChannels>::ElementType*>(wtp._pointer));
#define DISPATCH_DISK_TO_GENERIC_LOCAL_CONVERSION(numChannels) \ #define DISPATCH_DISK_TO_GENERIC_LOCAL_CONVERSION(numChannels) \
if (source->getParent()->getNumChannels() == (numChannels)) { \ if (parent->getNumChannels() == (numChannels)) { \
switch (wtp._baseType) { \ switch (wtp._baseType) { \
case WeaklyTypedPointer::UINT8: \ case WeaklyTypedPointer::UINT8: \
CONVERT_DISK_TO_GENERIC_LOCAL(uint8_t, (numChannels)) \ CONVERT_DISK_TO_GENERIC_LOCAL(uint8_t, (numChannels)) \
...@@ -223,7 +224,7 @@ namespace campvis { ...@@ -223,7 +224,7 @@ namespace campvis {
tgtAssert(false, "Should not reach this - wrong number of channel!"); tgtAssert(false, "Should not reach this - wrong number of channel!");
return 0; return 0;
} }
} }
} }
\ No newline at end of file
...@@ -63,6 +63,8 @@ namespace campvis { ...@@ -63,6 +63,8 @@ namespace campvis {
*/ */
static ImageRepresentationLocal* tryConvertFrom(const AbstractImageRepresentation* source); static ImageRepresentationLocal* tryConvertFrom(const AbstractImageRepresentation* source);
static ImageRepresentationLocal* create(const ImageData* parent, WeaklyTypedPointer wtp);
/// \see AbstractData::clone() /// \see AbstractData::clone()
virtual ImageRepresentationLocal* clone(ImageData* newParent) const = 0; virtual ImageRepresentationLocal* clone(ImageData* newParent) const = 0;
...@@ -210,9 +212,6 @@ namespace campvis { ...@@ -210,9 +212,6 @@ namespace campvis {
private: private:
static ImageRepresentationLocal* convertToGenericLocal(const AbstractImageRepresentation* source, const WeaklyTypedPointer& wtp);
// We don't want this data to be copied - clone() must be enough // We don't want this data to be copied - clone() must be enough
// (read: We are too lazy to implement a correct copy constructor / assignment-operator) // (read: We are too lazy to implement a correct copy constructor / assignment-operator)
ImageRepresentationLocal(const ImageRepresentationLocal& rhs); ImageRepresentationLocal(const ImageRepresentationLocal& rhs);
......
...@@ -40,6 +40,13 @@ namespace campvis { ...@@ -40,6 +40,13 @@ namespace campvis {
tgtAssert(_numChannels > 0 && _numChannels <= 4, "Number of channels out of bounds!"); tgtAssert(_numChannels > 0 && _numChannels <= 4, "Number of channels out of bounds!");
}; };
WeaklyTypedPointer::WeaklyTypedPointer()
: _baseType(UINT8)
, _numChannels(0)
, _pointer(0)
{
}
WeaklyTypedPointer::~WeaklyTypedPointer() { WeaklyTypedPointer::~WeaklyTypedPointer() {
// We do _not_ own the pointer, so we don't need to delete it. // We do _not_ own the pointer, so we don't need to delete it.
} }
......
...@@ -105,6 +105,11 @@ namespace campvis { ...@@ -105,6 +105,11 @@ namespace campvis {
*/ */
WeaklyTypedPointer(BaseType pt, size_t numChannels, void* ptr); WeaklyTypedPointer(BaseType pt, size_t numChannels, void* ptr);
/**
* Empty default constructor, you have to initialize everything yourself.
*/
WeaklyTypedPointer();
/** /**
* Destructor, does _not_ delete the handled pointer! * Destructor, does _not_ delete the handled pointer!
*/ */
......
...@@ -80,10 +80,11 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(CAMPCOM REQUIRED_VARS CAMPCOM_LIBRARY CAMPCOM_ ...@@ -80,10 +80,11 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(CAMPCOM REQUIRED_VARS CAMPCOM_LIBRARY CAMPCOM_
if(CAMPCOM_FOUND) if(CAMPCOM_FOUND)
set(CAMPCOM_INCLUDE_DIRS ${CAMPCOM_INCLUDE_DIR}) set(CAMPCOM_INCLUDE_DIRS ${CAMPCOM_INCLUDE_DIR})
set(CAMPCOM_LIBRARIES ${CAMPCOM_LIBRARY}) GET_FILENAME_COMPONENT(CcLibPath ${CAMPCOM_LIBRARY} PATH)
GET_FILENAME_COMPONENT(LibExt ${CAMPCOM_LIBRARY} EXT)
set(CAMPCOM_LIBRARIES "${CcLibPath}/CCClientLib${LibExt}" "${CcLibPath}/CCCommonLib${LibExt}" "${CcLibPath}/CCServerLib${LibExt}")
endif() endif()
LIST(APPEND CAMPCOM_INCLUDE_DIRS LIST(APPEND CAMPCOM_INCLUDE_DIRS
${CAMPCOM_INCLUDE_DIR}/CommonLib/MathLib ${CAMPCOM_INCLUDE_DIR}/CommonLib/MathLib
${CAMPCOM_INCLUDE_DIR}/CommonLib/MathLib/GL ${CAMPCOM_INCLUDE_DIR}/CommonLib/MathLib/GL
......
...@@ -4,12 +4,19 @@ LIST(APPEND CMAKE_MODULE_PATH "${ModulesDir}/campcom") ...@@ -4,12 +4,19 @@ LIST(APPEND CMAKE_MODULE_PATH "${ModulesDir}/campcom")
FIND_PACKAGE(CAMPCom REQUIRED) FIND_PACKAGE(CAMPCom REQUIRED)
IF(CAMPCOM_FOUND) IF(CAMPCOM_FOUND)
LIST(APPEND ThisModIncludeDirs ${CAMPCOM_INCLUDE_DIRS}) #LIST(APPEND ThisModIncludeDirs ${CAMPCOM_INCLUDE_DIRS})
LIST(APPEND ThisModExternalLibs ${CAMPCOM_LIBRARIES}) LIST(APPEND ThisModExternalLibs ${CAMPCOM_LIBRARIES})
# dirty hack
INCLUDE("${CAMPCOM_INCLUDE_DIR}/cmake/campcom_use_file.cmake")
LIST(APPEND ThisModIncludeDirs ${CAMPCOM_INCLUDE_DIRS})
LIST(APPEND ThisModExternalLibs ${CAMPCOM_EXTERNAL_LIBS})
ELSE() ELSE()
MESSAGE(FATAL_ERROR "Could not find CAMPCom. Please specify CAMPCOM_ROOT.") MESSAGE(FATAL_ERROR "Could not find CAMPCom. Please specify CAMPCOM_ROOT.")
ENDIF() ENDIF()
# Source files: # Source files:
FILE(GLOB ThisModSources RELATIVE ${ModulesDir} FILE(GLOB ThisModSources RELATIVE ${ModulesDir}
modules/campcom/pipelines/*.cpp modules/campcom/pipelines/*.cpp
......
...@@ -27,10 +27,13 @@ ...@@ -27,10 +27,13 @@
// //
// ================================================================================================ // ================================================================================================
#define CAMPCOM_FAST_SERIALIZATION
#include "campcommhdreceiver.h" #include "campcommhdreceiver.h"
#include "core/datastructures/imagedata.h" #include "core/datastructures/imagedata.h"
#include "core/datastructures/genericimagerepresentationlocal.h" #include "core/datastructures/genericimagerepresentationlocal.h"
#include "core/tools/stringutils.h"
namespace campvis { namespace campvis {
const std::string CampcomMhdReceiver::loggerCat_ = "CAMPVis.modules.io.CampcomMhdReceiver"; const std::string CampcomMhdReceiver::loggerCat_ = "CAMPVis.modules.io.CampcomMhdReceiver";
...@@ -44,6 +47,8 @@ namespace campvis { ...@@ -44,6 +47,8 @@ namespace campvis {
, p_voxelSize("VoxelSize", "Voxel Size in mm", tgt::vec3(1.f), tgt::vec3(-100.f), tgt::vec3(100.f), tgt::vec3(0.1f)) , p_voxelSize("VoxelSize", "Voxel Size in mm", tgt::vec3(1.f), tgt::vec3(-100.f), tgt::vec3(100.f), tgt::vec3(0.1f))
, _ccclient(0) , _ccclient(0)
{ {
_incomingMhd = 0;
addProperty(&p_address); addProperty(&p_address);
addProperty(&p_targetImageID); addProperty(&p_targetImageID);
addProperty(&p_connect); addProperty(&p_connect);
...@@ -62,17 +67,58 @@ namespace campvis { ...@@ -62,17 +67,58 @@ namespace campvis {
void CampcomMhdReceiver::deinit() { void CampcomMhdReceiver::deinit() {
p_connect.s_clicked.disconnect(this); p_connect.s_clicked.disconnect(this);
_ccclient->disconnect(); if (_ccclient) {
delete _ccclient; _ccclient->disconnect();
delete _ccclient;
}
_ccclient = 0; _ccclient = 0;
} }
void CampcomMhdReceiver::process(DataContainer& data) { void CampcomMhdReceiver::process(DataContainer& data) {
validate(INVALID_RESULT);
campcom::MHDImageData* mid = _incomingMhd.fetch_and_store(0);
if (mid == 0)
return;
int numChannels = 1;
size_t dimensionality = mid->NDims;
tgt::svec3 size(1);
for (int i = 0; i < mid->DimSize.size(); ++i)
size.elem[i] = mid->DimSize[i];
WeaklyTypedPointer wtp;
wtp._pointer = &(mid->imageData.front().front());
wtp._numChannels = numChannels;
std::string et = StringUtils::uppercase(mid->elementType);
if (et == "MET_UCHAR")
wtp._baseType = WeaklyTypedPointer::UINT8;
else if (et == "MET_CHAR")
wtp._baseType = WeaklyTypedPointer::INT8;
else if (et == "MET_USHORT")
wtp._baseType = WeaklyTypedPointer::UINT16;
else if (et == "MET_SHORT")
wtp._baseType = WeaklyTypedPointer::INT16;
else if (et == "MET_UINT")
wtp._baseType = WeaklyTypedPointer::UINT32;
else if (et == "MET_INT")
wtp._baseType = WeaklyTypedPointer::INT32;
else if (et == "MET_FLOAT")
wtp._baseType = WeaklyTypedPointer::FLOAT;
else {
LERROR("Error while parsing MHD header: Unsupported element type: " << et);
return;
}
tgt::vec3 imageOffset(0.f);
tgt::vec3 voxelSize(1.f);
// all parsing done - lets create the image: // all parsing done - lets create the image:
// ImageData* image = new ImageData(dimensionality, size, numChannels); ImageData* image = new ImageData(dimensionality, size, numChannels);
// ImageRepresentationDisk::create(image, url, pt, offset, e); ImageRepresentationLocal::create(image, wtp);
// image->setMappingInformation(ImageMappingInformation(size, imageOffset + p_imageOffset.getValue(), voxelSize * p_voxelSize.getValue())); image->setMappingInformation(ImageMappingInformation(size, imageOffset + p_imageOffset.getValue(), voxelSize * p_voxelSize.getValue()));
// data.addData(p_targetImageID.getValue(), image); data.addData(p_targetImageID.getValue(), image);
validate(INVALID_RESULT); validate(INVALID_RESULT);
} }
...@@ -84,7 +130,7 @@ namespace campvis { ...@@ -84,7 +130,7 @@ namespace campvis {
_ccclient = 0; _ccclient = 0;
} }
_ccclient = new campcom::CAMPComClient("Campvis", campcom::Device_CAMPVis, p_address.getValue()); _ccclient = new campcom::CAMPComClient("Campvis", campcom::Device_TestDevice, p_address.getValue());
_ccclient->connect(); _ccclient->connect();
if (_ccclient->isConnected()) { if (_ccclient->isConnected()) {
campcom::DataCallback dc; campcom::DataCallback dc;
...@@ -94,12 +140,27 @@ namespace campvis { ...@@ -94,12 +140,27 @@ namespace campvis {
} }
else { else {
LWARNING("Could not connect to CAMPCom server."); LWARNING("Could not connect to CAMPCom server.");
delete _ccclient; // delete _ccclient;
_ccclient = 0; _ccclient = 0;
} }
} }
void CampcomMhdReceiver::ccReceiveImage(std::vector<campcom::Byte>& msg) { void CampcomMhdReceiver::ccReceiveImage(std::vector<campcom::Byte>& msg) {
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...");
campcom::MHDImageData* copy = new campcom::MHDImageData(return_payload);
campcom::MHDImageData* toDelete = _incomingMhd.fetch_and_store(copy);
delete toDelete;
invalidate(INVALID_RESULT);
}
else {
LWARNING("New MHDImageData received but it isn't valid!");
}
} }
......
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#include <CommonLib/DataTypes/MHDImageData.hpp> #include <CommonLib/DataTypes/MHDImageData.hpp>
#include <ClientLib/src/CAMPComClient.hpp> #include <ClientLib/src/CAMPComClient.hpp>
#include <tbb/atomic.h>
#include "core/pipeline/abstractprocessor.h" #include "core/pipeline/abstractprocessor.h"
#include "core/properties/buttonproperty.h" #include "core/properties/buttonproperty.h"
#include "core/properties/datanameproperty.h" #include "core/properties/datanameproperty.h"
...@@ -95,6 +97,7 @@ namespace campvis { ...@@ -95,6 +97,7 @@ namespace campvis {
void ccSuccessCalback(bool b); void ccSuccessCalback(bool b);
campcom::CAMPComClient* _ccclient; campcom::CAMPComClient* _ccclient;
tbb::atomic<campcom::MHDImageData*> _incomingMhd;
static const std::string loggerCat_; static const std::string loggerCat_;
}; };
......
...@@ -89,6 +89,7 @@ namespace campvis { ...@@ -89,6 +89,7 @@ namespace campvis {
p_outputImage.addSharedProperty(&_raycaster.p_targetImageID); p_outputImage.addSharedProperty(&_raycaster.p_targetImageID);
p_inputVolume.s_changed.connect(this, &VolumeRenderer::onPropertyChanged);
} }
VolumeRenderer::~VolumeRenderer() { VolumeRenderer::~VolumeRenderer() {
...@@ -162,6 +163,9 @@ namespace campvis { ...@@ -162,6 +163,9 @@ namespace campvis {
_eepGenerator.p_exitImageID.setValue(p_outputImage.getValue() + ".exitpoints"); _eepGenerator.p_exitImageID.setValue(p_outputImage.getValue() + ".exitpoints");
_raycaster.p_exitImageID.setValue(p_outputImage.getValue() + ".exitpoints"); _raycaster.p_exitImageID.setValue(p_outputImage.getValue() + ".exitpoints");
} }
else if (prop == &p_inputVolume) {
invalidate(AbstractProcessor::INVALID_RESULT | PG_INVALID);
}
VisualizationProcessor::onPropertyChanged(prop); VisualizationProcessor::onPropertyChanged(prop);
} }
......
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