예제 #1
0
파일: Part.cs 프로젝트: ovevans/STAN
        /// <summary>
        /// Clip this part - Set Mapper input to Clipper
        /// </summary>
        public void ClipPart(vtkPlane ClipPlane, bool clip)
        {
            if (clip == true)
            {
                Clipper = vtkTableBasedClipDataSet.New();
                Clipper.SetClipFunction(ClipPlane);
                Clipper.SetInputConnection(Grid.GetProducerPort());
                Clipper.Update();
                Mapper.SetInputConnection(Clipper.GetOutputPort());
                Mapper.Update();

                // Update Feature Filter -> will update Edges and Faces
                Filter.SetInput(Clipper.GetOutput());
                Filter.Update();



                // ------- Alternative without Clip Surface Extraction --------------

                //vtkPlaneCollection planes = vtkPlaneCollection.New();
                //planes.AddItem(ClipPlane);
                //Edges.GetMapper().SetClippingPlanes(planes);
                //Edges.GetMapper().Update();

                //vtkPlaneCollection Planes = vtkPlaneCollection.New();
                //Planes.AddItem(ClipPlane);
                //Mapper.SetClippingPlanes(Planes);
                //Mapper.Update();
            }
            else
            {
                Mapper.SetInput(Grid);
                Mapper.Update();

                // Update Feature Filter -> will update Edges and Faces
                Filter.SetInput(Grid);
                Filter.Update();


                // ------- Alternative without Clip Surface Extraction --------------
                // Edges
                //vtkPlaneCollection planes = vtkPlaneCollection.New();
                //Edges.GetMapper().SetClippingPlanes(planes);
                //Edges.GetMapper().Update();

                //vtkPlaneCollection Planes = vtkPlaneCollection.New();
                //Mapper.SetClippingPlanes(Planes);
                //Mapper.Update();
            }
        }
예제 #2
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
        }