GetVolumeAtDose error

Oct 28, 2015 at 9:46 PM
Perhaps someone can tell me what I am doing wrong. I can use the GetDoseAtVolume Method without errors but cannot get the GetVolumeAtDose method to work. The error is:
"Cannot implicitly convert type 'double' to 'VMS.TPS.Common.Model.Types.DoseValue'

The GetVolumeAtDose method ask for inputs of type: structure, DoseValue and VolumePresentation. Even if I create these types (as in the code below) I still get the above error.

There seems to be a problem with the DoseValue argument but I am stumped.
Here is the code:
using System;
using System.Linq;
using System.Text;
using System.Windows;
using System.Collections.Generic;
using VMS.TPS.Common.Model.API;
using VMS.TPS.Common.Model.Types;

namespace VMS.TPS
{
  public class Script
  {
    public Script()
    {
    }

    public void Execute(ScriptContext context /*, System.Windows.Window window*/)
    {
      // TODO : Add here your code that is called when the script is launched from Eclipse
        if (context.Patient == null || context.PlanSetup == null || context.PlanSetup.Dose == null || context.StructureSet == null)
            MessageBox.Show("Please load a patient, structure set, and a plan that has dose calculated!");

        // get reference to selected plan
        PlanSetup plan = context.PlanSetup;

        // linq query finds the first PTV structure
        Structure target = (from s in context.StructureSet.Structures where s.DicomType == "PTV" select s).FirstOrDefault();

        if (target == null)
            throw new ApplicationException("Plan '" + plan.Id + "' has no PTV!");
        // DoseValue PTVVal = plan.GetDoseAtVolume(target, 99.0, VolumePresentation.Relative, DoseValuePresentation.Relative);
        
        DoseValue ninetyfive = plan.TotalPrescribedDose*.95;
        VolumePresentation volpres = VolumePresentation.Relative;
        DoseValue ptvval = plan.GetVolumeAtDose(target, ninetyfive, volpres);
        MessageBox.Show("The Volume of PTV receiving 95% of the dose is: " + ptvval);

        
    }
  }
}
Developer
Oct 28, 2015 at 10:15 PM
Simple

Replace your second last line with following:

DoseValue ptvval = plan.GetVolumeAtDose(target, new DoseValue(plan.TotalPrescribedDose.Dose*0.95,DoseValue.DoseUnit.Gy), volpres);

Cheers

Oct 29, 2015 at 3:38 AM
Thanks for the quick reply, unfortunately I still get the same error. Strangely enough I create a local DoseValue type named "ninetyfive" (4th line of code from bottom), I can MessageBox this and get "5700.0 cGy" which looks like a DoseType - it has both a double and string.

Is it possible I have a bad VMS.TPS.Common.Model.Types dll file?
Coordinator
Oct 29, 2015 at 11:37 AM
Edited Oct 29, 2015 at 11:48 AM
I thought the error was DoseValue types did not have multiplication operators. ShashankTheBest, I have learned from this post that is a perfectly legal operation. I think your suggestion was that you had to descend to Dose property to get a multiplication operation to work, but
DoseValue*0.95 
works (surprisingly). Instead, the issue I think is that:

plan.GetVolumeAtDose returns a double value, but you are casting to DoseValue implicitly by:
DoseValue ptvval = plan.GetVolumeAtDose(target, new DoseValue(plan.TotalPrescribedDose.Dose*0.95,DoseValue.DoseUnit.Gy), volpres);
Should be :
var ptvval = plan.GetVolumeAtDose(target, new DoseValue(plan.TotalPrescribedDose.Dose*0.95,DoseValue.DoseUnit.Gy), volpres);
or
double ptvval = plan.GetVolumeAtDose(target, new DoseValue(plan.TotalPrescribedDose.Dose*0.95,DoseValue.DoseUnit.Gy), volpres);
Marked as answer by rexcardan on 10/29/2015 at 4:40 AM
Oct 29, 2015 at 2:52 PM
That worked thanks!