Exemple #1
0
        private vtkImageData CreateVtkVolume()
        {
            vtkImageData vtkVolume = new vtkImageData();

            VtkHelper.RegisterVtkErrorEvents(vtkVolume);

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

            if (!this.Signed)
            {
                vtkVolume.SetScalarTypeToUnsignedShort();
                vtkVolume.GetPointData().SetScalars(
                    VtkHelper.ConvertToVtkUnsignedShortArray(_volumeDataUInt16));
            }
            else
            {
                vtkVolume.SetScalarTypeToShort();
                vtkVolume.GetPointData().SetScalars(
                    VtkHelper.ConvertToVtkShortArray(_volumeDataInt16));
            }

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

            return(vtkVolume);
        }
Exemple #2
0
        private vtkImageData CreateVolumeImageData()
        {
            vtkImageData imageData = new vtkImageData();

            imageData.SetDimensions(this.Width, this.Height, this.Depth);
            imageData.SetSpacing(GetFirstFrame().PixelSpacing.Column, GetFirstFrame().PixelSpacing.Row, GetSliceSpacing());
            imageData.AllocateScalars();
            imageData.SetScalarTypeToUnsignedShort();
            imageData.GetPointData().SetScalars(BuildVolumeImageData());

            return(imageData);
        }
        private void Window_Activated(object sender, EventArgs e)
        {
            // 一定要先 vtkformhost.Child = vtkControl;下面三条顺序不能乱 否则报错 切记!
            vtkformhost.Child = vtkControl;
            vtkRenderWindow renWin    = vtkControl.RenderWindow;
            vtkRenderer     aRenderer = renWin.GetRenderers().GetFirstRenderer();

            renWin.AddRenderer(aRenderer);

            Marshal.Copy(ys1, 0, temp128, imgLine * imgPixel * imgNum);


            temp.SetArray(temp128, imgLine * imgPixel * imgNum, 1);

            testimgdata.SetDimensions(imgLine, imgPixel, imgNum);
            testimgdata.SetSpacing(1, 1, 4);
            testimgdata.SetScalarTypeToUnsignedChar();
            testimgdata.SetNumberOfScalarComponents(1);
            testimgdata.AllocateScalars();
            testimgdata.GetPointData().SetScalars(temp);
            testimgdata.Modified();

            VtkSetColor();
            VtkSetOpacity();

            volumeProperty.SetColor(colorTransferFunction);
            volumeProperty.SetScalarOpacity(opacityTransferFunction);
            volumeProperty.ShadeOn();
            volumeProperty.SetInterpolationTypeToLinear();

            volumeMapper.SetVolumeRayCastFunction(compositeFunction);
            volumeMapper.SetInput(testimgdata);

            volume.SetMapper(volumeMapper);
            volume.SetProperty(volumeProperty);

            aCamera.SetViewUp(0, -1, 0);
            aCamera.SetPosition(-1, 0, 1);
            aCamera.ComputeViewPlaneNormal();

            aRenderer.AddVolume(volume);
            aRenderer.SetBackground(0, 0, 0.6);
            aRenderer.SetActiveCamera(aCamera);
            aRenderer.ResetCamera();
            renWin.SetSize(800, 800);
            renWin.Render();
        }
        //把fyGrid转为vtkImageData
        private vtkImageData ConvertfyGrid2vtkImageData(ExGrid Grid)
        {
            vtkImageData ImageData = vtkImageData.New();

            ImageData.SetScalarTypeToUnsignedChar();

            ImageData.SetNumberOfScalarComponents(1);
            ImageData.SetDimensions(Grid.ICount, Grid.JCount, Grid.KCount);
            ImageData.SetSpacing(1, 1, 1);
            ImageData.AllocateScalars();
            byte[] data = new byte[Grid.CellCount];

            for (int i = 0; i < Grid.CellCount; i++)
            {
                data[i] = (byte)Grid.GetCell(i).Value;
            }
            System.Runtime.InteropServices.Marshal.Copy(data, 0, (IntPtr)ImageData.GetScalarPointer(), data.Length);
            return(ImageData);
        }
