From 44cd2da41a93b82eb18f6e22c1d8b58d44b64539 Mon Sep 17 00:00:00 2001 From: maltaverne Date: Tue, 17 Mar 2009 16:41:08 +0000 Subject: [PATCH] Add support for Ultrasonix images (.rf, .b8, .b32). --- src2/CMakeLists.txt | 2 +- src2/creaImageIOUltrasonixImageReader.cpp | 235 ++++++++++++++++++++++ src2/creaImageIOUltrasonixImageReader.h | 40 ++++ 3 files changed, 276 insertions(+), 1 deletion(-) create mode 100644 src2/creaImageIOUltrasonixImageReader.cpp create mode 100644 src2/creaImageIOUltrasonixImageReader.h diff --git a/src2/CMakeLists.txt b/src2/CMakeLists.txt index 1ce13d9..cac05e5 100644 --- a/src2/CMakeLists.txt +++ b/src2/CMakeLists.txt @@ -20,7 +20,7 @@ SET( SRCS creaImageIOAbstractImageReader creaImageIOVtkImageReader creaImageIODicomImageReader - creaImageIORFImageReader + creaImageIOUltrasonixImageReader creaImageIOImageReader creaImageIOMultiThreadImageReader diff --git a/src2/creaImageIOUltrasonixImageReader.cpp b/src2/creaImageIOUltrasonixImageReader.cpp new file mode 100644 index 0000000..12c7440 --- /dev/null +++ b/src2/creaImageIOUltrasonixImageReader.cpp @@ -0,0 +1,235 @@ + +#include +#include +#include +#include "boost/filesystem/path.hpp" + +namespace creaImageIO +{ +#define HEADER_SIZE 19 +#define TYPE_RF 16 +#define TYPE_B8 4 +#define TYPE_B32 8 + + + //===================================================================== + UltrasonixImageReader::UltrasonixImageReader() + { + SetName("Ultrasonix"); + } + //===================================================================== + + //===================================================================== + UltrasonixImageReader::~UltrasonixImageReader() + { + } + //===================================================================== + + //===================================================================== + struct Ultrasonix_header + { + // frames, width, height, ultrasounds frequency, sampling rate + int type,frame,width,height,frequency,samplingRate; + }; + //===================================================================== + + + //===================================================================== + bool ReadHeader( FILE *Ultrasonix_file, Ultrasonix_header& h ) + { + int *header=(int*)malloc(sizeof(int)*HEADER_SIZE); + fread(header,sizeof(int),HEADER_SIZE,Ultrasonix_file); + h.type = header[0]; + h.frame = header[1]; + h.height = header[2]; + h.width = header[3]; + h.frequency = header[14]; + h.samplingRate = header[15]; + free(header); + return true; + } + //===================================================================== + + //===================================================================== + bool UltrasonixImageReader::CanRead(const std::string& filename) + { + bool ok = false; + FILE *Ultrasonix_file=fopen(filename.c_str(),"rb"); + long size; + if (Ultrasonix_file) + { + Ultrasonix_header h; + ReadHeader(Ultrasonix_file,h); + + fseek(Ultrasonix_file,0,SEEK_END); // go to end of file + if (h.type == TYPE_RF) + size = (ftell(Ultrasonix_file) - (HEADER_SIZE+h.frame) * sizeof(int)) / sizeof(short); + else if (h.type == TYPE_B8) + size = (ftell(Ultrasonix_file) - HEADER_SIZE * sizeof(int)) / sizeof(char); + else if (h.type == TYPE_B32) + size = (ftell(Ultrasonix_file) - HEADER_SIZE * sizeof(int)) / sizeof(int); + + // check if the data size corresponds to the dimensions of the images + if (size == h.width * h.height * h.frame) + ok = true; + + fclose(Ultrasonix_file); + } + return ok; + } + //===================================================================== + + //===================================================================== + vtkImageData* UltrasonixImageReader::ReadImage(const std::string& filename) + { + + std::cout<<"UltrasonixImageReader reading "<& v) + { + v.push_back("Ultrasonix"); + } + //===================================================================== + + + + //===================================================================== + void UltrasonixImageReader::ReadAttributes(const std::string& filename, + std::map& attr) + { + // std::cout << "UltrasonixImageReader::ReadDicomInfo '"<::iterator i; + if ( (i = attr.find("FullFileName")) != attr.end()) + { + // boost::filesystem::path full_path(filename); + // std::string f = full_path.leaf(); + i->second = filename; + } + if ( (i = attr.find("D0004_1500")) != attr.end()) + { + boost::filesystem::path full_path(filename); + std::string f = full_path.leaf(); + i->second = f; + } + if ( (i = attr.find("D0028_0010")) != attr.end()) + { + i->second = rows; + } + if ( (i = attr.find("D0028_0011")) != attr.end()) + { + i->second = cols; + } + + if ( (i = attr.find("D0028_0012")) != attr.end()) + { + i->second = planes; + } + + GimmickMessage(2,"Attributes map:"< +#include + +namespace creaImageIO +{ + + + /** + * \ingroup IO + */ + + //===================================================================== + /// Concrete image reader for ultrasonix 'rf' files + class CREAIMAGEIO_EXPORT UltrasonixImageReader : virtual public AbstractImageReader + { + public: + UltrasonixImageReader(); + + virtual ~UltrasonixImageReader(); + + virtual void PushBackExtensions(std::vector&); + virtual bool CanRead(const std::string& filename); + virtual vtkImageData* ReadImage(const std::string& filename); + virtual void ReadAttributes(const std::string& filename, + tree::AttributeMapType& attr); + + }; + //===================================================================== + + + +} // namespace creaImageIO + + + +#endif // #ifndef __creaImageIOUltrasonixImageReader_h_INCLUDED__ -- 2.46.1