示例#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();

            if (!engine.loginToWorkstation(USER, PASS, WORKSTATION_PATH, true))
            {
                //if (!engine.loginToGrid(USER, PASS, GRID_IP, GRID_PORT, GRID_DB)) {
                throw new System.Exception(engine.getErrorMessage());
            }
            AppDomain.CurrentDomain.ProcessExit += (source, data) => { engine.logout(); };

            // try to list liver patient volumes
            loadAndListVolumes(engine, LIVER_PATIENT_ID);

            var importOps = engine.getImportOperations();

            Console.WriteLine("Importing SPECT, Liver ...");
            if (importOps.importDirectory(LIVER_IMPORT_DIR, true))
            {
                Console.WriteLine("Successfully imported.");
            }
            else
            {
                Console.WriteLine("Import error: {0}", importOps.getErrorMessage());
            }

            // try again to list the volumes for the liver patient
            loadAndListVolumes(engine, LIVER_PATIENT_ID);
        }
示例#3
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");
        }
示例#4
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);

            // create registration
            var regOps = engine.getRegistrationOperations();

            Console.WriteLine("Creating registration object: {0}", REG_NAME);
            var registration = regOps.createNewRegistration(REG_NAME);

            ValidOrThrow(registration, regOps);
            ValidOrThrow(engine.loadRegistration(registration.getVelocityId()), engine);

            // first move the head into the right general area
            var manualSettings = new ManualRegistrationSettingsStructure();

            manualSettings.registrationMatrix = new MatrixR44d(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -0.308194699, -0.38874362499, -0.583499961, 1.0);
            orThrow(regOps.performManualAlignment(manualSettings));

            Console.WriteLine("Running rigid registration ...");
            var rigidSettings = new RigidRegistrationSettingsStructure();

            rigidSettings.roiStart[0] = -0.102021;
            rigidSettings.roiStart[1] = -0.1362766;
            rigidSettings.roiStart[2] = -0.55900709;
            rigidSettings.roiEnd[0]   = 0.100532;
            rigidSettings.roiEnd[1]   = 0.19934;
            rigidSettings.roiEnd[2]   = -0.254681;

            rigidSettings.primaryStartLevel   = 15084.0;
            rigidSettings.primaryEndLevel     = 20035.0;
            rigidSettings.secondaryStartLevel = 16361.0;
            rigidSettings.secondaryEndLevel   = 22731.0;

            rigidSettings.preprocessingMethod         = PreprocessingFilterMethod.NoFilter;
            rigidSettings.performInitialAutoAlignment = true;
            rigidSettings.disableRotationsX           = false;
            rigidSettings.disableRotationsY           = false;
            rigidSettings.disableRotationsZ           = false;
            rigidSettings.maximumNumberOfIterations   = 45;
            rigidSettings.minimumStepLength           = 0.0001;
            rigidSettings.maximumStepLength           = 17.0;
            rigidSettings.samplesDenominator          = 10;
            rigidSettings.numberOfHistogramBins       = 25;

            orThrow(regOps.performRigidRegistration(rigidSettings));
            Console.WriteLine("done");

            // perform a deformable registration in the same area
            Console.WriteLine("Performing deformable registration...");
            var bsplineSettings = new BSplineDeformableRegistrationSettingsStructure();

            bsplineSettings.roiStart[0] = -0.102021;
            bsplineSettings.roiStart[1] = -0.1362766;
            bsplineSettings.roiStart[2] = -0.55900709;
            bsplineSettings.roiEnd[0]   = 0.100532;
            bsplineSettings.roiEnd[1]   = 0.19934;
            bsplineSettings.roiEnd[2]   = -0.254681;

            bsplineSettings.primaryStartLevel   = 15084.0;
            bsplineSettings.primaryEndLevel     = 20035.0;
            bsplineSettings.secondaryStartLevel = 16361.0;
            bsplineSettings.secondaryEndLevel   = 22731.0;

            bsplineSettings.preprocessingMethod                = PreprocessingFilterMethod.NoFilter;
            bsplineSettings.numberOfMultiResolutionLevels      = 3; //  # so each List setting should be length 3
            bsplineSettings.applyBoundaryContinuityConstraints = new BoolList(new bool[] { false, false, false });
            bsplineSettings.applyTopologicalRegularizer        = new BoolList(new bool[] { false, false, false });
            var r3dZeroes = new VectorR3d(0.0);

            bsplineSettings.topologicalRegularizerDistanceLimitingCoefficient = new VectorR3dList(new VectorR3d[] { r3dZeroes, r3dZeroes, r3dZeroes });
            bsplineSettings.numberOfHistogramBins     = new IntList(new int[] { 50, 50, 50 });
            bsplineSettings.maximumNumberOfIterations = new IntList(new int[] { 30, 30, 30 });
            bsplineSettings.maximumNumberOfConsecutiveOptimizerAttempts = new IntList(new int[] { 10, 10, 10 });
            bsplineSettings.metricValuePercentageDifference             = new DoubleList(new double[] { 0.0, 0.0, 0.0 });
            bsplineSettings.minimumStepLength          = new DoubleList(new double[] { 0.000001, 0.000001, 0.000001 });
            bsplineSettings.maximumStepLength          = new DoubleList(new double[] { 100.0, 100.0, 100.0 });
            bsplineSettings.samplesDenominator         = new IntList(new int[] { 5, 5, 5 });
            bsplineSettings.relaxationFactor           = new DoubleList(new double[] { 0.9, 0.9, 0.9 });
            bsplineSettings.gradientMagnitudeTolerance = new DoubleList(Enumerable.Repeat(0.000000000000000000005, 3).ToArray());
            bsplineSettings.gridCellSize     = new VectorR3dList(new VectorR3d[] { new VectorR3d(5.0), new VectorR3d(10.0), new VectorR3d(15.0) });
            bsplineSettings.gridCellSizeType = new CharList(new char[] { 'n', 'n', 'n' });

            orThrow(regOps.performBsplineRegistration(bsplineSettings));
            Console.WriteLine("done");

            // save the changes
            ValidOrThrow(regOps.saveRegistration(), regOps);
        }