Exemple #5
0
        private static vtkImageData CreateVtkVolume(short[] data, int width, int height, int depth)
        {
            var vtkVolume = new vtkImageData();

            RegisterVtkErrorEvents(vtkVolume);

            vtkVolume.SetDimensions(width, height, depth);
            vtkVolume.SetOrigin(0, 0, 0);
            vtkVolume.SetSpacing(1.0, 1.0, 1.0);

            using (var array = ConvertToVtkShortArray(data))
            {
                vtkVolume.SetScalarTypeToShort();
                vtkVolume.GetPointData().SetScalars(array);

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

            return(vtkVolume);
        }
Exemple #6
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());
            }
        }
Exemple #7
0
        void CreateVectorField(ref vtkImageData image)
        {
            // Specify the size of the image data
            image.SetDimensions(3, 3, 3);
            image.SetNumberOfScalarComponents(3);
            image.SetScalarTypeToFloat();
            image.AllocateScalars();
            image.SetSpacing(10.0, 10.0, 10.0);
            int[] dims = image.GetDimensions();

            float[] pixel = new float[] { 0.0f, 0.0f, 0.0f };
            IntPtr  pPixel;

            // Zero the vectors
            for (int z = 0; z < dims[2]; z++)
            {
                for (int y = 0; y < dims[1]; y++)
                {
                    for (int x = 0; x < dims[0]; x++)
                    {
                        pPixel = image.GetScalarPointer(x, y, 0);
                        Marshal.Copy(pixel, 0, pPixel, 3);
                    }
                }
            }

            // Set two of the pixels to non zero values
            pixel[0] = 8.0f;
            pixel[1] = 8.0f;
            pixel[2] = -8.0f;
            pPixel   = image.GetScalarPointer(0, 2, 0);
            Marshal.Copy(pixel, 0, pPixel, 3);

            pixel[0] = 8.0f;
            pixel[1] = -8.0f;
            pixel[2] = 8.0f;
            pPixel   = image.GetScalarPointer(2, 0, 2);
            Marshal.Copy(pixel, 0, pPixel, 3);
        }
        void CreateVectorField(ref vtkImageData image)
        {
            // Specify the size of the image data
             image.SetDimensions(3, 3, 3);
             image.SetNumberOfScalarComponents(3);
             image.SetScalarTypeToFloat();
             image.AllocateScalars();
             image.SetSpacing(10.0, 10.0, 10.0);
             int[]  dims = image.GetDimensions();

             float[] pixel = new float[] {0.0f, 0.0f, 0.0f};
             IntPtr pPixel;

             // Zero the vectors
             for(int z = 0; z < dims[2]; z++) {
            for(int y = 0; y < dims[1]; y++) {
               for(int x = 0; x < dims[0]; x++) {
                  pPixel = image.GetScalarPointer(x, y, 0);
                  Marshal.Copy(pixel, 0, pPixel, 3);
               }
            }
             }

             // Set two of the pixels to non zero values
             pixel[0] = 8.0f;
             pixel[1] = 8.0f;
             pixel[2] = -8.0f;
             pPixel = image.GetScalarPointer(0, 2, 0);
             Marshal.Copy(pixel, 0, pPixel, 3);

             pixel[0] = 8.0f;
             pixel[1] = -8.0f;
             pixel[2] = 8.0f;
             pPixel = image.GetScalarPointer(2, 0, 2);
             Marshal.Copy(pixel, 0, pPixel, 3);
        }
Exemple #9
0
		private static vtkImageData CreateVtkVolume(short[] data, int width, int height, int depth)
		{
			var vtkVolume = new vtkImageData();

			RegisterVtkErrorEvents(vtkVolume);

			vtkVolume.SetDimensions(width, height, depth);
			vtkVolume.SetOrigin(0, 0, 0);
			vtkVolume.SetSpacing(1.0, 1.0, 1.0);

			using (var array = ConvertToVtkShortArray(data))
			{
				vtkVolume.SetScalarTypeToShort();
				vtkVolume.GetPointData().SetScalars(array);

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

			return vtkVolume;
		}
		private vtkImageData CreateVolumeImageData()
		{
			vtkImageData imageData = new vtkImageData();
			imageData.SetDimensions(this.Width, this.Height, this.Depth);
			imageData.SetSpacing(GetFirstFrame().PixelSpacing.Column, GetFirstFrame().PixelSpacing.Row, GetSliceSpacing());
			imageData.AllocateScalars();
			imageData.SetScalarTypeToUnsignedShort();
			imageData.GetPointData().SetScalars(BuildVolumeImageData());
			
			return imageData;
		}
Exemple #11
0
		private vtkImageData CreateVtkVolume()
		{
			vtkImageData vtkVolume = new vtkImageData();

			VtkHelper.RegisterVtkErrorEvents(vtkVolume);

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

			if (!this.Signed)
			{
				vtkVolume.SetScalarTypeToUnsignedShort();
				vtkVolume.GetPointData().SetScalars(
					VtkHelper.ConvertToVtkUnsignedShortArray(_volumeDataUInt16));
			}
			else
			{
				vtkVolume.SetScalarTypeToShort();
				vtkVolume.GetPointData().SetScalars(
					VtkHelper.ConvertToVtkShortArray(_volumeDataInt16));
			}

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

			return vtkVolume;
		}
Exemple #12
0
        static public vtkProp3D genFieldActor(FieldBase data)
        {
            int    N_width = data.Ex.Count;
            int    M_depth = data.Ex.Count;
            double ds      = data.ds_x;
            double width   = N_width * ds;
            double depth   = M_depth * ds;

            vtkImageData img = vtkImageData.New();

            img.SetDimensions(N_width, M_depth, 1);
            img.SetSpacing(0.01 * ds / 0.01, 0.01 * ds / 0.01, 1);
            img.SetScalarTypeToDouble();
            img.SetNumberOfScalarComponents(1);

            double max = -100000000, min = 0;
            List <List <Complex> > tempEH = null;

            int          content          = 1;
            bool         isPhs            = false;
            bool         isLinear         = true;
            const double dB_RABNGE        = 60;

            switch (content)
            {
            case 0:
                tempEH = data.Ex;
                break;

            case 1:
                tempEH = data.Ey;
                break;

            case 2:
                tempEH = data.Ez;
                break;

            case 3:
                tempEH = data.Hx;
                break;

            case 4:
                tempEH = data.Hy;
                break;

            case 5:
                tempEH = data.Hz;
                break;

            default:
                break;
            }
            double[] data_tmp = new double[M_depth * N_width];
            int      count    = 0;

            for (int j = 0; j < M_depth; j++)
            {
                for (int i = 0; i < N_width; i++)
                {
                    double  tempD;
                    Complex temp;
                    temp = tempEH[i][j];

                    if (isPhs)
                    {
                        if (temp.real != 0)
                        {
                            tempD = Math.Atan2(temp.imag, temp.real);
                        }
                        else
                        {
                            tempD = 0;
                        }
                    }
                    else
                    {
                        tempD = Math.Pow((temp.real * temp.real + temp.imag * temp.imag), 0.5);
                    }
                    if (!isLinear && !isPhs)
                    {
                        tempD = 20 * Math.Log(tempD + 0.000000001);
                        if (min > tempD)
                        {
                            min = tempD;
                        }
                        if (max < tempD)
                        {
                            max = tempD;
                        }
                    }
                    else
                    {
                        if (max < tempD)
                        {
                            max = tempD;
                        }
                        if (min > tempD)
                        {
                            min = tempD;
                        }
                    }
                    data_tmp[count++] = tempD;
                }
            }

            //ptr = img.GetScalarPointer();
            vtkLookupTable colorTable = vtkLookupTable.New();

            if (!isLinear && !isPhs)
            {
                min = max - dB_RABNGE;
            }
            if (!isPhs)
            {
                for (int i = 0; i < N_width * M_depth * 1; i++)
                {
                    data_tmp[i] = max - data_tmp[i];
                }
                colorTable.SetRange(0, max - min);
            }
            else
            {
                colorTable.SetRange(min, max);
            }

            IntPtr ptr = img.GetScalarPointer();

            System.Runtime.InteropServices.Marshal.Copy(data_tmp, 0, ptr, M_depth * N_width);
            colorTable.Build();

            vtkImageMapToColors colorMap = vtkImageMapToColors.New();

            colorMap.SetInput(img);
            colorMap.SetLookupTable(colorTable);
            colorMap.Update();

            vtkTransform transform = vtkTransform.New();

            transform.Translate(data.coordinate.pos.x, data.coordinate.pos.y, data.coordinate.pos.z);
            transform.RotateWXYZ(data.coordinate.rotate_theta, data.coordinate.rotate_axis.x,
                                 data.coordinate.rotate_axis.y, data.coordinate.rotate_axis.z);
            transform.Translate(-width / 2, -depth / 2, 0);

            vtkImageActor actor = vtkImageActor.New();

            actor.SetInput(colorMap.GetOutput());
            actor.SetUserTransform(transform);

            return(actor);
        }
        //private void CommonInit(Sequence BinarySubImageSeq)
        //{
        //    vtkImageData ImageData1 = new vtkImageData();
        //    ImageData1.SetDimensions(BinarySubImageSeq.Width, BinarySubImageSeq.Height, BinarySubImageSeq.Depth);
        //    ImageData1.SetNumberOfScalarComponents(1);
        //    ImageData1.SetSpacing(BinarySubImageSeq.XResolution, BinarySubImageSeq.YResolution, BinarySubImageSeq.ZResolution);
        //    ImageData1.SetScalarTypeToFloat();
        //    vtkFloatArray array1 = new vtkFloatArray();
        //    for (int i = 0; i < BinarySubImageSeq.ImageSize; i++)
        //        array1.InsertTuple1(i, BinarySubImageSeq[0].Data[0][i]);
        //    ImageData1.GetPointData().SetScalars(array1);
        //    vtkExtractVOI VOI = new vtkExtractVOI();
        //    VOI.SetInput(ImageData1);
        //    VOI.SetSampleRate(1, 1, 1);
        //    vtkMarchingCubes ContourObject = vtkMarchingCubes.New();
        //    vtk_PolyDataMapper = vtkPolyDataMapper.New();
        //    //ContourActor = new vtkActor();
        //    VOI.SetVOI(0, BinarySubImageSeq.Width - 1, 0, BinarySubImageSeq.Height - 1, 0, BinarySubImageSeq.Depth - 1);
        //    ContourObject.SetInput(VOI.GetOutput());
        //    ContourObject.SetValue(0, 0.5);
        //    vtk_PolyDataMapper.SetInput(ContourObject.GetOutput());
        //    vtk_PolyDataMapper.ScalarVisibilityOn();
        //    vtk_PolyDataMapper.SetScalarModeToUseFieldData();
        //}
        ///// <summary>
        ///// Generate a 3D mesh using marching-cubes algorithm. If voxel value is lower than 1 it is consider as background, else as object
        ///// </summary>
        ///// <param name="BinarySubImageSeq">The binary image</param>
        ///// <param name="Colour">Mesh color</param>
        ///// <param name="Pos">Postion of the object in the world</param>
        //public void Generate(Sequence BinarySubImageSeq, Color Colour, cPoint3D Pos)
        //{
        //    vtkImageData ImageData1 = new vtkImageData();
        //    ImageData1.SetDimensions(BinarySubImageSeq.Width, BinarySubImageSeq.Height, BinarySubImageSeq.Depth);
        //    ImageData1.SetNumberOfScalarComponents(1);
        //    ImageData1.SetSpacing(BinarySubImageSeq.XResolution, BinarySubImageSeq.YResolution, BinarySubImageSeq.ZResolution);
        //    ImageData1.SetScalarTypeToFloat();
        //    vtkFloatArray array1 = new vtkFloatArray();
        //    for (int i = 0; i < BinarySubImageSeq.ImageSize; i++)
        //        array1.InsertTuple1(i, BinarySubImageSeq[0].Data[0][i]);
        //    ImageData1.GetPointData().SetScalars(array1);
        //    vtkExtractVOI VOI = new vtkExtractVOI();
        //    VOI.SetInput(ImageData1);
        //    VOI.SetSampleRate(1, 1, 1);
        //    vtkMarchingCubes ContourObject = vtkMarchingCubes.New();
        //    vtk_PolyDataMapper = vtkPolyDataMapper.New();
        //    //ContourActor = new vtkActor();
        //    VOI.SetVOI(0, BinarySubImageSeq.Width - 1, 0, BinarySubImageSeq.Height - 1, 0, BinarySubImageSeq.Depth - 1);
        //    // perform the amrching cubes
        //    ContourObject.SetInput(VOI.GetOutput());
        //    ContourObject.SetValue(0, 0.5);
        //    //vtkDecimatePro deci
        //    //deci SetInputConnection [fran GetOutputPort]
        //    //deci SetTargetReduction 0.9
        //    //deci PreserveTopologyOn
        //    if (MeshSmoother!=null)
        //    {
        //        vtkSmoothPolyDataFilter smoother = new vtkSmoothPolyDataFilter();
        //        smoother.SetInputConnection(ContourObject.GetOutputPort());// [deci GetOutputPort]
        //        smoother.SetNumberOfIterations(50);
        //        vtk_PolyData = smoother.GetOutput();
        //    }
        //    else
        //    {
        //        vtk_PolyData = ContourObject.GetOutput();
        //    }
        //    vtk_PolyDataMapper.SetInput(vtk_PolyData);
        //    vtk_PolyDataMapper.ScalarVisibilityOn();
        //    vtk_PolyDataMapper.SetScalarModeToUseFieldData();
        //    this.Position = new cPoint3D(Pos.X, Pos.Y, Pos.Z);
        //    this.Colour = Colour;
        //    CreateVTK3DObject(1);
        //    vtk_PolyData = ContourObject.GetOutput();
        //    // compute convex hull
        //    hullFilter = vtkHull.New();
        //    hullFilter.SetInputConnection(ContourObject.GetOutputPort());
        //    hullFilter.AddRecursiveSpherePlanes(1);
        //    hullFilter.Update();
        //    //  this.BackfaceCulling(false);
        //    Information = new cInformation(ContourObject, this, hullFilter);
        //}
        public void Generate(cImage BinarySubImageSeq, Color Colour, cPoint3D Pos/*, List<cBiological3DObject> Containers, int ContainerMode*/)
        {
            vtkImageData ImageData1 = new vtkImageData();

            ImageData1.SetDimensions(BinarySubImageSeq.Width, BinarySubImageSeq.Height, BinarySubImageSeq.Depth);
            ImageData1.SetNumberOfScalarComponents(1);
            ImageData1.SetSpacing(BinarySubImageSeq.Resolution.X, BinarySubImageSeq.Resolution.Y, BinarySubImageSeq.Resolution.Z);
            ImageData1.SetScalarTypeToFloat();

            vtkFloatArray array1 = new vtkFloatArray();
            for (int i = 0; i < BinarySubImageSeq.ImageSize; i++)
                array1.InsertTuple1(i, BinarySubImageSeq.SingleChannelImage[0].Data[i]);
            ImageData1.GetPointData().SetScalars(array1);

            vtkExtractVOI VOI = new vtkExtractVOI();
            VOI.SetInput(ImageData1);
            VOI.SetSampleRate(1, 1, 1);

            vtkMarchingCubes ContourObject = vtkMarchingCubes.New();
            vtk_PolyDataMapper = vtkPolyDataMapper.New();
            //ContourActor = new vtkActor();

            VOI.SetVOI(0, BinarySubImageSeq.Width - 1, 0, BinarySubImageSeq.Height - 1, 0, BinarySubImageSeq.Depth - 1);
            ContourObject.SetInput(VOI.GetOutput());
            ContourObject.SetValue(0, 0.5);

            vtkAlgorithmOutput AlgoOutPut = null;

            if (MeshSmoother != null)
            {
                //vtkSmoothPolyDataFilter smoother = new vtkSmoothPolyDataFilter();
                vtkWindowedSincPolyDataFilter smoother = new vtkWindowedSincPolyDataFilter();
                smoother.SetInputConnection(ContourObject.GetOutputPort());// [deci GetOutputPort]
                smoother.SetNumberOfIterations(MeshSmoother.NumberOfIterations);
                vtk_PolyData = smoother.GetOutput();
                //smoother.GetOutputPort();
                AlgoOutPut = smoother.GetOutputPort();
            }
            else
            {
                vtk_PolyData = ContourObject.GetOutput();
                AlgoOutPut = ContourObject.GetOutputPort();
            }

            vtk_PolyDataMapper.SetInput(vtk_PolyData);
            vtk_PolyDataMapper.ScalarVisibilityOn();
            vtk_PolyDataMapper.SetScalarModeToUseFieldData();

            vtkActor TmpActor = vtkActor.New();
            TmpActor.SetMapper(vtk_PolyDataMapper);
            TmpActor.SetPosition(Pos.X, Pos.Y, Pos.Z);

            //Console.WriteLine("PosX"+Pos.X+" PosY"+Pos.Y+" PosZ"+Pos.Z);

            #region deal with the containers

            if (this.Containers != null)
            {
                if (this.Containers.ContainerMode == 0)
                {
                    cPoint3D Centroid = new cPoint3D((float)TmpActor.GetCenter()[0], (float)TmpActor.GetCenter()[1], (float)TmpActor.GetCenter()[2]);
                    bool IsInside = false;

                    for (int Idx = 0; Idx < Containers.Containers.Count; Idx++)
                    {
                        cBiological3DVolume CurrentContainer = (cBiological3DVolume)(Containers.Containers[Idx]);

                        if (CurrentContainer.IsPointInside(Centroid))
                        {
                            IsInside = true;
                            ContainerIdx = Idx;
                            break;
                        }
                    }
                    if (IsInside)
                    {
                        this.SetPosition(new cPoint3D(Pos.X, Pos.Y, Pos.Z));
                        this.Colour = Colour;
                        CreateVTK3DObject(1);
                        //   vtk_PolyData = ContourObject.GetOutput();

                        // compute convex hull
                        hullFilter = vtkHull.New();
                        hullFilter.SetInputConnection(AlgoOutPut);
                        hullFilter.AddRecursiveSpherePlanes(0);
                        hullFilter.Update();

                        Information = new cInformation(AlgoOutPut, this, hullFilter);
                        this.Detected = true;
                    }
                    else
                    {
                        this.Detected = false;
                    }
                }
                else if (Containers.ContainerMode == 1)
                {
                    this.Detected = true;
                    //bool IsInside = false;
                    for (int Idx = 0; Idx < Containers.Containers.Count; Idx++)
                    {
                        cBiological3DVolume CurrentContainer = (cBiological3DVolume)(Containers.Containers[Idx]);

                        if (CurrentContainer.IsPointInside(Pos))
                        {
                            //IsInside = false;
                            this.Detected = false;
                            return;
                        }
                    }
                    this.SetPosition(new cPoint3D(Pos.X, Pos.Y, Pos.Z));
                    this.Colour = Colour;

                    CreateVTK3DObject(1);
                    // vtk_PolyData = ContourObject.GetOutput();

                    // compute convex hull
                    hullFilter = vtkHull.New();
                    hullFilter.SetInputConnection(AlgoOutPut);
                    hullFilter.AddRecursiveSpherePlanes(0);
                    hullFilter.Update();

                    Information = new cInformation(AlgoOutPut, this, hullFilter);
                    this.Detected = true;
                }
            }
            else
            {
                this.SetPosition(new cPoint3D(Pos.X, Pos.Y, Pos.Z));
                this.Colour = Colour;

                CreateVTK3DObject(1);

                //  vtk_PolyData = ContourObject.GetOutput();

                // compute convex hull
                hullFilter = vtkHull.New();
                hullFilter.SetInputConnection(AlgoOutPut);
                hullFilter.AddRecursiveSpherePlanes(1);
                hullFilter.Update();

                //  this.BackfaceCulling(false);
                Information = new cInformation(AlgoOutPut, this, hullFilter);

            }

            #endregion
        }
		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;
		}
        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);
        }