Ejemplo n.º 1
0
        static public vtkProp3D genQuadricSurfaceActor(CompontData data, vtkProperty pro)
        {
            if (data.restriction != null)
            {
                return(genActorByRestriction(data, pro));
            }
            QuadricSurfaceData s = (QuadricSurfaceData)data;

            vtkQuadric quadric = vtkQuadric.New();

            quadric.SetCoefficients(s.param[0], s.param[1], s.param[2], s.param[3], s.param[4], s.param[5], s.param[6],
                                    s.param[7], s.param[8], s.param[9] + 1);

            //二次函数采样分辨率
            vtkSampleFunction sample = vtkSampleFunction.New();

            sample.SetSampleDimensions(60, 60, 30);
            sample.SetImplicitFunction(quadric);
            sample.SetModelBounds(s.param[10], s.param[11], s.param[12], s.param[13], s.param[14], s.param[15]);
            vtkContourFilter contourFilter = vtkContourFilter.New();

            contourFilter.SetInputConnection(sample.GetOutputPort());
            contourFilter.GenerateValues(1, 1, 1);
            contourFilter.Update();

            return(genUserActor(data, contourFilter.GetOutputPort(), pro));
        }
Ejemplo n.º 2
0
        private void ImplicitBoolean()
        {
            vtkSphere sphere1 = vtkSphere.New();

            sphere1.SetCenter(.9, 0, 0);
            vtkSphere sphere2 = vtkSphere.New();

            sphere2.SetCenter(-.9, 0, 0);

            vtkImplicitBoolean implicitBoolean = vtkImplicitBoolean.New();

            implicitBoolean.AddFunction(sphere1);
            implicitBoolean.AddFunction(sphere2);
            implicitBoolean.SetOperationTypeToUnion();
            //implicitBoolean.SetOperationTypeToIntersection();

            // Sample the function
            vtkSampleFunction sample = vtkSampleFunction.New();

            sample.SetSampleDimensions(50, 50, 50);
            sample.SetImplicitFunction(implicitBoolean);
            double value = 3.0;
            double xmin = -value, xmax = value,
                   ymin = -value, ymax = value,
                   zmin = -value, zmax = value;

            sample.SetModelBounds(xmin, xmax, ymin, ymax, zmin, zmax);

            // Create the 0 isosurface
            vtkContourFilter contours       = vtkContourFilter.New();

#if VTK_MAJOR_VERSION_5
            contours.SetInputConnection(sample.GetOutputPort());
#else
            contours.SetInputData(sample);
#endif
            contours.GenerateValues(1, 1, 1);

            // Map the contours to graphical primitives
            vtkPolyDataMapper contourMapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            contourMapper.SetInputConnection(contours.GetOutputPort());
#else
            contourMapper.SetInputData(contours);
#endif
            contourMapper.ScalarVisibilityOff();

            // Create an actor for the contours
            vtkActor contourActor           = vtkActor.New();
            contourActor.SetMapper(contourMapper);
            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
            // set background color
            renderer.SetBackground(.2, .3, .4);
            renderer.AddActor(contourActor);
        }
Ejemplo n.º 3
0
        private void sliderContourValue_Scroll(object sender, EventArgs e)
        {
            TrackBar slider = sender as TrackBar;

            if (slider != null)
            {
                _ContourFilter.GenerateValues(1, slider.Value, slider.Value);
                _RenderWindow.Render();
            }
        }
Ejemplo n.º 4
0
        private void IsoContours()
        {
            vtkImageData data = vtkImageData.New();

            CreateData(ref data);

            // Create an isosurface
            _ContourFilter = vtkContourFilter.New();
#if VTK_MAJOR_VERSION_5
            _ContourFilter.SetInput(data);
#else
            contourFilter.SetInputData(data);
#endif
            _ContourFilter.GenerateValues(1, 10, 10); // (numContours, rangeStart, rangeEnd)

            // Map the contours to graphical primitives
            vtkPolyDataMapper contourMapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            contourMapper.SetInputConnection(_ContourFilter.GetOutputPort());
#else
            contourMapper.SetInputData(contourFilter);
#endif
            // Create an actor for the contours
            vtkActor contourActor = vtkActor.New();
            contourActor.SetMapper(contourMapper);

            // Create the outline
            vtkOutlineFilter  outlineFilter = vtkOutlineFilter.New();
            vtkPolyDataMapper outlineMapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            outlineFilter.SetInput(data);
            outlineMapper.SetInputConnection(outlineFilter.GetOutputPort());
#else
            outlineFilter.SetInputData(data);
            outlineMapper.SetInputData(outlineFilter);
#endif
            vtkActor outlineActor = vtkActor.New();
            outlineActor.SetMapper(outlineMapper);

            // get a reference to the renderwindow of our renderWindowControl1
            _RenderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = _RenderWindow.GetRenderers().GetFirstRenderer();
            // set background color
            renderer.SetBackground(.2, .3, .4);
            // add our actor to the renderer
            renderer.AddActor(contourActor);
            renderer.AddActor(outlineActor);
        }
Ejemplo n.º 5
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVlabeledContours(String [] argv)
    {
        //Prefix Content is: ""

          // demonstrate labeling of contour with scalar value[]
          // Create the RenderWindow, Renderer and both Actors[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.SetMultiSamples(0);
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          // Read a slice and contour it[]
          v16 = new vtkVolume16Reader();
          v16.SetDataDimensions((int)64,(int)64);
          v16.GetOutput().SetOrigin((double)0.0,(double)0.0,(double)0.0);
          v16.SetDataByteOrderToLittleEndian();
          v16.SetFilePrefix((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/headsq/quarter");
          v16.SetImageRange((int)45,(int)45);
          v16.SetDataSpacing((double)3.2,(double)3.2,(double)1.5);
          iso = new vtkContourFilter();
          iso.SetInputConnection((vtkAlgorithmOutput)v16.GetOutputPort());
          iso.GenerateValues((int)6,(double)500,(double)1150);
          iso.Update();
          numPts = iso.GetOutput().GetNumberOfPoints();
          isoMapper = vtkPolyDataMapper.New();
          isoMapper.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort());
          isoMapper.ScalarVisibilityOn();
          isoMapper.SetScalarRange((double)((vtkDataSet)iso.GetOutput()).GetScalarRange()[0],(double)((vtkDataSet)iso.GetOutput()).GetScalarRange()[1]);
          isoActor = new vtkActor();
          isoActor.SetMapper((vtkMapper)isoMapper);
          // Subsample the points and label them[]
          mask = new vtkMaskPoints();
          mask.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort());
          mask.SetOnRatio((int)(numPts/50));
          mask.SetMaximumNumberOfPoints((int)50);
          mask.RandomModeOn();
          // Create labels for points - only show visible points[]
          visPts = new vtkSelectVisiblePoints();
          visPts.SetInputConnection((vtkAlgorithmOutput)mask.GetOutputPort());
          visPts.SetRenderer((vtkRenderer)ren1);
          ldm = new vtkLabeledDataMapper();
          ldm.SetInputConnection((vtkAlgorithmOutput)mask.GetOutputPort());
          //    ldm SetLabelFormat "%g"[]
          ldm.SetLabelModeToLabelScalars();
          tprop = ldm.GetLabelTextProperty();
          tprop.SetFontFamilyToArial();
          tprop.SetFontSize((int)10);
          tprop.SetColor((double)1,(double)0,(double)0);
          contourLabels = new vtkActor2D();
          contourLabels.SetMapper((vtkMapper2D)ldm);
          // Add the actors to the renderer, set the background and size[]
          //[]
          ren1.AddActor2D((vtkProp)isoActor);
          ren1.AddActor2D((vtkProp)contourLabels);
          ren1.SetBackground((double)1,(double)1,(double)1);
          renWin.SetSize((int)500,(int)500);
          renWin.Render();
          ren1.GetActiveCamera().Zoom((double)1.5);
          // render the image[]
          //[]
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
Ejemplo n.º 6
0
        private void SampleFunction()
        {
            vtkSphere sphere = vtkSphere.New();

            // Sample the function
            vtkSampleFunction sample = vtkSampleFunction.New();

            sample.SetSampleDimensions(50, 50, 50);
            sample.SetImplicitFunction(sphere);
            double value = 2.0;
            double xmin = -value, xmax = value, ymin = -value, ymax = value, zmin = -value, zmax = value;

            sample.SetModelBounds(xmin, xmax, ymin, ymax, zmin, zmax);

            // Create the 0 isosurface
            vtkContourFilter contours       = vtkContourFilter.New();

#if VTK_MAJOR_VERSION_5
            contours.SetInputConnection(sample.GetOutputPort());
#else
            contours.SetInputData(sample);
#endif
            contours.GenerateValues(1, 1, 1);

            // Map the contours to graphical primitives
            vtkPolyDataMapper contourMapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            contourMapper.SetInputConnection(contours.GetOutputPort());
#else
            contourMapper.SetInputData(contours);
#endif
            contourMapper.SetScalarRange(0.0, 1.2);

            // Create an actor for the contours
            vtkActor contourActor           = vtkActor.New();
            contourActor.SetMapper(contourMapper);

            // -- create a box around the function to indicate the sampling volume --

            // Create outline
            vtkOutlineFilter outline = vtkOutlineFilter.New();
#if VTK_MAJOR_VERSION_5
            outline.SetInputConnection(sample.GetOutputPort());
#else
            outline.SetInputData(sample);
#endif

            // Map it to graphics primitives
            vtkPolyDataMapper outlineMapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            outlineMapper.SetInputConnection(outline.GetOutputPort());
#else
            outlineMapper.SetInputData(outline);
#endif

            // Create an actor for it
            vtkActor outlineActor = vtkActor.New();

            outlineActor.SetMapper(outlineMapper);
            outlineActor.GetProperty().SetColor(0, 0, 0);
            // 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.0, 1.0, 1.0);
            // add our actor to the renderer
            renderer.AddActor(contourActor);
            renderer.AddActor(outlineActor);
        }
Ejemplo n.º 7
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVgaussian(String [] argv)
    {
        //Prefix Content is: ""

          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          renWin.SetSize((int)300,(int)300);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          camera = new vtkCamera();
          camera.ParallelProjectionOn();
          camera.SetViewUp((double)0,(double)1,(double)0);
          camera.SetFocalPoint((double)12,(double)10.5,(double)15);
          camera.SetPosition((double)-70,(double)15,(double)34);
          camera.ComputeViewPlaneNormal();
          ren1.SetActiveCamera((vtkCamera)camera);
          // Create the reader for the data[]
          //vtkStructuredPointsReader reader[]
          reader = new vtkGaussianCubeReader();
          reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/m4_TotalDensity.cube");
          reader.SetHBScale((double)1.1);
          reader.SetBScale((double)10);
          reader.Update();
          range = reader.GetGridOutput().GetPointData().GetScalars().GetRange();
          min = (double)(lindex(range,0));
          max = (double)(lindex(range,1));
          readerSS = new vtkImageShiftScale();
          readerSS.SetInput((vtkDataObject)reader.GetGridOutput());
          readerSS.SetShift((double)min*-1);
          readerSS.SetScale((double)255/(max-min));
          readerSS.SetOutputScalarTypeToUnsignedChar();
          bounds = new vtkOutlineFilter();
          bounds.SetInput((vtkDataObject)reader.GetGridOutput());
          boundsMapper = vtkPolyDataMapper.New();
          boundsMapper.SetInputConnection((vtkAlgorithmOutput)bounds.GetOutputPort());
          boundsActor = new vtkActor();
          boundsActor.SetMapper((vtkMapper)boundsMapper);
          boundsActor.GetProperty().SetColor((double)0,(double)0,(double)0);
          contour = new vtkContourFilter();
          contour.SetInput((vtkDataObject)reader.GetGridOutput());
          contour.GenerateValues((int)5,(double)0,(double).05);
          contourMapper = vtkPolyDataMapper.New();
          contourMapper.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort());
          contourMapper.SetScalarRange((double)0,(double).1);
          ((vtkLookupTable)contourMapper.GetLookupTable()).SetHueRange(0.32,0);
          contourActor = new vtkActor();
          contourActor.SetMapper((vtkMapper)contourMapper);
          contourActor.GetProperty().SetOpacity((double).5);
          // Create transfer mapping scalar value to opacity[]
          opacityTransferFunction = new vtkPiecewiseFunction();
          opacityTransferFunction.AddPoint((double)0,(double)0.01);
          opacityTransferFunction.AddPoint((double)255,(double)0.35);
          opacityTransferFunction.ClampingOn();
          // Create transfer mapping scalar value to color[]
          colorTransferFunction = new vtkColorTransferFunction();
          colorTransferFunction.AddHSVPoint((double)0.0,(double)0.66,(double)1.0,(double)1.0);
          colorTransferFunction.AddHSVPoint((double)50.0,(double)0.33,(double)1.0,(double)1.0);
          colorTransferFunction.AddHSVPoint((double)100.0,(double)0.00,(double)1.0,(double)1.0);
          // The property describes how the data will look[]
          volumeProperty = new vtkVolumeProperty();
          volumeProperty.SetColor((vtkColorTransferFunction)colorTransferFunction);
          volumeProperty.SetScalarOpacity((vtkPiecewiseFunction)opacityTransferFunction);
          volumeProperty.SetInterpolationTypeToLinear();
          // The mapper / ray cast function know how to render the data[]
          compositeFunction = new vtkVolumeRayCastCompositeFunction();
          volumeMapper = new vtkVolumeRayCastMapper();
          //vtkVolumeTextureMapper2D volumeMapper[]
          volumeMapper.SetVolumeRayCastFunction((vtkVolumeRayCastFunction)compositeFunction);
          volumeMapper.SetInputConnection((vtkAlgorithmOutput)readerSS.GetOutputPort());
          // The volume holds the mapper and the property and[]
          // can be used to position/orient the volume[]
          volume = new vtkVolume();
          volume.SetMapper((vtkAbstractVolumeMapper)volumeMapper);
          volume.SetProperty((vtkVolumeProperty)volumeProperty);
          ren1.AddVolume((vtkProp)volume);
          //ren1 AddActor contourActor[]
          ren1.AddActor((vtkProp)boundsActor);
          //#####################################################################[]
          Sphere = new vtkSphereSource();
          Sphere.SetCenter((double)0,(double)0,(double)0);
          Sphere.SetRadius((double)1);
          Sphere.SetThetaResolution((int)16);
          Sphere.SetStartTheta((double)0);
          Sphere.SetEndTheta((double)360);
          Sphere.SetPhiResolution((int)16);
          Sphere.SetStartPhi((double)0);
          Sphere.SetEndPhi((double)180);
          Glyph = new vtkGlyph3D();
          Glyph.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
          Glyph.SetOrient((int)1);
          Glyph.SetColorMode((int)1);
          //Glyph ScalingOn[]
          Glyph.SetScaleMode((int)2);
          Glyph.SetScaleFactor((double).6);
          Glyph.SetSource((vtkPolyData)Sphere.GetOutput());
          AtomsMapper = vtkPolyDataMapper.New();
          AtomsMapper.SetInputConnection((vtkAlgorithmOutput)Glyph.GetOutputPort());
          AtomsMapper.SetImmediateModeRendering((int)1);
          AtomsMapper.UseLookupTableScalarRangeOff();
          AtomsMapper.SetScalarVisibility((int)1);
          AtomsMapper.SetScalarModeToDefault();
          Atoms = new vtkActor();
          Atoms.SetMapper((vtkMapper)AtomsMapper);
          Atoms.GetProperty().SetRepresentationToSurface();
          Atoms.GetProperty().SetInterpolationToGouraud();
          Atoms.GetProperty().SetAmbient((double)0.15);
          Atoms.GetProperty().SetDiffuse((double)0.85);
          Atoms.GetProperty().SetSpecular((double)0.1);
          Atoms.GetProperty().SetSpecularPower((double)100);
          Atoms.GetProperty().SetSpecularColor((double)1,(double)1,(double)1);
          Atoms.GetProperty().SetColor((double)1,(double)1,(double)1);
          Tube = new vtkTubeFilter();
          Tube.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
          Tube.SetNumberOfSides((int)16);
          Tube.SetCapping((int)0);
          Tube.SetRadius((double)0.2);
          Tube.SetVaryRadius((int)0);
          Tube.SetRadiusFactor((double)10);
          BondsMapper = vtkPolyDataMapper.New();
          BondsMapper.SetInputConnection((vtkAlgorithmOutput)Tube.GetOutputPort());
          BondsMapper.SetImmediateModeRendering((int)1);
          BondsMapper.UseLookupTableScalarRangeOff();
          BondsMapper.SetScalarVisibility((int)1);
          BondsMapper.SetScalarModeToDefault();
          Bonds = new vtkActor();
          Bonds.SetMapper((vtkMapper)BondsMapper);
          Bonds.GetProperty().SetRepresentationToSurface();
          Bonds.GetProperty().SetInterpolationToGouraud();
          Bonds.GetProperty().SetAmbient((double)0.15);
          Bonds.GetProperty().SetDiffuse((double)0.85);
          Bonds.GetProperty().SetSpecular((double)0.1);
          Bonds.GetProperty().SetSpecularPower((double)100);
          Bonds.GetProperty().SetSpecularColor((double)1,(double)1,(double)1);
          Bonds.GetProperty().SetColor((double)1,(double)1,(double)1);
          ren1.AddActor((vtkProp)Bonds);
          ren1.AddActor((vtkProp)Atoms);
          //###################################################[]
          ren1.SetBackground((double)1,(double)1,(double)1);
          ren1.ResetCamera();
          renWin.Render();
          //method moved

          renWin.AbortCheckEvt += new Kitware.VTK.vtkObject.vtkObjectEventHandler(TkCheckAbort_Command.Execute);
          iren.Initialize();

        //deleteAllVTKObjects();
    }
