示例#1
0
        static public void Show(RenderWindowControl aRenderControl)
        {
            // get a reference to the renderwindow of our renderWindowControl1
            var aRenderWindow = aRenderControl.RenderWindow;

            // get a reference to the renderer
            var aRenderer = aRenderWindow.GetRenderers().GetFirstRenderer();

            aRenderer.Clear();
            aRenderer.RemoveAllViewProps();

            // set background color
            aRenderer.SetBackground(0.2, 0.3, 0.4);

            var aMesher = new CMshTriangleMesherDouble();

            Mesh2D.GenerateMesh(aMesher, aRenderer);

            var anUnstructuredGrid = vtkUnstructuredGrid.New();

            Mesh2D.DrawMesh(aMesher, anUnstructuredGrid, aRenderer);

            aRenderer.ResetCamera();

            aRenderControl.Refresh();
        }
示例#2
0
        static public void GenerateMesh(CMshTriangleMesherDouble aMesher, vtkRenderer aRenderer)
        {
            var aNode1 = new CMshNodeDouble(0.0, 0.0, 0.0);
            var aNode2 = new CMshNodeDouble(1.0, 0.0, 0.0);
            var aNode3 = new CMshNodeDouble(1.0, 1.0, 0.0);
            var aNode4 = new CMshNodeDouble(0.0, 1.0, 0.0);

            var anEdgeMesh = new CMshMeshDouble();

            anEdgeMesh.addNode(1, aNode1);
            anEdgeMesh.addNode(2, aNode2);
            anEdgeMesh.addNode(3, aNode3);
            anEdgeMesh.addNode(4, aNode4);

            var anElement1 = new CMshElementDouble(EElementType.ET_BEAM);

            anElement1.addNodeId(1);
            anElement1.addNodeId(2);

            var anElement2 = new CMshElementDouble(EElementType.ET_BEAM);

            anElement2.addNodeId(2);
            anElement2.addNodeId(3);

            var anElement3 = new CMshElementDouble(EElementType.ET_BEAM);

            anElement3.addNodeId(3);
            anElement3.addNodeId(4);

            var anElement4 = new CMshElementDouble(EElementType.ET_BEAM);

            anElement4.addNodeId(4);
            anElement4.addNodeId(1);

            anEdgeMesh.addElement(1, anElement1);
            anEdgeMesh.addElement(2, anElement2);
            anEdgeMesh.addElement(3, anElement3);
            anEdgeMesh.addElement(4, anElement4);

            Mesh2D.AddCircle(anEdgeMesh, 0.3, 0.3, 0.1);
            Mesh2D.AddCircle(anEdgeMesh, 0.7, 0.3, 0.1);
            Mesh2D.AddCircle(anEdgeMesh, 0.7, 0.7, 0.1);
            Mesh2D.AddCircle(anEdgeMesh, 0.3, 0.7, 0.1);

            var sLinesPolyData = vtkPolyData.New();

            vtkPoints sPoints = vtkPoints.New();

            for (int i = 0; i < anEdgeMesh.nbNodes(); ++i)
            {
                int aNodeId = anEdgeMesh.nodeId(i);

                var aNode = anEdgeMesh.node(aNodeId);

                sPoints.InsertNextPoint(aNode.x(), aNode.y(), aNode.z());
            }

            sLinesPolyData.SetPoints(sPoints);

            var sLines = vtkCellArray.New();

            for (int i = 0; i < anEdgeMesh.nbElements(); ++i)
            {
                int anElementId = anEdgeMesh.elementId(i);

                var anElement = anEdgeMesh.element(anElementId);

                var aLine = vtkLine.New();
                aLine.GetPointIds().SetId(0, anEdgeMesh.nodeIndex(anElement.nodeId(0)));
                aLine.GetPointIds().SetId(1, anEdgeMesh.nodeIndex(anElement.nodeId(1)));

                sLines.InsertNextCell(aLine);
            }

            sLinesPolyData.SetLines(sLines);

            // add actor to the renderer
            var anEdgeActor = vtkActor.New();

            aRenderer.AddActor(anEdgeActor);

            var anEdgeMapper = vtkDataSetMapper.New();

            anEdgeMapper.SetInput(sLinesPolyData);

            anEdgeActor.SetMapper(anEdgeMapper);

            var aMeshSize = 0.026;

            anEdgeMesh.generateFaces(1E-3);

            aMesher.remesh(anEdgeMesh, aMeshSize);
            aMesher.generate(anEdgeMesh, 99999, aMeshSize, aMeshSize * 0.1, aMeshSize * 10.0, 1E-6);

            for (int i = 0; i < 3; i++)
            {
                aMesher.relaxNodes(1E-5);
                aMesher.flipEdges(1E-5);
            }

            aMesher.mesh().renumber();
        }