Example #1
0
        private static void NullPoint()
        {
            vtkPoints points = vtkPoints.New();

            points.InsertNextPoint(1, 1, 1);
            points.InsertNextPoint(2, 2, 2);
            points.InsertNextPoint(3, 3, 3);

            vtkPolyData polydata = vtkPolyData.New();

            polydata.SetPoints(points);

            vtkFloatArray floatArray = vtkFloatArray.New();

            floatArray.SetNumberOfValues(3);
            floatArray.SetNumberOfComponents(1);
            floatArray.SetName("FloatArray");
            for (int i = 0; i < 3; i++)
            {
                floatArray.SetValue(i, 2);
            }
            polydata.GetPointData().AddArray(floatArray);

            vtkIntArray intArray = vtkIntArray.New();

            intArray.SetNumberOfValues(3);
            intArray.SetNumberOfComponents(1);
            intArray.SetName("IntArray");
            for (int i = 0; i < 3; i++)
            {
                intArray.SetValue(i, 2);
            }

            polydata.GetPointData().AddArray(intArray);

            Console.WriteLine("PointIdx   x y z " + "floatArray" + " " + "intArray");
            Console.WriteLine("----------------------------------------");
            for (int i = 0; i < 3; i++)
            {
                double[]      p = polydata.GetPoint(i);
                vtkFloatArray pointsFloatArray = vtkFloatArray.SafeDownCast(polydata.GetPointData().GetArray("FloatArray"));
                vtkIntArray   pointsIntArray   = vtkIntArray.SafeDownCast(polydata.GetPointData().GetArray("IntArray"));
                Console.WriteLine("   " + i + "       " + p[0] + " " + p[1] + " " + p[2] + "    "
                                  + pointsFloatArray.GetValue(i) + "          " + pointsIntArray.GetValue(i));
            }

            polydata.GetPointData().NullPoint(1);
            polydata.Modified();
            Console.WriteLine("");

            for (int i = 0; i < 3; i++)
            {
                double[]      p = polydata.GetPoint(i);
                vtkFloatArray pointsFloatArray = vtkFloatArray.SafeDownCast(polydata.GetPointData().GetArray("FloatArray"));
                vtkIntArray   pointsIntArray   = vtkIntArray.SafeDownCast(polydata.GetPointData().GetArray("IntArray"));
                Console.WriteLine("   " + i + "       " + p[0] + " " + p[1] + " " + p[2] + "    "
                                  + pointsFloatArray.GetValue(i) + "          " + pointsIntArray.GetValue(i));
            }
        }
