CTL  0.6.1
Computed Tomography Library
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
CTL::ProjectionDataView Class Reference

The ProjectionDataView class is a read-only wrapper for a reference to ProjectionData. More...

#include <projectiondataview.h>

Collaboration diagram for CTL::ProjectionDataView:
Collaboration graph
[legend]

Public Member Functions

 ProjectionDataView (const ProjectionData &projections, std::vector< uint > viewIds)
 Constructs a ProjectionDataView that references the projections with ids viewIds in projections.
 
 ProjectionDataView (const ProjectionData &projections)
 Constructs a ProjectionDataView that references all data of projections. More...
 
 ProjectionDataView ()
 Creates a ProjectionDataView that does not reference any data. More...
 
 ProjectionDataView (ProjectionData &&projections)=delete
 Deleted for safety reasons. Please refer to ProjectionDataView::dangling(ProjectionData&&).
 
 ProjectionDataView (ProjectionData &&projections, std::vector< uint > viewIds)=delete
 Deleted for safety reasons. Please refer to ProjectionDataView::dangling(ProjectionData&&,std::vector<uint>).
 
void resetData (const ProjectionData &projections, std::vector< uint > viewIds)
 Resets the data that is referenced by this instance to projections and the corresponding referenced view ids to viewIds. More...
 
void resetData (ProjectionData &&projections, std::vector< uint > viewIds)=delete
 Deleted for safety reasons. More...
 
const SingleViewDatafirst () const
 Returns a reference-to-const to the first view referenced by this instance.
 
const SingleViewDataview (uint i) const
 Returns a reference-to-const to i-th view referenced by this instance.
 
ProjectionData::Dimensions dimensions () const
 Returns the dimensions of the referenced data under consideration that only a subset of views may be referenced. More...
 
SingleViewData::Dimensions viewDimensions () const
 Returns the view dimensions (i.e. number of channels, rows, and modules) of the data referenced by this instance.
 
ProjectionData combined (const ModuleLayout &layout=ModuleLayout()) const
 Returns a ProjectionData copy of the data referenced by this instance that has been combined according to the ModuleLayout layout. More...
 
bool isValid () const
 Returns true if this instance references data. More...
 
float max () const
 Returns the maximum value that appears in all views that are referenced by this instance. More...
 
float min () const
 Returns the minimum value that appears in all views that are referenced by this instance. More...
 
uint nbViews () const
 Returns the number of views referenced by this instance.
 
std::vector< float > toVector () const
 Returns a concatenated vector of all pixel values in the referenced data. More...
 
bool containsView (uint viewId) const
 Returns true if this instance references the view with id viewId from the original dataset.
 
void shuffle ()
 Randomly shuffles the order in which the view ids referenced by this instance appear. More...
 
void shuffle (uint seed)
 Randomly shuffles the order in which the view ids referenced by this instance appear. More...
 
ProjectionDataView shuffled () const
 Returns a ProjectionDataView that references the same data but with a list of view ids whose order has been shuffled at random. More...
 
ProjectionDataView shuffled (uint seed) const
 Returns a ProjectionDataView that references the same data but with a list of view ids whose order has been shuffled at random. More...
 
ProjectionDataView subset (const std::vector< uint > &idsInView) const
 Returns a ProjectionDataView that references the subset with indices idsInView of the data referenced by this instance. More...
 
ProjectionDataView subset (uint pos=0, uint count=std::numeric_limits< uint >::max()) const
 Returns a ProjectionDataView that references a subset containing count views starting at view id pos of the data referenced by this instance. More...
 
const std::vector< uint > & viewIds () const
 Returns the view ids of the views that are referenced by this instance.
 
 operator ProjectionData () const
 Explicit conversion to ProjectionData; returns a copy of the data referenced by this instance. More...
 
ProjectionData dataCopy () const
 Returns a copy of the data referenced by this instance as ProjectionData. More...
 
bool operator== (const ProjectionDataView &other) const
 Returns true if this instance and other are equal. More...
 
bool operator!= (const ProjectionDataView &other) const
 Returns true if this instance and other are not equal. More...
 
ProjectionData operator+ (const ProjectionDataView &other) const
 Computes the sum of this instance and other and returns the result as ProjectionData.
 
ProjectionData operator- (const ProjectionDataView &other) const
 Computes the difference between this instance and other and returns the result as ProjectionData.
 
ProjectionData operator * (float factor) const
 Multiplies data referenced by this instance with factor and returns the result as ProjectionData.
 
ProjectionData operator/ (float divisor) const
 Divides data referenced by this instance by divisor and returns the result as ProjectionData.
 

Static Public Member Functions

static ProjectionDataView invalidView ()
 Creates a ProjectionDataView that does not reference any data. More...
 
static ProjectionDataView dangling (ProjectionData &&projections)
 Creates a ProjectionDataView on temporary (r-value) projections. More...
 
static ProjectionDataView dangling (ProjectionData &&projections, std::vector< uint > viewIds)
 Creates a ProjectionDataView on the projections with ids viewIds of temporary (r-value reference) data projections. More...
 

Private Member Functions

template<class Function >
void parallelExecution (const Function &f) const
 

Private Attributes

const ProjectionData_dataPtr = nullptr
 
std::vector< uint_viewIds
 

Detailed Description

The ProjectionDataView class is a read-only wrapper for a reference to ProjectionData.

This class provides a read-only view on an existent ProjectionData object. ProjectionDataView can be used to efficiently pass around read access to projections without memory overhead. An important feature of the view is its ability to manage subsets of the projections included in the original ProjectionData object. By providing a vector of projection indices that shall be included in the subset, a ProjectionDataView can be created and used in a very similar fashion as an actual ProjectionData object that would contain the specified projections. An example of this is shown in the following:

ProjectionData fullProjections(10, 10, 1);
fullProjections.allocateMemory(10);
for(uint v = 0; v < fullProjections.nbViews(); ++v)
fullProjections.view(v).fill(static_cast<float>(v));
// this creates a ProjectionDataView on all projections in 'fullProjections'
ProjectionDataView projView(fullProjections);
// se can see this, e.g., through the viewIds
qInfo() << projView.viewIds(); // output: std::vector(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
// we can create a subset that includes every other view, like this:
ProjectionDataView subset(fullProjections, { 0, 2, 4, 6, 8 });
qInfo() << subset.viewIds(); // output: std::vector(0, 2, 4, 6, 8)
// when we address the second view in 'subset' we are automatically directed to viewId 2 in the original data
qInfo() << subset.view(1).max(); // output: 2 (because we are in viewId 2)

Subsets of ProjectionDataView can also be created through the subset() method. This allows us, for example, to further restrict an already existing subset. If we continue our above example and select only the second and fourth view that is managed in subset, we get:

// note that the ids we pass here refer to the ids in 'subset' (i.e. 0 to 4) not in the original data
auto moreRestrictedSubset = subset.subset( { 1, 3 } );
qInfo() << moreRestrictedSubset.viewIds(); // output: std::vector(2, 6)

Constructor & Destructor Documentation

◆ ProjectionDataView() [1/2]

CTL::ProjectionDataView::ProjectionDataView ( const ProjectionData projections)

Constructs a ProjectionDataView that references all data of projections.

This creates a ProjectionDataView containing all views in projections. Same as passing a vector containing the numbers from zero to (number of projections - 1) to the two-argument ctor.

◆ ProjectionDataView() [2/2]

CTL::ProjectionDataView::ProjectionDataView ( )

Creates a ProjectionDataView that does not reference any data.

Note that the resulting instance is invalid and can only be made valid through re-assignment or by means of resetData(). Its sole purpose is creation of placeholder variables. For reasons of expressiveness and readability, it is strongly encouraged to use the invalidView() factory method (does the same thing) instead of this ctor.

Member Function Documentation

◆ combined()

ProjectionData CTL::ProjectionDataView::combined ( const ModuleLayout layout = ModuleLayout()) const

Returns a ProjectionData copy of the data referenced by this instance that has been combined according to the ModuleLayout layout.

Note that combining data is meaningful only in case of multi-module projections.

See also
ProjectionData::combined().

◆ dangling() [1/2]

ProjectionDataView CTL::ProjectionDataView::dangling ( ProjectionData &&  projections)
static

Creates a ProjectionDataView on temporary (r-value) projections.

This allows creation of a ProjectionDataView from a temporary ProjectionData object. Note that this leads to a dangling (hence, the name) reference inside the view. Using the ProjectionDataView later on will most likely result in a crash. However, within a single expression, this remains valid use. Therefore, it allows for convenient in-line use-cases like: rec.reconstruct(ProjectionDataView::dangling(projector.project(...))).

Example:

