From 338ed1f30be585105988afc257d92ada334f07cc Mon Sep 17 00:00:00 2001
From: Walter Van Herck <w.van.herck@fz-juelich.de>
Date: Fri, 3 Feb 2017 15:56:38 +0100
Subject: [PATCH] Set Fresnel map directly in constructor of IComputationTerm

---
 Core/Computation/IComputationTerm.cpp           | 10 +++-------
 Core/Computation/IComputationTerm.h             |  6 +-----
 Core/Computation/MainComputation.cpp            | 16 +++++-----------
 Core/Computation/MainComputation.h              |  1 -
 Core/Computation/ParticleLayoutComputation.cpp  |  3 ++-
 Core/Computation/ParticleLayoutComputation.h    |  5 +++--
 Core/Computation/RoughMultiLayerComputation.cpp | 11 +++++------
 Core/Computation/RoughMultiLayerComputation.h   |  3 ++-
 Core/Computation/SpecularComputation.cpp        |  5 +++--
 Core/Computation/SpecularComputation.h          |  2 +-
 10 files changed, 25 insertions(+), 37 deletions(-)

diff --git a/Core/Computation/IComputationTerm.cpp b/Core/Computation/IComputationTerm.cpp
index c459ee2264b..8cc7196a709 100644
--- a/Core/Computation/IComputationTerm.cpp
+++ b/Core/Computation/IComputationTerm.cpp
@@ -16,15 +16,11 @@
 #include "IComputationTerm.h"
 
 
-IComputationTerm::IComputationTerm(const MultiLayer* p_multilayer)
+IComputationTerm::IComputationTerm(const MultiLayer* p_multilayer,
+                                   const ILayerSpecularInfo* p_fresnel_map)
     : mp_multilayer(p_multilayer)
-    , mp_fresnel_map(nullptr)
+    , mp_fresnel_map(p_fresnel_map)
 {}
 
 IComputationTerm::~IComputationTerm()
 {}
-
-void IComputationTerm::setSpecularInfo(const ILayerSpecularInfo* p_full_map)
-{
-    mp_fresnel_map = p_full_map;
-}
diff --git a/Core/Computation/IComputationTerm.h b/Core/Computation/IComputationTerm.h
index 74ba09f736a..14b6d4b510e 100644
--- a/Core/Computation/IComputationTerm.h
+++ b/Core/Computation/IComputationTerm.h
@@ -18,7 +18,6 @@
 
 #include <vector>
 
-
 class ILayerSpecularInfo;
 class MultiLayer;
 class ProgressHandler;
@@ -33,12 +32,9 @@ class SimulationOptions;
 class IComputationTerm
 {
 public:
-    IComputationTerm(const MultiLayer* p_multilayer);
+    IComputationTerm(const MultiLayer* p_multilayer, const ILayerSpecularInfo* p_fresnel_map);
     virtual ~IComputationTerm();
 
-    //! Sets magnetic reflection/transmission info for all layers
-    void setSpecularInfo(const ILayerSpecularInfo* p_full_map);
-
     //! Calculate scattering intensity for each SimulationElement
     //! returns false if nothing needed to be calculated
     virtual bool eval(const SimulationOptions& options,
diff --git a/Core/Computation/MainComputation.cpp b/Core/Computation/MainComputation.cpp
index 1fd7ddd3e8e..ee14f38d6eb 100644
--- a/Core/Computation/MainComputation.cpp
+++ b/Core/Computation/MainComputation.cpp
@@ -47,15 +47,16 @@ MainComputation::MainComputation(
         const Layer* layer = mP_multi_layer->getLayer(i);
         for (size_t j=0; j<layer->getNumberOfLayouts(); ++j)
             m_computation_terms.push_back(
-                        new ParticleLayoutComputation(mP_multi_layer.get(),
+                        new ParticleLayoutComputation(mP_multi_layer.get(), mP_fresnel_map.get(),
                                                       layer->getLayout(j), i));
     }
     // scattering from rough surfaces in DWBA
     if (mP_multi_layer->hasRoughness())
-        m_computation_terms.push_back(new RoughMultiLayerComputation(mP_multi_layer.get()));
+        m_computation_terms.push_back(new RoughMultiLayerComputation(mP_multi_layer.get(),
+                                                                     mP_fresnel_map.get()));
     if (m_sim_options.includeSpecular())
-        m_computation_terms.push_back(new SpecularComputation(mP_multi_layer.get()));
-    passFresnelInfo();
+        m_computation_terms.push_back(new SpecularComputation(mP_multi_layer.get(),
+                                                              mP_fresnel_map.get()));
 }
 
 MainComputation::~MainComputation()
@@ -96,13 +97,6 @@ void MainComputation::runProtected()
     }
 }
 
