Exporting dose in same size as ct

May 17, 2015 at 2:01 AM
Hi,

Is there anyway to export the dose so it is in the same size as ct image?

Currently the ct image is 500x500. I would like the dose to be also 500x500.

thanks a lot.
Coordinator
May 17, 2015 at 6:51 PM
You can use the GetDoseProfile method in the Dose class. It takes the first and last point (VVector) of a line segment from which to sample the dose. It also takes a pre-allocated buffer (double[]) of any length, but in your case it should be the length of your image (500). According to my understanding, the method will evenly sample the dose along the line segment you specified. Therefore, you need to call GetDoseProfile within a loop that goes through each row (or column) of your image. If it's a 3D image, then you need to wrap this loop within another loop that goes through each plane of the image.

I've included sample code below that gets the dose (as a double[, ,]) from a PlanSetup, such that the dose is the same size as the 3D image. I've had to modify it a little from my original implementation, so it might not compile as is. I've found that getting the dose for an entire 3D image is quite slow (about a minute), so if you're implementing this for a UI, you might want to think about reporting the progress after obtaining the dose for every plane of the image.
        public double[, ,] GetDose(PlanSetup plan)
        {
            plan.DoseValuePresentation = DoseValuePresentation.Absolute;

            Image image = plan.GetImage();    // Extension method that gets the image
            int xSize = image.XSize;
            int ySize = image.YSize;
            int zSize = image.ZSize;

            Dose dose = plan.Dose;
            double[, ,] data = new double[xSize, ySize, zSize];

            for (int z = 0; z < zSize; z++)
            {
                for (int y = 0; y < ySize; y++)
                {
                    double[] doseProfile = GetDoseProfile(plan, dose, image, y, z);

                    for (int x = 0; x < xSize; x++)
                    {
                        data[x, y, z] = doseProfile[x];
                    }
                }
            }

            return data;
        }

        private double[] GetDoseProfile(PlanSetup plan, Dose dose, Image image, int y, int z)
        {
            double[] buffer = new double[image.XSize];

            VVector start = GetCoordinate(image, 0, y, z);
            VVector end = GetCoordinate(image, image.XSize - 1, y, z);

            dose.GetDoseProfile(start, end, buffer);

            return buffer;
        }

        private VVector GetCoordinate(Image image, int x, int y, int z)
        {
            return new VVector(IndexToCoordinate(x, image.Origin.x, image.XRes),
                               IndexToCoordinate(y, image.Origin.y, image.YRes),
                               IndexToCoordinate(z, image.Origin.z, image.ZRes));
        }

        private double IndexToCoordinate(int index, double origin, double res)
        {
            return origin + (double)index * res;
        }
May 18, 2015 at 3:20 AM
Thank you so much!!! I will try this out.

Along the same line, is there an easy way to report the contour information as well? Cause if you export as an RS file, you also run into the problem of the coordinate not being the same.
Coordinator
May 18, 2015 at 3:20 PM
What kind of contour information? You can get the contour points with the GetContoursOnImagePlane method in the Structure class. If I remember right, the coordinate system is the same as the image's.
May 18, 2015 at 5:58 PM
In the export 3D example, how do I make small modification to the code so I can get the coordinate for the image and contour (also dose if possible) to be the same?
May 18, 2015 at 7:14 PM
Can you please elaborate on this method plan.GetImage()?
Coordinator
May 18, 2015 at 9:34 PM
It's an extension method (see http://en.wikipedia.org/wiki/Extension_method) that's equivalent to calling plan.StructureSet.Image. The only difference is that in the method I check to make sure plan.StructureSet is not null before retrieving the image. If it is, the method returns null:
        public static Image GetImage(this PlanSetup plan)
        {
            if (plan.StructureSet != null)
            {
                return plan.StructureSet.Image;
            }
            else
            {
                return null;
            }
        }
May 19, 2015 at 1:45 AM
Thank you so much!!! Can you please tell me how to use GetContoursOnImagePlane to get the structure files?
Coordinator
May 19, 2015 at 3:20 PM
I'm not sure what you mean by structure files. GetContoursOnImagePlane simply returns an array of contours (each contour is an array of VVector). If you would like to save these contours to a file (say, in XML format), you'll have to implement that yourself.
Coordinator
Apr 4, 2016 at 5:39 PM
I further discuss extension methods in ESAPI in the following blog post: http://www.carlosjanderson.com/enhance-esapi-with-extension-methods/