17#ifndef __dwi_tractography_mapping_mapper_h__
18#define __dwi_tractography_mapping_mapper_h__
40#define CURVATURE_TRACK_SMOOTHING_FWHM 10.0
49 namespace Tractography {
59 template <
class HeaderType>
61 info (template_image),
68 template <
class HeaderType>
70 info (template_image),
85 void set_upsample_ratio (
const size_t i) {
upsampler.set_ratio (i); }
86 void set_map_zero (
const bool i) {
map_zero = i; }
87 void set_use_precise_mapping (
const bool i) {
89 throw Exception (
"Cannot do precise mapping and endpoint mapping together");
92 void set_map_ends_only (
const bool i) {
94 throw Exception (
"Cannot do precise mapping and endpoint mapping together");
104 void create_tod_plugin (
const size_t N)
111 template <
class Cont>
112 bool operator() (
const Streamline<>& in, Cont& out)
const
116 out.weight = in.weight;
175 template <
class Cont>
179 auto prev = tck.cbegin();
180 const auto last = tck.cend() - 1;
183 for (
auto i = tck.cbegin(); i != last; ++i) {
186 const Eigen::Vector3d dir = (*(i+1) - *prev).cast<
default_type>().normalized();
187 if (dir.allFinite() && !dir.isZero())
195 const Eigen::Vector3d dir = (*last - *prev).cast<default_type>().normalized();
196 if (dir.allFinite() && !dir.isZero())
200 for (
auto& i : output)
210 template <
class Cont>
224 const point_type tck_proj_front = (tck[ 0 ] * 2.0) - tck[ 1 ];
225 const point_type tck_proj_back = (tck[tck.size()-1] * 2.0) - tck[tck.size()-2];
230 bool end_track =
false;
235 const point_type p_voxel_entry (p_voxel_exit);
238 const auto this_voxel = next_voxel;
240 while ((p != tck.size()) && ((next_voxel =
round (
scanner2voxel * tck[p])) == this_voxel)) {
241 length += (p_prev - tck[p]).norm();
247 if (p == tck.size()) {
248 p_voxel_exit = tck.back();
256 const point_type* p_one = (p == 1) ? &tck_proj_front : &tck[p - 2];
257 const point_type* p_four = (p == tck.size() - 1) ? &tck_proj_back : &tck[p + 1];
262 while ((p_min - p_max).squaredNorm() > accuracy) {
264 mu = 0.5 * (mu_min + mu_max);
266 const point_type p_mu = hermite.
value (*p_one, tck[p - 1], tck[p], *p_four);
269 if (mu_voxel == this_voxel) {
276 next_voxel = mu_voxel;
280 p_voxel_exit = p_max;
284 length += (p_prev - p_voxel_exit).norm();
285 const Eigen::Vector3d traversal_vector = (p_voxel_exit - p_voxel_entry).cast<default_type>().normalized();
286 if (std::isfinite (traversal_vector[0]) &&
check (this_voxel,
info))
289 }
while (!end_track);
295 template <
class Cont>
300 if (tck.size() == 1) {
306 for (
size_t end = 0; end != 2; ++end) {
311 dir = (end ? (tck[tck.size()-1] - tck[tck.size()-2]) : (tck[0] - tck[1])).cast<default_type>().normalized();
342 Eigen::Matrix<default_type, Eigen::Dynamic, 1> sh;
343 (*tod_plugin) (sh, d);
361 template <
class HeaderType>
378 void add_scalar_image (
const std::string&);
379 void set_backtrack();
380 void add_fod_image (
const std::string&);
383 void add_vector_data (
const std::string&);
void insert(const Dixel &v)
void insert(const VoxelDEC &v)
void insert(const VoxelDir &v)
void insert(const Voxel &v)
void insert(const VoxelTOD &v)
const Eigen::Transform< float, 3, Eigen::AffineCompact > scanner2voxel
void voxelise_precise(const Streamline<> &, Cont &) const
DWI::Tractography::Resampling::Upsampler upsampler
std::shared_ptr< TODMappingPlugin > tod_plugin
void add_to_set(SetVoxel &, const Eigen::Vector3i &, const Eigen::Vector3d &, const default_type) const
std::shared_ptr< DixelMappingPlugin > dixel_plugin
virtual void postprocess(const Streamline<> &tck, SetVoxelExtras &out) const
virtual bool preprocess(const Streamline<> &tck, SetVoxelExtras &out) const
void voxelise_ends(const Streamline<> &, Cont &) const
void voxelise(const Streamline<> &, SetVoxel &) const
vector< default_type > factors
std::unique_ptr< TWIImagePluginBase > image_plugin
const contrast_t contrast
void load_factors(const Streamline<> &) const
const tck_stat_t track_statistic
std::shared_ptr< Eigen::VectorXf > vector_data
void set(value_type position)
S value(const S *vals) const
constexpr T pow2(const T &v)
Eigen::Vector3i round(const Eigen::Matrix< T, 3, 1 > &p)
bool check(const Eigen::Vector3i &V, const HeaderType &H)
typename Streamline<>::point_type point_type
PointType::Scalar length(const vector< PointType > &tck)
MR::default_type value_type
double default_type
the default type used throughout MRtrix
constexpr default_type NaN