Esempio n. 1
0
        public static double[,,] EsapiDoseToDose3dArray(Dose doseEsapi)
        {
            int xSize = doseEsapi.XSize;
            int ySize = doseEsapi.YSize;
            int zSize = doseEsapi.ZSize;

            double[,,] dose3dArray = new double[zSize, ySize, xSize];

            int[,] voxelValuesInPlane = new int[xSize, ySize];
            for (int i = 0; i < zSize; i++)
            {
                doseEsapi.GetVoxels(i, voxelValuesInPlane);

                for (int j = 0; j < ySize; j++)
                {
                    for (int k = 0; k < xSize; k++)
                    {
                        int voxelValue = voxelValuesInPlane[k, j];
                        var doseValue  = doseEsapi.VoxelToDoseValue(voxelValue);
                        dose3dArray[i, j, k] = doseValue.Dose;
                    }
                }
            }

            return(dose3dArray);
        }
Esempio n. 2
0
        //---------------------------------------------------------------------------------------------
        /// <summary>
        /// This method finds the maximum vocel value of the dose matrix
        /// </summary>
        /// <param name="dose">Dose</param>
        /// <returns>Maximum value</returns>
        //---------------------------------------------------------------------------------------------
        static int FindMaxValue(Dose dose)
        {
            int maxValue = 0;

            int[,] buffer = new int[dose.XSize, dose.YSize];
            if (dose != null)
            {
                for (int z = 0; z < dose.ZSize; z++)
                {
                    dose.GetVoxels(z, buffer);
                    for (int y = 0; y < dose.YSize; y++)
                    {
                        for (int x = 0; x < dose.XSize; x++)
                        {
                            int value = buffer[x, y];
                            if (value > maxValue)
                            {
                                maxValue = value;
                            }
                        }
                    }
                }
            }
            return(maxValue);
        }
Esempio n. 3
0
        public static string EsapiDoseUnitString(Dose doseEsapi)
        {
            int xSize = doseEsapi.XSize;
            int ySize = doseEsapi.YSize;

            int[,] voxelValuesInPlane = new int[xSize, ySize];
            doseEsapi.GetVoxels(0, voxelValuesInPlane);
            int voxelValue = voxelValuesInPlane[0, 0];

            DoseValue doseValue = doseEsapi.VoxelToDoseValue(voxelValue);

            return(doseValue.UnitAsString);
        }
Esempio n. 4
0
        public static double[,] GetDosePlane(int z, Dose dose)
        {
            var voxels = new int[dose.XSize, dose.YSize];

            dose.GetVoxels(z, voxels);

            var dosePlane = new double[dose.XSize, dose.YSize];

            for (int x = 0; x < dose.XSize; x++)
            {
                for (int y = 0; y < dose.YSize; y++)
                {
                    dosePlane[x, y] = dose.VoxelToDoseValue(voxels[x, y]).Dose;
                }
            }

            return(dosePlane);
        }
Esempio n. 5
0
        //---------------------------------------------------------------------------------------------
        /// <summary>
        /// This method saves the given dose or image voxels to a file in the vtk structure points format.
        /// Note that either Dose or Image is given as parameter and the other must be null.
        /// </summary>
        /// <param name="dose">Dose to output or null</param>
        /// <param name="image">Image to output or null</param>
        /// <param name="outputFileName">>Name of the file to write</param>
        //---------------------------------------------------------------------------------------------
        public static void SaveDoseOrImageToVTKStructurePoints(Dose dose, Image image, string outputFileName)
        {
            if (File.Exists(outputFileName))
            {
                File.SetAttributes(outputFileName, FileAttributes.Normal);
                File.Delete(outputFileName);
            }

            int     W, H, D;
            double  sx, sy, sz;
            VVector origin, rowDirection, columnDirection;

            if (dose != null)
            {
                W               = dose.XSize;
                H               = dose.YSize;
                D               = dose.ZSize;
                sx              = dose.XRes;
                sy              = dose.YRes;
                sz              = dose.ZRes;
                origin          = dose.Origin;
                rowDirection    = dose.XDirection;
                columnDirection = dose.YDirection;
            }
            else
            {
                W               = image.XSize;
                H               = image.YSize;
                D               = image.ZSize;
                sx              = image.XRes;
                sy              = image.YRes;
                sz              = image.ZRes;
                origin          = image.Origin;
                rowDirection    = image.XDirection;
                columnDirection = image.YDirection;
            }

            using (TextWriter writer = new StreamWriter(outputFileName))
            {
                writer.WriteLine("# vtk DataFile Version 3.0");
                writer.WriteLine("vtk output");
                writer.WriteLine("ASCII");
                writer.WriteLine("DATASET STRUCTURED_POINTS");
                writer.WriteLine("DIMENSIONS " + W + " " + H + " " + D);

                int[,] buffer = new int[W, H];

                double xsign = rowDirection.x > 0 ? 1.0 : -1.0;
                double ysign = columnDirection.y > 0 ? 1.0 : -1.0;
                double zsign = GetZDirection(rowDirection, columnDirection).z > 0 ? 1.0 : -1.0;

                writer.WriteLine("ORIGIN " + origin.x.ToString() + " " + origin.y.ToString() + " " + origin.z.ToString());
                writer.WriteLine("SPACING " + sx * xsign + " " + sy * ysign + " " + sz * zsign);
                writer.WriteLine("POINT_DATA " + W * H * D);
                writer.WriteLine("SCALARS image_data unsigned_short 1");
                writer.WriteLine("LOOKUP_TABLE default");

                int maxValueForScaling = dose != null?FindMaxValue(dose) : 0;

                for (int z = 0; z < D; z++)
                {
                    if (dose != null)
                    {
                        dose.GetVoxels(z, buffer);
                    }
                    else
                    {
                        image.GetVoxels(z, buffer);
                    }
                    for (int y = 0; y < H; y++)
                    {
                        for (int x = 0; x < W; x++)
                        {
                            int    value    = buffer[x, y];
                            UInt16 curvalue = 0;
                            if (image != null)
                            {
                                curvalue = (UInt16)value;
                            }
                            else
                            {
                                curvalue = (UInt16)((double)value * 100 / (double)maxValueForScaling);
                            }
                            writer.Write(curvalue + " ");
                        }
                        writer.WriteLine();
                    }
                }
            }
        }