Skip to content

Commit

Permalink
introduced a quick fix for dicom output failure #1128
Browse files Browse the repository at this point in the history
  • Loading branch information
evgueni-ovtchinnikov committed Oct 20, 2022
1 parent 9ef5044 commit 87540f7
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 17 deletions.
8 changes: 6 additions & 2 deletions src/xGadgetron/cGadgetron/cgadgetron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ void* cGT_newObject(const char* name)
NEW_GADGET(PhysioInterpolationGadget);
NEW_GADGET(GPURadialSensePrepGadget);
NEW_GADGET(GPUCGSenseGadget);
NEW_GADGET(FFTGadget);
NEW_GADGET(CombineGadget);
NEW_GADGET(ExtractGadget);
NEW_GADGET(AutoScaleGadget);
NEW_GADGET(ComplexToFloatGadget);
Expand Down Expand Up @@ -1041,14 +1043,16 @@ cGT_imageParameter(void* ptr_im, const char* name)

extern "C"
void*
cGT_reconstructImages(void* ptr_recon, void* ptr_input)
cGT_reconstructImages(void* ptr_recon, void* ptr_input, const char* dcm_prefix)
{
try {
CAST_PTR(DataHandle, h_recon, ptr_recon);
CAST_PTR(DataHandle, h_input, ptr_input);
ImagesReconstructor& recon = objectFromHandle<ImagesReconstructor>(h_recon);
MRAcquisitionData& input = objectFromHandle<MRAcquisitionData>(h_input);
recon.process(input);
if (strlen(dcm_prefix) < 1)
dcm_prefix = 0;
recon.process(input, dcm_prefix);
return new DataHandle;
}
CATCH;
Expand Down
21 changes: 15 additions & 6 deletions src/xGadgetron/cGadgetron/gadgetron_x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,8 @@ AcquisitionsProcessor::process(MRAcquisitionData& acquisitions)
}