-void MainComputation::passFresnelInfo()
-{
-    for (IComputationTerm* comp: m_computation_terms) {
-        comp->setSpecularInfo(mP_fresnel_map.get());
-    }
-}
-
 ILayerSpecularInfo* MainComputation::createFresnelMap(const MultiLayer* p_multilayer,
                                                       const MultiLayer* p_inverted_multilayer)
 {
diff --git a/Core/Computation/MainComputation.h b/Core/Computation/MainComputation.h
index c26d976ff53..8c055a286f3 100644
--- a/Core/Computation/MainComputation.h
+++ b/Core/Computation/MainComputation.h
@@ -54,7 +54,6 @@ public:
 
 private:
     void runProtected();
-    void passFresnelInfo();
     static ILayerSpecularInfo* createFresnelMap(const MultiLayer* p_multilayer,
                                                 const MultiLayer* p_inverted_multilayer);
 
diff --git a/Core/Computation/ParticleLayoutComputation.cpp b/Core/Computation/ParticleLayoutComputation.cpp
index 597a64cba50..aa39fee13dc 100644
--- a/Core/Computation/ParticleLayoutComputation.cpp
+++ b/Core/Computation/ParticleLayoutComputation.cpp
@@ -25,8 +25,9 @@
 #include "SimulationElement.h"
 
 ParticleLayoutComputation::ParticleLayoutComputation(const MultiLayer* p_multilayer,
+                                                     const ILayerSpecularInfo* p_fresnel_map,
                                                      const ILayout* p_layout, size_t layer_index)
-    : IComputationTerm(p_multilayer)
+    : IComputationTerm(p_multilayer, p_fresnel_map)
     , mp_layout(p_layout)
     , m_layer_index(layer_index)
 {}
diff --git a/Core/Computation/ParticleLayoutComputation.h b/Core/Computation/ParticleLayoutComputation.h
index 715f6c1d259..35f94b8d37a 100644
--- a/Core/Computation/ParticleLayoutComputation.h
+++ b/Core/Computation/ParticleLayoutComputation.h
@@ -29,8 +29,9 @@ class ILayout;
 class ParticleLayoutComputation final : public IComputationTerm
 {
 public:
-    ParticleLayoutComputation(const MultiLayer* p_multilayer, const ILayout* p_layout,
-                              size_t layer_index);
+    ParticleLayoutComputation(
+        const MultiLayer* p_multilayer, const ILayerSpecularInfo* p_fresnel_map,
+        const ILayout* p_layout, size_t layer_index);
 
     bool eval(const SimulationOptions& options,
               ProgressHandler* progress,
diff --git a/Core/Computation/RoughMultiLayerComputation.cpp b/Core/Computation/RoughMultiLayerComputation.cpp
index fde554f2df9..3820f3cd87d 100644
--- a/Core/Computation/RoughMultiLayerComputation.cpp
+++ b/Core/Computation/RoughMultiLayerComputation.cpp
@@ -40,14 +40,13 @@ namespace {
     }
 }
 
-RoughMultiLayerComputation::RoughMultiLayerComputation(const MultiLayer *p_multi_layer)
-    : IComputationTerm(p_multi_layer)
-{
-}
+RoughMultiLayerComputation::RoughMultiLayerComputation(const MultiLayer *p_multi_layer,
+                                                       const ILayerSpecularInfo* p_fresnel_map)
+    : IComputationTerm(p_multi_layer, p_fresnel_map)
+{}
 
 RoughMultiLayerComputation::~RoughMultiLayerComputation()
-{
-}
+{}
 
 bool RoughMultiLayerComputation::eval(
     const SimulationOptions&, ProgressHandler* progress, bool,
diff --git a/Core/Computation/RoughMultiLayerComputation.h b/Core/Computation/RoughMultiLayerComputation.h
index c54d014cbf4..7bc027302b4 100644
--- a/Core/Computation/RoughMultiLayerComputation.h
+++ b/Core/Computation/RoughMultiLayerComputation.h
@@ -30,7 +30,8 @@ class SimulationElement;
 class RoughMultiLayerComputation final : public IComputationTerm
 {
 public:
-    RoughMultiLayerComputation(const MultiLayer* p_multi_layer);
+    RoughMultiLayerComputation(const MultiLayer* p_multi_layer,
+                               const ILayerSpecularInfo* p_fresnel_map);
     ~RoughMultiLayerComputation();
 
     bool eval(const SimulationOptions& options,
diff --git a/Core/Computation/SpecularComputation.cpp b/Core/Computation/SpecularComputation.cpp
index 25cae08d66a..250372351bc 100644
--- a/Core/Computation/SpecularComputation.cpp
+++ b/Core/Computation/SpecularComputation.cpp
@@ -19,8 +19,9 @@
 #include "ILayerRTCoefficients.h"
 #include "MultiLayer.h"
 
-SpecularComputation::SpecularComputation(const MultiLayer* p_multi_layer)
-    : IComputationTerm(p_multi_layer)
+SpecularComputation::SpecularComputation(const MultiLayer* p_multi_layer,
+                                         const ILayerSpecularInfo* p_fresnel_map)
+    : IComputationTerm(p_multi_layer, p_fresnel_map)
 {}
 
 bool SpecularComputation::eval(
diff --git a/Core/Computation/SpecularComputation.h b/Core/Computation/SpecularComputation.h
index 688f14b730b..e74ac0cb219 100644
--- a/Core/Computation/SpecularComputation.h
+++ b/Core/Computation/SpecularComputation.h
@@ -25,7 +25,7 @@
 class SpecularComputation final : public IComputationTerm
 {
 public:
-    SpecularComputation(const MultiLayer* p_multi_layer);
+    SpecularComputation(const MultiLayer* p_multi_layer, const ILayerSpecularInfo* p_fresnel_map);
 
     bool eval(const SimulationOptions& options,
               ProgressHandler* progress,
-- 
GitLab