[vtkusers] Three cutting planes?
    Carlos Martinez Burgos 
    cmarbur at iti.upv.es
       
    Fri Mar  9 04:10:44 EST 2001
    
    
  
Hi all.
I am trying to apply three cutting planes to an object (see the atachment
file). I pass the object to a ClipPolyData filter an to a Cutter
filter like in the capCow.tcl example. Then I append the results and take
it's output like an object, to cut it whith the second plane. The same is
done with the third.
I think I got the wrong way but I don't know how to do it easily. I have
tried whith vtkImplicitBoolean and with vtkPlanes, but I get wrong
results.
Please, could somebody take a look to my program and tell me how? (It is
written in Java, but the pipeline is the same)
How can I apply the same three cutting planes to more than one object?
Thanks in advance. I have a big problem and I don't have much knowledge 
of VTK.
Greetings.
-- 
----------------------------------------------------------------------
Carlos Martínez Burgos      |     Instituto Tecnológico de Informática
Ingeniero Informático       |      Universidad Politécnica de Valencia
Tlf: +34 963877237          |                        Camí de Vera, S/N
cmarbur at iti.upv.es          |                   46071 Valencia - Spain
www.iti.upv.es/~cmarbur     |                           www.iti.upv.es
----------------------------------------------------------------------
-------------- next part --------------
import vtk.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Prueba extends JPanel implements KeyListener {
    vtkPanel panelVTK;
    vtkRenderer renderer;
    double corteX,corteY,corteZ;
    vtkPlane planoX,planoY,planoZ;
    vtkClipPolyData clipperX,clipperY,clipperZ;
    vtkCutter cutterX,cutterY,cutterZ;
    vtkFeatureEdges edgesX,edgesY,edgesZ;
    vtkCleanPolyData cleanX,cleanY,cleanZ;
    vtkTriangleFilter triangles;
    vtkStripper stripperX,stripperY,stripperZ;
    vtkPolyData cuttedPolyX,cuttedPolyY,cuttedPolyZ;
    vtkAppendPolyData appendX,appendY,appendZ;
    vtkPolyDataMapper mapper;
    vtkActor actor;
    public Prueba() {
	panelVTK=new vtkPanel();
	panelVTK.setSize(500,500);
	panelVTK.addKeyListener(this);
	add(panelVTK);
	renderer=panelVTK.getRenderer();
	renderer.TwoSidedLightingOn();
	renderer.SetBackground(1,1,1);
	corteX=0;
	planoX=new vtkPlane();
	planoX.SetOrigin(corteX,0,0);
	planoX.SetNormal(1,0,0);
	corteY=0;
	planoY=new vtkPlane();
	planoY.SetOrigin(0,corteY,0);
	planoY.SetNormal(0,1,0);
	corteZ=0;
	planoZ=new vtkPlane();
	planoZ.SetOrigin(0,0,corteZ);
	planoZ.SetNormal(0,0,1);
	vtkSphereSource esfera=new vtkSphereSource();
	esfera.SetCenter(0,0,0);
	esfera.SetRadius(100);
	esfera.SetPhiResolution(20);
	esfera.SetThetaResolution(20);
	clipperX=new vtkClipPolyData();
	clipperX.SetInput(esfera.GetOutput());
	clipperX.SetClipFunction(planoX);
	clipperX.GenerateClipScalarsOff();
	clipperX.GenerateClippedOutputOff();
	clipperX.SetValue(0);
	cutterX=new vtkCutter();
	cutterX.SetInput(esfera.GetOutput());
	cutterX.SetCutFunction(planoX);
	cutterX.GenerateCutScalarsOn();
	cutterX.SetValue(0,0);
	stripperX=new vtkStripper();
	stripperX.SetInput(cutterX.GetOutput());
	stripperX.Update();
	cuttedPolyX=new vtkPolyData();
	cuttedPolyX.SetPoints(stripperX.GetOutput().GetPoints());
	cuttedPolyX.SetPolys(stripperX.GetOutput().GetLines());
	appendX=new vtkAppendPolyData();
	appendX.AddInput(clipperX.GetOutput());
	appendX.AddInput(cuttedPolyX);
	clipperY=new vtkClipPolyData();
	clipperY.SetInput(appendX.GetOutput());
	clipperY.SetClipFunction(planoY);
	clipperY.GenerateClipScalarsOff();
	clipperY.GenerateClippedOutputOff();
	clipperY.SetValue(0);
	cutterY=new vtkCutter();
	cutterY.SetInput(appendX.GetOutput());
	cutterY.SetCutFunction(planoY);
	cutterY.GenerateCutScalarsOn();
	cutterY.SetValue(0,0);
	stripperY=new vtkStripper();
	stripperY.SetInput(cutterY.GetOutput());
	stripperY.Update();
	cuttedPolyY=new vtkPolyData();
	cuttedPolyY.SetPoints(stripperY.GetOutput().GetPoints());
	cuttedPolyY.SetPolys(stripperY.GetOutput().GetLines());
	appendY=new vtkAppendPolyData();
	appendY.AddInput(clipperY.GetOutput());
	appendY.AddInput(cuttedPolyY);
	clipperZ=new vtkClipPolyData();
	clipperZ.SetInput(appendY.GetOutput());
	clipperZ.SetClipFunction(planoZ);
	clipperZ.GenerateClipScalarsOff();
	clipperZ.GenerateClippedOutputOff();
	clipperZ.SetValue(0);
	cutterZ=new vtkCutter();
	cutterZ.SetInput(appendY.GetOutput());
	cutterZ.SetCutFunction(planoZ);
	cutterZ.GenerateCutScalarsOn();
	cutterZ.SetValue(0,0);
	stripperZ=new vtkStripper();
	stripperZ.SetInput(cutterZ.GetOutput());
	stripperZ.Update();
	cuttedPolyZ=new vtkPolyData();
	cuttedPolyZ.SetPoints(stripperZ.GetOutput().GetPoints());
	cuttedPolyZ.SetPolys(stripperZ.GetOutput().GetLines());
	appendZ=new vtkAppendPolyData();
	appendZ.AddInput(clipperZ.GetOutput());
	appendZ.AddInput(cuttedPolyZ);
	mapper=new vtkPolyDataMapper();
	mapper.SetInput(appendZ.GetOutput());
	actor=new vtkActor();
	actor.SetMapper(mapper);
	actor.GetProperty().SetColor(0,0,1);
	renderer.AddActor(actor);
    }
    public void actualizar() {
	planoX.SetOrigin(corteX,0,0);
	planoY.SetOrigin(0,corteY,0);
	planoZ.SetOrigin(0,0,corteZ);
	stripperX.Update();
	cuttedPolyX.SetPoints(stripperX.GetOutput().GetPoints());
	cuttedPolyX.SetPolys(stripperX.GetOutput().GetLines());
	stripperY.Update();
	cuttedPolyY.SetPoints(stripperY.GetOutput().GetPoints());
	cuttedPolyY.SetPolys(stripperY.GetOutput().GetLines());
	stripperZ.Update();
	cuttedPolyZ.SetPoints(stripperZ.GetOutput().GetPoints());
	cuttedPolyZ.SetPolys(stripperZ.GetOutput().GetLines());
	mapper.Update();
	panelVTK.Render();
    }
    public void updatePipeline() {
	panelVTK.Render();
    }
    public void keyPressed(KeyEvent e) {
	if (e.getKeyCode()==KeyEvent.VK_Q) {
	    System.exit(0);
	}
	else if (e.getKeyCode()==KeyEvent.VK_X) {
	    if (e.getModifiers()==KeyEvent.SHIFT_MASK)
		corteX+=10;
	    else
		corteX-=10;
	    System.out.println("Corte X="+corteX);
	}
	else if (e.getKeyCode()==KeyEvent.VK_Y) {
	    if (e.getModifiers()==KeyEvent.SHIFT_MASK)
		corteY+=10;
	    else
		corteY-=10;
	    System.out.println("Corte Y="+corteY);
	}
	else if (e.getKeyCode()==KeyEvent.VK_Z) {
	    if (e.getModifiers()==KeyEvent.SHIFT_MASK)
		corteZ+=10;
	    else
		corteZ-=10;
	    System.out.println("Corte Z="+corteZ);
	}
	actualizar();
    }
    public void keyReleased(KeyEvent e) {}
    public void keyTyped(KeyEvent e) {}
    public static void main(String args[]) {
	JFrame frame=new JFrame("Prueba de VTK con Java");
	frame.addWindowListener(new WindowAdapter() {
		public void windowClosing(WindowEvent e) {
		    System.exit(0);
		}
	    });
	frame.getContentPane().add(new Prueba());
	frame.pack();
	frame.setSize(500,500);
	frame.setVisible(true);
    }
}
    
    
More information about the vtkusers
mailing list