CASToR  2.0
Tomographic Reconstruction (PET/SPECT/CT)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
oProjectorManager.cc
Go to the documentation of this file.
1 /*
2 This file is part of CASToR.
3 
4  CASToR is free software: you can redistribute it and/or modify it under the
5  terms of the GNU General Public License as published by the Free Software
6  Foundation, either version 3 of the License, or (at your option) any later
7  version.
8 
9  CASToR is distributed in the hope that it will be useful, but WITHOUT ANY
10  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  details.
13 
14  You should have received a copy of the GNU General Public License along with
15  CASToR (in file GNU_GPL.TXT). If not, see <http://www.gnu.org/licenses/>.
16 
17 Copyright 2017-2018 all CASToR contributors listed below:
18 
19  --> current contributors: Thibaut MERLIN, Simon STUTE, Didier BENOIT, Claude COMTAT, Marina FILIPOVIC, Mael MILLARDET
20  --> past contributors: Valentin VIELZEUF
21 
22 This is CASToR version 2.0.
23 */
24 
31 #include "oProjectorManager.hh"
32 #include "sOutputManager.hh"
33 #include "sAddonManager.hh"
34 #include "iDataFilePET.hh"
35 
36 // =====================================================================
37 // ---------------------------------------------------------------------
38 // ---------------------------------------------------------------------
39 // =====================================================================
40 
42 {
43  // Scanner and image dimensions
44  mp_Scanner = NULL;
46  // Data file (used to get some info about TOF bins and POI)
47  mp_DataFile = NULL;
48  // TOF and POI options
49  m_applyTOF = false;
50  m_applyPOI = false;
51  m_nbTOFBins = -1;
52  // Computation strategy for projection lines
54  // Forward and backward options for projectors
55  m_optionsForward = "";
56  m_optionsBackward = "";
57  // Common options
58  m_optionsCommon = "";
59  // Forward and backward projectors
64  mp_ProjectorForward = NULL;
65  mp_ProjectorBackward = NULL;
68  m_useProjectorForward = false;
69  m_useProjectorBackward = false;
70  m_useMatchedProjectors = false;
71  // Forward and backward projection lines (as many as threads)
72  m2p_ProjectionLines = NULL;
73  // Verbosity
74  m_verbose = 0;
75  // Not checked yet
76  m_checked = false;
77  // Not initialized yet
78  m_initialized = false;
79  m_applyMask = false;
80  mp_mask = NULL;
81 }
82 
83 // =====================================================================
84 // ---------------------------------------------------------------------
85 // ---------------------------------------------------------------------
86 // =====================================================================
87 
89 {
90  // Go through the destructor only if the object was initialized
91  if (m_initialized)
92  {
93  // Delete projection lines
95  {
97  if (m2p_ProjectionLines[th]) delete m2p_ProjectionLines[th];
98  delete[] m2p_ProjectionLines;
99  }
100  // Delete projectors
103  if (m_applyMask) delete[] mp_mask;
105  {
108  }
109  }
110 }
111 
112 // =====================================================================
113 // ---------------------------------------------------------------------
114 // ---------------------------------------------------------------------
115 // =====================================================================
116 
118 {
119  // Case for a vProjector
121  // Case for a system matrix
123 }
124 
125 // =====================================================================
126 // ---------------------------------------------------------------------
127 // ---------------------------------------------------------------------
128 // =====================================================================
129 
131 {
132  // Case for a vProjector
134  // Case for a system matrix
136 }
137 
138 // =====================================================================
139 // ---------------------------------------------------------------------
140 // ---------------------------------------------------------------------
141 // =====================================================================
142 
144 {
145  // Check scanner
146  if (mp_Scanner==NULL)
147  {
148  Cerr("***** oProjectorManager::CheckParameters() -> No scanner provided !" << endl);
149  return 1;
150  }
151  // Check image dimensions
153  {
154  Cerr("***** oProjectorManager::CheckParameters() -> No image dimensions provided !" << endl);
155  return 1;
156  }
157  // Check data file
158  if (mp_DataFile==NULL)
159  {
160  Cerr("***** oProjectorManager::CheckParameters() -> No data file provided !" << endl);
161  return 1;
162  }
163  // Check computation strategy
167  {
168  Cerr("***** oProjectorManager::CheckParameters() -> Unknown computation strategy provided !" << endl);
169  return 1;
170  }
171  // Check forward projector options
172  if (m_optionsForward=="")
173  {
174  Cerr("***** oProjectorManager::CheckParameters() -> No forward projector options provided !" << endl);
175  return 1;
176  }
177  // Check backward projector options
178  if (m_optionsBackward=="")
179  {
180  Cerr("***** oProjectorManager::CheckParameters() -> No backward projector options provided !" << endl);
181  return 1;
182  }
183  // Check verbosity
184  if (m_verbose<0)
185  {
186  Cerr("***** oProjectorManager::CheckParameters() -> Wrong verbosity level provided !" << endl);
187  return 1;
188  }
189  // Normal end
190  m_checked = true;
191  return 0;
192 }
193 
194 // =====================================================================
195 // ---------------------------------------------------------------------
196 // ---------------------------------------------------------------------
197 // =====================================================================
198 
199 int oProjectorManager::CheckSPECTAttenuationCompatibility(const string& a_pathToAttenuationImage)
200 {
201  // In SPECT with attenuation correction, there are some requirements with the projection method
202  if (a_pathToAttenuationImage!="" && mp_DataFile->GetDataType()==TYPE_SPECT)
203  {
204  // Check that the projection line strategy is not IMAGE_COMPUTATION_STRATEGY (this is not compatible)
205  // Note that we cannot do this check in the oProjectionLine directly, because we cannot now in advance
206  // that the projection method including attenuation will be used...
208  {
209  Cerr("***** oProjectorManager::CheckSPECTAttenuationCompatibility() -> The image-computation strategy of the oProjectionLine is not compatible with SPECT attenuation correction !");
210  return 1;
211  }
212  // Check that the forward projector is compatible with SPECT with attenuation correction
214  {
215  Cerr("***** oProjectorManager::CheckSPECTAttenuationCompatibility() -> The forward projector is not compatible with SPECT attenuation correction !" << endl);
216  return 1;
217  }
218  // Check that the backward projector is compatible with SPECT with attenuation correction
220  {
221  Cerr("***** oProjectorManager::CheckSPECTAttenuationCompatibility() -> The backward projector is not compatible with SPECT attenuation correction !" << endl);
222  return 1;
223  }
224  }
225  // End
226  return 0;
227 }
228 
229 // =====================================================================
230 // ---------------------------------------------------------------------
231 // ---------------------------------------------------------------------
232 // =====================================================================
233 
235 {
236  // Forbid initialization without check
237  if (!m_checked)
238  {
239  Cerr("***** oProjectorManager::Initialize() -> Must call CheckParameters() before Initialize() !" << endl);
240  return 1;
241  }
242 
243  // Verbose
244  if (m_verbose>=1) Cout("oProjectorManager::Initialize() -> Initialize projectors and projection lines" << endl);
245 
246  // -------------------------------------------------------------------
247  // Manage TOF
248  // -------------------------------------------------------------------
249 
250  FLTNB tof_resolution = -1.;
251  FLTNB tof_bin_size = -1.;
252  // TOF is only for PET data
254  {
255  // Cast the datafile pointer
256  iDataFilePET* p_pet_datafile = (dynamic_cast<iDataFilePET*>(mp_DataFile));
257  // Case of TOF information in the datafile
258  if (p_pet_datafile->GetTOFInfoFlag())
259  {
260  // Case where it is asked to ignore TOF info
261  if (p_pet_datafile->GetIgnoreTOFFlag())
262  {
264  m_nbTOFBins = 1;
265  }
266  // Otherwise, we use TOF
267  else
268  {
269  // Get the TOF resolution from the data file, if we apply TOF
270  tof_resolution = p_pet_datafile->GetTOFResolution();
271  // Get the TOF bin size in ps, if we apply TOF
272  tof_bin_size = p_pet_datafile->GetTOFBinSize();
273  // For list-mode data
275  {
276  m_nbTOFBins = 1;
278  }
279  // For histogram data
280  else
281  {
283  // Get the number of TOF bins from the data file
284  m_nbTOFBins = p_pet_datafile->GetNbTOFBins();
285  }
286  }
287  // Verbose
289  {
290  if (m_applyTOF==USE_NOTOF) Cout(" --> Do not use the TOF projections" << endl);
291  else if (m_applyTOF==USE_TOFBIN) Cout(" --> Use TOF projector for histogram data" << endl);
292  else if (m_applyTOF==USE_TOFPOS) Cout(" --> Use TOF projector for listmode data" << endl);
293  }
294  }
295  // Case no TOF
296  else
297  {
299  m_nbTOFBins = 1;
300  }
301  }
302  // Not PET data
303  else
304  {
305  m_nbTOFBins = 1;
307  }
308 
309  // -------------------------------------------------------------------
310  // Manage POI
311  // -------------------------------------------------------------------
312 
313  // Case we have POI and it is not asked to ignore the information
315  {
316  // Cannot use POI with histogram mode
318  {
319  Cerr("***** oProjectorManager::Initialize() -> POI information has no sense with histogram data !" << endl);
320  return 1;
321  }
322  // Apply POI
323  m_applyPOI = true;
324  }
325  // Case we do not use POI
326  else m_applyPOI = false;
327  // Get POI resolution from the data file
328  FLTNB* poi_resolution = mp_DataFile->GetPOIResolution();
329 
330  // -------------------------------------------------------------------
331  // Initialize projectors and or system matrix
332  // -------------------------------------------------------------------
333 
334  // Compare projector options to know if we use matched ones for forward and backward operations
336  else m_useMatchedProjectors = false;
337 
338  // Parse projector options and initialize them
340  {
341  Cerr("***** oProjectorManager::Initialize() -> A problem occured while parsing projector options and initializing it !" << endl);
342  return 1;
343  }
344 
345  // -------------------------------------------------------------------
346  // If compression, loaded SM and some projectors are not compatible
347  // -------------------------------------------------------------------
348 
349  // Compression can currently occur only in PET
351  {
352  // Check if there is some compression
353  if ( (dynamic_cast<iDataFilePET*>(mp_DataFile))->GetMaxNumberOfLinesPerEvent() > 1 )
354  {
355  // It is not compatible with loaded forward system matrices
357  {
358  Cerr("***** oProjectorManager::Initialize() -> Cannot use a loaded forward system matrix with compression in the datafile !" << endl);
359  return 1;
360  }
361  // It is not compatible with forward projectors declared as not compatible !
363  {
364  Cerr("***** oProjectorManager::Initialize() -> Selected forward projector '" << m_forwardProjectorName << "' is not compatible with compression in the datafile !" << endl);
365  return 1;
366  }
367  // It is not compatible with loaded backward system matrices
369  {
370  Cerr("***** oProjectorManager::Initialize() -> Cannot use a loaded backward system matrix with compression in the datafile !" << endl);
371  return 1;
372  }
373  // It is not compatible with backward projectors declared as not compatible !
375  {
376  Cerr("***** oProjectorManager::Initialize() -> Selected backward projector '" << m_backwardProjectorName << "' is not compatible with compression in the datafile !" << endl);
377  return 1;
378  }
379  }
380  }
381 
382  // -------------------------------------------------------------------
383  // Transfer the mask to projectors
384  // -------------------------------------------------------------------
385 
386  if (m_applyMask)
387  {
390  }
391 
392 
393  // -------------------------------------------------------------------
394  // Initialize projection lines
395  // -------------------------------------------------------------------
396 
397  // Initialize as many projection lines as threads
400  {
405  m2p_ProjectionLines[th]->SetTOFBinSize(tof_bin_size);
406  m2p_ProjectionLines[th]->SetTOFResolution(tof_resolution);
407  m2p_ProjectionLines[th]->SetPOIResolution(poi_resolution);
414  {
415  Cerr("***** oProjectorManager::Initialize() -> An error occured while checking parameters of an oProjectionLine !" << endl);
416  return 1;
417  }
418  if (m2p_ProjectionLines[th]->Initialize())
419  {
420  Cerr("***** oProjectorManager::Initialize() -> An error occured while initializing an oProjectionLine !" << endl);
421  return 1;
422  }
423  }
424 
425  // Normal end
426  m_initialized = true;
427  return 0;
428 }
429 
430 // =====================================================================
431 // ---------------------------------------------------------------------
432 // ---------------------------------------------------------------------
433 // =====================================================================
434 
436 {
437  string list_options = "";
438  string file_options = "";
439 
440  // This is for the automatic initialization of the projectors
441  typedef vProjector *(*maker_projector) ();
442 
443  // ---------------------------------------------------------------------------------------------------
444  // Manage forward projector
445  // ---------------------------------------------------------------------------------------------------
446 
447  // ______________________________________________________________________________
448  // Get the projector name in the options and isolate the real projector's options
449 
450  // Search for a colon ":", this indicates that a configuration file is provided after the projector name
451  size_t colon = m_optionsForward.find_first_of(":");
452  size_t comma = m_optionsForward.find_first_of(",");
453 
454  // Case 1: we have a colon
455  if (colon!=string::npos)
456  {
457  // Get the projector name before the colon
458  m_forwardProjectorName = m_optionsForward.substr(0,colon);
459  // Get the configuration file after the colon
460  file_options = m_optionsForward.substr(colon+1);
461  // List of options is empty
462  list_options = "";
463  }
464  // Case 2: we have a comma
465  else if (comma!=string::npos)
466  {
467  // Get the projector name before the first comma
468  m_forwardProjectorName = m_optionsForward.substr(0,comma);
469  // Get the list of options after the first comma
470  list_options = m_optionsForward.substr(comma+1);
471  // Configuration file is empty
472  file_options = "";
473  }
474  // Case 3: no colon and no comma (a single projector name)
475  else
476  {
477  // Get the projector name
479  // List of options is empty
480  list_options = "";
481  // Build the default configuration file
482  file_options = sOutputManager::GetInstance()->GetPathToConfigDir() + "/projector/" + m_forwardProjectorName + ".conf";
483  }
484 
485  // ______________________________________________________________________________
486  // Case 1: projector is equal to keyword 'matrix', then use a system matrix
488  {
489  mp_ProjectorForward = NULL;
490  m_useProjectorForward = false;
492  // TODO: put all these limitations into a dedicated function from oSystemMatrix
493  // TODO: forbid TOF in PET with system matrix
494  // TODO: forbid simultaneous bed reconstruction with system matrix
495  // TODO: forbid image offset with system matrix
496  Cerr("***** oProjectorManager::ParseOptionsAndInitializeProjectors() -> Loading of custom system matrices is not yet implemented !" << endl);
497  return 1;
498  }
499  // ______________________________________________________________________________
500  // Case 2: on-the-fly projector
501  else
502  {
503  // Unset system matrix
504  mp_SystemMatrixForward = NULL;
505  m_useSystemMatrixForward = false;
506  // Set projector on
507  m_useProjectorForward = true;
508  // Get projector's listfrom addon manager
509  std::map <string,maker_projector> list = sAddonManager::GetInstance()->mp_listOfProjectors;
510  // Create the projector
512  else
513  {
514  Cerr("***** oProjectorManager::ParseOptionsAndInitializeProjectors() -> Projector '" << m_forwardProjectorName << "' does not exist !" << endl);
515  return 1;
516  }
517  // Set parameters
520  {
521  Cerr("***** oProjectorManager::ParseOptionsAndInitializeProjectors() -> A problem occured while setting the image dimensions of the forward projector !" << endl);
522  return 1;
523  }
527  // Provide common options list
529  {
530  Cerr("***** oProjectorManager::ParseOptionsAndInitializeProjectors() -> A problem occured while parsing and reading forward projector's common options !" << endl);
531  return 1;
532  }
533  // Provide configuration file if any
534  if (file_options!="" && mp_ProjectorForward->ReadConfigurationFile(file_options))
535  {
536  Cerr("***** oProjectorManager::ParseOptionsAndInitializeProjectors() -> A problem occured while parsing and reading forward projector's configuration file !" << endl);
537  return 1;
538  }
539  // Provide options if any
540  if (list_options!="" && mp_ProjectorForward->ReadOptionsList(list_options))
541  {
542  Cerr("***** oProjectorManager::ParseOptionsAndInitializeProjectors() -> A problem occured while parsing and reading forward projector's options !" << endl);
543  return 1;
544  }
545  // Check parameters
547  {
548  Cerr("***** oProjectorManager::ParseOptionsAndInitializeProjectors() -> A problem occured while checking forward projector parameters !" << endl);
549  return 1;
550  }
551  // Initialize the projector
553  {
554  Cerr("***** oProjectorManager::ParseOptionsAndInitializeProjectors() -> A problem occured while initializing the forward projector !" << endl);
555  return 1;
556  }
557  }
558 
559  // ---------------------------------------------------------------------------------------------------
560  // Manage backward projector
561  // ---------------------------------------------------------------------------------------------------
562 
563  // If options are the same, then forward and backward are the same
565  {
566  // In this case, matched projectors
571  }
572  // Else, unmatched projectors
573  else
574  {
575  // ______________________________________________________________________________
576  // Get the projector name in the options and isolate the real projector's options
577 
578  // Search for a colon ":", this indicates that a configuration file is provided after the projector name
579  colon = m_optionsBackward.find_first_of(":");
580  comma = m_optionsBackward.find_first_of(",");
581 
582  // Case 1: we have a colon
583  if (colon!=string::npos)
584  {
585  // Get the projector name before the colon
586  m_backwardProjectorName = m_optionsBackward.substr(0,colon);
587  // Get the configuration file after the colon
588  file_options = m_optionsBackward.substr(colon+1);
589  // List of options is empty
590  list_options = "";
591  }
592  // Case 2: we have a comma
593  else if (comma!=string::npos)
594  {
595  // Get the projector name before the first comma
596  m_backwardProjectorName = m_optionsBackward.substr(0,comma);
597  // Get the list of options after the first comma
598  list_options = m_optionsBackward.substr(comma+1);
599  // Configuration file is empty
600  file_options = "";
601  }
602  // Case 3: no colon and no comma (a single projector name)
603  else
604  {
605  // Get the projector name
607  // List of options is empty
608  list_options = "";
609  // Build the default configuration file
610  file_options = sOutputManager::GetInstance()->GetPathToConfigDir() + "/projector/" + m_backwardProjectorName + ".conf";
611  }
612 
613  // ______________________________________________________________________________
614  // Case 1: projector is equal to keyword 'matrix', then use a system matrix
616  {
617  mp_ProjectorBackward = NULL;
618  m_useProjectorBackward = false;
620  // TODO: put all these limitations into a dedicated function from oSystemMatrix
621  // TODO: forbid TOF in PET with system matrix
622  // TODO: forbid simultaneous bed reconstruction with system matrix
623  // TODO: forbid image offset with system matrix
624  Cerr("***** oProjectorManager::ParseOptionsAndInitializeProjectors() -> Loading of custom system matrices is not yet implemented !" << endl);
625  return 1;
626  }
627  // ______________________________________________________________________________
628  // Case 2: on-the-fly projector
629  else
630  {
631  // Unset system matrix
634  // Set projector on
635  m_useProjectorBackward = true;
636  // Get projector's listfrom addon manager
637  std::map <string,maker_projector> list = sAddonManager::GetInstance()->mp_listOfProjectors;
638  // Create the projector
640  else
641  {
642  Cerr("***** oProjectorManager::ParseOptionsAndInitializeProjectors() -> Projector '" << m_backwardProjectorName << "' does not exist !" << endl);
643  return 1;
644  }
645  // Set parameters
648  {
649  Cerr("***** oProjectorManager::ParseOptionsAndInitializeProjectors() -> A problem occured while setting the image dimensions of the backward projector !" << endl);
650  return 1;
651  }
655  // Provide common options list
657  {
658  Cerr("***** oProjectorManager::ParseOptionsAndInitializeProjectors() -> A problem occured while parsing and reading backward projector's common options !" << endl);
659  return 1;
660  }
661  // Provide configuration file if any
662  if (file_options!="" && mp_ProjectorBackward->ReadConfigurationFile(file_options))
663  {
664  Cerr("***** oProjectorManager::ParseOptionsAndInitializeProjectors() -> A problem occured while parsing and reading backward projector's configuration file !" << endl);
665  return 1;
666  }
667  // Provide options if any
668  if (list_options!="" && mp_ProjectorBackward->ReadOptionsList(list_options))
669  {
670  Cerr("***** oProjectorManager::ParseOptionsAndInitializeProjectors() -> A problem occured while parsing and reading backward projector's options !" << endl);
671  return 1;
672  }
673  // Check parameters
675  {
676  Cerr("***** oProjectorManager::ParseOptionsAndInitializeProjectors() -> A problem occured while checking backward projector parameters !" << endl);
677  return 1;
678  }
679  // Initialize the projector
681  {
682  Cerr("***** oProjectorManager::ParseOptionsAndInitializeProjectors() -> A problem occured while initializing backward projector !" << endl);
683  return 1;
684  }
685  }
686  }
687 
688  // Normal end
689  return 0;
690 }
691 
692 // =====================================================================
693 // ---------------------------------------------------------------------
694 // ---------------------------------------------------------------------
695 // =====================================================================
696 
698 {
699  // Set the sensitivity ON in the projectors, if used
702  // If the data file is a list-mode, then deactivate the TOF usage in the projector
704  {
707  }
708 }
709 
710 // =====================================================================
711 // ---------------------------------------------------------------------
712 // ---------------------------------------------------------------------
713 // =====================================================================
714 
716 {
717  // Set the sensitivity OFF in the projectors, if used
720  // Reset TOF and POI parameters to original values
722  {
725  }
727  {
730  }
731 }
732 
733 // =====================================================================
734 // ---------------------------------------------------------------------
735 // ---------------------------------------------------------------------
736 // =====================================================================
737 
739 {
740  // Apply it to all projection lines (only if more than one bed position)
744 }
745 
746 // =====================================================================
747 // ---------------------------------------------------------------------
748 // ---------------------------------------------------------------------
749 // =====================================================================
750 
752 {
753  #ifdef CASTOR_DEBUG
754  if (!m_initialized)
755  {
756  Cerr("***** oProjectorManager::ComputeProjectionLine() -> Called while not initialized !" << endl);
757  return NULL;
758  }
759  #endif
760 
762 
763  // Get the list of indices
764  uint32_t *index1 = ap_Event->GetEventID1();
765  uint32_t *index2 = ap_Event->GetEventID2();
766  int nb_indices = ap_Event->GetNbLines();
767 
768  // Clean the projection line
769  m2p_ProjectionLines[a_th]->Reset();
770 
771  // With list-mode data, we may need POI and/or TOF measurements
772  if (ap_Event->GetDataMode()==MODE_LIST)
773  {
774  // Set POI measurement
775  if (m_applyPOI)
776  {
777  // For PET
778  if (ap_Event->GetDataType()==TYPE_PET)
779  {
780  // Have to dynamic_cast the event into a iEventPETList to access the GetPOI functions
781  m2p_ProjectionLines[a_th]->SetPOI1((dynamic_cast<iEventListPET*>(ap_Event))->GetPOI1());
782  m2p_ProjectionLines[a_th]->SetPOI2((dynamic_cast<iEventListPET*>(ap_Event))->GetPOI2());
783  }
784  // For SPECT
785  else if (ap_Event->GetDataType()==TYPE_SPECT)
786  {
787  // By convention in SPECT, the second end point is in the camera (the first one being outside)
788  //m2p_ProjectionLines[a_th]->SetPOI2((dynamic_cast<iEventListModeSPECT*>(ap_Event))->GetPOI());
789  }
790  // For CT
791  else if (ap_Event->GetDataType()==TYPE_CT)
792  {
793  ;
794  }
795  }
796  // Set TOF measurement (only for PET obviously)
797  if (m_applyTOF && ap_Event->GetDataType()==TYPE_PET)
798  {
799  // Have to dynamic_cast the event into a iEventPETList to access the GetTOF function
800  m2p_ProjectionLines[a_th]->SetTOFMeasurement((dynamic_cast<iEventListPET*>(ap_Event))->GetTOFMeasurement());
801  }
802  }
803 
804  // Project forward (and also compute line length)
805  int return_value = 0;
807  return_value = mp_ProjectorForward->Project( FORWARD, m2p_ProjectionLines[a_th], index1, index2, nb_indices );
808  else if (m_useSystemMatrixForward)
809  return_value = mp_SystemMatrixForward->Project( FORWARD, m2p_ProjectionLines[a_th], index1, index2, nb_indices );
810  if (return_value)
811  {
812  Cerr("***** oProjectorManager::ComputeProjectionLine() -> A problem occured while forward projecting an event !" << endl);
813  return NULL;
814  }
815 
816  // Project backward
818  {
819  // Then project
821  return_value = mp_ProjectorBackward->Project( BACKWARD, m2p_ProjectionLines[a_th], index1, index2, nb_indices );
822  else if (m_useSystemMatrixBackward)
823  return_value = mp_SystemMatrixBackward->Project( BACKWARD, m2p_ProjectionLines[a_th], index1, index2, nb_indices);
824  if (return_value)
825  {
826  Cerr("***** oProjectorManager::ComputeProjectionLine() -> A problem occured while backward projecting an event !" << endl);
827  return NULL;
828  }
829  }
830 
831  // Return the line
832  return m2p_ProjectionLines[a_th];
833 }
834 
835 // =====================================================================
836 // ---------------------------------------------------------------------
837 // ---------------------------------------------------------------------
838 // =====================================================================
840 {
842 
843  if (mp_mask!=NULL)
844  {
845  Cerr("***** oProjectorManager::ProcessAndSetMask() -> Mask already initialized !" << endl);
846  return 1;
847  }
848 
851  {
852  mp_mask[v] = (ap_maskImage[v]>0.);
853  }
854  m_applyMask = true;
855 
856  return 0;
857 }
oProjectionLine ** m2p_ProjectionLines
#define VERBOSE_DEBUG_EVENT
bool GetTOFInfoFlag()
#define MODE_HISTOGRAM
Definition: vDataFile.hh:59
#define TYPE_PET
Definition: vDataFile.hh:74
#define IMAGE_COMPUTATION_STRATEGY
#define MODE_LIST
Definition: vDataFile.hh:57
void SetMask(bool *ap_mask)
Set a mask for voxels.
Definition: vProjector.hh:332
void SetThreadNumber(int a_threadNumber)
This function is used to set the thread number of this particular line.
#define FLTNB
Definition: gVariables.hh:81
int GetDataType()
Definition: vEvent.hh:126
void SetImageDimensionsAndQuantification(oImageDimensionsAndQuantification *ap_ImageDimensionsAndQuantification)
This function is used to set the pointer to the oImageDimensionsAndQuantification in use...
void SetScanner(vScanner *ap_Scanner)
Set the pointer to the scanner in use.
Definition: vProjector.hh:285
void SetMatchedProjectors(bool a_UseMatchedProjectors)
This function is used to set the boolean that says if we use matched projectors.
int Initialize()
A function used to initialize the manager and the projectors or system matrices it manages...
FLTNB GetBedPosition(int a_bedIndex)
Get the bed position associated to a bed index.
uint32_t * GetEventID2()
Definition: vEvent.hh:120
bool GetPOIInfoFlag()
Definition: vDataFile.hh:386
This class is designed to generically described any on-the-fly projector.
Definition: vProjector.hh:76
bool GetCompatibilityWithSPECTAttenuationCorrection()
int Initialize()
A public function used to initialize the projector.
Definition: vProjector.cc:228
int Project(int a_direction, oProjectionLine *ap_ProjectionLine, uint32_t *ap_index1, uint32_t *ap_index2, int a_nbIndices)
A function use to computed the projection elements with respect to the provided parameters.
Definition: vProjector.cc:263
oProjectorManager()
The constructor of oProjectorManager.
void SetSensitivityModeOff()
Say that the projector will no longer be used to compute the global sensitivity.
#define ADAPTATIVE_LIST_COMPUTATION_STRATEGY
static sOutputManager * GetInstance()
Instanciate the singleton object and Initialize member variables if not already done, return a pointer to this object otherwise.
#define TYPE_SPECT
Definition: vDataFile.hh:76
#define TYPE_CT
Definition: vDataFile.hh:78
Declaration of class iDataFilePET.
bool GetCompatibilityWithSPECTAttenuationCorrection()
Definition: vProjector.hh:319
int GetDataMode()
Definition: vEvent.hh:132
void SetApplyTOF(int a_applyTOF)
Set the TOF mode.
Definition: vProjector.hh:299
static sAddonManager * GetInstance()
int ReadCommonOptionsList(const string &a_optionsList)
This function is used to read options common to all projectors given as a string. ...
Definition: vProjector.cc:147
oSystemMatrix * mp_SystemMatrixBackward
void SetVerbose(int a_verbose)
Set the verbose level.
Definition: vProjector.hh:278
#define FIXED_LIST_COMPUTATION_STRATEGY
~oProjectorManager()
The destructor of oProjectorManager.
#define Cerr(MESSAGE)
bool GetIgnorePOIFlag()
Definition: vDataFile.hh:392
void SetComputationStrategy(int a_computationStrategy)
This function is used to set the computation strategy in use.
int ParseOptionsAndInitializeProjectors()
Parse forward and backward projection options contained in the previously provided strings...
FLTNB GetTOFResolution()
const string & GetPathToConfigDir()
Return the path to the CASTOR config directory.
void SetSensitivityMode(bool a_sensitivityMode)
Set the sensitivity mode on or off.
Definition: vProjector.hh:292
int GetNbBeds()
Get the number of bed positions.
int CheckParameters()
A public function used to check the parameters settings.
Definition: vProjector.cc:170
oSystemMatrix * mp_SystemMatrixForward
virtual int ReadOptionsList(const string &a_optionsList)=0
A function used to read options from a list of options.
void SetNbTOFBins(int a_nbTOFBins)
This function is used to set the number of TOF bins in use.
virtual int ReadConfigurationFile(const string &a_configurationFile)=0
A function used to read options from a configuration file.
void SetPOI2(FLTNB *ap_POI2)
This function is used to set the POI of point 2.
oProjectionLine * ComputeProjectionLine(vEvent *ap_Event, int a_th)
This function is used to compute system matrix elements from the associated projector or pre-computed...
#define VERBOSE_NORMAL
FLTNB * GetPOIResolution()
Definition: vDataFile.hh:374
void Reset()
Reset length and all the voxel indices and weights tabs.
int GetDataType()
Definition: vDataFile.hh:311
int CheckParameters()
A function used to check the parameters settings.
void SetTOFBinSize(FLTNB a_TOFBinSize)
This function is used to set the size of a TOF bin in ps.
void ApplyBedOffset(int a_bed)
Compute the bed offset from the provided bed index and apply it to all projection lines...
void SetSensitivityModeOn()
Say that the projector will be used to compute the global sensitivity.
void SetVerbose(int a_verbose)
This function is used to set the verbose level.
std::map< string, maker_projector > mp_listOfProjectors
oImageDimensionsAndQuantification * mp_ImageDimensionsAndQuantification
bool GetCompatibilityWithCompression()
Definition: vProjector.hh:325
void SetBackwardProjector(vProjector *ap_Projector)
This function is used to set the pointer to the backward projector.
#define SYSTEM_MATRIX_KEYWORD
int ProcessAndSetMask(FLTNB *ap_maskImage)
Process and set the provided mask image for projector masking.
bool IsBackwardOperatorCompatibleWithSPECTAttenuationCorrection()
void SetPOI1(FLTNB *ap_POI1)
This function is used to set the POI of point 1.
#define INTNB
Definition: gVariables.hh:92
This class is designed to manage and store system matrix elements associated to a vEvent...
vProjector * mp_ProjectorBackward
vProjector * mp_ProjectorForward
void SetPOIResolution(FLTNB *ap_POIResolution)
This function is used to set the POI resolution along the 3 axes.
uint16_t GetNbLines()
Definition: vEvent.hh:94
void SetForwardProjector(vProjector *ap_Projector)
This function is used to set the pointer to the forward projector.
Declaration of class sOutputManager.
Mother class for the Event objects.
Definition: vEvent.hh:43
bool GetIgnoreTOFFlag()
FLTNB GetTOFBinSize()
int GetDataMode()
Definition: vDataFile.hh:300
INTNB GetNbVoxXYZ()
Get the total number of voxels.
void SetTOFResolution(FLTNB a_TOFResolution)
This function is used to set the TOF resolution in use.
int GetNbThreadsForProjection()
Get the number of threads used for projections.
#define USE_TOFPOS
Definition: vProjector.hh:50
int GetNbTOFBins()
void SetTOFMeasurement(FLTNB a_TOFMeasurement)
This function is used to set the TOF measurement associated to the line.
#define DEBUG_VERBOSE(IGNORED1, IGNORED2)
#define USE_NOTOF
Definition: vProjector.hh:52
uint32_t * GetEventID1()
Definition: vEvent.hh:114
int Project(int a_direction, oProjectionLine *ap_ProjectionLine, uint32_t *ap_index1, uint32_t *ap_index2, int a_nbIndices)
#define FORWARD
#define Cout(MESSAGE)
void SetApplyPOI(bool a_applyPOI)
Set the POI mode.
Definition: vProjector.hh:306
#define USE_TOFBIN
Definition: vProjector.hh:48
int CheckSPECTAttenuationCompatibility(const string &a_pathToAttenuationImage)
A function used to check specific compatibility with SPECT and attenuation correction.
Declaration of class oProjectorManager.
int SetImageDimensionsAndQuantification(oImageDimensionsAndQuantification *ap_ImageDimensionsAndQuantification)
Set the pointer to the image dimensions in use and copy locally some often use variables.
Definition: vProjector.cc:83
Inherit from vDataFile. Class that manages the reading of a PET input file (header + data)...
Definition: iDataFilePET.hh:44
Declaration of class sAddonManager.
bool IsForwardOperatorCompatibleWithSPECTAttenuationCorrection()
#define BACKWARD