コード例 #1
0
ファイル: VTKRoot.cs プロジェクト: sebastianbk/VtkUnity
    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();
            }
        }
    }
コード例 #2
0
ファイル: VTKRoot.cs プロジェクト: sebastianbk/VtkUnity
    /*
     * 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);
    }
コード例 #3
0
ファイル: VTKNode.cs プロジェクト: rfrister/VtkUnity
    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;
    }
コード例 #4
0
ファイル: VTKNode.cs プロジェクト: sebastianbk/VtkUnity
    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);
    }
コード例 #5
0
ファイル: VTKRoot.cs プロジェクト: sebastianbk/VtkUnity
    /*
     * 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;
        }
    }
コード例 #6
0
ファイル: VTKNode.cs プロジェクト: sebastianbk/VtkUnity
    /*
     * 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);
    }
コード例 #7
0
ファイル: VTKNode.cs プロジェクト: sebastianbk/VtkUnity
    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;
    }
コード例 #8
0
ファイル: VTKNode.cs プロジェクト: rfrister/VtkUnity
 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;
 }
コード例 #9
0
ファイル: VTKRoot.cs プロジェクト: sebastianbk/VtkUnity
    private void ResetFilter(VTKNode node)
    {
        node.filter.Reset();

        if (node.hasChildren)
        {
            foreach (VTKNode child in node.children)
            {
                ResetFilter(child);
            }
        }
    }
コード例 #10
0
ファイル: EditorVTKRoot.cs プロジェクト: sebastianbk/VtkUnity
    /*
     * 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);
            }
        }
    }
コード例 #11
0
ファイル: VTK.cs プロジェクト: rfrister/VtkUnity
    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;
    }
コード例 #12
0
    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);
    }
コード例 #13
0
ファイル: VTKNode.cs プロジェクト: sebastianbk/VtkUnity
    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);
    }
コード例 #14
0
ファイル: VTKNode.cs プロジェクト: rfrister/VtkUnity
    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;
    }
コード例 #15
0
ファイル: VTKRoot.cs プロジェクト: sebastianbk/VtkUnity
    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;
    }
コード例 #16
0
ファイル: VTKRoot.cs プロジェクト: sebastianbk/VtkUnity
    /*
     * 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);
            }
        }
    }
コード例 #17
0
ファイル: VTKNode.cs プロジェクト: sebastianbk/VtkUnity
    //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);
    }
コード例 #18
0
ファイル: VTKNode.cs プロジェクト: sebastianbk/VtkUnity
    //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);
    }
コード例 #19
0
ファイル: VTKRoot.cs プロジェクト: rfrister/VtkUnity
    private void ResetFilter(VTKNode node)
    {
        node.filter.Reset();

        if(node.hasChildren)
        {
            foreach(VTKNode child in node.children)
            {
                ResetFilter(child);
            }
        }
    }
コード例 #20
0
ファイル: VTKRoot.cs プロジェクト: sebastianbk/VtkUnity
    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);
            }
        }
    }
コード例 #21
0
ファイル: VTKRoot.cs プロジェクト: rfrister/VtkUnity
    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;
    }
コード例 #22
0
ファイル: VTKRoot.cs プロジェクト: rfrister/VtkUnity
    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);
            }
        }
    }
コード例 #23
0
ファイル: VTKNode.cs プロジェクト: rfrister/VtkUnity
    /*
     * 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);
    }
コード例 #24
0
ファイル: VTKNode.cs プロジェクト: rfrister/VtkUnity
    //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;
    }
コード例 #25
0
ファイル: VTKRoot.cs プロジェクト: rfrister/VtkUnity
    /*
     * 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);
            }
        }
    }
コード例 #26
0
ファイル: VTKRoot.cs プロジェクト: rfrister/VtkUnity
    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();
            }
        }
    }
コード例 #27
0
ファイル: VTKRoot.cs プロジェクト: rfrister/VtkUnity
    /*
     * 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;
        }
    }
コード例 #28
0
ファイル: EditorVTKRoot.cs プロジェクト: rfrister/VtkUnity
    /*
     * 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);
            }
        }
    }