Ejemplo n.º 8
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVprobeComb(String [] argv)
    {
        //Prefix Content is: ""

        // create planes[]
        // Create the RenderWindow, Renderer and both Actors[]
        //[]
        ren1   = vtkRenderer.New();
        renWin = vtkRenderWindow.New();
        renWin.SetMultiSamples(0);
        renWin.AddRenderer((vtkRenderer)ren1);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        // create pipeline[]
        //[]
        pl3d = new vtkMultiBlockPLOT3DReader();
        pl3d.SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin");
        pl3d.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin");
        pl3d.SetScalarFunctionNumber((int)100);
        pl3d.SetVectorFunctionNumber((int)202);
        pl3d.Update();
        plane = new vtkPlaneSource();
        plane.SetResolution((int)50, (int)50);
        transP1 = new vtkTransform();
        transP1.Translate((double)3.7, (double)0.0, (double)28.37);
        transP1.Scale((double)5, (double)5, (double)5);
        transP1.RotateY((double)90);
        tpd1 = new vtkTransformPolyDataFilter();
        tpd1.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort());
        tpd1.SetTransform((vtkAbstractTransform)transP1);
        outTpd1 = new vtkOutlineFilter();
        outTpd1.SetInputConnection((vtkAlgorithmOutput)tpd1.GetOutputPort());
        mapTpd1 = vtkPolyDataMapper.New();
        mapTpd1.SetInputConnection((vtkAlgorithmOutput)outTpd1.GetOutputPort());
        tpd1Actor = new vtkActor();
        tpd1Actor.SetMapper((vtkMapper)mapTpd1);
        tpd1Actor.GetProperty().SetColor((double)0, (double)0, (double)0);
        transP2 = new vtkTransform();
        transP2.Translate((double)9.2, (double)0.0, (double)31.20);
        transP2.Scale((double)5, (double)5, (double)5);
        transP2.RotateY((double)90);
        tpd2 = new vtkTransformPolyDataFilter();
        tpd2.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort());
        tpd2.SetTransform((vtkAbstractTransform)transP2);
        outTpd2 = new vtkOutlineFilter();
        outTpd2.SetInputConnection((vtkAlgorithmOutput)tpd2.GetOutputPort());
        mapTpd2 = vtkPolyDataMapper.New();
        mapTpd2.SetInputConnection((vtkAlgorithmOutput)outTpd2.GetOutputPort());
        tpd2Actor = new vtkActor();
        tpd2Actor.SetMapper((vtkMapper)mapTpd2);
        tpd2Actor.GetProperty().SetColor((double)0, (double)0, (double)0);
        transP3 = new vtkTransform();
        transP3.Translate((double)13.27, (double)0.0, (double)33.30);
        transP3.Scale((double)5, (double)5, (double)5);
        transP3.RotateY((double)90);
        tpd3 = new vtkTransformPolyDataFilter();
        tpd3.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort());
        tpd3.SetTransform((vtkAbstractTransform)transP3);
        outTpd3 = new vtkOutlineFilter();
        outTpd3.SetInputConnection((vtkAlgorithmOutput)tpd3.GetOutputPort());
        mapTpd3 = vtkPolyDataMapper.New();
        mapTpd3.SetInputConnection((vtkAlgorithmOutput)outTpd3.GetOutputPort());
        tpd3Actor = new vtkActor();
        tpd3Actor.SetMapper((vtkMapper)mapTpd3);
        tpd3Actor.GetProperty().SetColor((double)0, (double)0, (double)0);
        appendF = new vtkAppendPolyData();
        appendF.AddInputConnection(tpd1.GetOutputPort());
        appendF.AddInputConnection(tpd2.GetOutputPort());
        appendF.AddInputConnection(tpd3.GetOutputPort());
        probe = new vtkProbeFilter();
        probe.SetInputConnection((vtkAlgorithmOutput)appendF.GetOutputPort());
        probe.SetSourceData((vtkDataSet)pl3d.GetOutput().GetBlock(0));
        contour = new vtkContourFilter();
        contour.SetInputConnection((vtkAlgorithmOutput)probe.GetOutputPort());
        contour.GenerateValues((int)50, (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0],
                               (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]);
        contourMapper = vtkPolyDataMapper.New();
        contourMapper.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort());
        contourMapper.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[0],
                                     (double)((vtkDataSet)pl3d.GetOutput().GetBlock(0)).GetScalarRange()[1]);
        planeActor = new vtkActor();
        planeActor.SetMapper((vtkMapper)contourMapper);
        outline = new vtkStructuredGridOutlineFilter();
        outline.SetInputData((vtkDataSet)pl3d.GetOutput().GetBlock(0));
        outlineMapper = vtkPolyDataMapper.New();
        outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
        outlineActor = new vtkActor();
        outlineActor.SetMapper((vtkMapper)outlineMapper);
        outlineActor.GetProperty().SetColor((double)0, (double)0, (double)0);
        ren1.AddActor((vtkProp)outlineActor);
        ren1.AddActor((vtkProp)planeActor);
        ren1.AddActor((vtkProp)tpd1Actor);
        ren1.AddActor((vtkProp)tpd2Actor);
        ren1.AddActor((vtkProp)tpd3Actor);
        ren1.SetBackground((double)1, (double)1, (double)1);
        renWin.SetSize((int)400, (int)400);
        cam1 = ren1.GetActiveCamera();
        cam1.SetClippingRange((double)3.95297, (double)50);
        cam1.SetFocalPoint((double)8.88908, (double)0.595038, (double)29.3342);
        cam1.SetPosition((double)-12.3332, (double)31.7479, (double)41.2387);
        cam1.SetViewUp((double)0.060772, (double)-0.319905, (double)0.945498);
        iren.Initialize();
        // prevent the tk window from showing up then start the event loop[]

//deleteAllVTKObjects();
    }
Ejemplo n.º 9
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVlabeledContours(String [] argv)
    {
        //Prefix Content is: ""

        // demonstrate labeling of contour with scalar value[]
        // Create the RenderWindow, Renderer and both Actors[]
        //[]
        ren1   = vtkRenderer.New();
        renWin = vtkRenderWindow.New();
        renWin.SetMultiSamples(0);
        renWin.AddRenderer((vtkRenderer)ren1);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        // Read a slice and contour it[]
        v16 = new vtkVolume16Reader();
        v16.SetDataDimensions((int)64, (int)64);
        v16.GetOutput().SetOrigin((double)0.0, (double)0.0, (double)0.0);
        v16.SetDataByteOrderToLittleEndian();
        v16.SetFilePrefix((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/headsq/quarter");
        v16.SetImageRange((int)45, (int)45);
        v16.SetDataSpacing((double)3.2, (double)3.2, (double)1.5);
        iso = new vtkContourFilter();
        iso.SetInputConnection((vtkAlgorithmOutput)v16.GetOutputPort());
        iso.GenerateValues((int)6, (double)500, (double)1150);
        iso.Update();
        numPts    = iso.GetOutput().GetNumberOfPoints();
        isoMapper = vtkPolyDataMapper.New();
        isoMapper.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort());
        isoMapper.ScalarVisibilityOn();
        isoMapper.SetScalarRange((double)((vtkDataSet)iso.GetOutput()).GetScalarRange()[0], (double)((vtkDataSet)iso.GetOutput()).GetScalarRange()[1]);
        isoActor = new vtkActor();
        isoActor.SetMapper((vtkMapper)isoMapper);
        // Subsample the points and label them[]
        mask = new vtkMaskPoints();
        mask.SetInputConnection((vtkAlgorithmOutput)iso.GetOutputPort());
        mask.SetOnRatio((int)(numPts / 50));
        mask.SetMaximumNumberOfPoints((int)50);
        mask.RandomModeOn();
        // Create labels for points - only show visible points[]
        visPts = new vtkSelectVisiblePoints();
        visPts.SetInputConnection((vtkAlgorithmOutput)mask.GetOutputPort());
        visPts.SetRenderer((vtkRenderer)ren1);
        ldm = new vtkLabeledDataMapper();
        ldm.SetInputConnection((vtkAlgorithmOutput)mask.GetOutputPort());
        //    ldm SetLabelFormat "%g"[]
        ldm.SetLabelModeToLabelScalars();
        tprop = ldm.GetLabelTextProperty();
        tprop.SetFontFamilyToArial();
        tprop.SetFontSize((int)10);
        tprop.SetColor((double)1, (double)0, (double)0);
        contourLabels = new vtkActor2D();
        contourLabels.SetMapper((vtkMapper2D)ldm);
        // Add the actors to the renderer, set the background and size[]
        //[]
        ren1.AddActor2D((vtkProp)isoActor);
        ren1.AddActor2D((vtkProp)contourLabels);
        ren1.SetBackground((double)1, (double)1, (double)1);
        renWin.SetSize((int)500, (int)500);
        renWin.Render();
        ren1.GetActiveCamera().Zoom((double)1.5);
        // render the image[]
        //[]
        // prevent the tk window from showing up then start the event loop[]

//deleteAllVTKObjects();
    }
Ejemplo n.º 10
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVgaussian(String [] argv)
    {
        //Prefix Content is: ""

        ren1   = vtkRenderer.New();
        renWin = vtkRenderWindow.New();
        renWin.SetMultiSamples(0);
        renWin.AddRenderer((vtkRenderer)ren1);
        renWin.SetSize((int)300, (int)300);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        camera = new vtkCamera();
        camera.ParallelProjectionOn();
        camera.SetViewUp((double)0, (double)1, (double)0);
        camera.SetFocalPoint((double)12, (double)10.5, (double)15);
        camera.SetPosition((double)-70, (double)15, (double)34);
        camera.ComputeViewPlaneNormal();
        ren1.SetActiveCamera((vtkCamera)camera);
        // Create the reader for the data[]
        //vtkStructuredPointsReader reader[]
        reader = new vtkGaussianCubeReader();
        reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/m4_TotalDensity.cube");
        reader.SetHBScale((double)1.1);
        reader.SetBScale((double)10);
        reader.Update();
        range    = reader.GetGridOutput().GetPointData().GetScalars().GetRange();
        min      = (double)(lindex(range, 0));
        max      = (double)(lindex(range, 1));
        readerSS = new vtkImageShiftScale();
        readerSS.SetInputData((vtkDataObject)reader.GetGridOutput());
        readerSS.SetShift((double)min * -1);
        readerSS.SetScale((double)255 / (max - min));
        readerSS.SetOutputScalarTypeToUnsignedChar();
        bounds = new vtkOutlineFilter();
        bounds.SetInputData((vtkDataObject)reader.GetGridOutput());
        boundsMapper = vtkPolyDataMapper.New();
        boundsMapper.SetInputConnection((vtkAlgorithmOutput)bounds.GetOutputPort());
        boundsActor = new vtkActor();
        boundsActor.SetMapper((vtkMapper)boundsMapper);
        boundsActor.GetProperty().SetColor((double)0, (double)0, (double)0);
        contour = new vtkContourFilter();
        contour.SetInputData((vtkDataObject)reader.GetGridOutput());
        contour.GenerateValues((int)5, (double)0, (double).05);
        contourMapper = vtkPolyDataMapper.New();
        contourMapper.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort());
        contourMapper.SetScalarRange((double)0, (double).1);
        ((vtkLookupTable)contourMapper.GetLookupTable()).SetHueRange(0.32, 0);
        contourActor = new vtkActor();
        contourActor.SetMapper((vtkMapper)contourMapper);
        contourActor.GetProperty().SetOpacity((double).5);
        // Create transfer mapping scalar value to opacity[]
        opacityTransferFunction = new vtkPiecewiseFunction();
        opacityTransferFunction.AddPoint((double)0, (double)0.01);
        opacityTransferFunction.AddPoint((double)255, (double)0.35);
        opacityTransferFunction.ClampingOn();
        // Create transfer mapping scalar value to color[]
        colorTransferFunction = new vtkColorTransferFunction();
        colorTransferFunction.AddHSVPoint((double)0.0, (double)0.66, (double)1.0, (double)1.0);
        colorTransferFunction.AddHSVPoint((double)50.0, (double)0.33, (double)1.0, (double)1.0);
        colorTransferFunction.AddHSVPoint((double)100.0, (double)0.00, (double)1.0, (double)1.0);
        // The property describes how the data will look[]
        volumeProperty = new vtkVolumeProperty();
        volumeProperty.SetColor((vtkColorTransferFunction)colorTransferFunction);
        volumeProperty.SetScalarOpacity((vtkPiecewiseFunction)opacityTransferFunction);
        volumeProperty.SetInterpolationTypeToLinear();
        // The mapper / ray cast function know how to render the data[]
        compositeFunction = new vtkVolumeRayCastCompositeFunction();
        volumeMapper      = new vtkVolumeRayCastMapper();
        //vtkVolumeTextureMapper2D volumeMapper[]
        volumeMapper.SetVolumeRayCastFunction((vtkVolumeRayCastFunction)compositeFunction);
        volumeMapper.SetInputConnection((vtkAlgorithmOutput)readerSS.GetOutputPort());
        // The volume holds the mapper and the property and[]
        // can be used to position/orient the volume[]
        volume = new vtkVolume();
        volume.SetMapper((vtkAbstractVolumeMapper)volumeMapper);
        volume.SetProperty((vtkVolumeProperty)volumeProperty);
        ren1.AddVolume((vtkProp)volume);
        //ren1 AddActor contourActor[]
        ren1.AddActor((vtkProp)boundsActor);
        //#####################################################################[]
        Sphere = new vtkSphereSource();
        Sphere.SetCenter((double)0, (double)0, (double)0);
        Sphere.SetRadius((double)1);
        Sphere.SetThetaResolution((int)16);
        Sphere.SetStartTheta((double)0);
        Sphere.SetEndTheta((double)360);
        Sphere.SetPhiResolution((int)16);
        Sphere.SetStartPhi((double)0);
        Sphere.SetEndPhi((double)180);
        Glyph = new vtkGlyph3D();
        Glyph.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
        Glyph.SetOrient((int)1);
        Glyph.SetColorMode((int)1);
        //Glyph ScalingOn[]
        Glyph.SetScaleMode((int)2);
        Glyph.SetScaleFactor((double).6);
        Glyph.SetSourceConnection(Sphere.GetOutputPort());
        AtomsMapper = vtkPolyDataMapper.New();
        AtomsMapper.SetInputConnection((vtkAlgorithmOutput)Glyph.GetOutputPort());
        AtomsMapper.SetImmediateModeRendering((int)1);
        AtomsMapper.UseLookupTableScalarRangeOff();
        AtomsMapper.SetScalarVisibility((int)1);
        AtomsMapper.SetScalarModeToDefault();
        Atoms = new vtkActor();
        Atoms.SetMapper((vtkMapper)AtomsMapper);
        Atoms.GetProperty().SetRepresentationToSurface();
        Atoms.GetProperty().SetInterpolationToGouraud();
        Atoms.GetProperty().SetAmbient((double)0.15);
        Atoms.GetProperty().SetDiffuse((double)0.85);
        Atoms.GetProperty().SetSpecular((double)0.1);
        Atoms.GetProperty().SetSpecularPower((double)100);
        Atoms.GetProperty().SetSpecularColor((double)1, (double)1, (double)1);
        Atoms.GetProperty().SetColor((double)1, (double)1, (double)1);
        Tube = new vtkTubeFilter();
        Tube.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
        Tube.SetNumberOfSides((int)16);
        Tube.SetCapping((int)0);
        Tube.SetRadius((double)0.2);
        Tube.SetVaryRadius((int)0);
        Tube.SetRadiusFactor((double)10);
        BondsMapper = vtkPolyDataMapper.New();
        BondsMapper.SetInputConnection((vtkAlgorithmOutput)Tube.GetOutputPort());
        BondsMapper.SetImmediateModeRendering((int)1);
        BondsMapper.UseLookupTableScalarRangeOff();
        BondsMapper.SetScalarVisibility((int)1);
        BondsMapper.SetScalarModeToDefault();
        Bonds = new vtkActor();
        Bonds.SetMapper((vtkMapper)BondsMapper);
        Bonds.GetProperty().SetRepresentationToSurface();
        Bonds.GetProperty().SetInterpolationToGouraud();
        Bonds.GetProperty().SetAmbient((double)0.15);
        Bonds.GetProperty().SetDiffuse((double)0.85);
        Bonds.GetProperty().SetSpecular((double)0.1);
        Bonds.GetProperty().SetSpecularPower((double)100);
        Bonds.GetProperty().SetSpecularColor((double)1, (double)1, (double)1);
        Bonds.GetProperty().SetColor((double)1, (double)1, (double)1);
        ren1.AddActor((vtkProp)Bonds);
        ren1.AddActor((vtkProp)Atoms);
        //###################################################[]
        ren1.SetBackground((double)1, (double)1, (double)1);
        ren1.ResetCamera();
        renWin.Render();
        //method moved

        renWin.AbortCheckEvt += new Kitware.VTK.vtkObject.vtkObjectEventHandler(TkCheckAbort_Command.Execute);
        iren.Initialize();

//deleteAllVTKObjects();
    }