AcquisitionSetup setup(makeCTSystem<blueprints::GenericCarmCT>(), 100);
setup.applyPreparationProtocol(protocols::ShortScanTrajectory(700.0));
auto P = makeProjector<OCL::RayCasterProjector>();
auto R = makeReconstructor<OCL::FDKReconstructor>();
P->configure(setup);
R->configure(setup);
auto phantom = VoxelVolume<float>::cube(100, 1.0f, 1.0f);
auto reco = R->reconstruct(ProjectionDataView::dangling(P->project(phantom)),
VoxelVolume<float>::cube(128, 1.0f, 0.0f));
// note: visualization requires the 'gui_widgets.pri' submodule
gui::plot(reco);

◆ dangling() [2/2]

ProjectionDataView CTL::ProjectionDataView::dangling ( ProjectionData &&  projections,
std::vector< uint viewIds 
)
static

Creates a ProjectionDataView on the projections with ids viewIds of temporary (r-value reference) data projections.

Same as ProjectionDataView::dangling(ProjectionData&&) just with the additional possibility to select a subset of views from the referenced data through their ids (i.e. viewIds).

◆ dataCopy()

ProjectionData CTL::ProjectionDataView::dataCopy ( ) const

Returns a copy of the data referenced by this instance as ProjectionData.

Use this method wherever you need a ProjectionData object when working with a ProjectionDataView. A prominent example would be visualization using gui::plot().

The waiver of implicit conversion from ProjectionDataView to ProjectionData is done intentionally to avoid the risk of unwanted copies.

Same as explicit conversion through operator ProjectionData().

◆ dimensions()

ProjectionData::Dimensions CTL::ProjectionDataView::dimensions ( ) const

Returns the dimensions of the referenced data under consideration that only a subset of views may be referenced.

This returns the view dimensions (i.e. number of channels, rows, and modules) of the referenced data and the number of views referenced by this instance.

Same as ProjectionData::Dimensions(viewDimensions(), nbViews()).

◆ invalidView()

ProjectionDataView CTL::ProjectionDataView::invalidView ( )
static

Creates a ProjectionDataView that does not reference any data.

Note that the resulting instance is invalid and can only be made valid through re-assignment or by means of resetData(). Its sole purpose is creation of placeholder variables. For reasons of expressiveness and readability, it is strongly encouraged to use this method instead of the default ctor.

◆ isValid()

bool CTL::ProjectionDataView::isValid ( ) const

Returns true if this instance references data.

Note that this method cannot verify whether the referenced data is still valid. The responsibility to ensure validity of the referenced data is at the side of the creator of the ProjectionDataView instance.

The only invalid ProjectionDataView object is one created via ProjectionDataView::invalidView() or through the default constructor.

◆ max()

float CTL::ProjectionDataView::max ( ) const

Returns the maximum value that appears in all views that are referenced by this instance.

Note that, since a ProjectionDataView can reference a subset of the original data - the maximum of the ProjectionDataView instance may be less than that of the original (i.e. full) dataset.

◆ min()

float CTL::ProjectionDataView::min ( ) const

Returns the minimum value that appears in all views that are referenced by this instance.

Note that, since a ProjectionDataView can reference a subset of the original data - the minimum of the ProjectionDataView instance may be greater than that of the original (i.e. full) dataset.

◆ operator ProjectionData()

CTL::ProjectionDataView::operator ProjectionData ( ) const
explicit

Explicit conversion to ProjectionData; returns a copy of the data referenced by this instance.

Use this method wherever you need a ProjectionData object when working with a ProjectionDataView. A prominent example would be visualization using gui::plot().

The waiver of implicit conversion from ProjectionDataView to ProjectionData is done intentionally to avoid the risk of unwanted copies.

◆ operator!=()

bool CTL::ProjectionDataView::operator!= ( const ProjectionDataView other) const

Returns true if this instance and other are not equal.

See comparison operator for more details on how equality is determined.

◆ operator==()

bool CTL::ProjectionDataView::operator== ( const ProjectionDataView other) const

Returns true if this instance and other are equal.

Comparison operates on the level of the actual referenced data, meaning that as long as the data that one would access when using the two instances is equal, both ProjectionDataView instances are considered equal. For that, it is checked whether:

  • dimensions of both instances are identical
  • data of the referenced views is the same (using comparison operation of SingleViewData)

Since this means, in particular, that for equality it is not mandatory that this instance and other are identical with respect to their internal state (i.e. same data reference and same view id vectors), multiple cases can exist where two instances are considered equal. This encompasses two different settings:

  1. Both instances reference the exact same dataset (i.e. point to the same memory) and contain the same ids.
  2. The two instances reference different datasets (and potentially also have different view id vectors (with the same length)), but the actual data that is referenced is equal.

