Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//
//
/*!
\file
\ingroup projection
\ingroup SPECTGPU

\brief Back projection class using SPECTGPU's GPU implementation.

\author Daniel Deidda

\todo SPECTGPU limitations -

\todo STIR wrapper limitations -
*/
/*
Copyright (C) 2026, National Physical Laboratory
This file is part of STIR.

SPDX-License-Identifier: Apache-2.0

See STIR/LICENSE.txt for details
*/
#ifndef __stir_gpu_BackProjectorByBinSPECTGPU_h__
#define __stir_gpu_BackProjectorByBinSPECTGPU_h__

#include "stir/RegisteredParsingObject.h"
#include "stir/recon_buildblock/BackProjectorByBin.h"
#include "stir/recon_buildblock/SPECTGPU_projector/SPECTGPUHelper.h"

START_NAMESPACE_STIR

class DataSymmetriesForViewSegmentNumbers;

/*!
\ingroup projection
\brief Class for SPECTGPU's GPU back projector
*/
class BackProjectorByBinSPECTGPU : public RegisteredParsingObject<BackProjectorByBinSPECTGPU, BackProjectorByBin>
{
public:
//! Name which will be used when parsing a BackProjectorByBin object
static const char* const registered_name;

//! Default constructor calls reset_timers()
BackProjectorByBinSPECTGPU();

virtual ~BackProjectorByBinSPECTGPU();

/// Keymap
virtual void initialise_keymap();

//! Stores all necessary geometric info
/*!
If necessary, set_up() can be called more than once.
*/
virtual void set_up(const shared_ptr<const ProjDataInfo>& proj_data_info_ptr,
const shared_ptr<const DiscretisedDensity<3, float>>& density_info_sptr // TODO should be Info only
);

/// Back project
void back_project(const ProjData&, int subset_num = 0, int num_subsets = 1);

/// Get output
virtual void get_output(DiscretisedDensity<3, float>&) const;

/*! \brief tell the back projector to start accumulating into a new target.
This function has to be called before any back-projection is initiated.*/
virtual void start_accumulating_in_new_target();

/// Set verbosity
void set_verbosity(const bool verbosity) { _cuda_verbosity = verbosity; }

/// Set use truncation - truncate before forward
/// projection and after back projection
void set_use_truncation(const bool use_truncation) { _use_truncation = use_truncation; }

protected:
virtual void actual_back_project(const RelatedViewgrams<float>&,
const int min_axial_pos_num,
const int max_axial_pos_num,
const int min_tangential_pos_num,
const int max_tangential_pos_num);

virtual void actual_back_project(DiscretisedDensity<3, float>& stir_image,
const RelatedViewgrams<float>&,
const int min_axial_pos_num,
const int max_axial_pos_num,
const int min_tangential_pos_num,
const int max_tangential_pos_num);

private:
shared_ptr<DataSymmetriesForViewSegmentNumbers> _symmetries_sptr;
SPECTGPUHelper _helper;
int _cuda_device;
bool _cuda_verbosity;
std::vector<float> _np_sino;
bool _use_truncation;
};

END_NAMESPACE_STIR

#endif // __stir_gpu_BackProjectorByBinSPECTGPU_h__
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//
//

#ifndef __stir_gpu_ForwardProjectorByBinSPECTGPU_h__
#define __stir_gpu_ForwardProjectorByBinSPECTGPU_h__
/*!
\file
\ingroup projection
\ingroup SPECTGPU

\brief Forward projection class using SPECTGPU's GPU implementation.

\author Daniel Deidda

\todo SPECTGPU limitations -

\todo STIR wrapper limitations -

*/
/*
Copyright (C) 2026, National Physical Laboratory
This file is part of STIR.

SPDX-License-Identifier: Apache-2.0

See STIR/LICENSE.txt for details
*/

#include "stir/RegisteredParsingObject.h"
#include "stir/recon_buildblock/ForwardProjectorByBin.h"
#include "stir/recon_buildblock/SPECTGPU_projector/SPECTGPUHelper.h"

START_NAMESPACE_STIR

class ProjDataInMemory;
class DataSymmetriesForViewSegmentNumbers;

