Exemplo n.º 1
1
        /// <summary>
        /// Instantiates an empty point cloud, ready for us to dump some data
        /// </summary>
        public vtkICP()
        {
            //instantiate empty lists and point clouds
            pointClouds = new List<PointCloud>();
            txpointClouds = new List<PointCloud>();
            pcd = new PointCloud();

            //instantiate vtk lists
            vtkICPAlgo = new vtkIterativeClosestPointTransform();
            sourceData = new vtkPoints();
            sourcePoints = new vtkCellArray();
        }
Exemplo n.º 2
0
        public void VTKDrawEdgesModel(ref vtkPoints points,
                                      ref vtkCellArray strips,
                                      FormParas paras)
        {
            int cnt = 0;

            for (int i = 0; i < NodeListSize; i++)
            {
                points.InsertPoint(cnt,
                                   NodeList[i].Node_Coord[0],
                                   0,
                                   -NodeList[i].Node_Coord[1]);
                cnt++;
            }

            foreach (ListElemBase elem in ElemList)
            {
                for (int i = 0; i < 8; i++)
                {
                    strips.InsertNextCell(2);
                    if (i != 7)
                    {
                        strips.InsertCellPoint((int)NodeElemTable[elem.Elem_Nodes[i]] - 1);
                        strips.InsertCellPoint((int)NodeElemTable[elem.Elem_Nodes[i + 1]] - 1);
                    }
                    else
                    {
                        strips.InsertCellPoint((int)NodeElemTable[elem.Elem_Nodes[i]] - 1);
                        strips.InsertCellPoint((int)NodeElemTable[elem.Elem_Nodes[0]] - 1);
                    }
                }
            }
        }
        // Draw poly data: earth demo
        private void earthToolStripMenuItem_Click(object sender, EventArgs e)
        {
            vtkEarthSource    source = new vtkEarthSource();
            vtkPolyDataMapper map    = vtkPolyDataMapper.New();
            vtkPolyData       poly   = new vtkPolyData();
            vtkActor          actor  = new vtkActor();

            vtkPoints    pts   = new vtkPoints();
            vtkCellArray strip = new vtkCellArray();

            // 定义三个点
            pts.InsertNextPoint(0, 0, 0);
            pts.InsertNextPoint(1, 0, 0);
            pts.InsertNextPoint(1, 1, 0);

            // 定义一个单元
            strip.InsertCellPoint(3);
            strip.InsertNextCell(0);
            strip.InsertNextCell(1);
            strip.InsertNextCell(2);
            // 定义vtkPolyData为点集
            poly.SetPoints(pts);
            poly.SetVerts(strip);// 用SetVerts函数定义点, Verts即Vertices(顶点,Vertex的复数)
            // 定义mapper
            map.SetInput(poly);
            map.SetInput(source.GetOutput());
            actor.SetMapper(map);
            m_Renderer.SetBackground(.5, .5, 1);
            imgPropList.Add(actor);
            m_Renderer.AddActor(actor);
            //Rerender the screen
            m_RenderWindow.Render();
            m_Renderer.Render();
        }
Exemplo n.º 4
0
        private void Vertex()
        {
            vtkPoints points = vtkPoints.New();

            points.InsertNextPoint(0, 0, 0);

            vtkVertex vertex = vtkVertex.New();

            vertex.GetPointIds().SetId(0, 0);

            vtkCellArray vertices = vtkCellArray.New();

            vertices.InsertNextCell(vertex);

            vtkPolyData polydata = vtkPolyData.New();

            polydata.SetPoints(points);
            polydata.SetVerts(vertices);

            // Visualize
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputConnection(polydata.GetProducerPort());
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            actor.GetProperty().SetPointSize(10);
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            vtkRenderer     renderer     = renderWindow.GetRenderers().GetFirstRenderer();

            renderer.SetBackground(0.2, 0.3, 0.4);
            // Add the actor to the scene
            renderer.AddActor(actor);
        }
Exemplo n.º 5
0
 //保存当前cell的id
 // static int m_totalCell = 0;
 public GridActor()
 {
     m_gridData = new vtkUnstructuredGrid();
     m_points   = new vtkPoints();
     m_cells    = new vtkCellArray();
     //  m_totalCell = 0;
 }
Exemplo n.º 6
0
        public void WriteVTP(string filePath, List <Vector3d> point_data, List <Vector3> cellPointsList, Dictionary <String, vtkDataArray> scalar_dataArray, List <String> arrayNames)
        {
            vtkPoints points = vtkPoints.New();

            for (int i = 0; i < point_data.Count(); i++)
            {
                points.InsertNextPoint(point_data[i].X, point_data[i].Y, point_data[i].Z);
            }

            vtkPolyData polyData = vtkPolyData.New();

            polyData.SetPoints(points);

            vtkCellArray cellArrayOne = vtkCellArray.New();

            for (int i = 0; i < cellPointsList.Count(); i++)
            {
                vtkTetra tetra = vtkTetra.New();

                tetra.GetPointIds().SetId(0, (long)cellPointsList[i][0]);
                tetra.GetPointIds().SetId(1, (long)cellPointsList[i][1]);
                tetra.GetPointIds().SetId(2, (long)cellPointsList[i][2]);
                tetra.GetPointIds().SetId(3, (long)cellPointsList[i][2]);
                cellArrayOne.InsertNextCell(tetra);
            }

            polyData.SetPolys(cellArrayOne);

            int numberOfScalarData = scalar_dataArray.Count();

            for (int i = 0; i < numberOfScalarData; i++)
            {
                scalar_dataArray.TryGetValue(arrayNames[i], out vtkDataArray scalars);
                polyData.GetPointData().AddArray(scalars);
            }

            vtkXMLPolyDataWriter writer = vtkXMLPolyDataWriter.New();

            // add file ending if it is not existent
            string suffix = (".vtp");

            if (!(filePath.EndsWith(suffix)))
            {
                filePath += suffix;
            }

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

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

            if (reader.CanReadFile(filePath) == 0)
            {
                //MessageBox.Show("Cannot read file \"" + filePath + "\"", "Error", MessageBoxButtons.OK);
                return;
            }
            Console.WriteLine("VTP file was writen and is saved at {0}", filePath);
        }
Exemplo n.º 7
0
        static public vtkPolyData ArrayList2PolyData(int type, List <Point3D> centers, double[] trueScale, double[] centroidScale
                                                     , double[] scale, int clock, int clock_y, int clock_x)//ArrayList转成可视化PolyData
        {
            vtkPolyData polydata = new vtkPolyData();

            vtkPoints    SourcePoints   = new vtkPoints();
            vtkCellArray SourceVertices = new vtkCellArray();

            int[] pid = new int[1];
            if (type == 1)
            {
                for (int i = 0; i < centers.Count; i++)
                {
                    //if (!centers[i].isFilter)
                    //{
                    //pid[0] = SourcePoints.InsertNextPoint(centers[i].tmp_X, centers[i].tmp_Y, centers[i].tmp_Z);
                    pid[0] = SourcePoints.InsertNextPoint(centers[i].tmp_X, centers[i].tmp_Y, 0);
                    SourceVertices.InsertNextCell(1, pid);
                    //}
                }
            }
            polydata.SetPoints(SourcePoints); //把点导入的polydata中去
            polydata.SetVerts(SourceVertices);
            return(polydata);
        }
Exemplo n.º 8
0
        void Test()
        {
            foreach (var actor in m_actorDict.Keys)
            {
                int xmin    = 0;
                int xlength = 1000;
                int xmax    = xmin + xlength;
                int ymin    = 0;
                int ylength = 1000;
                int ymax    = ymin + ylength;

                int[] pos = { xmin, xmin + xlength, ymin, ymin + ylength };
                #region RECT
                vtkPoints pts = vtkPoints.New();
                pts.InsertPoint(0, xmin, ymin, 0);
                pts.InsertPoint(1, xmax, ymin, 0);
                pts.InsertPoint(2, xmax, ymax, 0);
                pts.InsertPoint(3, xmin, ymax, 0);
                vtkCellArray rect = vtkCellArray.New();
                rect.InsertNextCell(5);
                rect.InsertCellPoint(0);
                rect.InsertCellPoint(1);
                rect.InsertCellPoint(2);
                rect.InsertCellPoint(3);
                rect.InsertCellPoint(0);
                vtkPolyData selectRect = vtkPolyData.New();
                selectRect.SetPoints(pts);
                selectRect.SetLines(rect);
                vtkPolyDataMapper2D rectMapper = vtkPolyDataMapper2D.New();
                rectMapper.SetInput(selectRect);
                vtkActor2D rectActor = vtkActor2D.New();
                rectActor.SetMapper(rectMapper);
                m_render.AddActor(rectActor);
                #endregion
                vtkIdFilter ids = vtkIdFilter.New();
                ids.SetInput(actor.GetMapper().GetInput());
                //ids.SetInputConnection( actor.GetMapper().GetOutputPort());
                ids.PointIdsOn();
                ids.FieldDataOn();

                vtkSelectVisiblePoints visPts = vtkSelectVisiblePoints.New();
                visPts.SetInput(ids.GetOutput());
                visPts.SetRenderer(m_render);
                visPts.SelectInvisibleOn();
                visPts.SelectionWindowOn();
                //visPts.SelectInvisibleOff();
                visPts.SetSelection(pos[0], pos[1], pos[2], pos[3]);

                vtkLabeledDataMapper labelMapper = vtkLabeledDataMapper.New();
                labelMapper.SetInputConnection(visPts.GetOutputPort());
                // labelMapper.SetInput(visPts.GetInput());
                labelMapper.SetLabelModeToLabelFieldData();
                vtkActor2D actor2d = vtkActor2D.New();
                actor2d.SetMapper(labelMapper);
                m_render.AddActor(actor2d);
            }
            m_render.Render();
        }
Exemplo n.º 9
0
        private void Hexahedron()
        {
            // Setup the coordinates of eight points
            // (faces must be in counter clockwise order as viewed from the outside)
            double[,] p = new double[, ] {
                { 0.0, 0.0, 0.0 },
                { 1.0, 0.0, 0.0 },
                { 1.0, 1.0, 0.0 },
                { 0.0, 1.0, 0.0 },
                { 0.0, 0.0, 1.0 },
                { 1.0, 0.0, 1.0 },
                { 1.0, 1.0, 1.0 },
                { 0.0, 1.0, 1.0 }
            };

            // Create the points
            vtkPoints points = vtkPoints.New();

            for (int i = 0; i < 8; i++)
            {
                points.InsertNextPoint(p[i, 0], p[i, 1], p[i, 2]);
            }

            // Create a hexahedron from the points
            vtkHexahedron hex = vtkHexahedron.New();

            for (int i = 0; i < 8; i++)
            {
                hex.GetPointIds().SetId(i, i);
            }

            // Add the hexahedron to a cell array
            vtkCellArray hexs = vtkCellArray.New();

            hexs.InsertNextCell(hex);

            // Add the points and hexahedron to an unstructured grid
            vtkUnstructuredGrid uGrid = vtkUnstructuredGrid.New();

            uGrid.SetPoints(points);
            uGrid.InsertNextCell(hex.GetCellType(), hex.GetPointIds());

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

            mapper.SetInput(uGrid);
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            actor.GetProperty().SetLineWidth(4);
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            vtkRenderer     renderer     = renderWindow.GetRenderers().GetFirstRenderer();

            renderer.SetBackground(0.2, 0.3, 0.4);
            renderer.AddActor(actor);
            renderer.ResetCamera();
        }
Exemplo n.º 10
0
        private void CreateViewportBorder(vtkRenderer renderer, double[] color)
        {
            ModelLoaded = false;

            // points start at upper right and proceed anti-clockwise
            vtkPoints points = vtkPoints.New();

            points.SetNumberOfPoints(4);
            points.InsertPoint(0, 1, 1, 0);
            points.InsertPoint(1, 1e-3, 1, 0);
            points.InsertPoint(2, 1e-3, 1e-3, 0);
            points.InsertPoint(3, 1, 1e-3, 0);

            // create cells, and lines
            vtkCellArray cells = vtkCellArray.New();

            cells.Initialize();

            vtkPolyLine lines = vtkPolyLine.New();

            lines.GetPointIds().SetNumberOfIds(5);
            for (int i = 0; i < 4; ++i)
            {
                lines.GetPointIds().SetId(i, i);
            }
            lines.GetPointIds().SetId(4, 0);
            cells.InsertNextCell(lines);

            // now make tge polydata and display it
            vtkPolyData poly = vtkPolyData.New();

            poly.Initialize();
            poly.SetPoints(points);
            poly.SetLines(cells);

            // use normalized viewport coordinates since
            // they are independent of window size
            vtkCoordinate coordinate = vtkCoordinate.New();

            coordinate.SetCoordinateSystemToNormalizedViewport();

            vtkPolyDataMapper2D mapper = vtkPolyDataMapper2D.New();

            mapper.SetInput(poly);
            mapper.SetTransformCoordinate(coordinate);

            vtkActor2D actor = vtkActor2D.New();

            actor.SetMapper(mapper);
            actor.GetProperty().SetColor(color[0], color[1], color[2]);
            // line width should be at least 2 to be visible at extremes

            actor.GetProperty().SetLineWidth((float)2.0); // Line Width

            renderer.AddViewProp(actor);
        }