void
ImagesReconstructor::process(MRAcquisitionData& acquisitions)
ImagesReconstructor::process(MRAcquisitionData& acquisitions, const char* dcm_prefix)
{
//check_gadgetron_connection(host_, port_);

std::string config = xml();
//std::cout << "config:\n" << config << std::endl;

uint32_t nacquisitions = 0;
nacquisitions = acquisitions.number();
//std::cout << nacquisitions << " acquisitions" << std::endl;
Expand All @@ -254,6 +249,19 @@ ImagesReconstructor::process(MRAcquisitionData& acquisitions)
conn().register_reader(GADGET_MESSAGE_ISMRMRD_IMAGE,
shared_ptr<GadgetronClientMessageReader>
(new GadgetronClientImageMessageCollector(sptr_images_)));
if (dcm_prefix) {
add_gadget("extract", gadgetron::shared_ptr<aGadget>(new ExtractGadget));
add_gadget("autoscale", gadgetron::shared_ptr<aGadget>(new AutoScaleGadget));
add_writer("writer_dcm", writer_dcm_);
gadgetron::shared_ptr<DicomFinishGadget> endgadget(new DicomFinishGadget);
set_endgadget(endgadget);
conn().register_reader(GADGET_MESSAGE_DICOM_WITHNAME,
shared_ptr<GadgetronClientMessageReader>
(new GadgetronClientBlobMessageReader(std::string(dcm_prefix), std::string("dcm"))));
}
std::string config = xml();
//std::cout << "config:\n" << config << std::endl;

for (int nt = 0; nt < N_TRIALS; nt++) {
try {
conn().connect(host_, port_);
Expand Down Expand Up @@ -288,6 +296,7 @@ ImagesProcessor::process(const GadgetronImageData& images)
THROW("DICOM writer does not support complex images");

std::string config = xml();
std::cout << xml() << '\n';
GTConnector conn;
sptr_images_ = images.new_images_container();
if (dicom_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extern "C" {
int from, int till, int n, PTR_FLOAT values);

// image methods
void* cGT_reconstructImages(void* ptr_recon, void* ptr_input);
void* cGT_reconstructImages(void* ptr_recon, void* ptr_input, const char* dcm_prefix);
void* cGT_reconstructedImages(void* ptr_recon);
void* cGT_readImages(const char* file);
void* cGT_ImageFromAcquisitiondata(void* ptr_acqs);
Expand Down
24 changes: 23 additions & 1 deletion src/xGadgetron/cGadgetron/include/sirf/Gadgetron/gadget_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,29 @@ namespace sirf {
}
};

class GenericReconCartesianFFTGadget : public Gadget {
class FFTGadget : public Gadget {
public:
FFTGadget() :
Gadget("FFT", "gadgetron_mricore", "FFTGadget")
{}
static const char* class_name()
{
return "FFTGadget";
}
};

class CombineGadget : public Gadget {
public:
CombineGadget() :
Gadget("Combine", "gadgetron_mricore", "CombineGadget")
{}
static const char* class_name()
{
return "CombineGadget";
}
};

class GenericReconCartesianFFTGadget : public Gadget {
public:
GenericReconCartesianFFTGadget() :
Gadget("Recon", "gadgetron_mricore", "GenericReconCartesianFFTGadget")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,14 @@ namespace sirf {
, file_prefix(fileprefix)
, file_suffix(filesuffix)
{
//std::cout << fileprefix << '.' << filesuffix << '\n';
}

virtual ~GadgetronClientBlobMessageReader() {}

virtual void read(boost::asio::ip::tcp::socket* socket)
{
//std::cout << "in GadgetronClientBlobMessageReader::read...\n";
// MUST READ 32-bits
uint32_t nbytes;
boost::asio::read(*socket, boost::asio::buffer(&nbytes, sizeof(uint32_t)));
Expand Down Expand Up @@ -255,7 +257,7 @@ namespace sirf {
filename << "." << file_suffix;
filename_attrib.append("_attrib.xml");

std::cout << "Writing image " << filename.str() << std::endl;
//std::cout << "Writing image " << filename.str() << std::endl;

std::ofstream outfile;
outfile.open(filename.str().c_str(), std::ios::out | std::ios::binary);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ namespace sirf {

ImagesReconstructor() :
reader_(new IsmrmrdAcqMsgReader),
writer_(new IsmrmrdImgMsgWriter)
writer_(new IsmrmrdImgMsgWriter),
writer_dcm_(new DicomImageMessageWriter)
{
//class_ = "ImagesReconstructor";
sptr_images_.reset();
add_reader("reader", reader_);
add_writer("writer", writer_);
Expand All @@ -253,7 +253,7 @@ namespace sirf {
return "ImagesReconstructor";
}

void process(MRAcquisitionData& acquisitions);
void process(MRAcquisitionData& acquisitions, const char* dcm_prefix = "image");
gadgetron::shared_ptr<GadgetronImageData> get_output()
{
return sptr_images_;
Expand All @@ -262,6 +262,7 @@ namespace sirf {
private:
gadgetron::shared_ptr<IsmrmrdAcqMsgReader> reader_;
gadgetron::shared_ptr<IsmrmrdImgMsgWriter> writer_;
gadgetron::shared_ptr<DicomImageMessageWriter> writer_dcm_;
gadgetron::shared_ptr<GadgetronImageData> sptr_images_;
};

Expand Down
13 changes: 10 additions & 3 deletions src/xGadgetron/pGadgetron/Gadgetron.py
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ class Reconstructor(GadgetChain):
Class for a chain of gadgets that has AcquisitionData on input and
ImageData on output.
'''
def __init__(self, list = None):
def __init__(self, list=None):
self.handle = None
self.handle = pygadgetron.cGT_newObject('ImagesReconstructor')
check_status(self.handle)
Expand All @@ -1435,14 +1435,21 @@ def set_input(self, input_data):
'''
assert isinstance(input_data, AcquisitionData)
self.input_data = input_data
def process(self):
def process(self, dcm_prefix=None):
'''
Processes the input with the gadget chain.
dcm_prefix: Python text string.
If dcm_prefix is not None, the reconstructed images are written to
files <dcm_prefix>_<image number>.dcm.
Otherwise, they are stored in memory and can be retrieved by
get_output().
'''
if self.input_data is None:
raise error('no input data')
if dcm_prefix is None:
dcm_prefix = ""
try_calling(pygadgetron.cGT_reconstructImages\
(self.handle, self.input_data.handle))
(self.handle, self.input_data.handle, dcm_prefix))
def get_output(self, subset = None):
'''
Returns specified subset of the output ImageData. If no subset is
Expand Down

0 comments on commit 87540f7

Please sign in to comment.