Пример #1
0
        static void Main(string[] args)
        {
            // connect to the grid
            var           engine  = new VelocityEngine();
            Action <bool> orThrow = result => OrThrow(result, engine);

            //orThrow(engine.loginToGrid(USER, PASS, GRID_IP, GRID_PORT, GRID_DB));
            orThrow(engine.loginToWorkstation(USER, PASS, WORKSTATION_PATH, true));
            AppDomain.CurrentDomain.ProcessExit += (source, data) => { engine.logout(); };

            orThrow(engine.loadPatientByPatientId(PATIENT_ID));
            Console.WriteLine("Loaded patient: {0}", PATIENT_ID);
            orThrow(engine.loadPrimaryVolumeByUID(PRIMARY_UID));
            Console.WriteLine("Loaded primary volume: {0}", PRIMARY_UID);
            orThrow(engine.loadSecondaryVolumeByUID(SECONDARY_UID));
            Console.WriteLine("Loaded secondary volume: {0}", SECONDARY_UID);

            // load registration
            ValidOrThrow(engine.loadRegistrationByName(REG_NAME), engine);
            Console.WriteLine("Loaded registration: {0}", REG_NAME);

            var structure = engine.loadStructureByName(STRUCT_1, STRUCTSET_1UID);

            ValidOrThrow(structure, engine);
            Console.WriteLine("Loading existing structure: {0}", STRUCT_1);

            var structNames          = new StringList(new string[] { STRUCT_1 });
            var structAlphaBetaRatio = new DoubleList(new double[] { 2, DEFAULT_ALPHABETA_TISSUE });
            var structUIDs           = new StringList(new string[] { structure.getInstanceUID() });

            var vo = engine.getVolumeOperations();

            OrThrow(vo.createBEDoseByStructureUIDs(25, structNames, structUIDs, structAlphaBetaRatio) != -1, vo);
            Console.WriteLine("Biological Effective Dose created");
        }
Пример #2
0
        static void Main(string[] args)
        {
            // connect to the grid
            var           engine  = new VelocityEngine();
            Action <bool> orThrow = result => OrThrow(result, engine);

            //orThrow(engine.loginToGrid(USER, PASS, GRID_IP, GRID_PORT, GRID_DB));
            orThrow(engine.loginToWorkstation(USER, PASS, WORKSTATION_PATH, true));
            AppDomain.CurrentDomain.ProcessExit += (source, data) => { engine.logout(); };

            ValidOrThrow(engine.loadPatientByPatientId(PATIENT_ID), engine);
            Console.WriteLine("Loaded patient: {0}", PATIENT_ID);
            ValidOrThrow(engine.loadPrimaryVolumeByUID(PRIMARY_UID), engine);
            Console.WriteLine("Loaded primary volume: {0}", PRIMARY_UID);
            ValidOrThrow(engine.loadSecondaryVolumeByUID(SECONDARY_UID), engine);
            Console.WriteLine("Loaded secondary volume: {0}", SECONDARY_UID);

            // load registration
            ValidOrThrow(engine.loadRegistrationByName(REG_NAME), engine);
            Console.WriteLine("Loaded registration: {0}", REG_NAME);

            var structure = engine.loadStructureByName(STRUCT_1, STRUCTSET_1UID);

            ValidOrThrow(structure, engine);
            Console.WriteLine("Loading existing structure: {0}", STRUCT_1);

            var bedStructure = new BedStructureVariables();

            bedStructure.structureId    = structure.getVelocityId();
            bedStructure.alphaBetaRatio = 2;
            bedStructure.structureName  = structure.getName();

            var calculationData = new BedDoseCalculationData();

            calculationData.bedVariablesByStructure = new BedStructureVariablesList(new BedStructureVariables[] { bedStructure });
            calculationData.fractions = 25;

            var backgroundData = new BedBackgroundData();

            backgroundData.alphaBetaRatio = DEFAULT_ALPHABETA_TISSUE;

            var vo = engine.getVolumeOperations();

            OrThrow(vo.createBEDose(calculationData, backgroundData, false) != -1, vo);
            Console.WriteLine("Biological Effective Dose created");
        }
Пример #3
0
        static void Main(string[] args)
        {
            const string USER             = "******";
            const string PASS             = "******";
            const string WORKSTATION_PATH = @"C:\Velocity\Databases\WKS414";
            const string GRID_IP          = "127.0.0.1";
            const int    GRID_PORT        = 57000;
            const string GRID_DB          = "vscDatabase";

            const string PATIENT_ID = "hyperarc";

            // connect to db
            var           engine  = new VelocityEngine();
            Action <bool> orThrow = result => OrThrow(result, engine);

            //orThrow(engine.loginToGrid(USER, PASS, GRID_IP, GRID_PORT, GRID_DB));
            orThrow(engine.loginToWorkstation(USER, PASS, WORKSTATION_PATH, true));
            AppDomain.CurrentDomain.ProcessExit += (source, data) => { engine.logout(); };

            var volOps  = engine.getVolumeOperations();
            var patient = engine.loadPatientByPatientId(PATIENT_ID);

            ValidOrThrow(patient, engine);
            Console.WriteLine("Loaded patient: {0}", PATIENT_ID);

            //sort CTs ascending by AcquisitionDate
            var cts   = patient.getVolumes("CT").OrderBy(o => o.getAcquisitionDate());
            var doses = patient.getVolumes("RTDOSE");

            // find all CT-DS in the same frame of reference
            //if multiple DS for same CT pick first one that has a plan
            var ctDosePair = new Dictionary <Volume, Volume>();

            Console.WriteLine("Finding CT-DS pairs to be resampled");
            foreach (Volume ct in cts)
            {
                var plans = ct.getLinkedPlans().ToList();
                foreach (Volume d in doses)
                {
                    if (d.getName() == "auto resampled" || d.getName() == "SUM RTDOSE")
                    {
                        continue;
                    }
                    if (ct.getFrameOfReferenceUID() == d.getFrameOfReferenceUID())
                    {
                        ctDosePair[ct] = d;
                        bool hasPlan = plans.Exists(p => p.getInstanceUID() == d.getPlanUID());
                        if (hasPlan)
                        {
                            break;
                        }
                    }
                }
            }

            //resample doses onto the most recent CT
            Console.WriteLine("Resampling DS onto most recent CT");
            var primaryCT      = cts.Last();    // most recent by Acq Date
            var resampledDoses = new IntList(); // holds the ids of all doses to be summed
            var primaryDoseId  = -1;

            foreach (Volume ct in ctDosePair.Keys)
            {
                var dose = ctDosePair[ct];
                if (ct.getVelocityId() != primaryCT.getVelocityId())
                {
                    //need to load CT-DS to activate/create DICOM registration needed for chain
                    ValidOrThrow(engine.loadPrimaryVolume(ct.getVelocityId()), engine);
                    Console.WriteLine("Loaded CT {0} as primary", ct.getName());
                    ValidOrThrow(engine.loadSecondaryVolume(dose.getVelocityId()), engine);
                    Console.WriteLine("Loaded dose {0} as secondary", dose.getName());
                    var dicomReg = engine.loadRegistrationByName("DICOM");
                    ValidOrThrow(dicomReg, engine);

                    // make new reg for resampling between primary CT and secondary CT
                    var ct2ctReg = makeAutoReg(engine, primaryCT, ct, "resample_reg");

                    //now load primary CT and dose, load chain reg and resample onto primary CT
                    ValidOrThrow(engine.loadPrimaryVolume(primaryCT.getVelocityId()), engine);
                    Console.WriteLine("Loaded CT {0} as primary volume", primaryCT.getName());
                    ValidOrThrow(engine.loadSecondaryVolume(dose.getVelocityId()), engine);
                    Console.WriteLine("Loaded Dose id {0} as secondary volume", dose.getName());
                    //load registration resample_reg + DICOM
                    orThrow(engine.loadChainRegistration(ct2ctReg.getVelocityId(), dicomReg.getVelocityId()));
                    Console.WriteLine("Loaded registration resample_reg + DICOM");
                    Console.WriteLine("Creating resampled dose...");

                    var id = volOps.createResampledVolume(VolumeResampleOperation.VolumeResampleReplace, "auto resampled");
                    if (id == -1)
                    {
                        Console.WriteLine("Error creating resampled dose {0}", volOps.getErrorMessage());
                        continue;
                    }

                    Console.WriteLine("Resampled dose created with id {0}", (id));
                    resampledDoses.Add(id);
                }
                else
                {
                    //this dose does not require resample, same FOR as primary CT
                    primaryDoseId = dose.getVelocityId();
                    resampledDoses.Add(primaryDoseId);
                }
            }

            Console.WriteLine("Summing {0} dose volumes ...", resampledDoses.Count());
            ValidOrThrow(engine.loadPrimaryVolume(primaryDoseId), engine);
            //load primary dose as anchor
            Console.WriteLine("Loaded DS id {0} as primary volume", primaryDoseId);
            int sumId = volOps.createResampledVolumeAggregate(VolumeResampleOperation.VolumeResampleAdd, resampledDoses, (int)ResampleFlags.Flags.AllowNone); // sum

            if (sumId == -1)
            {
                Console.WriteLine("Error creating sum dose {0}", volOps.getErrorMessage());
            }
            else
            {
                Console.WriteLine("Sum dose created with id {0}", sumId);
            }
        }