82 FLTNB* p_angles = NULL;
83 FLTNB* p_CORtoDetectorDistance = NULL;
95 p_CORtoDetectorDistance,
101 Cerr(
"***** iDataFileSPECT::ReadSpecificInfoInHeader() -> Number of projections should be strictly positive !" << endl);
119 Cout(
" --> Provided projection angles | distance Center of Rotation (COR) to detector: " << endl);
129 Cerr(
"***** iDataFileSPECT::ReadSpecificInfoInHeader() -> Error while reading optional fields in the header data file !" << endl);
136 Cerr(
"***** iDataFileSPECT::ReadSpecificInfoInHeader() -> A problem occurred while setting the isotope to oImageDimensionsAndQuantification !" << endl);
182 m_sizeEvent =
sizeof(uint32_t) + 2*
sizeof(uint32_t);
187 for (
int i=0 ; i<3; i++)
205 Cerr(
"***** iDataFileSPECT::ComputeSizeEvent() -> Unknown event mode !" << endl);
212 Cerr(
"***** iDataFileSPECT::ComputeSizeEvent() -> Error, the Event size in bytes should be >= 0 !" << endl;);
262 Cerr(
"*****iDataFileSPECT::PrepareDataFile() -> Error while trying to allocate memory for the Event object!" << endl);
280 else Cout(
" --> Correct for normalization" << endl);
292 else Cout(
" --> Correct for scatter events" << endl);
310 char* file_position = ap_buffer;
318 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
319 file_position +=
sizeof(uint32_t);
323 event->SetKind(*reinterpret_cast<uint8_t*>(file_position));
324 file_position +=
sizeof(uint8_t);
339 for (
int i=0; i<3; i++)
343 if (!
m_ignorePOIFlag)
event->SetPOI(i,*reinterpret_cast<FLTNBDATA*>(file_position));
348 event->SetID1(0, *reinterpret_cast<uint32_t*>(file_position));
349 file_position +=
sizeof(uint32_t);
351 event->SetID2(0, *reinterpret_cast<uint32_t*>(file_position));
352 file_position +=
sizeof(uint32_t);
361 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
362 file_position +=
sizeof(uint32_t);
364 event->SetEventValue(0, *reinterpret_cast<FLTNBDATA*>(file_position));
379 event->SetID1(0, *reinterpret_cast<uint32_t*>(file_position));
380 file_position +=
sizeof(uint32_t);
382 event->SetID2(0, *reinterpret_cast<uint32_t*>(file_position));
383 file_position +=
sizeof(uint32_t);
400 Cout(
"iDataFileSPECT::DescribeSpecific() -> Here is some specific content of the SPECT datafile" << endl);
411 else Cout(
" --> Head rotation is undefined !!!" << endl);
428 Cerr(
"***** iDataFileSPECT::CheckSpecificParameters() -> Data type should be SPECT !'" << endl);
434 Cerr(
"***** iDataFileSPECT::CheckSpecificParameters() -> Number of projections not initialized (should be >0) !" << endl);
440 Cerr(
"***** iDataFileSPECT::CheckSpecificParameters() -> Projection angles not initialized !" << endl);
457 fstream* p_file =
new fstream(
m_dataFileName.c_str(), ios::binary| ios::in );
459 if (!p_file->is_open())
461 Cerr(
"***** iDataFilePET::CheckFileSizeConsistency() -> Failed to open input file '" <<
m_dataFileName.c_str() <<
"' !" << endl);
466 p_file->seekg(0, ios::end);
467 int64_t sizeInBytes = p_file->tellg();
474 Cerr(
"----------------------------------------------------------------------------------------------------------------------------------------" << endl);
475 Cerr(
"***** iDataFileSPECT::CheckFileSizeConsistency() -> DataFile size is not consistent with the information provided by the user/datafile !" << endl);
477 Cerr(
" --> Actual size: "<< sizeInBytes << endl << endl);
478 Cerr(
" ADDITIONAL INFORMATION ABOUT THE DATAFILE INITIALIZATION" << endl);
480 else Cerr(
" --> No information about the kind of events in the data" << endl);
482 else Cerr(
" --> No normalization correction term in the data" << endl);
484 else Cerr(
" --> No scatter correction term in the data" << endl);
486 Cerr(
" --> Number of bins are equal to " <<
mp_nbOfBins[0] <<
"," <<
mp_nbOfBins[1] <<
" for transaxial,axial axis respectively" << endl);
493 Cerr(
"----------------------------------------------------------------------------------------------------------------------------------------" << endl);
513 Cerr(
"***** iDataFileSPECT::CheckSpecificConsistencyWithAnotherDataFile() -> Isotopes are inconsistent !" << endl);
519 Cerr(
"***** iDataFileSPECT::CheckSpecificConsistencyWithAnotherDataFile() -> Event kind flags are inconsistent !" << endl);
525 Cerr(
"***** iDataFileSPECT::CheckSpecificConsistencyWithAnotherDataFile() -> Normalization correction flags are inconsistent !" << endl);
531 Cerr(
"***** iDataFileSPECT::CheckSpecificConsistencyWithAnotherDataFile() -> Scatter correction flags are inconsistent !" << endl);
537 Cerr(
"***** iDataFileSPECT::CheckSpecificConsistencyWithAnotherDataFile() -> Data modes are inconsistent (list-mode or histogram) !" << endl);
555 Cerr(
"***** iDataFileSPECT::InitAngles() -> Number of projection angles not initialized !'" << endl);
577 Cerr(
"***** iDataFileSPECT::InitAngles() -> Number of projection angles not initialized !'" << endl);
626 datafile_name.append(
"_").append(ss.str());
628 m2p_dataFile[th] =
new fstream( datafile_name.c_str(), ios::binary | ios::out | ios::trunc);
633 ofstream output_file(
m_dataFileName.c_str(), ios::out | ios::trunc);
655 Cerr(
"*****iDataFileSPECT::WriteEvent() -> Error while trying to write projection datafile (list-mode)" << endl);
664 Cerr(
"*****iDataFileSPECT::WriteEvent() -> Error while trying to write projection datafile (histogram)" << endl);
685 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
702 uint32_t id1 = ap_Event->
GetID1(0);
703 uint32_t id2 = ap_Event->
GetID2(0);
704 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
705 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
723 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
727 uint8_t event_kind = ap_Event->
GetKind();
728 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&event_kind),
sizeof(uint8_t));
761 uint32_t id1 = ap_Event->
GetID1(0);
762 uint32_t id2 = ap_Event->
GetID2(0);
763 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
764 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
782 if (!headerFile.is_open())
784 Cerr(
"***** iDataFileSPECT::WriteHeader() -> Failed to open output header file '" <<
m_headerFileName <<
"' !" << endl);
790 headerFile <<
"Number of events: " <<
m_nbEvents << endl;
796 headerFile <<
"Data type: SPECT" << endl;
809 headerFile <<
"Projection angles: " <<
mp_angles[0];
814 bool global_distance_flag =
true;
820 global_distance_flag =
false;
823 if(global_distance_flag)
827 headerFile <<
"Distance camera surface to COR: " << mp_CORtoDetectorDistance[0];
828 for (
int p=1 ; p<
m_nbOfProjections ; p++) headerFile <<
", " << mp_CORtoDetectorDistance[p];
834 headerFile <<
"Isotope: " <<
m_isotope << endl;
841 headerFile <<
"Head rotation direction: " << rot_direction << endl;
859 FLTNB* p_angles = NULL;
860 FLTNB* p_CORtoDetectorDistance = NULL;
861 FLTNB p_pixSizeXY[2] ;
865 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.