Ejemplo n.º 11
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVprobeComb(String [] argv)
    {
        //Prefix Content is: ""

          // create planes[]
          // Create the RenderWindow, Renderer and both Actors[]
          //[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          // create pipeline[]
          //[]
          pl3d = new vtkPLOT3DReader();
          pl3d.SetXYZFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin");
          pl3d.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin");
          pl3d.SetScalarFunctionNumber((int)100);
          pl3d.SetVectorFunctionNumber((int)202);
          pl3d.Update();
          plane = new vtkPlaneSource();
          plane.SetResolution((int)50,(int)50);
          transP1 = new vtkTransform();
          transP1.Translate((double)3.7,(double)0.0,(double)28.37);
          transP1.Scale((double)5,(double)5,(double)5);
          transP1.RotateY((double)90);
          tpd1 = new vtkTransformPolyDataFilter();
          tpd1.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort());
          tpd1.SetTransform((vtkAbstractTransform)transP1);
          outTpd1 = new vtkOutlineFilter();
          outTpd1.SetInputConnection((vtkAlgorithmOutput)tpd1.GetOutputPort());
          mapTpd1 = vtkPolyDataMapper.New();
          mapTpd1.SetInputConnection((vtkAlgorithmOutput)outTpd1.GetOutputPort());
          tpd1Actor = new vtkActor();
          tpd1Actor.SetMapper((vtkMapper)mapTpd1);
          tpd1Actor.GetProperty().SetColor((double)0,(double)0,(double)0);
          transP2 = new vtkTransform();
          transP2.Translate((double)9.2,(double)0.0,(double)31.20);
          transP2.Scale((double)5,(double)5,(double)5);
          transP2.RotateY((double)90);
          tpd2 = new vtkTransformPolyDataFilter();
          tpd2.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort());
          tpd2.SetTransform((vtkAbstractTransform)transP2);
          outTpd2 = new vtkOutlineFilter();
          outTpd2.SetInputConnection((vtkAlgorithmOutput)tpd2.GetOutputPort());
          mapTpd2 = vtkPolyDataMapper.New();
          mapTpd2.SetInputConnection((vtkAlgorithmOutput)outTpd2.GetOutputPort());
          tpd2Actor = new vtkActor();
          tpd2Actor.SetMapper((vtkMapper)mapTpd2);
          tpd2Actor.GetProperty().SetColor((double)0,(double)0,(double)0);
          transP3 = new vtkTransform();
          transP3.Translate((double)13.27,(double)0.0,(double)33.30);
          transP3.Scale((double)5,(double)5,(double)5);
          transP3.RotateY((double)90);
          tpd3 = new vtkTransformPolyDataFilter();
          tpd3.SetInputConnection((vtkAlgorithmOutput)plane.GetOutputPort());
          tpd3.SetTransform((vtkAbstractTransform)transP3);
          outTpd3 = new vtkOutlineFilter();
          outTpd3.SetInputConnection((vtkAlgorithmOutput)tpd3.GetOutputPort());
          mapTpd3 = vtkPolyDataMapper.New();
          mapTpd3.SetInputConnection((vtkAlgorithmOutput)outTpd3.GetOutputPort());
          tpd3Actor = new vtkActor();
          tpd3Actor.SetMapper((vtkMapper)mapTpd3);
          tpd3Actor.GetProperty().SetColor((double)0,(double)0,(double)0);
          appendF = new vtkAppendPolyData();
          appendF.AddInput((vtkPolyData)tpd1.GetOutput());
          appendF.AddInput((vtkPolyData)tpd2.GetOutput());
          appendF.AddInput((vtkPolyData)tpd3.GetOutput());
          probe = new vtkProbeFilter();
          probe.SetInputConnection((vtkAlgorithmOutput)appendF.GetOutputPort());
          probe.SetSource((vtkDataObject)pl3d.GetOutput());
          contour = new vtkContourFilter();
          contour.SetInputConnection((vtkAlgorithmOutput)probe.GetOutputPort());
          contour.GenerateValues((int)50,(double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[0],
          (double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[1]);
          contourMapper = vtkPolyDataMapper.New();
          contourMapper.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort());
          contourMapper.SetScalarRange((double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[0],
          (double)((vtkDataSet)pl3d.GetOutput()).GetScalarRange()[1]);
          planeActor = new vtkActor();
          planeActor.SetMapper((vtkMapper)contourMapper);
          outline = new vtkStructuredGridOutlineFilter();
          outline.SetInputConnection((vtkAlgorithmOutput)pl3d.GetOutputPort());
          outlineMapper = vtkPolyDataMapper.New();
          outlineMapper.SetInputConnection((vtkAlgorithmOutput)outline.GetOutputPort());
          outlineActor = new vtkActor();
          outlineActor.SetMapper((vtkMapper)outlineMapper);
          outlineActor.GetProperty().SetColor((double)0,(double)0,(double)0);
          ren1.AddActor((vtkProp)outlineActor);
          ren1.AddActor((vtkProp)planeActor);
          ren1.AddActor((vtkProp)tpd1Actor);
          ren1.AddActor((vtkProp)tpd2Actor);
          ren1.AddActor((vtkProp)tpd3Actor);
          ren1.SetBackground((double)1,(double)1,(double)1);
          renWin.SetSize((int)400,(int)400);
          cam1 = ren1.GetActiveCamera();
          cam1.SetClippingRange((double)3.95297,(double)50);
          cam1.SetFocalPoint((double)8.88908,(double)0.595038,(double)29.3342);
          cam1.SetPosition((double)-12.3332,(double)31.7479,(double)41.2387);
          cam1.SetViewUp((double)0.060772,(double)-0.319905,(double)0.945498);
          iren.Initialize();
          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
Ejemplo n.º 12
0
        private void FilledContours(string filePath, int numberOfContours)
        {
            // Read the file
            vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New();

            reader.SetFileName(filePath);
            reader.Update(); // Update so that we can get the scalar range

            double[] scalarRange = reader.GetOutput().GetPointData().GetScalars().GetRange();

            vtkAppendPolyData appendFilledContours = vtkAppendPolyData.New();

            double delta = (scalarRange[1] - scalarRange[0]) / (numberOfContours - 1);

            // Keep the clippers alive
            List <vtkClipPolyData> clippersLo = new List <vtkClipPolyData>();
            List <vtkClipPolyData> clippersHi = new List <vtkClipPolyData>();

            for (int i = 0; i < numberOfContours; i++)
            {
                double valueLo = scalarRange[0] + i * delta;
                double valueHi = scalarRange[0] + (i + 1) * delta;

                clippersLo.Add(vtkClipPolyData.New());
                clippersLo[i].SetValue(valueLo);
                if (i == 0)
                {
                    clippersLo[i].SetInputConnection(reader.GetOutputPort());
                }
                else
                {
                    clippersLo[i].SetInputConnection(clippersHi[i - 1].GetOutputPort(1));
                }
                clippersLo[i].InsideOutOff();
                clippersLo[i].Update();

                clippersHi.Add(vtkClipPolyData.New());
                clippersHi[i].SetValue(valueHi);
                clippersHi[i].SetInputConnection(clippersLo[i].GetOutputPort());
                clippersHi[i].GenerateClippedOutputOn();
                clippersHi[i].InsideOutOn();
                clippersHi[i].Update();
                if (clippersHi[i].GetOutput().GetNumberOfCells() == 0)
                {
                    continue;
                }

                vtkFloatArray cd = vtkFloatArray.New();
                cd.SetNumberOfComponents(1);
                cd.SetNumberOfTuples(clippersHi[i].GetOutput().GetNumberOfCells());
                cd.FillComponent(0, valueLo);

                clippersHi[i].GetOutput().GetCellData().SetScalars(cd);
                appendFilledContours.AddInputConnection(clippersHi[i].GetOutputPort());
            }

            vtkCleanPolyData filledContours = vtkCleanPolyData.New();

            filledContours.SetInputConnection(appendFilledContours.GetOutputPort());

            vtkLookupTable lut = vtkLookupTable.New();

            lut.SetNumberOfTableValues(numberOfContours + 1);
            lut.Build();
            vtkPolyDataMapper contourMapper = vtkPolyDataMapper.New();

            contourMapper.SetInputConnection(filledContours.GetOutputPort());
            contourMapper.SetScalarRange(scalarRange[0], scalarRange[1]);
            contourMapper.SetScalarModeToUseCellData();
            contourMapper.SetLookupTable(lut);

            vtkActor contourActor = vtkActor.New();

            contourActor.SetMapper(contourMapper);
            contourActor.GetProperty().SetInterpolationToFlat();

            vtkContourFilter contours = vtkContourFilter.New();

            contours.SetInputConnection(filledContours.GetOutputPort());
            contours.GenerateValues(numberOfContours, scalarRange[0], scalarRange[1]);

            vtkPolyDataMapper contourLineMapperer = vtkPolyDataMapper.New();

            contourLineMapperer.SetInputConnection(contours.GetOutputPort());
            contourLineMapperer.SetScalarRange(scalarRange[0], scalarRange[1]);
            contourLineMapperer.ScalarVisibilityOff();

            vtkActor contourLineActor = vtkActor.New();

            contourLineActor.SetMapper(contourLineMapperer);
            contourLineActor.GetProperty().SetLineWidth(2);

            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
            // renderer
            vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();

            // set background color
            renderer.SetBackground(.2, .3, .4);
            // add our actor to the renderer
            renderer.AddActor(contourActor);
            renderer.AddActor(contourLineActor);
        }
Ejemplo n.º 13
0
        private void DrawVisQuad()
        {
            //# This example demonstrates the use of the contour filter, and the use of
            //# the vtkSampleFunction to generate a volume of data samples from an
            //# implicit function.

            //# VTK supports implicit functions of the form f(x,y,z)=constant. These
            //# functions can represent things spheres, cones, etc. Here we use a
            //# general form for a quadric to create an elliptical data field.

            vtkQuadric quadricFunction = vtkQuadric.New();

            quadricFunction.SetCoefficients(0.5, 1, 0.2, 0, 0.1, 0, 0, 0.2, 0, 0);

            //# vtkSampleFunction samples an implicit function over the x-y-z range
            //# specified (here it defaults to -1,1 in the x,y,z directions).
            vtkSampleFunction sample = vtkSampleFunction.New();

            sample.SetSampleDimensions(30, 30, 30);
            sample.SetImplicitFunction(quadricFunction);

            //# Create five surfaces F(x,y,z) = constant between range specified. The
            //# GenerateValues() method creates n isocontour values between the range
            //# specified.
            vtkContourFilter contourFilter = vtkContourFilter.New();

            contourFilter.SetInputConnection(sample.GetOutputPort());
            contourFilter.GenerateValues(10, 0.0, 1.2);

            vtkPolyDataMapper contMapper = vtkPolyDataMapper.New();

            contMapper.SetInputConnection(contourFilter.GetOutputPort());
            contMapper.SetScalarRange(0.0, 1.2);

            vtkActor conActor = vtkActor.New();

            conActor.SetMapper(contMapper);

            //We'll put a simple outline around the data
            vtkOutlineFilter outline = vtkOutlineFilter.New();

            outline.SetInputConnection(sample.GetOutputPort());

            vtkPolyDataMapper outlineMapper = vtkPolyDataMapper.New();

            outlineMapper.SetInputConnection(outline.GetOutputPort());

            vtkActor outlineActor = vtkActor.New();

            outlineActor.SetMapper(outlineMapper);
            outlineActor.GetProperty().SetColor(0, 0, 0);

            //The usual rendering stuff
            vtkRenderer     ren    = vtkRenderer.New();
            vtkRenderWindow renWin = myRenderWindowControl.RenderWindow;

            //vtkRenderWindow renWin = vtkRenderWindow.New();
            renWin.AddRenderer(ren);
            //vtkRenderWindowInteractor iren = vtkRenderWindowInteractor.New();
            //iren.SetRenderWindow(renWin);

            ren.SetBackground(1, 1, 1);
            ren.AddActor(conActor);
            ren.AddActor(outlineActor);

            //iren.Initialize();
            //renWin.Render();
            //iren.Start();
        }