CTL
0.6.1
Computed Tomography Library
|
The ProjectionDataView class is a read-only wrapper for a reference to ProjectionData. More...
#include <projectiondataview.h>
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 SingleViewData & | first () const |
Returns a reference-to-const to the first view referenced by this instance. | |
const SingleViewData & | view (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 |
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:
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:
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.
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.
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.
|
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:
|
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).
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()
.
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())
.
|
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.
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.
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.
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.
|
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.
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.
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:
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:
Note: must not be applied to invalid views.
|
private |
Helper function for running tasks in parallel over views.
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).
|
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>).
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.
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.
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.
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.
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:
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 }
.
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.