FAST  3.2.0
Framework for Heterogeneous Medical Image Computing and Visualization
TensorAccess.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <eigen3/unsupported/Eigen/CXX11/Tensor>
4 #include <FAST/Object.hpp>
6 
7 namespace fast {
8 
9 // Rename the Eigen float tensor for simplicity
10 template<int NumDimensions>
11 using TensorData = Eigen::TensorMap<Eigen::Tensor<float, NumDimensions, Eigen::RowMajor>>;
12 
13 class Tensor;
14 
15 class FAST_EXPORT TensorAccess {
16  public:
17  typedef std::unique_ptr<TensorAccess> pointer;
18  TensorAccess(float* data, TensorShape shape, std::shared_ptr<Tensor> tensor);
19  float * getRawData();
20  TensorShape getShape() const;
21  ~TensorAccess();
22  void release();
23  template <int NumDimensions>
24  TensorData<NumDimensions> getData() const;
25  private:
26  std::shared_ptr<Tensor> m_tensor;
27  TensorShape m_shape;
28  float* m_data;
29 };
30 
31 
32 template <int NumDimensions>
34  if(NumDimensions != m_shape.getDimensions())
35  throw Exception("Dimension mismatch for Eigen tensor in TensorAccess::getData<#Dimension>().");
36 
37  // Construct eigen shape
38  Eigen::array<int64_t, NumDimensions> sizes;
39  for(int i = 0; i < m_shape.getDimensions(); ++i)
40  sizes[i] = m_shape[i];
41 
42  // Create and return mapped eigen tensor
43  return TensorData<NumDimensions>(m_data, sizes);
44 }
45 
46 
47 
48 }
Object.hpp
fast::Exception
Definition: Exception.hpp:15
fast::TensorShape
Definition: TensorShape.hpp:9
TensorShape.hpp
fast
Definition: AffineTransformation.hpp:7
fast::TensorAccess::pointer
std::unique_ptr< TensorAccess > pointer
Definition: TensorAccess.hpp:17
fast::TensorShape::getDimensions
int getDimensions() const
fast::Tensor
Definition: Tensor.hpp:12
fast::TensorAccess
Definition: TensorAccess.hpp:15
fast::TensorData
Eigen::TensorMap< Eigen::Tensor< float, NumDimensions, Eigen::RowMajor > > TensorData
Definition: TensorAccess.hpp:11
fast::TensorAccess::getData
TensorData< NumDimensions > getData() const
Definition: TensorAccess.hpp:33