From c3deee3e812d151e7ad14324e8c618235c1e5c1e Mon Sep 17 00:00:00 2001
From: Walter Van Herck <w.van.herck@fz-juelich.de>
Date: Fri, 26 Jan 2018 16:54:58 +0100
Subject: [PATCH] Implement result() in OffSpecSimulation, removed some code
 duplication, fixed python example

---
 Core/Simulation/GISASSimulation.cpp           |   5 -
 Core/Simulation/GISASSimulation.h             |   7 +-
 Core/Simulation/OffSpecSimulation.cpp         |  12 +-
 Core/Simulation/OffSpecSimulation.h           |   6 +-
 Core/Simulation/Simulation2D.cpp              |   5 +
 Core/Simulation/Simulation2D.h                |   9 +
 .../AxesInDifferentUnits.py                   |   2 +-
 auto/Wrap/libBornAgainCore.py                 |  45 ++-
 auto/Wrap/libBornAgainCore_wrap.cpp           | 338 +++++++-----------
 9 files changed, 187 insertions(+), 242 deletions(-)

diff --git a/Core/Simulation/GISASSimulation.cpp b/Core/Simulation/GISASSimulation.cpp
index 3ae073cd79d..29bef2256b9 100644
--- a/Core/Simulation/GISASSimulation.cpp
+++ b/Core/Simulation/GISASSimulation.cpp
@@ -76,11 +76,6 @@ SimulationResult GISASSimulation::result() const
                              "wrong or absent detector type");
 }
 
-OutputData<double>* GISASSimulation::getDetectorIntensity(AxesUnits units_type) const
-{
-    return result().data(units_type);
-}
-
 void GISASSimulation::setBeamParameters(double wavelength, double alpha_i, double phi_i)
 {
     if (wavelength<=0.0)
diff --git a/Core/Simulation/GISASSimulation.h b/Core/Simulation/GISASSimulation.h
index e43c90432ba..3fb8a84efa7 100644
--- a/Core/Simulation/GISASSimulation.h
+++ b/Core/Simulation/GISASSimulation.h
@@ -17,7 +17,6 @@
 
 #include "Simulation2D.h"
 #include "SimulationElement.h"
-#include "SimulationResult.h"
 
 class MultiLayer;
 class IMultiLayerBuilder;
@@ -48,11 +47,7 @@ public:
 
     //! Returns the results of the simulation in a format that supports unit conversion and export
     //! to numpy arrays
-    SimulationResult result() const;
-
-    //! Returns clone of the detector intensity map with detector resolution applied
-    OutputData<double>* getDetectorIntensity(
-            AxesUnits units_type = AxesUnits::DEFAULT) const override;
+    SimulationResult result() const override;
 
     //! Sets beam parameters from here (forwarded to Instrument)
     void setBeamParameters(double wavelength, double alpha_i, double phi_i);
diff --git a/Core/Simulation/OffSpecSimulation.cpp b/Core/Simulation/OffSpecSimulation.cpp
index 974c4f40905..ac0290a57db 100644
--- a/Core/Simulation/OffSpecSimulation.cpp
+++ b/Core/Simulation/OffSpecSimulation.cpp
@@ -49,10 +49,16 @@ size_t OffSpecSimulation::numberOfSimulationElements() const
     return getInstrument().getDetector()->numberOfSimulationElements()*mP_alpha_i_axis->size();
 }
 
-OutputData<double>*OffSpecSimulation::getDetectorIntensity(AxesUnits units_type) const
+SimulationResult OffSpecSimulation::result() const
 {
-    (void)units_type;
-    return m_intensity_map.clone();
+    auto data = std::unique_ptr<OutputData<double>>(m_intensity_map.clone());
+    auto p_det = dynamic_cast<const IDetector2D*>(getInstrument().getDetector());
+    if (p_det) {
+        OffSpecularConverter converter(*p_det, getInstrument().getBeam(), *mP_alpha_i_axis);
+        return SimulationResult(*data, converter);
+    }
+    throw std::runtime_error("Error in OffSpecSimulation::result: "
+                             "wrong or absent detector type");
 }
 
 void OffSpecSimulation::setBeamParameters(double lambda, const IAxis& alpha_axis, double phi_i)
