let BarycentreOrderingStrategy be aware of the current view scaling to enhance ranking

This commit is contained in:
Martin Pernollet 2012-10-21 20:32:18 +02:00
parent 5fc16117e2
commit a3bc8973ca
35 changed files with 268 additions and 184 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ build
doc/javadoc
.settings
*.class
*.log

View File

@ -1,6 +1,5 @@
dist
build
doc/javadoc
.settings
*.class
# Package Files #
*.jar
*.war
*.ear

View File

@ -28,13 +28,13 @@ public class ColorMapper implements IColorMappable{
this.max = 1;
}
public ColorMapper(IColorMap colormap, float min, float max){
public ColorMapper(IColorMap colormap, double min, double max){
this.colormap = colormap;
this.min = min;
this.max = max;
}
public ColorMapper(IColorMap colormap, float min, float max, Color factor){
public ColorMapper(IColorMap colormap, double min, double max, Color factor){
this.colormap = colormap;
this.min = min;
this.max = max;
@ -58,7 +58,7 @@ public class ColorMapper implements IColorMappable{
return out;
}
public Color getColor(float v){ //To allow the Color to be a variable independent of the coordinates
public Color getColor(double v){ //To allow the Color to be a variable independent of the coordinates
Color out = colormap.getColor(this, v);
if(factor!=null)
@ -88,25 +88,25 @@ public class ColorMapper implements IColorMappable{
return colormap;
}
public float getMin(){
public double getMin(){
return min;
}
public float getMax(){
public double getMax(){
return max;
}
public void setMin(float value){
public void setMin(double value){
min = value;
}
public void setMax(float value){
public void setMax(double value){
max = value;
}
public void setRange(Range range){
min = (float)range.getMin();
max = (float)range.getMax();
min = (double)range.getMin();
max = (double)range.getMax();
}
public Range getRange(){
@ -114,8 +114,8 @@ public class ColorMapper implements IColorMappable{
}
public void setScale(Scale range){
min = (float)range.getMin();
max = (float)range.getMax();
min = (double)range.getMin();
max = (double)range.getMax();
}
public Scale getScale(){
@ -130,8 +130,8 @@ public class ColorMapper implements IColorMappable{
/* */
protected float min;
protected float max;
protected double min;
protected double max;
protected IColorMap colormap;
protected Color factor = null;
}

View File

@ -16,24 +16,24 @@ public interface IColorMappable {
* Retrieve the lower value boundary for a {@link IColorMap}.
* @return the minimum Z value
*/
public float getMin();
public double getMin();
/**
* Retrieve the upper value boundary for a {@link IColorMap}.
* @return the maximum Z value
*/
public float getMax();
public double getMax();
/**
* Set the lower value boundary for a {@link IColorMap}.
* @param value the minimum Z value
*/
public void setMin(float value);
public void setMin(double value);
/**
* Set the upper value boundary for a {@link IColorMap}.
* @param value the maximum Z value
*/
public void setMax(float value);
public void setMax(double value);
}

View File

@ -3,6 +3,7 @@ package org.jzy3d.colors;
import java.util.List;
import org.jzy3d.colors.colormaps.IColorMap;
import org.jzy3d.maths.Array;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.maths.Statistics;
import org.jzy3d.plot3d.primitives.AbstractDrawable;
@ -45,8 +46,13 @@ public class OrderingStrategyScoreColorMapper extends ColorMapper{
scores[k++] = s.score(d);
}
min = (float)Statistics.min(scores);
max = (float)Statistics.max(scores);
min = Statistics.min(scores);
max = Statistics.max(scores);
if(min==max){
System.err.println(OrderingStrategyScoreColorMapper.class.getSimpleName() + " !! min = max = "+min);
//Array.print(scores);
}
}
public Color getColor(Coord3d coord){

View File

@ -29,11 +29,11 @@ public class ColorMapGrayscale implements IColorMap{
return direction;
}
public Color getColor( IColorMappable colorable, float x, float y, float z ){
public Color getColor( IColorMappable colorable, double x, double y, double z ){
return getColor( x, y, z, colorable.getMin(), colorable.getMax() );
}
public Color getColor( float x, float y, float z, float zMin, float zMax ){
public Color getColor( double x, double y, double z, double zMin, double zMax ){
double rel_value = 0;
@ -51,7 +51,7 @@ public class ColorMapGrayscale implements IColorMap{
return new Color( r, v, b );
}
public Color getColor( IColorMappable colorable, float z ){
public Color getColor( IColorMappable colorable, double z ){
return getColor( 0.0f, 0.0f, z, colorable.getMin(), colorable.getMax() ); //To re-use the existing code
}

View File

@ -30,7 +30,7 @@ public class ColorMapHotCold implements IColorMap {
return direction;
}
public Color getColor( IColorMappable colorable, float x, float y, float z ){
public Color getColor( IColorMappable colorable, double x, double y, double z ){
return getColor( x, y, z, colorable.getMin(), colorable.getMax() );
}
@ -38,9 +38,9 @@ public class ColorMapHotCold implements IColorMap {
* A helper for getColor( ColorMappable waferview, Point3d pt ) that calls
* other helper functions
*/
private Color getColor( float x, float y, float z, float zMin, float zMax ){
private Color getColor( double x, double y, double z, double zMin, double zMax ){
float rel_value = 0;
double rel_value = 0;
if( z < zMin )
rel_value = 0;
@ -53,25 +53,25 @@ public class ColorMapHotCold implements IColorMap {
rel_value = ( zMax - z ) / ( zMax - zMin );
}
float b = (float) colorComponentAbsolute( rel_value, -0.250f, +0.875f, +0.250f, +0.500f );
float v = (float) colorComponentAbsolute( rel_value, +0.125f, +0.875f, +0.500f, +0.500f );
float r = (float) colorComponentAbsolute( rel_value, +0.125f, +1.250f, +0.500f, +0.750f );
float b = (float) colorComponentAbsolute( rel_value, -0.250, +0.875, +0.250, +0.500 );
float v = (float) colorComponentAbsolute( rel_value, +0.125, +0.875, +0.500, +0.500 );
float r = (float) colorComponentAbsolute( rel_value, +0.125, +1.250, +0.500, +0.750 );
return new Color( r, v, b );
}
public Color getColor( IColorMappable colorable, float z ){
public Color getColor( IColorMappable colorable, double z ){
return getColor( 0.0f, 0.0f, z, colorable.getMin(), colorable.getMax() ); //To re-use the existing code
}
/*private float creneau_relatif( float value, float center, float topwidth, float bottomwidth ){
/*private double creneau_relatif( double value, double center, double topwidth, double bottomwidth ){
return creneau_absolu( value, center-(bottomwidth/2), center+(bottomwidth/2), center-(topwidth/2), center+(topwidth/2) );
}*/
private float colorComponentAbsolute( float value, float bLeft, float bRight, float tLeft, float tRight ){
float output = 0;
private double colorComponentAbsolute( double value, double bLeft, double bRight, double tLeft, double tRight ){
double output = 0;
// a gauche ou a droite du creneau
if( (value < bLeft) || (value >= bRight) ){
output = 0;

View File

@ -19,13 +19,13 @@ public class ColorMapRBG implements IColorMap {
}
public Color getColor( IColorMappable colorable, float x, float y, float z ){
public Color getColor( IColorMappable colorable, double x, double y, double z ){
return getColor( x, y, z, colorable.getMin(), colorable.getMax() );
}
private Color getColor( float x, float y, float z, float zMin, float zMax ){
private Color getColor( double x, double y, double z, double zMin, double zMax ){
float rel_value = 0;
double rel_value = 0;
if( z < zMin )
rel_value = 0;
@ -45,7 +45,7 @@ public class ColorMapRBG implements IColorMap {
return new Color( r, v, b );
}
public Color getColor( IColorMappable colorable, float z ){
public Color getColor( IColorMappable colorable, double z ){
return getColor( 0.0f, 0.0f, z, colorable.getMin(), colorable.getMax() ); //To re-use the existing code
}
@ -89,7 +89,7 @@ public class ColorMapRBG implements IColorMap {
* @param bottomwidth
* @return color influence.
*/
private float colorComponentRelative( float value, float center, float topwidth, float bottomwidth ){
private double colorComponentRelative( double value, double center, double topwidth, double bottomwidth ){
return colorComponentAbsolute( value, center-(bottomwidth/2), center+(bottomwidth/2), center-(topwidth/2), center+(topwidth/2) );
}
@ -116,8 +116,8 @@ public class ColorMapRBG implements IColorMap {
*
* @return color influence.
*/
private float colorComponentAbsolute( float value, float bLeft, float bRight, float tLeft, float tRight ){
float output = 0;
private double colorComponentAbsolute( double value, double bLeft, double bRight, double tLeft, double tRight ){
double output = 0;
// a gauche ou a droite du creneau
if( (value < bLeft) || (value >= bRight) ){
output = 0;

View File

@ -44,7 +44,7 @@ public class ColorMapRainbow implements IColorMap {
}
public Color getColor(IColorMappable colorable, float x, float y, float z) {
public Color getColor(IColorMappable colorable, double x, double y, double z) {
return getColor( x, y, z, colorable.getMin(), colorable.getMax() );
}
@ -52,9 +52,9 @@ public class ColorMapRainbow implements IColorMap {
* A helper for getColor( ColorMappable waferview, Point3d pt ) that calls
* other helper functions
*/
private Color getColor( float x, float y, float z, float zMin, float zMax ){
private Color getColor( double x, double y, double z, double zMin, double zMax ){
float rel_value = 0;
double rel_value = 0;
if( z < zMin )
rel_value = 0;
@ -74,7 +74,7 @@ public class ColorMapRainbow implements IColorMap {
return new Color( r, v, b );
}
public Color getColor( IColorMappable colorable, float z ){
public Color getColor( IColorMappable colorable, double z ){
return getColor( 0.0f, 0.0f, z, colorable.getMin(), colorable.getMax() ); //To re-use the existing code
}
@ -118,7 +118,7 @@ public class ColorMapRainbow implements IColorMap {
* @param bottomwidth
* @return color influence.
*/
private float colorComponentRelative( float value, float center, float topwidth, float bottomwidth ){
private double colorComponentRelative( double value, double center, double topwidth, double bottomwidth ){
return colorComponentAbsolute( value, center-(bottomwidth/2), center+(bottomwidth/2), center-(topwidth/2), center+(topwidth/2) );
}
@ -145,8 +145,8 @@ public class ColorMapRainbow implements IColorMap {
*
* @return color influence.
*/
private float colorComponentAbsolute( float value, float bLeft, float bRight, float tLeft, float tRight ){
float output = 0;
private double colorComponentAbsolute( double value, double bLeft, double bRight, double tLeft, double tRight ){
double output = 0;
// a gauche ou a droite du creneau
if( (value < bLeft) || (value >= bRight) ){
output = 0;

View File

@ -18,13 +18,13 @@ public class ColorMapRedAndGreen implements IColorMap {
return direction;
}
public Color getColor( IColorMappable colorable, float x, float y, float z ){
public Color getColor( IColorMappable colorable, double x, double y, double z ){
return getColor( x, y, z, colorable.getMin(), colorable.getMax() );
}
private Color getColor( float x, float y, float z, float zMin, float zMax ){
private Color getColor( double x, double y, double z, double zMin, double zMax ){
float rel_value = 0;
double rel_value = 0;
if( z < zMin )
rel_value = 0;
@ -44,16 +44,16 @@ public class ColorMapRedAndGreen implements IColorMap {
return new Color( r, v, b );
}
public Color getColor( IColorMappable colorable, float z ){
public Color getColor( IColorMappable colorable, double z ){
return getColor( 0.0f, 0.0f, z, colorable.getMin(), colorable.getMax() ); //To re-use the existing code
}
private float colorComponentRelative( float value, float center, float topwidth, float bottomwidth ){
private double colorComponentRelative( double value, double center, double topwidth, double bottomwidth ){
return colorComponentAbsolute( value, center-(bottomwidth/2), center+(bottomwidth/2), center-(topwidth/2), center+(topwidth/2) );
}
private float colorComponentAbsolute( float value, float bLeft, float bRight, float tLeft, float tRight ){
float output = 0;
private double colorComponentAbsolute( double value, double bLeft, double bRight, double tLeft, double tRight ){
double output = 0;
// a gauche ou a droite du creneau
if( (value < bLeft) || (value >= bRight) ){
output = 0;

View File

@ -29,7 +29,7 @@ public class ColorMapWhiteBlue implements IColorMap {
return direction;
}
public Color getColor( IColorMappable colorable, float x, float y, float z ){
public Color getColor( IColorMappable colorable, double x, double y, double z ){
return getColor( x, y, z, colorable.getMin(), colorable.getMax() );
}
@ -37,9 +37,9 @@ public class ColorMapWhiteBlue implements IColorMap {
* A helper for getColor( ColorMappable waferview, Point3d pt ) that calls
* other helper functions
*/
private Color getColor( float x, float y, float z, float zMin, float zMax ){
private Color getColor( double x, double y, double z, double zMin, double zMax ){
float rel_value = 0;
double rel_value = 0;
if( z < zMin )
rel_value = 0;
@ -52,10 +52,10 @@ public class ColorMapWhiteBlue implements IColorMap {
rel_value = ( zMax - z ) / ( zMax - zMin );
}
return new Color( rel_value, rel_value, 1.0f );
return new Color( (float)rel_value, (float)rel_value, 1.0f );
}
public Color getColor( IColorMappable colorable, float z ){
public Color getColor( IColorMappable colorable, double z ){
return getColor( 0.0f, 0.0f, z, colorable.getMin(), colorable.getMax() ); //To re-use the existing code
}

View File

@ -30,7 +30,7 @@ public class ColorMapWhiteGreen implements IColorMap {
return direction;
}
public Color getColor( IColorMappable colorable, float x, float y, float z ){
public Color getColor( IColorMappable colorable, double x, double y, double z ){
return getColor( x, y, z, colorable.getMin(), colorable.getMax() );
}
@ -38,9 +38,9 @@ public class ColorMapWhiteGreen implements IColorMap {
* A helper for getColor( ColorMappable waferview, Point3d pt ) that calls
* other helper functions
*/
private Color getColor( float x, float y, float z, float zMin, float zMax ){
private Color getColor( double x, double y, double z, double zMin, double zMax ){
float rel_value = 0;
double rel_value = 0;
if( z < zMin )
rel_value = 0;
@ -53,10 +53,10 @@ public class ColorMapWhiteGreen implements IColorMap {
rel_value = ( zMax - z ) / ( zMax - zMin );
}
return new Color( rel_value, 1.0f, rel_value );
return new Color( (float)rel_value, 1.0f, (float)rel_value );
}
public Color getColor( IColorMappable colorable, float z ){
public Color getColor( IColorMappable colorable, double z ){
return getColor( 0.0f, 0.0f, z, colorable.getMin(), colorable.getMax() ); //To re-use the existing code
}

View File

@ -31,7 +31,7 @@ public class ColorMapWhiteRed implements IColorMap {
}
public Color getColor( IColorMappable colorable, float x, float y, float z ){
public Color getColor( IColorMappable colorable, double x, double y, double z ){
return getColor( x, y, z, colorable.getMin(), colorable.getMax() );
}
@ -39,9 +39,9 @@ public class ColorMapWhiteRed implements IColorMap {
* A helper for getColor( ColorMappable waferview, Point3d pt ) that calls
* other helper functions
*/
private Color getColor( float x, float y, float z, float zMin, float zMax ){
private Color getColor( double x, double y, double z, double zMin, double zMax ){
float rel_value = 0;
double rel_value = 0;
if( z < zMin )
rel_value = 0;
@ -54,10 +54,10 @@ public class ColorMapWhiteRed implements IColorMap {
rel_value = ( zMax - z ) / ( zMax - zMin );
}
return new Color( 1.0f, rel_value, rel_value );
return new Color( 1.0f, (float)rel_value, (float)rel_value );
}
public Color getColor( IColorMappable colorable, float z ){
public Color getColor( IColorMappable colorable, double z ){
return getColor( 0.0f, 0.0f, z, colorable.getMin(), colorable.getMax() ); //To re-use the existing code
}

View File

@ -26,7 +26,7 @@ public interface IColorMap {
* @param z
* @return a color for the given point.
*/
Color getColor( IColorMappable colorable, float x, float y, float z );
Color getColor( IColorMappable colorable, double x, double y, double z );
/**
*
* @param colorable A @link ColorMappable object.
@ -34,7 +34,7 @@ public interface IColorMap {
* @return a color for the given point.
*/
Color getColor(IColorMappable colorable, float v);
Color getColor(IColorMappable colorable, double v);
/**
* Indicates if the colormap use the standard or reverted color direction

View File

@ -629,20 +629,20 @@ public class GridLoader implements IColorMappable{
/**********************************************************************/
public float getMin(){
public double getMin(){
return colorZmin;
}
public float getMax(){
public double getMax(){
return colorZmax;
}
public void setMin(float zmin){
colorZmin = zmin;
public void setMin(double zmin){
colorZmin = (float)zmin;
}
public void setMax(float zmax){
colorZmax = zmax;
public void setMax(double zmax){
colorZmax = (float)zmax;
}
/**********************************************************************/

View File

@ -56,8 +56,7 @@ public class ColorbarImageGenerator {
// Draw colorbar centering in half the Legend text height
for(int h=txtSize/2; h<=(height-txtSize/2); h++){
// Compute value & color
float v = min + (max-min) * ((float)h)/((float)(height-txtSize));
// Color c = mapper.getColor(new Coord3d(0,0,v));
double v = min + (max-min) * ((float)h)/((float)(height-txtSize));
Color c = mapper.getColor(v); //To allow the Color to be a variable independent of the coordinates
// Draw line
@ -71,12 +70,12 @@ public class ColorbarImageGenerator {
// Text annotation
if(provider!=null){
float[] ticks = provider.generateTicks(min, max);
float ypos;
double[] ticks = provider.generateTicks(min, max);
int ypos;
String txt;
for(int t=0; t<ticks.length; t++){
// ypos = (int)(height-height*((ticks[t]-min)/(max-min)));
ypos = (int)txtSize+(height-txtSize-(height-txtSize)*((ticks[t]-min)/(max-min))); //Making sure that the first and last tick appear in the colorbar
ypos = (int)(txtSize+(height-txtSize-(height-txtSize)*((ticks[t]-min)/(max-min)))); //Making sure that the first and last tick appear in the colorbar
txt = renderer.format(ticks[t]);
graphic.drawString(txt, barWidth+1, ypos);
}
@ -115,8 +114,8 @@ public class ColorbarImageGenerator {
protected ColorMapper mapper;
protected ITickProvider provider;
protected ITickRenderer renderer;
protected float min;
protected float max;
protected double min;
protected double max;
protected boolean hasBackground = false;
protected java.awt.Color backgroundColor;
protected java.awt.Color foregroundColor = java.awt.Color.BLACK;

View File

@ -416,31 +416,31 @@ public class AxeBox implements IAxe{
protected void drawGridOnQuad(GL2 gl, int quad){
// Draw X grid along X axis
if((quad!=0)&&(quad!=1)){
float[] xticks = layout.getXTicks();
double[] xticks = layout.getXTicks();
for(int t=0; t<xticks.length; t++){
gl.glBegin(GL2.GL_LINES);
gl.glVertex3f( xticks[t], quady[quad][0], quadz[quad][0]);
gl.glVertex3f( xticks[t], quady[quad][2], quadz[quad][2]);
gl.glVertex3d( xticks[t], quady[quad][0], quadz[quad][0]);
gl.glVertex3d( xticks[t], quady[quad][2], quadz[quad][2]);
gl.glEnd();
}
}
// Draw Y grid along Y axis
if((quad!=2)&&(quad!=3)){
float[] yticks = layout.getYTicks();
double[] yticks = layout.getYTicks();
for(int t=0; t<yticks.length; t++){
gl.glBegin(GL2.GL_LINES);
gl.glVertex3f( quadx[quad][0], yticks[t], quadz[quad][0]);
gl.glVertex3f( quadx[quad][2], yticks[t], quadz[quad][2]);
gl.glVertex3d( quadx[quad][0], yticks[t], quadz[quad][0]);
gl.glVertex3d( quadx[quad][2], yticks[t], quadz[quad][2]);
gl.glEnd();
}
}
// Draw Z grid along Z axis
if((quad!=4)&&(quad!=5)){
float[] zticks = layout.getZTicks();
double[] zticks = layout.getZTicks();
for(int t=0; t<zticks.length; t++){
gl.glBegin(GL2.GL_LINES);
gl.glVertex3f( quadx[quad][0], quady[quad][0], zticks[t]);
gl.glVertex3f( quadx[quad][2], quady[quad][2], zticks[t]);
gl.glVertex3d( quadx[quad][0], quady[quad][0], zticks[t]);
gl.glVertex3d( quadx[quad][2], quady[quad][2], zticks[t]);
gl.glEnd();
}
}
@ -478,15 +478,15 @@ public class AxeBox implements IAxe{
// Computes POSition of ticks lying on the selected axe
// (i.e. 1st point of the tick line)
float xpos = normx[quad_0] + normx[quad_1];
float ypos = normy[quad_0] + normy[quad_1];
float zpos = normz[quad_0] + normz[quad_1];
double xpos = normx[quad_0] + normx[quad_1];
double ypos = normy[quad_0] + normy[quad_1];
double zpos = normz[quad_0] + normz[quad_1];
// Variables for storing the position of the LABel position
// (2nd point on the tick line)
float xlab;
float ylab;
float zlab;
double xlab;
double ylab;
double zlab;
// Computes the DIRection of the ticks
// assuming initial vector point is the center
@ -531,7 +531,7 @@ public class AxeBox implements IAxe{
}
// Retrieve the selected tick positions
float ticks[];
double ticks[];
if(direction==AXE_X)
ticks = layout.getXTicks();
else if(direction==AXE_Y)
@ -572,8 +572,8 @@ public class AxeBox implements IAxe{
// Draw the tick line
gl.glBegin(GL2.GL_LINES);
gl.glVertex3f( xpos, ypos, zpos );
gl.glVertex3f( xlab, ylab, zlab );
gl.glVertex3d( xpos, ypos, zpos );
gl.glVertex3d( xlab, ylab, zlab );
gl.glEnd();
// Select the alignement of the tick label

View File

@ -50,7 +50,7 @@ public class AxeBoxLayout implements IAxeLayout{
}
@Override
public float[] getXTicks(float min, float max) {
public double[] getXTicks(double min, double max) {
lastXmin = min;
lastXmax = max;
xTicks = xTickProvider.generateTicks(min, max);
@ -58,7 +58,7 @@ public class AxeBoxLayout implements IAxeLayout{
}
@Override
public float[] getYTicks(float min, float max) {
public double[] getYTicks(double min, double max) {
lastYmin = min;
lastYmax = max;
yTicks = yTickProvider.generateTicks(min, max);
@ -66,7 +66,7 @@ public class AxeBoxLayout implements IAxeLayout{
}
@Override
public float[] getZTicks(float min, float max) {
public double[] getZTicks(double min, double max) {
lastZmin = min;
lastZmax = max;
zTicks = zTickProvider.generateTicks(min, max);
@ -97,15 +97,15 @@ public class AxeBoxLayout implements IAxeLayout{
zAxeLabel = axeLabel;
}
public float[] getXTicks() {
public double[] getXTicks() {
return xTicks;
}
public float[] getYTicks() {
public double[] getYTicks() {
return yTicks;
}
public float[] getZTicks() {
public double[] getZTicks() {
return zTicks;
}
@ -273,9 +273,9 @@ public class AxeBoxLayout implements IAxeLayout{
protected boolean yAxeLabelDisplayed;
protected boolean zAxeLabelDisplayed;
protected float xTicks[];
protected float yTicks[];
protected float zTicks[];
protected double xTicks[];
protected double yTicks[];
protected double zTicks[];
protected ITickProvider xTickProvider;
protected ITickProvider yTickProvider;
@ -298,12 +298,12 @@ public class AxeBoxLayout implements IAxeLayout{
protected Color quadColor;
protected Color gridColor;
protected float lastXmin = Float.NaN;
protected float lastXmax = Float.NaN;
protected float lastYmin = Float.NaN;
protected float lastYmax = Float.NaN;
protected float lastZmin = Float.NaN;
protected float lastZmax = Float.NaN;
protected double lastXmin = Float.NaN;
protected double lastXmax = Float.NaN;
protected double lastYmin = Float.NaN;
protected double lastYmax = Float.NaN;
protected double lastZmin = Float.NaN;
protected double lastZmax = Float.NaN;
protected Color mainColor;
}

View File

@ -59,12 +59,12 @@ public interface IAxeLayout {
public void updateYTicks(float min, float max);
public void updateZTicks(float min, float max);*/
public float[] getXTicks(float min, float max);
public float[] getYTicks(float min, float max);
public float[] getZTicks(float min, float max);
public float[] getXTicks();
public float[] getYTicks();
public float[] getZTicks();
public double[] getXTicks(double min, double max);
public double[] getYTicks(double min, double max);
public double[] getZTicks(double min, double max);
public double[] getXTicks();
public double[] getYTicks();
public double[] getZTicks();
public void setXTickColor(Color color);
public void setYTickColor(Color color);

View File

@ -3,7 +3,7 @@ package org.jzy3d.plot3d.primitives.axes.layout.providers;
public abstract class AbstractTickProvider implements ITickProvider{
@Override
public float[] generateTicks(float min, float max) {
public double[] generateTicks(double min, double max) {
return generateTicks( min, max, getDefaultSteps() );
}
}

View File

@ -1,7 +1,7 @@
package org.jzy3d.plot3d.primitives.axes.layout.providers;
public interface ITickProvider {
public float[] generateTicks(float min, float max);
public float[] generateTicks(float min, float max, int steps);
public double[] generateTicks(double min, double max);
public double[] generateTicks(double min, double max, int steps);
public int getDefaultSteps();
}

View File

@ -11,9 +11,9 @@ public class RegularTickProvider extends AbstractTickProvider implements ITickPr
}
@Override
public float[] generateTicks(float min, float max, int steps) {
float[] ticks = new float[steps];
float step = (max-min)/(steps-1);
public double[] generateTicks(double min, double max, int steps) {
double[] ticks = new double[steps];
double step = (max-min)/(steps-1);
ticks[0] = min;
ticks[steps-1] = max;

View File

@ -15,35 +15,35 @@ public class SmartTickProvider extends AbstractTickProvider implements ITickProv
}
@Override
public float[] generateTicks(float min, float max, int steps) {
public double[] generateTicks(double min, double max, int steps) {
if(min == max){
float[] ticks = new float[1];
double[] ticks = new double[1];
ticks[0] = min;
return ticks;
}
else if(min > max)
return new float[0];
return new double[0];
double absscale = Math.floor(Math.log10(max-min));
double relscale = Math.log10(max-min) - absscale;
float ticksize = 0;
double ticksize = 0;
if( relscale < Math.log10(0.2*steps) )
ticksize = (float) (Math.pow(10,absscale)*0.2);
ticksize = (Math.pow(10,absscale)*0.2);
else if( relscale < Math.log10(0.5*steps) )
ticksize = (float) (Math.pow(10,absscale)*0.5);
ticksize = (Math.pow(10,absscale)*0.5);
else if( relscale < Math.log10(1*steps) )
ticksize = (float) Math.pow(10,absscale)*1;
ticksize = Math.pow(10,absscale)*1;
else
ticksize = (float) Math.pow(10,absscale)*2;
ticksize = Math.pow(10,absscale)*2;
int start = (int)Math.ceil(min/ticksize);
int stop = (int)Math.floor(max/ticksize);
double start = (int)Math.ceil(min/ticksize);
double stop = (int)Math.floor(max/ticksize);
float[] ticks = new float[stop-start+1];
double[] ticks = new double[(int)(stop-start+1)];
for(int t=start; t<=stop; t++)
ticks[t-start] = (t*ticksize);
for(double t=start; t<=stop; t++)
ticks[(int)(t-start)] = (t*ticksize);
return ticks;
}

View File

@ -2,12 +2,12 @@ package org.jzy3d.plot3d.primitives.axes.layout.providers;
public class StaticTickProvider extends AbstractTickProvider implements ITickProvider{
public StaticTickProvider(float[] values){
public StaticTickProvider(double[] values){
this.values = values;
}
@Override
public float[] generateTicks(float min, float max, int steps) {
public double[] generateTicks(double min, double max, int steps) {
return values;
}
@ -16,5 +16,5 @@ public class StaticTickProvider extends AbstractTickProvider implements ITickPro
return 0;
}
protected float[] values;
protected double[] values;
}

View File

@ -16,7 +16,7 @@ public class DateTickRenderer implements ITickRenderer{
}
@Override
public String format(float value) {
public String format(double value) {
Date date = Utils.num2dat( (long)value );
return Utils.dat2str( date, format );
}

View File

@ -13,7 +13,7 @@ public class DefaultDecimalTickRenderer implements ITickRenderer{
}
@Override
public String format(float value) {
public String format(double value) {
return Utils.num2str('g', value, precision);
}

View File

@ -13,7 +13,7 @@ public class FixedDecimalTickRenderer implements ITickRenderer{
}
@Override
public String format(float value) {
public String format(double value) {
return Utils.num2str('f', value, precision);
}

View File

@ -1,5 +1,5 @@
package org.jzy3d.plot3d.primitives.axes.layout.renderers;
public interface ITickRenderer {
public String format(float value);
public String format(double value);
}

View File

@ -5,7 +5,7 @@ public class IntegerTickRenderer implements ITickRenderer{
}
@Override
public String format(float value) {
public String format(double value) {
return "" + (int)value;
}
}

View File

@ -13,7 +13,7 @@ public class ScientificNotationTickRenderer implements ITickRenderer{
}
@Override
public String format(float value) {
public String format(double value) {
return Utils.num2str('e', value, precision);
}

View File

@ -8,25 +8,25 @@ import java.util.Map;
* @author Martin Pernollet
*/
public class TickLabelMap implements ITickRenderer{
public void register(float value, String string){
public void register(double value, String string){
tickValues.put(value, string);
}
public boolean contains(float value){
public boolean contains(double value){
return tickValues.containsKey(value);
}
public Map<Float, String> getMap(){
public Map<Double, String> getMap(){
return tickValues;
}
@Override
public String format(float value) {
public String format(double value) {
if( tickValues.get(value) != null )
return tickValues.get(value);
else
return "";
}
protected Map<Float, String> tickValues = new HashMap<Float, String>();
protected Map<Double, String> tickValues = new HashMap<Double, String>();
}

View File

@ -3,6 +3,7 @@ package org.jzy3d.plot3d.rendering.ordering;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.plot3d.primitives.AbstractDrawable;
import org.jzy3d.plot3d.rendering.view.Camera;
import org.jzy3d.plot3d.rendering.view.View;
/** The {@link BarycentreOrderingStrategy} compare two {@link AbstractDrawable}s by computing
@ -12,6 +13,13 @@ import org.jzy3d.plot3d.rendering.view.Camera;
* @author Martin Pernollet
*/
public class BarycentreOrderingStrategy extends AbstractOrderingStrategy{
public BarycentreOrderingStrategy(){
super();
}
public BarycentreOrderingStrategy(View view){
this.view = view;
}
/**
* Operation must be:
@ -29,11 +37,29 @@ public class BarycentreOrderingStrategy extends AbstractOrderingStrategy{
@Override
public double score(AbstractDrawable d) {
return camera.getDistance(d);
if(view!=null)
return camera.getDistance(d, view.getLastViewScaling());
else
return camera.getDistance(d);
}
@Override
public double score(Coord3d coord) {
return camera.getDistance(coord);
if(view!=null)
return camera.getDistance(coord, view.getLastViewScaling());
else
return camera.getDistance(coord);
}
public View getView() {
return view;
}
public void setView(View view) {
this.view = view;
}
protected View view;
}

View File

@ -3,7 +3,7 @@ package org.jzy3d.plot3d.rendering.ordering;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.plot3d.primitives.AbstractDrawable;
/** The default ordering strategy let drawables be displayed in their original order.*/
/** The default ordering strategy let drawables be displayed in their original order and as thus no computation cost.*/
public class DefaultOrderingStrategy extends AbstractOrderingStrategy{
public int compare(AbstractDrawable o1, AbstractDrawable o2) {
return 0;

View File

@ -409,10 +409,18 @@ public class Camera extends AbstractViewport {
public double getDistance(AbstractDrawable drawable) {
return drawable.getBarycentre().distanceSq(getEye());
}
public double getDistance(AbstractDrawable drawable, Coord3d viewScale) {
return drawable.getBarycentre().distanceSq(getEye().mul(viewScale));
}
public double getDistance(Coord3d coord) {
return coord.distanceSq(getEye());
}
public double getDistance(Coord3d coord, Coord3d viewScale) {
return coord.distanceSq(getEye().mul(viewScale));
}
/********************************************************/

View File

@ -4,11 +4,17 @@ package org.jzy3d.tests;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import org.jzy3d.chart.Chart;
import org.jzy3d.chart.ChartLauncher;
import org.jzy3d.chart.controllers.mouse.camera.CameraMouseController;
import org.jzy3d.chart.controllers.mouse.camera.CameraMouseControllerNewt;
import org.jzy3d.chart.controllers.mouse.camera.ICameraMouseController;
import org.jzy3d.chart.factories.ChartComponentFactory;
import org.jzy3d.chart.factories.IChartComponentFactory;
import org.jzy3d.colors.Color;
import org.jzy3d.colors.ColorMapper;
import org.jzy3d.colors.CompositeColorMapperUpdatePolicy;
@ -19,7 +25,6 @@ import org.jzy3d.events.IViewPointChangedListener;
import org.jzy3d.events.ViewPointChangedEvent;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.maths.Range;
import org.jzy3d.maths.TicToc;
import org.jzy3d.plot3d.builder.Builder;
import org.jzy3d.plot3d.builder.Mapper;
import org.jzy3d.plot3d.builder.concrete.OrthonormalGrid;
@ -30,6 +35,7 @@ import org.jzy3d.plot3d.primitives.axes.layout.renderers.FixedDecimalTickRendere
import org.jzy3d.plot3d.primitives.axes.layout.renderers.ScientificNotationTickRenderer;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.legends.colorbars.ColorbarLegend;
import org.jzy3d.plot3d.rendering.ordering.BarycentreOrderingStrategy;
import org.jzy3d.plot3d.rendering.scene.Graph;
import org.jzy3d.plot3d.rendering.view.Renderer2d;
import org.jzy3d.plot3d.rendering.view.View;
@ -47,7 +53,7 @@ import org.jzy3d.plot3d.text.drawable.DrawableTextBillboard;
*
*/
public class TestOrderingStrategyScoreWithColor {
static double SCALE_FACTOR = 1;
static double SCALE_FACTOR = 100;
public static void main(String[] args) throws Exception {
TestOrderingStrategyScoreWithColor surface = new TestOrderingStrategyScoreWithColor();
@ -55,13 +61,17 @@ public class TestOrderingStrategyScoreWithColor {
}
public void BuildAndLaunch() {
final Chart chart = new Chart(Quality.Advanced, "newt");
IChartComponentFactory factory = getFactory();
final Chart chart = new Chart(factory, Quality.Advanced, "newt");
chart.getAxeLayout().setZTickRenderer(new ScientificNotationTickRenderer(1));
chart.getAxeLayout().setZTickRenderer(new FixedDecimalTickRenderer(0));
chart.getAxeLayout().setYTickRenderer(new FixedDecimalTickRenderer(1));
chart.getAxeLayout().setXTickRenderer(new FixedDecimalTickRenderer(1));
genSurface(chart.getView(), chart.getScene().getGraph(), chart.getAxeLayout());
// allow camera eye transform according to view scaling
BarycentreOrderingStrategy s = (BarycentreOrderingStrategy)chart.getScene().getGraph().getStrategy();
s.setView(chart.getView()); // experimental solution: scale camera eye with current view scaling
genMapperSurface(chart.getView(), chart.getScene().getGraph(), chart.getAxeLayout());
chart.addRenderer(new Renderer2d(){
@Override
@ -69,6 +79,7 @@ public class TestOrderingStrategyScoreWithColor {
Graphics2D g2d = (Graphics2D)g;
g2d.setColor(java.awt.Color.BLACK);
g2d.drawString("eye="+chart.getView().getCamera().getEye(), 20, 20);
g2d.drawString("scaling="+chart.getView().getLastViewScaling(), 20, 50);
}
});
@ -77,6 +88,33 @@ public class TestOrderingStrategyScoreWithColor {
// chart.getView().setSquared(false);
ChartLauncher.openChart(chart);
//chart.getView().getViewPointL
}
private ChartComponentFactory getFactory() {
return new ChartComponentFactory()/*{
@Override
public ICameraMouseController newMouseController(final Chart chart){
ICameraMouseController mouse = null;
if(!chart.getWindowingToolkit().equals("newt"))
mouse = new CameraMouseController(chart){
public void mouseDragged(MouseEvent e){
super.mouseDragged(e);
updateColorMapperRange();
}
};
else
mouse = new CameraMouseControllerNewt(chart){
public void mouseDragged(com.jogamp.newt.event.MouseEvent e){
super.mouseDragged(e);
updateColorMapperRange();
System.out.println("update");
}
};
return mouse;
}
}*/;
}
public void createPoints(final Chart chart) {
@ -101,7 +139,7 @@ public class TestOrderingStrategyScoreWithColor {
/**
* Build a mapper based surface
*/
public Shape genSurface(final View view, final Graph graph, final IAxeLayout layout){
public Shape genMapperSurface(final View view, final Graph graph, final IAxeLayout layout){
Mapper mapper = new Mapper() {
public double f(double x, double y) {
return SCALE_FACTOR * Math.sin(x / 10) * Math.cos(y / 20) * x;
@ -109,19 +147,19 @@ public class TestOrderingStrategyScoreWithColor {
};
Range range = new Range(-150, 150);
int steps = 50;
Shape surface = Builder.buildOrthonormal(new OrthonormalGrid(range, steps, range, steps), mapper);
surface = Builder.buildOrthonormal(new OrthonormalGrid(range, steps, range, steps), mapper);
return createSurface(surface, view, graph, layout);
}
/**
* Build a delaunay based surface
*/
public Shape createSurface(final View view, final Graph graph, final IAxeLayout layout){
public Shape genDelaunaySurface(final View view, final Graph graph, final IAxeLayout layout){
List<Coord3d> data = new ArrayList<Coord3d>();
for (int i = 0; i < _x.length; i++) {
data.add(new Coord3d(_x[i], _y[i], _z[i]));
}
Shape surface = Builder.buildDelaunay(data);
surface = Builder.buildDelaunay(data);
return createSurface(surface, view, graph, layout);
}
@ -131,34 +169,41 @@ public class TestOrderingStrategyScoreWithColor {
public Shape createSurface(final Shape surface, final View view, final Graph graph, final IAxeLayout layout) {
Color factor = new Color(1, 1, 1, 0.75f);
final IColorMap colormap = new ColorMapRainbow();
colormap = new ColorMapRainbow();
colormap.setDirection(false);
final ColorMapper colormapper = new OrderingStrategyScoreColorMapper(colormap, new CompositeColorMapperUpdatePolicy(), graph, factor);
colormapper = new OrderingStrategyScoreColorMapper(colormap, new CompositeColorMapperUpdatePolicy(), graph, factor);
surface.setColorMapper(colormapper);
surface.setWireframeDisplayed(false);
final ColorbarLegend colorbar = new ColorbarLegend(surface, layout);
colorbar = new ColorbarLegend(surface, layout);
surface.setLegend(colorbar);
view.addViewPointChangedListener(new IViewPointChangedListener(){
@Override
public void viewPointChanged(ViewPointChangedEvent e) {
//Coord3d c = graph.getStrategy().getCamera().getEye();
//System.out.println("predraw from eye " + c);
TicToc t = new TicToc();
t.tic();
colormapper.preDraw(surface); // update all distance range
t.toc();
//System.out.println("min:" + colormapper.getMin() + " max:" + colormapper.getMax());
//TicToc t = new TicToc();
//t.tic();
updateColorMapperRange();
//t.toc();
}
});
graph.add(surface);
return surface;
}
public void updateColorMapperRange(){
colormapper.preDraw(surface);
}
protected IColorMap colormap;
protected ColorMapper colormapper;
protected ColorbarLegend colorbar;
protected Shape surface;
private final double[] _x;
private final double[] _y;
private final double[] _z;