Exemplo n.º 11
0
        private void DrawTriangle()
        {
            //创建点数据
            vtkPoints points = vtkPoints.New();

            points.InsertNextPoint(1.0, 0.0, 0.0);
            points.InsertNextPoint(0.0, 1.0, 0.0);
            points.InsertNextPoint(0.0, 0.0, 0.0);

            //每两个坐标之间分别创建一条线
            //SetId()的第一个参数是线段的端点ID,第二参数是连接的的点的ID
            vtkLine line0 = vtkLine.New();

            line0.GetPointIds().SetId(0, 0);
            line0.GetPointIds().SetId(1, 1);

            vtkLine line1 = vtkLine.New();

            line1.GetPointIds().SetId(0, 1);
            line1.GetPointIds().SetId(1, 2);

            vtkLine line2 = vtkLine.New();

            line2.GetPointIds().SetId(0, 2);
            line2.GetPointIds().SetId(1, 0);

            //创建单元数组,用于存储以上创建的线段
            vtkCellArray lines = vtkCellArray.New();

            lines.InsertNextCell(line0);
            lines.InsertNextCell(line1);
            lines.InsertNextCell(line2);

            //将点和线加入数据集中,前者定义数据集的几何结构,后者定义拓扑结构
            //创建vtkPolyData类型的数据,是一种数据集
            vtkPolyData polyData = vtkPolyData.New();

            //将创建的点数据加入vtkPolyData数据里
            polyData.SetPoints(points); //点数据定义了polydata数据集的几何结构。
            polyData.SetLines(lines);   //定义拓扑结构

            //显示数据
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputData(polyData);
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            actor.GetProperty().SetColor(1.0, 0.0, 0.0);
            vtkRenderWindow renWin   = myRenderWindowControl.RenderWindow;
            vtkRenderer     renderer = renWin.GetRenderers().GetFirstRenderer();

            renderer.SetBackground(1.0, 1.0, 1.0);
            renderer.AddActor(actor);
        }
Exemplo n.º 12
0
        private static void IterateOverLines()
        {
            double[] origin = new double[] { 0.0, 0.0, 0.0 };
            double[,] p = new double[, ] {
                { 1.0, 0.0, 0.0 },
                { 0.0, 1.0, 0.0 },
                { 0.0, 1.0, 2.0 },
                { 1.0, 2.0, 3.0 }
            };

            // Create a vtkPoints object and store the points in it
            vtkPoints points = vtkPoints.New();

            points.InsertNextPoint(origin[0], origin[1], origin[2]);
            for (int i = 0; i < 4; i++)
            {
                points.InsertNextPoint(p[i, 0], p[i, 1], p[i, 2]);
            }

            // Create a cell array to store the lines in and add the lines to it
            vtkCellArray lines = vtkCellArray.New();

            // Create four lines
            for (int i = 0; i < 4; i++)
            {
                vtkLine line = vtkLine.New();
                line.GetPointIds().SetId(0, i);
                line.GetPointIds().SetId(1, i + 1);
                lines.InsertNextCell(line);
            }

            // Create a polydata to store everything in
            vtkPolyData linesPolyData = vtkPolyData.New();

            // Add the points to the dataset
            linesPolyData.SetPoints(points);

            // Add the lines to the dataset
            linesPolyData.SetLines(lines);

            Console.WriteLine("There are " + linesPolyData.GetNumberOfLines() + " lines.");
            linesPolyData.GetLines().InitTraversal();
            vtkIdList idList = vtkIdList.New();

            while (linesPolyData.GetLines().GetNextCell(idList) != 0)
            {
                Console.WriteLine("Line has " + idList.GetNumberOfIds() + " points.");

                for (int pointId = 0; pointId < idList.GetNumberOfIds(); pointId++)
                {
                    Console.Write(idList.GetId(pointId) + " ");
                }
                Console.Write(Environment.NewLine);
            }
        }
Exemplo n.º 13
0
        private void ExtractEdges()
        {
            vtkSphereSource sphereSource = vtkSphereSource.New();

            sphereSource.Update();

            Debug.WriteLine("Sphere" + Environment.NewLine + "----------");
            Debug.WriteLine("There are " + sphereSource.GetOutput().GetNumberOfCells() + " cells.");
            Debug.WriteLine("There are " + sphereSource.GetOutput().GetNumberOfPoints() + " points.");

            vtkExtractEdges extractEdges = vtkExtractEdges.New();

#if VTK_MAJOR_VERSION_5
            extractEdges.SetInputConnection(sphereSource.GetOutputPort());
#else
            extractEdges.SetInputData(sphereSource);
#endif
            extractEdges.Update();

            vtkCellArray lines  = extractEdges.GetOutput().GetLines();
            vtkPoints    points = extractEdges.GetOutput().GetPoints();

            Debug.WriteLine(Environment.NewLine + "Edges" + Environment.NewLine + "----------");
            Debug.WriteLine("There are " + lines.GetNumberOfCells() + " cells.");
            Debug.WriteLine("There are " + points.GetNumberOfPoints() + " points.");

            // Traverse all of the edges
            for (int i = 0; i < extractEdges.GetOutput().GetNumberOfCells(); i++)
            {
                //Debug.WriteLine("Type: " + extractEdges.GetOutput().GetCell(i).GetClassName() );
                vtkLine line = vtkLine.SafeDownCast(extractEdges.GetOutput().GetCell(i));
                Debug.WriteLine("Line " + i + " : " + line);
            }

            // Visualize the edges

            // Create a mapper and actor
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            mapper.SetInputConnection(extractEdges.GetOutputPort());
#else
            mapper.SetInputData(extractEdges);
#endif
            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(1, 1, 1);
            // add our actor to the renderer
            renderer.AddActor(actor);
        }
Exemplo n.º 14
0
        private void PolyLine()
        {
            // Create five points
            double[,] p = new double[, ] {
                { 0.0, 0.0, 0.0 },
                { 1.0, 0.0, 0.0 },
                { 0.0, 1.0, 0.0 },
                { 0.0, 1.0, 2.0 },
                { 0.0, 3.0, 3.0 }
            };

            // Create the points
            vtkPoints points = vtkPoints.New();

            for (int i = 0; i < 5; i++)
            {
                points.InsertNextPoint(p[i, 0], p[i, 1], p[i, 2]);
            }


            vtkPolyLine polyLine = vtkPolyLine.New();

            polyLine.GetPointIds().SetNumberOfIds(5);
            for (int i = 0; i < 5; i++)
            {
                polyLine.GetPointIds().SetId(i, i);
            }

            // Create a cell array to store the lines in and add the lines to it
            vtkCellArray cells = vtkCellArray.New();

            cells.InsertNextCell(polyLine);

            // Create a polydata to store everything in
            vtkPolyData polyData = vtkPolyData.New();

            // Add the points to the dataset
            polyData.SetPoints(points);

            // Add the lines to the dataset
            polyData.SetLines(cells);
            //Create an actor and mapper
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInput(polyData);
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            vtkRenderer     renderer     = renderWindow.GetRenderers().GetFirstRenderer();

            renderer.SetBackground(0.2, 0.3, 0.4);
            renderer.AddActor(actor);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Instantiates an empty point cloud, ready for us to dump some data
        /// </summary>
        public vtkICP()
        {
            //instantiate empty lists and point clouds
            pointClouds   = new List <PointCloud>();
            txpointClouds = new List <PointCloud>();
            pcd           = new PointCloud();

            //instantiate vtk lists
            vtkICPAlgo   = new vtkIterativeClosestPointTransform();
            sourceData   = new vtkPoints();
            sourcePoints = new vtkCellArray();
        }
Exemplo n.º 16
0
        private void LongLine()
        {
            // Create five points
            double[,] p = new double[, ] {
                { 0.0, 0.0, 0.0 },
                { 1.0, 0.0, 0.0 },
                { 0.0, 1.0, 0.0 },
                { 0.0, 1.0, 2.0 },
                { 1.0, 2.0, 3.0 }
            };

            // Create a vtkPoints object and store the points in it
            vtkPoints points = vtkPoints.New();

            for (int i = 0; i < 5; i++)
            {
                points.InsertNextPoint(p[i, 0], p[i, 1], p[i, 2]);
            }

            // Create a cell array to store the lines in and add the lines to it
            vtkCellArray lines = vtkCellArray.New();

            for (int i = 0; i < 4; i++)
            {
                vtkLine line = vtkLine.New();
                line.GetPointIds().SetId(0, i);
                line.GetPointIds().SetId(1, i + 1);
                lines.InsertNextCell(line);
            }

            // Create a polydata to store everything in
            vtkPolyData linesPolyData = vtkPolyData.New();

            // Add the points to the dataset
            linesPolyData.SetPoints(points);

            // Add the lines to the dataset
            linesPolyData.SetLines(lines);
            // Visualize
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInput(linesPolyData);
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            actor.GetProperty().SetLineWidth(4);
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            vtkRenderer     renderer     = renderWindow.GetRenderers().GetFirstRenderer();

            renderer.SetBackground(0.2, 0.3, 0.4);
            renderer.AddActor(actor);
            renderer.ResetCamera();
        }
Exemplo n.º 17
0
        private void DrawPoint()
        {
            // Create the geometry of the points (the coordinate)
            vtkPoints points = vtkPoints.New();

            double[,] p = new double[, ]
            {
                { 1.0, 2.0, 3.0 },
                { 3.0, 1.0, 2.0 },
                { 2.0, 3.0, 1.0 },
                { 1.0, 3.0, 3.0 }
            };

            // Create topology of the points (a vertex per point)
            vtkCellArray vertices = vtkCellArray.New();
            int          nPts     = 4;

            int[] ids = new int[nPts];
            for (int i = 0; i < nPts; i++)
            {
                ids[i] = (int)points.InsertNextPoint(p[i, 0], p[i, 1], p[i, 2]);
            }

            int    size = Marshal.SizeOf(typeof(int)) * nPts;
            IntPtr pIds = Marshal.AllocHGlobal(size);

            Marshal.Copy(ids, 0, pIds, nPts);
            vertices.InsertNextCell(nPts, pIds);
            Marshal.FreeHGlobal(pIds);

            // Create a polydata object
            vtkPolyData pointPoly = vtkPolyData.New();

            // Set the points and vertices we created as the geometry and topology of the polydata
            pointPoly.SetPoints(points);
            pointPoly.SetVerts(vertices);

            // Visualize
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputData(pointPoly);

            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            actor.GetProperty().SetPointSize(10);
            vtkRenderWindow renderWindow = myRenderWindowControl.RenderWindow;
            vtkRenderer     renderer     = renderWindow.GetRenderers().GetFirstRenderer();

            renderer.SetBackground(0.3, 0.2, 0.1);
            renderer.AddActor(actor);
        }
Exemplo n.º 18
0
        //private vtkActor DrawVehicleID(float curX, float ySign)
        //{

        //				// Create text
        //				vtkVectorText textSource = new vtkVectorText();
        //				textSource.SetText("Hello");
        //				textSource.Update();

        //				// Visualize
        //				vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
        //				mapper.SetInputConnection(textSource.GetOutputPort());


        //				vtkActor textActor = vtkActor.New();

        //				textActor.SetScale(Constants.INDICATOR_TEXT_SIZE_X, Constants.INDICATOR_TEXT_SIZE_Y, 1);

        //				double[] bounds = textActor.GetXRange();

        //				Console.WriteLine(bounds[0]);
        //				Console.WriteLine(bounds[1]);

        //				double halfSize = (bounds[1] - bounds[0]) / 2d;

        //				textActor.SetPosition(curX - halfSize, Constants.INDICATOR_LINE_OFFSET * ySign, 0);

        //				textActor.SetMapper(mapper);
        //				textActor.GetProperty().SetColor(1, 0, 0);

        //				return textActor;
        //}

        private vtkActor DrawLineSector(float startX, float yOffset, float size, Color color, float deltaY)
        {
            float topY = yOffset + Constants.TUBE_DEFAULT_HALFSIZE_Y;
            float botY = yOffset - Constants.TUBE_DEFAULT_HALFSIZE_Y;

            if (deltaY > 0)
            {
                topY += deltaY;
            }
            else
            {
                botY += deltaY;
            }

            vtkPoints points = new vtkPoints();

            points.InsertNextPoint(startX, botY, 0.0);
            points.InsertNextPoint(startX + size, botY, 0.0);
            points.InsertNextPoint(startX + size, topY, 0.0);
            points.InsertNextPoint(startX, topY, 0.0);

            vtkPolygon rectangle = new vtkPolygon();

            rectangle.GetPointIds().SetNumberOfIds(4);
            rectangle.GetPointIds().SetId(0, 0);
            rectangle.GetPointIds().SetId(1, 1);
            rectangle.GetPointIds().SetId(2, 2);
            rectangle.GetPointIds().SetId(3, 3);

            vtkCellArray polygons = new vtkCellArray();

            polygons.InsertNextCell(rectangle);

            vtkPolyData polygonPolyData = new vtkPolyData();

            polygonPolyData.SetPoints(points);
            polygonPolyData.SetPolys(polygons);


            // Visualize
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInput(polygonPolyData);
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            actor.GetProperty().SetColor(color.r, color.g, color.b);

            return(actor);
        }
Exemplo n.º 19
0
        private void Quad()
        {
            double[,] p = new double[, ] {
                { 0.0, 0.0, 0.0 },
                { 1.0, 0.0, 0.0 },
                { 1.0, 1.0, 0.0 },
                { 0.0, 1.0, 0.0 }
            };

            // Create the points
            vtkPoints points = vtkPoints.New();

            for (int i = 0; i < 4; i++)
            {
                points.InsertNextPoint(p[i, 0], p[i, 1], p[i, 2]);
            }


            vtkQuad quad = vtkQuad.New();

            quad.GetPointIds().SetNumberOfIds(4);
            for (int i = 0; i < 4; i++)
            {
                quad.GetPointIds().SetId(i, i);
            }

            // Create a cell array to store the quad in and add the quad to it
            vtkCellArray cells = vtkCellArray.New();

            cells.InsertNextCell(quad);

            // Create a polydata to store everything in
            vtkPolyData polyData = vtkPolyData.New();

            // Add the points to the dataset
            polyData.SetPoints(points);

            // Add the quad to the dataset
            polyData.SetPolys(cells);

            //Create an actor and mapper
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInput(polyData);
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);

            RenderAddActor(actor);
        }
