9 #include "iDataFileCT.hh" 53 FLTNB* p_angles = NULL;
65 Cerr(
"***** iDataFileCT::ReadSpecificInfoInHeader() -> Number of projections should be strictly positive !" << endl);
78 Cout(
" --> Provided projection angles" << endl);
87 Cerr(
"***** iDataFileCT::ReadSpecificInfoInHeader() -> Error while reading optional fields in the header data file !" << endl);
128 m_sizeEvent =
sizeof(uint32_t) + 2*
sizeof(uint32_t);
146 Cerr(
"***** iDataFileCT::ComputeSizeEvent() -> Unknown event mode !" << endl);
153 Cerr(
"***** iDataFileCT::ComputeSizeEvent() -> Error, the Event size in bytes should be >= 0 !" << endl;);
204 Cerr(
"*****iDataFileCT::PrepareDataFile() -> Error while trying to allocate memory for the Event object!" << endl);
223 else Cout(
" --> Correct for blank" << endl);
235 else Cout(
" --> Correct for scatter events" << endl);
253 char* file_position = ap_buffer;
261 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
262 file_position +=
sizeof(uint32_t);
266 event->SetKind(*reinterpret_cast<uint8_t*>(file_position));
267 file_position +=
sizeof(uint8_t);
282 event->SetID1(0, *reinterpret_cast<uint32_t*>(file_position));
283 file_position +=
sizeof(uint32_t);
285 event->SetID2(0, *reinterpret_cast<uint32_t*>(file_position));
286 file_position +=
sizeof(uint32_t);
295 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
296 file_position +=
sizeof(uint32_t);
298 event->SetEventValue(0, *reinterpret_cast<FLTNBDATA*>(file_position));
313 event->SetID1(0, *reinterpret_cast<uint32_t*>(file_position));
314 file_position +=
sizeof(uint32_t);
316 event->SetID2(0, *reinterpret_cast<uint32_t*>(file_position));
317 file_position +=
sizeof(uint32_t);
334 Cout(
"iDataFileCT::DescribeSpecific() -> Here is some specific content of the CT datafile" << endl);
340 else Cout(
" --> Detector rotation is undefined !!!" << endl);
356 Cerr(
"***** iDataFileCT::CheckSpecificParameters() -> Data type should be CT !'" << endl);
362 Cerr(
"***** iDataFileCT::CheckSpecificParameters() -> Number of projections not initialized (should be >0) !" << endl);
368 Cerr(
"***** iDataFileCT::CheckSpecificParameters() -> Projection angles not initialized !" << endl);
385 fstream* p_file =
new fstream(
m_dataFileName.c_str(), ios::binary| ios::in );
387 if (!p_file->is_open())
389 Cerr(
"***** iDataFilePET::CheckFileSizeConsistency() -> Failed to open input file '" <<
m_dataFileName.c_str() <<
"' !" << endl);
394 p_file->seekg(0, ios::end);
395 int64_t sizeInBytes = p_file->tellg();
402 Cerr(
"-------------------------------------------------------------------------------------------------------------------------------------" << endl);
403 Cerr(
"***** iDataFileCT::CheckFileSizeConsistency() -> DataFile size is not consistent with the information provided by the user/datafile !" << endl);
405 Cerr(
" --> Actual size: "<< sizeInBytes << endl << endl);
406 Cerr(
" ADDITIONAL INFORMATION ABOUT THE DATAFILE INITIALIZATION" << endl);
408 else Cerr(
" --> No information about the kind of events in the data" << endl);
410 else Cerr(
" --> No blank correction term in the data" << endl);
412 else Cerr(
" --> No scatter correction term in the data" << endl);
414 Cerr(
"----------------------------------------------------------------------------------------------------------------------------------------" << endl);
434 Cerr(
"***** iDataFileCT::CheckSpecificConsistencyWithAnotherDataFile() -> Event kind flags are inconsistent !" << endl);
440 Cerr(
"***** iDataFileCT::CheckSpecificConsistencyWithAnotherDataFile() -> Blank correction flags are inconsistent !" << endl);
446 Cerr(
"***** iDataFileCT::CheckSpecificConsistencyWithAnotherDataFile() -> Scatter correction flags are inconsistent !" << endl);
452 Cerr(
"***** iDataFileCT::CheckSpecificConsistencyWithAnotherDataFile() -> Data modes are inconsistent (list-mode or histogram) !" << endl);
470 Cerr(
"***** iDataFileCT::InitAngles() -> Number of projection angles not initialized !'" << endl);
518 datafile_name.append(
"_").append(ss.str());
520 m2p_dataFile[th] =
new fstream( datafile_name.c_str(), ios::binary | ios::out | ios::trunc);
525 ofstream output_file(
m_dataFileName.c_str(), ios::out | ios::trunc);
547 Cerr(
"*****iDataFileCT::WriteEvent() -> Error while trying to write projection datafile (list-mode)" << endl);
556 Cerr(
"*****iDataFileCT::WriteEvent() -> Error while trying to write projection datafile (histogram)" << endl);
577 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
594 uint32_t id1 = ap_Event->
GetID1(0);
595 uint32_t id2 = ap_Event->
GetID2(0);
596 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
597 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
615 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
619 uint8_t event_kind = ap_Event->
GetKind();
620 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&event_kind),
sizeof(uint8_t));
635 uint32_t id1 = ap_Event->
GetID1(0);
636 uint32_t id2 = ap_Event->
GetID2(0);
637 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
638 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
656 if (!headerFile.is_open())
658 Cerr(
"***** iDataFileCT::WriteHeader() -> Failed to open output header file '" <<
m_headerFileName <<
"' !" << endl);
664 headerFile <<
"Number of events: " <<
m_nbEvents << endl;
670 headerFile <<
"Data type: CT" << endl;
680 headerFile <<
"Projection angles: " <<
mp_angles[0];
689 headerFile <<
"Scanner rotation direction: " << rot_direction << endl;
707 FLTNB* p_angles = NULL;
711 Cerr(
"*****iDataFileCT::PROJ_GetScannerSpecificParameters() -> An error occurred while trying to get CT geometric parameters from the scanner object !" << endl);
uint32_t GetID2(int a_line)
This class is designed to be a mother virtual class for DataFile.
static sScannerManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
bool GetScatCorrectionFlag()
Simply return m_scatCorrectionFlag.
#define MODE_NORMALIZATION
int GetDetectorRotDirection()
Simply return m_detectorRotDirection.
int InitAngles(FLTNB *ap_angles)
int SetSpecificParametersFrom(vDataFile *ap_DataFile)
bool m_blankCorrectionFlag
Inherit from iEventCT. Class for CT list-mode events.
iDataFileCT()
iDataFileCT constructor. Initialize the member variables to their default values. ...
bool m_ignoreScatCorrectionFlag
uint16_t m_nbOfProjections
int ReadSpecificInfoInHeader(bool a_affectQuantificationFlag)
static sOutputManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
bool m_ignoreBlankCorrectionFlag
bool m_scatCorrectionFlag
int WriteHeader()
Generate a header file according to the data output information.
bool GetIgnoreNormCorrectionFlag()
Get the boolean that says if the normalization correction is ignored or not.
int WriteListEvent(iEventListCT *ap_Event, int a_th)
const string & GetPathName()
int ComputeSizeEvent()
Computation of the size of each event according to the mandatory/optional correction fields...
#define DEBUG_VERBOSE(IGNORED1, IGNORED2)
Singleton class that manages output writing on disk (images, sinograms, etc). It also manages loggi...
vEvent * GetEventSpecific(char *ap_buffer, int a_th)
Singleton class that Instantiate and initialize the scanner object.
vEvent ** m2p_BufferEvent
int PROJ_GetScannerSpecificParameters()
Get SPECT specific parameters for projections from the scanner object, through the scannerManager...
int CheckSpecificParameters()
Check parameters specific to CT data.
void DescribeSpecific()
Implementation of the pure virtual eponym function that simply prints info about the datafile...
Inherit from iEventCT. Class for CT histogram mode events.
int PROJ_InitFile()
Initialize the fstream objets for output writing as well as some other variables specific to the Proj...
bool GetBlankCorrectionFlag()
Simply return m_blankCorrectionFlag.
#define SPEC_TRANSMISSION
bool GetEventKindFlag()
Simply return m_eventKindFlag.
int m_detectorRotDirection
int CheckSpecificConsistencyWithAnotherDataFile(vDataFile *ap_DataFile)
uint16_t GetNbProjections()
const string & GetBaseName()
void SetTimeInMs(uint32_t a_value)
int WriteEvent(vEvent *ap_Event, int a_th=0)
Mother class for the Event objects.
Inherit from vDataFile. Class that manages the reading of a CT input file (header + data)...
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 m_calibrationFactor
uint32_t GetID1(int a_line)
string GetFileFromPath(const string &a_pathToFile)
Simply return the file from a path string passed in parameter.
#define VERBOSE_DEBUG_LIGHT
~iDataFileCT()
iDataFileCT destructor.
int GetCTSpecificParameters(uint16_t *ap_nbOfProjections, FLTNB *&ap_angles, int *ap_headRotDirection)
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...
int WriteHistoEvent(iEventHistoCT *ap_Event, int a_th)
int PrepareDataFile()
Store different kind of information inside arrays (data relative to specific correction as well as ba...
int CheckFileSizeConsistency()
This function is implemented in child classes Check if file size is consistent. ...
FLTNB GetEventValue(int a_bin)
#define VERBOSE_DEBUG_EVENT
oImageDimensionsAndQuantification * mp_ID