AndroidPlot: How to combine different chart types on the one plot? - charts

How to combine line chart and bar chart on the one plot? The documentation does not mention about this functionality. Is this possible for AndroidPlot?

Use this in oncreate() of ur activity.
setContentView(R.layout.main);
XYPlot plot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
Number[] series1Numeros = { 1, 8, 5, 2, 7, 4 };
XYSeries series1 = new SimpleXYSeries(Arrays.asList(series1Numeros),
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Intereses");
XYSeries series = new SimpleXYSeries(Arrays.asList(new Number[] { 1, 2, 3, 4, 5 }),
SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "title");
BarFormatter formatter = new BarFormatter(Color.rgb(0, 200, 0), Color.rgb(100, 0, 0));
plot.addSeries(series, BarRenderer.class, formatter);
BarRenderer renderer = (BarRenderer) plot.getRenderer(BarRenderer.class);
LineAndPointFormatter series1Format = new LineAndPointFormatter(Color.rgb(0, 200, 0),
Color.rgb(0, 100, 0),
null);
plot.addSeries(series1, series1Format);

Related

modulo to cycle though a compute buffer not working as expected

The Setup
In my compute-shader I have a StructuredBuffer that is storing an amount of colors. There is also an int variable storing the amount of colors in total ( _colres ). From another script a node tree is dispatched into the shader every frame. The amount of nodes changes dynamically. Because of that the points buffer containing the nodes is at a fixed size of 8192 that the amount of nodes never exceeds.
The Problem
When I'm now trying to draw the points I am storing in the points buffer, oddly enough only every third color is displayed, starting at index [0] (tested for up to 12 colors -> [0],[3],[6],[9]).
Result[pointsBuffer[id.x].xy] = colorsBuffer[id.x % _colres];
What I tried
I used the fmod() function instead but was presented with the same result. Individually targeting stored colors by hard-coding the index has worked so my guess would be that the colors buffer is not the problem. Maybe it has something to do with all the empty spaces in the pointsbuffer but I could't figure it out.
The Question(s)
Is there a fundamental problem I am overlooking?
Is there some other simple way to cycle through the indices of my colorsbuffer that works in this scenario?
Detailed Information
System:
Unity Version 2021.2.12f1 using the HDRP on MacOS Monterey 12.2.1
Compute-Shader
#pragma kernel DrawPoints
// texture
shared RWTexture2D<float4> Result;
int _texres;
int _colres;
// buffer
StructuredBuffer<float2> pointsBuffer;
StructuredBuffer<float4> colorsBuffer;
[numthreads(64,1,1)]
void DrawPoints (uint3 id : SV_DispatchThreadID)
{
if ((pointsBuffer[id.x].x * pointsBuffer[id.x].y) > 0) Result[pointsBuffer[id.x].xy] = colorsBuffer[id.x % _colres];
}
C# Setup
public differentialGrowth diffGrowth;
int texResolution = 4096;
int colorAmount = 12;
RenderTexture settingRef;
Material target;
ComputeShader shader;
RenderTexture outputTexture;
ComputeBuffer pointsBuffer;
ComputeBuffer colorsBuffer;
int pointsHandle;
void Start()
{
outputTexture = new RenderTexture(settingRef);
outputTexture.enableRandomWrite = true;
outputTexture.Create();
// INIT
pointsHandle = shader.FindKernel("DrawPoints");
shader.SetInt("_texres", texResolution);
shader.SetInt("_colres", colorAmount);
int stride = (3) * 4; // every component as a float (3) * 4 bytes per float
pointsBuffer = new ComputeBuffer(8192, stride);
stride = (4) * 4;
colorsBuffer = new ComputeBuffer(colorAmount, stride);
shader.SetTexture( pointsHandle, "Result", outputTexture );
target.SetTexture("_MainTex", outputTexture);
Color[] testColors = new Color[colorAmount];
testColors[0] = new Color(1, 0, 0, 0); //red _ yes
testColors[1] = new Color(0, 1, 0, 0); //green
testColors[2] = new Color(0, 0, 1, 0); //blue
testColors[3] = new Color(1, 1, 0, 0); //yellow _yes
testColors[4] = new Color(0, 1, 1, 0); //cyan
testColors[5] = new Color(1, 0, 1, 0); //magenta
testColors[6] = new Color(0.5f, 0, 1, 0); //mix6 _yes
testColors[7] = new Color(1, 0.5f, 1, 0); //mix7
testColors[8] = new Color(0.5f, 0, 1, 0); //mix8
testColors[9] = new Color(0.5f, 0.5f, 1, 0); //mix9 _yes
testColors[10] = new Color(0.5f, 0.5f, 1, 0); //mix10
testColors[11] = new Color(0.5f, 0.5f, 1, 0); //mix11
}
void Update()
{
pointsBuffer.SetData(diffGrowth.nodes.Points);
shader.SetBuffer(pointsHandle, "colorsBuffer", colorsBuffer);
shader.SetBuffer(pointsHandle, "pointsBuffer", pointsBuffer);
shader.Dispatch(pointsHandle, 128, 1, 1);
}
private void OnDestroy()
{
if (pointsBuffer != null) pointsBuffer.Dispose();
if (colorsBuffer != null) colorsBuffer.Dispose();
}
}

I have Problem in making solid ground in cannonjs

I have faced a problem while making solid ground that will make my sphere stop from falling through the plane…
the code below should prevent the sphere from falling through the plane, and also I know that you need to rotate the solid body...
const planeBody = new CANNON.Body({mass: 0})
but surprisingly it doesn’t have any effect at all, what should happen is that it should stop the sphere from falling through the plane…
also, there is another weird problem
the code below should make the plane fall along with the sphere if the sphere also has a mass equal to 1, and indeed that is what happens here
const planeBody = new CANNON.Body({mass: 1})
but when you try to rewrite it in this form, it stops from working
const planeBody = new CANNON.Body()
planeBody.mass = 1;
here is my complete code
import * as THREE from './threeJS/three.module.js';
import { OrbitControls } from './examples/jsm/controls/OrbitControls.js';
import { GUI } from '../dat.gui/files/dat.gui.module.js';
import * as THREEx from './threeX/threeX.keyboardState.js';
// gui
// const gui = new GUI();
// keyboard
const keyboard = new THREEx.default();
// console.log(THREEx.default);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x777777);
// Meshes
const plane = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({ color: 0xdddddd, side: THREE.DoubleSide })
);
plane.rotateX(90 / 57.3);
const sphere = new THREE.Mesh(
new THREE.SphereGeometry(3, 64, 32),
new THREE.MeshStandardMaterial({ color: 'red' })
);
sphere.position.y = 5;
let clientWidth = document.documentElement.clientWidth;
let clientHeight = document.documentElement.clientHeight;
// prettier-ignore
const camera = new THREE.PerspectiveCamera(45, clientWidth / clientHeight, 0.1, 1000);
const canvas = document.querySelector('.webgl');
const controls = new OrbitControls(camera, canvas);
controls.enableDamping = true;
camera.position.set(0, 20, 30);
controls.update();
const renderer = new THREE.WebGLRenderer({
canvas: canvas,
antialias: true,
});
renderer.setSize(clientWidth, clientHeight);
renderer.shadowMap.enabled = true;
// lights
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
directionalLight.position.set(0, 7, 5);
directionalLight.target = sphere;
directionalLight.target.updateMatrixWorld();
directionalLight.castShadow = true;
// shadows
// ! only three types of light that support shadows
// ! spotlight
// ! directional light
// ! point light
// ! castShadow means will it create a shadow? receiveShadow means will the shadow be on it?
sphere.castShadow = true;
plane.receiveShadow = true;
// Helpers
const AxesHelper = new THREE.AxesHelper(5);
scene.add(AxesHelper, camera, sphere, plane, directionalLight, ambientLight);
// Clock
const clock = new THREE.Clock();
let oldElapsedTime = 0;
// physics
const world = new CANNON.World();
world.gravity.set(0, -9.82, 0);
// Sphere
const sphereShape = new CANNON.Sphere(3);
const sphereBody = new CANNON.Body({
mass: 1,
position: new CANNON.Vec3(0, 5, 0),
shape: sphereShape,
});
world.addBody(sphereBody);
// infinite Plane
const planeShape = new CANNON.Plane();
const planeBody = new CANNON.Body({
mass: 0,
});
planeBody.addShape(planeShape);
planeBody.quaternion.setFromAxisAngle(new CANNON.Vec3(-1, 0, 0), Math.PI * 0.5);
world.addBody(planeBody);
function animate() {
requestAnimationFrame(animate);
let ElapsedTime = clock.getElapsedTime();
let deltaTime = ElapsedTime - oldElapsedTime;
oldElapsedTime = deltaTime;
// to update the world 60 times per second
world.step(1 / 60, deltaTime, 3);
directionalLight.position.z = 3 * Math.sin(ElapsedTime);
directionalLight.position.x = 3 * Math.cos(ElapsedTime);
directionalLight.lookAt(sphere.position);
sphere.position.copy(sphereBody.position);
plane.position.copy(planeBody.position);
// sphere.position.x = keyboard.pressed('right')
// ? sphere.position.x + 0.1
// : keyboard.pressed('left')
// ? sphere.position.x - 0.1
// : sphere.position.x;
// sphere.position.z = keyboard.pressed('up')
// ? sphere.position.z - 0.1
// : keyboard.pressed('down')
// ? sphere.position.z + 0.1
// : sphere.position.z;
controls.update();
renderer.render(scene, camera);
}
animate();
//events
window.addEventListener('resize', () => {
clientWidth = document.documentElement.clientWidth;
clientHeight = document.documentElement.clientHeight;
camera.aspect = clientWidth / clientHeight;
camera.updateProjectionMatrix();
renderer.setSize(clientWidth, clientHeight);
});
window.addEventListener('dblclick', () => {
if (!document.fullscreenElement) {
canvas.requestFullscreen();
} else {
document.exitFullscreen();
}
});

