Exemplo n.º 1
0
        public void SetDefaultColor()
        {
            vtkUnsignedCharArray cellColors = new vtkUnsignedCharArray();

            cellColors.SetNumberOfComponents(3);
            int cellNum = this.GetMapper().GetInput().GetNumberOfCells();

            cellColors.SetNumberOfTuples(cellNum);
            for (int i = 0; i < cellNum; ++i)
            {
                cellColors.SetTuple3(i, this.m_defaultColor[0], this.m_defaultColor[1], this.m_defaultColor[2]);
            }
            this.GetMapper().GetInput().GetCellData().SetScalars(cellColors);

            vtkUnsignedCharArray ptColors = new vtkUnsignedCharArray();

            ptColors.SetNumberOfComponents(3);
            int ptNum = this.GetMapper().GetInput().GetNumberOfPoints();

            ptColors.SetNumberOfTuples(ptNum);
            for (int i = 0; i < ptNum; i++)
            {
                ptColors.SetTuple3(i, this.m_defaultColor[0], this.m_defaultColor[1], this.m_defaultColor[2]);
            }
            this.GetMapper().GetInput().GetPointData().SetScalars(ptColors);
            // this.GetMapper().SetScalarModeToUsePointData();

            this.GetMapper().SetScalarModeToUseCellData();
            this.GetMapper().Update();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts 3D byte array to vtkImageData.
        /// </summary>
        /// <param name="data">Input array.</param>
        /// <param name="dims">Input array dimensions. Give the begin and end extent for each dimension.</param>
        /// <returns>Converted array.</returns>
        public static vtkImageData byteToVTK1D(byte[] data, int[] dims)
        {
            int h = dims[1] - dims[0] + 1;
            int w = dims[3] - dims[2] + 1;
            int d = dims[5] - dims[4] + 1;
            //Create VTK data for putput
            vtkImageData vtkdata = vtkImageData.New();
            //Character array for conversion
            vtkUnsignedCharArray charArray = vtkUnsignedCharArray.New();
            //Pin byte array
            GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);

            //Set character array input
            charArray.SetArray(pinnedArray.AddrOfPinnedObject(), h * w * d, 1);
            //Set vtkdata properties and connect array
            //Data from char array
            vtkdata.GetPointData().SetScalars(charArray);
            //Number of scalars/pixel
            vtkdata.SetNumberOfScalarComponents(1);
            //Set data extent
            vtkdata.SetExtent(dims[0], dims[1], dims[2], dims[3], dims[4], dims[5]);
            //Scalar type
            vtkdata.SetScalarTypeToUnsignedChar();
            vtkdata.Update();

            return(vtkdata);
        }
Exemplo n.º 3
0
        public void ReadPointIntoObject(RenderWindowControl renderWindowControl, List <nvmPointModel> listPointModel)
        {
            vtkUnsignedCharArray colors = vtkUnsignedCharArray.New();

            colors.SetNumberOfComponents(3);
            colors.SetName("Colors");
            vtkPoints points = vtkPoints.New();

            foreach (var point in listPointModel)
            {
                colors.InsertNextValue(byte.Parse(point.color.X.ToString(), CultureInfo.InvariantCulture));
                colors.InsertNextValue(byte.Parse(point.color.Y.ToString(), CultureInfo.InvariantCulture));
                colors.InsertNextValue(byte.Parse(point.color.Z.ToString(), CultureInfo.InvariantCulture));
                points.InsertNextPoint(
                    double.Parse(point.position.X.ToString(), CultureInfo.InvariantCulture),
                    double.Parse(point.position.Y.ToString(), CultureInfo.InvariantCulture),
                    double.Parse(point.position.Z.ToString(), CultureInfo.InvariantCulture));
            }

            vtkPolyData polydata = vtkPolyData.New();

            polydata.SetPoints(points);
            polydata.GetPointData().SetScalars(colors);
            vtkVertexGlyphFilter glyphFilter = vtkVertexGlyphFilter.New();

            glyphFilter.SetInputConnection(polydata.GetProducerPort());

            // Visualize
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInputConnection(glyphFilter.GetOutputPort());
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);
            actor.GetProperty().SetPointSize(2);
            // get a reference to the renderwindow of our renderWindowControl1
            vtkRenderWindow renderWindow = renderWindowControl.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);
            renderer.ResetCamera();
        }
