17#ifndef __dwi_tractography_mapping_gaussian_mapper_h__ 
   18#define __dwi_tractography_mapping_gaussian_mapper_h__ 
   31    namespace Tractography {
 
   44            template <
class HeaderType>
 
   46              BaseMapper (template_image, c, 
GAUSSIAN),
 
   58                throw Exception (
"Cannot set Gaussian FWHM unless the track statistic is Gaussian");
 
   59              const default_type theta = FWHM / (2.0 * std::sqrt (2.0 * std::log (2.0)));
 
   72                out.weight = in.weight;
 
  120          template <
class Cont>
 
  125              const size_t last = tck.size() - 1;
 
  128              for (
size_t i = 0; i != last; ++i) {
 
  131                  const Eigen::Vector3d dir ((tck[i+1] - tck[prev]).cast<default_type>().normalized());
 
  140                const Eigen::Vector3d dir ((tck[last] - tck[prev]).cast<default_type>().normalized());
 
  145              for (
auto& i : output)
 
  155          template <
class Cont>
 
  170              const point_type tck_proj_front = (tck[      0     ] * 2.0) - tck[     1      ];
 
  171              const point_type tck_proj_back  = (tck[tck.size()-1] * 2.0) - tck[tck.size()-2];
 
  176              bool end_track = 
false;
 
  181                const point_type p_voxel_entry (p_voxel_exit);
 
  185                const Eigen::Vector3i this_voxel = next_voxel;
 
  187                while ((p != tck.size()) && ((next_voxel = 
round (
scanner2voxel * tck[p])) == this_voxel)) {
 
  188                  length += (p_prev - tck[p]).norm();
 
  194                if (p == tck.size()) {
 
  195                  p_voxel_exit = tck.back();
 
  202                  const point_type* p_one  = (p == 1)              ? &tck_proj_front : &tck[p - 2];
 
  203                  const point_type* p_four = (p == tck.size() - 1) ? &tck_proj_back  : &tck[p + 1];
 
  208                  while ((p_min - p_max).squaredNorm() > accuracy) {
 
  210                    mu = 0.5 * (mu_min + mu_max);
 
  212                    const point_type p_mu = hermite.
value (*p_one, tck[p - 1], tck[p], *p_four);
 
  215                    if (mu_voxel == this_voxel) {
 
  221                      next_voxel = mu_voxel;
 
  225                  p_voxel_exit = p_max;
 
  229                length += (p_prev - p_voxel_exit).norm();
 
  230                Eigen::Vector3d traversal_vector = (p_voxel_exit - p_voxel_entry).cast<default_type>().normalized();
 
  231                if (traversal_vector.allFinite() && 
check (this_voxel, 
info)) {
 
  233                  const size_t mean_tck_index = 
std::round (0.5 * (index_voxel_entry + index_voxel_exit));
 
  238              } 
while (!end_track);
 
  244          template <
class Cont>
 
  247              for (
size_t end = 0; end != 2; ++end) {
 
  250                  const Eigen::Vector3d dir = (end ? (tck[tck.size()-1] - tck[tck.size()-2]) : (tck[0] - tck[1])).cast<default_type>().normalized();
 
  261            out.insert (v, l, f);
 
  265            out.insert (v, d, l, f);
 
  270            const size_t bin = (*dixel_plugin) (d);
 
  271            out.insert (v, bin, l, f);
 
  277            (*tod_plugin) (sh, d);
 
  278            out.insert (v, sh, l, f);
 
  288            const size_t lower_index = std::max (
size_t(
std::floor (ideal_index)), 
size_t(0));
 
  289            const size_t upper_index = std::min (
size_t(
std::ceil  (ideal_index)), 
size_t(
factors.size() - 1));
 
  291            return ((mu * 
factors[upper_index]) + ((1.0-mu) * 
factors[lower_index]));
 
bool operator()(Streamline<> &in, Cont &out) const
void voxelise_precise(const Streamline<> &, Cont &) const
bool preprocess(const Streamline<> &tck, SetVoxelExtras &out) const
void set_gaussian_FWHM(const default_type FWHM)
TrackMapper(const TrackMapper &)=default
default_type tck_index_to_factor(const size_t) const
void set_factor(const Streamline<> &tck, SetVoxelExtras &out) const
void voxelise(const Streamline<> &, Cont &) const
TrackMapper(const HeaderType &template_image, const contrast_t c)
void voxelise_ends(const Streamline<> &, Cont &) const
void add_to_set(SetVoxel &, const Eigen::Vector3i &, const Eigen::Vector3d &, const default_type, const default_type) const
void gaussian_smooth_factors(const Streamline<> &) const
default_type gaussian_denominator
Eigen::Matrix< default_type, Eigen::Dynamic, 1 > vector_type
const Eigen::Transform< float, 3, Eigen::AffineCompact > scanner2voxel
DWI::Tractography::Resampling::Upsampler upsampler
std::shared_ptr< TODMappingPlugin > tod_plugin
std::shared_ptr< DixelMappingPlugin > dixel_plugin
virtual void postprocess(const Streamline<> &tck, SetVoxelExtras &out) const
vector< default_type > factors
const tck_stat_t track_statistic
void set(value_type position)
S value(const S *vals) const
constexpr T pow2(const T &v)
constexpr I ceil(const T x)
template function with cast to different type
constexpr I floor(const T x)
template function with cast to different type
constexpr I round(const T x)
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