Verified Commit c11f1417 authored by Tobias WEBER's avatar Tobias WEBER
Browse files

cleanups

parent 2f284b53
...@@ -93,13 +93,15 @@ t_real PathsBuilder::GetPathLength(const t_vec2& _vec) const ...@@ -93,13 +93,15 @@ t_real PathsBuilder::GetPathLength(const t_vec2& _vec) const
kf_fixed = false; kf_fixed = false;
} }
const Instrument& instr = m_instrspace->GetInstrument();
// monochromator 2theta angular speed (alternatively analyser speed if kf is not fixed) // monochromator 2theta angular speed (alternatively analyser speed if kf is not fixed)
t_real a2_speed = kf_fixed t_real a2_speed = kf_fixed
? m_instrspace->GetInstrument().GetMonochromator().GetAxisAngleOutSpeed() ? instr.GetMonochromator().GetAxisAngleOutSpeed()
: m_instrspace->GetInstrument().GetAnalyser().GetAxisAngleOutSpeed(); : instr.GetAnalyser().GetAxisAngleOutSpeed();
// sample 2theta angular speed // sample 2theta angular speed
t_real a4_speed = m_instrspace->GetInstrument().GetSample().GetAxisAngleOutSpeed(); t_real a4_speed = instr.GetSample().GetAxisAngleOutSpeed();
t_vec2 vec = _vec; t_vec2 vec = _vec;
vec[0] /= a4_speed; vec[0] /= a4_speed;
...@@ -293,10 +295,12 @@ bool PathsBuilder::CalculateConfigSpace( ...@@ -293,10 +295,12 @@ bool PathsBuilder::CalculateConfigSpace(
} }
} }
const Instrument& instr = m_instrspace->GetInstrument();
// analyser angle (alternatively monochromator angle if kf is not fixed) // analyser angle (alternatively monochromator angle if kf is not fixed)
t_real a6 = kf_fixed t_real a6 = kf_fixed
? m_instrspace->GetInstrument().GetAnalyser().GetAxisAngleOut() // a6 or ? instr.GetAnalyser().GetAxisAngleOut() // a6 or
: m_instrspace->GetInstrument().GetMonochromator().GetAxisAngleOut(); // a2 : instr.GetMonochromator().GetAxisAngleOut(); // a2
// include scattering senses // include scattering senses
if(sensesCCW) if(sensesCCW)
...@@ -338,15 +342,17 @@ bool PathsBuilder::CalculateConfigSpace( ...@@ -338,15 +342,17 @@ bool PathsBuilder::CalculateConfigSpace(
t_real a2 = angle[1]; t_real a2 = angle[1];
t_real a3 = a4 * 0.5; t_real a3 = a4 * 0.5;
Instrument& instr = instrspace_cpy.GetInstrument();
// set scattering angles (a2 and a6 are flipped in case kf is not fixed) // set scattering angles (a2 and a6 are flipped in case kf is not fixed)
instrspace_cpy.GetInstrument().GetMonochromator().SetAxisAngleOut(kf_fixed ? a2 : a6); instr.GetMonochromator().SetAxisAngleOut(kf_fixed ? a2 : a6);
instrspace_cpy.GetInstrument().GetSample().SetAxisAngleOut(a4); instr.GetSample().SetAxisAngleOut(a4);
instrspace_cpy.GetInstrument().GetAnalyser().SetAxisAngleOut(kf_fixed ? a6 : a2); instr.GetAnalyser().SetAxisAngleOut(kf_fixed ? a6 : a2);
// set crystal angles (a1 and a5 are flipped in case kf is not fixed) // set crystal angles (a1 and a5 are flipped in case kf is not fixed)
instrspace_cpy.GetInstrument().GetMonochromator().SetAxisAngleInternal(kf_fixed ? 0.5*a2 : 0.5*a6); instr.GetMonochromator().SetAxisAngleInternal(kf_fixed ? 0.5*a2 : 0.5*a6);
instrspace_cpy.GetInstrument().GetSample().SetAxisAngleInternal(a3); instr.GetSample().SetAxisAngleInternal(a3);
instrspace_cpy.GetInstrument().GetAnalyser().SetAxisAngleInternal(kf_fixed ? 0.5*a6 : 0.5*a2); instr.GetAnalyser().SetAxisAngleInternal(kf_fixed ? 0.5*a6 : 0.5*a2);
// set image value // set image value
bool angle_ok = instrspace_cpy.CheckAngularLimits(); bool angle_ok = instrspace_cpy.CheckAngularLimits();
...@@ -654,7 +660,7 @@ bool PathsBuilder::CalculateVoronoi(bool group_lines, VoronoiBackend backend, ...@@ -654,7 +660,7 @@ bool PathsBuilder::CalculateVoronoi(bool group_lines, VoronoiBackend backend,
regions.SetPointsOutsideRegions(&m_points_outside_regions); regions.SetPointsOutsideRegions(&m_points_outside_regions);
regions.SetInvertedRegions(&m_inverted_regions); regions.SetInvertedRegions(&m_inverted_regions);
regions.SetRegionFunc(use_region_function ? &region_func : nullptr); regions.SetRegionFunc(use_region_function ? &region_func : nullptr);
regions.SetValidateFunc(&validation_func); regions.SetValidateFunc(m_remove_bisectors_below_min_wall_dist ? &validation_func : nullptr);
if(backend == VoronoiBackend::BOOST) if(backend == VoronoiBackend::BOOST)
{ {
...@@ -811,6 +817,7 @@ InstrumentPath PathsBuilder::FindPath( ...@@ -811,6 +817,7 @@ InstrumentPath PathsBuilder::FindPath(
} }
InstrumentSpace instrspace_cpy = *this->m_instrspace; InstrumentSpace instrspace_cpy = *this->m_instrspace;
Instrument& instr = instrspace_cpy.GetInstrument();
// set instrument angles to start point // set instrument angles to start point
t_real a2 = a2_i; t_real a2 = a2_i;
...@@ -823,15 +830,15 @@ InstrumentPath PathsBuilder::FindPath( ...@@ -823,15 +830,15 @@ InstrumentPath PathsBuilder::FindPath(
if(kf_fixed) if(kf_fixed)
{ {
instrspace_cpy.GetInstrument().GetMonochromator().SetAxisAngleOut(a2); instr.GetMonochromator().SetAxisAngleOut(a2);
instrspace_cpy.GetInstrument().GetMonochromator().SetAxisAngleInternal(0.5 * a2); instr.GetMonochromator().SetAxisAngleInternal(0.5 * a2);
} }
else else
{ {
instrspace_cpy.GetInstrument().GetAnalyser().SetAxisAngleOut(a2); instr.GetAnalyser().SetAxisAngleOut(a2);
instrspace_cpy.GetInstrument().GetAnalyser().SetAxisAngleInternal(0.5 * a2); instr.GetAnalyser().SetAxisAngleInternal(0.5 * a2);
} }
instrspace_cpy.GetInstrument().GetSample().SetAxisAngleOut(a4); instr.GetSample().SetAxisAngleOut(a4);
bool in_angular_limits = instrspace_cpy.CheckAngularLimits(); bool in_angular_limits = instrspace_cpy.CheckAngularLimits();
bool colliding = instrspace_cpy.CheckCollision2D(); bool colliding = instrspace_cpy.CheckCollision2D();
...@@ -849,15 +856,15 @@ InstrumentPath PathsBuilder::FindPath( ...@@ -849,15 +856,15 @@ InstrumentPath PathsBuilder::FindPath(
if(kf_fixed) if(kf_fixed)
{ {
instrspace_cpy.GetInstrument().GetMonochromator().SetAxisAngleOut(a2); instr.GetMonochromator().SetAxisAngleOut(a2);
instrspace_cpy.GetInstrument().GetMonochromator().SetAxisAngleInternal(0.5 * a2); instr.GetMonochromator().SetAxisAngleInternal(0.5 * a2);
} }
else else
{ {
instrspace_cpy.GetInstrument().GetAnalyser().SetAxisAngleOut(a2); instr.GetAnalyser().SetAxisAngleOut(a2);
instrspace_cpy.GetInstrument().GetAnalyser().SetAxisAngleInternal(0.5 * a2); instr.GetAnalyser().SetAxisAngleInternal(0.5 * a2);
} }
instrspace_cpy.GetInstrument().GetSample().SetAxisAngleOut(a4); instr.GetSample().SetAxisAngleOut(a4);
in_angular_limits = instrspace_cpy.CheckAngularLimits(); in_angular_limits = instrspace_cpy.CheckAngularLimits();
colliding = instrspace_cpy.CheckCollision2D(); colliding = instrspace_cpy.CheckCollision2D();
...@@ -1348,19 +1355,21 @@ std::vector<t_vec2> PathsBuilder::GetPathVertices( ...@@ -1348,19 +1355,21 @@ std::vector<t_vec2> PathsBuilder::GetPathVertices(
t_real a4 = _angle[0]; t_real a4 = _angle[0];
t_real a2 = _angle[1]; t_real a2 = _angle[1];
Instrument& instr = instrspace_cpy.GetInstrument();
// set scattering angles // set scattering angles
if(kf_fixed) if(kf_fixed)
instrspace_cpy.GetInstrument().GetMonochromator().SetAxisAngleOut(a2); instr.GetMonochromator().SetAxisAngleOut(a2);
else else
instrspace_cpy.GetInstrument().GetAnalyser().SetAxisAngleOut(a2); instr.GetAnalyser().SetAxisAngleOut(a2);
instrspace_cpy.GetInstrument().GetSample().SetAxisAngleOut(a4); instr.GetSample().SetAxisAngleOut(a4);
// set crystal angles // set crystal angles
if(kf_fixed) if(kf_fixed)
instrspace_cpy.GetInstrument().GetMonochromator().SetAxisAngleInternal(0.5 * a2); instr.GetMonochromator().SetAxisAngleInternal(0.5 * a2);
else else
instrspace_cpy.GetInstrument().GetAnalyser().SetAxisAngleInternal(0.5 * a2); instr.GetAnalyser().SetAxisAngleInternal(0.5 * a2);
//instrspace_cpy.GetInstrument().GetSample().SetAxisAngleInternal(a3); //instr.GetSample().SetAxisAngleInternal(a3);
bool angle_ok = instrspace_cpy.CheckAngularLimits(); bool angle_ok = instrspace_cpy.CheckAngularLimits();
bool colliding = instrspace_cpy.CheckCollision2D(); bool colliding = instrspace_cpy.CheckCollision2D();
......
...@@ -224,6 +224,9 @@ public: ...@@ -224,6 +224,9 @@ public:
t_real GetMinDistToWalls() const { return m_min_angular_dist_to_walls; } t_real GetMinDistToWalls() const { return m_min_angular_dist_to_walls; }
void SetMinDistToWalls(t_real dist) { m_min_angular_dist_to_walls = dist; } void SetMinDistToWalls(t_real dist) { m_min_angular_dist_to_walls = dist; }
void SetRemoveBisectorsBelowMinWallDist(bool b) { m_remove_bisectors_below_min_wall_dist = b; }
bool GetRemoveBisectorsBelowMinWallDist() const { return m_remove_bisectors_below_min_wall_dist; }
unsigned int GetMaxNumThreads() const { return m_maxnum_threads; } unsigned int GetMaxNumThreads() const { return m_maxnum_threads; }
void SetMaxNumThreads(unsigned int n) { m_maxnum_threads = n; } void SetMaxNumThreads(unsigned int n) { m_maxnum_threads = n; }
...@@ -322,6 +325,9 @@ private: ...@@ -322,6 +325,9 @@ private:
// minimum distance to keep from the walls (e.g. for direct path calculation) // minimum distance to keep from the walls (e.g. for direct path calculation)
t_real m_min_angular_dist_to_walls = 5. / t_real(180.) * tl2::pi<t_real>; t_real m_min_angular_dist_to_walls = 5. / t_real(180.) * tl2::pi<t_real>;
// remove bisectors that are below the minimum distance given above
bool m_remove_bisectors_below_min_wall_dist = true;
// minimum distance to consider "staircase artefacts" // minimum distance to consider "staircase artefacts"
t_real m_simplify_mindist = 3.; t_real m_simplify_mindist = 3.;
......
...@@ -840,7 +840,7 @@ void ConfigSpaceDlg::CalculatePathMesh() ...@@ -840,7 +840,7 @@ void ConfigSpaceDlg::CalculatePathMesh()
return; return;
m_pathsbuilder->StartPathMeshWorkflow(); m_pathsbuilder->StartPathMeshWorkflow();
const auto& instr = m_pathsbuilder->GetInstrumentSpace()->GetInstrument(); const Instrument& instr = m_pathsbuilder->GetInstrumentSpace()->GetInstrument();
bool kf_fixed = true; bool kf_fixed = true;
if(m_pathsbuilder && m_pathsbuilder->GetTasCalculator()) if(m_pathsbuilder && m_pathsbuilder->GetTasCalculator())
......
...@@ -130,10 +130,10 @@ void PathsRenderer::LoadInstrument(const InstrumentSpace& instrspace) ...@@ -130,10 +130,10 @@ void PathsRenderer::LoadInstrument(const InstrumentSpace& instrspace)
m_objs[lowerFloor].m_mat(2,3) = -0.01; m_objs[lowerFloor].m_mat(2,3) = -0.01;
// instrument // instrument
const auto& instr = instrspace.GetInstrument(); const Instrument& instr = instrspace.GetInstrument();
const auto& mono = instr.GetMonochromator(); const Axis& mono = instr.GetMonochromator();
const auto& sample = instr.GetSample(); const Axis& sample = instr.GetSample();
const auto& ana = instr.GetAnalyser(); const Axis& ana = instr.GetAnalyser();
for(const Axis* axis : { &mono, &sample, &ana }) for(const Axis* axis : { &mono, &sample, &ana })
{ {
......
...@@ -400,6 +400,12 @@ bool PathsTool::OpenFile(const QString &file) ...@@ -400,6 +400,12 @@ bool PathsTool::OpenFile(const QString &file)
m_instrspace.GetInstrument().AddUpdateSlot( m_instrspace.GetInstrument().AddUpdateSlot(
[this](const Instrument& instr) [this](const Instrument& instr)
{ {
if(&instr != &m_instrspace.GetInstrument())
{
std::cerr << "Error: Received update from unknown instrument." << std::endl;
return;
}
// is ki or kf fixed? // is ki or kf fixed?
bool kf_fixed = true; bool kf_fixed = true;
if(!std::get<1>(m_tascalc.GetKfix())) if(!std::get<1>(m_tascalc.GetKfix()))
...@@ -410,9 +416,9 @@ bool PathsTool::OpenFile(const QString &file) ...@@ -410,9 +416,9 @@ bool PathsTool::OpenFile(const QString &file)
t_real oldA2 = m_tasProperties->GetWidget()->GetMonoScatteringAngle()/t_real{180}*tl2::pi<t_real>; t_real oldA2 = m_tasProperties->GetWidget()->GetMonoScatteringAngle()/t_real{180}*tl2::pi<t_real>;
// get scattering angles // get scattering angles
t_real monoScAngle = m_instrspace.GetInstrument().GetMonochromator().GetAxisAngleOut(); t_real monoScAngle = instr.GetMonochromator().GetAxisAngleOut();
t_real sampleScAngle = m_instrspace.GetInstrument().GetSample().GetAxisAngleOut(); t_real sampleScAngle = instr.GetSample().GetAxisAngleOut();
t_real anaScAngle = m_instrspace.GetInstrument().GetAnalyser().GetAxisAngleOut(); t_real anaScAngle = instr.GetAnalyser().GetAxisAngleOut();
// set scattering angles // set scattering angles
m_tasProperties->GetWidget()->SetMonoScatteringAngle(monoScAngle*t_real{180}/tl2::pi<t_real>); m_tasProperties->GetWidget()->SetMonoScatteringAngle(monoScAngle*t_real{180}/tl2::pi<t_real>);
...@@ -420,9 +426,9 @@ bool PathsTool::OpenFile(const QString &file) ...@@ -420,9 +426,9 @@ bool PathsTool::OpenFile(const QString &file)
m_tasProperties->GetWidget()->SetAnaScatteringAngle(anaScAngle*t_real{180}/tl2::pi<t_real>); m_tasProperties->GetWidget()->SetAnaScatteringAngle(anaScAngle*t_real{180}/tl2::pi<t_real>);
// get crystal rocking angles // get crystal rocking angles
t_real monoXtalAngle = m_instrspace.GetInstrument().GetMonochromator().GetAxisAngleInternal(); t_real monoXtalAngle = instr.GetMonochromator().GetAxisAngleInternal();
t_real sampleXtalAngle = m_instrspace.GetInstrument().GetSample().GetAxisAngleInternal(); t_real sampleXtalAngle = instr.GetSample().GetAxisAngleInternal();
t_real anaXtalAngle = m_instrspace.GetInstrument().GetAnalyser().GetAxisAngleInternal(); t_real anaXtalAngle = instr.GetAnalyser().GetAxisAngleInternal();
// set crystal rocking angles // set crystal rocking angles
m_tasProperties->GetWidget()->SetMonoCrystalAngle(monoXtalAngle*t_real{180}/tl2::pi<t_real>); m_tasProperties->GetWidget()->SetMonoCrystalAngle(monoXtalAngle*t_real{180}/tl2::pi<t_real>);
...@@ -632,7 +638,7 @@ void PathsTool::GotoCoordinates( ...@@ -632,7 +638,7 @@ void PathsTool::GotoCoordinates(
// set instrument angles // set instrument angles
else else
{ {
auto& instr = m_instrspace.GetInstrument(); Instrument& instr = m_instrspace.GetInstrument();
// send one update signal at the end // send one update signal at the end
// and not after each angle change // and not after each angle change
...@@ -698,7 +704,7 @@ void PathsTool::GotoAngles(std::optional<t_real> a1, ...@@ -698,7 +704,7 @@ void PathsTool::GotoAngles(std::optional<t_real> a1,
// set instrument angles // set instrument angles
else else
{ {
auto& instr = m_instrspace.GetInstrument(); Instrument& instr = m_instrspace.GetInstrument();
// send one update signal at the end // send one update signal at the end
// and not after each angle change // and not after each angle change
...@@ -1789,6 +1795,7 @@ void PathsTool::InitSettings() ...@@ -1789,6 +1795,7 @@ void PathsTool::InitSettings()
m_pathsbuilder.SetTryDirectPath(g_try_direct_path != 0); m_pathsbuilder.SetTryDirectPath(g_try_direct_path != 0);
m_pathsbuilder.SetVerifyPath(g_verifypath != 0); m_pathsbuilder.SetVerifyPath(g_verifypath != 0);
m_pathsbuilder.SetMinDistToWalls(g_min_dist_to_walls); m_pathsbuilder.SetMinDistToWalls(g_min_dist_to_walls);
m_pathsbuilder.SetRemoveBisectorsBelowMinWallDist(g_remove_bisectors_below_min_wall_dist != 0);
//m_pathsbuilder.SetUseRegionFunction(g_use_region_function != 0); //m_pathsbuilder.SetUseRegionFunction(g_use_region_function != 0);
QMainWindow::DockOptions dockoptions{}; QMainWindow::DockOptions dockoptions{};
...@@ -2105,7 +2112,7 @@ void PathsTool::CalculatePathMesh() ...@@ -2105,7 +2112,7 @@ void PathsTool::CalculatePathMesh()
return; \ return; \
} }
const auto& instr = m_instrspace.GetInstrument(); const Instrument& instr = m_instrspace.GetInstrument();
// get the angular limits from the instrument model // get the angular limits from the instrument model
t_real starta2 = instr.GetMonochromator().GetAxisAngleOutLowerLimit(); t_real starta2 = instr.GetMonochromator().GetAxisAngleOutLowerLimit();
......
...@@ -484,6 +484,7 @@ void XtalConfigSpaceDlg::Calculate() ...@@ -484,6 +484,7 @@ void XtalConfigSpaceDlg::Calculate()
auto task = [this, img_w, img_row, vec1start, vec1end, yparam, E]() auto task = [this, img_w, img_row, vec1start, vec1end, yparam, E]()
{ {
InstrumentSpace instrspace_cpy = *this->m_instrspace; InstrumentSpace instrspace_cpy = *this->m_instrspace;
Instrument& instr = instrspace_cpy.GetInstrument();
for(std::size_t img_col=0; img_col<img_w; ++img_col) for(std::size_t img_col=0; img_col<img_w; ++img_col)
{ {
...@@ -496,20 +497,14 @@ void XtalConfigSpaceDlg::Calculate() ...@@ -496,20 +497,14 @@ void XtalConfigSpaceDlg::Calculate()
if(angles.mono_ok && angles.ana_ok && angles.sample_ok) if(angles.mono_ok && angles.ana_ok && angles.sample_ok)
{ {
// set scattering angles // set scattering angles
instrspace_cpy.GetInstrument().GetMonochromator(). instr.GetMonochromator().SetAxisAngleOut(angles.monoXtalAngle * t_real{2});
SetAxisAngleOut(angles.monoXtalAngle * t_real{2}); instr.GetSample().SetAxisAngleOut(angles.sampleScatteringAngle);
instrspace_cpy.GetInstrument().GetSample(). instr.GetAnalyser().SetAxisAngleOut(angles.anaXtalAngle * t_real{2});
SetAxisAngleOut(angles.sampleScatteringAngle);
instrspace_cpy.GetInstrument().GetAnalyser().
SetAxisAngleOut(angles.anaXtalAngle * t_real{2});
// set crystal angles // set crystal angles
instrspace_cpy.GetInstrument().GetMonochromator(). instr.GetMonochromator().SetAxisAngleInternal(angles.monoXtalAngle);
SetAxisAngleInternal(angles.monoXtalAngle); instr.GetSample().SetAxisAngleInternal(angles.sampleXtalAngle);
instrspace_cpy.GetInstrument().GetSample(). instr.GetAnalyser().SetAxisAngleInternal(angles.anaXtalAngle);
SetAxisAngleInternal(angles.sampleXtalAngle);
instrspace_cpy.GetInstrument().GetAnalyser().
SetAxisAngleInternal(angles.anaXtalAngle);
} }
else else
{ {
......
...@@ -73,6 +73,9 @@ int g_voronoi_backend = 0; ...@@ -73,6 +73,9 @@ int g_voronoi_backend = 0;
// use region calculation function // use region calculation function
int g_use_region_function = 1; int g_use_region_function = 1;
// use bisector verification function
int g_remove_bisectors_below_min_wall_dist = 1;
// path-finding options // path-finding options
int g_pathstrategy = 0; int g_pathstrategy = 0;
......
...@@ -85,6 +85,9 @@ extern int g_voronoi_backend; ...@@ -85,6 +85,9 @@ extern int g_voronoi_backend;
// use region calculation function // use region calculation function
extern int g_use_region_function; extern int g_use_region_function;
// use bisector verification function
extern int g_remove_bisectors_below_min_wall_dist;
// which path finding strategy to use? // which path finding strategy to use?
// 0: shortest path, 1: avoid walls // 0: shortest path, 1: avoid walls
...@@ -147,7 +150,7 @@ extern int g_nested_docks; ...@@ -147,7 +150,7 @@ extern int g_nested_docks;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// variables register // variables register
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
constexpr std::array<SettingsVariable, 25> g_settingsvariables constexpr std::array<SettingsVariable, 26> g_settingsvariables
{{ {{
// epsilons and precisions // epsilons and precisions
{ {
...@@ -242,6 +245,12 @@ constexpr std::array<SettingsVariable, 25> g_settingsvariables ...@@ -242,6 +245,12 @@ constexpr std::array<SettingsVariable, 25> g_settingsvariables
.value = &g_use_region_function, .value = &g_use_region_function,
.editor = SettingsVariableEditor::YESNO, .editor = SettingsVariableEditor::YESNO,
}, },
{
.description = "Remove bisectors close to walls",
.key = "settings/remove_bisectors_below_min_wall_dist",
.value = &g_remove_bisectors_below_min_wall_dist,
.editor = SettingsVariableEditor::YESNO,
},
// path options // path options
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment