private void vtkPolyDataConnectivityFilter_LargestRegion()
        {
            // Small sphere
            vtkSphereSource sphereSource1 = vtkSphereSource.New();

            sphereSource1.Update();

            // Large sphere
            vtkSphereSource sphereSource2 = vtkSphereSource.New();

            sphereSource2.SetRadius(10);
            sphereSource2.SetCenter(25, 0, 0);
            sphereSource2.SetThetaResolution(10);
            sphereSource2.SetPhiResolution(10);
            sphereSource2.Update();

            vtkAppendPolyData appendFilter = vtkAppendPolyData.New();

            appendFilter.AddInputConnection(sphereSource1.GetOutputPort());
            appendFilter.AddInputConnection(sphereSource2.GetOutputPort());
            appendFilter.Update();

            vtkPolyDataConnectivityFilter connectivityFilter = vtkPolyDataConnectivityFilter.New();

            connectivityFilter.SetInputConnection(appendFilter.GetOutputPort());
            connectivityFilter.SetExtractionModeToLargestRegion();
            connectivityFilter.Update();

            // Create a mapper and actor for original data
            vtkPolyDataMapper originalMapper = vtkPolyDataMapper.New();

            originalMapper.SetInputConnection(appendFilter.GetOutputPort());
            originalMapper.Update();

            vtkActor originalActor = vtkActor.New();

            originalActor.SetMapper(originalMapper);

            // Create a mapper and actor for extracted data
            vtkPolyDataMapper extractedMapper = vtkPolyDataMapper.New();

            extractedMapper.SetInputConnection(connectivityFilter.GetOutputPort());
            extractedMapper.Update();

            vtkActor extractedActor = vtkActor.New();

            extractedActor.GetProperty().SetColor(1, 0, 0);
            extractedActor.SetMapper(extractedMapper);
            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();

            // set background color
            renderer.SetBackground(0.2, 0.3, 0.4);
            // add our actor to the renderer
            renderer.AddActor(originalActor);
            renderer.AddActor(extractedActor);
        }
        public static vtkPolyData Create(List <List <double[]> > xyzList, double radius)
        {
            vtkAppendPolyData append = new vtkAppendPolyData();

            foreach (List <double[]> list in xyzList)
            {
                append.AddInput(Create(list, radius));
            }

            append.Update();

            return(append.GetOutput());
        }
Exemple #3
0
        static public vtkAlgorithmOutput combiFrustumCone(double start_radius, double distance,
                                                          double angle, bool is_foucs, double foucs_radius)
        {
            double tanArc     = Math.Tan(Math.PI * angle / 180);
            double origin_dis = start_radius / tanArc;

            if (is_foucs) // 缩小
            {
                double origin_foucs_dis = foucs_radius / tanArc;
                double fouce_dis        = origin_dis - origin_foucs_dis;
                if (distance > fouce_dis) //缩小到焦点后放大
                {
                    vtkAppendPolyData polydata = vtkAppendPolyData.New();
                    polydata.AddInputConnection(genFrustumCone(origin_dis, start_radius, fouce_dis, false));
                    vtkTransform transform = vtkTransform.New();
                    transform.Translate(0, 0, fouce_dis);

                    vtkTransformPolyDataFilter transFilter = vtkTransformPolyDataFilter.New();
                    origin_dis = origin_foucs_dis + distance - fouce_dis;
                    transFilter.SetInputConnection(genFrustumCone(origin_dis, origin_dis * tanArc, distance - fouce_dis, true));
                    transFilter.SetTransform(transform); //use vtkTransform (or maybe vtkLinearTransform)
                    transFilter.Update();
                    polydata.AddInputConnection(transFilter.GetOutputPort());
                    polydata.Update();
                    return(polydata.GetOutputPort());
                }
                else
                {
                    return(genFrustumCone(origin_dis, start_radius, distance, false));
                }
            }
            else // 放大
            {
                double total_dis  = origin_dis + distance;
                double end_radius = total_dis * tanArc;

                return(genFrustumCone(total_dis, end_radius, distance, true));
            }
        }