From 449bba18f272279972b0374fa9f8c5b39d4498ee Mon Sep 17 00:00:00 2001
From: Walter Van Herck <w.van.herck@fz-juelich.de>
Date: Wed, 21 Sep 2016 13:19:25 +0200
Subject: [PATCH] Remove IPixelMap::contains() and replace its usage by
 SimulationElement::containsSpecularWavevector()

---
 Core/Binning/IPixelMap.h                |   1 -
 Core/Binning/SimulationElement.cpp      |   3 +-
 Core/Instrument/IDetector2D.cpp         |   3 +
 Core/Instrument/RectangularDetector.cpp |   5 -
 Core/Instrument/RectangularDetector.h   |   1 -
 Core/Instrument/SphericalDetector.cpp   |  15 ---
 Core/Instrument/SphericalDetector.h     |   1 -
 auto/Wrap/libBornAgainCore.py           |  15 ---
 auto/Wrap/libBornAgainCore_wrap.cpp     | 120 ------------------------
 9 files changed, 4 insertions(+), 160 deletions(-)

diff --git a/Core/Binning/IPixelMap.h b/Core/Binning/IPixelMap.h
index 5d95947a1ab..7906be197f4 100644
--- a/Core/Binning/IPixelMap.h
+++ b/Core/Binning/IPixelMap.h
@@ -31,7 +31,6 @@ public:
     virtual kvector_t getK(double x, double y, double wavelength) const=0;
     virtual double getIntegrationFactor(double x, double y) const=0;
     virtual double getSolidAngle() const=0;
-    virtual bool contains(kvector_t k) const=0;
 };
 
 #endif // IPIXELMAP_H
diff --git a/Core/Binning/SimulationElement.cpp b/Core/Binning/SimulationElement.cpp
index aaee117d627..2caabca3bf2 100644
--- a/Core/Binning/SimulationElement.cpp
+++ b/Core/Binning/SimulationElement.cpp
@@ -106,8 +106,7 @@ double SimulationElement::getPhi(double x, double y) const
 
 bool SimulationElement::containsSpecularWavevector() const
 {
-    kvector_t k = vecOfLambdaAlphaPhi(m_wavelength, -m_alpha_i, m_phi_i);
-    return mP_pixel_map->contains(k);
+    return  m_contains_specular;
 }
 
 void SimulationElement::setSpecular(bool contains_specular)
diff --git a/Core/Instrument/IDetector2D.cpp b/Core/Instrument/IDetector2D.cpp
index 5cf945f2604..5dbc171e0d9 100644
--- a/Core/Instrument/IDetector2D.cpp
+++ b/Core/Instrument/IDetector2D.cpp
@@ -185,6 +185,9 @@ std::vector<SimulationElement> IDetector2D::createSimulationElements(const Beam
         SimulationElement sim_element(wavelength, alpha_i, phi_i, P_pixel_map.get());
         sim_element.setPolarization(beam_polarization);
         sim_element.setAnalyzerOperator(analyzer_operator);
+        if (index==getIndexOfSpecular()) {
+            sim_element.setSpecular(true);
+        }
         result.push_back(sim_element);
     }
     return result;
diff --git a/Core/Instrument/RectangularDetector.cpp b/Core/Instrument/RectangularDetector.cpp
index 2805ac78fc7..9ba43191950 100644
--- a/Core/Instrument/RectangularDetector.cpp
+++ b/Core/Instrument/RectangularDetector.cpp
@@ -427,11 +427,6 @@ double RectPixelMap::getSolidAngle() const
     return m_solid_angle;
 }
 