Note: must not be applied to invalid views.

◆ parallelExecution()

template<class Function >
void CTL::ProjectionDataView::parallelExecution ( const Function &  f) const
private

Helper function for running tasks in parallel over views.

◆ resetData() [1/2]

void CTL::ProjectionDataView::resetData ( const ProjectionData projections,
std::vector< uint viewIds 
)

Resets the data that is referenced by this instance to projections and the corresponding referenced view ids to viewIds.

This is essentially the same as re-assignement with a newly created instance of ProjectionDataView on the new data (i.e. projections and viewIds).

◆ resetData() [2/2]

CTL::ProjectionDataView::resetData ( ProjectionData &&  projections,
std::vector< uint viewIds 
)
delete

Deleted for safety reasons.

If you need to utilize temporary projection data within a ProjectionDataView, please refer to ProjectionDataView::dangling(ProjectionData&&,std::vector<uint>).

◆ shuffle() [1/2]

void CTL::ProjectionDataView::shuffle ( )

Randomly shuffles the order in which the view ids referenced by this instance appear.

This uses std::random_device to create a seed for the random number generator used to perform the shuffling.

◆ shuffle() [2/2]

void CTL::ProjectionDataView::shuffle ( uint  seed)

Randomly shuffles the order in which the view ids referenced by this instance appear.

Seeds the random number generator used to perform the shuffling with seed.

◆ shuffled() [1/2]

ProjectionDataView CTL::ProjectionDataView::shuffled ( ) const

Returns a ProjectionDataView that references the same data but with a list of view ids whose order has been shuffled at random.

This uses std::random_device to create a seed for the random number generator used to perform the shuffling.

◆ shuffled() [2/2]

ProjectionDataView CTL::ProjectionDataView::shuffled ( uint  seed) const

Returns a ProjectionDataView that references the same data but with a list of view ids whose order has been shuffled at random.

Seeds the random number generator used to perform the shuffling with seed.

◆ subset() [1/2]

ProjectionDataView CTL::ProjectionDataView::subset ( const std::vector< uint > &  idsInView) const

Returns a ProjectionDataView that references the subset with indices idsInView of the data referenced by this instance.

Note that the view ids (i.e. idsInView) refer to the id within the current ProjectionDataView. That means the range of valid ids to pass to this method ranges from zero to nbViews() - 1.

Example:

ProjectionData fullProjections(10, 10, 1);
fullProjections.allocateMemory(10); // 'fullProjections' now has 10 views
// we create a subset that includes every other view
ProjectionDataView subset(fullProjections, { 0, 2, 4, 6, 8 });
qInfo() << subset.viewIds(); // output: std::vector(0, 2, 4, 6, 8)
// we now futher restrict the subset by selecting the second and fourth view of 'subset'
auto moreRestrictedSubset = subset.subset( { 1, 3 } );
// note that the ids we passed here refer to the ids in 'subset' not in the original data
qInfo() << moreRestrictedSubset.viewIds(); // output: std::vector(2, 6)

◆ subset() [2/2]

ProjectionDataView CTL::ProjectionDataView::subset ( uint  pos = 0,
uint  count = std::numeric_limits<uint>::max() 
) const

Returns a ProjectionDataView that references a subset containing count views starting at view id pos of the data referenced by this instance.

Same as using the index-based version of subset(const std::vector<uint>&) with an input vector of { pos, ..., pos + count -1 }.

ProjectionData fullProjections(10, 10, 1);
fullProjections.allocateMemory(10); // 'fullProjections' now has 10 views
// we create a subset that includes every other view
ProjectionDataView subset(fullProjections, { 0, 2, 4, 6, 8 });
qInfo() << subset.viewIds(); // output: std::vector(0, 2, 4, 6, 8)
// we now futher restrict the subset by selecting from 'subset' three views starting at id 1
auto moreRestrictedSubset = subset.subset(1, 3);
qInfo() << moreRestrictedSubset.viewIds(); // output: std::vector(2, 4, 6)

◆ toVector()

std::vector< float > CTL::ProjectionDataView::toVector ( ) const

Returns a concatenated vector of all pixel values in the referenced data.

Values are in row-major order, i.e. the vector starts with the data from the first row of the first module, followed by the remaining rows of that module. Subsequently, the next modules are appended with the same concept. Ultimately, proceeds with the next view that is referenced by this instance.


The documentation for this class was generated from the following files: