public DoseMatrix(DICOMObject dcm) { _doseObject = new DICOMSelector(dcm); ValueSizeInBytes = _doseObject.BitsStored.Data / 8; DoseValues = new List<double>(); this.Scaling= _doseObject.DoseGridScaling.Data; using (var stream = _doseObject.ToDICOMObject().PixelStream) { var binReader = new BinaryReader(stream); if (ValueSizeInBytes == 4) { while (binReader.BaseStream.Position < binReader.BaseStream.Length) { DoseValues.Add(Scaling * binReader.ReadInt32()); } } else { while (binReader.BaseStream.Position < binReader.BaseStream.Length) { DoseValues.Add(Scaling * binReader.ReadUInt16()); } } } }
private void calculprescription(String nom) { var dcm = DICOMObject.Read(nom); var sel = new DICOMSelector(dcm); try { var PrescripDose = sel.TargetPrescriptionDose.Data; var DoseFraction = sel.NumberOfFractionsPlanned.Data; var DoseParSeance = PrescripDose / DoseFraction; Console.WriteLine("- Dose totale prescrite : " + PrescripDose); Console.WriteLine("- Nombre de séance : " + DoseFraction); Console.WriteLine("- Dose par séance : " + DoseParSeance); var BeamDoseSpec = sel.BeamDoseSpecificationPoint_; // nombre de dose var NbBeamDoseSpec = sel.BeamDoseSpecificationPoint_.Count; //var NbBeamDoseSpec = 3; for (int i = 0; i < BeamDoseSpec.Count; i++) { sel.BeamDoseSpecificationPoint_[i].Data_.Clear(); } Console.WriteLine("- Les " + sel.BeamDoseSpecificationPoint_.Count + " champs 'Beam Dose Spécifation Point' sont maintenant vides "); var numberDose_nar = DoseParSeance / NbBeamDoseSpec; var numberDose = Math.Round(numberDose_nar, 3); Console.WriteLine("- Pondération par faisceau : " + numberDose); var beamdose = sel.BeamDose_; var nbBeamDose = beamdose.Count - 1; for (int i = 0; i < beamdose.Count; i++) { for (int k = 0; i < beamdose.Count; i++) { sel.BeamDose_[i].Data_[k] = numberDose; if (nbBeamDose == i) { var total = numberDose * nbBeamDose; var totallast = DoseParSeance - total; sel.BeamDose_[i].Data_[k] = totallast; } Console.WriteLine("Faisceau " + i + " : " + sel.BeamDose_[i].Data_[k]); } } } catch (NullReferenceException) { MessageBox.Show("Impossible de calculer la dose pour le fichier " + nom, "Erreur", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); status.ForeColor = System.Drawing.Color.Red; status.Text = "Modification interrompu"; test = false; }; dcm.Write(nom); }
public RTDose(DICOMObject dcm) { _doseObject = new DICOMSelector(dcm); ValueSizeInBytes = _doseObject.BitsStored.Data / 8; DoseValues = new List <double>(); Scaling = _doseObject.DoseGridScaling.Data; using (var stream = _doseObject.ToDICOMObject().GetPixelStream()) { var binReader = new BinaryReader(stream); if (ValueSizeInBytes == 4) { while (binReader.BaseStream.Position < binReader.BaseStream.Length) { DoseValues.Add(Scaling * binReader.ReadInt32()); } } else { while (binReader.BaseStream.Position < binReader.BaseStream.Length) { DoseValues.Add(Scaling * binReader.ReadUInt16()); } } } }
public AbstractDIMSERequest(DICOMObject d) { var sel = new DICOMSelector(d); GroupLength = sel.CommandGroupLength.Data; AffectedSOPClassUID = sel.AffectedSOPClassUID.Data; MessageID = sel.MessageID.Data; DataSetType = sel.CommandDataSetType.Data; }
protected virtual void CopyTreatmentMachineSequence(DICOMObject fromPatientPlan, DICOMObject toVerificationPlan) { var patientSelector = new DICOMSelector(fromPatientPlan); var verificationSelector = new DICOMSelector(toVerificationPlan); var machineSeq = patientSelector.TreatmentMachineSequence; verificationSelector.TreatmentMachineSequence = machineSeq; }
/// <summary> /// Constructor por defecto /// </summary> public MyDicom() { minPixVal = 0; signedImage = false; bmp = null; pixelData = new List<ushort>(); dcm = null; selector = null; }
protected virtual void CopyFractionGroupSeq(DICOMObject patientPlan, DICOMObject verificationPlan) { var patientSelector = new DICOMSelector(patientPlan); var verificationSelector = new DICOMSelector(verificationPlan); var fractionSeq = patientSelector.FractionGroupSequence; verificationSelector.FractionGroupSequence = fractionSeq; }
public CFindRequest(DICOMObject d) { var sel = new DICOMSelector(d); GroupLength = sel.CommandGroupLength.Data; AffectedSOPClassUID = sel.AffectedSOPClassUID.Data; CommandField = (ushort)C.C_FIND_RQ; MessageID = sel.MessageID.Data; Priority = sel.Priority.Data; DataSetType = sel.CommandDataSetType.Data; }
protected virtual void UpdateVerificationPlanLabel(DICOMObject patientPlan, DICOMObject verificationPlan) { var patientSelector = new DICOMSelector(patientPlan); var verificationSelector = new DICOMSelector(verificationPlan); var patientLabel = patientSelector.RTPlanLabel; verificationSelector.RTPlanLabel.Data += " - " + patientLabel.Data; verificationSelector.RTPlanName.Data = verificationSelector.RTPlanLabel.Data; }
public CGetRequest(DICOMObject d) { var sel = new DICOMSelector(d); GroupLength = sel.CommandGroupLength.Data; AffectedSOPClassUID = sel.AffectedSOPClassUID.Data; CommandField = (ushort)C.C_MOVE_RQ; MessageID = sel.MessageID.Data; Priority = sel.Priority.Data; DataSetType = sel.CommandDataSetType.Data; }
public AbstractDIMSEResponse(DICOMObject d) { var sel = new DICOMSelector(d); GroupLength = sel.CommandGroupLength.Data; if (sel.AffectedSOPClassUID != null) { AffectedSOPClassUID = sel.AffectedSOPClassUID.Data; }; MessageIDBeingResponsedTo = sel.MessageIDBeingRespondedTo.Data; DataSetType = sel.CommandDataSetType.Data; Status = sel.Status.Data; }
public NActionRequest(DICOMObject d) { CommandField = (ushort)N_ACTION_RQ; var sel = new DICOMSelector(d); GroupLength = sel.CommandGroupLength.Data; RequestedSOPClassUID = sel.RequestedSOPClassUID.Data; RequestedSOPInstanceUID = sel.RequestedSOPInstanceUID.Data; CommandField = sel.CommandField.Data; MessageID = sel.MessageID.Data; DataSetType = sel.CommandDataSetType.Data; ActionTypeID = sel.ActionTypeID.Data; }
public NEventReportRequest(DICOMObject d) { CommandField = (ushort)N_EVENT_REPORT_RQ; var sel = new DICOMSelector(d); GroupLength = sel.CommandGroupLength.Data; AffectedSOPClassUID = sel.AffectedSOPClassUID.Data; AffectedSOPInstanceUID = sel.AffectedSOPInstanceUID.Data; CommandField = sel.CommandField.Data; MessageID = sel.MessageID.Data; DataSetType = sel.CommandDataSetType.Data; EventTypeId = sel.EventTypeID.Data; }
public CEchoResponse(DICOMObject d) { var sel = new DICOMSelector(d); GroupLength = sel.CommandGroupLength.Data; if (sel.AffectedSOPClassUID != null) { AffectedSOPClassUID = sel.AffectedSOPClassUID.Data; }; CommandField = (ushort)C.C_ECHO_RP; MessageIDBeingResponsedTo = sel.MessageIDBeingRespondedTo.Data; DataSetType = sel.CommandDataSetType.Data; Status = sel.Status.Data; }
public AbstractDIMSEResponse(DICOMObject d) { var sel = new DICOMSelector(d); GroupLength = sel.CommandGroupLength.Data; if (sel.AffectedSOPClassUID != null) { AffectedSOPClassUID = sel.AffectedSOPClassUID.Data; } ; MessageIDBeingRespondedTo = sel.MessageIDBeingRespondedTo.Data; DataSetType = sel.CommandDataSetType.Data; Status = sel.Status.Data; }
public CStoreRequest(DICOMObject d) { var sel = new DICOMSelector(d); GroupLength = sel.CommandGroupLength.Data; AffectedSOPClassUID = sel.AffectedSOPClassUID.Data; CommandField = sel.CommandField.Data; MessageID = sel.MessageID.Data; Priority = sel.Priority.Data; DataSetType = sel.CommandDataSetType.Data; AffectedSOPInstanceUID = sel.AffectedSOPInstanceUID.Data; MoveOrigAETitle = sel.MoveOriginatorApplicationEntityTitle != null ? sel.MoveOriginatorApplicationEntityTitle.Data : ""; MoveOrigMessageID = sel.MoveOriginatorMessageID != null ? sel.MoveOriginatorMessageID.Data : default(ushort); }
public CEchoResponse(DICOMObject d) { var sel = new DICOMSelector(d); GroupLength = sel.CommandGroupLength.Data; if (sel.AffectedSOPClassUID != null) { AffectedSOPClassUID = sel.AffectedSOPClassUID.Data; } ; CommandField = (ushort)C.C_ECHO_RP; MessageIDBeingRespondedTo = sel.MessageIDBeingRespondedTo.Data; DataSetType = sel.CommandDataSetType.Data; Status = sel.Status.Data; }
public NActionResponse(DICOMObject d) { CommandField = (ushort)N_ACTION_RP; var sel = new DICOMSelector(d); GroupLength = sel.CommandGroupLength.Data; AffectedSOPClassUID = sel.AffectedSOPClassUID.Data; AffectedSOPInstanceUID = sel.AffectedSOPInstanceUID.Data; MessageIDBeingRespondedTo = sel.MessageIDBeingRespondedTo.Data; DataSetType = sel.CommandDataSetType.Data; Status = sel.Status.Data; if (sel.ActionTypeID != null) { ActionTypeID = sel.ActionTypeID.Data; } }
protected virtual void CopyApplicationSetupSequence(DICOMObject patientPlan, DICOMObject verificationPlan, int fromChannelNumber, int toChannelNumber) { int numberOfChannelsInValidationPlan = toChannelNumber - fromChannelNumber; var patientSelector = new DICOMSelector(patientPlan); var verificationSelector = new DICOMSelector(verificationPlan); var totalReferenceAirKerma = patientSelector.TotalReferenceAirKerma; verificationSelector.TotalReferenceAirKerma = totalReferenceAirKerma; var channelSeq = patientSelector.ChannelSequence; int channelId = 1; foreach (var item in channelSeq.Data_) { var itemSelector = new DICOMSelector(item); var channelNumber = itemSelector.ChannelNumber; if (channelNumber != null) { bool bInsideTheBlock = IsInsideTheChannelBlock(channelNumber.Data, fromChannelNumber, toChannelNumber); if (!bInsideTheBlock) { continue; } var numberOfControlPoints = itemSelector.NumberOfControlPoints; var channelLength = itemSelector.ChannelLength; var channelTotalTime = itemSelector.ChannelTotalTime; var sourceApplicatorLength = itemSelector.SourceApplicatorLength; var sourceApplicatorStep = itemSelector.SourceApplicatorStepSize; var finalCumulativeTimeweight = itemSelector.FinalCumulativeTimeWeight; var brachyControlPointSeq = itemSelector.BrachyControlPointSequence; UpdateTarget(verificationSelector, channelNumber, numberOfControlPoints, channelLength, channelTotalTime, sourceApplicatorLength, sourceApplicatorStep, finalCumulativeTimeweight, brachyControlPointSeq, channelId); ++channelId; } } }
public void UpdatePlan() { string description = "EGD2 generated from " + this.planUID + "\r\nα/β = " + this.alphaBeta.ToString(); var sel = new DICOMSelector(plan); if (sel.RTPlanDescription == null) { sel.RTPlanDescription = new ShortText(TagHelper.RTPLAN_DESCRIPTION, description); } else { sel.RTPlanDescription.Data += description; } sel.SOPInstanceUID.Data = UIDHelper.GenerateUID("1.2.246.352.71.5"); sel.SeriesInstanceUID.Data = UIDHelper.GenerateUID("1.2.246.352.71.2"); /* * sel.MediaStorageSOPClassUID = new UniqueIdentifier(TagHelper.MEDIA_STORAGE_SOPCLASS_UID, sel.SOPClassUID.Data); * sel.MediaStorageSOPInstanceUID = new UniqueIdentifier(TagHelper.MEDIA_STORAGE_SOPINSTANCE_UID, sel.SOPInstanceUID.Data); * sel.ImplementationClassUID = new UniqueIdentifier(TagHelper.IMPLEMENTATION_CLASS_UID, UIDHelper.GenerateUID()); */ sel.ApprovalStatus.Data = "REJECTED"; sel.RTPlanLabel.Data = "EQD2_" + sel.RTPlanLabel.Data.Trim(); if (sel.RTPlanLabel.Data.Length > 13) { sel.RTPlanLabel.Data = sel.RTPlanLabel.Data.Substring(0, 13).Trim(); } plan = sel.ToDICOMObject(); /* * plan.FindFirst(TagHelper.SOPINSTANCE_UID).DData = UIDHelper.GenerateUID(); * plan.FindFirst(TagHelper.SERIES_INSTANCE_UID).DData = UIDHelper.GenerateUID(); * plan.FindFirst(TagHelper.RTPLAN_LABEL).DData = "EQD2_" + plan.FindFirst(TagHelper.RTPLAN_LABEL).DData; * plan.FindFirst(TagHelper.APPROVAL_STATUS).DData = "REJECTED"; * this.planUID = plan.FindFirst(TagHelper.SOPINSTANCE_UID).DData.ToString(); * return plan.FindFirst(TagHelper.SOPINSTANCE_UID).DData.ToString(); */ this.planUID = sel.SOPInstanceUID.Data; // add metadata plan = AddMetaData(plan); //return this.planUID; }
public void UpdateDose(string path) { // Compute new dose matrix string fileName = path + this.DoseUID + ".dcm"; var DoseValues = computeEQD2(fileName, this.nFractions, this.alphaBeta); var sel = new DICOMSelector(dose); sel.SOPInstanceUID.Data = UIDHelper.GenerateUID("1.2.246.352.71.7"); sel.SeriesInstanceUID.Data = UIDHelper.GenerateUID("1.2.246.352.71.2"); /* * dose.FindFirst(TagHelper.SOPINSTANCE_UID).DData = UIDHelper.GenerateUID(); * dose.FindFirst(TagHelper.SERIES_INSTANCE_UID).DData = UIDHelper.GenerateUID(); * this.doseUID = dose.FindFirst(TagHelper.SOPINSTANCE_UID).DData.ToString(); * return dose.FindFirst(TagHelper.SOPINSTANCE_UID).DData.ToString(); */ sel.ReferencedRTPlanSequence_[0].ReferencedSOPInstanceUID.Data = this.planUID; // overwrite dose matrix var _16b = 1 / Math.Pow(2, 16); sel.DoseGridScaling.Data = _16b; using (var stream = new MemoryStream()) { var binWriter = new BinaryWriter(stream); foreach (var d in DoseValues) { int integ = (int)(d / _16b); var bytes = BitConverter.GetBytes(integ); binWriter.Write(integ); } var ows = new OtherWordString(TagHelper.PIXEL_DATA, stream.ToArray()); sel.ToDICOMObject().Replace(ows); } //dose = sel.ToDICOMObject(); this.doseUID = sel.SOPInstanceUID.Data; // add metadata dose = AddMetaData(dose); }
private void ajouttag(String nom) { var dcm = DICOMObject.Read(nom); var sel = new DICOMSelector(dcm); var refDoseRate = new DecimalString { Tag = TagHelper.DoseRateSet, Data = 400 }; var nbBeams = sel.NumberOfBeams.Data; for (int i = 0; i < nbBeams; i++) { sel.ControlPointSequence_[i].Items[0].Add(refDoseRate); } Console.WriteLine("- Ajout du tag pour l'AutoBreast"); dcm.Write(nom); }
protected virtual void UpdateTarget(DICOMSelector verificationSelector, IntegerString channelNumber, IntegerString numberOfControlPoints, DecimalString channelLength, DecimalString channelTotalTime, DecimalString sourceApplicatorLength, DecimalString sourceApplicatorStep, DecimalString finalCumulativeTimeweight, Sequence brachyControlPointSeq, int channelId) { var channelSeq = verificationSelector.ChannelSequence; foreach (var item in channelSeq.Data_) { var itemSelector = new DICOMSelector(item); var cn = itemSelector.ChannelNumber.Data; if (cn != channelId) { continue; } itemSelector.NumberOfControlPoints = numberOfControlPoints; //itemSelector.ChannelLength; itemSelector.ChannelTotalTime = channelTotalTime; itemSelector.SourceApplicatorLength = sourceApplicatorLength; itemSelector.SourceApplicatorStepSize = sourceApplicatorStep; itemSelector.FinalCumulativeTimeWeight = finalCumulativeTimeweight; itemSelector.BrachyControlPointSequence = brachyControlPointSeq; } }
public static void Render(DICOMSelector sel, DRR drr) { //Field rendering var exposure = sel.ExposureSequence; var beamLimits = exposure?.Select(s => s.BeamLimitingDeviceSequence); if (beamLimits != null) { var collAngle = sel.BeamLimitingDeviceAngle.Data; var mmPerPixel = sel.ImagePlanePixelSpacing.Data_; var points = new List <List <Point> >(); var xLimits = beamLimits.Items.FirstOrDefault(b => b.GetSelector().RTBeamLimitingDeviceType.Data == "X" || b.GetSelector().RTBeamLimitingDeviceType.Data == "ASYMX"); var yLimits = beamLimits.Items.FirstOrDefault(b => b.GetSelector().RTBeamLimitingDeviceType.Data == "Y" || b.GetSelector().RTBeamLimitingDeviceType.Data == "ASYMY"); if (xLimits != null && yLimits != null) { var xjaws = xLimits.GetSelector().LeafJawPositions.Data_; var yjaws = yLimits.GetSelector().LeafJawPositions.Data_; var x1y1 = new Point(xjaws[0] / mmPerPixel[0], yjaws[0] / mmPerPixel[0]); var x1y2 = new Point(xjaws[0] / mmPerPixel[0], yjaws[1] / mmPerPixel[0]); var x2y2 = new Point(xjaws[1] / mmPerPixel[0], yjaws[1] / mmPerPixel[0]); var x2y1 = new Point(xjaws[1] / mmPerPixel[0], yjaws[0] / mmPerPixel[0]); x1y1 = DRR.Rotate(x1y1, collAngle) + drr.Iso2D; x1y2 = DRR.Rotate(x1y2, collAngle) + drr.Iso2D; x2y2 = DRR.Rotate(x2y2, collAngle) + drr.Iso2D; x2y1 = DRR.Rotate(x2y1, collAngle) + drr.Iso2D; points.Add(new List <Point>() { x1y1, x1y2, x2y2, x2y1 }); } //points.Add(field.Points().Select(p => new Point(p.X, p.Y)).ToList()); drr.Image.DrawContours(points, 0, new Scalar(255, 0, 0)); } }
public int GetTotalNumberOfChannelsInPlan(DICOMObject plan) { try { var patientSelector = new DICOMSelector(plan); var channelSeq = patientSelector.ChannelSequence; if (channelSeq != null) { var numberOfChannels = channelSeq.Items.Count; return(numberOfChannels); } else { return(0); } } catch (Exception e) { Console.WriteLine(e); throw; } }
public CMoveResponse(DICOMObject d) : base(d) { var sel = new DICOMSelector(d); GroupLength = sel.CommandGroupLength.Data; AffectedSOPClassUID = sel.AffectedSOPClassUID.Data; CommandField = (ushort) C.C_MOVE_RP; MessageIDBeingResponsedTo = sel.MessageIDBeingRespondedTo.Data; DataSetType = sel.CommandDataSetType.Data; NumberOfFailedOps = sel.NumberOfFailedSuboperations != null ? sel.NumberOfFailedSuboperations.Data : (ushort) 0; NumberOfRemainingOps = sel.NumberOfRemainingSuboperations != null ? sel.NumberOfRemainingSuboperations.Data : (ushort) 0; NumberOfCompletedOps = sel.NumberOfCompletedSuboperations != null ? sel.NumberOfCompletedSuboperations.Data : (ushort) 0; NumberOfWarningOps = sel.NumberOfWarningSuboperations != null ? sel.NumberOfWarningSuboperations.Data : (ushort) 0; Status = sel.Status.Data; }
private void vidangeligne(String nom) { var dcm = DICOMObject.Read(nom); var sel = new DICOMSelector(dcm); try { var Vertical = sel.TableTopVerticalPosition_; var Longitudinal = sel.TableTopLongitudinalPosition_; var Lateral = sel.TableTopLateralPosition_; for (int i = 0; i < Vertical.Count; i++) { sel.TableTopVerticalPosition_[i].Data_.Clear(); } for (int j = 0; j < Longitudinal.Count; j++) { sel.TableTopLongitudinalPosition_[j].Data_.Clear(); } for (int k = 0; k < Lateral.Count; k++) { sel.TableTopLateralPosition_[k].Data_.Clear(); } Console.WriteLine("- Les lignes 'Table TopVertical Position', 'Table Top Longitudinal Position' et 'TableTopLateralPosition' sont vide."); } catch (NullReferenceException) { MessageBox.Show("Impossible de vider les lignes pour le fichier " + nom, "Erreur", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); status.ForeColor = System.Drawing.Color.Red; status.Text = "Modification interrompu "; test = false; } dcm.Write(nom); }
public CMoveResponse(DICOMObject d) : base(d) { var sel = new DICOMSelector(d); GroupLength = sel.CommandGroupLength.Data; AffectedSOPClassUID = sel.AffectedSOPClassUID.Data; CommandField = (ushort)C.C_MOVE_RP; MessageIDBeingRespondedTo = sel.MessageIDBeingRespondedTo.Data; DataSetType = sel.CommandDataSetType.Data; NumberOfFailedOps = sel.NumberOfFailedSuboperations != null ? sel.NumberOfFailedSuboperations.Data : (ushort)0; NumberOfRemainingOps = sel.NumberOfRemainingSuboperations != null ? sel.NumberOfRemainingSuboperations.Data : (ushort)0; NumberOfCompletedOps = sel.NumberOfCompletedSuboperations != null ? sel.NumberOfCompletedSuboperations.Data : (ushort)0; NumberOfWarningOps = sel.NumberOfWarningSuboperations != null ? sel.NumberOfWarningSuboperations.Data : (ushort)0; Status = sel.Status.Data; }
/// <summary> /// Constructor con asignación. Lee la ruta del DICOM, lo lee y decodifica la informacion de pixeles. NO NORMALIZA /// </summary> /// <param name="ruta">Ruta del DICOM a leer</param> public MyDicom(string ruta) { dcm = DICOMObject.Read(@ruta); selector = dcm.GetSelector(); pixelData = Byte2Pixels16((List<byte>)selector.PixelData.Data_, Convert.ToInt16(selector.Columns.Data), Convert.ToInt16(selector.Rows.Data), Convert.ToInt16(selector.PixelRepresentation.Data), Convert.ToDouble(selector.RescaleSlope.Data), Convert.ToDouble(selector.RescaleIntercept.Data), Convert.ToString(selector.PhotometricInterpretation.Data)); }
public AbstractDIMSEIOD(DICOMObject dcm) { _sel = new DICOMSelector(dcm); }
public AbstractDIMSEIOD() { _sel = new DICOMSelector(new DICOMObject()); }