-bool RectPixelMap::contains(kvector_t) const
-{
-    return false;
-}
-
 kvector_t RectPixelMap::normalizeLength(const kvector_t direction, double length) const
 {
     return direction.unit()*length;
diff --git a/Core/Instrument/RectangularDetector.h b/Core/Instrument/RectangularDetector.h
index 27678bab96a..e9a21d194dc 100644
--- a/Core/Instrument/RectangularDetector.h
+++ b/Core/Instrument/RectangularDetector.h
@@ -133,7 +133,6 @@ public:
     kvector_t getK(double x, double y, double wavelength) const override;
     double getIntegrationFactor(double x, double y) const override;
     double getSolidAngle() const override;
-    bool contains(kvector_t k) const override;
 private:
     kvector_t normalizeLength(const kvector_t direction, double length) const;
     double calculateSolidAngle() const;
diff --git a/Core/Instrument/SphericalDetector.cpp b/Core/Instrument/SphericalDetector.cpp
index 15b0cde6255..86ecc7721a3 100644
--- a/Core/Instrument/SphericalDetector.cpp
+++ b/Core/Instrument/SphericalDetector.cpp
@@ -182,10 +182,8 @@ std::string SphericalDetector::getAxisName(size_t index) const
     switch (index) {
     case 0:
         return BornAgain::PHI_AXIS_NAME;
-        break;
     case 1:
         return BornAgain::ALPHA_AXIS_NAME;
-        break;
     default:
         throw Exceptions::LogicErrorException(
             "SphericalDetector::getAxisName(size_t index) -> Error! index > 1");
@@ -239,16 +237,3 @@ double AngularPixelMap::getSolidAngle() const
     if (m_solid_angle<=0.0) return 1.0;
     return m_solid_angle;
 }
-
-bool AngularPixelMap::contains(kvector_t k) const
-{
-    if (m_dalpha==0.0) return false;
-    if (m_dphi==0.0) return false;
-    double alpha = M_PI_2 - k.theta();
-    double x = (alpha - m_alpha)/m_dalpha;
-    if (x<0.0 || x>=1.0) return false;
-    double phi = k.phi();
-    double y = (phi - m_phi)/m_dphi;
-    if (y<0.0 || y>=1.0) return false;
-    return true;
-}
diff --git a/Core/Instrument/SphericalDetector.h b/Core/Instrument/SphericalDetector.h
index dd8bb6f85b9..5faa7bc6c31 100644
--- a/Core/Instrument/SphericalDetector.h
+++ b/Core/Instrument/SphericalDetector.h
@@ -90,7 +90,6 @@ public:
     kvector_t getK(double x, double y, double wavelength) const override;
     double getIntegrationFactor(double x, double y) const override;
     double getSolidAngle() const override;
-    bool contains(kvector_t k) const override;
 private:
     double m_alpha, m_phi;
     double m_dalpha, m_dphi;
diff --git a/auto/Wrap/libBornAgainCore.py b/auto/Wrap/libBornAgainCore.py
index 92093e8a1ee..589a2fd5e1d 100644
--- a/auto/Wrap/libBornAgainCore.py
+++ b/auto/Wrap/libBornAgainCore.py
@@ -19546,11 +19546,6 @@ class IPixelMap(_object):
         """
         return _libBornAgainCore.IPixelMap_getSolidAngle(self)
 
-
-    def contains(self, k):
-        """contains(IPixelMap self, kvector_t k) -> bool"""
-        return _libBornAgainCore.IPixelMap_contains(self, k)
-
 IPixelMap_swigregister = _libBornAgainCore.IPixelMap_swigregister
 IPixelMap_swigregister(IPixelMap)
 
@@ -19716,11 +19711,6 @@ class AngularPixelMap(IPixelMap):
         """
         return _libBornAgainCore.AngularPixelMap_getSolidAngle(self)
 
-
-    def contains(self, k):
-        """contains(AngularPixelMap self, kvector_t k) -> bool"""
-        return _libBornAgainCore.AngularPixelMap_contains(self, k)
-
 AngularPixelMap_swigregister = _libBornAgainCore.AngularPixelMap_swigregister
 AngularPixelMap_swigregister(AngularPixelMap)
 
@@ -23956,11 +23946,6 @@ class RectPixelMap(IPixelMap):
         """
         return _libBornAgainCore.RectPixelMap_getSolidAngle(self)
 
-
-    def contains(self, k):
-        """contains(RectPixelMap self, kvector_t k) -> bool"""
-        return _libBornAgainCore.RectPixelMap_contains(self, k)
-
 RectPixelMap_swigregister = _libBornAgainCore.RectPixelMap_swigregister
 RectPixelMap_swigregister(RectPixelMap)
 
diff --git a/auto/Wrap/libBornAgainCore_wrap.cpp b/auto/Wrap/libBornAgainCore_wrap.cpp
index 2cf29c2da72..81ac4ae2b0f 100644
--- a/auto/Wrap/libBornAgainCore_wrap.cpp
+++ b/auto/Wrap/libBornAgainCore_wrap.cpp
@@ -83216,45 +83216,6 @@ fail:
 }
 
 
-SWIGINTERN PyObject *_wrap_IPixelMap_contains(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
-  PyObject *resultobj = 0;
-  IPixelMap *arg1 = (IPixelMap *) 0 ;
-  kvector_t arg2 ;
-  void *argp1 = 0 ;
-  int res1 = 0 ;
-  void *argp2 ;
-  int res2 = 0 ;
-  PyObject * obj0 = 0 ;
-  PyObject * obj1 = 0 ;
-  bool result;
-  
-  if (!PyArg_ParseTuple(args,(char *)"OO:IPixelMap_contains",&obj0,&obj1)) SWIG_fail;
-  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_IPixelMap, 0 |  0 );
-  if (!SWIG_IsOK(res1)) {
-    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "IPixelMap_contains" "', argument " "1"" of type '" "IPixelMap const *""'"); 
-  }
-  arg1 = reinterpret_cast< IPixelMap * >(argp1);
-  {
-    res2 = SWIG_ConvertPtr(obj1, &argp2, SWIGTYPE_p_BasicVector3DT_double_t,  0  | 0);
-    if (!SWIG_IsOK(res2)) {
-      SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "IPixelMap_contains" "', argument " "2"" of type '" "kvector_t""'"); 
-    }  
-    if (!argp2) {
-      SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "IPixelMap_contains" "', argument " "2"" of type '" "kvector_t""'");
-    } else {
-      kvector_t * temp = reinterpret_cast< kvector_t * >(argp2);
-      arg2 = *temp;
-      if (SWIG_IsNewObj(res2)) delete temp;
-    }
-  }
-  result = (bool)((IPixelMap const *)arg1)->contains(arg2);
-  resultobj = SWIG_From_bool(static_cast< bool >(result));
-  return resultobj;
-fail:
-  return NULL;
-}
-
-
 SWIGINTERN PyObject *IPixelMap_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *obj;
   if (!PyArg_ParseTuple(args,(char*)"O:swigregister", &obj)) return NULL;
@@ -83819,45 +83780,6 @@ fail:
 }
 
 
-SWIGINTERN PyObject *_wrap_AngularPixelMap_contains(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
-  PyObject *resultobj = 0;
-  AngularPixelMap *arg1 = (AngularPixelMap *) 0 ;
-  kvector_t arg2 ;
-  void *argp1 = 0 ;
-  int res1 = 0 ;
-  void *argp2 ;
-  int res2 = 0 ;
-  PyObject * obj0 = 0 ;
-  PyObject * obj1 = 0 ;
-  bool result;
-  
-  if (!PyArg_ParseTuple(args,(char *)"OO:AngularPixelMap_contains",&obj0,&obj1)) SWIG_fail;
-  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_AngularPixelMap, 0 |  0 );
-  if (!SWIG_IsOK(res1)) {
-    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "AngularPixelMap_contains" "', argument " "1"" of type '" "AngularPixelMap const *""'"); 
-  }
-  arg1 = reinterpret_cast< AngularPixelMap * >(argp1);
-  {
-    res2 = SWIG_ConvertPtr(obj1, &argp2, SWIGTYPE_p_BasicVector3DT_double_t,  0  | 0);
-    if (!SWIG_IsOK(res2)) {
-      SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "AngularPixelMap_contains" "', argument " "2"" of type '" "kvector_t""'"); 
-    }  
-    if (!argp2) {
-      SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "AngularPixelMap_contains" "', argument " "2"" of type '" "kvector_t""'");
-    } else {
-      kvector_t * temp = reinterpret_cast< kvector_t * >(argp2);
-      arg2 = *temp;
-      if (SWIG_IsNewObj(res2)) delete temp;
-    }
-  }
-  result = (bool)((AngularPixelMap const *)arg1)->contains(arg2);
-  resultobj = SWIG_From_bool(static_cast< bool >(result));
-  return resultobj;
-fail:
-  return NULL;
-}
-
-
 SWIGINTERN PyObject *AngularPixelMap_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *obj;
   if (!PyArg_ParseTuple(args,(char*)"O:swigregister", &obj)) return NULL;
@@ -98352,45 +98274,6 @@ fail:
 }
 
 
-SWIGINTERN PyObject *_wrap_RectPixelMap_contains(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
-  PyObject *resultobj = 0;
-  RectPixelMap *arg1 = (RectPixelMap *) 0 ;
-  kvector_t arg2 ;
-  void *argp1 = 0 ;
-  int res1 = 0 ;
-  void *argp2 ;
-  int res2 = 0 ;
-  PyObject * obj0 = 0 ;
-  PyObject * obj1 = 0 ;
-  bool result;
-  
-  if (!PyArg_ParseTuple(args,(char *)"OO:RectPixelMap_contains",&obj0,&obj1)) SWIG_fail;
-  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_RectPixelMap, 0 |  0 );
-  if (!SWIG_IsOK(res1)) {
-    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "RectPixelMap_contains" "', argument " "1"" of type '" "RectPixelMap const *""'"); 
-  }
-  arg1 = reinterpret_cast< RectPixelMap * >(argp1);
-  {
-    res2 = SWIG_ConvertPtr(obj1, &argp2, SWIGTYPE_p_BasicVector3DT_double_t,  0  | 0);
-    if (!SWIG_IsOK(res2)) {
-      SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "RectPixelMap_contains" "', argument " "2"" of type '" "kvector_t""'"); 
-    }  
-    if (!argp2) {
-      SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "RectPixelMap_contains" "', argument " "2"" of type '" "kvector_t""'");
-    } else {
-      kvector_t * temp = reinterpret_cast< kvector_t * >(argp2);
-      arg2 = *temp;
-      if (SWIG_IsNewObj(res2)) delete temp;
-    }
-  }
-  result = (bool)((RectPixelMap const *)arg1)->contains(arg2);
-  resultobj = SWIG_From_bool(static_cast< bool >(result));
-  return resultobj;
-fail:
-  return NULL;
-}
-
-
 SWIGINTERN PyObject *RectPixelMap_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *obj;
   if (!PyArg_ParseTuple(args,(char*)"O:swigregister", &obj)) return NULL;
@@ -110017,7 +109900,6 @@ static PyMethodDef SwigMethods[] = {
 		"virtual double IPixelMap::getSolidAngle() const =0\n"
 		"\n"
 		""},
-	 { (char *)"IPixelMap_contains", _wrap_IPixelMap_contains, METH_VARARGS, (char *)"IPixelMap_contains(IPixelMap self, kvector_t k) -> bool"},
 	 { (char *)"IPixelMap_swigregister", IPixelMap_swigregister, METH_VARARGS, NULL},
 	 { (char *)"new_SphericalDetector", _wrap_new_SphericalDetector, METH_VARARGS, (char *)"\n"
 		"SphericalDetector()\n"
@@ -110106,7 +109988,6 @@ static PyMethodDef SwigMethods[] = {
 		"double AngularPixelMap::getSolidAngle() const \n"
 		"\n"
 		""},
-	 { (char *)"AngularPixelMap_contains", _wrap_AngularPixelMap_contains, METH_VARARGS, (char *)"AngularPixelMap_contains(AngularPixelMap self, kvector_t k) -> bool"},
 	 { (char *)"AngularPixelMap_swigregister", AngularPixelMap_swigregister, METH_VARARGS, NULL},
 	 { (char *)"new_IsGISAXSDetector", _wrap_new_IsGISAXSDetector, METH_VARARGS, (char *)"\n"
 		"IsGISAXSDetector()\n"
@@ -112534,7 +112415,6 @@ static PyMethodDef SwigMethods[] = {
 		"double RectPixelMap::getSolidAngle() const \n"
 		"\n"
 		""},
-	 { (char *)"RectPixelMap_contains", _wrap_RectPixelMap_contains, METH_VARARGS, (char *)"RectPixelMap_contains(RectPixelMap self, kvector_t k) -> bool"},
 	 { (char *)"RectPixelMap_swigregister", RectPixelMap_swigregister, METH_VARARGS, NULL},
 	 { (char *)"new_ResolutionFunction2DGaussian", _wrap_new_ResolutionFunction2DGaussian, METH_VARARGS, (char *)"\n"
 		"new_ResolutionFunction2DGaussian(double sigma_x, double sigma_y) -> ResolutionFunction2DGaussian\n"
-- 
GitLab