58 FLTNB* p_angles = NULL;
59 FLTNB* p_CORtoDetectorDistance = NULL;
70 p_CORtoDetectorDistance,
76 Cerr(
"***** iDataFileSPECT::ReadSpecificInfoInHeader() -> Number of projections should be strictly positive !" << endl);
94 Cout(
" --> Provided projection angles | distance Center of Rotation (COR) to detector: " << endl);
104 Cerr(
"***** iDataFileSPECT::ReadSpecificInfoInHeader() -> Error while reading optional fields in the header data file !" << endl);
111 Cerr(
"***** iDataFileSPECT::ReadSpecificInfoInHeader() -> A problem occured while setting the isotope to oImageDimensionsAndQuantification !" << endl);
134 m_sizeEvent =
sizeof(uint32_t) + 2*
sizeof(uint32_t);
139 for (
int i=0 ; i<3; i++)
157 Cerr(
"***** iDataFileSPECT::ComputeSizeEvent() -> Unknown event mode !" << endl);
164 Cerr(
"***** iDataFileSPECT::ComputeSizeEvent() -> Error, the Event size in bytes should be >= 0 !" << endl;);
214 Cerr(
"*****iDataFileSPECT::PrepareDataFile() -> Error while trying to allocate memory for the Event object!" << endl);
232 else Cout(
" --> Correct for normalization" << endl);
244 else Cout(
" --> Correct for scatter events" << endl);
262 char* file_position = ap_buffer;
270 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
271 file_position +=
sizeof(uint32_t);
275 event->SetKind(*reinterpret_cast<uint8_t*>(file_position));
276 file_position +=
sizeof(uint8_t);
291 for (
int i=0; i<3; i++)
295 if (!
m_ignorePOIFlag)
event->SetPOI(i,*reinterpret_cast<FLTNBDATA*>(file_position));
300 event->SetID1(0, *reinterpret_cast<uint32_t*>(file_position));
301 file_position +=
sizeof(uint32_t);
303 event->SetID2(0, *reinterpret_cast<uint32_t*>(file_position));
304 file_position +=
sizeof(uint32_t);
313 event->
SetTimeInMs(*reinterpret_cast<uint32_t*>(file_position));
314 file_position +=
sizeof(uint32_t);
316 event->SetEventValue(0, *reinterpret_cast<FLTNBDATA*>(file_position));
331 event->SetID1(0, *reinterpret_cast<uint32_t*>(file_position));
332 file_position +=
sizeof(uint32_t);
334 event->SetID2(0, *reinterpret_cast<uint32_t*>(file_position));
335 file_position +=
sizeof(uint32_t);
353 Cerr(
"***** iDataFileSPECT::CheckSpecificParameters() -> Data type should be SPECT !'" << endl);
359 Cerr(
"***** iDataFileSPECT::CheckSpecificParameters() -> Number of projections not initialized (should be >0) !" << endl);
365 Cerr(
"***** iDataFileSPECT::CheckSpecificParameters() -> Projection angles not initialized !" << endl);
386 Cerr(
"----------------------------------------------------------------------------------------------------------------------------------------" << endl);
387 Cerr(
"***** iDataFileSPECT::CheckFileSizeConsistency() -> Datafile size is not consistent with the information provided by the user/datafile !" << endl);
389 Cerr(
" --> Actual size: "<< sizeInBytes << endl << endl);
390 Cerr(
" ADDITIONAL INFORMATION ABOUT THE DATAFILE INITIALIZATION" << endl);
392 else Cerr(
" --> No information about the kind of coincidences in the data" << endl);
394 else Cerr(
" --> No normalization correction term in the data" << endl);
396 else Cerr(
" --> No scatter correction term in the data" << endl);
398 Cerr(
" --> Number of bins are equal to " <<
mp_nbOfBins[0] <<
"," <<
mp_nbOfBins[1] <<
" for transaxial,axial axis respectively" << endl);
405 Cerr(
"----------------------------------------------------------------------------------------------------------------------------------------" << endl);
412 Cout(
"------------------------------------------------- Datafile initialization -------------------------------------------------" << endl);
414 else Cout(
" --> No information about the kind of coincidences in the data" << endl);
416 else Cout(
" --> No normalization correction terms in the data" << endl);
418 else Cout(
" --> No scatter correction terms in the data" << endl);
420 Cout(
" --> Number of bins are equal to " <<
mp_nbOfBins[0] <<
"," <<
mp_nbOfBins[1] <<
" for transaxial,axial axis respectively" << endl);
427 Cout(
"---------------------------------------------------------------------------------------------------------------------------" << endl);
447 Cerr(
"***** iDataFileSPECT::CheckSpecificConsistencyWithAnotherDatafile() -> Isotopes are inconsistent !" << endl);
453 Cerr(
"***** iDataFileSPECT::CheckSpecificConsistencyWithAnotherDatafile() -> Event kind flags are inconsistent !" << endl);
459 Cerr(
"***** iDataFileSPECT::CheckSpecificConsistencyWithAnotherDatafile() -> Normalization correction flags are inconsistent !" << endl);
465 Cerr(
"***** iDataFileSPECT::CheckSpecificConsistencyWithAnotherDatafile() -> Scatter correction flags are inconsistent !" << endl);
483 Cerr(
"***** iDataFileSPECT::InitAngles() -> Number of projection angles not initialized !'" << endl);
505 Cerr(
"***** iDataFileSPECT::InitAngles() -> Number of projection angles not initialized !'" << endl);
542 if(
m_verbose >=3)
Cout(
"iDataFileSPECT::PROJ_InitFile() ..." << endl);
563 m_headerFileName = path_name.append(img_name).append(
"_CstrProj").append(
".Cdh");
574 datafile_name.append(
"_").append(ss.str());
576 m2p_dataFile[th] =
new fstream( datafile_name.c_str(), ios::binary | ios::out | ios::trunc);
581 ofstream output_file(
m_dataFileName.c_str(), ios::out | ios::trunc);
608 #ifdef CASTOR_VERBOSE
610 if(
m_verbose>=4)
Cout(
"iDataFileSPECT::PROJ_WriteEvent() ..."<< endl);
618 Cerr(
"*****iDataFileSPECT::PROJ_WriteEvent() -> Error while trying to write projection datafile (list-mode)" << endl);
627 Cerr(
"*****iDataFileSPECT::PROJ_WriteEvent() -> Error while trying to write projection datafile (histogram)" << endl);
649 #ifdef CASTOR_VERBOSE
651 if(
m_verbose>=4)
Cout(
"iDataFileSPECT::PROJ_WriteHistoEvent() ..."<< endl);
658 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
672 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&norm_corr_factor),
sizeof(
FLTNB));
675 uint32_t id1 = ap_Event->
GetID1(0);
676 uint32_t id2 = ap_Event->
GetID2(0);
677 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
678 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
697 #ifdef CASTOR_VERBOSE
699 if(
m_verbose>=4)
Cout(
"iDataFileSPECT::PROJ_WriteListEvent() ..."<< endl);
706 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&time),
sizeof(uint32_t));
710 uint8_t event_kind = ap_Event->
GetKind();
711 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&event_kind),
sizeof(uint8_t));
723 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&norm_corr_factor),
sizeof(
FLTNB));
744 uint32_t id1 = ap_Event->
GetID1(0);
745 uint32_t id2 = ap_Event->
GetID2(0);
746 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id1),
sizeof(uint32_t));
747 m2p_dataFile[a_th]->write(reinterpret_cast<char*>(&id2),
sizeof(uint32_t));
769 if(
m_verbose>=3)
Cout(
"iDataFileSPECT::PROJ_WriteHeader() ..."<< endl);
780 headerFile <<
"Data mode:" <<
" " <<
m_dataMode << endl;
782 headerFile <<
"Data type: " <<
" " <<
"SPECT" << endl;
791 headerFile <<
"Scanner name:" <<
" " << p_scannermanager->
GetScannerName() << endl;
799 headerFile <<
"Projection angles:" <<
" ";
803 headerFile <<
", " << mp_angles[a];
809 for(
int h=1 ; h<
m_nbHeads ; h++) headerFile <<
"," << mp_CORtoDetectorDistance[h] << endl;
818 headerFile <<
"Isotope:" <<
" " <<
m_isotope << endl;
823 headerFile <<
"Head rotation direction:" <<
" " << rot_direction << endl;
844 if(
m_verbose>=3)
Cout(
"iDataFileSPECT::PROJ_GetScannerSpecificParameters() ..."<< endl);
850 FLTNB* p_angles = NULL;
851 FLTNB* p_CORtoDetectorDistance = NULL;
852 FLTNB p_pixSizeXY[2] ;
857 Cerr(
"*****iDataFileSPECT::PROJ_GetScannerSpecificParameters() -> An error occurred while trying to get SPECT geometric parameters from the scanner object !" << endl);
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 CheckSpecificConsistencyWithAnotherDatafile(vDataFile *ap_Datafile)
Check consistency between 'this' and the provided datafile, for specific characteristics.
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)
Inherit from iEventSPECT. Class for SPECT histogram mode events.
int PROJ_WriteListEvent(iEventListSPECT *ap_Event, int a_th)
Write a SPECT list-mode event.
static sOutputManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
int GetSPECTSpecificParameters(uint16_t *ap_nbOfProjections, uint16_t *ap_nbHeads, 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. ...
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_WriteEvent(vEvent *ap_Event, int a_th)
Write event according to the chosen type of data.
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
Inherit from vDataFile. Class that manages the reading of a SPECT input file (header + data)...
vEvent * GetEventFromBuffer(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
FLTNB * mp_CORtoDetectorDistance
const string & GetBaseName()
void SetTimeInMs(uint32_t a_value)
Set the timestamp of the Event.
int PROJ_WriteHistoEvent(iEventHistoSPECT *ap_Event, int a_th)
Write a SPECT histogram event.
Mother class for the Event objects.
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.
#define DEBUG_VERBOSE(IGNORED1, IGNORED2)
FLTNB m_calibrationFactor
int PROJ_WriteHeader()
Generate a header file according to the projection and data output informations. Used by Projection...
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.