Exemplo n.º 20
0
        private void Polygon()
        {
            // Setup four points
            vtkPoints points = vtkPoints.New();
            double    c      = Math.Cos(Math.PI / 6); // helper variable

            points.InsertNextPoint(0.0, -1.0, 0.0);
            points.InsertNextPoint(c, -0.5, 0.0);
            points.InsertNextPoint(c, 0.5, 0.0);
            points.InsertNextPoint(0.0, 1.0, 0.0);
            points.InsertNextPoint(-c, 0.5, 0.0);
            points.InsertNextPoint(-c, -0.5, 0.0);

            // Create the polygon
            vtkPolygon polygon = vtkPolygon.New();

            polygon.GetPointIds().SetNumberOfIds(6); //make a six-sided figure
            polygon.GetPointIds().SetId(0, 0);
            polygon.GetPointIds().SetId(1, 1);
            polygon.GetPointIds().SetId(2, 2);
            polygon.GetPointIds().SetId(3, 3);
            polygon.GetPointIds().SetId(4, 4);
            polygon.GetPointIds().SetId(5, 5);

            // Add the polygon to a list of polygons
            vtkCellArray polygons = vtkCellArray.New();

            polygons.InsertNextCell(polygon);

            // Create a PolyData
            vtkPolyData polygonPolyData = vtkPolyData.New();

            polygonPolyData.SetPoints(points);
            polygonPolyData.SetPolys(polygons);

            // Create a mapper and actor
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInput(polygonPolyData);
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            vtkRenderer     renderer     = renderWindow.GetRenderers().GetFirstRenderer();

            renderer.SetBackground(0.2, 0.3, 0.4);
            renderer.AddActor(actor);
            renderer.ResetCamera();
        }
Exemplo n.º 21
0
        private void Pyramid()
        {
            vtkPoints points = vtkPoints.New();

            double[,] p = new double[, ] {
                { 1.0, 1.0, 1.0 },
                { -1.0, 1.0, 1.0 },
                { -1.0, -1.0, 1.0 },
                { 1.0, -1.0, 1.0 },
                { 0.0, 0.0, 0.0 }
            };

            for (int i = 0; i < 5; i++)
            {
                points.InsertNextPoint(p[i, 0], p[i, 1], p[i, 2]);
            }

            vtkPyramid pyramid = vtkPyramid.New();

            for (int i = 0; i < 5; i++)
            {
                pyramid.GetPointIds().SetId(i, i);
            }

            vtkCellArray cells = vtkCellArray.New();

            cells.InsertNextCell(pyramid);

            vtkUnstructuredGrid ug = vtkUnstructuredGrid.New();

            ug.SetPoints(points);
            ug.InsertNextCell(pyramid.GetCellType(), pyramid.GetPointIds());

            //Create an actor and mapper
            vtkDataSetMapper mapper = vtkDataSetMapper.New();

            mapper.SetInput(ug);
            vtkActor actor = vtkActor.New();

            actor.RotateX(105.0);
            actor.RotateZ(-36.0);
            actor.SetMapper(mapper);
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            vtkRenderer     renderer     = renderWindow.GetRenderers().GetFirstRenderer();

            renderer.SetBackground(0.2, 0.3, 0.4);
            renderer.AddActor(actor);
            renderer.ResetCamera();
        }
Exemplo n.º 22
0
        private vtkActor2D VirtualHeaterVTKBuilder()
        {
            vtkActor2D actor = vtkActor2D.New();

            vtkPoints      pointSource = vtkPoints.New();
            vtkStringArray labels      = vtkStringArray.New();
            vtkCellArray   verts       = vtkCellArray.New();

            TowerModelInstance.VTKLabelGetter(ref pointSource, ref labels, ref verts, paras, WorkSpaceInstance);

            //MessageBox.Show(labels.ToString());
            vtkPolyData polyData = vtkPolyData.New();

            polyData.SetPoints(pointSource);
            polyData.SetVerts(verts);
            polyData.GetPointData().AddArray(labels);

            vtkTextProperty textProp = vtkTextProperty.New();

            textProp.SetFontSize(12);
            //textProp.SetColor(1.0, 1.0, 0.5);
            textProp.SetFontFamilyToArial();

            vtkPointSetToLabelHierarchy hie = vtkPointSetToLabelHierarchy.New();

            hie.SetInput(polyData);
            hie.SetMaximumDepth(15);
            hie.SetLabelArrayName("111");
            hie.SetTargetLabelCount(100);
            hie.SetTextProperty(textProp);

            vtkLabelPlacementMapper labelMapper = new vtkLabelPlacementMapper();

            labelMapper.SetInputConnection(hie.GetOutputPort());

            vtkFreeTypeLabelRenderStrategy strategy = new vtkFreeTypeLabelRenderStrategy();

            labelMapper.SetRenderStrategy(strategy);
            labelMapper.UseDepthBufferOn();
            labelMapper.SetShapeToNone();
            labelMapper.SetStyleToOutline();

            //labelMapper.UseUnicodeStringsOff();

            actor.SetMapper(labelMapper);
            return(actor);
        }
Exemplo n.º 23
0
        /// <summary>
        /// 获取弹体截面的一半形状
        /// </summary>
        /// <returns></returns>
        private static vtkPolyData GetBulletSection(ModelingBaseInfo info, SECTIONTYPE reflect)
        {//传入弹体参数,返回截面,该截面在ZOY面上
            vtkPolyData polyData = vtkPolyData.New();
            vtkPoints   points   = vtkPoints.New();
            vtkPolygon  polygon  = vtkPolygon.New();

            // 获取截面 点和拓扑结构
            ProcessBulletInfo(info, ref points, ref polygon, reflect);

            vtkCellArray cellArray = vtkCellArray.New();

            cellArray.InsertNextCell(polygon);
            polyData.SetPoints(points);
            polyData.SetPolys(cellArray);// 形成半个多边形

            return(polyData);
        }