diff --git a/Core/Simulation/OffSpecSimulation.h b/Core/Simulation/OffSpecSimulation.h
index 6d3180e4cd2..3bf4873f1e7 100644
--- a/Core/Simulation/OffSpecSimulation.h
+++ b/Core/Simulation/OffSpecSimulation.h
@@ -42,9 +42,9 @@ public:
     //! Gets the number of elements this simulation needs to calculate
     size_t numberOfSimulationElements() const final;
 
-    //! Returns clone of the detector intensity map
-    OutputData<double>* getDetectorIntensity(
-            AxesUnits units_type = AxesUnits::DEFAULT) const override;
+    //! Returns the results of the simulation in a format that supports unit conversion and export
+    //! to numpy arrays
+    SimulationResult result() const override;
 
     //! Sets beam parameters from here (forwarded to Instrument)
     void setBeamParameters(double lambda, const IAxis& alpha_axis, double phi_i);
diff --git a/Core/Simulation/Simulation2D.cpp b/Core/Simulation/Simulation2D.cpp
index 59a77175e2c..15d03355c1f 100644
--- a/Core/Simulation/Simulation2D.cpp
+++ b/Core/Simulation/Simulation2D.cpp
@@ -77,6 +77,11 @@ void Simulation2D::setDetector(const IDetector2D& detector)
     initUnitConverter();
 }
 