Exemplo n.º 4
0
        /// <summary>
        /// 当有点和cell被选择是更新颜色
        /// </summary>
        public override void UpdateSelectedColor()
        {
            ///cell
            if (m_selectedCellsIds != null && m_selectedCellsIds.Count > 0)
            {
                vtkUnsignedCharArray colors = new vtkUnsignedCharArray();
                colors.SetNumberOfComponents(3);
                int cellNum = this.GetMapper().GetInput().GetNumberOfCells();
                colors.SetNumberOfTuples(cellNum);
                for (int i = 0; i < cellNum; ++i)
                {
                    colors.SetTuple3(i, m_defaultColor [0], m_defaultColor [1], m_defaultColor [2]);
                }
                foreach (int cellID in m_selectedCellsIds.Keys)
                {
                    colors.SetTuple3(cellID, ModelUtils.SelectedColor[0], ModelUtils.SelectedColor[1],
                                     ModelUtils.SelectedColor[2]);
                }
                this.GetMapper().GetInput().GetCellData().SetScalars(colors);
            }
            ///point
            else if (m_selectedPointsIds != null && m_selectedPointsIds.Count > 0)
            {
                vtkUnsignedCharArray ptcolors = new vtkUnsignedCharArray();
                ptcolors.SetNumberOfComponents(3);
                int ptNum = this.GetMapper().GetInput().GetNumberOfPoints();
                ptcolors.SetNumberOfTuples(ptNum);

                for (int i = 0; i < ptNum; ++i)
                {
                    ptcolors.SetTuple3(i, m_defaultColor[0], m_defaultColor[1], m_defaultColor[2]);
                }
                foreach (int ptid in m_selectedPointsIds.Keys)
                {
                    ptcolors.SetTuple3(ptid, ModelUtils.SelectedColor[0], ModelUtils.SelectedColor[1], ModelUtils.SelectedColor[2]);
                }

                this.GetMapper().SetScalarModeToUsePointData();
                this.GetMapper().GetInput().GetPointData().SetScalars(ptcolors);

                //this.GetProperty().SetPointSize(4);
                //this.GetProperty().SetRepresentationToPoints();
            }
            this.GetMapper().Update();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Converts 3D byte array to vtkImageData.
        /// </summary>
        /// <param name="data">Input array.</param>
        /// <param name="orientation">Data orientation as a list of axes (0-2)</param>
        /// <returns>Converted array.</returns>
        public static vtkImageData byteToVTK(byte[,,] data, int[] orientation = null)
        {
            //Get input dimensions
            int[] dims = new int[] { data.GetLength(0), data.GetLength(1), data.GetLength(2) };
            //Create VTK data for putput
            vtkImageData vtkdata = vtkImageData.New();
            //Character array for conversion
            vtkUnsignedCharArray charArray = vtkUnsignedCharArray.New();
            //Pin byte array
            GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);

            //Set character array input
            charArray.SetArray(pinnedArray.AddrOfPinnedObject(), dims[0] * dims[1] * dims[2], 1);
            //Set vtkdata properties and connect array
            //Data from char array
            vtkdata.GetPointData().SetScalars(charArray);
            //Number of scalars/pixel
            vtkdata.SetNumberOfScalarComponents(1);
            //Data extent, 1st and last axis are swapped from the char array
            //Data is converted back to original orientation
            vtkdata.SetExtent(0, dims[2] - 1, 0, dims[1] - 1, 0, dims[0] - 1);
            //Scalar type
            vtkdata.SetScalarTypeToUnsignedChar();
            vtkdata.SetSpacing(1.0, 1.0, 1.0);
            vtkdata.Update();
            pinnedArray.Free();
            //Return vtk data
            if (orientation == null)
            {
                return(vtkdata);
            }
            else
            {
                vtkImagePermute permuter = vtkImagePermute.New();
                permuter.SetInput(vtkdata);
                permuter.SetFilteredAxes(orientation[0], orientation[1], orientation[2]);
                permuter.Update();
                return(permuter.GetOutput());
            }
        }