示例#5
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);
            ValidOrThrow(engine.loadRegistrationByName(DEFORMABLE_NAME), engine);
            Console.WriteLine("Loaded registration: {0}", DEFORMABLE_NAME);


            var rops = engine.getRegistrationOperations();
            var sops = engine.getStructureOperations();

            var primaryVolume   = engine.getPrimaryVolume();
            var secondaryVolume = engine.getSecondaryVolume();

            // find an external structure
            StructureSet primarySet = primaryVolume.getStructureSets().Where(ss => ss.getName() == "Original SIM").First();
            Structure    structure  = primarySet.getStructures().Where(s => s.getName() == "Mandible").First();

            Console.WriteLine("Using structure '{0}' from structure set '{1}'", structure.getName(), primarySet.getName());

            // create a new structure set on the secondary volume
            string targetSetName = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture).Substring(0, 16);
            var    targetSet     = sops.createStructureSet(targetSetName, false);

            ValidOrThrow(targetSet, sops);

            // copy the external to the new structure set
            Console.WriteLine("Copying structure to secondary...");
            var structureIds  = new IntList(new int[] { structure.getVelocityId() });
            var newStructures = sops.copyStructuresToSecondary(structureIds, targetSet.getVelocityId());

            // IMPORTANT: call save after finishing a set of modifications to a structure set
            targetSet = sops.saveStructureSet(targetSet.getVelocityId());

            OrThrow(newStructures.Count == 1, sops);
            var newStructure = newStructures.First().Value;

            Action metrics = delegate() {
                var c = sops.conformality(structure.getVelocityId(), newStructure.getVelocityId());
                Console.WriteLine("Conformality: {0}", c);
                if (c < 0.0)
                {
                    Console.WriteLine("Error: {0}", sops.getErrorMessage());
                }

                var mets = sops.surfaceDistanceMetrics(structure.getVelocityId(), newStructure.getVelocityId());
                if (!mets.isValid)
                {
                    Console.WriteLine("Error: {0}", sops.getErrorMessage());
                }
                else
                {
                    Console.WriteLine("Metrics: Hausdorff={0}, min={1}, median={2}, mean={3}, stddev={4}",
                                      mets.hausdorffDistance, mets.min, mets.median, mets.mean, mets.standardDeviation);
                }
            };

            // show metrics on registration used for copying
            metrics();

            // now on an alternative registration
            ValidOrThrow(engine.loadRegistrationByName(RIGID_NAME), engine);
            Console.WriteLine("Loaded registration: {0}", RIGID_NAME);
            metrics();
        }
        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);
            }
        }