6 public static void Main(
string[] args)
10 Scene scene =
new Scene(
"SDFHaptics");
11 SurfaceMesh axesMesh = MeshIO.readSurfaceMesh(
"../data/axesPoly.vtk");
12 ImageData sdfImage = MeshIO.readImageData(
"../data/stanfordBunny/stanfordBunny_SDF.nii");
13 SignedDistanceField sdf =
new SignedDistanceField(sdfImage.cast((byte)Utils.IMSTK_DOUBLE));
15 scene.getActiveCamera().setPosition(-2.3, 23.81, 45.65);
16 scene.getActiveCamera().setFocalPoint(9.41, 8.45, 5.76);
18 CollidingObject bunnyObj =
new CollidingObject(
"Bunny");
20 bunnyObj.setCollidingGeometry(sdf);
22 SurfaceMeshFlyingEdges isoExtract =
new SurfaceMeshFlyingEdges();
23 isoExtract.setInputImage(sdfImage);
26 isoExtract.getOutputMesh().flipNormals();
27 bunnyObj.setVisualGeometry(isoExtract.getOutputMesh());
29 scene.addSceneObject(bunnyObj);
32 SceneObject axesObj =
new SceneObject(
"Axes");
34 axesObj.setVisualGeometry(axesMesh);
35 scene.addSceneObject(axesObj);
39 DirectionalLight whiteLight =
new DirectionalLight();
41 whiteLight.setDirection(
new Vec3d(5.0, -8.0, -5.0));
42 whiteLight.setIntensity(1.0);
43 scene.addLight(
"whiteLight", whiteLight);
47 DeviceManager hapticManager = DeviceManagerFactory.makeDeviceManager();
48 DeviceClient client = hapticManager.makeDeviceClient();
53 VTKViewer viewer =
new VTKViewer(
"Viewer");
54 viewer.setActiveScene(scene);
57 SceneManager sceneManager =
new SceneManager(
"Scene Manager");
58 sceneManager.setActiveScene(scene);
59 sceneManager.setExecutionType(Module.ExecutionType.ADAPTIVE);
61 SimulationManager driver =
new SimulationManager();
62 driver.addModule(viewer);
63 driver.addModule(sceneManager);
64 driver.addModule(hapticManager);
66 ImplicitFunctionCentralGradient centralGrad =
new ImplicitFunctionCentralGradient();
67 centralGrad.setFunction(sdf);
68 centralGrad.setDx(sdf.getImage().getSpacing());
70 Utils.connectEvent(sceneManager, Utils.SceneManager_getPostUpdate_cb,
73 Vec3d tmpPos = client.getPosition();
74 Vec3d pos = tmpPos * 0.1 + new Vec3d(0.0, 0.1, 10.0);
77 axesMesh.setTranslation(pos);
78 axesMesh.setRotation(client.getOrientation());
79 axesMesh.postModified();
81 double dx = sdf.getFunctionValue(pos);
84 Vec3d g = centralGrad.compute(pos);
85 Vec3d nrm_g = new Vec3d(-g[0] * dx * 4.0, -g[1] * dx * 4.0, -g[2] * dx * 4.0);
86 client.setForce(nrm_g);
92 MouseSceneControl mouseControl =
new MouseSceneControl();
93 mouseControl.setDevice(viewer.getMouseDevice());
94 mouseControl.setSceneManager(sceneManager);
95 scene.addControl(mouseControl);
97 KeyboardSceneControl keyControl =
new KeyboardSceneControl();
98 keyControl.setDevice(viewer.getKeyboardDevice());
99 keyControl.setSceneManager(
new SceneManagerWeakPtr(sceneManager));
100 keyControl.setModuleDriver(
new ModuleDriverWeakPtr(driver));
101 scene.addControl(keyControl);
lazy initialized singleton