Smooth curve


Hi All,

1. I have some N points connected together as a curve.
I want to draw this curve using VisAD. I am able to
draw a set of lines connecting the points using
Gridded2DSets and I want to have the smoothning
effect. Please suggest if there is any example which
does the smoothning of the curve, or suggest me how to
approach in doing this.

2. Is there any way to get the X and Y co-ordinate
values, when a mouse is moved. Please suggest. 

3. The below code is to draw a geometry. The end
points are drawn as real tuples and the lines as
gridded sets. i can see both the functions(drawing
real tuples and drawing gridded sets) working well
when used  individually(commenting the other) but, i
need both the function for the points and lines to be
working togehter. When i run the code with both the
functions the system hangs. At present I have
commented the function to draw the Griddedsets. 
Please suggest with this matter.


import visad.*;
import visad.java2d.DisplayImplJ2D;
import visad.java3d.*;
import java.rmi.RemoteException;
import javax.swing.*;
import java.io.*;
import visad.java2d.*;
import javax.media.j3d.*;
import java.util.Vector;


public class DrawPoints extends Object {
    RealType row, column;
    RealTupleType domain_tuple, rtt;
    DisplayImplJ2D display;
    ScalarMap rowMap, colMap;
    DisplayRenderer dRenderer;
    FieldImpl field, flatfield, text_field;
    TextType text;
    TupleType text_tuple;
    Linear1DSet time_set;
    FunctionType text_function;
    DataReferenceImpl d_ref;
    float dx, dy;
    Vector xvector, yvector;
    Gridded2DSet g;
    int i = 0;
    
    float[][] samp = new float[2][2];
    
       
    /** Creates new DrawPoints */
    public DrawPoints() throws RemoteException,
VisADException {
        row = new RealType("X", null, null);
        column = new RealType("Y", null, null);
        
        domain_tuple = new RealTupleType(row, column);
        
        display = new DisplayImplJ2D("display1");
        
        dRenderer = display.getDisplayRenderer();
        dRenderer.setBoxOn(false);
        dRenderer.setBackgroundColor(1.0f, 1.0f,
1.0f);
        dRenderer.setCursorColor( 0.0f, 0.0f, 1.0f );
        
        rowMap = new ScalarMap(row, Display.XAxis);
        colMap = new ScalarMap(column, Display.YAxis);
        
        display.addMap(rowMap);
        display.addMap(colMap);
        
        rowMap.setRange(0, 10);
        colMap.setRange(0, 10);
        
        
        JFrame jframe = new JFrame("Draw Points");
       
jframe.getContentPane().add(display.getComponent());
        
        jframe.setSize(300, 300);
        jframe.setVisible(true);
        
        
        jframe.addWindowListener(new
java.awt.event.WindowAdapter() {
            public void
windowClosing(java.awt.event.WindowEvent evt) {
                System.exit(0);
            }
        }
        );
    }
    
    public void drawPointsOnTheFrame() throws
RemoteException, VisADException {
        final ConstantMap[] pointsCol = {     new
ConstantMap( 1.0f, Display.Red),
        new ConstantMap( 0.0f, Display.Green),
        new ConstantMap( 0.0f, Display.Blue),
        new ConstantMap( 5.0f, Display.PointSize)};
        xvector = new Vector();
        yvector = new Vector();
                
        display.addDisplayListener(new
DisplayListener() {
            public void displayChanged(DisplayEvent e)
throws RemoteException, VisADException {
                
                if(e.getId() =
DisplayEvent.MOUSE_PRESSED_CENTER) {
                    float d1
(float)dRenderer.getDirectAxisValue(row);
                    float d2
(float)dRenderer.getDirectAxisValue(column);
                    
                    xvector.addElement(new Float(d1));
                    yvector.addElement(new Float(d2));
                    
                    Real[] r = { new Real(row, d1),
new Real(column, d2) };
                    createRealTuples(r);
                                                      
    
                    if((xvector.size()) > 1) {
                        samp[0][0]
(float)((Float)(xvector.elementAt(xvector.size()-2))).floatValue();
                        samp[1][0]
(float)((Float)(yvector.elementAt(yvector.size()-2))).floatValue();
                        
                        samp[0][1]
(float)((Float)(xvector.elementAt(xvector.size()-1))).floatValue();
                        samp[1][1]
(float)((Float)(yvector.elementAt(yvector.size()-1))).floatValue();
                        
                  //     createGridded2DSets(samp);   
                                                
                    }
                    
                }
            }
        });
        
    }
    
    public void createRealTuples(Real[] r) throws
RemoteException, VisADException {
        
        final ConstantMap[] pointsCol = {     new
ConstantMap( 1.0f, Display.Red),
        new ConstantMap( 0.0f, Display.Green),
        new ConstantMap( 0.0f, Display.Blue),
        new ConstantMap( 5.0f, Display.PointSize)};
        
        RealTuple rt = new RealTuple(r);
        DataReferenceImpl d_ref = new
DataReferenceImpl("d_ref");
        d_ref.setData(rt);
        display.addReferences(new
DirectManipulationRendererJ2D(), d_ref, pointsCol); 
       
    }
    
    public void createGridded2DSets(float[][] s)
throws RemoteException, VisADException {
        ConstantMap[] linesCol = {      new
ConstantMap( 0.0f, Display.Red),
        new ConstantMap( 0.0f, Display.Green),
        new ConstantMap( 1.0f, Display.Blue)};
        
        DataReferenceImpl g_ref = new
DataReferenceImpl("g_ref");
        g = new Gridded2DSet(domain_tuple, s, 2);
        g_ref.setData(g);
        display.addReference(g_ref,linesCol);
        
    }
    
    public static void main(String args[]) throws
RemoteException, VisADException {
        DrawPoints dp = new DrawPoints();
        dp.drawPointsOnTheFrame();
    }
}

Thanks and Regards,

Karan.

__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com


  • 2001 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: