public void CreateGameObject(VTKNode node) { string gameObjectName = VTK.GetGameObjectName(node); Debug.Log("Create gameobject " + gameObjectName); if (node.filter.outputType == VTK.DataType.PolyData) { //Create gameobject VtkToUnity vtu = new VtkToUnity(node.filter.vtkFilter.GetOutputPort(), VTK.GetGameObjectName(node)); vtu.go.transform.parent = gameObject.transform; vtu.ColorBy(Color.magenta); vtu.Update(); gameObjects.Add(vtu.go.name, vtu); if (node.filter.outputType == VTK.DataType.PolyData) { //Add mesh for controller support GameObject go = FindGameObject(gameObjectName); MeshCollider mc = go.AddComponent <MeshCollider>(); mc.isTrigger = true; ControllerGameObject cg = go.AddComponent <ControllerGameObject>(); cg.node = node; cg.Initialize(); } } }
void Generate() { if (SphereSource == null) { SphereSource = Kitware.VTK.vtkSphereSource.New(); } if (vtkToUnity == null) { vtkToUnity = new VtkToUnity(SphereSource.GetOutputPort(), "VTK Run In Editor"); vtkToUnity.ColorBy(Color.green); } SphereSource.SetPhiResolution(resolution); SphereSource.SetThetaResolution(resolution); SphereSource.SetRadius(1); SphereSource.Update(); vtkToUnity.Update(); }
void Start() { string filepath = System.IO.Path.Combine(Application.streamingAssetsPath, "Vtk-Data/Box.vtp"); //Application.dataPath + "/" + "Vtk-Data/Box.vtp"; //filepath = filepath.Replace("/", "\\"); Kitware.VTK.vtkXMLPolyDataReader reader = Kitware.VTK.vtkXMLPolyDataReader.New(); if (reader.CanReadFile(filepath) == 0) { Debug.Log(filepath + " could not be loaded by Vtk!"); return; } reader.SetFileName(filepath); reader.Update(); VtkToUnity vtkToUnity = new VtkToUnity(reader.GetOutputPort(), "Vtk-Data/Box.vtp"); vtkToUnity.ColorBy("Elevation", VtkToUnity.VtkColorType.POINT_DATA); vtkToUnity.SetLut(VtkToUnity.LutPreset.BLUE_RED); //vtkToUnity.ColorBy(Color.red); vtkToUnity.Update(); vtkToUnity.go.transform.Translate(-2f, 0f, 0f); Kitware.VTK.vtkContourFilter contours = Kitware.VTK.vtkContourFilter.New(); contours.SetInputConnection(vtkToUnity.triangleFilter.GetOutputPort()); contours.SetInputArrayToProcess(0, 0, 0, (int)Kitware.VTK.vtkDataObject.FieldAssociations.FIELD_ASSOCIATION_POINTS, "Elevation"); for (int i = 0; i < 10; ++i) { contours.SetValue(i, i / 10.0); } contours.ComputeScalarsOn(); VtkToUnity vtkToUnityContours = new VtkToUnity(contours.GetOutputPort(), "Contours"); vtkToUnityContours.ColorBy("Elevation", VtkToUnity.VtkColorType.POINT_DATA); vtkToUnityContours.SetLut(VtkToUnity.LutPreset.BLUE_RED); //vtkToUnityContours.ColorBy(Color.red); vtkToUnityContours.Update(); vtkToUnityContours.go.transform.Translate(-4f, 0f, 0f); // Points filepath = System.IO.Path.Combine(Application.streamingAssetsPath, "Vtk-Data/Points.vtp"); if (reader.CanReadFile(filepath) == 0) { Debug.Log(filepath + " could not be loaded by Vtk!"); return; } reader.SetFileName(filepath); reader.Update(); VtkToUnity vtkToUnityPoints = new VtkToUnity(reader.GetOutputPort(), "Vtk-Data/Points.vtp"); vtkToUnityPoints.ColorBy("Elevation", VtkToUnity.VtkColorType.POINT_DATA); vtkToUnityPoints.SetLut(VtkToUnity.LutPreset.RED_BLUE); //vtkToUnityPoints.ColorBy(Color.red); vtkToUnityPoints.Update(); vtkToUnityPoints.go.transform.Translate(2f, 0f, 0f); }
void Start() { SphereSource = Kitware.VTK.vtkSphereSource.New(); SphereSource.SetRadius(1); SphereSource.Update(); vtkToUnity = new VtkToUnity(SphereSource.GetOutputPort(), "VTK Sphere Source"); vtkToUnity.ColorBy(Color.grey); vtkToUnity.Update(); }
void Update() { if (Input.GetKeyDown(KeyCode.UpArrow)) { resolution++; } if (Input.GetKeyDown(KeyCode.DownArrow) && resolution > 3) { resolution--; } if (resolution != oldResolution) { SphereSource.SetPhiResolution(resolution); SphereSource.SetThetaResolution(resolution); vtkToUnity.Update(); oldResolution = resolution; } }
public void CreateGameObject(VTKNode node) { string gameObjectName = VTK.GetGameObjectName(node); Debug.Log ("Create gameobject " + gameObjectName); if(node.filter.outputType == VTK.DataType.PolyData) { //Create gameobject VtkToUnity vtu = new VtkToUnity(node.filter.vtkFilter.GetOutputPort(), VTK.GetGameObjectName (node)); vtu.go.transform.parent = gameObject.transform; vtu.ColorBy (Color.magenta); vtu.Update (); gameObjects.Add(vtu.go.name, vtu); if(node.filter.outputType == VTK.DataType.PolyData) { //Add mesh for controller support GameObject go = FindGameObject(gameObjectName); MeshCollider mc = go.AddComponent<MeshCollider>(); mc.isTrigger = true; ControllerGameObject cg = go.AddComponent<ControllerGameObject>(); cg.node = node; cg.Initialize(); } } }