mirror of https://github.com/rusefi/jzy3d-api.git
One more drawable ScatterPoint supporting LightPoint+1 more time serie 2d
This commit is contained in:
parent
0d95faf38d
commit
271292f59e
|
@ -9,6 +9,7 @@ import org.jzy3d.chart.AWTChart;
|
|||
import org.jzy3d.chart.factories.IChartComponentFactory;
|
||||
import org.jzy3d.chart.factories.IChartComponentFactory.Toolkit;
|
||||
import org.jzy3d.chart2d.primitives.LineSerie2d;
|
||||
import org.jzy3d.chart2d.primitives.ScatterPointSerie2d;
|
||||
import org.jzy3d.chart2d.primitives.ScatterSerie2d;
|
||||
import org.jzy3d.chart2d.primitives.Serie2d;
|
||||
import org.jzy3d.maths.BoundingBox3d;
|
||||
|
@ -34,6 +35,10 @@ public class Chart2d extends AWTChart {
|
|||
public Chart2d(Toolkit toolkit) {
|
||||
this(new Chart2dComponentFactory(), Quality.Intermediate, toolkit.toString());
|
||||
|
||||
layout2d();
|
||||
}
|
||||
|
||||
public void layout2d() {
|
||||
IAxeLayout axe = getAxeLayout();
|
||||
axe.setZAxeLabelDisplayed(false);
|
||||
axe.setTickLineDisplayed(false);
|
||||
|
@ -70,6 +75,8 @@ public class Chart2d extends AWTChart {
|
|||
serie = new LineSerie2d(name);
|
||||
else if (Serie2d.Type.SCATTER.equals(type))
|
||||
serie = new ScatterSerie2d(name);
|
||||
else if (Serie2d.Type.SCATTER_POINTS.equals(type))
|
||||
serie = new ScatterPointSerie2d(name);
|
||||
else
|
||||
throw new IllegalArgumentException("Unsupported serie type " + type);
|
||||
return serie;
|
||||
|
@ -83,6 +90,7 @@ public class Chart2d extends AWTChart {
|
|||
|
||||
public Chart2d(IChartComponentFactory factory, Quality quality, String windowingToolkit) {
|
||||
super(factory, quality, windowingToolkit);
|
||||
layout2d();
|
||||
}
|
||||
|
||||
public Chart2d(IChartComponentFactory components, Quality quality) {
|
||||
|
|
|
@ -18,6 +18,12 @@ public class Chart2dComponentFactory extends AWTChartComponentFactory{
|
|||
public Chart newChart(IChartComponentFactory factory, Quality quality, String toolkit){
|
||||
return new Chart2d(factory, quality, toolkit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chart newChart(Quality quality, Toolkit toolkit) {
|
||||
return new Chart2d(this, quality, toolkit.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAxe newAxe(BoundingBox3d box, View view) {
|
||||
AxeBox2d axe = new AxeBox2d(box);
|
||||
|
@ -30,20 +36,20 @@ public class Chart2dComponentFactory extends AWTChartComponentFactory{
|
|||
return new View2d(this, scene, canvas, quality);
|
||||
}
|
||||
|
||||
public static Chart chart() {
|
||||
return chart(Quality.Intermediate);
|
||||
public static Chart2d chart() {
|
||||
return (Chart2d)chart(Quality.Intermediate);
|
||||
}
|
||||
public static Chart chart(Quality quality) {
|
||||
return f.newChart(quality, Toolkit.newt);
|
||||
public static Chart2d chart(Quality quality) {
|
||||
return (Chart2d)f.newChart(quality, Toolkit.newt);
|
||||
}
|
||||
public static Chart chart(String toolkit) {
|
||||
return f.newChart(Chart.DEFAULT_QUALITY, toolkit);
|
||||
public static Chart2d chart(String toolkit) {
|
||||
return (Chart2d)f.newChart(Chart.DEFAULT_QUALITY, toolkit);
|
||||
}
|
||||
public static Chart chart(Quality quality, Toolkit toolkit) {
|
||||
return f.newChart(quality, toolkit);
|
||||
public static Chart2d chart(Quality quality, Toolkit toolkit) {
|
||||
return (Chart2d)f.newChart(quality, toolkit);
|
||||
}
|
||||
public static Chart chart(Quality quality, String toolkit) {
|
||||
return f.newChart(quality, toolkit);
|
||||
public static Chart2d chart(Quality quality, String toolkit) {
|
||||
return (Chart2d)f.newChart(quality, toolkit);
|
||||
}
|
||||
|
||||
static Chart2dComponentFactory f = new Chart2dComponentFactory();
|
||||
|
|
|
@ -5,9 +5,8 @@ import java.util.List;
|
|||
import org.jzy3d.colors.Color;
|
||||
import org.jzy3d.maths.Coord2d;
|
||||
import org.jzy3d.maths.Coord3d;
|
||||
import org.jzy3d.plot3d.primitives.AbstractDrawable;
|
||||
import org.jzy3d.plot3d.primitives.Point;
|
||||
import org.jzy3d.plot3d.primitives.ConcurrentLineStrip;
|
||||
import org.jzy3d.plot3d.primitives.Point;
|
||||
|
||||
public class LineSerie2d implements Serie2d {
|
||||
protected ConcurrentLineStrip line = new ConcurrentLineStrip();
|
||||
|
@ -33,6 +32,11 @@ public class LineSerie2d implements Serie2d {
|
|||
line.add(new Point(new Coord3d(c.x, c.y, 0)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Coord2d c, Color color) {
|
||||
line.add(new Point(new Coord3d(c.x, c.y, 0), color));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(List<Coord2d> c) {
|
||||
for(Coord2d c2: c){
|
||||
|
@ -64,5 +68,10 @@ public class LineSerie2d implements Serie2d {
|
|||
public void clear() {
|
||||
line.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidth(int width) {
|
||||
line.setWireframeWidth(width);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
package org.jzy3d.chart2d.primitives;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jzy3d.colors.Color;
|
||||
import org.jzy3d.maths.Coord2d;
|
||||
import org.jzy3d.maths.Coord3d;
|
||||
import org.jzy3d.plot3d.primitives.AbstractDrawable;
|
||||
import org.jzy3d.plot3d.primitives.ConcurrentScatterPoint;
|
||||
import org.jzy3d.plot3d.primitives.LightPoint;
|
||||
|
||||
// TODO : create LightPoint that don't hold a bounding box
|
||||
public class ScatterPointSerie2d implements Serie2d {
|
||||
protected ConcurrentScatterPoint scatter;
|
||||
protected String name;
|
||||
protected Color defaultColor = Color.YELLOW.clone();
|
||||
|
||||
public ScatterPointSerie2d(String name){
|
||||
this.name = name;
|
||||
this.scatter = makeDrawable();
|
||||
}
|
||||
|
||||
protected ConcurrentScatterPoint makeDrawable() {
|
||||
ConcurrentScatterPoint s = new ConcurrentScatterPoint();
|
||||
s.setWidth(3);
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(float x, float y) {
|
||||
scatter.add(new LightPoint(new Coord3d(x, y, 0), defaultColor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(double x, double y) {
|
||||
scatter.add(new LightPoint(new Coord3d(x, y, 0), defaultColor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Coord2d c) {
|
||||
scatter.add(new LightPoint(new Coord3d(c.x, c.y, 0), defaultColor));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Coord2d c, Color color) {
|
||||
scatter.add(new LightPoint(new Coord3d(c.x, c.y, 0), color));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void add(List<Coord2d> c) {
|
||||
for(Coord2d c2: c){
|
||||
scatter.add(new LightPoint(new Coord3d(c2.x, c2.y, 0), defaultColor));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(Color color){
|
||||
//line.setColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor(){
|
||||
return null;//line.getWireframeColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractDrawable getDrawable() {
|
||||
return scatter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
scatter.clear();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setWidth(int width) {
|
||||
scatter.setWidth(width);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -21,6 +21,27 @@ public class ScatterSerie2d implements Serie2d {
|
|||
}
|
||||
|
||||
protected ScatterMultiColorList makeDrawable() {
|
||||
ColorMapRedAndGreen g = colormap();
|
||||
ColorMapper m = colormapper(g);
|
||||
ScatterMultiColorList s = new ConcurrentScatterMultiColorList(m);
|
||||
s.setWidth(3);
|
||||
return s;
|
||||
}
|
||||
|
||||
public ColorMapper colormapper(ColorMapRedAndGreen g) {
|
||||
ColorMapper m = new ColorMapper(g, 0, 1){
|
||||
public Color getColor(Coord3d coord){
|
||||
Color out = colormap.getColor(this, coord.x, coord.z, coord.y);
|
||||
|
||||
if(factor!=null)
|
||||
out.mul(factor);
|
||||
return out;
|
||||
}
|
||||
};
|
||||
return m;
|
||||
}
|
||||
|
||||
public ColorMapRedAndGreen colormap() {
|
||||
ColorMapRedAndGreen g = new ColorMapRedAndGreen(){
|
||||
public Color getColor(double x, double y, double z, double zMin, double zMax) {
|
||||
double rel_value = processRelativeZValue(z, zMin, zMax);
|
||||
|
@ -37,19 +58,7 @@ public class ScatterSerie2d implements Serie2d {
|
|||
}
|
||||
};
|
||||
g.setDirection(false);
|
||||
ColorMapper m = new ColorMapper(g, 0, 1){
|
||||
public Color getColor(Coord3d coord){
|
||||
Color out = colormap.getColor(this, coord.x, coord.z, coord.y);
|
||||
|
||||
if(factor!=null)
|
||||
out.mul(factor);
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
ScatterMultiColorList s = new ConcurrentScatterMultiColorList(m);
|
||||
s.setWidth(3);
|
||||
return s;
|
||||
return g;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,6 +76,12 @@ public class ScatterSerie2d implements Serie2d {
|
|||
scatter.add(new Coord3d(c.x, c.y, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Coord2d c, Color color) {
|
||||
scatter.add(new Coord3d(c.x, c.y, 0));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void add(List<Coord2d> c) {
|
||||
for(Coord2d c2: c){
|
||||
|
@ -98,5 +113,10 @@ public class ScatterSerie2d implements Serie2d {
|
|||
public void clear() {
|
||||
scatter.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidth(int width) {
|
||||
scatter.setWidth(width);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,15 +11,18 @@ public interface Serie2d {
|
|||
public void add(float x, float y);
|
||||
public void add(double x, double y);
|
||||
public void add(Coord2d c);
|
||||
public void add(Coord2d c, Color color);
|
||||
public void add(List<Coord2d> c);
|
||||
public String getName();
|
||||
|
||||
public void setWidth(int width);
|
||||
|
||||
public void setColor(Color color);
|
||||
public Color getColor();
|
||||
|
||||
public AbstractDrawable getDrawable();
|
||||
|
||||
public enum Type{
|
||||
LINE, SCATTER
|
||||
LINE, SCATTER, SCATTER_POINTS
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
package org.jzy3d.plot3d.primitives;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.media.opengl.GL;
|
||||
import javax.media.opengl.GL2;
|
||||
|
||||
import org.jzy3d.maths.Coord3d;
|
||||
import org.jzy3d.plot3d.rendering.compat.GLES2CompatUtils;
|
||||
import org.jzy3d.plot3d.transform.Transform;
|
||||
|
||||
public class ConcurrentScatterPoint extends ScatterPoint {
|
||||
public ConcurrentScatterPoint() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ConcurrentScatterPoint(List<LightPoint> points, float width) {
|
||||
super(points, width);
|
||||
}
|
||||
|
||||
public void drawGLES2() {
|
||||
GLES2CompatUtils.glPointSize(width);
|
||||
GLES2CompatUtils.glBegin(GL2.GL_POINTS);
|
||||
|
||||
if (points != null) {
|
||||
synchronized (points) {
|
||||
for (LightPoint p : points) {
|
||||
GLES2CompatUtils.glColor4f(p.rgb.r, p.rgb.g, p.rgb.b, p.rgb.a);
|
||||
GLES2CompatUtils.glVertex3f(p.xyz.x, p.xyz.y, p.xyz.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
GLES2CompatUtils.glEnd();
|
||||
}
|
||||
|
||||
public void drawGL2(GL gl) {
|
||||
gl.getGL2().glPointSize(width);
|
||||
gl.getGL2().glBegin(GL2.GL_POINTS);
|
||||
|
||||
if (points != null) {
|
||||
synchronized (points) {
|
||||
for (LightPoint p : points) {
|
||||
gl.getGL2().glColor4f(p.rgb.r, p.rgb.g, p.rgb.b, p.rgb.a);
|
||||
gl.getGL2().glVertex3f(p.xyz.x, p.xyz.y, p.xyz.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
gl.getGL2().glEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyGeometryTransform(Transform transform) {
|
||||
synchronized (points) {
|
||||
for (LightPoint p : points) {
|
||||
Coord3d c = p.xyz;
|
||||
c.set(transform.compute(c));
|
||||
}
|
||||
}
|
||||
updateBounds();
|
||||
}
|
||||
|
||||
public void add(LightPoint point) {
|
||||
synchronized (points) {
|
||||
this.points.add(point);
|
||||
}
|
||||
updateBounds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBounds() {
|
||||
bbox.reset();
|
||||
synchronized (points) {
|
||||
for (LightPoint c : points)
|
||||
bbox.add(c.xyz);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package org.jzy3d.plot3d.primitives;
|
||||
|
||||
import org.jzy3d.colors.Color;
|
||||
import org.jzy3d.maths.Coord3d;
|
||||
|
||||
public class LightPoint {
|
||||
public Coord3d xyz;
|
||||
public Color rgb;
|
||||
|
||||
public LightPoint(Coord3d xyz, Color rgb) {
|
||||
this.xyz = xyz;
|
||||
this.rgb = rgb;
|
||||
}
|
||||
}
|
|
@ -94,11 +94,13 @@ public class LineStrip extends AbstractWireframeable {
|
|||
for (Point p : points) {
|
||||
gl.getGL2().glColor4f(p.rgb.r, p.rgb.g, p.rgb.b, p.rgb.a);
|
||||
gl.getGL2().glVertex3f(p.xyz.x, p.xyz.y, p.xyz.z);
|
||||
//System.out.println(p.xyz + p.rgb.toString());
|
||||
}
|
||||
} else {
|
||||
for (Point p : points) {
|
||||
gl.getGL2().glColor4f(wfcolor.r, wfcolor.g, wfcolor.b, wfcolor.a);
|
||||
gl.getGL2().glVertex3f(p.xyz.x, p.xyz.y, p.xyz.z);
|
||||
//System.out.println(p.xyz + wfcolor.toString());
|
||||
}
|
||||
}
|
||||
gl.getGL2().glEnd();
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
package org.jzy3d.plot3d.primitives;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.media.opengl.GL;
|
||||
import javax.media.opengl.GL2;
|
||||
import javax.media.opengl.glu.GLU;
|
||||
|
||||
import org.jzy3d.colors.Color;
|
||||
import org.jzy3d.colors.ISingleColorable;
|
||||
import org.jzy3d.maths.BoundingBox3d;
|
||||
import org.jzy3d.maths.Coord3d;
|
||||
import org.jzy3d.plot3d.rendering.compat.GLES2CompatUtils;
|
||||
import org.jzy3d.plot3d.rendering.view.Camera;
|
||||
import org.jzy3d.plot3d.transform.Transform;
|
||||
|
||||
/**
|
||||
* Experimental 3d object.
|
||||
*
|
||||
* @author Martin Pernollet
|
||||
*
|
||||
*/
|
||||
public class ScatterPoint extends AbstractDrawable implements ISingleColorable {
|
||||
|
||||
public ScatterPoint() {
|
||||
bbox = new BoundingBox3d();
|
||||
setWidth(1.0f);
|
||||
setPoints(new ArrayList<LightPoint>());
|
||||
}
|
||||
|
||||
public ScatterPoint(List<LightPoint> points, float width) {
|
||||
bbox = new BoundingBox3d();
|
||||
setPoints(points);
|
||||
setWidth(width);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
points.clear();;
|
||||
bbox.reset();
|
||||
}
|
||||
|
||||
/* */
|
||||
|
||||
public void draw(GL gl, GLU glu, Camera cam) {
|
||||
doTransform(gl, glu, cam);
|
||||
|
||||
if (gl.isGL2()) {
|
||||
drawGL2(gl);
|
||||
} else {
|
||||
drawGLES2();
|
||||
}
|
||||
|
||||
doDrawBounds(gl, glu, cam);
|
||||
}
|
||||
|
||||
public void drawGLES2() {
|
||||
GLES2CompatUtils.glPointSize(width);
|
||||
GLES2CompatUtils.glBegin(GL2.GL_POINTS);
|
||||
if (points != null) {
|
||||
for (LightPoint p : points) {
|
||||
GLES2CompatUtils.glColor4f(p.rgb.r, p.rgb.g, p.rgb.b, p.rgb.a);
|
||||
GLES2CompatUtils.glVertex3f(p.xyz.x, p.xyz.y, p.xyz.z);
|
||||
}
|
||||
}
|
||||
GLES2CompatUtils.glEnd();
|
||||
}
|
||||
|
||||
public void drawGL2(GL gl) {
|
||||
gl.getGL2().glPointSize(width);
|
||||
gl.getGL2().glBegin(GL2.GL_POINTS);
|
||||
if (points != null) {
|
||||
for (LightPoint p : points) {
|
||||
gl.getGL2().glColor4f(p.rgb.r, p.rgb.g, p.rgb.b, p.rgb.a);
|
||||
gl.getGL2().glVertex3f(p.xyz.x, p.xyz.y, p.xyz.z);
|
||||
}
|
||||
}
|
||||
gl.getGL2().glEnd();
|
||||
}
|
||||
|
||||
public void applyGeometryTransform(Transform transform) {
|
||||
for (LightPoint p : points) {
|
||||
Coord3d c = p.xyz;
|
||||
c.set(transform.compute(c));
|
||||
}
|
||||
updateBounds();
|
||||
}
|
||||
|
||||
/* */
|
||||
|
||||
public void add(LightPoint point) {
|
||||
this.points.add(point);
|
||||
updateBounds();
|
||||
}
|
||||
|
||||
public void setPoints(List<LightPoint> points) {
|
||||
this.points = points;
|
||||
updateBounds();
|
||||
}
|
||||
|
||||
public void updateBounds() {
|
||||
bbox.reset();
|
||||
for (LightPoint c : points)
|
||||
bbox.add(c.xyz);
|
||||
}
|
||||
|
||||
public List<LightPoint> getData() {
|
||||
return points;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the width of the point.
|
||||
*
|
||||
* @param width
|
||||
* point's width
|
||||
*/
|
||||
public void setWidth(float width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public List<LightPoint> points;
|
||||
public float width;
|
||||
}
|
Loading…
Reference in New Issue