SURF with hashing

I want to ask you if i can use hashing technique with SURF algorithm,i made a program to make face recognition by matching test image with saved image dataset.
i used Accord.net and made bag of features by BOW of this library then I made ID3 decision tree and KNN but the result in both ways were not very good, i am asking if i can use hashing technique to make fast and better result,or this will not be feasible ?
this is the code for BOW
private void button2_Click(object sender, EventArgs e)
{
try
{
var watchFEC = System.Diagnostics.Stopwatch.StartNew();
Accord.Math.Random.Generator.Seed = 0;
bow.ParallelOptions.MaxDegreeOfParallelism = 1;
bow.Learn(DatasetImages);
// After this point, we will be able to translate
// images into double[] feature vectors using
features = bow.Transform(DatasetImages);
watchFEC.Stop();
var elapsedMs = watchFEC.ElapsedMilliseconds;
MessageBox.Show("Feature Extraction and Clastering is done" + '\n' + "Time for Feature Extraction and Clastering for Dataset is: " + elapsedMs.ToString() + " ms");
} catch { MessageBox.Show("Error"); } }
and this is the code for learn
private void button3_Click(object sender, EventArgs e)
{
try
{
var watchLearn = System.Diagnostics.Stopwatch.StartNew();
inputs = features.ToInt32();
tree = teacher.Learn(inputs, outputs);
error = new ZeroOneLoss(outputs).Loss(tree.Decide(inputs));
MessageBox.Show("Error rate of learning is : "+error.ToString());
watchLearn.Stop();
var elapsedMs = watchLearn.ElapsedMilliseconds;
MessageBox.Show("Learning is done" + '\n' + "Time for Learning is: " + elapsedMs.ToString() + " ms");
}
catch(Exception ex) { MessageBox.Show("Error"+ex); }
}
and this code for test
private void button4_Click_1(object sender, EventArgs e)
{
try
{
var watchTest = System.Diagnostics.Stopwatch.StartNew();
Bitmap[] testimage = new Bitmap[1];
testimage[0] = (Bitmap)pictureBox1.Image;
var ff = bow.Transform(testimage);
ff.ToInt32();
var predicted = tree.Decide(ff);
int i = 1;
for (i = 1; i < sizeofdataset; i++)
{
if (predicted[0] == Convert.ToInt16(workSheet.Cells[i, 3].Value.ToString()))
{
listBox1.SelectedItem = i;
MessageBox.Show("Test" + i);
break;
}
}
MessageBox.Show("Test" + predicted[0]);
pictureBox2.Image = new Bitmap(workSheet.Cells[i, 1].Value.ToString());
watchTest.Stop();
var elapsedMs = watchTest.ElapsedMilliseconds;
MessageBox.Show("Time for Testing is: " + elapsedMs.ToString() + " ms");
}
catch (Exception ex) { MessageBox.Show("Error" + ex); }
}
Instead of ID3 or k-NN, please try using a SVM with a Chi-Square kernel.
If you would like to give SVMs a try, there is an example on how to create multi-class kernel SVMs at the bottom of this page (see second example). You can replace all places where it is written "Gaussian" by "ChiSquare" in order to create a chi-square SVM.
If you happen to run in a {"Index was outside the bounds of the array."} as you have indicated in the project's issue tracker, I think you might have a class without training or testing samples. Please make sure you have enough training samples for all classes, that your class numbers start at 0, that the highest class label in your output vector corresponds to the number_of_classes - 1 and that there are no integers in this interval without any associated training samples.
I am posting below an example on how to train SVMs using a Chi-Square kernel in the Accord.NET Framework:
// Let's say we have the following data to be classified
// into three possible classes. Those are the samples:
//
double[][] inputs =
{
// input output
new double[] { 0, 1, 1, 0 }, // 0
new double[] { 0, 1, 0, 0 }, // 0
new double[] { 0, 0, 1, 0 }, // 0
new double[] { 0, 1, 1, 0 }, // 0
new double[] { 0, 1, 0, 0 }, // 0
new double[] { 1, 0, 0, 0 }, // 1
new double[] { 1, 0, 0, 0 }, // 1
new double[] { 1, 0, 0, 1 }, // 1
new double[] { 0, 0, 0, 1 }, // 1
new double[] { 0, 0, 0, 1 }, // 1
new double[] { 1, 1, 1, 1 }, // 2
new double[] { 1, 0, 1, 1 }, // 2
new double[] { 1, 1, 0, 1 }, // 2
new double[] { 0, 1, 1, 1 }, // 2
new double[] { 1, 1, 1, 1 }, // 2
};
int[] outputs = // those are the class labels
{
0, 0, 0, 0, 0,
1, 1, 1, 1, 1,
2, 2, 2, 2, 2,
};
// Create the multi-class learning algorithm for the machine
var teacher = new MulticlassSupportVectorLearning<ChiSquare>()
{
// Configure the learning algorithm to use SMO to train the
// underlying SVMs in each of the binary class subproblems.
Learner = (param) => new SequentialMinimalOptimization<ChiSquare>()
{
// Estimate a suitable guess for the Gaussian kernel's parameters.
// This estimate can serve as a starting point for a grid search.
UseKernelEstimation = true
}
};
// Configure parallel execution options (or leave it at the default value for maximum speed)
teacher.ParallelOptions.MaxDegreeOfParallelism = 1;
// Learn a machine
var machine = teacher.Learn(inputs, outputs);
// Obtain class predictions for each sample
int[] predicted = machine.Decide(inputs);
// Get class scores for each sample
double[] scores = machine.Score(inputs);
// Compute classification error
double error = new ZeroOneLoss(outputs).Loss(predicted);

