Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Halcyon #1

Open
brjdenis opened this issue May 29, 2021 · 1 comment
Open

Halcyon #1

brjdenis opened this issue May 29, 2021 · 1 comment

Comments

@brjdenis
Copy link

Hi. this is not an issue, but more like a comment. If anyone is interested in getting the script to work with Halcyon, here is what you can do.
Because Halcyon uses two levels of 1 cm leaves displaced by 0.5cm laterally, you can convert the aperture into a sequence of 0.5cm leaves, without changing most of the script. I don't use any Aria queries to get leaf widths, so you may have to compensate for that yourself, but the idea is to have something like this.
Modify the AperturesFromBeamCreator class from AperturesFromBeamCreator.cs for Halcyon (add if statements to check for Halcyon if you are using other machines as well).

public double[,] GetLeafPositions(ControlPoint controlPoint, Beam beam)
{
    int m = controlPoint.LeafPositions.GetLength(0);
    int n = controlPoint.LeafPositions.GetLength(1);

    double[,] leafPositions = new double[m, n];

    if (!beam.TreatmentUnit.Id.Contains("Halcyon"))  //Stupid way of checking if machine is Halcyon
    {
        //convert from float to double and reorder
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                // Leaf positions are given from bottom to top by ESAPI,
                // but the Aperture class expects them from top to bottom
                leafPositions[i, j] = controlPoint.LeafPositions[i, n - j - 1];
            }
        }
        return leafPositions;
    }

    else
    {
        //convert from float to double
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                leafPositions[i, j] = controlPoint.LeafPositions[i, j];
            }
        }
        double[,] leafPositionsHalcyon = new double[2, 56];
        // 5 mm leaf -> formed from original table
        // 1 -> 1+29
        // 2 -> 1+30
        // 3 -> 2+30
        // 4 -> 2+31
        // 5 -> 3+31
        // 6 -> 3+32
        // 7 -> 4+32
        // 8 -> 4+33
        // 9 -> 5+33
        //...
        int[] a = new int[] { 0,  0,  1,  1,  2,  2,  3,  3,  4,  4,  5,  5,  6,  6,  7,  7,  8,
                                8,  9,  9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16,
                                17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25,
                                25, 26, 26, 27, 27};
        int[] b = new int[] {28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, 35, 36, 36,
                                37, 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 45,
                                45, 46, 46, 47, 47, 48, 48, 49, 49, 50, 50, 51, 51, 52, 52, 53, 53,
                                54, 54, 55, 55, 56};

        for (int j = 0; j < 56; j++)
        {
            int ai = a[j];
            int bi = b[j];

            if (leafPositions[0, ai] < leafPositions[0, bi])
            {
                leafPositionsHalcyon[0, j] = leafPositions[0, bi];
            }
            else
            {
                leafPositionsHalcyon[0, j] = leafPositions[0, ai];
            }

            if (leafPositions[1, ai] < leafPositions[1, bi])
            {
                leafPositionsHalcyon[1, j] = leafPositions[1, ai];
            }
            else
            {
                leafPositionsHalcyon[1, j] = leafPositions[1, bi];
            }
        }

        double[,] leafPositionsHalcyon2 = new double[2, 56];

        for (int j = 0; j < 56; j++)
        {
            // Leaf positions are given from bottom to top by ESAPI,
            // but the Aperture class expects them from top to bottom
            int indj = 55 - j;
            if (leafPositionsHalcyon[0, indj] > leafPositionsHalcyon[1, indj])
            {
                leafPositionsHalcyon2[0, j] = 0;
                leafPositionsHalcyon2[1, j] = 0;
            }
            else
            {
                leafPositionsHalcyon2[0, j] = leafPositionsHalcyon[0, indj];
                leafPositionsHalcyon2[1, j] = leafPositionsHalcyon[1, indj];
            }                 
        }
        return leafPositionsHalcyon2;
    }
}

public double[] GetLeafWidths(Patient patient, PlanSetup plan, Beam beam)
{
    try
    {
        double [] MLC120 = new double[] {14, 10, 10, 10, 10, 10, 10, 10, 10, 10,  5,  5, 
                                         5,  5,  5,  5,  5, 5,  5,  5,  5,  5,  5,  5,  5,
                                         5,  5,  5,  5,  5,  5,  5,  5,  5, 5,  5,  5,  5,
                                         5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5, 10,
                                         10, 10, 10, 10, 10, 10, 10, 10, 14};
        
        double [] MLC120HD = new double[] {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2.5, 2.5,
                                           2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5,
                                            2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5,
                                            2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5,
                                            5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 };
        
        double[] MLCHalcyon = new double[] {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
                                            5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
                                            5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
                                            5, 5, 5, 5, 5};

        List<string> MLC120Machines = new List<string> {"Linac1", "Linac2"};
        List<string> MLC120HDMachines = new List<string> {"Linac3", "Linac4"};
        List<string> MLCHalcyonMachines = new List<string> { "Linac5" };

        double [] leafwidths = new double[] { };
        
        var machine = beam.TreatmentUnit.Id;
        leafwidths = MLC120;
        
        if (MLC120HDMachines.Contains(machine))
        {
            leafwidths = MLC120HD;
        }
        else if (MLCHalcyonMachines.Contains(machine))
        {
            leafwidths = MLCHalcyon;
        }
        return leafwidths.ToArray();
    }
    catch (Exception e)
    {
        throw new LeafWidthsNotFoundException
            ("Unable to obtain leaf widths for beam " + beam.Id, e);
    }
}

The end result will look like this:
image

@brianmanderson
Copy link

I was having a very difficult time getting the Aria integration to work, and this workaround removed it entirely since I could pass along the leaf-widths directly.

Thank you very much!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants