[vtkusers] Drwaing on a vtkActor in Java

Sebastien Jourdain sebastien.jourdain at kitware.com
Mon Jul 25 14:14:48 EDT 2011


Hi,

you are not doing anything wrong. The matter is the graphical
component of VTK is AWT and get draw on top of every layer.
To my knowledge, Java 7 is supposed to offer a solution to that
ordering limitation.

Seb

On Mon, Jul 25, 2011 at 2:02 PM, cakbulut <cakbulut at web.de> wrote:
> Hi all,
>
> I am using vtk for rendering DICOM images in Java. My target is to draw
> points (java Point) on the DICOM Image. The DICOM images is rendered in a
> vtkCanvas (in an extended version MyCanvas, see below) object.
>
> The following code shows the loading and adding of the vtk canvas in a
> JInternalFrame.
>
>                 vtkDICOMImageReader reader = new vtkDICOMImageReader();
>
>                 reader.SetDirectoryName("C:\\vtkDev\\Book\\data\\SE000002");
>                 reader.Update();
>
>                 mapper.SetInput(reader.GetOutput());
>
>                 actor = new vtkActor2D();
>                 actor.SetMapper(mapper);
>                 canvas.GetRenderer().AddActor2D(actor);
>                 // canvas.addMouseListener(arg0)
>
>                 this.add(canvas, BorderLayout.CENTER);
>
> Over the GUI I create a Java BufferedImage which I put on the vtkActor in
> the paint method of the canvas. In the paint method I use the Graphics
> object of the vtkCanvas and override the paint method.
>
> THE PROBLEM: The BufferedImages are not on the DICOM Image they are under
> the DICOM Image.
> What I am makeing wrong????
>
>  The code follows:
>
>         class MyCanvas extends vtkCanvas implements MouseInputListener
>         {
>                 ArrayList<Point> points = new ArrayList<Point>();
>
>                 public void mouseClicked(MouseEvent e)
>                 {
>                         int x = e.getX();
>                         int y = e.getY();
>                         points.add(new Point(x, y));
>                         //repaint();
>                 }
>
>                 public void paint(Graphics g)
>                 {
>                         super.paint(g);
>                         g.setColor(Color.RED);
>                         BufferedImage b = null;
>                         Graphics2D d2 = null;
>                         Graphics2D g2d = (Graphics2D) g;
>                         if (images.size() > 0)
>                         {
> // if (b != null)
> // g2d.drawImage(b, null, 500, 500);
>
>                                 b = images.get(0);
>
>                                 d2= b.createGraphics();
>                                 d2.setBackground(Color.YELLOW);
>                                 d2.setColor(Color.RED);
>                                 System.out.println("Hallo");
>                                 d2.drawString("ballo", 50, 50);
>                                 d2.drawLine(10, 10, 50, 50);
>                                 g2d.drawImage(b,null, 0, 0);
>
>                                 if(images.size() > 1)
>                                 {
>                                         BufferedImage b1 = images.get(1);
>                                         Graphics2D d3= b1.createGraphics();
>                                         d3.setBackground(Color.YELLOW);
>                                         d3.setColor(Color.YELLOW);
>                                         System.out.println("Hallo");
>                                         d3.drawString("sallo", 80, 80);
>                                         d3.drawLine(10, 10, 50, 40);
>                                         g2d.drawImage(b1,null, 0, 0);
>                                 }
>                         }
>
>                         // If user has chosen a point, paint a small dot on
> top.
>                         if (points != null)
>                         {
>                                 for (Point x : points)
>                                 {
>                                         g2d.setColor(Color.RED);
>                                         g2d.fillRect(x.x, x.y, 3, 3);
>                                 }
>                         }
>                 }
>
>
> Best regards.
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/Drwaing-on-a-vtkActor-in-Java-tp4631768p4631768.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list