+OutputData<double>* Simulation2D::getDetectorIntensity(AxesUnits units_type) const
+{
+    return result().data(units_type);
+}
+
 Histogram2D* Simulation2D::getIntensityData(AxesUnits units_type) const
 {
     std::unique_ptr<OutputData<double>> data(getDetectorIntensity(units_type));
diff --git a/Core/Simulation/Simulation2D.h b/Core/Simulation/Simulation2D.h
index 161cae2a14c..5b74d84731f 100644
--- a/Core/Simulation/Simulation2D.h
+++ b/Core/Simulation/Simulation2D.h
@@ -16,6 +16,7 @@
 #define SIMULATION2D_H
 
 #include "Simulation.h"
+#include "SimulationResult.h"
 
 //! Pure virtual base class of OffSpecularSimulation and GISASSimulation.
 //! Holds the common implementations for simulations with a 2D detector
@@ -44,6 +45,14 @@ public:
     //! Sets the detector (axes can be overwritten later)
     void setDetector(const IDetector2D& detector);
 
+    //! Returns the results of the simulation in a format that supports unit conversion and export
+    //! to numpy arrays
+    virtual SimulationResult result() const=0;
+
+    //! Returns clone of the detector intensity map with detector resolution applied
+    OutputData<double>* getDetectorIntensity(
+            AxesUnits units_type = AxesUnits::DEFAULT) const override;
+
     //! Returns histogram representing intensity map in requested axes units
     Histogram2D* getIntensityData(AxesUnits units_type = AxesUnits::DEFAULT) const;
 
diff --git a/Examples/python/simulation/ex06_Miscellaneous/AxesInDifferentUnits.py b/Examples/python/simulation/ex06_Miscellaneous/AxesInDifferentUnits.py
index 56fce2b6d28..03b890aa804 100644
--- a/Examples/python/simulation/ex06_Miscellaneous/AxesInDifferentUnits.py
+++ b/Examples/python/simulation/ex06_Miscellaneous/AxesInDifferentUnits.py
@@ -71,7 +71,7 @@ def run_simulation():
     results['mm'] = simulation.getIntensityData()
     results['nbins'] = simulation.getIntensityData(ba.AxesUnits.NBINS)
     results['deg'] = simulation.getIntensityData(ba.AxesUnits.DEGREES)
-    results['qyqz'] = simulation.getIntensityData(ba.AxesUnits.QYQZ)
+    results['qyqz'] = simulation.getIntensityData(ba.AxesUnits.QSPACE)
 
     return results
 
diff --git a/auto/Wrap/libBornAgainCore.py b/auto/Wrap/libBornAgainCore.py
index 4015cb61e33..3c0f28dc129 100644
--- a/auto/Wrap/libBornAgainCore.py
+++ b/auto/Wrap/libBornAgainCore.py
@@ -16605,6 +16605,24 @@ class Simulation2D(Simulation):
         return _libBornAgainCore.Simulation2D_setDetector(self, detector)
 
 
+    def result(self):
+        """result(Simulation2D self) -> SimulationResult"""
+        return _libBornAgainCore.Simulation2D_result(self)
+
+
+    def getDetectorIntensity(self, *args):
+        """
+        getDetectorIntensity(Simulation2D self, AxesUnits units_type) -> IntensityData
+        getDetectorIntensity(Simulation2D self) -> IntensityData
+
+        virtual OutputData<double>* Simulation::getDetectorIntensity(AxesUnits units_type=AxesUnits::DEFAULT) const =0
+
+        Clone simulated intensity map. 
+
+        """
+        return _libBornAgainCore.Simulation2D_getDetectorIntensity(self, *args)
+
+
     def getIntensityData(self, *args):
         """
         getIntensityData(Simulation2D self, AxesUnits units_type) -> Histogram2D
@@ -16920,19 +16938,6 @@ class GISASSimulation(Simulation2D):
         return _libBornAgainCore.GISASSimulation_result(self)
 
 
-    def getDetectorIntensity(self, *args):
-        """
-        getDetectorIntensity(GISASSimulation self, AxesUnits units_type) -> IntensityData
-        getDetectorIntensity(GISASSimulation self) -> IntensityData
-
-        OutputData< double > * GISASSimulation::getDetectorIntensity(AxesUnits units_type=AxesUnits::DEFAULT) const override
-
-        Returns clone of the detector intensity map with detector resolution applied. 
-
-        """
-        return _libBornAgainCore.GISASSimulation_getDetectorIntensity(self, *args)
-
-
     def setBeamParameters(self, wavelength, alpha_i, phi_i):
         """
         setBeamParameters(GISASSimulation self, double wavelength, double alpha_i, double phi_i)
@@ -23691,17 +23696,9 @@ class OffSpecSimulation(Simulation2D):
         return _libBornAgainCore.OffSpecSimulation_numberOfSimulationElements(self)
 
 
-    def getDetectorIntensity(self, *args):
-        """
-        getDetectorIntensity(OffSpecSimulation self, AxesUnits units_type) -> IntensityData
-        getDetectorIntensity(OffSpecSimulation self) -> IntensityData
-
-        OutputData<double>* OffSpecSimulation::getDetectorIntensity(AxesUnits units_type=AxesUnits::DEFAULT) const override
-
-        Returns clone of the detector intensity map. 
-
-        """
-        return _libBornAgainCore.OffSpecSimulation_getDetectorIntensity(self, *args)
+    def result(self):
+        """result(OffSpecSimulation self) -> SimulationResult"""
+        return _libBornAgainCore.OffSpecSimulation_result(self)
 
 
     def setBeamParameters(self, arg2, alpha_axis, phi_i):
diff --git a/auto/Wrap/libBornAgainCore_wrap.cpp b/auto/Wrap/libBornAgainCore_wrap.cpp
index 3b7c3cb9acd..981dae40c17 100644
--- a/auto/Wrap/libBornAgainCore_wrap.cpp
+++ b/auto/Wrap/libBornAgainCore_wrap.cpp
@@ -77864,6 +77864,127 @@ fail:
 }
 
 
