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(); } } }
/* * Creates node new node * Creates or update gameobject * */ public void AddNode(string filterName) { VTKNode node = activeNode.AddChild(new VTKNode((VTKFilter)gameObject.AddComponent(filterName), activeNode, gameObject.AddComponent <VTKProperties>())); if (node == null) { return; } Debug.Log("Add node " + node.name); node.filter.node = node; node.filter.SetPlaymodeParameters(); node.properties.node = node; node.properties.SetPlaymodeParameters(); node.properties.Read(); node.UpdateFilter(); SetActiveNode(node); //Create or update gameobject for new node if (!node.parent.isRoot) { //If parent has no children, update parent if (node.parent.children.Count == 1) { //Destroy old gameobject gameObjects.Remove(VTK.GetGameObjectName(node.parent)); GameObject.DestroyImmediate(GameObject.Find(VTK.GetGameObjectName(node.parent))); } } CreateGameObject(node); }
public int CountFilter(string name, VTKNode node) { if(!node.isRoot) { int nodeNumber = int.Parse(node.name.Remove(0, node.GetFilterTypeAsString().Length)) + 1; if(number < nodeNumber) { number = nodeNumber; } } int count = 0; if(node.GetFilterTypeAsString() == name) { count++; } foreach(VTKNode child in node.children) { count += CountFilter(name, child); } return count; }
public int CountFilter(string name, VTKNode node) { if (!node.isRoot) { int nodeNumber = int.Parse(node.name.Remove(0, node.GetFilterTypeAsString().Length)) + 1; if (number < nodeNumber) { number = nodeNumber; } } int count = 0; if (node.GetFilterTypeAsString() == name) { count++; } foreach (VTKNode child in node.children) { count += CountFilter(name, child); } return(count); }
/* * Sets the given node active * Hides scripts from the current node * Shows scripts for the new node * */ public void SetActiveNode(VTKNode node) { if (activeNode == null) { activeNode = rootNode; } //Hide scripts old node if (!activeNode.isRoot) { activeNode.filter.hideFlags = HideFlags.HideInInspector; } activeNode.properties.hideFlags = HideFlags.HideInInspector; //Set active node activeNode = node; //Show scripts new node if (!activeNode.isRoot) { activeNode.filter.hideFlags = HideFlags.None; } if (!activeNode.hasChildren) //Show properties { activeNode.properties.hideFlags = HideFlags.None; } }
/* * Also removes drop-down filters * */ public void RemoveChild(VTKNode node) { if (node.isRoot) { return; } VTKNode parent = node.parent; //Drop-down filters if (node.hasChildren) { for (int i = 0; i < node.children.Count; i++) { RemoveChild(node.children[i]); } } //Remove filter script from editor Object.DestroyImmediate(node.filter); //Remove properties script from editor Object.DestroyImmediate(node.properties); //Remove node parent.children.Remove(node); }
public int number = 0; //Needed to generate filternumber public VTKNode(VTKFilter filter, VTKNode parent, VTKProperties properties) { this.filter = filter; this.parent = parent; this.children = new List <VTKNode> (); this.isRoot = (parent == null) ? true : false; this.name = (isRoot) ? name : filter.GetType().ToString().Remove(0, 9) + GetFilterNumber(); this.properties = properties; }
public VTKNode(VTKFilter filter, VTKNode parent, VTKProperties properties) { this.filter = filter; this.parent = parent; this.children = new List<VTKNode> (); this.isRoot = (parent == null) ? true : false; this.name = (isRoot) ? name : filter.GetType ().ToString ().Remove (0, 9) + GetFilterNumber(); this.properties = properties; }
private void ResetFilter(VTKNode node) { node.filter.Reset(); if (node.hasChildren) { foreach (VTKNode child in node.children) { ResetFilter(child); } } }
/* * Creates tree entries for a given node and its children * */ private void CreateSubTree(VTKNode n, int space) { //Change color of the node if it is the selected one if (script.activeNode == n) { treeNodeStyle.normal.textColor = Color.green; } EditorGUILayout.BeginHorizontal(); GUILayout.Space(space); if (GUILayout.Button(n.name, treeNodeStyle)) { script.SetActiveNode(n); } GameObject go = script.FindGameObject(VTK.GetGameObjectName(n)); if (go != null) { ControllerGameObject cgo = go.GetComponent <ControllerGameObject>(); if (cgo != null) { cgo.showGameObject = EditorGUILayout.Toggle(cgo.showGameObject); if (cgo.showGameObject) { go.renderer.enabled = true; } else { go.renderer.enabled = false; } } } EditorGUILayout.EndHorizontal(); //Reset color for other nodes if (script.activeNode == n) { treeNodeStyle.normal.textColor = Color.black; } //Show children if (n.hasChildren) { for (int i = 0; i < n.children.Count; i++) { CreateSubTree(n.children[i], space + 20); } } }
public static string GetGameObjectName(VTKNode node) { string name = ""; VTKNode current = node; while (current.parent != null) { name = "," + current.name + name; current = current.parent; } name = current.name + name; return name; }
public static string GetGameObjectName(VTKNode node) { string name = ""; VTKNode current = node; while (current.parent != null) { name = "," + current.name + name; current = current.parent; } name = current.name + name; return(name); }
public VTKNode AddChild(VTKNode node) { /* * if (!VTK.ApplicableFilters (this, node)) * { * Object.DestroyImmediate(node.filter); * Object.DestroyImmediate(node.properties); * * return null; * }*/ if (children == null) { children = new List <VTKNode>(); } this.children.Add(node); return(node); }
public VTKNode AddChild(VTKNode node) { /* if (!VTK.ApplicableFilters (this, node)) { Object.DestroyImmediate(node.filter); Object.DestroyImmediate(node.properties); return null; }*/ if (children == null) { children = new List<VTKNode>(); } this.children.Add (node); return node; }
public void Initialize() { string rootName = VTK.GetFileName(filepath); gameObject.name = rootName; supportedFilters = VTK.GetSupportedFiltersByName(); //Initialize file reader if (filepath.EndsWith(".vtp")) { dataType = VTK.DataType.PolyData; polyDataReader = vtkXMLPolyDataReader.New(); polyDataReader.SetFileName(filepath); polyDataReader.Update(); } if (filepath.EndsWith(".vtu")) { dataType = VTK.DataType.UnstructuredGrid; unstructuredGridReader = vtkXMLUnstructuredGridReader.New(); unstructuredGridReader.SetFileName(filepath); unstructuredGridReader.Update(); } //Initialize root node Debug.Log("Initialize root node"); rootNode.name = rootName; rootNode.filter = gameObject.AddComponent <VTKFilterRootNode> (); rootNode.properties = gameObject.AddComponent <VTKProperties> (); PreloadNode(rootNode); activeNode = rootNode; }
/* * Removes node (drop-down) * */ public void RemoveNode(VTKNode node) { if (node.isRoot) { return; } VTKNode parent = node.parent; SetActiveNode(parent); //Delete all gameobjects node is part of for (int i = gameObject.transform.childCount - 1; i > -1; i--) { GameObject go = gameObject.transform.GetChild(i).gameObject; if (go.name.Contains(node.name)) { gameObjects.Remove(go.name); DestroyImmediate(go); } } //Delete node parent.RemoveChild(node); //Update parent node //If no children left, show parent if (!parent.hasChildren && !parent.isRoot) { if (parent.filter.outputType == VTK.DataType.PolyData) { CreateGameObject(parent); } } }
//TODO brauch ich das noch? public VTKNode GetNode(string name) { if (this.name == name) { return(this); } if (!this.hasChildren) { return(null); } VTKNode found = null; if (this.hasChildren) { for (int i = 0; i < this.children.Count; i++) { found = children[i].GetNode(name); } } return(found); }
//TODO brauch ich das überhaupt noch? public VTKNode GetNode(VTKNode toFind) { //If there are no children get out if (!this.hasChildren) { return(null); } //If toFind is child of this object return it if (this.children.Contains(toFind)) { return(this.children[children.IndexOf(toFind)]); } //Recursivly search the children VTKNode found = null; for (int i = 0; i < this.children.Count && found == null; i++) { found = this.children[i].GetNode(toFind); } return(found); }
private void ResetFilter(VTKNode node) { node.filter.Reset(); if(node.hasChildren) { foreach(VTKNode child in node.children) { ResetFilter(child); } } }
public void PreloadNode(VTKNode node) { Debug.Log("Preload data for " + node.name); string objectName = VTK.GetGameObjectName(node); //Set filter if (node.isRoot) { if (dataType == VTK.DataType.PolyData) { polyDataReader = vtkXMLPolyDataReader.New(); polyDataReader.SetFileName(filepath); polyDataReader.Update(); node.filter.vtkFilter = polyDataReader; node.filter.outputType = VTK.DataType.PolyData; } if (dataType == VTK.DataType.UnstructuredGrid) { unstructuredGridReader = vtkXMLUnstructuredGridReader.New(); unstructuredGridReader.SetFileName(filepath); unstructuredGridReader.Update(); node.filter.vtkFilter = unstructuredGridReader; node.filter.outputType = VTK.DataType.UnstructuredGrid; } } else { node.filter.node = node; node.filter.UpdateInput(); node.filter.SetPlaymodeParameters(); } //Set properties node.properties.node = node; node.properties.SetPlaymodeParameters(); node.properties.Read(); //Set vtkToUnity VtkToUnity vtu; if (gameObjects.TryGetValue(objectName, out vtu)) { gameObjects.Set(objectName, new VtkToUnity(node.filter.vtkFilter.GetOutputPort(), FindGameObject(objectName))); node.UpdateProperties(); //Some filters need stuff from properties } //Set controller script ControllerGameObject cg = node.filter.gameObject.GetComponent <ControllerGameObject>(); if (cg != null) { cg.node = node; cg.Initialize(); } //Do it for the kids if (node.hasChildren) { foreach (VTKNode child in node.children) { //Set parent reference child.parent = node; PreloadNode(child); } } }
public void Initialize() { string rootName = VTK.GetFileName (filepath); gameObject.name = rootName; supportedFilters = VTK.GetSupportedFiltersByName (); //Initialize file reader if(filepath.EndsWith(".vtp")) { dataType = VTK.DataType.PolyData; polyDataReader = vtkXMLPolyDataReader.New (); polyDataReader.SetFileName(filepath); polyDataReader.Update(); } if(filepath.EndsWith(".vtu")) { dataType = VTK.DataType.UnstructuredGrid; unstructuredGridReader = vtkXMLUnstructuredGridReader.New(); unstructuredGridReader.SetFileName(filepath); unstructuredGridReader.Update(); } //Initialize root node Debug.Log("Initialize root node"); rootNode.name = rootName; rootNode.filter = gameObject.AddComponent<VTKFilterRootNode> (); rootNode.properties = gameObject.AddComponent<VTKProperties> (); PreloadNode(rootNode); activeNode = rootNode; }
public void PreloadNode(VTKNode node) { Debug.Log ("Preload data for " + node.name); string objectName = VTK.GetGameObjectName(node); //Set filter if(node.isRoot) { if(dataType == VTK.DataType.PolyData) { polyDataReader = vtkXMLPolyDataReader.New (); polyDataReader.SetFileName(filepath); polyDataReader.Update(); node.filter.vtkFilter = polyDataReader; node.filter.outputType = VTK.DataType.PolyData; } if(dataType == VTK.DataType.UnstructuredGrid) { unstructuredGridReader = vtkXMLUnstructuredGridReader.New(); unstructuredGridReader.SetFileName(filepath); unstructuredGridReader.Update(); node.filter.vtkFilter = unstructuredGridReader; node.filter.outputType = VTK.DataType.UnstructuredGrid; } } else { node.filter.node = node; node.filter.UpdateInput(); node.filter.SetPlaymodeParameters(); } //Set properties node.properties.node = node; node.properties.SetPlaymodeParameters(); node.properties.Read (); //Set vtkToUnity VtkToUnity vtu; if(gameObjects.TryGetValue (objectName, out vtu)) { gameObjects.Set(objectName, new VtkToUnity(node.filter.vtkFilter.GetOutputPort(), FindGameObject(objectName))); node.UpdateProperties(); //Some filters need stuff from properties } //Set controller script ControllerGameObject cg = node.filter.gameObject.GetComponent<ControllerGameObject>(); if(cg != null) { cg.node = node; cg.Initialize(); } //Do it for the kids if(node.hasChildren) { foreach (VTKNode child in node.children) { //Set parent reference child.parent = node; PreloadNode(child); } } }
/* * Also removes drop-down filters * */ public void RemoveChild(VTKNode node) { if (node.isRoot) return; VTKNode parent = node.parent; //Drop-down filters if(node.hasChildren) { for(int i = 0; i < node.children.Count; i++) { RemoveChild(node.children[i]); } } //Remove filter script from editor Object.DestroyImmediate(node.filter); //Remove properties script from editor Object.DestroyImmediate(node.properties); //Remove node parent.children.Remove (node); }
//TODO brauch ich das überhaupt noch? public VTKNode GetNode(VTKNode toFind) { //If there are no children get out if (!this.hasChildren) return null; //If toFind is child of this object return it if (this.children.Contains (toFind)) { return this.children[children.IndexOf(toFind)]; } //Recursivly search the children VTKNode found = null; for (int i = 0; i < this.children.Count && found == null; i++) { found = this.children[i].GetNode(toFind); } return found; }
/* * Removes node (drop-down) * */ public void RemoveNode(VTKNode node) { if (node.isRoot) return; VTKNode parent = node.parent; SetActiveNode (parent); //Delete all gameobjects node is part of for(int i = gameObject.transform.childCount - 1; i > -1; i--) { GameObject go = gameObject.transform.GetChild(i).gameObject; if(go.name.Contains(node.name)) { gameObjects.Remove(go.name); DestroyImmediate(go); } } //Delete node parent.RemoveChild (node); //Update parent node //If no children left, show parent if(!parent.hasChildren && !parent.isRoot) { if(parent.filter.outputType == VTK.DataType.PolyData) { CreateGameObject(parent); } } }
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(); } } }
/* * Sets the given node active * Hides scripts from the current node * Shows scripts for the new node * */ public void SetActiveNode(VTKNode node) { if(activeNode == null) activeNode = rootNode; //Hide scripts old node if (!activeNode.isRoot) { activeNode.filter.hideFlags = HideFlags.HideInInspector; } activeNode.properties.hideFlags = HideFlags.HideInInspector; //Set active node activeNode = node; //Show scripts new node if (!activeNode.isRoot) { activeNode.filter.hideFlags = HideFlags.None; } if(!activeNode.hasChildren) //Show properties { activeNode.properties.hideFlags = HideFlags.None; } }
/* * Creates tree entries for a given node and its children * */ private void CreateSubTree(VTKNode n, int space) { //Change color of the node if it is the selected one if(script.activeNode == n) treeNodeStyle.normal.textColor = Color.green; EditorGUILayout.BeginHorizontal (); GUILayout.Space (space); if (GUILayout.Button (n.name, treeNodeStyle)) { script.SetActiveNode(n); } GameObject go = script.FindGameObject(VTK.GetGameObjectName(n)); if(go != null) { ControllerGameObject cgo = go.GetComponent<ControllerGameObject>(); if(cgo != null) { cgo.showGameObject = EditorGUILayout.Toggle(cgo.showGameObject); if(cgo.showGameObject) { go.renderer.enabled = true; } else { go.renderer.enabled = false; } } } EditorGUILayout.EndHorizontal(); //Reset color for other nodes if(script.activeNode == n) treeNodeStyle.normal.textColor = Color.black; //Show children if (n.hasChildren) { for(int i = 0; i < n.children.Count; i++) { CreateSubTree(n.children[i], space + 20); } } }