Forge
cpu/field.cpp
/*******************************************************
* Copyright (c) 2015-2019, 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 <forge.h>
#define USE_FORGE_CPU_COPY_HELPERS
#include <ComputeCopy.h>
#include <complex>
#include <cmath>
#include <vector>
#include <iostream>
const unsigned DIMX = 640;
const unsigned DIMY = 480;
const float PI = 3.14159265359f;
const float MINIMUM = 1.0f;
const float MAXIMUM = 20.f;
const float STEP = 2.0f;
const float NELEMS = (MAXIMUM-MINIMUM+1)/STEP;
const unsigned DPOINTS[] = {5, 5, 5, 15, 15, 5, 15, 15};
using namespace std;
void generatePoints(std::vector<float> &points, std::vector<float> &dirs)
{
points.clear();
for (int j=0; j<NELEMS; ++j) {
float y = MINIMUM + j*STEP;
for (int i=0; i<NELEMS; ++i) {
float x = MINIMUM + i*STEP;
points.push_back(x);
points.push_back(y);
dirs.push_back(sin(2*PI*x/10.f));
dirs.push_back(sin(2*PI*y/10.f));
}
}
}
int main(void)
{
/*
* First Forge call should be a window creation call
* so that necessary OpenGL context is created for any
* other forge::* object to be created successfully
*/
forge::Window wnd(DIMX, DIMY, "Vector Field Demo");
wnd.makeCurrent();
chart.setAxesLimits(MINIMUM-1.0f, MAXIMUM, MINIMUM-1.0f, MAXIMUM);
chart.setAxesTitles("x-axis", "y-axis");
divPoints.setColor(0.9f, 0.9f, 0.0f, 1.f);
divPoints.setLegend("Convergence Points");
divPoints.setMarkerSize(24);
forge::VectorField field = chart.vectorField((unsigned)(NELEMS*NELEMS), forge::f32);
field.setColor(0.f, 0.6f, 0.3f, 1.f);
std::vector<float> points;
std::vector<float> dirs;
generatePoints(points, dirs);
GfxHandle* handles[3];
createGLBuffer(&handles[0], divPoints.vertices(), FORGE_VERTEX_BUFFER);
createGLBuffer(&handles[1], field.vertices(), FORGE_VERTEX_BUFFER);
createGLBuffer(&handles[2], field.directions(), FORGE_VERTEX_BUFFER);
copyToGLBuffer(handles[0], (ComputeResourceHandle)DPOINTS, divPoints.verticesSize());
copyToGLBuffer(handles[1], (ComputeResourceHandle)points.data(), field.verticesSize());
copyToGLBuffer(handles[2], (ComputeResourceHandle)dirs.data(), field.directionsSize());
do {
wnd.draw(chart);
} while(!wnd.close());
// destroy GL-cpu interop buffers
releaseGLBuffer(handles[0]);
releaseGLBuffer(handles[1]);
releaseGLBuffer(handles[2]);
return 0;
}
forge.h
forge::Plot
Plot is a line graph to display two dimensional data.
Definition: plot.h:198
forge::VectorField::directionsSize
FGAPI unsigned directionsSize() const
Get the directions buffer size.
FG_PLOT_SCATTER
@ FG_PLOT_SCATTER
Scatter plot.
Definition: defines.h:162
ComputeResourceHandle
void * ComputeResourceHandle
A backend-agnostic handle to a compute memory resource originating from an OpenGL resource.
Definition: ComputeCopy.h:73
forge::Window
Window is where other objects such as Images, Plots etc. are rendered.
Definition: window.h:300
forge::Plot::setLegend
FGAPI void setLegend(const char *pLegend)
Set plot legend.
forge::Plot::vertices
FGAPI unsigned vertices() const
Get the buffer identifier for vertices.
forge::Plot::setColor
FGAPI void setColor(const forge::Color pColor)
Set the color of line graph(plot)
FG_MARKER_CIRCLE
@ FG_MARKER_CIRCLE
Circle marker.
Definition: defines.h:169
forge::Plot::verticesSize
FGAPI unsigned verticesSize() const
Get the vertex buffer size in bytes.
forge::Plot::setMarkerSize
FGAPI void setMarkerSize(const float pMarkerSize)
Set global marker size.
FORGE_VERTEX_BUFFER
@ FORGE_VERTEX_BUFFER
OpenGL Vertex Buffer Object.
Definition: ComputeCopy.h:77
forge::VectorField::verticesSize
FGAPI unsigned verticesSize() const
Get the vertex buffer size in bytes.
forge::u32
@ u32
Definition: defines.h:192
forge::VectorField::setColor
FGAPI void setColor(const forge::Color pColor)
Set global color for the field lines.
forge::VectorField
VectorField is a line graph to display two dimensional data.
Definition: vector_field.h:180
FG_CHART_2D
@ FG_CHART_2D
Two dimensional charts.
Definition: defines.h:118
forge::VectorField::vertices
FGAPI unsigned vertices() const
Get the buffer identifier for vertices.
GfxHandle
Definition: ComputeCopy.h:80
forge::Chart
Chart is base canvas where other plottable objects are rendered.
Definition: chart.h:316
forge::VectorField::directions
FGAPI unsigned directions() const
Get the buffer identifier for field direction per vertex values.
ComputeCopy.h
forge::f32
@ f32
Definition: defines.h:193