+SWIGINTERN PyObject *_wrap_Simulation2D_result(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+  PyObject *resultobj = 0;
+  Simulation2D *arg1 = (Simulation2D *) 0 ;
+  void *argp1 = 0 ;
+  int res1 = 0 ;
+  PyObject * obj0 = 0 ;
+  SimulationResult result;
+  
+  if (!PyArg_ParseTuple(args,(char *)"O:Simulation2D_result",&obj0)) SWIG_fail;
+  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Simulation2D, 0 |  0 );
+  if (!SWIG_IsOK(res1)) {
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Simulation2D_result" "', argument " "1"" of type '" "Simulation2D const *""'"); 
+  }
+  arg1 = reinterpret_cast< Simulation2D * >(argp1);
+  result = ((Simulation2D const *)arg1)->result();
+  resultobj = SWIG_NewPointerObj((new SimulationResult(static_cast< const SimulationResult& >(result))), SWIGTYPE_p_SimulationResult, SWIG_POINTER_OWN |  0 );
+  return resultobj;
+fail:
+  return NULL;
+}
+
+
+SWIGINTERN PyObject *_wrap_Simulation2D_getDetectorIntensity__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+  PyObject *resultobj = 0;
+  Simulation2D *arg1 = (Simulation2D *) 0 ;
+  AxesUnits arg2 ;
+  void *argp1 = 0 ;
+  int res1 = 0 ;
+  int val2 ;
+  int ecode2 = 0 ;
+  PyObject * obj0 = 0 ;
+  PyObject * obj1 = 0 ;
+  OutputData< double > *result = 0 ;
+  
+  if (!PyArg_ParseTuple(args,(char *)"OO:Simulation2D_getDetectorIntensity",&obj0,&obj1)) SWIG_fail;
+  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Simulation2D, 0 |  0 );
+  if (!SWIG_IsOK(res1)) {
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Simulation2D_getDetectorIntensity" "', argument " "1"" of type '" "Simulation2D const *""'"); 
+  }
+  arg1 = reinterpret_cast< Simulation2D * >(argp1);
+  ecode2 = SWIG_AsVal_int(obj1, &val2);
+  if (!SWIG_IsOK(ecode2)) {
+    SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "Simulation2D_getDetectorIntensity" "', argument " "2"" of type '" "AxesUnits""'");
+  } 
+  arg2 = static_cast< AxesUnits >(val2);
+  result = (OutputData< double > *)((Simulation2D const *)arg1)->getDetectorIntensity(arg2);
+  resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_OutputDataT_double_t, 0 |  0 );
+  return resultobj;
+fail:
+  return NULL;
+}
+
+
+SWIGINTERN PyObject *_wrap_Simulation2D_getDetectorIntensity__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+  PyObject *resultobj = 0;
+  Simulation2D *arg1 = (Simulation2D *) 0 ;
+  void *argp1 = 0 ;
+  int res1 = 0 ;
+  PyObject * obj0 = 0 ;
+  OutputData< double > *result = 0 ;
+  
+  if (!PyArg_ParseTuple(args,(char *)"O:Simulation2D_getDetectorIntensity",&obj0)) SWIG_fail;
+  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_Simulation2D, 0 |  0 );
+  if (!SWIG_IsOK(res1)) {
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Simulation2D_getDetectorIntensity" "', argument " "1"" of type '" "Simulation2D const *""'"); 
+  }
+  arg1 = reinterpret_cast< Simulation2D * >(argp1);
+  result = (OutputData< double > *)((Simulation2D const *)arg1)->getDetectorIntensity();
+  resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_OutputDataT_double_t, 0 |  0 );
+  return resultobj;
+fail:
+  return NULL;
+}
+
+
+SWIGINTERN PyObject *_wrap_Simulation2D_getDetectorIntensity(PyObject *self, PyObject *args) {
+  Py_ssize_t argc;
+  PyObject *argv[3] = {
+    0
+  };
+  Py_ssize_t ii;
+  
+  if (!PyTuple_Check(args)) SWIG_fail;
+  argc = args ? PyObject_Length(args) : 0;
+  for (ii = 0; (ii < 2) && (ii < argc); ii++) {
+    argv[ii] = PyTuple_GET_ITEM(args,ii);
+  }
+  if (argc == 1) {
+    int _v;
+    void *vptr = 0;
+    int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_Simulation2D, 0);
+    _v = SWIG_CheckState(res);
+    if (_v) {
+      return _wrap_Simulation2D_getDetectorIntensity__SWIG_1(self, args);
+    }
+  }
+  if (argc == 2) {
+    int _v;
+    void *vptr = 0;
+    int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_Simulation2D, 0);
+    _v = SWIG_CheckState(res);
+    if (_v) {
+      {
+        int res = SWIG_AsVal_int(argv[1], NULL);
+        _v = SWIG_CheckState(res);
+      }
+      if (_v) {
+        return _wrap_Simulation2D_getDetectorIntensity__SWIG_0(self, args);
+      }
+    }
+  }
+  
+fail:
+  SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number or type of arguments for overloaded function 'Simulation2D_getDetectorIntensity'.\n"
+    "  Possible C/C++ prototypes are:\n"
+    "    Simulation2D::getDetectorIntensity(AxesUnits) const\n"
+    "    Simulation2D::getDetectorIntensity() const\n");
+  return 0;
+}
+
+
 SWIGINTERN PyObject *_wrap_Simulation2D_getIntensityData__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *resultobj = 0;
   Simulation2D *arg1 = (Simulation2D *) 0 ;
