7 #include "PlusConfigure.h" 11 #include "vtkImageData.h" 16 static const std::string GET_IMAGE_META_DATA =
"GET_IMGMETA";
17 static const std::string GET_IMAGE =
"GET_IMAGE";
19 static const char DeviceNameImageIdSeparator =
'-';
26 : ImageMetaDatasetsCount(1)
46 cmdNames.push_back(GET_IMAGE_META_DATA);
47 cmdNames.push_back(GET_IMAGE);
54 if (commandName.empty() || igsioCommon::IsEqualInsensitive(commandName, GET_IMAGE_META_DATA))
56 desc += GET_IMAGE_META_DATA;
57 desc +=
": Acquire the image meta data information from all the devices that are connected.";
59 if (commandName.empty() || igsioCommon::IsEqualInsensitive(commandName, GET_IMAGE))
62 desc +=
"Acquire the volume data and the ijkToRas transformation of the data from the specified device.";
70 SetName(GET_IMAGE_META_DATA);
82 std::string baseMessage = std::string(
"vtkPlusGetImageCommand ") + (!this->
Name.empty() ? this->
Name :
"(undefined)")
83 +
", device: (" + (this->GetImageId().empty() ?
"(undefined)" : this->GetImageId()) +
")";
86 if (igsioCommon::IsEqualInsensitive(this->
Name, GET_IMAGE_META_DATA))
88 std::string imageIdStr(this->GetImageId());
89 if (imageIdStr.size() > 0)
91 LOG_ERROR(
"The implementation of the GET_IMGMETA is not implemented for the case in which an id is specified. The id is supposed to be empty and then it will send the meta data from all connected devices")
101 else if (igsioCommon::IsEqualInsensitive(this->
Name, GET_IMAGE))
118 if (dataCollector == NULL)
120 outErrorString =
"The DataCollector is NULL.";
124 vtkSmartPointer<vtkImageData> imageData = vtkSmartPointer<vtkImageData>::New();
125 vtkSmartPointer<vtkMatrix4x4> ijkToRasTransform = vtkSmartPointer<vtkMatrix4x4>::New();
131 outErrorString =
"PLUS device has a NULL id.";
135 std::string imageIdStr(this->GetImageId());
136 size_t dashFound = imageIdStr.find_last_of(DeviceNameImageIdSeparator);
137 if (dashFound == std::string::npos)
139 outErrorString =
"ImageId has to contain a dash right after the deviceId.";
143 std::string requestedDeviceId = imageIdStr.substr(0, dashFound);
144 std::string requestedImageId = imageIdStr.substr(dashFound + 1);
145 std::string deviceIdStr(plusDevice->
GetDeviceId());
146 if (requestedDeviceId.compare(deviceIdStr) == 0)
148 std::string assignedImageId(
"");
149 if (plusDevice->
GetImage(requestedImageId, assignedImageId, std::string(
"Ras"), imageData, ijkToRasTransform))
151 if (assignedImageId.compare(requestedImageId) != 0)
153 outErrorString =
"The assignedImageId does not match requestedImageId.";
157 vtkSmartPointer<vtkPlusCommandImageResponse> imageResponse = vtkSmartPointer<vtkPlusCommandImageResponse>::New();
159 imageResponse->SetClientId(this->
ClientId);
160 imageResponse->SetImageName(this->GetImageId());
161 imageResponse->SetImageData(imageData);
163 imageResponse->SetImageToReferenceTransform(ijkToRasTransform);
169 outErrorString =
"Could not find the image.";
177 if (dataCollector == NULL)
179 outErrorString =
"The DataCollector is NULL.";
183 igsioCommon::ImageMetaDataList imageMetaDataList;
187 if (plusDevice == NULL)
189 outErrorString =
"NULL device found in data collector list.";
194 outErrorString =
"PLUS device has a NULL deviceId.";
197 igsioCommon::ImageMetaDataList imageMetaDataListDevice;
198 imageMetaDataListDevice.clear();
200 for (igsioCommon::ImageMetaDataList::iterator it = imageMetaDataListDevice.begin(); it != imageMetaDataListDevice.end(); it++)
202 if (it->Id.find(DeviceNameImageIdSeparator) != std::string::npos)
204 outErrorString =
"DeviceId cannot contain a dash.";
207 it->Id = std::string(plusDevice->
GetDeviceId()) + DeviceNameImageIdSeparator + (*it).Id;
209 imageMetaDataList.splice(imageMetaDataList.end(), imageMetaDataListDevice, imageMetaDataListDevice.begin(), imageMetaDataListDevice.end());
211 if (imageMetaDataList.size() == 0)
213 LOG_INFO(
"There are currently no images on the devices that are connected through plus.");
216 vtkSmartPointer<vtkPlusCommandImageMetaDataResponse > imageMetaDataResponse = vtkSmartPointer<vtkPlusCommandImageMetaDataResponse>::New();
218 imageMetaDataResponse->SetClientId(this->
ClientId);
220 imageMetaDataResponse->SetImageMetaDataItems(imageMetaDataList);
virtual void PrintSelf(ostream &os, vtkIndent indent)
Abstract interface for tracker and video devices.
std::vector< vtkPlusDevice * >::const_iterator DeviceCollectionConstIterator
virtual ~vtkPlusGetImageCommand()
virtual bool GetRespondWithCommandMessage()
const char ** errorString
vtkStandardNewMacro(vtkPlusGetImageCommand)
virtual void GetCommandNames(std::list< std::string > &cmdNames)
virtual std::string GetDeviceId() const
virtual PlusStatus Execute()
DeviceCollectionConstIterator GetDeviceConstIteratorBegin() const
virtual PlusStatus GetImageMetaData(igsioCommon::ImageMetaDataList &imageMetaDataItems)
PlusStatus ExecuteImageMetaReply(std::string &outErrorString)
virtual void PrintSelf(ostream &os, vtkIndent indent)
DeviceCollectionConstIterator GetDeviceConstIteratorEnd() const
Manages devices that record image or positional data.
bool RespondWithCommandMessage
virtual PlusStatus GetImage(const std::string &requestedImageId, std::string &assignedImageId, const std::string &imageReferencFrameName, vtkImageData *imageData, vtkMatrix4x4 *ijkToReferenceTransform)
void SetNameToGetImageMeta()
void QueueCommandResponse(PlusStatus status, const std::string &message, const std::string &error="", const igtl::MessageBase::MetaDataMap *metaData=nullptr)
virtual vtkPlusDataCollector * GetDataCollector()
PlusStatus ExecuteImageReply(std::string &outErrorString)
This command is used to answer the OpenIGTLink messages "GET_IMGMETA" and "GET_IMAGE"....
PlusCommandResponseList CommandResponseQueue
virtual std::string GetDescription(const std::string &commandName)