@Override public void keyPressed(KeyEvent e) { if (e.isConsumed()) return; if (ren.VisibleActorCount() == 0) return; vtkActorCollection ac; vtkActor anActor; int i; switch (e.getKeyChar()) { case 'r': // reset camera resetCamera(); repaint(); // consume event e.consume(); break; case 'w': // wireframe mode lock(); try { ac = ren.GetActors(); ac.InitTraversal(); for (i = 0; i < ac.GetNumberOfItems(); i++) { anActor = ac.GetNextActor(); anActor.GetProperty().SetRepresentationToWireframe(); } } finally { unlock(); } repaint(); // consume event e.consume(); break; case 's': lock(); try { ac = ren.GetActors(); ac.InitTraversal(); for (i = 0; i < ac.GetNumberOfItems(); i++) { anActor = ac.GetNextActor(); anActor.GetProperty().SetRepresentationToSurface(); } } finally { unlock(); } repaint(); // consume event e.consume(); break; } }
public static void main(String astring[]) { float f1 = 0.4F; float f2 = 0.4F; Ex63a ex63a = new Ex63a(); vtkPanel VtkPanel = new vtkPanel(); VtkPanel.setSize(400, 400); System.out.println("Here we go"); vtkQuadric VtkQuadric = new vtkQuadric(); VtkQuadric.SetCoefficients(1.0, 2.0, 3.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0); vtkSampleFunction VtkSampleFunction = new vtkSampleFunction(); VtkSampleFunction.SetSampleDimensions(25, 25, 25); VtkSampleFunction.SetImplicitFunction(VtkQuadric); VtkSampleFunction.DebugOn(); vtkContourFilter VtkContourFilter = new vtkContourFilter(); VtkContourFilter.SetInput(VtkSampleFunction.GetOutput()); VtkContourFilter.UseScalarTreeOn(); VtkContourFilter.DebugOn(); vtkPolyDataMapper VtkPolyDataMapper1 = new vtkPolyDataMapper(); VtkPolyDataMapper1.SetInput(VtkContourFilter.GetOutput()); VtkPolyDataMapper1.SetScalarRange(0.0, 7.0); vtkActor VtkActor1 = new vtkActor(); VtkActor1.SetMapper(VtkPolyDataMapper1); VtkPanel.getRenderer().AddActor(VtkActor1); vtkOutlineFilter VtkOutlineFilter = new vtkOutlineFilter(); VtkOutlineFilter.SetInput(VtkSampleFunction.GetOutput()); vtkPolyDataMapper VtkPolyDataMapper2 = new vtkPolyDataMapper(); VtkPolyDataMapper2.SetInput(VtkOutlineFilter.GetOutput()); vtkActor VtkActor2 = new vtkActor(); VtkActor2.SetMapper(VtkPolyDataMapper2); VtkActor2.GetProperty().SetColor(1.0, 1.0, 1.0); VtkPanel.getRenderer().AddActor(VtkActor2); ex63a.add("Center", VtkPanel); ex63a.pack(); MenuBar menuBar = new MenuBar(); Menu menu = new Menu("File"); menu.add(new MenuItem("Exit")); menuBar.add(menu); ex63a.setMenuBar(menuBar); ex63a.show(); for (float f3 = 0.0F; f3 < 12.0; f3++) { VtkContourFilter.SetValue(1, (double) (f1 + f3 * f2)); VtkPanel.Render(); } }
public static void main(String args[]) { vtkStructuredPointsReader reader = null; vtkActor isoActor = null; vtkPolyDataMapper isoMapper = null; MriIso f = new MriIso(); f.vPanel = new vtkPanel2(); f.vPanel.resize(400, 400); // f.savetofile = true; System.out.println("Here we go"); reader = new vtkStructuredPointsReader(); reader.SetFileName("MRIdata.vtk"); f.cFilt = new vtkContourFilter(); f.cFilt.SetValue(0, 225); f.cFilt.SetInput(reader.GetOutput()); isoMapper = new vtkPolyDataMapper(); isoMapper.SetInput(f.cFilt.GetOutput()); isoActor = new vtkActor(); isoActor.SetMapper(isoMapper); f.vPanel.GetRenderer().AddActor(isoActor); f.add("Center", f.vPanel); f.pack(); // Set up the menu MenuBar mb = new MenuBar(); Menu file = new Menu("File"); file.add(new MenuItem("Animate")); file.add(new MenuItem("Exit")); mb.add(file); f.setMenuBar(mb); f.show(); }
/** @param args */ public static void main(String[] args) { vtkPLYReader face1 = new vtkPLYReader(); face1.SetFileName("/home/m2ivi/vanegue/Documents/VisA/tp4/3Dmodels/Model1.ply"); face1.Update(); vtkPLYReader face2 = new vtkPLYReader(); face2.SetFileName("/home/m2ivi/vanegue/Documents/VisA/tp4/3Dmodels/Model2.ply"); face2.Update(); vtkIterativeClosestPointTransform recal = new vtkIterativeClosestPointTransform(); recal.SetSource(face1.GetOutput()); recal.SetTarget(face2.GetOutput()); recal.SetMaximumNumberOfLandmarks(5000); recal.GetLandmarkTransform().SetModeToRigidBody(); recal.StartByMatchingCentroidsOn(); recal.SetMaximumNumberOfIterations(1); recal.Modified(); recal.Update(); vtkTransformPolyDataFilter tpd = new vtkTransformPolyDataFilter(); tpd.SetInput(face1.GetOutput()); tpd.SetTransform(recal); tpd.Update(); vtkPolyDataMapper map = new vtkPolyDataMapper(); map.SetInput(tpd.GetOutput()); vtkPolyDataMapper map2 = new vtkPolyDataMapper(); map2.SetInput(face2.GetOutput()); vtkActor actorFace1 = new vtkActor(); actorFace1.SetMapper(map); actorFace1.GetProperty().SetColor(0, 0, 1); vtkActor actorFace2 = new vtkActor(); actorFace2.SetMapper(map2); actorFace2.GetProperty().SetColor(0, 1, 0); vtkRenderer ren1 = new vtkRenderer(); ren1.AddActor(actorFace1); ren1.AddActor(actorFace2); ren1.SetBackground(1, 1, 1); vtkRenderWindow renWin = new vtkRenderWindow(); renWin.AddRenderer(ren1); renWin.SetSize(500, 500); vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor(); iren.SetRenderWindow(renWin); renWin.Render(); iren.Start(); }
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); vtkCanvas canvas = new vtkCanvas(); vtkExtractSelectedFrustum selector = new vtkExtractSelectedFrustum(); // create sphere geometry vtkConeSource cone = new vtkConeSource(); cone.SetHeight(3.0); cone.SetRadius(1.0); cone.SetResolution(10); // map to graphics objects vtkPolyDataMapper map = new vtkPolyDataMapper(); map.SetInput(cone.GetOutput()); // actor coordinates geometry, properties, transformation vtkActor aSphere = new vtkActor(); aSphere.SetMapper(map); aSphere.GetProperty().SetColor(0, 0, 1); // color blue aSphere.GetProperty().SetRepresentationToWireframe(); canvas.GetRenderer().AddActor(aSphere); frame.add(canvas); frame.setSize(800, 600); frame.setVisible(true); selector.CreateFrustum( new double[] { 0., -10., 10., 1.0, 0., -10., -10., 1.0, 0., 10., 10., 1.0, 0., 10., -10., 1.0, 10., -10., 10., 1.0, 10., -10., -10., 1.0, 10., 10., 10., 1.0, 10., 10., -10., 1.0, }); /*selector.CreateFrustum(new double[] { 0.,-10.,-10.,1.0, 0.,-10.,10.,1.0, 0.,10.,-10.,1.0, 0.,10.,10.,1.0, 10.,-10.,-10.,1.0, 10.,-10.,10.,1.0, 10.,10.,-10.,1.0, 10.,10.,10.,1.0, });*/ // selector.SetContainingCells(1); vtkPlanes planes = selector.GetFrustum(); vtkDoubleArray normals = (vtkDoubleArray) planes.GetNormals(); System.out.println("Normals : " + Arrays.toString(normals.GetJavaArray())); System.out.println( "Points : " + Arrays.toString(((vtkFloatArray) planes.GetPoints().GetData()).GetJavaArray())); System.out.println("EVALUATION : " + planes.FunctionValue(1001, 11, 11)); System.out.println("planes." + planes.GetPlane(0).FunctionValue(-11, 0, 0)); selector.SetInput(cone.GetOutput()); // UNCOMMENT TO CHECK THE BOUNDARIES // selector.ShowBoundsOn(); // UNCOMMENT TO SEE THAT THE frustum extractor doesn't work inside and outside the boundaries // selector.InsideOutOn(); // canvas.lock(); selector.Update(); // canvas.unlock(); vtkActor actorFrustum = new vtkActor(); vtkDataSetMapper mapFrustum = new vtkDataSetMapper(); mapFrustum.SetInputConnection(selector.GetOutputPort()); actorFrustum.SetMapper(mapFrustum); canvas.GetRenderer().AddActor(actorFrustum); canvas.lock(); canvas.GetRenderer().ResetCamera(); canvas.unlock(); // COMMENT TO SEE THAT THE CONE IS IN THE BOUNDARIES canvas.GetRenderer().RemoveActor(aSphere); }
public static void main(String args[]) { vtkCamera camera; vtkPanel panel = new vtkPanel(); Ex94a f = new Ex94a(); vtkPLOT3DReader pl3d = new vtkPLOT3DReader(); pl3d.SetXYZFileName("g:/vtkdata/combxyz.bin"); pl3d.SetQFileName("g:/vtkdata/combq.bin"); pl3d.SetScalarFunctionNumber(100); pl3d.SetVectorFunctionNumber(202); pl3d.Update(); vtkPlaneSource plane = new vtkPlaneSource(); plane.SetResolution(50, 50); vtkTransform transP1 = new vtkTransform(); transP1.Translate(3.7, 0.0, 28.37); transP1.Scale(5, 5, 5); transP1.RotateY(90); vtkTransformPolyDataFilter tpd1 = new vtkTransformPolyDataFilter(); tpd1.SetInput(plane.GetOutput()); tpd1.SetTransform(transP1); vtkOutlineFilter outTpd1 = new vtkOutlineFilter(); outTpd1.SetInput(tpd1.GetOutput()); vtkPolyDataMapper mapTpd1 = new vtkPolyDataMapper(); // same as vtkPolyMapper in tcl mapTpd1.SetInput(outTpd1.GetOutput()); vtkActor tpd1Actor = new vtkActor(); tpd1Actor.SetMapper(mapTpd1); tpd1Actor.GetProperty().SetColor(0, 0, 0); vtkTransform transP2 = new vtkTransform(); transP2.Translate(9.2, 0.0, 31.20); transP2.Scale(5, 5, 5); transP2.RotateY(90); vtkTransformPolyDataFilter tpd2 = new vtkTransformPolyDataFilter(); tpd2.SetInput(plane.GetOutput()); tpd2.SetTransform(transP2); vtkOutlineFilter outTpd2 = new vtkOutlineFilter(); outTpd2.SetInput(tpd2.GetOutput()); vtkPolyDataMapper mapTpd2 = new vtkPolyDataMapper(); mapTpd2.SetInput(outTpd2.GetOutput()); vtkActor tpd2Actor = new vtkActor(); tpd2Actor.SetMapper(mapTpd2); tpd2Actor.GetProperty().SetColor(0, 0, 0); vtkTransform transP3 = new vtkTransform(); transP3.Translate(13.27, 0.0, 33.30); transP3.Scale(5, 5, 5); transP3.RotateY(90); vtkTransformPolyDataFilter tpd3 = new vtkTransformPolyDataFilter(); tpd3.SetInput(plane.GetOutput()); tpd3.SetTransform(transP3); vtkOutlineFilter outTpd3 = new vtkOutlineFilter(); outTpd3.SetInput(tpd3.GetOutput()); vtkPolyDataMapper mapTpd3 = new vtkPolyDataMapper(); mapTpd3.SetInput(outTpd3.GetOutput()); vtkActor tpd3Actor = new vtkActor(); tpd3Actor.SetMapper(mapTpd3); tpd3Actor.GetProperty().SetColor(0, 0, 0); vtkAppendPolyData appendF = new vtkAppendPolyData(); appendF.AddInput(tpd1.GetOutput()); appendF.AddInput(tpd2.GetOutput()); appendF.AddInput(tpd3.GetOutput()); vtkProbeFilter probe = new vtkProbeFilter(); probe.SetInput(appendF.GetOutput()); probe.SetSource(pl3d.GetOutput()); vtkHedgeHog hedgehog = new vtkHedgeHog(); // use hedgehog instead of contourfilter hedgehog.SetInput(probe.GetOutput()); hedgehog.SetScaleFactor(0.015); vtkPolyDataMapper hedgehogMapper = new vtkPolyDataMapper(); hedgehogMapper.SetInput(hedgehog.GetOutput()); hedgehogMapper.SetScalarRange(pl3d.GetOutput().GetScalarRange()); vtkActor planeActor = new vtkActor(); planeActor.SetMapper(hedgehogMapper); vtkStructuredGridOutlineFilter outline = new vtkStructuredGridOutlineFilter(); outline.SetInput(pl3d.GetOutput()); vtkPolyDataMapper outlineMapper = new vtkPolyDataMapper(); outlineMapper.SetInput(outline.GetOutput()); vtkActor outlineActor = new vtkActor(); outlineActor.SetMapper(outlineMapper); outlineActor.GetProperty().SetColor(0, 0, 0); panel.getRenderer().AddActor(outlineActor); panel.getRenderer().AddActor(planeActor); panel.getRenderer().AddActor(tpd1Actor); panel.getRenderer().AddActor(tpd2Actor); panel.getRenderer().AddActor(tpd3Actor); panel.getRenderer().SetBackground(1, 1, 1); panel.setSize(500, 500); camera = panel.getRenderer().GetActiveCamera(); camera.SetClippingRange(3.95297, 50); camera.SetFocalPoint(8.88908, 0.595038, 29.3342); camera.SetPosition(-12.3332, 31.7479, 41.2387); camera.ComputeViewPlaneNormal(); camera.SetViewUp(0.060772, -0.319905, 0.945498); f.add("Center", panel); f.pack(); // Set up the menu MenuBar mb = new MenuBar(); Menu file = new Menu("File"); file.add(new MenuItem("Exit")); mb.add(file); f.setMenuBar(mb); f.show(); }