@@ -78970,105 +79091,6 @@ fail:
 }
 
 
-SWIGINTERN PyObject *_wrap_GISASSimulation_getDetectorIntensity__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
-  PyObject *resultobj = 0;
-  GISASSimulation *arg1 = (GISASSimulation *) 0 ;
-  AxesUnits arg2 ;
-  void *argp1 = 0 ;
-  int res1 = 0 ;
-  int val2 ;
-  int ecode2 = 0 ;
-  PyObject * obj0 = 0 ;
-  PyObject * obj1 = 0 ;
-  OutputData< double > *result = 0 ;
-  
-  if (!PyArg_ParseTuple(args,(char *)"OO:GISASSimulation_getDetectorIntensity",&obj0,&obj1)) SWIG_fail;
-  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_GISASSimulation, 0 |  0 );
-  if (!SWIG_IsOK(res1)) {
-    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "GISASSimulation_getDetectorIntensity" "', argument " "1"" of type '" "GISASSimulation const *""'"); 
-  }
-  arg1 = reinterpret_cast< GISASSimulation * >(argp1);
-  ecode2 = SWIG_AsVal_int(obj1, &val2);
-  if (!SWIG_IsOK(ecode2)) {
-    SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "GISASSimulation_getDetectorIntensity" "', argument " "2"" of type '" "AxesUnits""'");
-  } 
-  arg2 = static_cast< AxesUnits >(val2);
-  result = (OutputData< double > *)((GISASSimulation const *)arg1)->getDetectorIntensity(arg2);
-  resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_OutputDataT_double_t, SWIG_POINTER_OWN |  0 );
-  return resultobj;
-fail:
-  return NULL;
-}
-
-
-SWIGINTERN PyObject *_wrap_GISASSimulation_getDetectorIntensity__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
-  PyObject *resultobj = 0;
-  GISASSimulation *arg1 = (GISASSimulation *) 0 ;
-  void *argp1 = 0 ;
-  int res1 = 0 ;
-  PyObject * obj0 = 0 ;
-  OutputData< double > *result = 0 ;
-  
-  if (!PyArg_ParseTuple(args,(char *)"O:GISASSimulation_getDetectorIntensity",&obj0)) SWIG_fail;
-  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_GISASSimulation, 0 |  0 );
-  if (!SWIG_IsOK(res1)) {
-    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "GISASSimulation_getDetectorIntensity" "', argument " "1"" of type '" "GISASSimulation const *""'"); 
-  }
-  arg1 = reinterpret_cast< GISASSimulation * >(argp1);
-  result = (OutputData< double > *)((GISASSimulation const *)arg1)->getDetectorIntensity();
-  resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_OutputDataT_double_t, SWIG_POINTER_OWN |  0 );
-  return resultobj;
-fail:
-  return NULL;
-}
-
-
-SWIGINTERN PyObject *_wrap_GISASSimulation_getDetectorIntensity(PyObject *self, PyObject *args) {
-  Py_ssize_t argc;
-  PyObject *argv[3] = {
-    0
-  };
-  Py_ssize_t ii;
-  
-  if (!PyTuple_Check(args)) SWIG_fail;
-  argc = args ? PyObject_Length(args) : 0;
-  for (ii = 0; (ii < 2) && (ii < argc); ii++) {
-    argv[ii] = PyTuple_GET_ITEM(args,ii);
-  }
-  if (argc == 1) {
-    int _v;
-    void *vptr = 0;
-    int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_GISASSimulation, 0);
-    _v = SWIG_CheckState(res);
-    if (_v) {
-      return _wrap_GISASSimulation_getDetectorIntensity__SWIG_1(self, args);
-    }
-  }
-  if (argc == 2) {
-    int _v;
-    void *vptr = 0;
-    int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_GISASSimulation, 0);
-    _v = SWIG_CheckState(res);
-    if (_v) {
-      {
-        int res = SWIG_AsVal_int(argv[1], NULL);
-        _v = SWIG_CheckState(res);
-      }
-      if (_v) {
-        return _wrap_GISASSimulation_getDetectorIntensity__SWIG_0(self, args);
-      }
-    }
-  }
-  
-fail:
-  SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number or type of arguments for overloaded function 'GISASSimulation_getDetectorIntensity'.\n"
-    "  Possible C/C++ prototypes are:\n"
-    "    GISASSimulation::getDetectorIntensity(AxesUnits) const\n"
-    "    GISASSimulation::getDetectorIntensity() const\n");
-  return 0;
-}
-
-
 SWIGINTERN PyObject *_wrap_GISASSimulation_setBeamParameters(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *resultobj = 0;
   GISASSimulation *arg1 = (GISASSimulation *) 0 ;
@@ -99526,105 +99548,28 @@ fail:
 }
 
 
