17#ifndef __dwi_directions_set_h__
18#define __dwi_directions_set_h__
30 namespace Directions {
41 explicit Set (
const std::string& path) :
43 dir_mask_excess_bits (0),
44 dir_mask_excess_bits_mask (0)
48 if (matrix.cols() != 2 && matrix.cols() != 3)
49 throw Exception (
"Text file \"" + path +
"\"does not contain directions as either azimuth-elevation pairs or XYZ triplets");
54 explicit Set (
const size_t d) :
56 dir_mask_excess_bits (0),
57 dir_mask_excess_bits_mask (0)
59 Eigen::MatrixXd az_el_pairs;
60 load_predefined (az_el_pairs, d);
61 initialise (az_el_pairs);
64 Set (
const Set& that) =
default;
69 dir_mask_bytes (that.dir_mask_bytes),
70 dir_mask_excess_bits (that.dir_mask_excess_bits),
71 dir_mask_excess_bits_mask (that.dir_mask_excess_bits_mask)
73 that.dir_mask_bytes = that.dir_mask_excess_bits = that.dir_mask_excess_bits_mask = 0;
77 template <
class MatrixType>
78 explicit Set (
const Eigen::Matrix<MatrixType, Eigen::Dynamic, Eigen::Dynamic>& m) :
80 dir_mask_excess_bits (0),
81 dir_mask_excess_bits_mask (0)
87 const Eigen::Vector3d& get_dir (
const size_t i)
const { assert (i < size());
return unit_vectors[i]; }
90 assert (one < size());
91 assert (two < size());
92 for (
const auto& i :
adj_dirs[one]) {
102 const Eigen::Vector3d& operator[] (
const size_t i)
const { assert (i < size());
return unit_vectors[i]; }
113 size_t dir_mask_bytes, dir_mask_excess_bits;
114 uint8_t dir_mask_excess_bits_mask;
119 void load_predefined (Eigen::MatrixXd& az_el_pairs,
const size_t);
120 template <
class MatrixType>
121 void initialise (
const Eigen::Matrix<MatrixType, Eigen::Dynamic, Eigen::Dynamic>&);
122 void initialise_adjacency();
123 void initialise_mask();
129 template <
class MatrixType>
130 void Set::initialise (
const Eigen::Matrix<MatrixType, Eigen::Dynamic, Eigen::Dynamic>& in)
133 if (in.cols() == 2) {
134 for (
size_t i = 0; i != size(); ++i) {
137 const default_type sin_elevation = std::sin (elevation);
138 unit_vectors[i] = { std::cos (azimuth) * sin_elevation, std::sin (azimuth) * sin_elevation, std::cos (elevation) };
140 }
else if (in.cols() == 3) {
141 for (
size_t i = 0; i != size(); ++i)
146 initialise_adjacency();
172 Set (std::move (that)),
173 grid_lookup (std::move (that.grid_lookup)),
174 num_az_grids (that.num_az_grids),
175 num_el_grids (that.num_el_grids),
176 total_num_angle_grids (that.total_num_angle_grids),
177 az_grid_step (that.az_grid_step),
178 el_grid_step (that.el_grid_step),
179 az_begin (that.az_begin),
180 el_begin (that.el_begin) { }
182 index_type select_direction (
const Eigen::Vector3d&)
const;
189 unsigned int num_az_grids, num_el_grids, total_num_angle_grids;
195 index_type select_direction_slow (
const Eigen::Vector3d&)
const;
199 size_t dir2gridindex (
const Eigen::Vector3d&)
const;
201 void test_lookup()
const;
vector< Eigen::Vector3d > unit_vectors
vector< vector< index_type > > adj_dirs
Eigen::Matrix< ValueType, Eigen::Dynamic, Eigen::Dynamic > load_matrix(const std::string &filename)
read matrix data into an Eigen::Matrix filename
double default_type
the default type used throughout MRtrix