Beispiel #1
0
void PlusProtocol::translate(const igtl::TransformMessage::Pointer body)
{
    CX_LOG_DEBUG() << "Transform incoming to plusprotocol";
    QString deviceName = body->GetDeviceName();
    this->registerTransformDeviceName(deviceName);

    IGTLinkConversion converter;
    Transform3D matrix = converter.decode(body);

    if(this->isCalibration(deviceName))
    {
        Transform3D s_M_igtltool = matrix;
        Transform3D s_M_custustool = s_M_igtltool * igtltool_M_custustool;
        Transform3D sMt = s_M_custustool;
        QString calibrationBelongsToDeviceName = this->findDeviceForCalibration(deviceName);
        if(calibrationBelongsToDeviceName != "NOT_FOUND")
        {
            emit calibration(calibrationBelongsToDeviceName, sMt);
        }
    }
    else
    {
		IGTLinkConversionBase baseConverter;
		double timestamp_ms = baseConverter.decode_timestamp(body).toMSecsSinceEpoch();
		timestamp_ms = this->getSyncedTimestampForTransformsAndImages(timestamp_ms);
        Transform3D prMs = matrix;
        emit transform(deviceName, prMs, timestamp_ms);
    }
}
Beispiel #2
0
void PlusProtocol::translate(const igtl::ImageMessage::Pointer body)
{
    CX_LOG_DEBUG() << "Image incoming to plusprotocol";
    //DIMENSION
    int x = 0;
    int y = 1;
    int z = 2;

    //There seems to be a bug in the received images spacing from the plusserver
    /*
    float wrong_spacing[3];
    body->GetSpacing(wrong_spacing);
    float right_spacing[3];
    right_spacing[x] = wrong_spacing[x];
    right_spacing[y] = wrong_spacing[z];
    right_spacing[z] = 1;
    body->SetSpacing(right_spacing);
    */

    int dimensions_p[3];
    body->GetDimensions(dimensions_p);
    float spacing[3];
    body->GetSpacing(spacing);
    int extent_p[3];
    extent_p[x] = dimensions_p[x]-1;
    extent_p[y] = dimensions_p[y]-1;
    extent_p[z] = dimensions_p[z]-1;

    //IMAGE
    IGTLinkConversion converter;
    ImagePtr theImage = converter.decode(body);

	IGTLinkConversionBase baseConverter;
	double timestamp_ms = baseConverter.decode_timestamp(body).toMSecsSinceEpoch();
	timestamp_ms = this->getSyncedTimestampForTransformsAndImages(timestamp_ms);
    theImage->setAcquisitionTime(QDateTime::fromMSecsSinceEpoch(timestamp_ms));
    emit image(theImage);

    //PROBEDEFINITION
    ProbeDefinitionPtr definition(new ProbeDefinition);
    definition->setUseDigitalVideo(true);
    definition->setType(ProbeDefinition::tLINEAR);
    definition->setSpacing(Vector3D(spacing[x], spacing[y], spacing[z]));
    definition->setSize(QSize(dimensions_p[x], dimensions_p[y]));
    definition->setOrigin_p(Vector3D(dimensions_p[x]/2, 0, 0));
    double depthstart_mm = 0;
    double depthend_mm = extent_p[y]*spacing[y];
    double width_mm = extent_p[x]*spacing[x];
    definition->setSector(depthstart_mm, depthend_mm, width_mm);
    definition->setClipRect_p(DoubleBoundingBox3D(0, extent_p[x], 0, extent_p[y], 0, extent_p[z]));

    emit probedefinition(mProbeToTrackerName, definition);
}
Beispiel #3
0
void OpenIGTLinkProtocol::translate(const igtl::TransformMessage::Pointer body)
{
    //CX_LOG_DEBUG() << "Transform incoming to OpenIGTLinkProtocol";
    QString deviceName = body->GetDeviceName();

    IGTLinkConversion converter;
    Transform3D prMs = converter.decode(body);

    IGTLinkConversionBase baseConverter;
    QDateTime timestamp = baseConverter.decode_timestamp(body);

    if (mStreamSynchronizer)
    {
        mStreamSynchronizer->addTimestamp(timestamp);
        timestamp = timestamp.addMSecs(mStreamSynchronizer->getShift());
    }

    emit transform(deviceName, prMs, timestamp.toMSecsSinceEpoch());
}
ImagePtr IGTLinkConversionSonixCXLegacy::decode(igtl::ImageMessage::Pointer message)
{
	vtkImageImportPtr imageImport = vtkImageImportPtr::New();

	// Retrive the image data
	float spacing[3]; // spacing (mm/pixel)
	int svsize[3]; // sub-volume size
	int svoffset[3]; // sub-volume offset
	int scalarType; // scalar type
	int size[3]; // image dimension

	// Note: subvolumes is not supported. Implement when needed.

	scalarType = message->GetScalarType();
	message->GetDimensions(size);
	message->GetSpacing(spacing);
	message->GetSubVolume(svsize, svoffset);
	QString deviceName = message->GetDeviceName();

	imageImport->SetNumberOfScalarComponents(1);

	switch (scalarType)
	{
	case igtl::ImageMessage::TYPE_INT8:
		CX_LOG_WARNING() << "signed char is not supported. Falling back to unsigned char.";
		imageImport->SetDataScalarTypeToUnsignedChar();
		break;
	case igtl::ImageMessage::TYPE_UINT8:
		imageImport->SetDataScalarTypeToUnsignedChar();
		break;
	case igtl::ImageMessage::TYPE_INT16:
		imageImport->SetDataScalarTypeToShort();
		break;
	case igtl::ImageMessage::TYPE_UINT16:
		imageImport->SetNumberOfScalarComponents(2);
		imageImport->SetDataScalarTypeToUnsignedChar();
		break;
	case igtl::ImageMessage::TYPE_INT32:
	case igtl::ImageMessage::TYPE_UINT32:
		imageImport->SetNumberOfScalarComponents(4);
		imageImport->SetDataScalarTypeToUnsignedChar();
		break;
	case igtl::ImageMessage::TYPE_FLOAT32:
		imageImport->SetDataScalarTypeToFloat();
		break;
	case igtl::ImageMessage::TYPE_FLOAT64:
		imageImport->SetDataScalarTypeToDouble();
		break;
	default:
		CX_LOG_WARNING() << "Unknown image type. Falling back to unsigned char.";
		imageImport->SetDataScalarTypeToUnsignedChar();
	}

	imageImport->SetDataOrigin(0, 0, 0);
	imageImport->SetDataSpacing(spacing[0], spacing[1], spacing[2]);
	imageImport->SetWholeExtent(0, size[0] - 1, 0, size[1] - 1, 0, size[2] - 1);
	imageImport->SetDataExtentToWholeExtent();
	imageImport->SetImportVoidPointer(message->GetScalarPointer());

	imageImport->Modified();
	imageImport->Update();

	ImagePtr retval(new Image(deviceName, imageImport->GetOutput()));
	IGTLinkConversionBase baseConverter;
	retval->setAcquisitionTime(baseConverter.decode_timestamp(message));
	retval = this->decode(retval);

	return retval;
}
igtl::ImageMessage::Pointer IGTLinkConversionSonixCXLegacy::encode(ImagePtr image)
{
	vtkImageDataPtr rawImage = image->getBaseVtkImageData();

	int   size[]     = {256, 256, 1};       // image dimension
	rawImage->GetDimensions(size);

	double spacingD[3];
	float spacingF[3];
	rawImage->GetSpacing(spacingD);
	spacingF[0] = spacingD[0];
	spacingF[1] = spacingD[1];
	spacingF[2] = spacingD[2];
	int*   svsize   = size;
	int   svoffset[] = {0, 0, 0};           // sub-volume offset
	int   scalarType = -1;

	if (rawImage->GetNumberOfScalarComponents()==4)
	{
		if (rawImage->GetScalarType()==VTK_UNSIGNED_CHAR)
		{
			scalarType = igtl::ImageMessage::TYPE_UINT32;// scalar type
		}
	}

	if (rawImage->GetNumberOfScalarComponents()==1)
	{
		if (rawImage->GetScalarType()==VTK_UNSIGNED_SHORT)
		{
			scalarType = igtl::ImageMessage::TYPE_UINT16;// scalar type
		}
		else if (rawImage->GetScalarType()==VTK_UNSIGNED_CHAR)
		{
			scalarType = igtl::ImageMessage::TYPE_UINT8;// scalar type
		}
	}

	if (scalarType==-1)
	{
		std::cerr << "Unsupported file type based on vtk " << rawImage->GetScalarTypeAsString() << std::endl;
		return igtl::ImageMessage::Pointer();
	}

	//------------------------------------------------------------
	// Create a new IMAGE type message
	igtl::ImageMessage::Pointer imgMsg = igtl::ImageMessage::New();
	imgMsg->SetDimensions(size);
	imgMsg->SetSpacing(spacingF);
	imgMsg->SetScalarType(scalarType);
	imgMsg->SetDeviceName(cstring_cast(image->getUid()));
	imgMsg->SetSubVolume(svsize, svoffset);
	imgMsg->AllocateScalars();

	IGTLinkConversionBase baseConverter;
	baseConverter.encode_timestamp(image->getAcquisitionTime(), imgMsg);

	int fsize = imgMsg->GetImageSize();
	memcpy(imgMsg->GetScalarPointer(), rawImage->GetScalarPointer(0,0,0), fsize); // not sure if we need to copy

	igtl::Matrix4x4 matrix;
	GetIdentityMatrix(matrix);
	imgMsg->SetMatrix(matrix);

	return imgMsg;
}