-SWIGINTERN PyObject *_wrap_OffSpecSimulation_getDetectorIntensity__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
-  PyObject *resultobj = 0;
-  OffSpecSimulation *arg1 = (OffSpecSimulation *) 0 ;
-  AxesUnits arg2 ;
-  void *argp1 = 0 ;
-  int res1 = 0 ;
-  int val2 ;
-  int ecode2 = 0 ;
-  PyObject * obj0 = 0 ;
-  PyObject * obj1 = 0 ;
-  OutputData< double > *result = 0 ;
-  
-  if (!PyArg_ParseTuple(args,(char *)"OO:OffSpecSimulation_getDetectorIntensity",&obj0,&obj1)) SWIG_fail;
-  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_OffSpecSimulation, 0 |  0 );
-  if (!SWIG_IsOK(res1)) {
-    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "OffSpecSimulation_getDetectorIntensity" "', argument " "1"" of type '" "OffSpecSimulation const *""'"); 
-  }
-  arg1 = reinterpret_cast< OffSpecSimulation * >(argp1);
-  ecode2 = SWIG_AsVal_int(obj1, &val2);
-  if (!SWIG_IsOK(ecode2)) {
-    SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "OffSpecSimulation_getDetectorIntensity" "', argument " "2"" of type '" "AxesUnits""'");
-  } 
-  arg2 = static_cast< AxesUnits >(val2);
-  result = (OutputData< double > *)((OffSpecSimulation const *)arg1)->getDetectorIntensity(arg2);
-  resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_OutputDataT_double_t, SWIG_POINTER_OWN |  0 );
-  return resultobj;
-fail:
-  return NULL;
-}
-
-
-SWIGINTERN PyObject *_wrap_OffSpecSimulation_getDetectorIntensity__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+SWIGINTERN PyObject *_wrap_OffSpecSimulation_result(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *resultobj = 0;
   OffSpecSimulation *arg1 = (OffSpecSimulation *) 0 ;
   void *argp1 = 0 ;
   int res1 = 0 ;
   PyObject * obj0 = 0 ;
-  OutputData< double > *result = 0 ;
+  SimulationResult result;
   
-  if (!PyArg_ParseTuple(args,(char *)"O:OffSpecSimulation_getDetectorIntensity",&obj0)) SWIG_fail;
+  if (!PyArg_ParseTuple(args,(char *)"O:OffSpecSimulation_result",&obj0)) SWIG_fail;
   res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_OffSpecSimulation, 0 |  0 );
   if (!SWIG_IsOK(res1)) {
-    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "OffSpecSimulation_getDetectorIntensity" "', argument " "1"" of type '" "OffSpecSimulation const *""'"); 
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "OffSpecSimulation_result" "', argument " "1"" of type '" "OffSpecSimulation const *""'"); 
   }
   arg1 = reinterpret_cast< OffSpecSimulation * >(argp1);
