[arrayfire] 26/284: adds scatter function

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:15 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 ed730cfcd174110a7483a9d8eca881672bab8e83
Author: syurkevi <stefan at arrayfire.com>
Date:   Fri Nov 20 13:14:14 2015 -0500

    adds scatter function
---
 include/af/defines.h          | 16 ++++++++++++++++
 include/af/graphics.h         | 35 +++++++++++++++++++++++++++++++++++
 src/api/c/graphics_common.cpp |  7 ++++---
 src/api/c/graphics_common.hpp |  2 +-
 src/api/c/plot.cpp            | 40 +++++++++++++++++++++++++++++++---------
 src/api/cpp/graphics.cpp      |  6 ++++++
 src/api/unified/graphics.cpp  |  6 ++++++
 7 files changed, 99 insertions(+), 13 deletions(-)

diff --git a/include/af/defines.h b/include/af/defines.h
index a25d239..2b53baa 100644
--- a/include/af/defines.h
+++ b/include/af/defines.h
@@ -378,6 +378,19 @@ typedef enum {
     AF_ID = 0
 } af_someenum_t;
 
+#if AF_API_VERSION >=32
+typedef enum {
+    AF_MARKER_NONE         = 0,
+    AF_MARKER_POINT        = 1,
+    AF_MARKER_CIRCLE       = 2,
+    AF_MARKER_SQUARE       = 3,
+    AF_MARKER_TRIANGLE     = 4,
+    AF_MARKER_CROSS        = 5,
+    AF_MARKER_PLUS         = 6,
+    AF_MARKER_STAR         = 7
+} af_marker_type;
+#endif
+
 #ifdef __cplusplus
 namespace af
 {
@@ -404,6 +417,9 @@ namespace af
 #if AF_API_VERSION >= 32
     typedef af_backend Backend;
 #endif
+#if AF_API_VERSION >= 32
+    typedef af_marker_type markerType;
+#endif
 }
 
 #endif
