Example #1
0
        public cBiologicalSpot(Color Colour, cPoint3D Pos, double Intensity, double Radius, List<cInteractive3DObject> Containers, int ContainerMode)
        {
            this.Intensity = Intensity;

            this.Detected = true;

            this.Intensity = Intensity;
            VTK_Sphere = vtkSphereSource.New();
            VTK_Sphere.SetThetaResolution(10);
            VTK_Sphere.SetPhiResolution(10);
            VTK_Sphere.SetRadius(Radius);
            vtk_PolyDataMapper = vtkPolyDataMapper.New();
            vtk_PolyDataMapper.SetInputConnection(VTK_Sphere.GetOutputPort());

            this.SetPosition(new cPoint3D(Pos.X, Pos.Y, Pos.Z));
            this.Colour = Colour;

            CreateVTK3DObject(1);
            Information = new cInformation(this);

            this.Detected = true;

            /*
            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);
            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.Count; Idx++)
            {
                cBiological3DVolume CurrentContainer = (cBiological3DVolume)(Containers[Idx]);

                if (CurrentContainer.IsPointInside(Centroid))
                {
                    IsInside = true;
                    ContainerIdx = Idx;
                    break;
                }
            }
            if (IsInside)
            {
                this.Position = new cPoint3D(Pos.X, Pos.Y, Pos.Z);
                this.Colour = Colour;

                CreateVTK3DObject(1);

                vtk_PolyData = ContourObject.GetOutput();
                //  this.BackfaceCulling(false);

                Information = new cInformation(ContourObject, this);
                this.Detected = true;
            }
            else
            {
                this.Detected = false;
            }*/
        }
Example #2
0
        /// <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 cBiologicalSpot(Color Colour, cPoint3D Pos, double Intensity, double Radius)
        {
            this.Intensity = Intensity;
            VTK_Sphere = vtkSphereSource.New();
            VTK_Sphere.SetThetaResolution(6);
            VTK_Sphere.SetPhiResolution(6);
            VTK_Sphere.SetRadius(Radius);
            vtk_PolyDataMapper = vtkPolyDataMapper.New();
            vtk_PolyDataMapper.SetInputConnection(VTK_Sphere.GetOutputPort());

            this.SetPosition(new cPoint3D(Pos.X, Pos.Y, Pos.Z));
            this.Colour = Colour;

            CreateVTK3DObject(1);
            Information = new cInformation(this);
        }
Example #3
0
        public c3DWell(cPoint3D MinPt, cPoint3D MaxPt, Color Colour, cWell CurrentWell)
        {
            this.SetPosition(new cPoint3D(0, 0, 0));

            this.Colour = Colour;
            VTK_Cube = vtkCubeSource.New();
            //VTK_Cube.SetBounds(MinPt.X, MaxPt.X, MinPt.Y, MaxPt.Y, MinPt.Z, MaxPt.Z);
            VTK_Cube.SetXLength(MaxPt.X - MinPt.X);
            VTK_Cube.SetYLength(MaxPt.Y - MinPt.Y);
            VTK_Cube.SetZLength(MaxPt.Z - MinPt.Z);

            vtk_PolyDataMapper = vtkPolyDataMapper.New();
            vtk_PolyDataMapper.SetInputConnection(VTK_Cube.GetOutputPort());

            this.SetPosition(MinPt);
            this.Colour = Colour;
            this.AssociatedWell = CurrentWell;

            CreateVTK3DObject(1);
            Information = new cInformation(this);
        }
Example #4
0
        //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
        }
Example #5
0
        public void Generate(CImage3D 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.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;

            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

            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(AlgoOutPut);
            hullFilter.AddRecursiveSpherePlanes(1);
            hullFilter.Update();

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

            #endregion
        }