[arrayfire] 35/284: adds scatter3

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:16 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/experimental
in repository arrayfire.

commit 6f52c36b5bd09657c1b40b16669f03b813916a17
Author: syurkevi <stefan at arrayfire.com>
Date:   Mon Nov 23 18:38:04 2015 -0500

    adds scatter3
---
 include/af/graphics.h         | 36 ++++++++++++++++++++++++++++++++----
 src/api/c/graphics_common.cpp | 23 ++++++++++++++++++++---
 src/api/c/graphics_common.hpp |  3 ++-
 src/api/c/plot.cpp            | 15 ++-------------
 src/api/c/plot3.cpp           | 29 ++++++++++++++++++++---------
 src/api/cpp/graphics.cpp      |  8 +++++++-
 src/api/unified/graphics.cpp  | 10 ++++++++--
 7 files changed, 91 insertions(+), 33 deletions(-)

diff --git a/include/af/graphics.h b/include/af/graphics.h
index e4286e1..129b439 100644
--- a/include/af/graphics.h
+++ b/include/af/graphics.h
@@ -177,7 +177,6 @@ class AFAPI Window {
 
            \ingroup gfx_func_draw
          */
-
         void plot(const array& X, const array& Y, const char* const title=NULL);
 
         /**
@@ -192,8 +191,19 @@ class AFAPI Window {
 
            \ingroup gfx_func_draw
          */
-
         void scatter(const array& X, const array& Y, const af::markerType marker=AF_MARKER_POINT, const char* const title=NULL);
+
+        /**
+           Renders the input arrays as a 2D scatter-plot to the window
+
+           \param[in]   P is an \ref af_array or matrix with the xyz-values of the points
+           \param[in] marker is an \ref markerType enum specifying which marker to use in the scatter plot
+           \param[in] title parameter is used when this function is called in grid mode
+
+           \ingroup gfx_func_draw
+         */
+        void scatter3(const array& P, const af::markerType marker=AF_MARKER_POINT, const char* const title=NULL);
+
         /**
            Renders the input array as a histogram to the window
 
@@ -392,8 +402,8 @@ AFAPI af_err af_draw_plot(const af_window wind, const af_array X, const af_array
    \param[in]   wind is the window handle
    \param[in]   X is an \ref af_array with the x-axis data points
    \param[in]   Y is an \ref af_array with the y-axis data points
+   \param[in]   marker is an \ref markerType enum specifying which marker to use in the scatter plot
    \param[in]   props is structure \ref af_cell that has the properties that are used
-   \param[in] marker is an \ref markerType enum specifying which marker to use in the scatter plot
    for the current rendering.
 
    \return     \ref AF_SUCCESS if rendering is successful, otherwise an appropriate error code
@@ -403,7 +413,7 @@ AFAPI af_err af_draw_plot(const af_window wind, const af_array X, const af_array
 
    \ingroup gfx_func_draw
 */
-AFAPI af_err af_draw_scatter(const af_window wind, const af_array X, const af_array Y, const af_cell* const props, const af_marker_type marker);
+AFAPI af_err af_draw_scatter(const af_window wind, const af_array X, const af_array Y, const af_marker_type marker, const af_cell* const props);
 #endif
 
 #if AF_API_VERSION >= 32
@@ -412,6 +422,24 @@ AFAPI af_err af_draw_scatter(const af_window wind, const af_array X, const af_ar
 
    \param[in]   wind is the window handle
    \param[in]   P is an \ref af_array or matrix with the xyz-values of the points
+   \param[in]   marker is an \ref markerType enum specifying which marker to use in the scatter plot
+   \param[in]   props is structure \ref af_cell that has the properties that are used
+   for the current rendering.
+
+   \return     \ref AF_SUCCESS if rendering is successful, otherwise an appropriate error code
+   is returned.
+
+   \ingroup gfx_func_draw
+*/
+AFAPI af_err af_draw_scatter3(const af_window wind, const af_array P, const af_marker_type marker, const af_cell* const props);
+
+#endif
+#if AF_API_VERSION >= 32
+/**
+   C Interface wrapper for drawing an array as a plot
+
+   \param[in]   wind is the window handle
+   \param[in]   P is an \ref af_array or matrix with the xyz-values of the points
    \param[in]   props is structure \ref af_cell that has the properties that are used
    for the current rendering.
 
diff --git a/src/api/c/graphics_common.cpp b/src/api/c/graphics_common.cpp
index 92346f5..a4132b5 100644
--- a/src/api/c/graphics_common.cpp
+++ b/src/api/c/graphics_common.cpp
@@ -19,6 +19,22 @@ using namespace std;
 template<typename T>
 GLenum getGLType() { return GL_FLOAT; }
 
+fg::MarkerType getFGMarker(const af_marker_type af_marker) {
+    fg::MarkerType fg_marker;
+    switch (af_marker) {
+        case AF_MARKER_NONE: fg_marker = fg::FG_NONE; break;
+        case AF_MARKER_POINT: fg_marker = fg::FG_POINT; break;
+        case AF_MARKER_CIRCLE: fg_marker = fg::FG_CIRCLE; break;
+        case AF_MARKER_SQUARE: fg_marker = fg::FG_SQUARE; break;
+        case AF_MARKER_TRIANGLE: fg_marker = fg::FG_TRIANGLE; break;
+        case AF_MARKER_CROSS: fg_marker = fg::FG_CROSS; break;
+        case AF_MARKER_PLUS: fg_marker = fg::FG_PLUS; break;
+        case AF_MARKER_STAR: fg_marker = fg::FG_STAR; break;
+        default: fg_marker = fg::FG_NONE; break;
+    }
+    return fg_marker;
+}
+
 #define INSTANTIATE_GET_FG_TYPE(T, ForgeEnum)\
     template<> fg::dtype getGLType<T>() { return ForgeEnum; }
 
@@ -181,7 +197,7 @@ fg::Plot* ForgeManager::getPlot(int nPoints, fg::dtype dtype, fg::PlotType ptype
     return mPltMap[key];
 }
 
-fg::Plot3* ForgeManager::getPlot3(int nPoints, fg::dtype type)
+fg::Plot3* ForgeManager::getPlot3(int nPoints, fg::dtype dtype, fg::PlotType ptype, fg::MarkerType mtype)
 {
     /* nPoints needs to fall in the range of [0, 2^48]
      * for the ForgeManager to correctly retrieve
@@ -189,11 +205,12 @@ fg::Plot3* ForgeManager::getPlot3(int nPoints, fg::dtype type)
      * is a limitation on how big of an plot graph can be rendered
      * using arrayfire graphics funtionality */
     assert(nPoints <= 2ll<<48);
-    long long key = ((nPoints & _48BIT) << 48) | (type & _16BIT);
+    long long key = ((nPoints & _48BIT) << 48);
+    key |= (((((dtype & 0x000F) << 12) | (ptype & 0x000F)) << 8) | (mtype & 0x000F));
 
     Plt3MapIter iter = mPlt3Map.find(key);
     if (iter==mPlt3Map.end()) {
-        fg::Plot3* temp = new fg::Plot3(nPoints, type);
+        fg::Plot3* temp = new fg::Plot3(nPoints, dtype, ptype, mtype);
         mPlt3Map[key] = temp;
     }
 
diff --git a/src/api/c/graphics_common.hpp b/src/api/c/graphics_common.hpp
index caadb88..8c7607f 100644
--- a/src/api/c/graphics_common.hpp
+++ b/src/api/c/graphics_common.hpp
@@ -30,6 +30,7 @@ GLenum glForceErrorCheck(const char *msg, const char* file, int line);
 #define ForceCheckGL(msg) glForceErrorCheck(msg, __FILE__, __LINE__)
 #define CheckGLSkip(msg)  glErrorSkip      (msg, __FILE__, __LINE__)
 
+fg::MarkerType getFGMarker(const af_marker_type af_marker);
 namespace graphics
 {
 
@@ -83,7 +84,7 @@ class ForgeManager
         fg::Window* getMainWindow(const bool dontCreate=false);
         fg::Image* getImage(int w, int h, fg::ChannelFormat mode, fg::dtype type);
         fg::Plot* getPlot(int nPoints, fg::dtype dtype, fg::PlotType ptype, fg::MarkerType mtype);
-        fg::Plot3* getPlot3(int nPoints, fg::dtype type);
+        fg::Plot3* getPlot3(int nPoints, fg::dtype dtype,fg::PlotType ptype, fg::MarkerType mtype);
         fg::Histogram* getHistogram(int nBins, fg::dtype type);
         fg::Surface* getSurface(int nX, int nY, fg::dtype type);
 
diff --git a/src/api/c/plot.cpp b/src/api/c/plot.cpp
index f274030..c58a894 100644
--- a/src/api/c/plot.cpp
+++ b/src/api/c/plot.cpp
@@ -111,19 +111,8 @@ af_err af_draw_plot(const af_window wind, const af_array X, const af_array Y, co
     return plotWrapper(wind, X, Y, props);
 }
 
-af_err af_draw_scatter(const af_window wind, const af_array X, const af_array Y, const af_cell* const props, const af::markerType af_marker)
+af_err af_draw_scatter(const af_window wind, const af_array X, const af_array Y, const af_marker_type af_marker, const af_cell* const props)
 {
-    fg::MarkerType fg_marker;
-    switch(af_marker){
-        case AF_MARKER_NONE: fg_marker = fg::FG_NONE; break;
-        case AF_MARKER_POINT: fg_marker = fg::FG_POINT; break;
-        case AF_MARKER_CIRCLE: fg_marker = fg::FG_CIRCLE; break;
-        case AF_MARKER_SQUARE: fg_marker = fg::FG_SQUARE; break;
-        case AF_MARKER_TRIANGLE: fg_marker = fg::FG_TRIANGLE; break;
-        case AF_MARKER_CROSS: fg_marker = fg::FG_CROSS; break;
-        case AF_MARKER_PLUS: fg_marker = fg::FG_PLUS; break;
-        case AF_MARKER_STAR: fg_marker = fg::FG_STAR; break;
-        default: fg_marker = fg::FG_NONE; break;
-    }
+    fg::MarkerType fg_marker = getFGMarker(af_marker);
     return plotWrapper(wind, X, Y, props, fg::FG_SCATTER, fg_marker);
 }
diff --git a/src/api/c/plot3.cpp b/src/api/c/plot3.cpp
index 473bce0..4d31105 100644
--- a/src/api/c/plot3.cpp
+++ b/src/api/c/plot3.cpp
@@ -30,7 +30,7 @@ using namespace detail;
 using namespace graphics;
 
 template<typename T>
-fg::Plot3* setup_plot3(const af_array P)
+fg::Plot3* setup_plot3(const af_array P, fg::PlotType ptype, fg::MarkerType mtype)
 {
     Array<T> pIn = getArray<T>(P);
     ArrayInfo Pinfo = getInfo(P);
@@ -58,7 +58,7 @@ fg::Plot3* setup_plot3(const af_array P)
     }
 
     ForgeManager& fgMngr = ForgeManager::getInstance();
-    fg::Plot3* plot3 = fgMngr.getPlot3(P_dims.elements()/3, getGLType<T>());
+    fg::Plot3* plot3 = fgMngr.getPlot3(P_dims.elements()/3, getGLType<T>(), ptype, mtype);
     plot3->setColor(1.0, 0.0, 0.0);
     plot3->setAxesLimits(max[0], min[0],
                          max[1], min[1],
@@ -74,7 +74,7 @@ fg::Plot3* setup_plot3(const af_array P)
 }
 #endif
 
-af_err af_draw_plot3(const af_window wind, const af_array P, const af_cell* const props)
+af_err plot3Wrapper(const af_window wind, const af_array P, const af_cell* const props, const fg::PlotType type=fg::FG_LINE, const fg::MarkerType marker=fg::FG_NONE)
 {
 #if defined(WITH_GRAPHICS)
     if(wind==0) {
@@ -91,12 +91,12 @@ af_err af_draw_plot3(const af_window wind, const af_array P, const af_cell* cons
         fg::Plot3* plot3 = NULL;
 
         switch(Ptype) {
-            case f32: plot3 = setup_plot3<float >(P); break;
-            case s32: plot3 = setup_plot3<int   >(P); break;
-            case u32: plot3 = setup_plot3<uint  >(P); break;
-            case s16: plot3 = setup_plot3<short >(P); break;
-            case u16: plot3 = setup_plot3<ushort>(P); break;
-            case u8 : plot3 = setup_plot3<uchar >(P); break;
+            case f32: plot3 = setup_plot3<float >(P, type, marker); break;
+            case s32: plot3 = setup_plot3<int   >(P, type, marker); break;
+            case u32: plot3 = setup_plot3<uint  >(P, type, marker); break;
+            case s16: plot3 = setup_plot3<short >(P, type, marker); break;
+            case u16: plot3 = setup_plot3<ushort>(P, type, marker); break;
+            case u8 : plot3 = setup_plot3<uchar >(P, type, marker); break;
             default:  TYPE_ERROR(1, Ptype);
         }
 
@@ -111,3 +111,14 @@ af_err af_draw_plot3(const af_window wind, const af_array P, const af_cell* cons
     return AF_ERR_NO_GFX;
 #endif
 }
+
+af_err af_draw_plot3(const af_window wind, const af_array P, const af_cell* const props)
+{
+    return plot3Wrapper(wind, P, props);
+}
+
+af_err af_draw_scatter3(const af_window wind, const af_array P, const af_marker_type af_marker, const af_cell* const props)
+{
+    fg::MarkerType fg_marker = getFGMarker(af_marker);
+    return plot3Wrapper(wind, P, props, fg::FG_SCATTER, fg_marker);
+}
diff --git a/src/api/cpp/graphics.cpp b/src/api/cpp/graphics.cpp
index cb9b080..162bacb 100644
--- a/src/api/cpp/graphics.cpp
+++ b/src/api/cpp/graphics.cpp
@@ -82,7 +82,13 @@ void Window::plot(const array& X, const array& Y, const char* const title)
 void Window::scatter(const array& X, const array& Y, af::markerType marker, const char* const title)
 {
     af_cell temp{_r, _c, title, AF_COLORMAP_DEFAULT};
-    AF_THROW(af_draw_scatter(get(), X.get(), Y.get(), &temp, marker));
+    AF_THROW(af_draw_scatter(get(), X.get(), Y.get(), marker, &temp));
+}
+
+void Window::scatter3(const array& P, af::markerType marker, const char* const title)
+{
+    af_cell temp{_r, _c, title, AF_COLORMAP_DEFAULT};
+    AF_THROW(af_draw_scatter3(get(), P.get(), marker, &temp));
 }
 
 void Window::plot3(const array& P, const char* const title)
diff --git a/src/api/unified/graphics.cpp b/src/api/unified/graphics.cpp
index 5964293..2895cc7 100644
--- a/src/api/unified/graphics.cpp
+++ b/src/api/unified/graphics.cpp
@@ -44,10 +44,16 @@ af_err af_draw_plot(const af_window wind, const af_array X, const af_array Y, co
     return CALL(wind, X, Y, props);
 }
 
-af_err af_draw_scatter(const af_window wind, const af_array X, const af_array Y, const af_cell* const props, const af_marker_type marker)
+af_err af_draw_scatter(const af_window wind, const af_array X, const af_array Y, const af_marker_type marker, const af_cell* const props)
 {
     CHECK_ARRAYS(X, Y);
-    return CALL(wind, X, Y, props, marker);
+    return CALL(wind, X, Y, marker, props);
+}
+
+af_err af_draw_scatter3(const af_window wind, const af_array P, const af_marker_type marker, const af_cell* const props)
+{
+    CHECK_ARRAYS(P);
+    return CALL(wind, P, marker, props);
 }
 
 af_err af_draw_plot3(const af_window wind, const af_array P, const af_cell* const props)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git



More information about the debian-science-commits mailing list