/*!
\ingroup projection
\brief Class for SPECTGPU's GPU forward projector.
*/
class ForwardProjectorByBinSPECTGPU : public RegisteredParsingObject<ForwardProjectorByBinSPECTGPU, ForwardProjectorByBin>
{
public:
//! Name which will be used when parsing a ForwardProjectorByBin object
static const char* const registered_name;

//! Default constructor calls reset_timers()
// inline
ForwardProjectorByBinSPECTGPU();

/// Constructor
virtual ~ForwardProjectorByBinSPECTGPU();

/// Keymap
virtual void initialise_keymap();

//! Stores all necessary geometric info
/*!
If necessary, set_up() can be called more than once.

Derived classes can assume that forward_project() will be called
with input corresponding to the arguments of the last call to set_up().

\warning there is currently no check on this.
\warning Derived classes have to call set_up from the base class.
*/
virtual void set_up(const shared_ptr<const ProjDataInfo>& proj_data_info_ptr,
const shared_ptr<const DiscretisedDensity<3, float>>& density_info_sptr // TODO should be Info only
);

/// Set input
virtual void set_input(const DiscretisedDensity<3, float>&);

/// Set verbosity
void set_verbosity(const bool verbosity) { _cuda_verbosity = verbosity; }

/// Set use truncation - truncate before forward
/// projection and after back projection
void set_use_truncation(const bool use_truncation) { _use_truncation = use_truncation; }

protected:
//! This virtual function has to be implemented by the derived class.
virtual void actual_forward_project(RelatedViewgrams<float>&,
const DiscretisedDensity<3, float>&,
const int min_axial_pos_num,
const int max_axial_pos_num,
const int min_tangential_pos_num,
const int max_tangential_pos_num);

virtual void actual_forward_project(RelatedViewgrams<float>& viewgrams,
const int min_axial_pos_num,
const int max_axial_pos_num,
const int min_tangential_pos_num,
const int max_tangential_pos_num);

protected:
struct cppdim3
{
int x;
int y;
int z;
};

int z_dim, y_dim, x_dim;
cppdim3 block_dim;
cppdim3 grid_dim;

private:
shared_ptr<ProjDataInMemory> _projected_data_sptr;
SPECTGPUHelper _helper;
int _cuda_device;
bool _cuda_verbosity;
bool _use_truncation;
};

END_NAMESPACE_STIR

#endif // __stir_gpu_ForwardProjectorByBinSPECTGPU_h__
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
//
/*
Copyright (C) 2026, National Physical Laboratory
This file is part of STIR.

SPDX-License-Identifier: Apache-2.0

See STIR/LICENSE.txt for details
*/
/*!
\file
\ingroup projection
\ingroup SPECTGPU

\brief Declares class stir::ProjectorByBinPairUsingSPECTGPU

\author Daniel Deidda

*/
#ifndef __stir_recon_buildblock_ProjectorByBinPairUsingSPECTGPU_h_
#define __stir_recon_buildblock_ProjectorByBinPairUsingSPECTGPU_h_

#include "stir/RegisteredParsingObject.h"
#include "stir/recon_buildblock/ProjectorByBinPair.h"

START_NAMESPACE_STIR

class Succeeded;
/*!
\ingroup projection
\brief A projector pair based on SPECTGPU projectors
*/
class ProjectorByBinPairUsingSPECTGPU
: public RegisteredParsingObject<ProjectorByBinPairUsingSPECTGPU, ProjectorByBinPair, ProjectorByBinPair>
{
private:
typedef RegisteredParsingObject<ProjectorByBinPairUsingSPECTGPU, ProjectorByBinPair, ProjectorByBinPair> base_type;

public:
//! Name which will be used when parsing a ProjectorByBinPair object
static const char* const registered_name;

//! Default constructor
ProjectorByBinPairUsingSPECTGPU();

/// Set verbosity
void set_verbosity(const bool verbosity);

/// Set use truncation - truncate before forward
/// projection and after back projection
void set_use_truncation(const bool use_truncation);

private:
void set_defaults();
void initialise_keymap();
bool post_processing();
bool _verbosity;
bool _use_truncation;
};

END_NAMESPACE_STIR

#endif // __stir_recon_buildblock_ProjectorByBinPairUsingSPECTGPU_h_
Loading