Example #1
0
        /// <summary>
        /// 将点做映射,按照xoz面来影射点,为2维的弹体做准备
        /// </summary>
        /// <param name="points"></param>
        /// <returns></returns>
        private static vtkPoints ReflectPointsByXOZ(vtkPoints points)
        {
            vtkPoints tempPoints = vtkPoints.New();
            int       numPoints  = points.GetNumberOfPoints();

            //点数扩大两倍
            tempPoints.SetNumberOfPoints(numPoints * 2);
            //构造相应的点
            for (int i = 0; i < numPoints; i++)
            {
                double[] temp = points.GetPoint(i);
                tempPoints.SetPoint(numPoints * 2 - 1 - i, temp[0] * (-1), temp[1], temp[2]);//x坐标变为相反数
                tempPoints.SetPoint(i, temp[0], temp[1], temp[2]);
            }
            return(tempPoints);
        }
Example #2
0
        public void ReadDataByLine(string filename)
        {
            try
            {
                var dataStrings = File.ReadAllLines(filename);
                points = vtkPoints.New();
                points.SetNumberOfPoints(dataStrings.Length);

                var colorArray = vtkUnsignedCharArray.New();
                colorArray.SetNumberOfComponents(3);

                for (var i = 0; i < dataStrings.Length; i++)
                {
                    var data = dataStrings[i].Split(' ');

                    if (data.Length < 6)
                    {
                        continue;
                    }

                    points.SetPoint(i, int.Parse(data[0]), int.Parse(data[1]), int.Parse(data[2]));
                    colorArray.InsertNextTuple3(double.Parse(data[3]), double.Parse(data[4]), double.Parse(data[5]));
                }

                PolyData = vtkPolyData.New();
                PolyData.SetPoints(points);
                PolyData.GetPointData().SetScalars(colorArray);
                PolyData.Update();
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #3
0
File: Part.cs Project: ovevans/STAN
        /// <summary>
        /// Update Part Nodes position
        /// <list>
        /// <item><c>DB</c></item>
        /// <description> - Database with results (e.g. Nodal displacements, Element stress, etc.)</description>
        /// <item><c>inc</c></item>
        /// <description> - increment number for which you want to update</description>
        /// </list>
        /// </summary>
        public void UpdateNode(Database DB, int inc)
        {
            // Update Node position
            foreach (var node in Nodes)   // Update Points coordinates and assign default color
            {
                int id    = node.Key;
                int index = node.Value;

                Points.SetPoint(index,
                                DB.NodeLib[id].GetDisp(inc, 0) + DB.NodeLib[id].X,
                                DB.NodeLib[id].GetDisp(inc, 1) + DB.NodeLib[id].Y,
                                DB.NodeLib[id].GetDisp(inc, 2) + DB.NodeLib[id].Z);
            }
        }
Example #4
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);
        }
        private void PlanesIntersection()
        {
            vtkSphereSource sphereSource = vtkSphereSource.New();

            sphereSource.Update();

            double[] bounds = new double[6];
            bounds = sphereSource.GetOutput().GetBounds();

            vtkPoints box = vtkPoints.New();

            box.SetNumberOfPoints(8);

            double xMin, xMax, yMin, yMax, zMin, zMax;

            xMin = bounds[0]; xMax = bounds[1];
            yMin = bounds[2]; yMax = bounds[3];
            zMin = bounds[4]; zMax = bounds[5];

            box.SetPoint(0, xMax, yMin, zMax);
            box.SetPoint(1, xMax, yMin, zMin);
            box.SetPoint(2, xMax, yMax, zMin);
            box.SetPoint(3, xMax, yMax, zMax);
            box.SetPoint(4, xMin, yMin, zMax);
            box.SetPoint(5, xMin, yMin, zMin);
            box.SetPoint(6, xMin, yMax, zMin);
            box.SetPoint(7, xMin, yMax, zMax);

            vtkPlanesIntersection planesIntersection = vtkPlanesIntersection.New();

            planesIntersection.SetBounds(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]);
            int intersects = planesIntersection.IntersectsRegion(box);

            Debug.WriteLine("Intersects? " + ((intersects == 1) ? true : false).ToString());
            // nothing to visualize
        }
        public CrossPackage(double size, vtkRenderer renderer)
        {
            //Console.WriteLine(string.Format("VTP文件 = {0}", vtpFile));
            vtkPolyData cursorPolyData = vtkPolyData.New();

            vtkPoints cursorPts = vtkPoints.New();

            cursorPts.SetNumberOfPoints(12);

            cursorPts.SetPoint(0, -size, -0, 0);
            cursorPts.SetPoint(1, size, -0, 0);
            cursorPts.SetPoint(2, size, 0, 0);
            cursorPts.SetPoint(3, -size, 0, 0);

            cursorPts.SetPoint(4, -0, size, 0);
            cursorPts.SetPoint(5, 0, size, 0);
            cursorPts.SetPoint(6, 0, -size, 0);
            cursorPts.SetPoint(7, -0, -size, 0);

            cursorPts.SetPoint(8, -0, 0, size);
            cursorPts.SetPoint(9, 0, 0, size);
            cursorPts.SetPoint(10, 0, 0, -size);
            cursorPts.SetPoint(11, -0, 0, -size);

            vtkCellArray cells = vtkCellArray.New();

            cells.InsertNextCell(3, VTKUtil.ConvertIntPtr(new long[] { 0, 1, 2 }));
            cells.InsertNextCell(3, VTKUtil.ConvertIntPtr(new long[] { 1, 2, 3 }));
            cells.InsertNextCell(3, VTKUtil.ConvertIntPtr(new long[] { 4, 5, 6 }));
            cells.InsertNextCell(3, VTKUtil.ConvertIntPtr(new long[] { 5, 6, 7 }));
            cells.InsertNextCell(3, VTKUtil.ConvertIntPtr(new long[] { 8, 9, 10 }));
            cells.InsertNextCell(3, VTKUtil.ConvertIntPtr(new long[] { 9, 10, 11 }));

            vtkCellArray lines = vtkCellArray.New();

            lines.InsertNextCell(2, VTKUtil.ConvertIntPtr(new long[] { 0, 1 }));
            lines.InsertNextCell(2, VTKUtil.ConvertIntPtr(new long[] { 6, 5 }));
            lines.InsertNextCell(2, VTKUtil.ConvertIntPtr(new long[] { 10, 9 }));

            cursorPolyData.SetPoints(cursorPts);
            cursorPolyData.SetVerts(cells);
            //CursorPolyData.SetPolys(cells);
            cursorPolyData.SetLines(lines);
            cursorPolyData.Update();

            PolyData = cursorPolyData;

            _polyDataMapper = vtkPolyDataMapper.New();
            _polyDataMapper.ScalarVisibilityOff();
            _polyDataMapper.SetInput(PolyData);
            _polyDataMapper.Update();

            actor = vtkActor.New();
            actor.SetMapper(_polyDataMapper);

            //marchingCubeActor.GetProperty().BackfaceCullingOn();
            //marchingCubeActor.GetProperty().FrontfaceCullingOn();
            //marchingCubeActor.GetProperty().BackfaceCullingOff();

            // now, tell the renderer our actors
            renderer.AddActor(actor);

            this._renderer = renderer;
        }