-  result = (OutputData< double > *)((OffSpecSimulation const *)arg1)->getDetectorIntensity();
-  resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_OutputDataT_double_t, SWIG_POINTER_OWN |  0 );
+  result = ((OffSpecSimulation const *)arg1)->result();
+  resultobj = SWIG_NewPointerObj((new SimulationResult(static_cast< const SimulationResult& >(result))), SWIGTYPE_p_SimulationResult, SWIG_POINTER_OWN |  0 );
   return resultobj;
 fail:
   return NULL;
 }
 
 
-SWIGINTERN PyObject *_wrap_OffSpecSimulation_getDetectorIntensity(PyObject *self, PyObject *args) {
-  Py_ssize_t argc;
-  PyObject *argv[3] = {
-    0
-  };
-  Py_ssize_t ii;
-  
-  if (!PyTuple_Check(args)) SWIG_fail;
-  argc = args ? PyObject_Length(args) : 0;
-  for (ii = 0; (ii < 2) && (ii < argc); ii++) {
-    argv[ii] = PyTuple_GET_ITEM(args,ii);
-  }
-  if (argc == 1) {
-    int _v;
-    void *vptr = 0;
-    int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_OffSpecSimulation, 0);
-    _v = SWIG_CheckState(res);
-    if (_v) {
-      return _wrap_OffSpecSimulation_getDetectorIntensity__SWIG_1(self, args);
-    }
-  }
-  if (argc == 2) {
-    int _v;
-    void *vptr = 0;
-    int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_OffSpecSimulation, 0);
-    _v = SWIG_CheckState(res);
-    if (_v) {
-      {
-        int res = SWIG_AsVal_int(argv[1], NULL);
-        _v = SWIG_CheckState(res);
-      }
-      if (_v) {
-        return _wrap_OffSpecSimulation_getDetectorIntensity__SWIG_0(self, args);
-      }
-    }
-  }
-  
-fail:
-  SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number or type of arguments for overloaded function 'OffSpecSimulation_getDetectorIntensity'.\n"
-    "  Possible C/C++ prototypes are:\n"
-    "    OffSpecSimulation::getDetectorIntensity(AxesUnits) const\n"
-    "    OffSpecSimulation::getDetectorIntensity() const\n");
-  return 0;
-}
-
-
 SWIGINTERN PyObject *_wrap_OffSpecSimulation_setBeamParameters(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *resultobj = 0;
   OffSpecSimulation *arg1 = (OffSpecSimulation *) 0 ;
@@ -121396,6 +121341,16 @@ static PyMethodDef SwigMethods[] = {
 		"\n"
 		""},
 	 { (char *)"Simulation2D_setDetector", _wrap_Simulation2D_setDetector, METH_VARARGS, (char *)"Simulation2D_setDetector(Simulation2D self, IDetector2D detector)"},
+	 { (char *)"Simulation2D_result", _wrap_Simulation2D_result, METH_VARARGS, (char *)"Simulation2D_result(Simulation2D self) -> SimulationResult"},
+	 { (char *)"Simulation2D_getDetectorIntensity", _wrap_Simulation2D_getDetectorIntensity, METH_VARARGS, (char *)"\n"
+		"getDetectorIntensity(AxesUnits units_type) -> IntensityData\n"
+		"Simulation2D_getDetectorIntensity(Simulation2D self) -> IntensityData\n"
+		"\n"
+		"virtual OutputData<double>* Simulation::getDetectorIntensity(AxesUnits units_type=AxesUnits::DEFAULT) const =0\n"
+		"\n"
+		"Clone simulated intensity map. \n"
+		"\n"
+		""},
 	 { (char *)"Simulation2D_getIntensityData", _wrap_Simulation2D_getIntensityData, METH_VARARGS, (char *)"\n"
 		"getIntensityData(AxesUnits units_type) -> Histogram2D\n"
 		"Simulation2D_getIntensityData(Simulation2D self) -> Histogram2D\n"
@@ -121564,15 +121519,6 @@ static PyMethodDef SwigMethods[] = {
 		"\n"
 		""},
 	 { (char *)"GISASSimulation_result", _wrap_GISASSimulation_result, METH_VARARGS, (char *)"GISASSimulation_result(GISASSimulation self) -> SimulationResult"},
-	 { (char *)"GISASSimulation_getDetectorIntensity", _wrap_GISASSimulation_getDetectorIntensity, METH_VARARGS, (char *)"\n"
-		"getDetectorIntensity(AxesUnits units_type) -> IntensityData\n"
-		"GISASSimulation_getDetectorIntensity(GISASSimulation self) -> IntensityData\n"
-		"\n"
-		"OutputData< double > * GISASSimulation::getDetectorIntensity(AxesUnits units_type=AxesUnits::DEFAULT) const override\n"
-		"\n"
-		"Returns clone of the detector intensity map with detector resolution applied. \n"
-		"\n"
-		""},
 	 { (char *)"GISASSimulation_setBeamParameters", _wrap_GISASSimulation_setBeamParameters, METH_VARARGS, (char *)"\n"
 		"GISASSimulation_setBeamParameters(GISASSimulation self, double wavelength, double alpha_i, double phi_i)\n"
 		"\n"
@@ -125398,15 +125344,7 @@ static PyMethodDef SwigMethods[] = {
 		"Gets the number of elements this simulation needs to calculate. \n"
 		"\n"
 		""},
-	 { (char *)"OffSpecSimulation_getDetectorIntensity", _wrap_OffSpecSimulation_getDetectorIntensity, METH_VARARGS, (char *)"\n"
-		"getDetectorIntensity(AxesUnits units_type) -> IntensityData\n"
-		"OffSpecSimulation_getDetectorIntensity(OffSpecSimulation self) -> IntensityData\n"
-		"\n"
-		"OutputData<double>* OffSpecSimulation::getDetectorIntensity(AxesUnits units_type=AxesUnits::DEFAULT) const override\n"
-		"\n"
-		"Returns clone of the detector intensity map. \n"
-		"\n"
-		""},
+	 { (char *)"OffSpecSimulation_result", _wrap_OffSpecSimulation_result, METH_VARARGS, (char *)"OffSpecSimulation_result(OffSpecSimulation self) -> SimulationResult"},
 	 { (char *)"OffSpecSimulation_setBeamParameters", _wrap_OffSpecSimulation_setBeamParameters, METH_VARARGS, (char *)"\n"
 		"OffSpecSimulation_setBeamParameters(OffSpecSimulation self, double arg3, IAxis alpha_axis, double phi_i)\n"
 		"\n"
-- 
GitLab