Exemplo n.º 6
0
        private void ElevationFilter()
        {
            // Created a grid of points (heigh/terrian map)
            vtkPoints points = vtkPoints.New();

            uint GridSize = 10;

            for (uint x = 0; x < GridSize; x++)
            {
                for (uint y = 0; y < GridSize; y++)
                {
                    points.InsertNextPoint(x, y, (x + y) / (y + 1));
                }
            }
            double[] bounds = points.GetBounds();

            // Add the grid points to a polydata object
            vtkPolyData inputPolyData = vtkPolyData.New();

            inputPolyData.SetPoints(points);

            // Triangulate the grid points
            vtkDelaunay2D delaunay = vtkDelaunay2D.New();

#if VTK_MAJOR_VERSION_5
            delaunay.SetInput(inputPolyData);
#else
            delaunay.SetInputData(inputPolyData);
#endif
            delaunay.Update();

            vtkElevationFilter elevationFilter = vtkElevationFilter.New();
            elevationFilter.SetInputConnection(delaunay.GetOutputPort());
            elevationFilter.SetLowPoint(0.0, 0.0, bounds[4]);
            elevationFilter.SetHighPoint(0.0, 0.0, bounds[5]);
            elevationFilter.Update();

            vtkPolyData output = vtkPolyData.New();
            output.ShallowCopy(vtkPolyData.SafeDownCast(elevationFilter.GetOutput()));

            vtkFloatArray elevation =
                vtkFloatArray.SafeDownCast(output.GetPointData().GetArray("Elevation"));

            // Create the color map
            vtkLookupTable colorLookupTable = vtkLookupTable.New();
            colorLookupTable.SetTableRange(bounds[4], bounds[5]);
            colorLookupTable.Build();

            // Generate the colors for each point based on the color map
            vtkUnsignedCharArray colors = vtkUnsignedCharArray.New();
            colors.SetNumberOfComponents(3);
            colors.SetName("Colors");

            for (int i = 0; i < output.GetNumberOfPoints(); i++)
            {
                double val = elevation.GetValue(i);
                Debug.WriteLine("val: " + val);

                double[] dcolor = colorLookupTable.GetColor(val);
                //Debug.WriteLine("dcolor: "
                //          + dcolor[0] + " "
                //          + dcolor[1] + " "
                //          + dcolor[2]);
                byte[] color = new byte[3];
                for (int j = 0; j < 3; j++)
                {
                    color[j] = (byte)(255 * dcolor[j]);
                }
                //Debug.WriteLine("color: "
                //          + color[0] + " "
                //          + color[1] + " "
                //          + color[2]);

                colors.InsertNextTuple3(color[0], color[1], color[2]);
            }

            output.GetPointData().AddArray(colors);

            // Visualize
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            mapper.SetInputConnection(output.GetProducerPort());
#else
            mapper.SetInputData(output);
#endif

            vtkActor actor = vtkActor.New();
            actor.SetMapper(mapper);

            // 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);
        }