Example #2
0
        public VTKDataModel(SimulationModel sm)
        {
            simModel = sm;

            int numCells = sm.Cells.Count;

            cellIDs = vtkIntArray.New();
            cellIDs.SetNumberOfComponents(1);
            cellIDs.SetNumberOfValues(numCells);
            cellIDs.SetName(cellIdsArrayName);

            cellTypes = vtkIntArray.New();
            cellTypes.SetNumberOfComponents(1);
            cellTypes.SetNumberOfValues(numCells);
            cellTypes.SetName(cellTypeArrayName);

            points = vtkPoints.New();
            points.SetNumberOfPoints(numCells);

            verts = vtkCellArray.New();
            verts.Allocate(verts.EstimateSize(1, numCells), 1000);
            verts.InsertNextCell(numCells);

            foreach (MotileCell cell in sm.Cells)
            {
                int i = cell.CellId;
                int c = cell.CellType;
                double[] p = cell.Position;
                points.SetPoint(i, p[0], p[1], p[2]);
                cellIDs.SetValue(i, i);
                cellTypes.SetValue(i, c);
                verts.InsertCellPoint(i);
            }

            poly = vtkPolyData.New();
            poly.SetPoints(points);
            poly.SetVerts(verts);
            poly.GetPointData().AddArray(cellIDs);
            poly.GetPointData().AddArray(cellTypes);
        }
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestRectilinearGridToTetrahedra(String[] argv)
    {
        //Prefix Content is: ""

        //## SetUp the pipeline[]
        FormMesh = new vtkRectilinearGridToTetrahedra();
        FormMesh.SetInput((double)4, (double)2, (double)2, (double)1, (double)1, (double)1, (double)0.001);
        FormMesh.RememberVoxelIdOn();
        TetraEdges = new vtkExtractEdges();
        TetraEdges.SetInputConnection((vtkAlgorithmOutput)FormMesh.GetOutputPort());
        tubes = new vtkTubeFilter();
        tubes.SetInputConnection((vtkAlgorithmOutput)TetraEdges.GetOutputPort());
        tubes.SetRadius((double)0.05);
        tubes.SetNumberOfSides((int)6);
        //## Run the pipeline 3 times, with different conversions to TetMesh[]
        Tubes[0] = new vtkPolyData();
        FormMesh.SetTetraPerCellTo5();
        tubes.Update();
        Tubes[0].DeepCopy((vtkDataObject)tubes.GetOutput());
        Tubes[1] = new vtkPolyData();
        FormMesh.SetTetraPerCellTo6();
        tubes.Update();
        Tubes[1].DeepCopy((vtkDataObject)tubes.GetOutput());
        Tubes[2] = new vtkPolyData();
        FormMesh.SetTetraPerCellTo12();
        tubes.Update();
        Tubes[2].DeepCopy((vtkDataObject)tubes.GetOutput());
        //## Run the pipeline once more, this time converting some cells to[]
        //## 5 and some data to 12 TetMesh[]
        //## Determine which cells are which[]

        DivTypes = new vtkIntArray();
        numCell = (long)((vtkDataSet)FormMesh.GetInput()).GetNumberOfCells();
        DivTypes.SetNumberOfValues((int)numCell);

        i = 0;
        while ((i) < numCell)
        {
            DivTypes.SetValue((int)i, (int)5 + (7 * (i % 4)));
            i = i + 1;
        }

        //## Finish this pipeline[]
        Tubes[3] = new vtkPolyData();
        FormMesh.SetTetraPerCellTo5And12();
        ((vtkRectilinearGrid)FormMesh.GetInput()).GetCellData().SetScalars(DivTypes);
        tubes.Update();
        Tubes[3].DeepCopy((vtkDataObject)tubes.GetOutput());
        //## Finish the 4 pipelines[]
        i = 1;
        while ((i) < 5)
        {
            mapEdges[i] = vtkPolyDataMapper.New();
            mapEdges[i].SetInputData((vtkPolyData)Tubes[i - 1]);
            edgeActor[i] = new vtkActor();
            edgeActor[i].SetMapper((vtkMapper)mapEdges[i]);
            edgeActor[i].GetProperty().SetColor((double)0.2000, 0.6300, 0.7900);
            edgeActor[i].GetProperty().SetSpecularColor((double)1, (double)1, (double)1);
            edgeActor[i].GetProperty().SetSpecular((double)0.3);
            edgeActor[i].GetProperty().SetSpecularPower((double)20);
            edgeActor[i].GetProperty().SetAmbient((double)0.2);
            edgeActor[i].GetProperty().SetDiffuse((double)0.8);
            ren[i] = vtkRenderer.New();
            ren[i].AddActor((vtkProp)edgeActor[i]);
            ren[i].SetBackground((double)0, (double)0, (double)0);
            ren[i].ResetCamera();
            ren[i].GetActiveCamera().Zoom((double)1);
            ren[i].GetActiveCamera().SetPosition((double)1.73906, (double)12.7987, (double)-0.257808);
            ren[i].GetActiveCamera().SetViewUp((double)0.992444, (double)0.00890284, (double)-0.122379);
            ren[i].GetActiveCamera().SetClippingRange((double)9.36398, (double)15.0496);
            i = i + 1;
        }

        // Create graphics objects[]
        // Create the rendering window, renderer, and interactive renderer[]
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer(ren[1]);
        renWin.AddRenderer(ren[2]);
        renWin.AddRenderer(ren[3]);
        renWin.AddRenderer(ren[4]);
        renWin.SetSize(600, 300);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        // Add the actors to the renderer, set the background and size[]
        ren[1].SetViewport((double).75, (double)0, (double)1, (double)1);
        ren[2].SetViewport((double).50, (double)0, (double).75, (double)1);
        ren[3].SetViewport((double).25, (double)0, (double).50, (double)1);
        ren[4].SetViewport((double)0, (double)0, (double).25, (double)1);
        // render the image[]
        //[]
        iren.Initialize();
        // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
Example #4
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestRectilinearGridToTetrahedra(String[] argv)
    {
        //Prefix Content is: ""

        //## SetUp the pipeline[]
        FormMesh = new vtkRectilinearGridToTetrahedra();
        FormMesh.SetInput((double)4, (double)2, (double)2, (double)1, (double)1, (double)1, (double)0.001);
        FormMesh.RememberVoxelIdOn();
        TetraEdges = new vtkExtractEdges();
        TetraEdges.SetInputConnection((vtkAlgorithmOutput)FormMesh.GetOutputPort());
        tubes = new vtkTubeFilter();
        tubes.SetInputConnection((vtkAlgorithmOutput)TetraEdges.GetOutputPort());
        tubes.SetRadius((double)0.05);
        tubes.SetNumberOfSides((int)6);
        //## Run the pipeline 3 times, with different conversions to TetMesh[]
        Tubes[0] = new vtkPolyData();
        FormMesh.SetTetraPerCellTo5();
        tubes.Update();
        Tubes[0].DeepCopy((vtkDataObject)tubes.GetOutput());
        Tubes[1] = new vtkPolyData();
        FormMesh.SetTetraPerCellTo6();
        tubes.Update();
        Tubes[1].DeepCopy((vtkDataObject)tubes.GetOutput());
        Tubes[2] = new vtkPolyData();
        FormMesh.SetTetraPerCellTo12();
        tubes.Update();
        Tubes[2].DeepCopy((vtkDataObject)tubes.GetOutput());
        //## Run the pipeline once more, this time converting some cells to[]
        //## 5 and some data to 12 TetMesh[]
        //## Determine which cells are which[]

        DivTypes = new vtkIntArray();
        numCell  = (long)((vtkDataSet)FormMesh.GetInput()).GetNumberOfCells();
        DivTypes.SetNumberOfValues((int)numCell);

        i = 0;
        while ((i) < numCell)
        {
            DivTypes.SetValue((int)i, (int)5 + (7 * (i % 4)));
            i = i + 1;
        }

        //## Finish this pipeline[]
        Tubes[3] = new vtkPolyData();
        FormMesh.SetTetraPerCellTo5And12();
        ((vtkRectilinearGrid)FormMesh.GetInput()).GetCellData().SetScalars(DivTypes);
        tubes.Update();
        Tubes[3].DeepCopy((vtkDataObject)tubes.GetOutput());
        //## Finish the 4 pipelines[]
        i = 1;
        while ((i) < 5)
        {
            mapEdges[i] = vtkPolyDataMapper.New();
            mapEdges[i].SetInputData((vtkPolyData)Tubes[i - 1]);
            edgeActor[i] = new vtkActor();
            edgeActor[i].SetMapper((vtkMapper)mapEdges[i]);
            edgeActor[i].GetProperty().SetColor((double)0.2000, 0.6300, 0.7900);
            edgeActor[i].GetProperty().SetSpecularColor((double)1, (double)1, (double)1);
            edgeActor[i].GetProperty().SetSpecular((double)0.3);
            edgeActor[i].GetProperty().SetSpecularPower((double)20);
            edgeActor[i].GetProperty().SetAmbient((double)0.2);
            edgeActor[i].GetProperty().SetDiffuse((double)0.8);
            ren[i] = vtkRenderer.New();
            ren[i].AddActor((vtkProp)edgeActor[i]);
            ren[i].SetBackground((double)0, (double)0, (double)0);
            ren[i].ResetCamera();
            ren[i].GetActiveCamera().Zoom((double)1);
            ren[i].GetActiveCamera().SetPosition((double)1.73906, (double)12.7987, (double)-0.257808);
            ren[i].GetActiveCamera().SetViewUp((double)0.992444, (double)0.00890284, (double)-0.122379);
            ren[i].GetActiveCamera().SetClippingRange((double)9.36398, (double)15.0496);
            i = i + 1;
        }

        // Create graphics objects[]
        // Create the rendering window, renderer, and interactive renderer[]
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer(ren[1]);
        renWin.AddRenderer(ren[2]);
        renWin.AddRenderer(ren[3]);
        renWin.AddRenderer(ren[4]);
        renWin.SetSize(600, 300);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        // Add the actors to the renderer, set the background and size[]
        ren[1].SetViewport((double).75, (double)0, (double)1, (double)1);
        ren[2].SetViewport((double).50, (double)0, (double).75, (double)1);
        ren[3].SetViewport((double).25, (double)0, (double).50, (double)1);
        ren[4].SetViewport((double)0, (double)0, (double).25, (double)1);
        // render the image[]
        //[]
        iren.Initialize();
        // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }