Hi Karan,
> 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.
I solved a very similar problem in visad/bom/FrontDrawer.java.
If you run 'java visad.bom.FrontDrawer', and draw curves
with the right mouse button held down, you'll see
how it works. First, a freehand curve is drawn using
visad.bom.CurveManipulationRendererJ3D, extended by
an internal class FrontManipulationRendererJ3D to capture
the user's release of the right mouse button. Once
the button is released, the curve is smoothed and redrawn
using a parameterized front pattern (note running
'java visad.bom.FrontDrawer N' will draw various patterns
for N between 0 and 20).
FrontDrawer.java is pretty complex, because it manages an
animation sequence of fronts, because it dynamically adjusts
the smoothing to ensure that the curved front shapes do not
self intersect, because it rescales the front pattern if the
display is zoomed in and out, and because it allows the
fronts to be saved and restored.
However, the smoothing logic is nicely encapsulated in the
static method:
public static float[][] smooth_curve(float[][] curve, int window)
which you can copy into your application. I recommend first
applying:
public static float[][] resample_curve(float[][] curve, float increment)
so that your curve is sampled at even intervals before
smoothing. Note that curves represented as float[][] are
natural from the getSamples() of a Set.
> 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.
You application hangs because you've created a deadlock by
calling DisplayImpl.addReference() and addReferences() from
within the displayChanged() method of your DisplayListener.
The fix is to add a CellImpl to call addReference() and
addReferences(), and to trigger the CellImpl from inside
your displayChanged() method, as follows:
final DataReferenceImpl cell_ref = new DataReferenceImpl("cell_ref");
CellImpl cell = new CellImpl() {
public void doAction() throws VisADException, RemoteException {
if (xvector.isEmpty() || yvector.isEmpty()) return;
float d1 = ((Float) xvector.lastElement()).floatValue();
float d2 = ((Float) yvector.lastElement()).floatValue();
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);
}
}
};
cell.addReference(cell_ref);
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));
cell_ref.setData(null);
}
}
});
Good luck,
Bill
----------------------------------------------------------
Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI 53706
hibbard@xxxxxxxxxxxxxxxxx 608-263-4427 fax: 608-263-6738
http://www.ssec.wisc.edu/~billh/vis.html