diff --git a/include/af/graphics.h b/include/af/graphics.h
index 5c143c7..e4286e1 100644
--- a/include/af/graphics.h
+++ b/include/af/graphics.h
@@ -181,6 +181,20 @@ class AFAPI Window {
         void plot(const array& X, const array& Y, const char* const title=NULL);
 
         /**
+           Renders the input arrays as a 2D scatter-plot to the window
+
+           \param[in] X is an \ref array with the x-axis data points
+           \param[in] Y is an \ref 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] title parameter is used when this function is called in grid mode
+
+           \note \p X and \p Y should be vectors.
+
+           \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 array as a histogram to the window
 
            \param[in] X is the data frequency \ref array
@@ -376,6 +390,27 @@ AFAPI af_err af_draw_plot(const af_window wind, const af_array X, const af_array
    C Interface wrapper for drawing an array as a plot
 
    \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]   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
+   is returned.
+
+   \note \p X and \p Y should be vectors.
+
+   \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);
+#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 4b50bc0..92346f5 100644
--- a/src/api/c/graphics_common.cpp
+++ b/src/api/c/graphics_common.cpp
@@ -161,7 +161,7 @@ fg::Image* ForgeManager::getImage(int w, int h, fg::ChannelFormat mode, fg::dtyp
     return mImgMap[key];
 }
 
-fg::Plot* ForgeManager::getPlot(int nPoints, fg::dtype type)
+fg::Plot* ForgeManager::getPlot(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
@@ -169,11 +169,12 @@ fg::Plot* ForgeManager::getPlot(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));
 
     PltMapIter iter = mPltMap.find(key);
     if (iter==mPltMap.end()) {
-        fg::Plot* temp = new fg::Plot(nPoints, type);
+        fg::Plot* temp = new fg::Plot(nPoints, dtype, ptype, mtype);
         mPltMap[key] = temp;
     }
 
diff --git a/src/api/c/graphics_common.hpp b/src/api/c/graphics_common.hpp
index 39225e6..caadb88 100644
--- a/src/api/c/graphics_common.hpp
+++ b/src/api/c/graphics_common.hpp
@@ -82,7 +82,7 @@ class ForgeManager
         fg::Font* getFont(const bool dontCreate=false);
         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 type);
+        fg::Plot* getPlot(int nPoints, fg::dtype dtype, fg::PlotType ptype, fg::MarkerType mtype);
         fg::Plot3* getPlot3(int nPoints, fg::dtype type);
         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 b22e928..f274030 100644
--- a/src/api/c/plot.cpp
+++ b/src/api/c/plot.cpp
@@ -27,7 +27,7 @@ using namespace detail;
 using namespace graphics;
 
 template<typename T>
-fg::Plot* setup_plot(const af_array X, const af_array Y)
+fg::Plot* setup_plot(const af_array X, const af_array Y, fg::PlotType type, fg::MarkerType marker)
 {
     Array<T> xIn = getArray<T>(X);
     Array<T> yIn = getArray<T>(Y);
@@ -46,7 +46,7 @@ fg::Plot* setup_plot(const af_array X, const af_array Y)
     af::dim4 X_dims = Xinfo.dims();
 
     ForgeManager& fgMngr = ForgeManager::getInstance();
-    fg::Plot* plot = fgMngr.getPlot(X_dims.elements(), getGLType<T>());
+    fg::Plot* plot = fgMngr.getPlot(X_dims.elements(), getGLType<T>(), type, marker);
     plot->setColor(1.0, 0.0, 0.0);
     plot->setAxesLimits(xmax, xmin, ymax, ymin);
     plot->setAxesTitles("X Axis", "Y Axis");
@@ -57,7 +57,7 @@ fg::Plot* setup_plot(const af_array X, const af_array Y)
 }
 #endif
 
-af_err af_draw_plot(const af_window wind, const af_array X, const af_array Y, const af_cell* const props)
+af_err plotWrapper(const af_window wind, const af_array X, const af_array Y, const af_cell* const props, fg::PlotType type=fg::FG_LINE, fg::MarkerType marker=fg::FG_NONE)
 {
 #if defined(WITH_GRAPHICS)
     if(wind==0) {
@@ -85,12 +85,12 @@ af_err af_draw_plot(const af_window wind, const af_array X, const af_array Y, co
         fg::Plot* plot = NULL;
 
         switch(Xtype) {
-            case f32: plot = setup_plot<float  >(X, Y); break;
-            case s32: plot = setup_plot<int    >(X, Y); break;
-            case u32: plot = setup_plot<uint   >(X, Y); break;
-            case s16: plot = setup_plot<short  >(X, Y); break;
-            case u16: plot = setup_plot<ushort >(X, Y); break;
-            case u8 : plot = setup_plot<uchar  >(X, Y); break;
+            case f32: plot = setup_plot<float  >(X, Y, type, marker); break;
+            case s32: plot = setup_plot<int    >(X, Y, type, marker); break;
+            case u32: plot = setup_plot<uint   >(X, Y, type, marker); break;
+            case s16: plot = setup_plot<short  >(X, Y, type, marker); break;
+            case u16: plot = setup_plot<ushort >(X, Y, type, marker); break;
+            case u8 : plot = setup_plot<uchar  >(X, Y, type, marker); break;
             default:  TYPE_ERROR(1, Xtype);
         }
 
@@ -105,3 +105,25 @@ af_err af_draw_plot(const af_window wind, const af_array X, const af_array Y, co
     return AF_ERR_NO_GFX;
 #endif
 }
+
+af_err af_draw_plot(const af_window wind, const af_array X, const af_array Y, const af_cell* const props)
+{
+    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)
+{
+    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 plotWrapper(wind, X, Y, props, fg::FG_SCATTER, fg_marker);
+}
diff --git a/src/api/cpp/graphics.cpp b/src/api/cpp/graphics.cpp
index b748019..8d2d8cd 100644
--- a/src/api/cpp/graphics.cpp
+++ b/src/api/cpp/graphics.cpp
@@ -79,6 +79,12 @@ void Window::plot(const array& X, const array& Y, const char* const title)
     AF_THROW(af_draw_plot(get(), X.get(), Y.get(), &temp));
 }
 
+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));
+}
+
 void Window::plot3(const array& P, const char* const title)
 {
     af_cell temp{_r, _c, title, AF_COLORMAP_DEFAULT};
diff --git a/src/api/unified/graphics.cpp b/src/api/unified/graphics.cpp
index 81076f2..5964293 100644
--- a/src/api/unified/graphics.cpp
+++ b/src/api/unified/graphics.cpp
@@ -44,6 +44,12 @@ 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)
+{
+    CHECK_ARRAYS(X, Y);
+    return CALL(wind, X, Y, props, marker);
+}
+
 af_err af_draw_plot3(const af_window wind, const af_array P, const af_cell* const props)
 {
     CHECK_ARRAYS(P);

-- 
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