63 #ifndef GADGETRON_CLIENT 64 #define GADGETRON_CLIENT 66 #ifndef WIN32_LEAN_AND_MEAN 67 #define WIN32_LEAN_AND_MEAN 71 #include <condition_variable> 80 #include <boost/asio.hpp> 81 #include <boost/thread/thread.hpp> 83 #include <ismrmrd/dataset.h> 84 #include <ismrmrd/ismrmrd.h> 85 #include <ismrmrd/meta.h> 87 #include "sirf/Gadgetron/cgadgetron_shared_ptr.h" 90 enum GadgetronMessageID {
91 GADGET_MESSAGE_INT_ID_MIN = 0,
92 GADGET_MESSAGE_CONFIG_FILE = 1,
93 GADGET_MESSAGE_CONFIG_SCRIPT = 2,
94 GADGET_MESSAGE_PARAMETER_SCRIPT = 3,
95 GADGET_MESSAGE_CLOSE = 4,
96 GADGET_MESSAGE_TEXT = 5,
97 GADGET_MESSAGE_INT_ID_MAX = 999,
98 GADGET_MESSAGE_EXT_ID_MIN = 1000,
99 GADGET_MESSAGE_ISMRMRD_ACQUISITION = 1008,
100 GADGET_MESSAGE_CLOUD_JOB = 1013,
101 GADGET_MESSAGE_GADGETCLOUD_JOB = 1014,
102 GADGET_MESSAGE_DICOM_WITHNAME = 1018,
103 GADGET_MESSAGE_DEPENDENCY_QUERY = 1019,
104 GADGET_MESSAGE_ISMRMRD_IMAGE = 1022,
105 GADGET_MESSAGE_RECONDATA = 1023,
106 GADGET_MESSAGE_EXT_ID_MAX = 4096
109 #define MAX_BLOBS_LOG_10 6 118 char configuration_file[1024];
122 uint32_t script_length;
129 virtual const char* what()
const throw()
146 virtual void read(boost::asio::ip::tcp::socket* s) = 0;
156 (gadgetron::shared_ptr<MRAcquisitionData> ptr_acqs) : ptr_acqs_(ptr_acqs) {}
159 virtual void read(boost::asio::ip::tcp::socket* stream);
162 gadgetron::shared_ptr<MRAcquisitionData> ptr_acqs_;
172 (gadgetron::shared_ptr<GadgetronImageData> ptr_images) : ptr_images_(ptr_images) {}
175 template <
typename T>
176 void read_data_attributes
177 (ISMRMRD::Image<T>* ptr,
const ISMRMRD::ImageHeader& h,
void** ptr_ptr,
178 boost::asio::ip::tcp::socket* stream)
180 ISMRMRD::Image < T >* ptr_im =
new ISMRMRD::Image < T > ;
181 *ptr_ptr = (
void*)ptr_im;
182 ISMRMRD::Image<T>& im = *ptr_im;
187 typedef unsigned long long size_t_type;
188 size_t_type meta_attrib_length;
190 (*stream, boost::asio::buffer(&meta_attrib_length,
sizeof(size_t_type)));
191 if (meta_attrib_length > 0) {
192 std::string meta_attrib(meta_attrib_length, 0);
193 boost::asio::read(*stream, boost::asio::buffer(const_cast < char* >
194 (meta_attrib.c_str()), meta_attrib_length));
195 im.setAttributeString(meta_attrib);
199 (*stream, boost::asio::buffer(im.getDataPtr(), im.getDataSize()));
202 virtual void read(boost::asio::ip::tcp::socket* stream);
205 gadgetron::shared_ptr<GadgetronImageData> ptr_images_;
212 : number_of_calls_(0)
213 , file_prefix(fileprefix)
214 , file_suffix(filesuffix)
220 virtual void read(boost::asio::ip::tcp::socket* socket)
224 boost::asio::read(*socket, boost::asio::buffer(&nbytes,
sizeof(uint32_t)));
226 std::vector<char> data(nbytes, 0);
227 boost::asio::read(*socket, boost::asio::buffer(&data[0], nbytes));
229 unsigned long long fileNameLen;
230 boost::asio::read(*socket, boost::asio::buffer(&fileNameLen,
sizeof(
unsigned long long)));
232 std::string filenameBuf(fileNameLen, 0);
233 boost::asio::read(*socket, boost::asio::buffer(const_cast<char*>
234 (filenameBuf.c_str()), fileNameLen));
236 typedef unsigned long long size_t_type;
238 size_t_type meta_attrib_length;
239 boost::asio::read(*socket, boost::asio::buffer(&meta_attrib_length,
sizeof(size_t_type)));
241 std::string meta_attrib;
242 if (meta_attrib_length > 0) {
243 std::string meta_attrib_socket(meta_attrib_length, 0);
244 boost::asio::read(*socket, boost::asio::buffer(const_cast<char*>(meta_attrib_socket.c_str()), meta_attrib_length));
245 meta_attrib = meta_attrib_socket;
248 std::stringstream filename;
249 std::string filename_attrib;
252 filename << file_prefix <<
"_";
253 filename << std::setfill(
'0') << std::setw(MAX_BLOBS_LOG_10) << number_of_calls_;
254 filename_attrib = filename.str();
255 filename <<
"." << file_suffix;
256 filename_attrib.append(
"_attrib.xml");
258 std::cout <<
"Writing image " << filename.str() << std::endl;
260 std::ofstream outfile;
261 outfile.open(filename.str().c_str(), std::ios::out | std::ios::binary);
263 std::ofstream outfile_attrib;
264 if (meta_attrib_length > 0) {
265 outfile_attrib.open(filename_attrib.c_str(), std::ios::out | std::ios::binary);
268 if (outfile.good()) {
270 outfile.write(&data[0], nbytes);
272 if (meta_attrib_length > 0) {
273 outfile_attrib.write(meta_attrib.c_str(), meta_attrib.length());
274 outfile_attrib.close();
284 size_t number_of_calls_;
285 std::string file_prefix;
286 std::string file_suffix;
304 void set_timeout(
unsigned int t)
313 reader_thread_.join();
316 void connect(std::string hostname, std::string port);
318 void send_gadgetron_close();
320 void send_gadgetron_configuration_file(std::string config_xml_name);
322 void send_gadgetron_configuration_script(std::string xml_string);
324 void send_gadgetron_parameters(std::string xml_string);
326 void send_ismrmrd_acquisition(ISMRMRD::Acquisition& acq);
329 void send_ismrmrd_image(ISMRMRD::Image<T>* ptr_im)
331 ISMRMRD::Image<T>& im = *ptr_im;
336 id.id = GADGET_MESSAGE_ISMRMRD_IMAGE;
342 boost::asio::buffer(&im.getHead(),
sizeof(ISMRMRD::ImageHeader)));
344 size_t meta_attrib_length = im.getAttributeStringLength();
345 std::string meta_attrib(meta_attrib_length + 1, 0);
346 im.getAttributeString(meta_attrib);
349 (*socket_, boost::asio::buffer(&meta_attrib_length,
sizeof(
size_t)));
351 (*socket_, boost::asio::buffer(meta_attrib.c_str(), meta_attrib_length));
354 (*socket_, boost::asio::buffer(im.getDataPtr(), im.getDataSize()));
357 void send_wrapped_image(
const ImageWrap& iw)
359 IMAGE_PROCESSING_SWITCH(iw.type(), send_ismrmrd_image, iw.ptr_image());
363 (
unsigned short slot, gadgetron::shared_ptr<GadgetronClientMessageReader> r)
370 std::map < unsigned short, gadgetron::shared_ptr<GadgetronClientMessageReader> >
375 boost::asio::io_service io_service;
376 boost::asio::ip::tcp::socket* socket_;
377 boost::thread reader_thread_;
379 unsigned int timeout_ms_;
Abstract base class for receiving messages from Gadgetron server.
Definition: gadgetron_client.h:140
Class for accumulating acquisitions sent by Gadgetron server.
Definition: gadgetron_client.h:152
Class for accumulating ISMRMRD images sent by Gadgetron server.
Definition: gadgetron_client.h:168
Definition: gadgetron_client.h:121
virtual void read(boost::asio::ip::tcp::socket *socket)
Definition: gadgetron_client.h:220
Definition: gadgetron_client.h:208
Abstract data container.
Definition: GeometricalInfo.cpp:141
Specification file for data container classes for Gadgetron data.
Definition: gadgetron_client.h:125
Class for communicating with Gadgetron server.
Definition: gadgetron_client.h:292
Definition: gadgetron_client.h:117
Definition: gadgetron_client.h:113
Wrapper for ISMRMRD::Image.
Definition: gadgetron_image_wrap.h:106