Exemplo n.º 24
0
        public void SetPosition(double[] xyz1, double[] xyz2)
        {
            vtkPoints points = vtkPoints.New();

            points.InsertPoint(0, xyz1[0], xyz1[1], xyz1[2]);
            points.InsertPoint(1, xyz2[0], xyz2[1], xyz2[2]);

            vtkCellArray lines = vtkCellArray.New();

            lines.InsertNextCell(2);

            lines.InsertCellPoint(0);
            lines.InsertCellPoint(1);

            vtkPolyData profileData = new vtkPolyData();

            profileData.SetPoints(points);
            profileData.SetLines(lines);
            profileData.SetVerts(lines);
            profileData.Update();

            vtkCleanPolyData cleanFilter = new vtkCleanPolyData();

            cleanFilter.SetInput(profileData);
            cleanFilter.Update();

            vtkTubeFilter profileTubes = new vtkTubeFilter();

            profileTubes.SetNumberOfSides(10);
            profileTubes.SetInput(cleanFilter.GetOutput());
            //profileTubes.SetVaryRadiusToVaryRadiusByVector();
            profileTubes.SetRadius(1);
            profileTubes.SetInputArrayToProcess(1, 0, 0, 0, "vectors");

            //vtkPolyDataMapper profileMapper = new vtkPolyDataMapper();
            //profileMapper.SetInputConnection(profileTubes.GetOutputPort());

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInput(profileTubes.GetOutput());

            centerLineActor.SetMapper(mapper);
            centerLineActor.GetProperty().SetOpacity(0.5);
        }
Exemplo n.º 25
0
        private void TriangleStrip()
        {
            vtkPoints points = vtkPoints.New();

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

            vtkTriangleStrip triangleStrip = vtkTriangleStrip.New();

            triangleStrip.GetPointIds().SetNumberOfIds(4);
            triangleStrip.GetPointIds().SetId(0, 0);
            triangleStrip.GetPointIds().SetId(1, 1);
            triangleStrip.GetPointIds().SetId(2, 2);
            triangleStrip.GetPointIds().SetId(3, 3);

            vtkCellArray cells = vtkCellArray.New();

            cells.InsertNextCell(triangleStrip);
            // Create a polydata to store everything in
            vtkPolyData polyData = vtkPolyData.New();

            // Add the points to the dataset
            polyData.SetPoints(points);
            // Add the strip to the dataset
            polyData.SetStrips(cells);

            //Create an actor and mapper
            vtkDataSetMapper mapper = vtkDataSetMapper.New();

            mapper.SetInput(polyData);
            vtkActor actor = vtkActor.New();

            actor.GetProperty().SetRepresentationToWireframe();

            actor.SetMapper(mapper);
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            vtkRenderer     renderer     = renderWindow.GetRenderers().GetFirstRenderer();

            renderer.SetBackground(0.2, 0.3, 0.4);
            renderer.AddActor(actor);
        }
Exemplo n.º 26
0
        private void Triangle()
        {
            // Create a triangle
            vtkPoints points = vtkPoints.New();

            points.InsertNextPoint(1.0, 0.0, 0.0);
            points.InsertNextPoint(0.0, 0.0, 0.0);
            points.InsertNextPoint(0.0, 1.0, 0.0);

            vtkTriangle triangle = vtkTriangle.New();

            triangle.GetPointIds().SetId(0, 0);
            triangle.GetPointIds().SetId(1, 1);
            triangle.GetPointIds().SetId(2, 2);

            // Create a cell array to store the triangle in and add the triangle to it
            vtkCellArray cells = vtkCellArray.New();

            cells.InsertNextCell(triangle);

            // Create a polydata to store everything in
            vtkPolyData polyData = vtkPolyData.New();

            // Add the points to the dataset
            polyData.SetPoints(points);

            // Add the quad to the dataset
            polyData.SetPolys(cells);

            //Create an actor and mapper
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInput(polyData);
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            vtkRenderer     renderer     = renderWindow.GetRenderers().GetFirstRenderer();

            renderer.SetBackground(0.2, 0.3, 0.4);
            renderer.AddActor(actor);
        }
Exemplo n.º 27
0
        public static vtkPolyData Create(List <double[]> xyz1, double radius)
        {
            vtkPoints points = new vtkPoints();

            for (int index = 0; index < xyz1.Count; index++)
            {
                double[] doubles = xyz1[index];
                points.InsertPoint(index, doubles[0], doubles[1], doubles[2]);
            }

            vtkCellArray lines = new vtkCellArray();

            lines.InsertNextCell(xyz1.Count);

            for (int index = 0; index < xyz1.Count; index++)
            {
                lines.InsertCellPoint(index);
            }

            vtkPolyData profileData = new vtkPolyData();

            profileData.SetPoints(points);
            profileData.SetLines(lines);
            profileData.SetVerts(lines);
            profileData.Update();

            vtkCleanPolyData cleanFilter = new vtkCleanPolyData();

            cleanFilter.SetInput(profileData);
            cleanFilter.Update();

            vtkTubeFilter profileTubes = new vtkTubeFilter();

            profileTubes.SetNumberOfSides(10);
            profileTubes.SetInput(cleanFilter.GetOutput());
            //profileTubes.SetVaryRadiusToVaryRadiusByVector();
            profileTubes.SetRadius(radius);
            profileTubes.SetInputArrayToProcess(1, 0, 0, 0, "vectors");

            return(profileTubes.GetOutput());
        }
Exemplo n.º 28
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);
        }
Exemplo n.º 29
0
        //vtkPoints points = vtkPoints.New();
        //points.InsertNextPoint(0.0, 0.0, 0.0);
        //points.InsertNextPoint(200.0, 0.0, 0.0);
        //points.InsertNextPoint(200.0, 200.0, 0.0);
        //points.InsertNextPoint(0.0, 200.0, 0.0);
        //points.InsertNextPoint(0.0, 0.0, 0.0);

        //vtkPolygon polygon = vtkPolygon.New();
        //polygon.GetPointIds().SetNumberOfIds(5);
        //for (int i = 0; i < 5; i++)
        //{
        //    polygon.GetPointIds().SetId(i, i);
        //}

        public vtkActor2D AddMarkerLine(double[] startCoords, double[] endCoords, Color color)
        {
            vtkPoints points = vtkPoints.New();

            points.InsertNextPoint(startCoords[0], startCoords[1], 0.0);
            points.InsertNextPoint(endCoords[0], endCoords[1], 0.0);

            vtkPolyLine line = vtkPolyLine.New();

            line.GetPointIds().SetNumberOfIds(2);
            for (int i = 0; i < 2; i++)
            {
                line.GetPointIds().SetId(i, i);
            }

            vtkCellArray cellArray = vtkCellArray.New();

            cellArray.InsertNextCell(line);

            vtkPolyData polyData = vtkPolyData.New();

            polyData.SetPoints(points);
            polyData.SetLines(cellArray);

            vtkPolyDataMapper2D mapper = vtkPolyDataMapper2D.New();

            mapper.SetInputData(polyData);

            vtkActor2D actor = vtkActor2D.New();

            actor.SetMapper(mapper);

            actor.GetProperty().SetOpacity((float)color.A / 255);
            actor.GetProperty().SetColor((float)color.R / 255, (float)color.G / 255, (float)color.B / 255);

            _markerLayerRenderer.AddActor(actor);

            return(actor);
        }
