/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/* original program:
 * Example.java
 *
 * Created on Mar 13, 2010, 2:46:54 PM
 */
/**
 *
 * @author siva
 */
//changed by M. Turhan Coban as surfacePlot
// This program plots surfaces from data or functions (or derivative of functions)
// datas can be read from any function 
import java.awt.*;
import javax.swing.*;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import java.awt.FlowLayout;

class f1a extends f_xj
{
public double func(double x[]) 
{
 double ff=(float)(x[0] * Math.sin(x[1]));
return ff; 
}
}



class f6a extends f_xj
{ public int n;
public f6a(int ni){n=ni;}
public double func(double x[]) 
{ f4a ff=new f4a();
 double fx=ff.dfunc(x,n);
 return fx; 
}
}

class f3a extends f_xj
{
public double func(double x[]) 
{
 double ff=21.5+x[0]*Math.sin(4.0*Math.PI*x[0])+x[1]*Math.sin(20.0*Math.PI*x[1]);
return ff; //minimum değil maxsimum istendiğinden - ile çarptık
}
}

class f4a extends f_xj
{
public double func(double x[]) 
{
 double ff=1.0+cos(Math.PI*(x[0]-3.0))*cos(2.0*Math.PI*(x[1]-2.0))/(1+(x[0]-3.0)*(x[0]-3.0)+(x[1]-2.0)*(x[1]-2.0));
return ff; //minimum değil maxsimum istendiğinden - ile çarptık
}
}
public class surfacePlot extends javax.swing.JFrame {
	    private static final long serialVersionUID = 89567567L;
	    ExampleSurfaceModel model;
	    SurfaceCanvas canvas;
	    JPanel southPanel;
	    Container c;
        public void plot()
        {
        canvas.setModel(model);
	    canvas.setSize(1000,1000);
	    canvas.setVisible(true);
        southPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 50, 5));
        southPanel.add(new JLabel("Rotate: Mouse Click & Drag"));
        southPanel.add(new JLabel("Zoom: Shift Key + Mouse Click & Drag"));
        southPanel.add(new JLabel("Move: Control Key + Mouse Click & Drag"));
        add(southPanel, BorderLayout.SOUTH);
	    this.setSize(1000,1000);
	    add(canvas, BorderLayout.CENTER);
	    this.repaint();
	    this.setVisible(true);
    }   
    public surfacePlot(String file,String xLabel, String yLabel,String zLabel,int ni)
    {   //Rear matrix data from text file
	    double xy[][]=Text.readDouble(file);
	    model = new ExampleSurfaceModel(xy,xLabel,yLabel,zLabel,ni);
	    canvas = new SurfaceCanvas();   
	}	
	public surfacePlot(String file,String xLabel, String yLabel,String zLabel)
    {   //Rear matrix data from text file
	    double xy[][]=Text.readDouble(file);
	    model = new ExampleSurfaceModel(xy,xLabel,yLabel,zLabel,80);
	    canvas = new SurfaceCanvas();   
	}
	public surfacePlot(String file)
    {   double xy[][]=Text.readDouble(file);
	    model = new ExampleSurfaceModel(xy,"X","Y","Z",80);
	    canvas = new SurfaceCanvas();   
	}

	public surfacePlot(String file,int ni)
    {   double xy[][]=Text.readDouble(file);
	    model = new ExampleSurfaceModel(xy,"X","Y","Z",ni);
	    canvas = new SurfaceCanvas();   
	}	
	 public surfacePlot(double xy[][],String xLabel, String yLabel,String zLabel)
    {   model = new ExampleSurfaceModel(xy,xLabel,yLabel,zLabel,80);
	    canvas = new SurfaceCanvas();   
	}
    public surfacePlot(double xy[][],String xLabel, String yLabel,String zLabel,int ni)
    {   model = new ExampleSurfaceModel(xy,xLabel,yLabel,zLabel,ni);
	    canvas = new SurfaceCanvas();   
	}
	public surfacePlot(double xy[][],int ni)
    {   model = new ExampleSurfaceModel(xy,ni);
	    canvas = new SurfaceCanvas();   
	}
		public surfacePlot(double xy[][])
    {   model = new ExampleSurfaceModel(xy,80);
	    canvas = new SurfaceCanvas();   
	}
	public surfacePlot(f_xj f,double x0,double xn,double y0,double yN,double z0,double zN,
	String xLabel, String yLabel,String zLabel)
    {   model = new ExampleSurfaceModel(f,x0,xn,y0,yN,z0,zN,xLabel,yLabel,zLabel,80);
	    canvas = new SurfaceCanvas();   
	}
	public surfacePlot(if_xj f,double x0,double xn,double y0,double yN,double z0,double zN,
	String xLabel, String yLabel,String zLabel)
    {   model = new ExampleSurfaceModel(f,x0,xn,y0,yN,z0,zN,xLabel,yLabel,zLabel,80);
	    canvas = new SurfaceCanvas();   
	}
    public surfacePlot(f_xj f,double x0,double xn,double y0,double yN,double z0,double zN,
	String xLabel, String yLabel,String zLabel,int ni)
    {   model = new ExampleSurfaceModel(f,x0,xn,y0,yN,z0,zN,xLabel,yLabel,zLabel,ni);
	    canvas = new SurfaceCanvas();   
	}
	public surfacePlot(if_xj f,double x0,double xn,double y0,double yN,double z0,double zN,
	String xLabel, String yLabel,String zLabel,int ni)
    {   model = new ExampleSurfaceModel(f,x0,xn,y0,yN,z0,zN,xLabel,yLabel,zLabel,ni);
	    canvas = new SurfaceCanvas();   
	}
    public static double[][] convertdata(double a[][],double x0,double xN,double y0,double yN)
    { //converts to x,y,z data format
	    int n=a.length;
     int m=a[0].length;
     int k=n*m;
     int l=0;
     double b[][]=new double[k][3];
     double x,y,z;
     for(int i=0;i<n;i++)
     {for(int j=0;j<m;j++)
       {x=x0+(xN-x0)*j;
        y=y0+(yN-y0)*i;
        z=a[i][j];
        l=i*j;
        b[l][0]=x;
        b[l][1]=y;
        b[l][2]=z;
       }
     }
     return b;
    }
    
    public static void main(String args[]) {
	    double a[][]=Text.readDouble("a.txt");
	    f2a f=new f2a(a,5);
	    surfacePlot p=new surfacePlot(f,-5.0,5.0,-5.0,5.0,-10.0,10.0,"X","Y","Z",50);
        p.plot();
        //f5 ff=new f5(a,5,0);
        //surfacePlot p1=new surfacePlot(ff,0.0,10.0,-10.0,10.0,-10.0,10.0,"X","Y","Z",150);
        //p1.plot();
    }
}