public class DataViewer extends Applet
{
public static void main( String args[] )
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
MainFrame app= new MainFrame( new DataViewer(), 340, 280 );
app.setVisible(true);
}
});
}
private PolygonAttributes polygAttr =new PolygonAttributes();
LineArray geom1;
PointArray geom;
PickCanvas pc;
TextField text;
nNetXmlMan.AnnDataRepository ms2 = new nNetXmlMan.AnnDataRepository();
FileImport ms3 =new FileImport();
public void init()
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
setLayout( new BorderLayout() );
GraphicsConfiguration gc = SimpleUniverse.getPreferredConfiguration();
Canvas3D cv = new Canvas3D( gc );
add( cv, BorderLayout.CENTER );
cv.addMouseListener( new MouseAdapter()
{
public void mouseClicked( MouseEvent event )
{
pick( event );
}
});
JFrame an = new JFrame();
JPanel panel=new JPanel();
panel.add(new JLabel("Wählen Sie polygonArten:"));
/*JRadioButton fillModeBtn = new JRadioButton("Fill");
fillModeBtn.setSelected(true);
fillModeBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
polygAttr.setPolygonMode(PolygonAttributes.POLYGON_FILL);
}
});*/
JRadioButton lineModeBtn=new JRadioButton("Line");
lineModeBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
polygAttr.setPolygonMode(PolygonAttributes.POLYGON_LINE) ;
}
});
JRadioButton pointModeBtn=new JRadioButton("Point");
pointModeBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
polygAttr.setPolygonMode(PolygonAttributes.POLYGON_POINT);
}
});
ButtonGroup bg1 = new ButtonGroup();
// bg1.add(fillModeBtn);
bg1.add(lineModeBtn);
bg1.add(pointModeBtn);
// panel.add(fillModeBtn);
panel.add(lineModeBtn);
panel.add(pointModeBtn);
add(panel,BorderLayout.NORTH);
// an.getContentPane().add(panel,BorderLayout.NORTH);
text = new TextField();
add( text, BorderLayout.SOUTH );
BranchGroup bg = createSceneGraph( cv );
bg.compile();
SimpleUniverse su = new SimpleUniverse( cv );
su.getViewingPlatform().setNominalViewingTransform();
su.addBranchGraph( bg );
}
});
}
private BranchGroup createSceneGraph( Canvas3D cv )
{
BranchGroup root = new BranchGroup();
TransformGroup spin = new TransformGroup();
spin.setCapability( TransformGroup.ALLOW_TRANSFORM_READ );
spin.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE );
root.addChild( spin );
// axes
Transform3D tr = new Transform3D();
tr.setScale( 0.3 );
TransformGroup tg = new TransformGroup( tr );
spin.addChild( tg );
Axes axes = new Axes();
tg.addChild( axes );
// appearance
LineAttributes la = new LineAttributes();
la.setLineWidth(2.0f);
//Appearance ap = new Appearance();
//ap.setLineAttributes(la);
Appearance ap = new Appearance();
ap.setPointAttributes( new PointAttributes( 20f, true ) ) ;
// objects
/*geom1 = new LineArray( n, LineArray.COORDINATES | LineArray.COLOR_4 ) ;
geom1.setCapability( LineArray.ALLOW_COORDINATE_READ );
geom1.setCapability( LineArray.ALLOW_FORMAT_READ );
geom1.setCapability( LineArray.ALLOW_COLOR_READ );
geom1.setCapability( LineArray.ALLOW_COLOR_WRITE );
geom1.setCapability( LineArray.ALLOW_COUNT_READ );
*/
int n = 7;
//geom = new PointArray( n, PointArray.COORDINATES | PointArray.COLOR_4 );
geom = new PointArray( 450, PointArray.COORDINATES | PointArray.COLOR_3 ) ;
geom.setCapability( PointArray.ALLOW_COORDINATE_READ );
geom.setCapability( PointArray.ALLOW_FORMAT_READ );
geom.setCapability(PointArray.ALLOW_COLOR_READ );
geom.setCapability( PointArray.ALLOW_COLOR_WRITE );
geom.setCapability( PointArray.ALLOW_COUNT_READ );
//FileImport.JTable jTable1=new FileImport.JTable();
int col = new FileImport().getjTable1().getSelectedColumn();
int row = new FileImport().getjTable1().getSelectedRow();
//Object zeile1 = new FileImport().getjTable1().getModel().getValueAt(row, col);
//int as= new FileImport().getjTable1().getRowCount();
Point3d[] cordns = new Point3d[450];
Color3f[] colors = new Color3f[450];
String clmHeaders1[] ={"Epochs", "TrainingsIndices", " Errors "," weight1"," weight2 "," weight3"};
/*coords[0] = new Point3d( ((Double)(new FileImport().getjTable1().getValueAt(1, 3))).doubleValue(), ((Double) (new FileImport().getjTable1().getModel().getValueAt(1, 2))).doubleValue(), ((Double) (new FileImport().getjTable1().getModel().getValueAt(1, 3))).doubleValue());
coords[1] = new Point3d( ((Double)(new FileImport().getjTable1().getValueAt(2, 3))).doubleValue(), ((Double) (new FileImport().getjTable1().getModel().getValueAt(2,2 ))).doubleValue(), ((Double) (new FileImport().getjTable1().getModel().getValueAt(2, 3))).doubleValue());
*/
/*int zeile = table.getSelectedRow(), spalte = 0;
Integer i = (Integer)table.getValueAt(zeile, spalte); //Zählung von Zeilen und Spalten beginnt bei 0
tf = new JTextField(String.valueOf(i.intValue()));
*/
int zeile = new FileImport().getjTable1().getSelectedRow(), spalte = 0 ;
String [] ali1 = new FileImport().getclmHeaders1();
//int intZahl = Integer.parseInt(ali1[]).intValue();
//Integer integerZahl = new Integer(ali1).intValue();
//------------------->hier zugreife ich auf meine klasse FileImport(),da steht meine JTable
Object ali2 = new FileImport().getrowData();
for(int i=0;i<450;i++){
cordns[i] = new Point3d( ((Double) (new FileImport().getjTable1().getModel().getValueAt(i, 2))).doubleValue() ((Double) (new FileImport().getjTable1().getModel().getValueAt(i, 3))).doubleValue(), ((Double) (new FileImport().getjTable1().getModel().getValueAt(i, 5))).doubleValue());--------------------------------<>-hier kommt immer fehler
colors[i] = new Color3f( 0.0f, 0.0f, 0.0f );--------------
}
);
geom.setCoordinates( 0, cordns );
geom.setColors( 0, colors );
BranchGroup bg = new BranchGroup();
spin.addChild( bg );
pc = new PickCanvas( cv, bg );
pc.setTolerance( 5 );
pc.setMode( PickTool.GEOMETRY_INTERSECT_INFO );
Shape3D shape = new Shape3D( geom, ap );
Shape3D shape1 = new Shape3D( geom1, ap );
bg.addChild( shape );
bg.addChild( shape1 );
PickTool.setCapabilities( shape, PickTool.INTERSECT_TEST );
shape.setCapability( Shape3D.ALLOW_GEOMETRY_READ );
PickTool.setCapabilities( shape1, PickTool.INTERSECT_TEST );
shape1.setCapability( Shape3D.ALLOW_GEOMETRY_READ );
// rotation
MouseRotate rotator = new MouseRotate( spin );
BoundingSphere bounds = new BoundingSphere();
rotator.setSchedulingBounds( bounds );
spin.addChild( rotator );
// translation
MouseTranslate translator = new MouseTranslate( spin );
translator.setSchedulingBounds( bounds );
spin.addChild( translator );
// zoom
MouseZoom zoom = new MouseZoom( spin );
zoom.setSchedulingBounds( bounds );
spin.addChild( zoom );
// background and light
Background background = new Background( 1.0f, 1.0f, 1.0f );
background.setApplicationBounds( bounds );
root.addChild( background );
AmbientLight light = new AmbientLight( true, new Color3f( Color.red ) );
light.setInfluencingBounds( bounds );
root.addChild( light );
PointLight ptlight = new PointLight( new Color3f( Color.red ), new Point3f( 3.0f, 3.0f, 3.0f ), new Point3f( 0.0f, 0.0f, 0.0f ) );
ptlight.setInfluencingBounds( bounds );
root.addChild( ptlight );
PointLight ptlight2 = new PointLight( new Color3f( Color.red ), new Point3f( -2.0f, 2.0f, 2.0f ), new Point3f( 0.0f, 0.0f, 0.0f ) );
ptlight2.setInfluencingBounds( bounds );
root.addChild( ptlight2 );
return root;
}
private void pick( MouseEvent event )
{
Color4f color = new Color4f();
pc.setShapeLocation( event );
PickResult[] results = pc.pickAll();
for ( int i = 0; (results != null) && (i < results.length); i++ )
{
PickIntersection inter = results[i].getIntersection( 0 );
Point3d pt = inter.getClosestVertexCoordinates();
int[] ind = inter.getPrimitiveCoordinateIndices();
text.setText( "vertex " + ind[0] + ": (" + pt.x + ", " + pt.y + ", " + pt.z + ")" );
geom.getColor( ind[0], color );
geom1.getColor( ind[0], color );
color.x = 1.0f - color.x;
color.y = 1.0f - color.y;
color.z = 1.0f - color.z;
if ( color.w > 0.8 )
color.w = 0.5f;
else
color.w = 1.0f;
geom.setColor( ind[0], color );
geom1.setColor( ind[0], color );
}
}
}