Exemplo n.º 7
0
        private void ColoredLines()
        {
            // Create three points. Join (Origin and P0) with a red line and
            // (Origin and P1) with a green line
            double[] origin = new double[] { 0.0, 0.0, 0.0 };
            double[] p0     = new double[] { 1.0, 0.0, 0.0 };
            double[] p1     = new double[] { 0.0, 1.0, 0.0 };

            // Create a vtkPoints object and store the points in it
            vtkPoints pts = vtkPoints.New();

            pts.InsertNextPoint(origin[0], origin[1], origin[2]);
            pts.InsertNextPoint(p0[0], p0[1], p0[2]);
            pts.InsertNextPoint(p1[0], p1[1], p1[2]);

            // Setup two colors - one for each line
            byte[] red   = new byte[] { 255, 0, 0 };
            byte[] green = new byte[] { 0, 255, 0 };

            // Setup the colors array
            vtkUnsignedCharArray colors = vtkUnsignedCharArray.New();

            colors.SetNumberOfComponents(3);
            colors.SetName("Colors");

            // Add the colors we created to the colors array
            colors.InsertNextValue(red[0]);
            colors.InsertNextValue(red[1]);
            colors.InsertNextValue(red[2]);

            colors.InsertNextValue(green[0]);
            colors.InsertNextValue(green[1]);
            colors.InsertNextValue(green[2]);

            // Create the first line (between Origin and P0)
            vtkLine line0 = vtkLine.New();

            line0.GetPointIds().SetId(0, 0); //the second 0 is the index of the Origin in the vtkPoints
            line0.GetPointIds().SetId(1, 1); //the second 1 is the index of P0 in the vtkPoints

            // Create the second line (between Origin and P1)
            vtkLine line1 = vtkLine.New();

            line1.GetPointIds().SetId(0, 0); //the second 0 is the index of the Origin in the vtkPoints
            line1.GetPointIds().SetId(1, 2); //2 is the index of P1 in the vtkPoints

            // Create a cell array to store the lines in and add the lines to it
            vtkCellArray lines = vtkCellArray.New();

            lines.InsertNextCell(line0);
            lines.InsertNextCell(line1);

            // Create a polydata to store everything in
            vtkPolyData linesPolyData = vtkPolyData.New();

            // Add the points to the dataset
            linesPolyData.SetPoints(pts);

            // Add the lines to the dataset
            linesPolyData.SetLines(lines);

            // Color the lines - associate the first component (red) of the
            // colors array with the first component of the cell array (line 0)
            // and the second component (green) of the colors array with the
            // second component of the cell array (line 1)
            linesPolyData.GetCellData().SetScalars(colors);

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.SetInput(linesPolyData);
            // create an actor
            vtkActor actor = vtkActor.New();

            actor.SetMapper(mapper);

            RenderAddActor(actor);
        }
Exemplo n.º 8
0
        private void ColoredElevationMap()
        {
            // Create a grid of points (height/terrian map)
            vtkPoints points = vtkPoints.New();

            uint   GridSize = 20;
            double xx, yy, zz;

            for (uint x = 0; x < GridSize; x++)
            {
                for (uint y = 0; y < GridSize; y++)
                {
                    xx = x + vtkMath.Random(-.2, .2);
                    yy = y + vtkMath.Random(-.2, .2);
                    zz = vtkMath.Random(-.5, .5);
                    points.InsertNextPoint(xx, yy, zz);
                }
            }

            // Add the grid points to a polydata object
            vtkPolyData inputPolyData = vtkPolyData.New();

            inputPolyData.SetPoints(points);

            // Triangulate the grid points
            vtkDelaunay2D delaunay = vtkDelaunay2D.New();

#if VTK_MAJOR_VERSION_5
            delaunay.SetInput(inputPolyData);
#else
            delaunay.SetInputData(inputPolyData);
#endif
            delaunay.Update();
            vtkPolyData outputPolyData = delaunay.GetOutput();

            double[] bounds = outputPolyData.GetBounds();

            // Find min and max z
            double minz = bounds[4];
            double maxz = bounds[5];

            Debug.WriteLine("minz: " + minz);
            Debug.WriteLine("maxz: " + maxz);

            // Create the color map
            vtkLookupTable colorLookupTable = vtkLookupTable.New();
            colorLookupTable.SetTableRange(minz, maxz);
            colorLookupTable.Build();

            // Generate the colors for each point based on the color map
            vtkUnsignedCharArray colors = vtkUnsignedCharArray.New();
            colors.SetNumberOfComponents(3);
            colors.SetName("Colors");

            Debug.WriteLine("There are " + outputPolyData.GetNumberOfPoints()
                            + " points.");


#if UNSAFE // fastest way to fill color array
            colors.SetNumberOfTuples(outputPolyData.GetNumberOfPoints());
            unsafe {
                byte *pColor = (byte *)colors.GetPointer(0).ToPointer();

                for (int i = 0; i < outputPolyData.GetNumberOfPoints(); i++)
                {
                    double[] p = outputPolyData.GetPoint(i);

                    double[] dcolor = colorLookupTable.GetColor(p[2]);
                    Debug.WriteLine("dcolor: "
                                    + dcolor[0] + " "
                                    + dcolor[1] + " "
                                    + dcolor[2]);

                    byte[] color = new byte[3];
                    for (uint j = 0; j < 3; j++)
                    {
                        color[j] = (byte)(255 * dcolor[j]);
                    }
                    Debug.WriteLine("color: "
                                    + color[0] + " "
                                    + color[1] + " "
                                    + color[2]);

                    *(pColor + 3 * i)     = color[0];
                    *(pColor + 3 * i + 1) = color[1];
                    *(pColor + 3 * i + 2) = color[2];
                }
            }
#else
            for (int i = 0; i < outputPolyData.GetNumberOfPoints(); i++)
            {
                double[] p = outputPolyData.GetPoint(i);

                double[] dcolor = colorLookupTable.GetColor(p[2]);
                Debug.WriteLine("dcolor: "
                                + dcolor[0] + " "
                                + dcolor[1] + " "
                                + dcolor[2]);

                byte[] color = new byte[3];
                for (uint j = 0; j < 3; j++)
                {
                    color[j] = (byte)(255 * dcolor[j]);
                }
                Debug.WriteLine("color: "
                                + color[0] + " "
                                + color[1] + " "
                                + color[2]);
                colors.InsertNextTuple3(color[0], color[1], color[2]);
                //IntPtr pColor = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(byte)) * 3);
                //Marshal.Copy(color, 0, pColor, 3);
                //colors.InsertNextTupleValue(pColor);
                //Marshal.FreeHGlobal(pColor);
            }
#endif

            outputPolyData.GetPointData().SetScalars(colors);

            // Create a mapper and actor
            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
#if VTK_MAJOR_VERSION_5
            mapper.SetInputConnection(outputPolyData.GetProducerPort());
#else
            mapper.SetInputData(outputPolyData);
#endif

            vtkActor actor = vtkActor.New();
            actor.SetMapper(mapper);

            // 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);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Calculates mean and standard deviation images from volume-of-interest. Obsolete.
        /// </summary>
        /// <param name="output"></param>
        /// <param name="mu"></param>
        /// <param name="std"></param>
        /// <param name="input"></param>
        /// <param name="depth"></param>
        /// <param name="threshold"></param>
        public static void get_voi_mu_std(out vtkImageData output, out double[,] mu, out double[,] std, vtkImageData input, int depth, double threshold = 70.0)
        {
            //Get data extent
            int[] dims = input.GetExtent();
            int   h    = dims[1] - dims[0] + 1;
            int   w    = dims[3] - dims[2] + 1;
            int   d    = dims[5] - dims[4] + 1;

            //Compute strides
            int stridew = 1;
            int strideh = w;
            int strided = h * w;

            byte[] bytedata = DataTypes.vtkToByte(input);
            byte[] voidata  = new byte[bytedata.Length];

            double[,] _mu  = new double[h, w];
            double[,] _std = new double[h, w];

            //Get voi indices
            Parallel.For(24, h - 24, (int y) =>
            {
                Parallel.For(24, w - 24, (int x) =>
                {
                    int start = d - 1;
                    int stop  = 0;
                    //Compute mean
                    for (int z = d - 1; z > 0; z -= 1)
                    {
                        int pos    = z * strided + y * strideh + x * stridew;
                        double val = (double)bytedata[pos];
                        if (val >= threshold)
                        {
                            start = z;
                            stop  = Math.Max(z - depth, 0);
                            //Compute mean and std
                            for (int zz = start; zz > stop; zz -= 1)
                            {
                                int newpos      = zz * strided + y * strideh + x * stridew;
                                double newval   = (double)bytedata[newpos];
                                voidata[newpos] = (byte)newval;
                                _mu[y, x]       = newval / (double)depth;
                            }

                            for (int zz = start; zz > stop; zz -= 1)
                            {
                                int newpos    = zz * strided + y * strideh + x * stridew;
                                double newval = (double)bytedata[newpos];
                                _std[y, x]   += ((double)newval - _mu[y, x]) * ((double)newval - _mu[y, x]);
                            }

                            _std[y, x] = Math.Pow(_std[y, x] / (depth - 1), 0.5);
                            break;
                        }
                    }
                });
            });

            mu     = _mu;
            std    = _std;
            output = vtkImageData.New();
            //Copy voi data to input array
            vtkUnsignedCharArray charArray = vtkUnsignedCharArray.New();
            //Pin byte array
            GCHandle pinnedArray = GCHandle.Alloc(voidata, GCHandleType.Pinned);

            //Set character array input
            charArray.SetArray(pinnedArray.AddrOfPinnedObject(), h * w * d, 1);
            //Set vtkdata properties and connect array
            //Data from char array
            output.GetPointData().SetScalars(charArray);
            //Number of scalars/pixel
            output.SetNumberOfScalarComponents(1);
            //Data extent, 1st and last axis are swapped from the char array
            //Data is converted back to original orientation
            output.SetExtent(dims[0], dims[1], dims[2], dims[3], dims[4], dims[5]);
            //Scalar type
            output.SetScalarTypeToUnsignedChar();
            output.Update();
        }
Exemplo n.º 10
0
		private static vtkImageData CreateVtkVolume(Volume volume)
		{
			var vtkVolume = new vtkImageData();
			vtkVolume.RegisterVtkErrorEvents();
			vtkVolume.SetDimensions(volume.ArrayDimensions.Width, volume.ArrayDimensions.Height, volume.ArrayDimensions.Depth);
			vtkVolume.SetOrigin(0, 0, 0);
			vtkVolume.SetSpacing(volume.VoxelSpacing.X, volume.VoxelSpacing.Y, volume.VoxelSpacing.Z);

			if (volume.BitsPerVoxel == 16)
			{
				if (!volume.Signed)
				{
					using (var array = new vtkUnsignedShortArray())
					{
						array.SetArray((ushort[]) volume.Array, (VtkIdType) volume.ArrayLength, 1);

						vtkVolume.SetScalarTypeToUnsignedShort();
						vtkVolume.GetPointData().SetScalars(array);
					}
				}
				else
				{
					using (var array = new vtkShortArray())
					{
						array.SetArray((short[]) volume.Array, (VtkIdType) volume.ArrayLength, 1);

						vtkVolume.SetScalarTypeToShort();
						vtkVolume.GetPointData().SetScalars(array);
					}
				}
			}
			else if (volume.BitsPerVoxel == 8)
			{
				if (!volume.Signed)
				{
					using (var array = new vtkUnsignedCharArray())
					{
						array.SetArray((byte[]) volume.Array, (VtkIdType) volume.ArrayLength, 1);

						vtkVolume.SetScalarTypeToUnsignedChar();
						vtkVolume.GetPointData().SetScalars(array);
					}
				}
				else
				{
					using (var array = new vtkSignedCharArray())
					{
						array.SetArray((sbyte[]) volume.Array, (VtkIdType) volume.ArrayLength, 1);

						vtkVolume.SetScalarTypeToSignedChar();
						vtkVolume.GetPointData().SetScalars(array);
					}
				}
			}
			else
			{
				throw new NotSupportedException("Unsupported volume scalar type.");
			}

			// This call is necessary to ensure vtkImageData data's info is correct (e.g. updates WholeExtent values)
			vtkVolume.UpdateInformation();

			return vtkVolume;
		}
Exemplo n.º 11
0
        public void SetPosition(List <double[]> xyz1, List <double> radius)
        {
            this._xyz = xyz1;
            _points   = vtkPoints.New();

            for (int index = 0; index < xyz1.Count; index++)
            {
                double[] doubles = xyz1[index];
                _points.InsertPoint(index, doubles[0], doubles[1], doubles[2]);
            }

            _lines = vtkCellArray.New();
            _lines.InsertNextCell(xyz1.Count);

            for (int index = 0; index < xyz1.Count; index++)
            {
                _lines.InsertCellPoint(index);
            }

            _profileData = vtkPolyData.New();
            _profileData.SetPoints(_points);
            _profileData.SetLines(_lines);
            _profileData.BuildLinks((int)_points.GetNumberOfPoints());

            vtkUnsignedCharArray radiusArray = vtkUnsignedCharArray.New();

            radiusArray.SetNumberOfComponents(1);
            foreach (var item in radius)
            {
                radiusArray.InsertNextTuple1(Math.Max(1, item));
            }

            _profileData.GetPointData().SetScalars(radiusArray);

            _profileData.Update();

            _cleanFilter = vtkCleanPolyData.New();
            _cleanFilter.SetInput(_profileData);
            _cleanFilter.Update();

            _profileTubes = vtkTubeFilter.New();
            //_profileTubes.CappingOn();
            _profileTubes.SetNumberOfSides(20);
            //_profileTubes.SetInput(_cleanFilter.GetOutput());
            _profileTubes.SetInput(_profileData);
            _profileTubes.SetVaryRadiusToVaryRadiusOff();
            _profileTubes.SetVaryRadiusToVaryRadiusByScalar();

            double[] tuberad_range = radiusArray.GetRange();

            _profileTubes.SetRadius(tuberad_range[0]);
            _profileTubes.SetRadiusFactor(tuberad_range[1] / tuberad_range[0]);

            //_profileTubes.SetRadius(0.5);
            //_profileTubes.SetRadiusFactor(20);
            //_profileTubes.Update();

            //_profileTubes.SetInputArrayToProcess(1, 0, 0, 0, "vectors");

            //vtkPolyDataMapper profileMapper = new vtkPolyDataMapper();
            //profileMapper.SetInputConnection(profileTubes.GetOutputPort());

            PolyData = _profileTubes.GetOutput();

            _mapper = vtkPolyDataMapper.New();
            _mapper.ScalarVisibilityOff();
            _mapper.SetInput(_profileTubes.GetOutput());

            centerLineActor.SetMapper(_mapper);
        }
Exemplo n.º 12
0
        private static vtkImageData CreateVtkVolume(Volume volume)
        {
            var vtkVolume = new vtkImageData();

            vtkVolume.RegisterVtkErrorEvents();
            vtkVolume.SetDimensions(volume.ArrayDimensions.Width, volume.ArrayDimensions.Height, volume.ArrayDimensions.Depth);
            vtkVolume.SetOrigin(0, 0, 0);
            vtkVolume.SetSpacing(volume.VoxelSpacing.X, volume.VoxelSpacing.Y, volume.VoxelSpacing.Z);

            if (volume.BitsPerVoxel == 16)
            {
                if (!volume.Signed)
                {
                    using (var array = new vtkUnsignedShortArray())
                    {
                        array.SetArray((ushort[])volume.Array, (VtkIdType)volume.ArrayLength, 1);

                        vtkVolume.SetScalarTypeToUnsignedShort();
                        vtkVolume.GetPointData().SetScalars(array);
                    }
                }
                else
                {
                    using (var array = new vtkShortArray())
                    {
                        array.SetArray((short[])volume.Array, (VtkIdType)volume.ArrayLength, 1);

                        vtkVolume.SetScalarTypeToShort();
                        vtkVolume.GetPointData().SetScalars(array);
                    }
                }
            }
            else if (volume.BitsPerVoxel == 8)
            {
                if (!volume.Signed)
                {
                    using (var array = new vtkUnsignedCharArray())
                    {
                        array.SetArray((byte[])volume.Array, (VtkIdType)volume.ArrayLength, 1);

                        vtkVolume.SetScalarTypeToUnsignedChar();
                        vtkVolume.GetPointData().SetScalars(array);
                    }
                }
                else
                {
                    using (var array = new vtkSignedCharArray())
                    {
                        array.SetArray((sbyte[])volume.Array, (VtkIdType)volume.ArrayLength, 1);

                        vtkVolume.SetScalarTypeToSignedChar();
                        vtkVolume.GetPointData().SetScalars(array);
                    }
                }
            }
            else
            {
                throw new NotSupportedException("Unsupported volume scalar type.");
            }

            // This call is necessary to ensure vtkImageData data's info is correct (e.g. updates WholeExtent values)
            vtkVolume.UpdateInformation();

            return(vtkVolume);
        }