/******************************************************* * 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 #include using af::dim4; using namespace detail; #if defined(WITH_GRAPHICS) using namespace graphics; template fg::Surface* setup_surface(const af_array xVals, const af_array yVals, const af_array zVals) { Array xIn = getArray(xVals); Array yIn = getArray(yVals); Array zIn = getArray(zVals); T xmax = reduce_all(xIn); T xmin = reduce_all(xIn); T ymax = reduce_all(yIn); T ymin = reduce_all(yIn); T zmax = reduce_all(zIn); T zmin = reduce_all(zIn); ArrayInfo Xinfo = getInfo(xVals); ArrayInfo Yinfo = getInfo(yVals); ArrayInfo Zinfo = getInfo(zVals); af::dim4 X_dims = Xinfo.dims(); af::dim4 Y_dims = Yinfo.dims(); af::dim4 Z_dims = Zinfo.dims(); dim4 rdims(1, 0, 2, 3); dim4 x_tdims(1, Y_dims[0], 1, 1); dim4 y_tdims(1, X_dims[0], 1, 1); if(Xinfo.isVector()){ xIn = tile(xIn, x_tdims); yIn = tile(yIn, y_tdims); yIn = reorder(yIn, rdims); } xIn.modDims(xIn.elements()); yIn.modDims(yIn.elements()); zIn.modDims(zIn.elements()); Array Z = join(1, join(1, xIn, yIn), zIn); Z = reorder(Z, rdims); Z.modDims(Z.elements()); ForgeManager& fgMngr = ForgeManager::getInstance(); fg::Surface* surface = fgMngr.getSurface(Z_dims[0], Z_dims[1], getGLType()); surface->setColor(1.0, 0.0, 0.0); surface->setAxesLimits(xmax, xmin, ymax, ymin, zmax, zmin); surface->setAxesTitles("X Axis", "Y Axis", "Z Axis"); copy_surface(Z, surface); return surface; } #endif af_err af_draw_surface(const af_window wind, const af_array xVals, const af_array yVals, const af_array S, const af_cell* const props) { #if defined(WITH_GRAPHICS) if(wind==0) { std::cerr<<"Not a valid window"<(wind); window->makeCurrent(); fg::Surface* surface = NULL; switch(Xtype) { case f32: surface = setup_surface(xVals, yVals , S); break; case s32: surface = setup_surface(xVals, yVals , S); break; case u32: surface = setup_surface(xVals, yVals , S); break; case s16: surface = setup_surface(xVals, yVals , S); break; case u16: surface = setup_surface(xVals, yVals , S); break; case u8 : surface = setup_surface(xVals, yVals , S); break; default: TYPE_ERROR(1, Xtype); } if (props->col>-1 && props->row>-1) window->draw(props->col, props->row, *surface, props->title); else window->draw(*surface); } CATCHALL; return AF_SUCCESS; #else AF_RETURN_ERROR("ArrayFire compiled without graphics support", AF_ERR_NO_GFX); #endif }