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;
        }
示例#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);
 }
        //切片模式_初始化颜色
        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);
        }
        //镂空模式_初始化颜色
        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);
                }
            }
        }
        //普通模式_初始化颜色
        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);
        }
        private void RenderXYZColor()
        {
            FileStream   fs = null;
            StreamReader sr = null;
            String       sLineBuffer;

            String[]  sXYZ;
            char[]    chDelimiter = new char[] { ' ', '\t', ';' };
            double[]  xyz         = new double[3];
            double[]  rgb         = new double[3];
            vtkPoints points      = vtkPoints.New();
            vtkPoints colors      = vtkPoints.New();
            int       cnt         = 0;

            try
            {
                // in case file must be open in another application too use "FileShare.ReadWrite"
                fs = new FileStream(m_FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                sr = new StreamReader(fs);

                vtkDoubleArray colorScalor = new vtkDoubleArray();
                int            n           = 1;
                while (!sr.EndOfStream)
                {
                    sLineBuffer = sr.ReadLine();
                    cnt++;
                    sXYZ = sLineBuffer.Split(chDelimiter, StringSplitOptions.RemoveEmptyEntries);
                    if (sXYZ == null || sXYZ.Length != 6)
                    {
                        MessageBox.Show("data seems to be in wrong format at line " + cnt, "Format Exception", MessageBoxButtons.OK);
                        return;
                    }
                    xyz[0] = double.Parse(sXYZ[0], CultureInfo.InvariantCulture) * 11100;
                    xyz[1] = double.Parse(sXYZ[1], CultureInfo.InvariantCulture) * 11100;
                    xyz[2] = double.Parse(sXYZ[2], CultureInfo.InvariantCulture);

                    rgb[0] = double.Parse(sXYZ[0], CultureInfo.InvariantCulture);
                    rgb[1] = double.Parse(sXYZ[1], CultureInfo.InvariantCulture);
                    rgb[2] = double.Parse(sXYZ[2], CultureInfo.InvariantCulture);

                    points.InsertNextPoint(xyz[0], xyz[1], xyz[2]);
                    colors.InsertNextPoint(rgb[0], rgb[1], rgb[2]);
                    colorScalor.InsertNextTuple1(n++);
                }
                vtkPolyData polydata = vtkPolyData.New();
                polydata.SetPoints(points);
                polydata.GetPointData().SetScalars(colorScalor); //设置点的Scalar(标量)属性

                vtkVertexGlyphFilter glyphFilter = vtkVertexGlyphFilter.New();
                glyphFilter.SetInputConnection(polydata.GetProducerPort());

                vtkLookupTable lookupTable = new vtkLookupTable();
                lookupTable.SetNumberOfColors(n);
                // SetSetTableValue(vtkIdType  indx, double r, double g, double  b, double a);
                Random random = new Random();
                for (int i = 0; i < n; i++)
                {
                    double[] tmp = colors.GetPoint(i);
                    double   r   = tmp[0];
                    double   g   = tmp[1];
                    double   b   = tmp[2];
                    lookupTable.SetTableValue(i, r, g, b, 1);
                }

                // Visualize
                vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
                mapper.SetInputConnection(glyphFilter.GetOutputPort());
                mapper.SetLookupTable(lookupTable);
                mapper.SetScalarRange(1, n);

                vtkActor actor = vtkActor.New();
                actor.SetMapper(mapper);
                actor.GetProperty().SetPointSize(1);
                //actor.GetProperty().SetColor(1, 0.5, 0);
                // 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();
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message, "IOException", MessageBoxButtons.OK);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                    sr.Dispose();
                    sr = null;
                }
            }
        }
示例#7
0
 public void ChangeColorNumber(int numb)
 {
     colorLookupTable.SetNumberOfColors(numb);
     ScalarBar.SetNumberOfLabels(numb);
 }
示例#8
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();
        }