Developer documentation
Version 3.0.3-105-gd3941f44
internalenergy.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __gt_internalenergy_h__
18#define __gt_internalenergy_h__
19
20#include "types.h"
21
22#include "math/math.h"
23#include "math/rng.h"
24
29
30
31namespace MR {
32 namespace DWI {
33 namespace Tractography {
34 namespace GT {
35
37 { MEMALIGN(InternalEnergyComputer)
38 public:
39
41 : EnergyComputer(s), pGrid(pgrid), cpot(1.0), dEint(0.0), neighbourhood(), normalization(1.0), rng_uniform()
42 {
43 DEBUG("Initialise computation of internal energy.");
44 neighbourhood.reserve(1000);
45 ParticleEnd pe;
46 pe.par = NULL;
47 pe.alpha = 0;
48 pe.p_suc = 1.0;
49 pe.e_conn = 0.0;
50 neighbourhood.push_back(pe);
51 }
52
53
54 double stageShift(const Particle* par, const Point_t& pos, const Point_t& dir)
55 {
56 dEint = 0.0;
57 if (par->hasPredecessor()) {
58 int a = (par->getPredecessor()->getPredecessor() == par) ? -1 : 1;
59 dEint -= calcEnergy(par, -1, par->getPredecessor(), a);
60 Point_t ep (pos);
61 ep -= Particle::L * dir;
62 dEint += calcEnergy(pos, ep, par->getPredecessor()->getPosition(), par->getPredecessor()->getEndPoint(a));
63 }
64 if (par->hasSuccessor()) {
65 int a = (par->getSuccessor()->getPredecessor() == par) ? -1 : 1;
66 dEint -= calcEnergy(par, 1, par->getSuccessor(), a);
67 Point_t ep (pos);
68 ep += Particle::L * dir;
69 dEint += calcEnergy(pos, ep, par->getSuccessor()->getPosition(), par->getSuccessor()->getEndPoint(a));
70 }
71 return dEint / stats.getTint();
72 }
73
74 double stageRemove(const Particle* par)
75 {
76 dEint = 0.0;
77 if (par->hasPredecessor()) {
78 int a = (par->getPredecessor()->getPredecessor() == par) ? -1 : 1;
79 dEint -= calcEnergy(par, -1, par->getPredecessor(), a);
80 }
81 if (par->hasSuccessor()) {
82 int a = (par->getSuccessor()->getPredecessor() == par) ? -1 : 1;
83 dEint -= calcEnergy(par, 1, par->getSuccessor(), a);
84 }
85 return dEint / stats.getTint();
86 }
87
88 double stageConnect(const ParticleEnd& pe1, ParticleEnd& pe2);
89
90 void acceptChanges()
91 {
92 stats.incEintTotal(dEint);
93 }
94
95 EnergyComputer* clone() const { return new InternalEnergyComputer(*this); }
96
97 double getConnPot() const
98 {
99 return cpot;
100 }
101
102 void setConnPot(const double connpot)
103 {
104 cpot = connpot;
105 }
106
107
108 protected:
110 double cpot, dEint;
114
115
116 double calcEnergy(const Particle* P1, const int ep1, const Particle* P2, const int ep2)
117 {
118 return calcEnergy(P1->getPosition(), P1->getEndPoint(ep1), P2->getPosition(), P2->getEndPoint(ep2));
119 }
120
121 double calcEnergy(const Point_t& pos1, const Point_t& ep1, const Point_t& pos2, const Point_t& ep2)
122 {
123 Point_t Xm = (pos1 + pos2) * 0.5; // midpoint between both segments
124 double Ucon = ( (ep1 - Xm).squaredNorm() + (ep2 - Xm).squaredNorm() ) / (Particle::L * Particle::L);
125 return Ucon - cpot;
126 }
127
128 void scanNeighbourhood(const Particle* p, const int alpha0, const double currTemp);
129
131
132
133 };
134
135
136 }
137 }
138 }
139}
140
141#endif // __gt_internalenergy_h__
double calcEnergy(const Particle *P1, const int ep1, const Particle *P2, const int ep2)
void scanNeighbourhood(const Particle *p, const int alpha0, const double currTemp)
double calcEnergy(const Point_t &pos1, const Point_t &ep1, const Point_t &pos2, const Point_t &ep2)
#define DEBUG(msg)
Definition: exception.h:75
Eigen::Vector3f Point_t
Definition: particle.h:29
Definition: base.h:24