/******************************************************* * Copyright (c) 2014, ArrayFire * All rights reserved. * * This file is distributed under 3-clause BSD license. * The complete license agreement can be obtained at: * http://arrayfire.com/licenses/BSD-3-Clause ********************************************************/ #include #include #include #include #include #include #include #include #include #include #include using af::dim4; using namespace detail; #if defined(WITH_GRAPHICS) using namespace graphics; template fg::Plot* setup_plot(const af_array X, const af_array Y) { Array xIn = getArray(X); Array yIn = getArray(Y); T xmax = reduce_all(xIn); T xmin = reduce_all(xIn); T ymax = reduce_all(yIn); T ymin = reduce_all(yIn); dim4 rdims(1, 0, 2, 3); Array Z = join(1, xIn, yIn); Array P = reorder(Z, rdims); ArrayInfo Xinfo = getInfo(X); af::dim4 X_dims = Xinfo.dims(); ForgeManager& fgMngr = ForgeManager::getInstance(); fg::Plot* plot = fgMngr.getPlot(X_dims.elements(), getGLType()); plot->setColor(1.0, 0.0, 0.0); plot->setAxesLimits(xmax, xmin, ymax, ymin); plot->setAxesTitles("X Axis", "Y Axis"); copy_plot(P, plot); return plot; } #endif af_err af_draw_plot(const af_window wind, const af_array X, const af_array Y, const af_cell* const props) { #if defined(WITH_GRAPHICS) if(wind==0) { std::cerr<<"Not a valid window"<(wind); window->makeCurrent(); fg::Plot* plot = NULL; switch(Xtype) { case f32: plot = setup_plot(X, Y); break; case s32: plot = setup_plot(X, Y); break; case u32: plot = setup_plot(X, Y); break; case s16: plot = setup_plot(X, Y); break; case u16: plot = setup_plot(X, Y); break; case u8 : plot = setup_plot(X, Y); break; default: TYPE_ERROR(1, Xtype); } if (props->col>-1 && props->row>-1) window->draw(props->col, props->row, *plot, props->title); else window->draw(*plot); } CATCHALL; return AF_SUCCESS; #else AF_RETURN_ERROR("ArrayFire compiled without graphics support", AF_ERR_NO_GFX); #endif }