How to use " 9-sliced" image type in non-GUI elements?

In my game, I am using simple textures on quads. I could see Unity GUI allows us to slice the image by setting "image type" option as sliced.
I would like to do the same to my other textures I use in quads.
In simple words, I dont want the edges of my textures to be scaled when the texture itself is scaled.
Thanks.
Looks like you have to generate the mesh yourself, not so hard as it sounds. The mesh has to look like this:
Each textured mesh is defined by vertices (red dots on the picture) and (in this case) each vertex has two parameters:
A Vector3 with position. Only x and y used here, as a quad is flat (so, z = 0).
A Vector2 with the UV, that is how the material is put on the mesh. This are the texture coordinates: u and v.
To configure this mesh, I added parameters:
b - for border - how big is the border of the gameobject (in 3d units)
w, h - for width and height of the gameobject (in 3d units)
m - how big is the margin in the image (in float 0f to 0.5f)
How to do this in Unity3d:
Create an GameObject, add a MeshRenderer with the material you want and an empty MeshFilter.
Add a script that creates a mesh. Look at Unity3d docs for Mesh, first example.
Note that for unity3d you have to create this with triangles, not quads (so for each quad make two triangles).
Chanibal's solutions worked like a charm for me, but since I wasn't an expert in the matter, it wasn't trivial to me to implement this. I will let this code here in case somebody could find it useful.
using UnityEngine;
public class SlicedMesh : MonoBehaviour
{
private float _b = 0.1f;
public float Border
{
get
{
return _b;
}
set
{
_b = value;
CreateSlicedMesh();
}
}
private float _w = 1.0f;
public float Width
{
get
{
return _w;
}
set
{
_w = value;
CreateSlicedMesh();
}
}
private float _h = 1.0f;
public float Height
{
get
{
return _h;
}
set
{
_h = value;
CreateSlicedMesh();
}
}
private float _m = 0.4f;
public float Margin
{
get
{
return _m;
}
set
{
_m = value;
CreateSlicedMesh();
}
}
void Start()
{
CreateSlicedMesh();
}
void CreateSlicedMesh()
{
Mesh mesh = new Mesh();
GetComponent<MeshFilter>().mesh = mesh;
mesh.vertices = new Vector3[] {
new Vector3(0, 0, 0), new Vector3(_b, 0, 0), new Vector3(_w-_b, 0, 0), new Vector3(_w, 0, 0),
new Vector3(0, _b, 0), new Vector3(_b, _b, 0), new Vector3(_w-_b, _b, 0), new Vector3(_w, _b, 0),
new Vector3(0, _h-_b, 0), new Vector3(_b, _h-_b, 0), new Vector3(_w-_b, _h-_b, 0), new Vector3(_w, _h-_b, 0),
new Vector3(0, _h, 0), new Vector3(_b, _h, 0), new Vector3(_w-_b, _h, 0), new Vector3(_w, _h, 0)
};
mesh.uv = new Vector2[] {
new Vector2(0, 0), new Vector2(_m, 0), new Vector2(1-_m, 0), new Vector2(1, 0),
new Vector2(0, _m), new Vector2(_m, _m), new Vector2(1-_m, _m), new Vector2(1, _m),
new Vector2(0, 1-_m), new Vector2(_m, 1-_m), new Vector2(1-_m, 1-_m), new Vector2(1, 1-_m),
new Vector2(0, 1), new Vector2(_m, 1), new Vector2(1-_m, 1), new Vector2(1, 1)
};
mesh.triangles = new int[] {
0, 4, 5,
0, 5, 1,
1, 5, 6,
1, 6, 2,
2, 6, 7,
2, 7, 3,
4, 8, 9,
4, 9, 5,
5, 9, 10,
5, 10, 6,
6, 10, 11,
6, 11, 7,
8, 12, 13,
8, 13, 9,
9, 13, 14,
9, 14, 10,
10, 14, 15,
10, 15, 11
};
}
}
Here is another impementation of the same mesh as described above(just add Tile9Mesh script to empty GameObject and it should work
):
using UnityEngine;
namespace Util {
[ExecuteInEditMode]
[RequireComponent(typeof(MeshRenderer), typeof(MeshFilter))]
public class Tile9Mesh : MonoBehaviour {
public float width = 1;
public float height = 1;
[Range(0, 0.5f)]
public float uvLeft = 0.2f;
[Range(0, 0.5f)]
public float uvRight = 0.2f;
[Range(0, 0.5f)]
public float uvTop = 0.2f;
[Range(0, 0.5f)]
public float uvBottom = 0.2f;
public float uvToWorldScaleX = 1;
public float uvToWorldScaleY = 1;
private Mesh mesh;
private Vector3[] vertices;
private Vector2[] uv;
private void Start() {
vertices = new Vector3[16];
uv = new Vector2[16];
mesh = new Mesh {
name = "Tile9Mesh"
};
FillGeometry();
FillMesh();
mesh.triangles = new[] {
0, 1, 12, 0, 12, 11,
1, 2, 13, 1, 13, 12,
2, 3, 4, 2, 4, 13,
13, 4, 5, 13, 5, 14,
14, 5, 6, 14, 6, 7,
15, 14, 7, 15, 7, 8,
10, 15, 8, 10, 8, 9,
11, 12, 15, 11, 15, 10,
12, 13, 14, 12, 14, 15
};
RecalculateMesh();
gameObject.GetComponent<MeshFilter>().mesh = mesh;
}
public void UpdateMesh() {
if (mesh != null) {
FillGeometry();
FillMesh();
mesh.RecalculateBounds();
mesh.RecalculateNormals();
}
}
private void FillGeometry() {
{
float w = width;
float h = height;
float l = uvLeft * uvToWorldScaleX;
float r = width - uvRight * uvToWorldScaleX;
float t = height - uvTop * uvToWorldScaleY;
float b = uvBottom * uvToWorldScaleY;
vertices[0] = new Vector3(0, 0, 0);
vertices[1] = new Vector3(0, b, 0);
vertices[2] = new Vector3(0, t, 0);
vertices[3] = new Vector3(0, h, 0);
vertices[4] = new Vector3(l, h, 0);
vertices[5] = new Vector3(r, h, 0);
vertices[6] = new Vector3(w, h, 0);
vertices[7] = new Vector3(w, t, 0);
vertices[8] = new Vector3(w, b, 0);
vertices[9] = new Vector3(w, 0, 0);
vertices[10] = new Vector3(r, 0, 0);
vertices[11] = new Vector3(l, 0, 0);
vertices[12] = new Vector3(l, b, 0);
vertices[13] = new Vector3(l, t, 0);
vertices[14] = new Vector3(r, t, 0);
vertices[15] = new Vector3(r, b, 0);
}
{
const float w = 1;
const float h = 1;
float l = uvLeft;
float r = 1 - uvRight;
float t = 1 - uvTop;
float b = uvBottom;
uv[0] = new Vector2(0, 0);
uv[1] = new Vector2(0, b);
uv[2] = new Vector2(0, t);
uv[3] = new Vector2(0, h);
uv[4] = new Vector2(l, h);
uv[5] = new Vector2(r, h);
uv[6] = new Vector2(w, h);
uv[7] = new Vector2(w, t);
uv[8] = new Vector2(w, b);
uv[9] = new Vector2(w, 0);
uv[10] = new Vector2(r, 0);
uv[11] = new Vector2(l, 0);
uv[12] = new Vector2(l, b);
uv[13] = new Vector2(l, t);
uv[14] = new Vector2(r, t);
uv[15] = new Vector2(r, b);
}
}
private void FillMesh() {
mesh.vertices = vertices;
mesh.uv = uv;
}
private void RecalculateMesh() {
mesh.RecalculateBounds();
mesh.RecalculateNormals();
}
#if UNITY_EDITOR
private void OnValidate() {
if (mesh != null) {
UpdateMesh();
}
}
#endif
}
}

columnchart using gwt visualization api

I am new to gwt visualization. I want to create a Column chart using gwt visualization api.
Problem is I am not able to plot values on x-axis. I am not sure how the x and y axis values are plotted. Y axis values are plotted automatically but not for x axis.
Runnable onLoadCallback = new Runnable() {
public void run() {
// Create a column chart visualization.
ColumnChart colChart = new ColumnChart(createTable(), createOptions());
basePanel.add(colChart);
}
};
VisualizationUtils.loadVisualizationApi(onLoadCallback, ColumnChart.PACKAGE);
private Options createOptions() {
Options options = Options.create();
options.setWidth(500);
options.setHeight(400);
options.set3D(true);
options.setTitle("Velocity");
options.setTitleX("Iterations");
options.setTitleY("Points accepted");
return options;
}
private AbstractDataTable createTable() {
final DataTable data = DataTable.create();
data.addColumn(ColumnType.NUMBER, "Points");
data.addRows(3);
data.setValue(0, 0, 1);
data.setValue(1, 0, 5);
data.setValue(2, 0, 9);
return data;
}
Can anybody tell how these values are plotted and how to achieve this? I am using a gwt visualization 1.0.2.jar.