Exemplo n.º 30
0
        public void WritSimpleVTM()
        {
            string filePath = "..\\..\\..\\..\\..\\03Daten\\testData\\simpleTest8Points.vtm";
            vtkMultiBlockDataSet multiBlockDataSet = vtkMultiBlockDataSet.New();

            multiBlockDataSet.SetNumberOfBlocks(2);

            vtkUnstructuredGrid unstructuredGrid1 = vtkUnstructuredGrid.New();

            vtkPoints points1 = vtkPoints.New();

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

            vtkPoints points2 = vtkPoints.New();

            points1.InsertNextPoint(2, 0, 0);
            points1.InsertNextPoint(2, 2, 0);
            points1.InsertNextPoint(2, 2, 3);
            points1.InsertNextPoint(0, 2, 3);

            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 cellArray1 = vtkCellArray.New();

            cellArray1.InsertNextCell(tetra);

            unstructuredGrid1.SetPoints(points1);
            const int VTK_TETRA = 10;

            unstructuredGrid1.SetCells(VTK_TETRA, cellArray1);

            vtkCellArray cellArray2 = vtkCellArray.New();

            tetra = vtkTetra.New();
            tetra.GetPointIds().SetId(0, 4);
            tetra.GetPointIds().SetId(1, 5);
            tetra.GetPointIds().SetId(2, 6);
            tetra.GetPointIds().SetId(3, 7);
            cellArray2.InsertNextCell(tetra);
            tetra = vtkTetra.New();
            tetra.GetPointIds().SetId(0, 7);
            tetra.GetPointIds().SetId(1, 5);
            tetra.GetPointIds().SetId(2, 2);
            tetra.GetPointIds().SetId(3, 4);

            cellArray2.InsertNextCell(tetra);


            vtkUnstructuredGrid unstructuredGrid = vtkUnstructuredGrid.New();

            unstructuredGrid.SetPoints(points1);
            unstructuredGrid.SetCells(VTK_TETRA, cellArray2);

            multiBlockDataSet.SetBlock(0, unstructuredGrid1);
            multiBlockDataSet.SetBlock(1, unstructuredGrid);

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

            writer.SetFileName(filePath);
            writer.SetInput(multiBlockDataSet);
            writer.Write();
        }
Exemplo n.º 31
0
 ///<summary> A Set Method for Static Variables </summary>
 public static void Setlines(vtkCellArray toSet)
 {
     lines = toSet;
 }
Exemplo n.º 32
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVclosedSplines(String [] argv)
    {
        //Prefix Content is: ""

          // get the interactor ui[]
          // Now create the RenderWindow, Renderer and Interactor[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          math = new vtkMath();
          numberOfInputPoints = 30;
          aKSplineX = new vtkKochanekSpline();
          aKSplineX.ClosedOn();
          aKSplineY = new vtkKochanekSpline();
          aKSplineY.ClosedOn();
          aKSplineZ = new vtkKochanekSpline();
          aKSplineZ.ClosedOn();
          aCSplineX = new vtkCardinalSpline();
          aCSplineX.ClosedOn();
          aCSplineY = new vtkCardinalSpline();
          aCSplineY.ClosedOn();
          aCSplineZ = new vtkCardinalSpline();
          aCSplineZ.ClosedOn();
          // add some points[]
          inputPoints = new vtkPoints();
          x = -1.0;
          y = -1.0;
          z = 0.0;
          aKSplineX.AddPoint((double)0,(double)x);
          aKSplineY.AddPoint((double)0,(double)y);
          aKSplineZ.AddPoint((double)0,(double)z);
          aCSplineX.AddPoint((double)0,(double)x);
          aCSplineY.AddPoint((double)0,(double)y);
          aCSplineZ.AddPoint((double)0,(double)z);
          inputPoints.InsertPoint((int)0,(double)x,(double)y,(double)z);
          x = 1.0;
          y = -1.0;
          z = 0.0;
          aKSplineX.AddPoint((double)1,(double)x);
          aKSplineY.AddPoint((double)1,(double)y);
          aKSplineZ.AddPoint((double)1,(double)z);
          aCSplineX.AddPoint((double)1,(double)x);
          aCSplineY.AddPoint((double)1,(double)y);
          aCSplineZ.AddPoint((double)1,(double)z);
          inputPoints.InsertPoint((int)1,(double)x,(double)y,(double)z);
          x = 1.0;
          y = 1.0;
          z = 0.0;
          aKSplineX.AddPoint((double)2,(double)x);
          aKSplineY.AddPoint((double)2,(double)y);
          aKSplineZ.AddPoint((double)2,(double)z);
          aCSplineX.AddPoint((double)2,(double)x);
          aCSplineY.AddPoint((double)2,(double)y);
          aCSplineZ.AddPoint((double)2,(double)z);
          inputPoints.InsertPoint((int)2,(double)x,(double)y,(double)z);
          x = -1.0;
          y = 1.0;
          z = 0.0;
          aKSplineX.AddPoint((double)3,(double)x);
          aKSplineY.AddPoint((double)3,(double)y);
          aKSplineZ.AddPoint((double)3,(double)z);
          aCSplineX.AddPoint((double)3,(double)x);
          aCSplineY.AddPoint((double)3,(double)y);
          aCSplineZ.AddPoint((double)3,(double)z);
          inputPoints.InsertPoint((int)3,(double)x,(double)y,(double)z);
          inputData = new vtkPolyData();
          inputData.SetPoints((vtkPoints)inputPoints);
          balls = new vtkSphereSource();
          balls.SetRadius((double).04);
          balls.SetPhiResolution((int)10);
          balls.SetThetaResolution((int)10);
          glyphPoints = new vtkGlyph3D();
          glyphPoints.SetInput((vtkDataObject)inputData);
          glyphPoints.SetSource((vtkPolyData)balls.GetOutput());
          glyphMapper = vtkPolyDataMapper.New();
          glyphMapper.SetInputConnection((vtkAlgorithmOutput)glyphPoints.GetOutputPort());
          glyph = new vtkActor();
          glyph.SetMapper((vtkMapper)glyphMapper);
          glyph.GetProperty().SetDiffuseColor((double) 1.0000, 0.3882, 0.2784 );
          glyph.GetProperty().SetSpecular((double).3);
          glyph.GetProperty().SetSpecularPower((double)30);
          ren1.AddActor((vtkProp)glyph);
          Kpoints = new vtkPoints();
          Cpoints = new vtkPoints();
          profileKData = new vtkPolyData();
          profileCData = new vtkPolyData();
          numberOfInputPoints = 5;
          numberOfOutputPoints = 100;
          offset = 1.0;
          //method moved
          fit();
          lines = new vtkCellArray();
          lines.InsertNextCell((int)numberOfOutputPoints);
          i = 0;
          while((i) < numberOfOutputPoints)
        {
          lines.InsertCellPoint((int)i);
          i = i + 1;
        }

          profileKData.SetPoints((vtkPoints)Kpoints);
          profileKData.SetLines((vtkCellArray)lines);
          profileCData.SetPoints((vtkPoints)Cpoints);
          profileCData.SetLines((vtkCellArray)lines);
          profileKTubes = new vtkTubeFilter();
          profileKTubes.SetNumberOfSides((int)8);
          profileKTubes.SetInput((vtkDataObject)profileKData);
          profileKTubes.SetRadius((double).01);
          profileKMapper = vtkPolyDataMapper.New();
          profileKMapper.SetInputConnection((vtkAlgorithmOutput)profileKTubes.GetOutputPort());
          profileK = new vtkActor();
          profileK.SetMapper((vtkMapper)profileKMapper);
          profileK.GetProperty().SetDiffuseColor((double) 0.8900, 0.8100, 0.3400 );
          profileK.GetProperty().SetSpecular((double).3);
          profileK.GetProperty().SetSpecularPower((double)30);
          ren1.AddActor((vtkProp)profileK);
          profileCTubes = new vtkTubeFilter();
          profileCTubes.SetNumberOfSides((int)8);
          profileCTubes.SetInput((vtkDataObject)profileCData);
          profileCTubes.SetRadius((double).01);
          profileCMapper = vtkPolyDataMapper.New();
          profileCMapper.SetInputConnection((vtkAlgorithmOutput)profileCTubes.GetOutputPort());
          profileC = new vtkActor();
          profileC.SetMapper((vtkMapper)profileCMapper);
          profileC.GetProperty().SetDiffuseColor((double) 0.2000, 0.6300, 0.7900 );
          profileC.GetProperty().SetSpecular((double).3);
          profileC.GetProperty().SetSpecularPower((double)30);
          ren1.AddActor((vtkProp)profileC);
          ren1.ResetCamera();
          ren1.GetActiveCamera().Dolly((double)1.5);
          ren1.ResetCameraClippingRange();
          renWin.SetSize((int)300,(int)300);
          // render the image[]
          //[]
          iren.Initialize();
          // prevent the tk window from showing up then start the event loop[]
          //method moved
          //method moved
          //method moved
          //method moved
          //method moved
          //method moved

        //deleteAllVTKObjects();
    }
