private void RenderVTU()
        {
            // reader
            vtkXMLUnstructuredGridReader reader = vtkXMLUnstructuredGridReader.New();

            reader.SetFileName(m_FileName);
            reader.Update(); // here we read the file actually

            // mapper
            vtkDataSetMapper gridMapper = vtkDataSetMapper.New();

            gridMapper.SetInputConnection(reader.GetOutputPort());

            // actor
            vtkActor gridActor = vtkActor.New();

            gridActor.SetMapper(gridMapper);

            // add our actor to the renderer
            imgPropList.Add(gridActor);
            m_Renderer.AddActor(gridActor);

            // reposition the camera, so that actor can be fully seen
            m_Renderer.ResetCamera();

            //Rerender the screen
            m_RenderWindow.Render();
            m_Renderer.Render();
        }
        private void renderWindowControl1_Load(object sender, EventArgs e)
        {
            try {
                string filePath = @"C:\VTK\vtkdata-5.8.0\Data\quadraticTetra01.vtu";

                // reader
                vtkXMLUnstructuredGridReader reader = vtkXMLUnstructuredGridReader.New();
                if (reader.CanReadFile(filePath) == 0)
                {
                    MessageBox.Show("Cannot read file \"" + filePath + "\"", "Error", MessageBoxButtons.OK);
                    return;
                }
                reader.SetFileName(filePath);
                reader.Update(); // here we read the file actually

                // mapper
                vtkDataSetMapper gridMapper = vtkDataSetMapper.New();
                gridMapper.SetInputConnection(reader.GetOutputPort());

                // actor
                vtkActor gridActor = vtkActor.New();
                gridActor.SetMapper(gridMapper);

                // get a reference to the renderwindow of our renderWindowControl1
                vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;

                // renderer
                vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
                // set background color
                renderer.SetBackground(0.2, 0.3, 0.4);

                // add our actor to the renderer
                renderer.AddActor(gridActor);

                // reposition the camera, so that actor can be fully seen
                renderer.ResetCamera();
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK);
            }
        }
Пример #3
0
    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;
    }
Пример #4
0
    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);
            }
        }
    }
Пример #5
0
    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;
    }
Пример #6
0
    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);
            }
        }
    }
Пример #7
0
        private void WriteVTUFile()
        {
            // Path to vtk data must be set as an environment variable
            // VTK_DATA_ROOT = "C:\VTK\vtkdata-5.8.0"
            vtkTesting test     = vtkTesting.New();
            string     root     = test.GetDataRoot();
            string     filePath = System.IO.Path.Combine(root, @"Data\tetra_test.vtu");

            vtkPoints points = vtkPoints.New();

            points.InsertNextPoint(0, 0, 0);
            points.InsertNextPoint(1, 0, 0);
            points.InsertNextPoint(1, 1, 0);
            points.InsertNextPoint(0, 1, 1);

            vtkTetra tetra = vtkTetra.New();

            tetra.GetPointIds().SetId(0, 0);
            tetra.GetPointIds().SetId(1, 1);
            tetra.GetPointIds().SetId(2, 2);
            tetra.GetPointIds().SetId(3, 3);

            vtkCellArray cellArray = vtkCellArray.New();

            cellArray.InsertNextCell(tetra);

            vtkUnstructuredGrid unstructuredGrid = vtkUnstructuredGrid.New();

            unstructuredGrid.SetPoints(points);
            const int VTK_TETRA = 10;

            unstructuredGrid.SetCells(VTK_TETRA, cellArray);

            // Write file
            vtkXMLUnstructuredGridWriter writer = vtkXMLUnstructuredGridWriter.New();

            writer.SetFileName(filePath);
            writer.SetInput(unstructuredGrid);
            writer.Write();

            // Read and display file for verification that it was written correctly
            vtkXMLUnstructuredGridReader reader = vtkXMLUnstructuredGridReader.New();

            if (reader.CanReadFile(filePath) == 0)
            {
                MessageBox.Show("Cannot read file \"" + filePath + "\"", "Error", MessageBoxButtons.OK);
                return;
            }
            reader.SetFileName(filePath);
            reader.Update();

            vtkDataSetMapper mapper = vtkDataSetMapper.New();

            mapper.SetInputConnection(reader.GetOutputPort());

            // actor
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);

            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();

            // set background color
            renderer.SetBackground(0.2, 0.3, 0.4);
            // add our actor to the renderer
            renderer.AddActor(actor);
        }
Пример #8
0
        public void Read_Unstructured_Grid_File(string filename)
        {
            // Initalize VTK Reader
            vtkXMLUnstructuredGridReader reader = new vtkXMLUnstructuredGridReader();

            reader.SetFileName(filename);

            reader.Update();

            vtkUnstructuredGrid grid = reader.GetOutput();

            vtkCellArray data     = grid.GetCells();
            vtkIdList    idList   = vtkIdList.New();
            int          numCells = (int)data.GetNumberOfCells();

            if (numCells != 0)
            {
                if (grid.GetCellType(0) == 10)
                {
                    isTetra = true;
                    Console.WriteLine("Celltype is tetra");
                }
                else if (grid.GetCellType(0) == 5)
                {
                    isTetra = false;
                    Console.WriteLine("Celltype is triangle");
                }
                else
                {
                    Console.WriteLine("No valid celltype");
                }

                for (int i = 0; i < numCells; i++)
                {
                    long cellTypeID = grid.GetCellType(i);
                    // alle punkte durchlaufen und in eine Variable für jeden Punkt die anderen drei Punkte speichern
                    if (isTetra)
                    {
                        Vector4 tetraPoint = new Vector4();

                        grid.GetCellPoints(i, idList);
                        // ueber alle vier punkte iterieren und diese in extra liste für jeden Punkt speichern
                        for (int j = 0; j < 4; j++)
                        {
                            tetraPoint[j] = idList.GetId(j);
                        }

                        tetraPoints.Add(tetraPoint);
                    }
                    else if (!isTetra)
                    {
                        Vector3 triangle = new Vector3();

                        grid.GetCellPoints(i, idList);
                        // ueber alle drei punkte iterieren und diese in extra liste für jeden Punkt speichern
                        for (int j = 0; j < 3; j++)
                        {
                            triangle[j] = idList.GetId(j);
                        }
                        trianglePoints.Add(triangle);
                    }
                }
            }

            // Read Point Coordinates
            vtkPoints points = grid.GetPoints();

            int numPoints = (int)points.GetNumberOfPoints();

            List <Vector3d> point_dat = new List <Vector3d>();

            if (numPoints != 0)
            {
                // Read Point Data
                double[] pt;
                for (int i = 0; i < numPoints; i++)
                {
                    pt = points.GetPoint(i);
                    point_dat.Add(new Vector3d((float)pt[0], (float)pt[1], (float)pt[2]));
                }

                if (this.vertex_data.ContainsKey("vertices"))
                {
                    this.vertex_data["vertices"] = point_dat;
                }
                else
                {
                    this.vertex_data.Add("vertices", point_dat);
                }
                Console.WriteLine("All points read in correctly!");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("---------------No Points existent");
            }

            vtkPointData pointData = grid.GetPointData();

            // Load point attributes
            this.Load_Point_Attributes(pointData);
        }