83 FLTNB* p_angles = NULL;
84 FLTNB* p_CORtoDetectorDistance = NULL;
96 p_CORtoDetectorDistance,
102 Cerr(
"***** iDataFileSPECT::ReadSpecificInfoInHeader() -> Number of projections should be strictly positive !" << endl);
120 Cout(
" --> Provided projection angles | distance Center of Rotation (COR) to detector: " << endl);
130 Cerr(
"***** iDataFileSPECT::ReadSpecificInfoInHeader() -> Error while reading optional fields in the header data file !" << endl);
137 Cerr(
"***** iDataFileSPECT::ReadSpecificInfoInHeader() -> A problem occured while setting the isotope to oImageDimensionsAndQuantification !" << endl);
183 m_sizeEvent =
sizeof(uint32_t) + 2*
sizeof(uint32_t);
188 for (
int i=0 ; i<3; i++)
206 Cerr(
"***** iDataFileSPECT::ComputeSizeEvent() -> Unknown event mode !" << endl);
213 Cerr(
"***** iDataFileSPECT::ComputeSizeEvent() -> Error, the Event size in bytes should be >= 0 !" << endl;);
263 Cerr(
"*****iDataFileSPECT::PrepareDataFile() -> Error while trying to allocate memory for the Event object!" << endl);
281 else Cout(
" --> Correct for normalization" << endl);
293 else Cout(
" --> Correct for scatter events" << endl);
311 char* file_position = ap_buffer;
319 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
320 file_position +=
sizeof(uint32_t);
324 event->SetKind(*reinterpret_cast<uint8_t*>(file_position));
325 file_position +=
sizeof(uint8_t);
340 for (
int i=0; i<3; i++)
344 if (!
m_ignorePOIFlag)
event->SetPOI(i,*reinterpret_cast<FLTNBDATA*>(file_position));
349 event->SetID1(0, *reinterpret_cast<uint32_t*>(file_position));
350 file_position +=
sizeof(uint32_t);
352 event->SetID2(0, *reinterpret_cast<uint32_t*>(file_position));
353 file_position +=
sizeof(uint32_t);
362 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
363 file_position +=
sizeof(uint32_t);
365 event->SetEventValue(0, *reinterpret_cast<FLTNBDATA*>(file_position));
380 event->SetID1(0, *reinterpret_cast<uint32_t*>(file_position));
381 file_position +=
sizeof(uint32_t);
383 event->SetID2(0, *reinterpret_cast<uint32_t*>(file_position));
384 file_position +=
sizeof(uint32_t);
401 Cout(
"iDataFileSPECT::DescribeSpecific() -> Here is some specific content of the SPECT datafile" << endl);
412 else Cout(
" --> Head rotation is undefined !!!" << endl);
429 Cerr(
"***** iDataFileSPECT::CheckSpecificParameters() -> Data type should be SPECT !'" << endl);
435 Cerr(
"***** iDataFileSPECT::CheckSpecificParameters() -> Number of projections not initialized (should be >0) !" << endl);
441 Cerr(
"***** iDataFileSPECT::CheckSpecificParameters() -> Projection angles not initialized !" << endl);
458 fstream* p_file =
new fstream(
m_dataFileName.c_str(), ios::binary| ios::in );
460 if (!p_file->is_open())
462 Cerr(
"***** iDataFilePET::CheckFileSizeConsistency() -> Failed to open input file '" <<
m_dataFileName.c_str() <<
"' !" << endl);
467 p_file->seekg(0, ios::end);
468 int64_t sizeInBytes = p_file->tellg();
475 Cerr(
"----------------------------------------------------------------------------------------------------------------------------------------" << endl);
476 Cerr(
"***** iDataFileSPECT::CheckFileSizeConsistency() -> DataFile size is not consistent with the information provided by the user/datafile !" << endl);
478 Cerr(
" --> Actual size: "<< sizeInBytes << endl << endl);
479 Cerr(
" ADDITIONAL INFORMATION ABOUT THE DATAFILE INITIALIZATION" << endl);
481 else Cerr(
" --> No information about the kind of events in the data" << endl);
483 else Cerr(
" --> No normalization correction term in the data" << endl);
485 else Cerr(
" --> No scatter correction term in the data" << endl);
487 Cerr(
" --> Number of bins are equal to " <<
mp_nbOfBins[0] <<
"," <<
mp_nbOfBins[1] <<
" for transaxial,axial axis respectively" << endl);
494 Cerr(
"----------------------------------------------------------------------------------------------------------------------------------------" << endl);
514 Cerr(
"***** iDataFileSPECT::CheckSpecificConsistencyWithAnotherDataFile() -> Isotopes are inconsistent !" << endl);
520 Cerr(
"***** iDataFileSPECT::CheckSpecificConsistencyWithAnotherDataFile() -> Event kind flags are inconsistent !" << endl);
526 Cerr(
"***** iDataFileSPECT::CheckSpecificConsistencyWithAnotherDataFile() -> Normalization correction flags are inconsistent !" << endl);
532 Cerr(
"***** iDataFileSPECT::CheckSpecificConsistencyWithAnotherDataFile() -> Scatter correction flags are inconsistent !" << endl);
538 Cerr(
"***** iDataFileSPECT::CheckSpecificConsistencyWithAnotherDataFile() -> Data modes are inconsistent (list-mode or histogram) !" << endl);
556 Cerr(
"***** iDataFileSPECT::InitAngles() -> Number of projection angles not initialized !'" << endl);
578 Cerr(
"***** iDataFileSPECT::InitAngles() -> Number of projection angles not initialized !'" << endl);
619 m_headerFileName = path_name.append(img_name).append(
"_CstrProj").append(
".Cdh");
630 datafile_name.append(
"_").append(ss.str());
632 m2p_dataFile[th] =
new fstream( datafile_name.c_str(), ios::binary | ios::out | ios::trunc);
637 ofstream output_file(
m_dataFileName.c_str(), ios::out | ios::trunc);
659 Cerr(
"*****iDataFileSPECT::WriteEvent() -> Error while trying to write projection datafile (list-mode)" << endl);
668 Cerr(
"*****iDataFileSPECT::WriteEvent() -> Error while trying to write projection datafile (histogram)" << endl);
689 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
703 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&norm_corr_factor),
sizeof(
FLTNB));
706 uint32_t id1 = ap_Event->
GetID1(0);
707 uint32_t id2 = ap_Event->
GetID2(0);
708 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
709 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
727 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
731 uint8_t event_kind = ap_Event->
GetKind();
732 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&event_kind),
sizeof(uint8_t));
744 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&norm_corr_factor),
sizeof(
FLTNB));
765 uint32_t id1 = ap_Event->
GetID1(0);
766 uint32_t id2 = ap_Event->
GetID2(0);
767 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
768 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
786 if (!headerFile.is_open())
788 Cerr(
"***** iDataFileSPECT::WriteHeader() -> Failed to open output header file '" <<
m_headerFileName <<
"' !" << endl);
794 headerFile <<
"Number of events: " <<
m_nbEvents << endl;
800 headerFile <<
"Data type: SPECT" << endl;
813 headerFile <<
"Projection angles: " <<
mp_angles[0];
818 for (
int h=1 ; h<
m_nbHeads ; h++) headerFile <<
", " << mp_CORtoDetectorDistance[h] << endl;
823 headerFile <<
"Isotope: " <<
m_isotope << endl;
830 headerFile <<
"Head rotation direction: " << rot_direction << endl;
848 FLTNB* p_angles = NULL;
849 FLTNB* p_CORtoDetectorDistance = NULL;
850 FLTNB p_pixSizeXY[2] ;
854 Cerr(
"*****iDataFileSPECT::PROJ_GetScannerSpecificParameters() -> An error occurred while trying to get SPECT geometric parameters from the scanner object !" << endl);
int CheckSpecificConsistencyWithAnotherDataFile(vDataFile *ap_DataFile)
Check consistency between 'this' and the provided datafile, for specific characteristics.
This class is designed to be a mother virtual class for DataFile.
int SetSPECTIsotope(int a_bed, const string &a_isotope)
Set the SPECT isotope for the provided bed.
static sScannerManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
#define VERBOSE_DEBUG_EVENT
bool GetNormCorrectionFlag()
Simply return m_normCorrectionFlag.
bool mp_POIDirectionFlag[3]
int InitAngles(FLTNB *ap_angles)
allocate memory for the mp_angles variable using m_nbProjections and initialize the projection angles...
int ReadSpecificInfoInHeader(bool a_affectQuantificationFlag)
Read through the header file and recover specific SPECT information.
#define MODE_NORMALIZATION
bool GetEventKindFlag()
Simply return m_eventKindFlag.
iDataFileSPECT()
iDataFileSPECT constructor. Initialize the member variables to their default values.
uint32_t GetID2(int a_line)
bool m_scatCorrectionFlag
FLTNB GetEventValue(int a_bin)
int WriteHeader()
Generate a header file according to the data output information.
Inherit from iEventSPECT. Class for SPECT histogram mode events.
void DescribeSpecific()
Implementation of the pure virtual eponym function that simply prints info about the datafile...
int GetSPECTSpecificParameters(uint16_t *ap_nbOfProjections, uint16_t *ap_nbHeads, FLTNB *ap_acquisitionZoom, uint16_t *ap_nbOfBins, FLTNB *ap_pixSizeXY, FLTNB *&ap_angles, FLTNB *&ap_CORtoDetectorDistance, int *ap_headRotDirection)
Transfer geometric information recovered from the datafile to the scanner object. ...
static sOutputManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
int WriteListEvent(iEventListSPECT *ap_Event, int a_th)
Write a SPECT list-mode event.
Declaration of class iDataFileSPECT.
string GetFileFromPath(const string &a_pathToFile)
Simply return the file from a path string passed in parameter.
~iDataFileSPECT()
iDataFileSPECT destructor.
uint16_t m_nbOfProjections
bool GetIgnoreNormCorrectionFlag()
Get the boolean that says if the normalization correction is ignored or not.
int PROJ_GetScannerSpecificParameters()
Get SPECT specific parameters for projections from the scanner object, through the scannerManager...
const string & GetPathName()
int ComputeSizeEvent()
Computation of the size of each event according to the mandatory/optional correction fields...
#define VERBOSE_DEBUG_LIGHT
Singleton class that manages output writing on disk (images, sinograms, etc). It also manages loggi...
int CheckSpecificParameters()
Check parameters specific to SPECT data.
int CheckFileSizeConsistency()
This function is implemented in child classes Check if file size is consistent. ...
int ReadDataASCIIFile(const string &a_file, const string &a_keyword, T *ap_return, int a_nbElts, bool a_mandatoryFlag)
Look for "a_nbElts" elts in the "a_file" file matching the "a_keyword" string passed as parameter a...
Singleton class that Instantiate and initialize the scanner object.
int InitCorToDetectorDistance(FLTNB *ap_CORtoDetectorDistance)
allocate memory for the ap_CORtoDetectorDistance variable using m_nbProjections, and initialize the p...
oImageDimensionsAndQuantification * mp_ID
uint16_t GetNbBins(int axis)
uint16_t GetNbProjections()
Inherit from vDataFile. Class that manages the reading of a SPECT input file (header + data)...
int GetHeadRotDirection()
Simply return m_headRotDirection.
int WriteHistoEvent(iEventHistoSPECT *ap_Event, int a_th)
Write a SPECT histogram event.
vEvent * GetEventSpecific(char *ap_buffer, int a_th)
Read an event from the position pointed by 'ap_buffer', parse the generic or modality-specific inform...
bool m_normCorrectionFlag
FLTNB mp_POIResolution[3]
int PROJ_InitFile()
Initialize the fstream objets for output writing as well as some other variables specific to the Proj...
bool m_ignoreNormCorrectionFlag
int SetSpecificParametersFrom(vDataFile *ap_DataFile)
Initialize all parameters specific to SPECT from the provided datafile.
FLTNB * mp_CORtoDetectorDistance
const string & GetBaseName()
void SetTimeInMs(uint32_t a_value)
Set the timestamp of the Event.
Mother class for the Event objects.
int WriteEvent(vEvent *ap_Event, int a_th=0)
Write event according to the chosen type of data.
vEvent ** m2p_BufferEvent
uint32_t GetID1(int a_line)
int GetNbThreadsForProjection()
Get the number of threads used for projections.
bool GetIgnoreScatCorrectionFlag()
Get the boolean that says if the scatter correction is ignored or not.
FLTNB * GetCORtoDetectorDistance()
#define DEBUG_VERBOSE(IGNORED1, IGNORED2)
FLTNB m_calibrationFactor
int PrepareDataFile()
Store different kind of information inside arrays (data relative to specific correction as well as ba...
bool m_ignoreScatCorrectionFlag
bool GetScatCorrectionFlag()
Simply return m_scatCorrectionFlag.
Inherit from iEventSPECT. Class for SPECT list-mode events.