public static vtkLookupTable Create(LutPreset preset, double rangeMin, double rangeMax)
        {
            var lut = new vtkLookupTable();
            lut.SetTableRange(rangeMin, rangeMax);
            switch (preset)
            {
                case LutPreset.BlueRed:
                    lut.SetHueRange(0.66, 1.0);
                    lut.SetNumberOfColors(128);
                    break;
                case LutPreset.RedBlue:
                    lut.SetHueRange(1.0, 0.66);
                    lut.SetNumberOfColors(128);
                    //lut.SetNumberOfTableValues(2);
                    //lut.SetTableValue(0, 1.0, 0.0, 0.0, 1.0);
                    //lut.SetTableValue(1, 0.0, 0.0, 1.0, 1.0);
                    break;
                case LutPreset.Rainbow:
                    lut.SetHueRange(0.0, 0.66);
                    lut.SetNumberOfColors(256);
                    break;
            }
            lut.Build();

            return lut;
        }
Esempio n. 2
0
 protected DatasetUnit()
 {
     lookupTable = vtkLookupTable.New();
     lookupTable.SetNumberOfColors(100);
     lookupTable.SetHueRange(0.67, 0.0);
     lookupTable.Build();
     scalarBarActor.SetOrientationToHorizontal();
     scalarBarActor.SetLookupTable(lookupTable);
     scalarBarActor.SetTitle(fieldName);
     scalarBarActor.GetAnnotationTextProperty().SetColor(0, 0, 0);
     scalarBarActor.GetTitleTextProperty().SetColor(0, 0, 0);
     scalarBarActor.GetLabelTextProperty().SetColor(0, 0, 0);
     scalarBarActor.GetAnnotationTextProperty().SetFontSize(20);
     scalarBarActor.GetTitleTextProperty().SetFontSize(20);
     scalarBarActor.GetLabelTextProperty().SetFontSize(20);
     scalarBarActor.GetAnnotationTextProperty().SetFontFamilyToArial();
     scalarBarActor.GetTitleTextProperty().SetFontFamilyToArial();
     scalarBarActor.GetLabelTextProperty().SetFontFamilyToArial();
     scalarBarActor.GetAnnotationTextProperty().ItalicOff();
     scalarBarActor.GetTitleTextProperty().ItalicOff();
     scalarBarActor.GetLabelTextProperty().ItalicOff();
     scalarBarActor.GetAnnotationTextProperty().BoldOff();
     scalarBarActor.GetTitleTextProperty().BoldOff();
     scalarBarActor.GetLabelTextProperty().BoldOff();
     scalarBarActor.SetUnconstrainedFontSize(true);
     scalarBarActor.SetBarRatio(0.15);
     scalarBarActor.SetNumberOfLabels(11);
 }
Esempio n. 3
0
        public VTKPoint(int w, int h, int d)
        {
            width  = w;
            height = h;
            depth  = h;
            data   = new int[w * h];
            pIds   = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * data.Length);

            //lut
            lut.SetHueRange(0.667, 0.0);
            lut.Build();

            //セルの生成
            using (var points = vtkPoints.New())
                using (var vertices = vtkCellArray.New())
                {
                    int[] ids = new int[w * h];
                    for (int y = 0; y < h; y++)
                    {
                        for (int x = 0; x < w; x++)
                        {
                            ids[x + w * y] = points.InsertNextPoint(x, -y, 0);
                        }
                    }
                    int    size = Marshal.SizeOf(typeof(int)) * w * h;
                    IntPtr pIds = Marshal.AllocHGlobal(size);
                    Marshal.Copy(ids, 0, pIds, w * h);
                    vertices.InsertNextCell(w * h, pIds);
                    Marshal.FreeHGlobal(pIds);

                    pointPoly.SetPoints(points);
                    pointPoly.SetVerts(vertices);
                }
        }
        //切片模式_初始化颜色
        private void InitializeColor_Slice(ExGrid Grid)
        {
            m_LookupTable = vtkLookupTable.New();
            m_LookupTable.SetTableRange(Grid.Min, Grid.Max);
            //蓝色->红色
            m_LookupTable.SetHueRange(0.667, 0);
            m_LookupTable.SetNumberOfColors(100);
            m_LookupTable.Build();

            //线性插值透明度
            m_PiecewiseFunction = vtkPiecewiseFunction.New();
            m_PiecewiseFunction.AddPoint(Grid.Min, 1);
            m_PiecewiseFunction.AddPoint(Grid.Max, 1);
        }
Esempio n. 5
0
        public void Init()
        {
            lut.SetHueRange(0.0, 0.667); /* 赤-> 青*/
            lut.Build();

            switch (plane)
            {
            case Plane.Curve:
                InitCurve();
                break;

            case Plane.Flat:
                InitFlat();
                break;
            }
        }
        //wizualizacja 3d -----------------------------------------------------------------
        public Visualization3D(RenderWindowControl window, vtkDICOMImageReader dicomReader)
        {
            this.window       = window;
            this.dicomReader  = dicomReader;
            this.presetMapper = new PresetMapper();

            vtkRenderer renderer = window.RenderWindow.GetRenderers().GetFirstRenderer();

            vtkSmartVolumeMapper mapper = vtkSmartVolumeMapper.New();

            vol = vtkVolume.New();

            vtkLookupTable bwLut = vtkLookupTable.New();

            bwLut.SetTableRange(0, 2000);
            bwLut.SetSaturationRange(0, 0);
            bwLut.SetHueRange(0, 0);
            bwLut.SetValueRange(0, 1);
            bwLut.Build(); //effective built

            vtkImageMapToColors sagittalColors = vtkImageMapToColors.New();

            sagittalColors.SetInputConnection(dicomReader.GetOutputPort());
            sagittalColors.SetLookupTable(bwLut);
            sagittalColors.Update();
            vtkImageActor sagittal = vtkImageActor.New();

            sagittal.SetInput(sagittalColors.GetOutput());
            sagittal.SetDisplayExtent(117, 117, 0, 173, 1, 180);

            vtkImageReslice reslicer = vtkImageReslice.New();

            reslicer.SetResliceAxesDirectionCosines(1, 0, 0, 2, 0, 0, 0, 0, 0);

            mapper.SetInputConnection(dicomReader.GetOutputPort());

            this.setColorFunction();
            this.setOpacityFunction();
            this.setGradientOpacity();

            vol.SetMapper(mapper);

            renderer.AddActor(sagittal);
            renderer.AddVolume(vol);
        }
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestImageStreamer(String [] argv)
    {
        //Prefix Content is: ""

        reader = new vtkImageReader();
        reader.ReleaseDataFlagOff();
        reader.SetDataByteOrderToLittleEndian();
        reader.SetDataExtent((int)0, (int)63, (int)0, (int)63, (int)1, (int)93);
        reader.SetFilePrefix((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/headsq/quarter");
        reader.SetDataMask((int)0x7fff);
        rangeStart = 0.0;
        rangeEnd   = 0.2;
        LUT        = new vtkLookupTable();
        LUT.SetTableRange((double)0, (double)1800);
        LUT.SetSaturationRange((double)1, (double)1);
        LUT.SetHueRange((double)rangeStart, (double)rangeEnd);
        LUT.SetValueRange((double)1, (double)1);
        LUT.SetAlphaRange((double)1, (double)1);
        LUT.Build();
        // added these unused default arguments so that the prototype[]
        // matches as required in python.[]
        //method moved
        mapToRGBA = new vtkImageMapToColors();
        mapToRGBA.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
        mapToRGBA.SetOutputFormatToRGBA();
        mapToRGBA.SetLookupTable((vtkScalarsToColors)LUT);

        mapToRGBA.EndEvt += new Kitware.VTK.vtkObject.vtkObjectEventHandler(changeLUT_Command.Execute);

        streamer = new vtkMemoryLimitImageDataStreamer();
        streamer.SetInputConnection((vtkAlgorithmOutput)mapToRGBA.GetOutputPort());
        streamer.SetMemoryLimit((uint)100);
        streamer.UpdateWholeExtent();
        // set the window/level to 255.0/127.5 to view full range[]
        viewer = new vtkImageViewer();
        viewer.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort());
        viewer.SetColorWindow((double)255.0);
        viewer.SetColorLevel((double)127.5);
        viewer.SetZSlice((int)50);
        viewer.Render();

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

          reader = new vtkImageReader();
          reader.ReleaseDataFlagOff();
          reader.SetDataByteOrderToLittleEndian();
          reader.SetDataExtent((int)0,(int)63,(int)0,(int)63,(int)1,(int)93);
          reader.SetFilePrefix((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/headsq/quarter");
          reader.SetDataMask((int)0x7fff);
          rangeStart = 0.0;
          rangeEnd = 0.2;
          LUT = new vtkLookupTable();
          LUT.SetTableRange((double)0,(double)1800);
          LUT.SetSaturationRange((double)1,(double)1);
          LUT.SetHueRange((double)rangeStart,(double)rangeEnd);
          LUT.SetValueRange((double)1,(double)1);
          LUT.SetAlphaRange((double)1,(double)1);
          LUT.Build();
          // added these unused default arguments so that the prototype[]
          // matches as required in python.[]
          //method moved
          mapToRGBA = new vtkImageMapToColors();
          mapToRGBA.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
          mapToRGBA.SetOutputFormatToRGBA();
          mapToRGBA.SetLookupTable((vtkScalarsToColors)LUT);

          mapToRGBA.EndEvt += new Kitware.VTK.vtkObject.vtkObjectEventHandler(changeLUT_Command.Execute);

          streamer = new vtkMemoryLimitImageDataStreamer();
          streamer.SetInputConnection((vtkAlgorithmOutput)mapToRGBA.GetOutputPort());
          streamer.SetMemoryLimit((uint)100);
          streamer.UpdateWholeExtent();
          // set the window/level to 255.0/127.5 to view full range[]
          viewer = new vtkImageViewer();
          viewer.SetInputConnection((vtkAlgorithmOutput)streamer.GetOutputPort());
          viewer.SetColorWindow((double)255.0);
          viewer.SetColorLevel((double)127.5);
          viewer.SetZSlice((int)50);
          viewer.Render();

        //deleteAllVTKObjects();
    }
        //镂空模式_初始化颜色
        private void InitializeColor_HollowOut(ExGrid Grid)
        {
            m_LookupTable = vtkLookupTable.New();
            m_LookupTable.SetTableRange(Grid.Min, Grid.Max);
            //蓝色->红色
            m_LookupTable.SetHueRange(0.666667, 0);
            m_LookupTable.SetNumberOfColors(100);
            m_LookupTable.Build();

            //设定标量值的颜色
            m_ColorTransferFunction = vtkColorTransferFunction.New();
            for (int i = 0; i < 100; i += 10)
            {
                var    color = m_LookupTable.GetTableValue(i);
                double Range = Grid.Max - Grid.Min;
                m_ColorTransferFunction.AddRGBPoint(Grid.Min + i * Range / 100.0, color[0], color[1], color[2]);
            }
            m_ColorTransferFunction.Build();

            //线性插值透明度
            m_PiecewiseFunction = vtkPiecewiseFunction.New();
            // [,)
            InitRanges();

            foreach (var range in m_IntersectRanges)
            {
                double Min = range.Min;
                double Max = range.Max;
                ////由于VTK的特性,对Max进行修正
                //如果透明
                if (range.Transparent)
                {
                    m_PiecewiseFunction.AddSegment(Min, Transparency_Yes, Max, Transparency_Yes);
                }
                //不透明
                else
                {
                    Min = Min + EPSILON;
                    Max = Max - EPSILON;
                    m_PiecewiseFunction.AddSegment(Min, Transparency_Not, Max, Transparency_Not);
                }
            }
        }
Esempio n. 10
0
        private void ReadDEM()
        {
            // Path to vtk data must be set as an environment variable
            // VTK_DATA_ROOT = "C:\VTK\vtkdata-5.8.0"
            vtkTesting test     = vtkTesting.New();
            string     root     = test.GetDataRoot();
            string     filePath = System.IO.Path.Combine(root, @"Data\SainteHelens.dem");

            vtkDEMReader reader = vtkDEMReader.New();

            reader.SetFileName(filePath);
            reader.Update();

            vtkLookupTable lut = vtkLookupTable.New();

            lut.SetHueRange(0.6, 0);
            lut.SetSaturationRange(1.0, 0);
            lut.SetValueRange(0.5, 1.0);
            double[] range = reader.GetOutput().GetScalarRange();
            lut.SetTableRange(range[0], range[1]);

            // Visualize
            vtkImageMapToColors mapColors = vtkImageMapToColors.New();

            mapColors.SetLookupTable(lut);
            mapColors.SetInputConnection(reader.GetOutputPort());

            // Create an actor
            vtkImageActor actor = vtkImageActor.New();

            actor.SetInput(mapColors.GetOutput());
            // 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(actor);
        }
        private void RenderDEM()
        {
            vtkDEMReader reader = vtkDEMReader.New();

            reader.SetFileName(m_FileName);
            reader.Update();

            vtkLookupTable lut = vtkLookupTable.New();

            lut.SetHueRange(0.6, 0);
            lut.SetSaturationRange(1.0, 0);
            lut.SetValueRange(0.5, 1.0);
            double[] range = reader.GetOutput().GetScalarRange();
            lut.SetTableRange(range[0], range[1]);

            // Visualize
            vtkImageMapToColors mapColors = vtkImageMapToColors.New();

            mapColors.SetLookupTable(lut);
            mapColors.SetInputConnection(reader.GetOutputPort());

            // Create an actor
            vtkImageActor actor = vtkImageActor.New();

            actor.SetInput(mapColors.GetOutput());

            // add our actor to the renderer
            m_Renderer.AddActor(actor);
            imgPropList.Add(actor);

            m_Renderer.ResetCamera();

            //Rerender the screen
            m_RenderWindow.Render();
            m_Renderer.Render();
        }
Esempio n. 12
0
        public VTK(int width, int height, int depth)
        {
            Width  = width;
            Height = height;
            Depth  = depth;

            data = new int[Size];
            pIds = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * Size);

            //lutの生成
            lut.SetHueRange(0.667, 0.0);
            lut.Build();

            //セルの生成
            using (var points = vtkPoints.New())
                using (var vertices = vtkCellArray.New())
                {
                    IntPtr pIds = Marshal.AllocHGlobal(Size * Marshal.SizeOf(typeof(int)));
                    int[]  ids  = new int[Size];
                    for (int y = 0; y < Height; y++)
                    {
                        for (int x = 0; x < Width; x++)
                        {
                            ids[x + y * Width] = points.InsertNextPoint(x, -y, 0);
                        }
                    }
                    Marshal.Copy(ids, 0, pIds, Size);
                    vertices.InsertNextCell(Size, pIds);
                    Marshal.FreeHGlobal(pIds);
                    // = vertex.GetPointIds().SetId(0, 0);

                    //
                    pointPoly.SetPoints(points);
                    pointPoly.SetVerts(vertices);
                }
        }
        //普通模式_初始化颜色
        private void InitializeColor_Normal(ExGrid Grid)
        {
            m_LookupTable = vtkLookupTable.New();
            m_LookupTable.SetTableRange(Grid.Min, Grid.Max);
            //蓝色->红色
            m_LookupTable.SetHueRange(0.667, 0);
            m_LookupTable.SetNumberOfColors(100);
            m_LookupTable.Build();

            //设定标量值的颜色
            m_ColorTransferFunction = vtkColorTransferFunction.New();
            for (int i = 0; i < 100; i += 10)
            {
                var    color = m_LookupTable.GetTableValue(i);
                double Range = Grid.Max - Grid.Min;
                m_ColorTransferFunction.AddRGBPoint(Grid.Min + i * Range / 100.0, color[0], color[1], color[2]);
            }
            m_ColorTransferFunction.Build();

            //线性插值透明度
            m_PiecewiseFunction = vtkPiecewiseFunction.New();
            m_PiecewiseFunction.AddPoint(Grid.Min, 1);
            m_PiecewiseFunction.AddPoint(Grid.Max, 1);
        }
Esempio n. 14
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVfieldToUGrid(String [] argv)
    {
        //Prefix Content is: ""

        // Read a field representing unstructured grid and display it (similar to blow.tcl)[]
        // create a reader and write out field daya[]
        reader = new vtkUnstructuredGridReader();
        reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/blow.vtk");
        reader.SetScalarsName((string)"thickness9");
        reader.SetVectorsName((string)"displacement9");
        ds2do = new vtkDataSetToDataObjectFilter();
        ds2do.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
        // we must be able to write here[]
        try
        {
            channel       = new StreamWriter("UGridField.vtk");
            tryCatchError = "NOERROR";
        }
        catch (Exception)
        { tryCatchError = "ERROR"; }

        if (tryCatchError.Equals("NOERROR"))
        {
            channel.Close();
            write = new vtkDataObjectWriter();
            write.SetInputConnection((vtkAlgorithmOutput)ds2do.GetOutputPort());
            write.SetFileName((string)"UGridField.vtk");
            write.Write();
            // Read the field and convert to unstructured grid.[]
            dor = new vtkDataObjectReader();
            dor.SetFileName((string)"UGridField.vtk");
            do2ds = new vtkDataObjectToDataSetFilter();
            do2ds.SetInputConnection((vtkAlgorithmOutput)dor.GetOutputPort());
            do2ds.SetDataSetTypeToUnstructuredGrid();
            do2ds.SetPointComponent((int)0, (string)"Points", (int)0);
            do2ds.SetPointComponent((int)1, (string)"Points", (int)1);
            do2ds.SetPointComponent((int)2, (string)"Points", (int)2);
            do2ds.SetCellTypeComponent((string)"CellTypes", (int)0);
            do2ds.SetCellConnectivityComponent((string)"Cells", (int)0);
            do2ds.Update();

            fd2ad = new vtkFieldDataToAttributeDataFilter();
            fd2ad.SetInputData((vtkDataObject)do2ds.GetUnstructuredGridOutput());
            fd2ad.SetInputFieldToDataObjectField();
            fd2ad.SetOutputAttributeDataToPointData();
            fd2ad.SetVectorComponent((int)0, (string)"displacement9", (int)0);
            fd2ad.SetVectorComponent((int)1, (string)"displacement9", (int)1);
            fd2ad.SetVectorComponent((int)2, (string)"displacement9", (int)2);
            fd2ad.SetScalarComponent((int)0, (string)"thickness9", (int)0);
            fd2ad.Update();

            // Now start visualizing[]
            warp = new vtkWarpVector();
            warp.SetInputData((vtkDataObject)fd2ad.GetUnstructuredGridOutput());
            // extract mold from mesh using connectivity[]
            connect = new vtkConnectivityFilter();
            connect.SetInputConnection((vtkAlgorithmOutput)warp.GetOutputPort());
            connect.SetExtractionModeToSpecifiedRegions();
            connect.AddSpecifiedRegion((int)0);
            connect.AddSpecifiedRegion((int)1);
            moldMapper = new vtkDataSetMapper();
            moldMapper.SetInputConnection((vtkAlgorithmOutput)connect.GetOutputPort());
            moldMapper.ScalarVisibilityOff();
            moldActor = new vtkActor();
            moldActor.SetMapper((vtkMapper)moldMapper);
            moldActor.GetProperty().SetColor((double).2, (double).2, (double).2);
            moldActor.GetProperty().SetRepresentationToWireframe();
            // extract parison from mesh using connectivity[]
            connect2 = new vtkConnectivityFilter();
            connect2.SetInputConnection((vtkAlgorithmOutput)warp.GetOutputPort());
            connect2.SetExtractionModeToSpecifiedRegions();
            connect2.AddSpecifiedRegion((int)2);
            parison = new vtkGeometryFilter();
            parison.SetInputConnection((vtkAlgorithmOutput)connect2.GetOutputPort());
            normals2 = new vtkPolyDataNormals();
            normals2.SetInputConnection((vtkAlgorithmOutput)parison.GetOutputPort());
            normals2.SetFeatureAngle((double)60);
            lut = new vtkLookupTable();
            lut.SetHueRange((double)0.0, (double)0.66667);
            parisonMapper = vtkPolyDataMapper.New();
            parisonMapper.SetInputConnection((vtkAlgorithmOutput)normals2.GetOutputPort());
            parisonMapper.SetLookupTable((vtkScalarsToColors)lut);
            parisonMapper.SetScalarRange((double)0.12, (double)1.0);
            parisonActor = new vtkActor();
            parisonActor.SetMapper((vtkMapper)parisonMapper);
            cf = new vtkContourFilter();
            cf.SetInputConnection((vtkAlgorithmOutput)connect2.GetOutputPort());
            cf.SetValue((int)0, (double).5);
            contourMapper = vtkPolyDataMapper.New();
            contourMapper.SetInputConnection((vtkAlgorithmOutput)cf.GetOutputPort());
            contours = new vtkActor();
            contours.SetMapper((vtkMapper)contourMapper);
            // Create graphics stuff[]
            ren1   = vtkRenderer.New();
            renWin = vtkRenderWindow.New();
            renWin.AddRenderer((vtkRenderer)ren1);
            iren = new vtkRenderWindowInteractor();
            iren.SetRenderWindow((vtkRenderWindow)renWin);
            // Add the actors to the renderer, set the background and size[]
            ren1.AddActor((vtkProp)moldActor);
            ren1.AddActor((vtkProp)parisonActor);
            ren1.AddActor((vtkProp)contours);
            ren1.ResetCamera();
            ren1.GetActiveCamera().Azimuth((double)60);
            ren1.GetActiveCamera().Roll((double)-90);
            ren1.GetActiveCamera().Dolly((double)2);
            ren1.ResetCameraClippingRange();
            ren1.SetBackground((double)1, (double)1, (double)1);
            renWin.SetSize((int)375, (int)200);
            iren.Initialize();
        }


        // prevent the tk window from showing up then start the event loop[]

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

        // we need to use composite data pipeline with multiblock datasets[]
        alg = new vtkAlgorithm();
        pip = new vtkCompositeDataPipeline();
        vtkAlgorithm.SetDefaultExecutivePrototype((vtkExecutive)pip);
        //skipping Delete pip
        // Create the RenderWindow, Renderer and both Actors[]
        //[]
        Ren1 = vtkRenderer.New();
        Ren1.SetBackground((double)0.33, (double)0.35, (double)0.43);
        renWin = vtkRenderWindow.New();
        renWin.AddRenderer((vtkRenderer)Ren1);
        renWin.SetSize((int)300, (int)300);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        pvTemp59 = new vtkXMLRectilinearGridReader();
        pvTemp59.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/cth.vtr");
        pvTemp59.UpdateInformation();
        pvTemp59.SetCellArrayStatus((string)"X Velocity", (int)0);
        pvTemp59.SetCellArrayStatus((string)"Y Velocity", (int)0);
        pvTemp59.SetCellArrayStatus((string)"Z Velocity", (int)0);
        pvTemp59.SetCellArrayStatus((string)"Mass for Armor Plate", (int)0);
        pvTemp59.SetCellArrayStatus((string)"Mass for Body, Nose", (int)0);
        pvTemp79 = new vtkExtractCTHPart();
        pvTemp79.SetInputConnection((vtkAlgorithmOutput)pvTemp59.GetOutputPort());
        pvTemp79.AddVolumeArrayName((string)"Volume Fraction for Armor Plate");
        pvTemp79.AddVolumeArrayName((string)"Volume Fraction for Body, Nose");
        pvTemp79.SetClipPlane(null);
        pvTemp104 = new vtkLookupTable();
        pvTemp104.SetNumberOfTableValues((int)256);
        pvTemp104.SetHueRange((double)0.6667, (double)0);
        pvTemp104.SetSaturationRange((double)1, (double)1);
        pvTemp104.SetValueRange((double)1, (double)1);
        pvTemp104.SetTableRange((double)0, (double)1);
        pvTemp104.SetVectorComponent((int)0);
        pvTemp104.Build();
        pvTemp87 = new vtkCompositePolyDataMapper();
        pvTemp87.SetInputConnection((vtkAlgorithmOutput)pvTemp79.GetOutputPort());
        pvTemp87.SetImmediateModeRendering((int)1);
        pvTemp87.SetScalarRange((double)0, (double)1);
        pvTemp87.UseLookupTableScalarRangeOn();
        pvTemp87.SetScalarVisibility((int)1);
        pvTemp87.SetScalarModeToUsePointFieldData();
        pvTemp87.SelectColorArray((string)"Part Index");
        pvTemp87.SetLookupTable((vtkScalarsToColors)pvTemp104);
        pvTemp88 = new vtkActor();
        pvTemp88.SetMapper((vtkMapper)pvTemp87);
        pvTemp88.GetProperty().SetRepresentationToSurface();
        pvTemp88.GetProperty().SetInterpolationToGouraud();
        pvTemp88.GetProperty().SetAmbient((double)0);
        pvTemp88.GetProperty().SetDiffuse((double)1);
        pvTemp88.GetProperty().SetSpecular((double)0);
        pvTemp88.GetProperty().SetSpecularPower((double)1);
        pvTemp88.GetProperty().SetSpecularColor((double)1, (double)1, (double)1);
        Ren1.AddActor((vtkProp)pvTemp88);
        renWin.Render();
        vtkAlgorithm.SetDefaultExecutivePrototype(null);

//deleteAllVTKObjects();
    }
Esempio n. 16
0
        //Parameters for building a model

        private void BasicVTKBuilder(ref vtkActor actor, ref vtkPoints points, ref vtkCellArray polys,
                                     ref vtkFloatArray scalars, ref vtkLookupTable Luk, ref vtkActor2D actor2D)
        {
            int pointsNum = 0;

            TowerModelInstance.VTKDrawModel(ref points, ref polys, ref scalars, ref pointsNum, paras);

            vtkPolyData profile = vtkPolyData.New();

            profile.SetPoints(points);
            profile.SetPolys(polys);

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            if (paras.RotateAngle == 0)
            {
                profile.GetCellData().SetScalars(scalars);
                mapper.SetInput(profile);
            }
            else
            {
                vtkRotationalExtrusionFilter refilter = vtkRotationalExtrusionFilter.New();
                profile.Update();
                profile.GetCellData().SetScalars(scalars);
                //profile.GetPointData().SetScalars(scalars);
                refilter.SetInput(profile);
                refilter.SetResolution(50);
                refilter.SetAngle(paras.RotateAngle);
                refilter.SetTranslation(0);
                refilter.SetDeltaRadius(0);

                mapper.SetInputConnection(refilter.GetOutputPort());
            }

            mapper.SetScalarRange(TowerModelInstance.GetColorGenColorTableMinvalue(),
                                  TowerModelInstance.GetColorGenColorTableMaxValue());
            actor.SetMapper(mapper);

            // This text property is for scalarBar
            vtkTextProperty textProperty = vtkTextProperty.New();

            //textProperty.SetFontFamilyToCourier();
            //textProperty.SetColor(1.0, 1.0, 0.5);
            textProperty.SetFontSize(10);

            vtkScalarBarActor scalarBar = vtkScalarBarActor.New();

            scalarBar.SetLookupTable(mapper.GetLookupTable());
            scalarBar.SetTitle("Color Table");
            scalarBar.SetNumberOfLabels(TowerModelInstance.GetColorGenColorTableSize());
            scalarBar.SetTitleTextProperty(textProperty);
            scalarBar.SetLabelTextProperty(textProperty);
            scalarBar.SetWidth(0.07);
            scalarBar.SetHeight(0.6);
            //scalarBar.SetDrawFrame(1);

            vtkLookupTable hueLut = vtkLookupTable.New();

            hueLut.SetTableRange(TowerModelInstance.GetColorGenColorTableMinvalue(),
                                 TowerModelInstance.GetColorGenColorTableMaxValue());
            hueLut.SetHueRange(0.667, 0);
            hueLut.SetSaturationRange(1, 1);
            hueLut.SetValueRange(1, 1);
            hueLut.SetNumberOfTableValues(TowerModelInstance.GetColorGenColorTableSize());
            hueLut.Build();

            mapper.SetLookupTable(hueLut);
            scalarBar.SetLookupTable(hueLut);

            // The actor links the data pipeline to the rendering subsystem
            actor2D = scalarBar;
            //actor.GetProperty().SetColor(0.388, 0.388, 0.388);
        }
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVTestExtractCTHPart(String [] argv)
    {
        //Prefix Content is: ""

          // we need to use composite data pipeline with multiblock datasets[]
          alg = new vtkAlgorithm();
          pip = new vtkCompositeDataPipeline();
          vtkAlgorithm.SetDefaultExecutivePrototype((vtkExecutive)pip);
          //skipping Delete pip
          // Create the RenderWindow, Renderer and both Actors[]
          //[]
          Ren1 = vtkRenderer.New();
          Ren1.SetBackground((double)0.33,(double)0.35,(double)0.43);
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)Ren1);
          renWin.SetSize((int)300,(int)300);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          pvTemp59 = new vtkXMLRectilinearGridReader();
          pvTemp59.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/cth.vtr");
          pvTemp59.UpdateInformation();
          pvTemp59.SetCellArrayStatus((string)"X Velocity",(int)0);
          pvTemp59.SetCellArrayStatus((string)"Y Velocity",(int)0);
          pvTemp59.SetCellArrayStatus((string)"Z Velocity",(int)0);
          pvTemp59.SetCellArrayStatus((string)"Mass for Armor Plate",(int)0);
          pvTemp59.SetCellArrayStatus((string)"Mass for Body, Nose",(int)0);
          pvTemp79 = new vtkExtractCTHPart();
          pvTemp79.SetInputConnection((vtkAlgorithmOutput)pvTemp59.GetOutputPort());
          pvTemp79.AddVolumeArrayName((string)"Volume Fraction for Armor Plate");
          pvTemp79.AddVolumeArrayName((string)"Volume Fraction for Body, Nose");
          pvTemp79.SetClipPlane(null);
          pvTemp104 = new vtkLookupTable();
          pvTemp104.SetNumberOfTableValues((int)256);
          pvTemp104.SetHueRange((double)0.6667,(double)0);
          pvTemp104.SetSaturationRange((double)1,(double)1);
          pvTemp104.SetValueRange((double)1,(double)1);
          pvTemp104.SetTableRange((double)0,(double)1);
          pvTemp104.SetVectorComponent((int)0);
          pvTemp104.Build();
          pvTemp87 = new vtkCompositePolyDataMapper();
          pvTemp87.SetInputConnection((vtkAlgorithmOutput)pvTemp79.GetOutputPort());
          pvTemp87.SetImmediateModeRendering((int)1);
          pvTemp87.SetScalarRange((double)0,(double)1);
          pvTemp87.UseLookupTableScalarRangeOn();
          pvTemp87.SetScalarVisibility((int)1);
          pvTemp87.SetScalarModeToUsePointFieldData();
          pvTemp87.SelectColorArray((string)"Part Index");
          pvTemp87.SetLookupTable((vtkScalarsToColors)pvTemp104);
          pvTemp88 = new vtkActor();
          pvTemp88.SetMapper((vtkMapper)pvTemp87);
          pvTemp88.GetProperty().SetRepresentationToSurface();
          pvTemp88.GetProperty().SetInterpolationToGouraud();
          pvTemp88.GetProperty().SetAmbient((double)0);
          pvTemp88.GetProperty().SetDiffuse((double)1);
          pvTemp88.GetProperty().SetSpecular((double)0);
          pvTemp88.GetProperty().SetSpecularPower((double)1);
          pvTemp88.GetProperty().SetSpecularColor((double)1,(double)1,(double)1);
          Ren1.AddActor((vtkProp)pvTemp88);
          renWin.Render();
          vtkAlgorithm.SetDefaultExecutivePrototype(null);

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

        // we need to use composite data pipeline with multiblock datasets[]
        alg = new vtkAlgorithm();
        pip = new vtkCompositeDataPipeline();
        vtkAlgorithm.SetDefaultExecutivePrototype((vtkExecutive)pip);
        //skipping Delete pip
        Ren1 = vtkRenderer.New();
        Ren1.SetBackground((double)0.33, (double)0.35, (double)0.43);

        renWin = vtkRenderWindow.New();
        renWin.AddRenderer((vtkRenderer)Ren1);

        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);

        Plot3D0 = new vtkMultiBlockPLOT3DReader();
        Plot3D0.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin");
        Plot3D0.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin");
        Plot3D0.SetBinaryFile((int)1);
        Plot3D0.SetMultiGrid((int)0);
        Plot3D0.SetHasByteCount((int)0);
        Plot3D0.SetIBlanking((int)0);
        Plot3D0.SetTwoDimensionalGeometry((int)0);
        Plot3D0.SetForceRead((int)0);
        Plot3D0.SetByteOrder((int)0);
        Plot3D0.Update();

        Geometry5 = new vtkStructuredGridOutlineFilter();
        Geometry5.SetInputData((vtkDataSet)Plot3D0.GetOutput().GetBlock(0));

        Mapper5 = vtkPolyDataMapper.New();
        Mapper5.SetInputConnection((vtkAlgorithmOutput)Geometry5.GetOutputPort());
        Mapper5.SetImmediateModeRendering((int)1);
        Mapper5.UseLookupTableScalarRangeOn();
        Mapper5.SetScalarVisibility((int)0);
        Mapper5.SetScalarModeToDefault();

        Actor5 = new vtkActor();
        Actor5.SetMapper((vtkMapper)Mapper5);
        Actor5.GetProperty().SetRepresentationToSurface();
        Actor5.GetProperty().SetInterpolationToGouraud();
        Actor5.GetProperty().SetAmbient((double)0.15);
        Actor5.GetProperty().SetDiffuse((double)0.85);
        Actor5.GetProperty().SetSpecular((double)0.1);
        Actor5.GetProperty().SetSpecularPower((double)100);
        Actor5.GetProperty().SetSpecularColor((double)1, (double)1, (double)1);

        Actor5.GetProperty().SetColor((double)1, (double)1, (double)1);
        Ren1.AddActor((vtkProp)Actor5);

        ExtractGrid[0] = new vtkExtractGrid();
        ExtractGrid[0].SetInputData((vtkDataSet)Plot3D0.GetOutput().GetBlock(0));
        ExtractGrid[0].SetVOI((int)0, (int)14, (int)0, (int)32, (int)0, (int)24);
        ExtractGrid[0].SetSampleRate((int)1, (int)1, (int)1);
        ExtractGrid[0].SetIncludeBoundary((int)0);

        ExtractGrid[1] = new vtkExtractGrid();
        ExtractGrid[1].SetInputData((vtkDataSet)Plot3D0.GetOutput().GetBlock(0));
        ExtractGrid[1].SetVOI((int)14, (int)29, (int)0, (int)32, (int)0, (int)24);
        ExtractGrid[1].SetSampleRate((int)1, (int)1, (int)1);
        ExtractGrid[1].SetIncludeBoundary((int)0);

        ExtractGrid[2] = new vtkExtractGrid();
        ExtractGrid[2].SetInputData((vtkDataSet)Plot3D0.GetOutput().GetBlock(0));
        ExtractGrid[2].SetVOI((int)29, (int)56, (int)0, (int)32, (int)0, (int)24);
        ExtractGrid[2].SetSampleRate((int)1, (int)1, (int)1);
        ExtractGrid[2].SetIncludeBoundary((int)0);

        LineSourceWidget0 = new vtkLineSource();
        LineSourceWidget0.SetPoint1((double)3.05638, (double)-3.00497, (double)28.2211);
        LineSourceWidget0.SetPoint2((double)3.05638, (double)3.95916, (double)28.2211);
        LineSourceWidget0.SetResolution((int)20);

        mbds = new vtkMultiBlockDataSet();
        mbds.SetNumberOfBlocks((uint)3);
        i = 0;
        while ((i) < 3)
        {
            ExtractGrid[i].Update();
            sg[i] = vtkStructuredGrid.New();
            sg[i].ShallowCopy(ExtractGrid[i].GetOutput());
            mbds.SetBlock((uint)i, sg[i]);
            //skipping Delete sg[i]
            i = i + 1;
        }

        Stream0 = new vtkStreamTracer();
        Stream0.SetInputData((vtkDataObject)mbds);
        Stream0.SetSourceConnection(LineSourceWidget0.GetOutputPort());
        Stream0.SetIntegrationStepUnit(2);
        Stream0.SetMaximumPropagation((double)20);
        Stream0.SetInitialIntegrationStep((double)0.5);
        Stream0.SetIntegrationDirection((int)0);
        Stream0.SetIntegratorType((int)0);
        Stream0.SetMaximumNumberOfSteps((int)2000);
        Stream0.SetTerminalSpeed((double)1e-12);

        //skipping Delete mbds

        aa = new vtkAssignAttribute();
        aa.SetInputConnection((vtkAlgorithmOutput)Stream0.GetOutputPort());
        aa.Assign((string)"Normals", (string)"NORMALS", (string)"POINT_DATA");

        Ribbon0 = new vtkRibbonFilter();
        Ribbon0.SetInputConnection((vtkAlgorithmOutput)aa.GetOutputPort());
        Ribbon0.SetWidth((double)0.1);
        Ribbon0.SetAngle((double)0);
        Ribbon0.SetDefaultNormal((double)0, (double)0, (double)1);
        Ribbon0.SetVaryWidth((int)0);

        LookupTable1 = new vtkLookupTable();
        LookupTable1.SetNumberOfTableValues((int)256);
        LookupTable1.SetHueRange((double)0, (double)0.66667);
        LookupTable1.SetSaturationRange((double)1, (double)1);
        LookupTable1.SetValueRange((double)1, (double)1);
        LookupTable1.SetTableRange((double)0.197813, (double)0.710419);
        LookupTable1.SetVectorComponent((int)0);
        LookupTable1.Build();

        Mapper10 = vtkPolyDataMapper.New();
        Mapper10.SetInputConnection((vtkAlgorithmOutput)Ribbon0.GetOutputPort());
        Mapper10.SetImmediateModeRendering((int)1);
        Mapper10.UseLookupTableScalarRangeOn();
        Mapper10.SetScalarVisibility((int)1);
        Mapper10.SetScalarModeToUsePointFieldData();
        Mapper10.SelectColorArray((string)"Density");
        Mapper10.SetLookupTable((vtkScalarsToColors)LookupTable1);

        Actor10 = new vtkActor();
        Actor10.SetMapper((vtkMapper)Mapper10);
        Actor10.GetProperty().SetRepresentationToSurface();
        Actor10.GetProperty().SetInterpolationToGouraud();
        Actor10.GetProperty().SetAmbient((double)0.15);
        Actor10.GetProperty().SetDiffuse((double)0.85);
        Actor10.GetProperty().SetSpecular((double)0);
        Actor10.GetProperty().SetSpecularPower((double)1);
        Actor10.GetProperty().SetSpecularColor((double)1, (double)1, (double)1);
        Ren1.AddActor((vtkProp)Actor10);

        // enable user interface interactor[]
        iren.Initialize();
        // prevent the tk window from showing up then start the event loop[]
        vtkAlgorithm.SetDefaultExecutivePrototype(null);
        //skipping Delete alg

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

          // we need to use composite data pipeline with multiblock datasets[]
          alg = new vtkAlgorithm();
          pip = new vtkCompositeDataPipeline();
          vtkAlgorithm.SetDefaultExecutivePrototype((vtkExecutive)pip);
          //skipping Delete pip
          Ren1 = vtkRenderer.New();
          Ren1.SetBackground((double)0.33,(double)0.35,(double)0.43);

          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)Ren1);

          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);

          Plot3D0 = new vtkPLOT3DReader();
          Plot3D0.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combxyz.bin");
          Plot3D0.SetQFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/combq.bin");
          Plot3D0.SetBinaryFile((int)1);
          Plot3D0.SetMultiGrid((int)0);
          Plot3D0.SetHasByteCount((int)0);
          Plot3D0.SetIBlanking((int)0);
          Plot3D0.SetTwoDimensionalGeometry((int)0);
          Plot3D0.SetForceRead((int)0);
          Plot3D0.SetByteOrder((int)0);

          Geometry5 = new vtkStructuredGridOutlineFilter();
          Geometry5.SetInputConnection((vtkAlgorithmOutput)Plot3D0.GetOutputPort());

          Mapper5 = vtkPolyDataMapper.New();
          Mapper5.SetInputConnection((vtkAlgorithmOutput)Geometry5.GetOutputPort());
          Mapper5.SetImmediateModeRendering((int)1);
          Mapper5.UseLookupTableScalarRangeOn();
          Mapper5.SetScalarVisibility((int)0);
          Mapper5.SetScalarModeToDefault();

          Actor5 = new vtkActor();
          Actor5.SetMapper((vtkMapper)Mapper5);
          Actor5.GetProperty().SetRepresentationToSurface();
          Actor5.GetProperty().SetInterpolationToGouraud();
          Actor5.GetProperty().SetAmbient((double)0.15);
          Actor5.GetProperty().SetDiffuse((double)0.85);
          Actor5.GetProperty().SetSpecular((double)0.1);
          Actor5.GetProperty().SetSpecularPower((double)100);
          Actor5.GetProperty().SetSpecularColor((double)1,(double)1,(double)1);

          Actor5.GetProperty().SetColor((double)1,(double)1,(double)1);
          Ren1.AddActor((vtkProp)Actor5);

          ExtractGrid[0] = new vtkExtractGrid();
          ExtractGrid[0].SetInputConnection((vtkAlgorithmOutput)Plot3D0.GetOutputPort());
          ExtractGrid[0].SetVOI((int)0,(int)14,(int)0,(int)32,(int)0,(int)24);
          ExtractGrid[0].SetSampleRate((int)1,(int)1,(int)1);
          ExtractGrid[0].SetIncludeBoundary((int)0);

          ExtractGrid[1] = new vtkExtractGrid();
          ExtractGrid[1].SetInputConnection((vtkAlgorithmOutput)Plot3D0.GetOutputPort());
          ExtractGrid[1].SetVOI((int)14,(int)29,(int)0,(int)32,(int)0,(int)24);
          ExtractGrid[1].SetSampleRate((int)1,(int)1,(int)1);
          ExtractGrid[1].SetIncludeBoundary((int)0);

          ExtractGrid[2] = new vtkExtractGrid();
          ExtractGrid[2].SetInputConnection((vtkAlgorithmOutput)Plot3D0.GetOutputPort());
          ExtractGrid[2].SetVOI((int)29,(int)56,(int)0,(int)32,(int)0,(int)24);
          ExtractGrid[2].SetSampleRate((int)1,(int)1,(int)1);
          ExtractGrid[2].SetIncludeBoundary((int)0);

          LineSourceWidget0 = new vtkLineSource();
          LineSourceWidget0.SetPoint1((double)3.05638,(double)-3.00497,(double)28.2211);
          LineSourceWidget0.SetPoint2((double)3.05638,(double)3.95916,(double)28.2211);
          LineSourceWidget0.SetResolution((int)20);

          mbds = new vtkMultiBlockDataSet();
          mbds.SetNumberOfBlocks((uint)3);
          i = 0;
          while((i) < 3)
        {
          ExtractGrid[i].Update();
          sg[i] = vtkStructuredGrid.New();
          sg[i].ShallowCopy(ExtractGrid[i].GetOutput());
          mbds.SetBlock((uint)i, sg[i]);
          //skipping Delete sg[i]
          i = i + 1;
        }

          Stream0 = new vtkStreamTracer();
          Stream0.SetInput((vtkDataObject)mbds);
          Stream0.SetSource((vtkDataSet)LineSourceWidget0.GetOutput());
          Stream0.SetIntegrationStepUnit(2);
          Stream0.SetMaximumPropagation((double)20);
          Stream0.SetInitialIntegrationStep((double)0.5);
          Stream0.SetIntegrationDirection((int)0);
          Stream0.SetIntegratorType((int)0);
          Stream0.SetMaximumNumberOfSteps((int)2000);
          Stream0.SetTerminalSpeed((double)1e-12);

          //skipping Delete mbds

          aa = new vtkAssignAttribute();
          aa.SetInputConnection((vtkAlgorithmOutput)Stream0.GetOutputPort());
          aa.Assign((string)"Normals",(string)"NORMALS",(string)"POINT_DATA");

          Ribbon0 = new vtkRibbonFilter();
          Ribbon0.SetInputConnection((vtkAlgorithmOutput)aa.GetOutputPort());
          Ribbon0.SetWidth((double)0.1);
          Ribbon0.SetAngle((double)0);
          Ribbon0.SetDefaultNormal((double)0,(double)0,(double)1);
          Ribbon0.SetVaryWidth((int)0);

          LookupTable1 = new vtkLookupTable();
          LookupTable1.SetNumberOfTableValues((int)256);
          LookupTable1.SetHueRange((double)0,(double)0.66667);
          LookupTable1.SetSaturationRange((double)1,(double)1);
          LookupTable1.SetValueRange((double)1,(double)1);
          LookupTable1.SetTableRange((double)0.197813,(double)0.710419);
          LookupTable1.SetVectorComponent((int)0);
          LookupTable1.Build();

          Mapper10 = vtkPolyDataMapper.New();
          Mapper10.SetInputConnection((vtkAlgorithmOutput)Ribbon0.GetOutputPort());
          Mapper10.SetImmediateModeRendering((int)1);
          Mapper10.UseLookupTableScalarRangeOn();
          Mapper10.SetScalarVisibility((int)1);
          Mapper10.SetScalarModeToUsePointFieldData();
          Mapper10.SelectColorArray((string)"Density");
          Mapper10.SetLookupTable((vtkScalarsToColors)LookupTable1);

          Actor10 = new vtkActor();
          Actor10.SetMapper((vtkMapper)Mapper10);
          Actor10.GetProperty().SetRepresentationToSurface();
          Actor10.GetProperty().SetInterpolationToGouraud();
          Actor10.GetProperty().SetAmbient((double)0.15);
          Actor10.GetProperty().SetDiffuse((double)0.85);
          Actor10.GetProperty().SetSpecular((double)0);
          Actor10.GetProperty().SetSpecularPower((double)1);
          Actor10.GetProperty().SetSpecularColor((double)1,(double)1,(double)1);
          Ren1.AddActor((vtkProp)Actor10);

          // enable user interface interactor[]
          iren.Initialize();
          // prevent the tk window from showing up then start the event loop[]
          vtkAlgorithm.SetDefaultExecutivePrototype(null);
          //skipping Delete alg

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

          // Read a field representing unstructured grid and display it (similar to blow.tcl)[]
          // create a reader and write out field daya[]
          reader = new vtkUnstructuredGridReader();
          reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/blow.vtk");
          reader.SetScalarsName((string)"thickness9");
          reader.SetVectorsName((string)"displacement9");
          ds2do = new vtkDataSetToDataObjectFilter();
          ds2do.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
          // we must be able to write here[]
          try
          {
         channel = new StreamWriter("UGridField.vtk");
          tryCatchError = "NOERROR";
          }
          catch(Exception)
          {tryCatchError = "ERROR";}

          if (tryCatchError.Equals("NOERROR"))
          {
          channel.Close();
          write = new vtkDataObjectWriter();
          write.SetInputConnection((vtkAlgorithmOutput)ds2do.GetOutputPort());
          write.SetFileName((string)"UGridField.vtk");
          write.Write();
          // Read the field and convert to unstructured grid.[]
          dor = new vtkDataObjectReader();
          dor.SetFileName((string)"UGridField.vtk");
          do2ds = new vtkDataObjectToDataSetFilter();
          do2ds.SetInputConnection((vtkAlgorithmOutput)dor.GetOutputPort());
          do2ds.SetDataSetTypeToUnstructuredGrid();
          do2ds.SetPointComponent((int)0,(string)"Points",(int)0);
          do2ds.SetPointComponent((int)1,(string)"Points",(int)1);
          do2ds.SetPointComponent((int)2,(string)"Points",(int)2);
          do2ds.SetCellTypeComponent((string)"CellTypes",(int)0);
          do2ds.SetCellConnectivityComponent((string)"Cells",(int)0);
          fd2ad = new vtkFieldDataToAttributeDataFilter();
          fd2ad.SetInput((vtkDataObject)do2ds.GetUnstructuredGridOutput());
          fd2ad.SetInputFieldToDataObjectField();
          fd2ad.SetOutputAttributeDataToPointData();
          fd2ad.SetVectorComponent((int)0,(string)"displacement9",(int)0);
          fd2ad.SetVectorComponent((int)1,(string)"displacement9",(int)1);
          fd2ad.SetVectorComponent((int)2,(string)"displacement9",(int)2);
          fd2ad.SetScalarComponent((int)0,(string)"thickness9",(int)0);
          // Now start visualizing[]
          warp = new vtkWarpVector();
          warp.SetInput((vtkDataObject)fd2ad.GetUnstructuredGridOutput());
          // extract mold from mesh using connectivity[]
          connect = new vtkConnectivityFilter();
          connect.SetInputConnection((vtkAlgorithmOutput)warp.GetOutputPort());
          connect.SetExtractionModeToSpecifiedRegions();
          connect.AddSpecifiedRegion((int)0);
          connect.AddSpecifiedRegion((int)1);
          moldMapper = new vtkDataSetMapper();
          moldMapper.SetInputConnection((vtkAlgorithmOutput)connect.GetOutputPort());
          moldMapper.ScalarVisibilityOff();
          moldActor = new vtkActor();
          moldActor.SetMapper((vtkMapper)moldMapper);
          moldActor.GetProperty().SetColor((double).2,(double).2,(double).2);
          moldActor.GetProperty().SetRepresentationToWireframe();
          // extract parison from mesh using connectivity[]
          connect2 = new vtkConnectivityFilter();
          connect2.SetInputConnection((vtkAlgorithmOutput)warp.GetOutputPort());
          connect2.SetExtractionModeToSpecifiedRegions();
          connect2.AddSpecifiedRegion((int)2);
          parison = new vtkGeometryFilter();
          parison.SetInputConnection((vtkAlgorithmOutput)connect2.GetOutputPort());
          normals2 = new vtkPolyDataNormals();
          normals2.SetInputConnection((vtkAlgorithmOutput)parison.GetOutputPort());
          normals2.SetFeatureAngle((double)60);
          lut = new vtkLookupTable();
          lut.SetHueRange((double)0.0,(double)0.66667);
          parisonMapper = vtkPolyDataMapper.New();
          parisonMapper.SetInputConnection((vtkAlgorithmOutput)normals2.GetOutputPort());
          parisonMapper.SetLookupTable((vtkScalarsToColors)lut);
          parisonMapper.SetScalarRange((double)0.12,(double)1.0);
          parisonActor = new vtkActor();
          parisonActor.SetMapper((vtkMapper)parisonMapper);
          cf = new vtkContourFilter();
          cf.SetInputConnection((vtkAlgorithmOutput)connect2.GetOutputPort());
          cf.SetValue((int)0,(double).5);
          contourMapper = vtkPolyDataMapper.New();
          contourMapper.SetInputConnection((vtkAlgorithmOutput)cf.GetOutputPort());
          contours = new vtkActor();
          contours.SetMapper((vtkMapper)contourMapper);
          // Create graphics stuff[]
          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          // Add the actors to the renderer, set the background and size[]
          ren1.AddActor((vtkProp)moldActor);
          ren1.AddActor((vtkProp)parisonActor);
          ren1.AddActor((vtkProp)contours);
          ren1.ResetCamera();
          ren1.GetActiveCamera().Azimuth((double)60);
          ren1.GetActiveCamera().Roll((double)-90);
          ren1.GetActiveCamera().Dolly((double)2);
          ren1.ResetCameraClippingRange();
          ren1.SetBackground((double)1,(double)1,(double)1);
          renWin.SetSize((int)375,(int)200);
          iren.Initialize();
        }

          // prevent the tk window from showing up then start the event loop[]

        //deleteAllVTKObjects();
    }
Esempio n. 21
0
        private void DrawRainBow()
        {
            //# First create pipeline a simple pipeline that reads a structure grid
            //# and then extracts a plane from the grid. The plane will be colored
            //# differently by using different lookup tables.
            //#
            //# Note: the Update method is manually invoked because it causes the
            //# reader to read; later on we use the output of the reader to set
            //# a range for the scalar values.
            vtkMultiBlockPLOT3DReader pl3d = vtkMultiBlockPLOT3DReader.New();

            pl3d.SetXYZFileName(@"..\..\Data\combxyz.bin");
            pl3d.SetQFileName(@"..\..\Data\combq.bin");
            pl3d.SetScalarFunctionNumber(100);
            pl3d.SetVectorFunctionNumber(202);
            pl3d.Update();
            vtkDataObject pl3d_output = pl3d.GetOutput().GetBlock(0);

            vtkStructuredGridGeometryFilter planeFilter = vtkStructuredGridGeometryFilter.New();

            planeFilter.SetInputData(pl3d_output);
            planeFilter.SetExtent(1, 100, 1, 100, 7, 7);
            vtkLookupTable    lut         = vtkLookupTable.New();
            vtkPolyDataMapper planeMapper = vtkPolyDataMapper.New();

            planeMapper.SetLookupTable(lut);
            planeMapper.SetInputConnection(planeFilter.GetOutputPort());
            //planeMapper.SetScalarRange(pl3d_output.)
            vtkActor planeActor = vtkActor.New();

            planeActor.SetMapper(planeMapper);

            //this creates an outline around the data
            vtkStructuredGridOutlineFilter outlineFilter = vtkStructuredGridOutlineFilter.New();

            outlineFilter.SetInputData(pl3d_output);
            vtkPolyDataMapper outlineMapper = vtkPolyDataMapper.New();

            outlineMapper.SetInputConnection(outlineFilter.GetOutputPort());
            vtkActor outlineActor = vtkActor.New();

            outlineActor.SetMapper(outlineMapper);

            //Much of the following is commented out. To try different lookup tables.
            //This create a black to white lut
            //lut.SetHueRange(0, 0);
            //lut.SetSaturationRange(0, 0);
            //lut.SetValueRange(0.2, 1.0);

            //This creates a red to blue lut
            //lut.SetHueRange(0.0, 0.677);

            //This creates a blue to red lue
            lut.SetHueRange(0.667, 0.0);

            //This creates a weird effect. the Build() method cause lookup
            //table to allocate memory and create a table based on the correct
            //hue, saturatioin, value, and alpha range. Here we then
            //manully overwrite the value generated by the Build() method.
            lut.SetNumberOfColors(256);
            lut.Build();
            for (int i = 0; i < 16; i++)
            {
                lut.SetTableValue(i * 16, (float)Color.Red.R / 256, (float)Color.Red.G / 256, (float)Color.Red.B / 256, 1);
                lut.SetTableValue(i * 16 + 1, (float)Color.Green.R / 256, (float)Color.Green.G / 256, (float)Color.Green.B / 256, 1);
                lut.SetTableValue(i * 16 + 2, (float)Color.Blue.R / 256, (float)Color.Blue.G / 256, (float)Color.Blue.B / 256, 1);
                lut.SetTableValue(i * 16 + 3, (float)Color.Black.R / 256, (float)Color.Black.G / 256, (float)Color.Black.B / 256, 1);
            }


            //Create the renderwindow, the render and both actors
            vtkRenderer     ren    = vtkRenderer.New();
            vtkRenderWindow renWin = myRenderWindowControl.RenderWindow;

            renWin.AddRenderer(ren);

            //Add the actors to the renderer, set the backgroud
            ren.AddActor(outlineActor);
            ren.AddActor(planeActor);

            ren.SetBackground(0.1, 0.2, 0.4);
            ren.TwoSidedLightingOff();
        }