-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lauras changes #86
base: master
Are you sure you want to change the base?
Lauras changes #86
Changes from all commits
5c7f0fc
c3ae18e
74cf5c4
38ce626
59f6a52
e0d7b7f
4147cea
26c8c3e
67e116c
efc7ccc
d040b75
f84fc17
7e705ac
9a29ed7
3cf8378
5fefdfb
bd6f65d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "igtlioNDArrayConverter.h" | ||
#include "igtlNDArrayMessage.h" | ||
#include <igtl_util.h> | ||
#include <vtkDataArray.h> | ||
#include <vtkDoubleArray.h> | ||
#include <vtkUnsignedIntArray.h> | ||
#include <vtkCollection.h> | ||
|
||
int igtlioNDArrayConverter::fromIGTL(igtl::MessageBase::Pointer source, | ||
HeaderData* header, | ||
ContentData* dest, | ||
bool checkCRC, | ||
igtl::MessageBase::MetaDataMap& outMetaInfo) | ||
{ | ||
igtl::NDArrayMessage::Pointer msg; | ||
msg = igtl::NDArrayMessage::New(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use a factory to create the message |
||
msg->Copy(source); | ||
|
||
int c = msg->Unpack(checkCRC); | ||
if ((c & igtl::MessageHeader::UNPACK_BODY == 0)) | ||
{ | ||
return 0; | ||
} | ||
|
||
if (!IGTLtoHeader(dynamic_pointer_cast<igtl::MessageBase>(msg), header, outMetaInfo)) | ||
return 0; | ||
|
||
vtkSmartPointer<vtkCollection> collection = vtkSmartPointer<vtkCollection>::New(); | ||
|
||
for (int i = 0; i < msg->GetArray()->GetSize()[0]; ++i) { | ||
vtkSmartPointer<vtkDoubleArray> NDArray_msg = vtkSmartPointer<vtkDoubleArray>::New(); | ||
NDArray_msg->SetNumberOfTuples(msg->GetArray()->GetSize()[0]); | ||
memcpy(NDArray_msg->GetPointer(0), static_cast<char*>(msg->GetArray()->GetRawArray()) + (NDArray_msg->GetDataSize() * NDArray_msg->GetDataTypeSize() * i), NDArray_msg->GetDataSize() * NDArray_msg->GetDataTypeSize()); | ||
collection->AddItem(NDArray_msg); | ||
} | ||
dest->collection = collection; | ||
return 1; | ||
} | ||
|
||
int igtlioNDArrayConverter::toIGTL(const HeaderData& header, const ContentData& source, igtl::NDArrayMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo) | ||
{ | ||
if (dest->IsNull()) | ||
*dest = igtl::NDArrayMessage::New(); | ||
(*dest)->InitPack(); | ||
igtl::NDArrayMessage::Pointer msg = *dest; | ||
|
||
if (!metaInfo.empty()) | ||
{ | ||
msg->SetHeaderVersion(IGTL_HEADER_VERSION_2); | ||
} | ||
igtl::MessageBase::Pointer basemsg = dynamic_pointer_cast<igtl::MessageBase>(msg); | ||
HeadertoIGTL(header, &basemsg, metaInfo); | ||
|
||
msg->Pack(); | ||
return 1; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef NDARRAYCONVERTER_H | ||
#define NDARRAYCONVERTER_H | ||
|
||
#include "igtlioConverterExport.h" | ||
#include <igtlNDArrayMessage.h> | ||
#include "igtlioBaseConverter.h" | ||
class vtkDataArray; | ||
typedef vtkSmartPointer<class igtlioNDArrayDevice> igtlioNDArrayDevicePointer; | ||
class OPENIGTLINKIO_CONVERTER_EXPORT igtlioNDArrayConverter : public igtlioBaseConverter | ||
{ | ||
public: | ||
|
||
|
||
struct ContentData | ||
{ | ||
vtkSmartPointer<vtkDataArray> NDArray_msg; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ContentData will also have to store what kind of scalar the array is. Use the IGTL type defines for this. |
||
|
||
static const char* GetIGTLName() { return GetIGTLTypeName(); } | ||
static const char* GetIGTLTypeName() {return "ARRAY"; } | ||
|
||
static int fromIGTL(igtl::MessageBase::Pointer source, HeaderData* header, ContentData* content, bool checkCRC, igtl::MessageBase::MetaDataMap& outMetaInfo); | ||
static int toIGTL(const HeaderData& header, const ContentData& source, igtl::NDArrayMessage::Pointer* dest, igtl::MessageBase::MetaDataMap metaInfo = igtl::MessageBase::MetaDataMap()); | ||
|
||
}; | ||
|
||
#endif //NDARRAYCONVERTER_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 space indentation