Exemplo n.º 33
0
        private void Tetrahedron()
        {
            vtkPoints points = vtkPoints.New();

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

            // Method 1
            vtkUnstructuredGrid unstructuredGrid1 = vtkUnstructuredGrid.New();

            unstructuredGrid1.SetPoints(points);

            int[]  ptIds        = new int[] { 0, 1, 2, 3 };
            IntPtr ptIdsPointer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * 4);

            Marshal.Copy(ptIds, 0, ptIdsPointer, 4);
            unstructuredGrid1.InsertNextCell(10, 4, ptIdsPointer);
            Marshal.FreeHGlobal(ptIdsPointer);

            // Method 2
            vtkUnstructuredGrid unstructuredGrid2 = vtkUnstructuredGrid.New();

            unstructuredGrid2.SetPoints(points);

            vtkTetra tetra = vtkTetra.New();

            tetra.GetPointIds().SetId(0, 4);
            tetra.GetPointIds().SetId(1, 5);
            tetra.GetPointIds().SetId(2, 6);
            tetra.GetPointIds().SetId(3, 7);

            vtkCellArray cellArray = vtkCellArray.New();

            cellArray.InsertNextCell(tetra);
            unstructuredGrid2.SetCells(10, cellArray);

            // Create a mapper and actor
            vtkDataSetMapper mapper1 = vtkDataSetMapper.New();

            mapper1.SetInputConnection(unstructuredGrid1.GetProducerPort());

            vtkActor actor1 = vtkActor.New();

            actor1.SetMapper(mapper1);

            // Create a mapper and actor
            vtkDataSetMapper mapper2 = vtkDataSetMapper.New();

            mapper2.SetInputConnection(unstructuredGrid2.GetProducerPort());

            vtkActor actor2 = vtkActor.New();

            actor2.SetMapper(mapper2);

            vtkRenderWindow renderWindow = myRenderWindowControl.RenderWindow;
            vtkRenderer     renderer     = renderWindow.GetRenderers().GetFirstRenderer();

            renderer.SetBackground(0.2, 0.3, 0.4);
            // Add the actor to the scene
            renderer.AddActor(actor1);
            renderer.AddActor(actor2);
            renderer.SetBackground(.3, .6, .3); // Background color green
        }
Exemplo n.º 34
0
        private void ColoredLines()
        {
            // Create three points. Join (Origin and P0) with a red line and
            // (Origin and P1) with a green line
            double[] origin = new double[] { 0.0, 0.0, 0.0 };
            double[] p0     = new double[] { 1.0, 0.0, 0.0 };
            double[] p1     = new double[] { 0.0, 1.0, 0.0 };

            // Create a vtkPoints object and store the points in it
            vtkPoints pts = vtkPoints.New();

            pts.InsertNextPoint(origin[0], origin[1], origin[2]);
            pts.InsertNextPoint(p0[0], p0[1], p0[2]);
            pts.InsertNextPoint(p1[0], p1[1], p1[2]);

            // Setup two colors - one for each line
            byte[] red   = new byte[] { 255, 0, 0 };
            byte[] green = new byte[] { 0, 255, 0 };

            // Setup the colors array
            vtkUnsignedCharArray colors = vtkUnsignedCharArray.New();

            colors.SetNumberOfComponents(3);
            colors.SetName("Colors");

            // Add the colors we created to the colors array
            colors.InsertNextValue(red[0]);
            colors.InsertNextValue(red[1]);
            colors.InsertNextValue(red[2]);

            colors.InsertNextValue(green[0]);
            colors.InsertNextValue(green[1]);
            colors.InsertNextValue(green[2]);

            // Create the first line (between Origin and P0)
            vtkLine line0 = vtkLine.New();

            line0.GetPointIds().SetId(0, 0); //the second 0 is the index of the Origin in the vtkPoints
            line0.GetPointIds().SetId(1, 1); //the second 1 is the index of P0 in the vtkPoints

            // Create the second line (between Origin and P1)
            vtkLine line1 = vtkLine.New();

            line1.GetPointIds().SetId(0, 0); //the second 0 is the index of the Origin in the vtkPoints
            line1.GetPointIds().SetId(1, 2); //2 is the index of P1 in the vtkPoints

            // Create a cell array to store the lines in and add the lines to it
            vtkCellArray lines = vtkCellArray.New();

            lines.InsertNextCell(line0);
            lines.InsertNextCell(line1);

            // Create a polydata to store everything in
            vtkPolyData linesPolyData = vtkPolyData.New();

            // Add the points to the dataset
            linesPolyData.SetPoints(pts);

            // Add the lines to the dataset
            linesPolyData.SetLines(lines);

            // Color the lines - associate the first component (red) of the
            // colors array with the first component of the cell array (line 0)
            // and the second component (green) of the colors array with the
            // second component of the cell array (line 1)
            linesPolyData.GetCellData().SetScalars(colors);

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInput(linesPolyData);
            // create an actor
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);

            RenderAddActor(actor);
        }