Leadtools.Dicom名前空間 > DicomDataSetクラス > SetIntValueメソッド :SetIntValue(DicomElement、IntPtr、Int32)メソッド |
'Declaration
Public Overloads Function SetIntValue( _ ByVal element As DicomElement, _ ByVal value As IntPtr, _ ByVal count As Integer _ ) As Boolean
'Usage
Dim instance As DicomDataSet Dim element As DicomElement Dim value As IntPtr Dim count As Integer Dim value As Boolean value = instance.SetIntValue(element, value, count)
public boolean setIntValue(DicomElement element, int[] intValue, int count)
データ要素の値フィールドで1つ以上の値を設定して、すべての整数値を整数値の配列に置いて、値を配列のアドレスに設定して、設定したいならば、エントリの対応する数まで数えます。たとえば、データ要素の値フィールドで3整数値を設定して、3整数値を格納している整数値の配列を作成して、値を配列のアドレスに設定して、設定することを望むならば、3まで数えます。
1つ以上の値がデータ要素の値フィールドで保存されるならば、同時にすべての値を設定しなければなりません。
データ要素の値表現が以下の通りである場合だけ、このメソッドは呼び出されることができます:
値表現の詳細については、「デフォルト値表現表」を参照してください。このサンプルはDICOMデータセットを初期化して、それから様々な種類の要素を挿入して、値を更新して、データセットから後ろへ読むことによって、最後にそれらの値を確かめます。
Imports Leadtools Imports Leadtools.Dicom <TestMethod()> _ Public Sub DicomSetGetValueTest() 'Make sure to initialize the DICOM engine, this needs to be done only once 'In the whole application DicomEngine.Startup() Dim dicomDataset As DicomDataSet = New DicomDataSet() Using (dicomDataset) dicomDataset.Reset() dicomDataset.Initialize(DicomClassType.Undefined, DicomDataSetInitializeType.ExplicitVRLittleEndian) Dim element As DicomElement = dicomDataset.InsertElement(Nothing, False, DicomTag.CineRate, DicomVRType.IS, False, 0) If Not element Is Nothing Then dicomDataset.SetIntValue(element, New Integer() {30}, 1) Dim value As Integer() = dicomDataset.GetIntValue(element, 0, 1) ' can also call GetLongValue Debug.Assert(value(0) = 30) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.ChannelMaximumValue, DicomVRType.OB, False, 0) If Not element Is Nothing Then dicomDataset.SetByteValue(element, New Byte() {55}, 1) Dim value As Byte() = dicomDataset.GetByteValue(element, 0, 1) Debug.Assert(value(0) = 55) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.PregnancyStatus, DicomVRType.US, False, 0) If Not element Is Nothing Then dicomDataset.SetShortValue(element, New Short() {2}, 1) Dim value As Short() = dicomDataset.GetShortValue(element, 0, 1) Debug.Assert(value(0) = 2) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.SliceLocation, DicomVRType.DS, False, 0) If Not element Is Nothing Then dicomDataset.SetDoubleValue(element, New Double() {10.5}, 1) Dim value As Double() = dicomDataset.GetDoubleValue(element, 0, 1) Debug.Assert(value(0) = 10.5) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.PresentationPixelMagnificationRatio, DicomVRType.FL, False, 0) If Not element Is Nothing Then dicomDataset.SetFloatValue(element, New Single() {3.2F}, 1) Dim value As Single() = dicomDataset.GetFloatValue(element, 0, 1) Debug.Assert(value(0) = 3.2F) ' Or you can use this overload dicomDataset.SetFloatValue(element, 4.0F) value = dicomDataset.GetFloatValue(element, 0, 1) Debug.Assert(value(0) = 4.0F) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.InstanceCreationDate, DicomVRType.DA, False, 0) If Not element Is Nothing Then Dim newvalue As DicomDateValue() = New DicomDateValue(0) {} newvalue(0).Year = 2004 newvalue(0).Month = 1 newvalue(0).Day = 8 dicomDataset.SetDateValue(element, newvalue) Dim value As DicomDateValue() = dicomDataset.GetDateValue(element, 0, 1) Debug.Assert((value(0).Year = 2004) AndAlso (value(0).Month = 1) AndAlso (value(0).Day = 8)) ' Or you can use the SetDateValue overload that takes a single DicomDateValue dicomDataset.SetDateValue(element, New DicomDateValue(1961, 6, 5)) value = dicomDataset.GetDateValue(element, 0, 1) Debug.Assert((value(0).Year = 1961) AndAlso (value(0).Month = 6) AndAlso (value(0).Day = 5)) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.InstanceCreationTime, DicomVRType.TM, False, 0) If Not element Is Nothing Then Dim newvalue As DicomTimeValue() = New DicomTimeValue(0) {} newvalue(0).Hours = 2 newvalue(0).Minutes = 3 newvalue(0).Seconds = 5 dicomDataset.SetTimeValue(element, newvalue) Dim value As DicomTimeValue() = dicomDataset.GetTimeValue(element, 0, 1) Debug.Assert((value(0).Hours = 2) AndAlso (value(0).Minutes = 3) AndAlso (value(0).Seconds = 5)) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.AcquisitionDateTime, DicomVRType.DT, False, 0) If Not element Is Nothing Then Dim newvalue As DicomDateTimeValue() = New DicomDateTimeValue(0) {} newvalue(0).Year = 2004 newvalue(0).Month = 1 newvalue(0).Day = 8 newvalue(0).Hours = 2 newvalue(0).Minutes = 3 newvalue(0).Seconds = 5 dicomDataset.SetDateTimeValue(element, newvalue) Dim value As DicomDateTimeValue() = dicomDataset.GetDateTimeValue(element, 0, 1) Debug.Assert((value(0).Hours = 2) AndAlso (value(0).Minutes = 3) AndAlso (value(0).Seconds = 5)) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.PatientAge, DicomVRType.AS, False, 0) If Not element Is Nothing Then Dim newvalue As DicomAgeValue() = New DicomAgeValue(0) {} newvalue(0).Number = 25 newvalue(0).Reference = DicomAgeReferenceType.Days dicomDataset.SetAgeValue(element, newvalue) Dim value As DicomAgeValue() = dicomDataset.GetAgeValue(element, 0, 1) Debug.Assert((value(0).Number = 25)) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.PatientName, DicomVRType.PN, False, 0) If Not element Is Nothing Then dicomDataset.FreeElementValue(element) dicomDataset.SetStringValue(element, "John Doe", DicomCharacterSetType.Default) Debug.Assert(dicomDataset.GetElementValueCount(element) = 1) Debug.Assert(dicomDataset.GetStringValue(element, 0) = "John Doe") End If Dim inPreamble As Byte() = New Byte(127) {} For i As Integer = 0 To 127 inPreamble(i) = CByte(i) Next i dicomDataset.SetPreamble(inPreamble, 0, 128) Dim outPreamble As Byte() = dicomDataset.GetPreamble(128) ' Or you can use this overload which takes an offset dicomDataset.GetPreamble(outPreamble, 0, 128) Debug.Assert(inPreamble.Length = outPreamble.Length) element = dicomDataset.FindFirstElement(element, DicomTag.NumberOfRemainingSubOperations, True) If Not element Is Nothing Then 'We don't really need to do this dicomDataset.FreeElementValue(element) Dim inBinaryValue As Byte() = New Byte(1) {} inBinaryValue(0) = 0 inBinaryValue(1) = 1 dicomDataset.SetBinaryValue(element, inBinaryValue, 2) Dim outBinaryValue As Byte() = dicomDataset.GetBinaryValue(element, 2) Debug.Assert((outBinaryValue(0) = 0) AndAlso (outBinaryValue(1) = 1)) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.StudyDate, DicomVRType.DA, False, 0) If Not element Is Nothing Then Dim date1 As DicomDateValue = New DicomDateValue() date1.Day = 1 date1.Month = 2 date1.Year = 2005 Dim newvalue As DicomDateRangeValue() = New DicomDateRangeValue(0) {} newvalue(0).Date1 = date1 newvalue(0).Type = DicomRangeType.Lower dicomDataset.SetDateRangeValue(element, newvalue) Dim value As DicomDateRangeValue = dicomDataset.GetDateRangeValue(element, 0) Debug.Assert((value.Type = DicomRangeType.Lower) AndAlso (value.Date1.Year = 2005)) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.StudyTime, DicomVRType.TM, False, 0) If Not element Is Nothing Then Dim time1 As DicomTimeValue = New DicomTimeValue() time1.Hours = 2 time1.Minutes = 1 time1.Seconds = 3 Dim newvalue As DicomTimeRangeValue() = New DicomTimeRangeValue(0) {} newvalue(0).Time1 = time1 newvalue(0).Type = DicomRangeType.Lower dicomDataset.SetTimeRangeValue(element, newvalue) Dim value As DicomTimeRangeValue = dicomDataset.GetTimeRangeValue(element, 0) Debug.Assert((value.Type = DicomRangeType.Lower) AndAlso (value.Time1.Hours = 2)) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.PatientID, DicomVRType.LO, False, 0) If Not element Is Nothing Then dicomDataset.SetConvertValue(element, "154-4485", 1) Debug.Assert(dicomDataset.GetConvertValue(element) = "154-4485") End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.SelectorULValue, DicomVRType.UL, False, 0) If Not element Is Nothing Then ' Set two unsigned integer values (minimum and maximum unsigned 32-bit values) Dim values() As Long = {0, 4294967295} dicomDataset.SetLongValue(element, values, 2) Dim s As String = dicomDataset.GetConvertValue(element) Debug.Assert(dicomDataset.GetConvertValue(element) = "0\4294967295") End If dicomDataset.Save(Path.Combine(LEAD_VARS.ImagesDir, "Test.dcm"), DicomDataSetSaveFlags.None) End Using DicomEngine.Shutdown() End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
using Leadtools; using Leadtools.Dicom; [TestMethod] public void DicomSetGetValueTest() { //Make sure to initialize the DICOM engine, this needs to be done only once //In the whole application DicomEngine.Startup(); using (DicomDataSet dicomDataset = new DicomDataSet()) { dicomDataset.Reset(); dicomDataset.Initialize(DicomClassType.Undefined, DicomDataSetInitializeType.ExplicitVRLittleEndian); DicomElement element = dicomDataset.InsertElement(null, false, DicomTag.CineRate, DicomVRType.IS, false, 0); if (element != null) { dicomDataset.SetIntValue(element, new int[] { 30 }, 1); int[] value = dicomDataset.GetIntValue(element, 0, 1);// can also call GetLongValue Debug.Assert(value[0] == 30); } element = dicomDataset.InsertElement(null, false, DicomTag.ChannelMaximumValue, DicomVRType.OB, false, 0); if (element != null) { dicomDataset.SetByteValue(element, new byte[] { 55 }, 1); byte[] value = dicomDataset.GetByteValue(element, 0, 1); Debug.Assert(value[0] == 55); } element = dicomDataset.InsertElement(null, false, DicomTag.PregnancyStatus, DicomVRType.US, false, 0); if (element != null) { dicomDataset.SetShortValue(element, new short[] { 2 }, 1); short[] value = dicomDataset.GetShortValue(element, 0, 1); Debug.Assert(value[0] == 2); } element = dicomDataset.InsertElement(null, false, DicomTag.SliceLocation, DicomVRType.DS, false, 0); if (element != null) { dicomDataset.SetDoubleValue(element, new double[] { 10.5 }, 1); double[] value = dicomDataset.GetDoubleValue(element, 0, 1); Debug.Assert(value[0] == 10.5); } element = dicomDataset.InsertElement(null, false, DicomTag.PresentationPixelMagnificationRatio, DicomVRType.FL, false, 0); if (element != null) { dicomDataset.SetFloatValue(element, new float[] { 3.2F }, 1); float[] value = dicomDataset.GetFloatValue(element, 0, 1); Debug.Assert(value[0] == 3.2F); // Or you can use this overload dicomDataset.SetFloatValue(element, 4.0F); value = dicomDataset.GetFloatValue(element, 0, 1); Debug.Assert(value[0] == 4.0F); } element = dicomDataset.InsertElement(null, false, DicomTag.InstanceCreationDate, DicomVRType.DA, false, 0); if (element != null) { DicomDateValue[] newvalue = new DicomDateValue[1]; newvalue[0].Year = 2004; newvalue[0].Month = 1; newvalue[0].Day = 8; dicomDataset.SetDateValue(element, newvalue); DicomDateValue[] value = dicomDataset.GetDateValue(element, 0, 1); Debug.Assert((value[0].Year == 2004) && (value[0].Month == 1) && (value[0].Day == 8)); // Or you can use the SetDateValue overload that takes a single DicomDateValue dicomDataset.SetDateValue(element, new DicomDateValue(1961, 6, 5)); value = dicomDataset.GetDateValue(element, 0, 1); Debug.Assert((value[0].Year == 1961) && (value[0].Month == 6) && (value[0].Day == 5)); } element = dicomDataset.InsertElement(null, false, DicomTag.InstanceCreationTime, DicomVRType.TM, false, 0); if (element != null) { DicomTimeValue[] newvalue = new DicomTimeValue[1]; newvalue[0].Hours = 2; newvalue[0].Minutes = 3; newvalue[0].Seconds = 5; dicomDataset.SetTimeValue(element, newvalue); DicomTimeValue[] value = dicomDataset.GetTimeValue(element, 0, 1); Debug.Assert((value[0].Hours == 2) && (value[0].Minutes == 3) && (value[0].Seconds == 5)); } element = dicomDataset.InsertElement(null, false, DicomTag.AcquisitionDateTime, DicomVRType.DT, false, 0); if (element != null) { DicomDateTimeValue[] newvalue = new DicomDateTimeValue[1]; newvalue[0].Year = 2004; newvalue[0].Month = 1; newvalue[0].Day = 8; newvalue[0].Hours = 2; newvalue[0].Minutes = 3; newvalue[0].Seconds = 5; dicomDataset.SetDateTimeValue(element, newvalue); DicomDateTimeValue[] value = dicomDataset.GetDateTimeValue(element, 0, 1); Debug.Assert((value[0].Hours == 2) && (value[0].Minutes == 3) && (value[0].Seconds == 5)); } element = dicomDataset.InsertElement(null, false, DicomTag.PatientAge, DicomVRType.AS, false, 0); if (element != null) { DicomAgeValue[] newvalue = new DicomAgeValue[1]; newvalue[0].Number = 25; newvalue[0].Reference = DicomAgeReferenceType.Days; dicomDataset.SetAgeValue(element, newvalue); DicomAgeValue[] value = dicomDataset.GetAgeValue(element, 0, 1); Debug.Assert((value[0].Number == 25)); } element = dicomDataset.InsertElement(null, false, DicomTag.PatientName, DicomVRType.PN, false, 0); if (element != null) { dicomDataset.FreeElementValue(element); dicomDataset.SetStringValue(element, "John Doe", DicomCharacterSetType.Default); Debug.Assert(dicomDataset.GetElementValueCount(element) == 1); Debug.Assert(dicomDataset.GetStringValue(element, 0) == "John Doe"); } byte[] inPreamble = new byte[128]; for (int i = 0; i < 128; i++) { inPreamble[i] = (byte)i; } dicomDataset.SetPreamble(inPreamble, 0, 128); byte[] outPreamble = dicomDataset.GetPreamble(128); // Or you can use this overload which takes an offset dicomDataset.GetPreamble(out outPreamble, 0, 128); Debug.Assert(inPreamble.Length == outPreamble.Length); element = dicomDataset.FindFirstElement(element, DicomTag.NumberOfRemainingSubOperations, true); if (element != null) { //We don't really need to do this dicomDataset.FreeElementValue(element); byte[] inBinaryValue = new byte[2]; inBinaryValue[0] = 0; inBinaryValue[1] = 1; dicomDataset.SetBinaryValue(element, inBinaryValue, 2); byte[] outBinaryValue = dicomDataset.GetBinaryValue(element, 2); Debug.Assert((outBinaryValue[0] == 0) && (outBinaryValue[1] == 1)); } element = dicomDataset.InsertElement(null, false, DicomTag.StudyDate, DicomVRType.DA, false, 0); if (element != null) { DicomDateValue date1 = new DicomDateValue(); date1.Day = 1; date1.Month = 2; date1.Year = 2005; DicomDateRangeValue[] newvalue = new DicomDateRangeValue[1]; newvalue[0].Date1 = date1; newvalue[0].Type = DicomRangeType.Lower; dicomDataset.SetDateRangeValue(element, newvalue); DicomDateRangeValue value = dicomDataset.GetDateRangeValue(element, 0); Debug.Assert((value.Type == DicomRangeType.Lower) && (value.Date1.Year == 2005)); } element = dicomDataset.InsertElement(null, false, DicomTag.StudyTime, DicomVRType.TM, false, 0); if (element != null) { DicomTimeValue time1 = new DicomTimeValue(); time1.Hours = 2; time1.Minutes = 1; time1.Seconds = 3; DicomTimeRangeValue[] newvalue = new DicomTimeRangeValue[1]; newvalue[0].Time1 = time1; newvalue[0].Type = DicomRangeType.Lower; dicomDataset.SetTimeRangeValue(element, newvalue); DicomTimeRangeValue value = dicomDataset.GetTimeRangeValue(element, 0); Debug.Assert((value.Type == DicomRangeType.Lower) && (value.Time1.Hours == 2)); } element = dicomDataset.InsertElement(null, false, DicomTag.PatientID, DicomVRType.LO, false, 0); if (element != null) { dicomDataset.SetConvertValue(element, "154-4485", 1); Debug.Assert(dicomDataset.GetConvertValue(element) == "154-4485"); } element = dicomDataset.InsertElement(null, false, DicomTag.SelectorULValue, DicomVRType.UL, false, 0); if (element != null) { // Set two unsigned integer values (minimum and maximum unsigned 32-bit values) long[] values = new long[] { 0, 4294967295 }; dicomDataset.SetLongValue(element, values, 2); string s = dicomDataset.GetConvertValue(element); Debug.Assert(dicomDataset.GetConvertValue(element) == "0\\4294967295"); } dicomDataset.Save(Path.Combine(LEAD_VARS.ImagesDir,"Test.dcm"), DicomDataSetSaveFlags.None); } DicomEngine.Shutdown(); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
using Leadtools.Dicom.Constants; using Leadtools; using Leadtools.Dicom; [TestMethod] public async Task DicomSetGetValueTest() { //Make sure to initialize the DICOM engine, this needs to be done only once //In the whole application DicomEngine.Startup(); using (DicomDataSet dicomDataset = new DicomDataSet()) { dicomDataset.Reset(); dicomDataset.Initialize(DicomClassType.Undefined, DicomDataSetInitializeType.ExplicitVRLittleEndian); DicomElement element = dicomDataset.InsertElement(null, false, DicomTagConstants.CineRate, DicomVRType.IS, false, 0); if (element != null) { dicomDataset.SetIntValue(element, new int[] { 30 }, 1); int[] value = dicomDataset.GetIntValue(element, 0, 1);// can also call GetLongValue Debug.Assert(value[0] == 30); } element = dicomDataset.InsertElement(null, false, DicomTagConstants.ChannelMaximumValue, DicomVRType.OB, false, 0); if (element != null) { dicomDataset.SetByteValue(element, new byte[] { 55 }, 1); byte[] value = dicomDataset.GetByteValue(element, 0, 1); Debug.Assert(value[0] == 55); } element = dicomDataset.InsertElement(null, false, DicomTagConstants.PregnancyStatus, DicomVRType.US, false, 0); if (element != null) { dicomDataset.SetShortValue(element, new short[] { 2 }, 1); short[] value = dicomDataset.GetShortValue(element, 0, 1); Debug.Assert(value[0] == 2); } element = dicomDataset.InsertElement(null, false, DicomTagConstants.SliceLocation, DicomVRType.DS, false, 0); if (element != null) { dicomDataset.SetDoubleValue(element, new double[] { 10.5 }, 1); double[] value = dicomDataset.GetDoubleValue(element, 0, 1); Debug.Assert(value[0] == 10.5); } element = dicomDataset.InsertElement(null, false, DicomTagConstants.PresentationPixelAspectRatio, DicomVRType.FL, false, 0); if (element != null) { dicomDataset.SetFloatValue(element, new float[] { 3.2F }, 1); float[] value = dicomDataset.GetFloatValue(element, 0, 1); Debug.Assert(value[0] == 3.2F); // Or you can use this overload dicomDataset.SetFloatValue(element, 4.0F); value = dicomDataset.GetFloatValue(element, 0, 1); Debug.Assert(value[0] == 4.0F); } element = dicomDataset.InsertElement(null, false, DicomTagConstants.InstanceCreationDate, DicomVRType.DA, false, 0); if (element != null) { DicomDateValue[] newvalue = new DicomDateValue[1]; newvalue[0].Year = 2004; newvalue[0].Month = 1; newvalue[0].Day = 8; dicomDataset.SetDateValue(element, newvalue); DicomDateValue[] value = dicomDataset.GetDateValue(element, 0, 1); Debug.Assert((value[0].Year == 2004) && (value[0].Month == 1) && (value[0].Day == 8)); // Or you can use the SetDateValue overload that takes a single DicomDateValue dicomDataset.SetDateValue(element, DicomDateValueHelper.Create(1961, 6, 5)); value = dicomDataset.GetDateValue(element, 0, 1); Debug.Assert((value[0].Year == 1961) && (value[0].Month == 6) && (value[0].Day == 5)); } element = dicomDataset.InsertElement(null, false, DicomTagConstants.InstanceCreationTime, DicomVRType.TM, false, 0); if (element != null) { DicomTimeValue[] newvalue = new DicomTimeValue[1]; newvalue[0].Hours = 2; newvalue[0].Minutes = 3; newvalue[0].Seconds = 5; dicomDataset.SetTimeValue(element, newvalue); DicomTimeValue[] value = dicomDataset.GetTimeValue(element, 0, 1); Debug.Assert((value[0].Hours == 2) && (value[0].Minutes == 3) && (value[0].Seconds == 5)); } element = dicomDataset.InsertElement(null, false, DicomTagConstants.AcquisitionDateTime, DicomVRType.DT, false, 0); if (element != null) { DicomDateTimeValue[] newvalue = new DicomDateTimeValue[1]; newvalue[0].Year = 2004; newvalue[0].Month = 1; newvalue[0].Day = 8; newvalue[0].Hours = 2; newvalue[0].Minutes = 3; newvalue[0].Seconds = 5; dicomDataset.SetDateTimeValue(element, newvalue); DicomDateTimeValue[] value = dicomDataset.GetDateTimeValue(element, 0, 1); Debug.Assert((value[0].Hours == 2) && (value[0].Minutes == 3) && (value[0].Seconds == 5)); } element = dicomDataset.InsertElement(null, false, DicomTagConstants.PatientAge, DicomVRType.AS, false, 0); if (element != null) { DicomAgeValue[] newvalue = new DicomAgeValue[1]; newvalue[0].Number = 25; newvalue[0].Reference = DicomAgeReferenceType.Days; dicomDataset.SetAgeValue(element, newvalue); DicomAgeValue[] value = dicomDataset.GetAgeValue(element, 0, 1); Debug.Assert((value[0].Number == 25)); } element = dicomDataset.InsertElement(null, false, DicomTagConstants.PatientName, DicomVRType.PN, false, 0); if (element != null) { dicomDataset.FreeElementValue(element); dicomDataset.SetStringValue(element, "John Doe", DicomCharacterSetType.Default); Debug.Assert(dicomDataset.GetElementValueCount(element) == 1); Debug.Assert(dicomDataset.GetStringValue(element, 0) == "John Doe"); } byte[] inPreamble = new byte[128]; for (int i = 0; i < 128; i++) { inPreamble[i] = (byte)i; } dicomDataset.SetPreamble(inPreamble, 0, 128); byte[] outPreamble_test1 = new byte[128]; byte[] outPreamble_test2 = new byte[128]; outPreamble_test1 = dicomDataset.GetPreamble(128); dicomDataset.GetPreamble(outPreamble_test2, 0, 128);// Or you can use this overload which takes an offset var joinResult = from a in outPreamble_test1 join b in outPreamble_test2 on a equals b select a; Debug.Assert(outPreamble_test1.Length == outPreamble_test2.Length); Debug.Assert(joinResult.Count() == outPreamble_test1.Length); element = dicomDataset.FindFirstElement(element, DicomTagConstants.NumberOfRemainingSubOperations, true); if (element != null) { //We don't really need to do this dicomDataset.FreeElementValue(element); byte[] inBinaryValue = new byte[2]; inBinaryValue[0] = 0; inBinaryValue[1] = 1; dicomDataset.SetBinaryValue(element, inBinaryValue, 2); byte[] outBinaryValue = dicomDataset.GetBinaryValue(element, 2); Debug.Assert((outBinaryValue[0] == 0) && (outBinaryValue[1] == 1)); } element = dicomDataset.InsertElement(null, false, DicomTagConstants.StudyDate, DicomVRType.DA, false, 0); if (element != null) { DicomDateValue date1 = new DicomDateValue(); date1.Day = 1; date1.Month = 2; date1.Year = 2005; DicomDateRangeValue[] newvalue = new DicomDateRangeValue[1]; newvalue[0].Date1 = date1; newvalue[0].Type = DicomRangeType.Lower; dicomDataset.SetDateRangeValue(element, newvalue); DicomDateRangeValue value = dicomDataset.GetDateRangeValue(element, 0); Debug.Assert((value.Type == DicomRangeType.Lower) && (value.Date1.Year == 2005)); } element = dicomDataset.InsertElement(null, false, DicomTagConstants.StudyTime, DicomVRType.TM, false, 0); if (element != null) { DicomTimeValue time1 = new DicomTimeValue(); time1.Hours = 2; time1.Minutes = 1; time1.Seconds = 3; DicomTimeRangeValue[] newvalue = new DicomTimeRangeValue[1]; newvalue[0].Time1 = time1; newvalue[0].Type = DicomRangeType.Lower; dicomDataset.SetTimeRangeValue(element, newvalue); DicomTimeRangeValue value = dicomDataset.GetTimeRangeValue(element, 0); Debug.Assert((value.Type == DicomRangeType.Lower) && (value.Time1.Hours == 2)); } element = dicomDataset.InsertElement(null, false, DicomTagConstants.PatientID, DicomVRType.LO, false, 0); if (element != null) { dicomDataset.SetConvertValue(element, "154-4485", 1); Debug.Assert(dicomDataset.GetConvertValue(element) == "154-4485"); } element = dicomDataset.InsertElement(null, false, DicomTagConstants.SelectorULValue, DicomVRType.UL, false, 0); if (element != null) { // Set two unsigned integer values (minimum and maximum unsigned 32-bit values) long[] values = new long[] { 0, 4294967295 }; dicomDataset.SetLongValue(element, values, 2); string s = dicomDataset.GetConvertValue(element); Debug.Assert(dicomDataset.GetConvertValue(element) == "0\\4294967295"); } StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync("Test.dcm"); ILeadStream saveStream = LeadStreamFactory.Create(saveFile); using (IDisposable disposable = saveStream as IDisposable) { await dicomDataset.SaveAsync(saveStream, DicomDataSetSaveFlags.None); } } DicomEngine.Shutdown(); }
using Leadtools; using Leadtools.Dicom; using Leadtools.Examples; public void DicomSetGetValueTest(Stream outputStream) { //Make sure to initialize the DICOM engine, this needs to be done only once //In the whole application DicomEngine.Startup(); using (DicomDataSet dicomDataset = new DicomDataSet()) { dicomDataset.Reset(); dicomDataset.Initialize(DicomClassType.Undefined, DicomDataSetInitializeType.ExplicitVRLittleEndian); DicomElement element = dicomDataset.InsertElement(null, false, DicomTag.CineRate, DicomVRType.IS, false, 0); if (element != null) { dicomDataset.SetIntValue(element, new int[] { 30 }, 1); int[] value = dicomDataset.GetIntValue(element, 0, 1);// can also call GetLongValue Debug.Assert(value[0] == 30); } element = dicomDataset.InsertElement(null, false, DicomTag.ChannelMaximumValue, DicomVRType.OB, false, 0); if (element != null) { dicomDataset.SetByteValue(element, new byte[] { 55 }, 1); byte[] value = dicomDataset.GetByteValue(element, 0, 1); Debug.Assert(value[0] == 55); } element = dicomDataset.InsertElement(null, false, DicomTag.NumberOfRemainingSubOperations, DicomVRType.US, false, 0); if (element != null) { dicomDataset.SetShortValue(element, new short[] { 2 }, 1); short[] value = dicomDataset.GetShortValue(element, 0, 1); Debug.Assert(value[0] == 2); } element = dicomDataset.InsertElement(null, false, DicomTag.SliceLocation, DicomVRType.DS, false, 0); if (element != null) { dicomDataset.SetDoubleValue(element, new double[] { 10.5 }, 1); double[] value = dicomDataset.GetDoubleValue(element, 0, 1); Debug.Assert(value[0] == 10.5); } element = dicomDataset.InsertElement(null, false, DicomTag.PresentationPixelMagnificationRatio, DicomVRType.FL, false, 0); if (element != null) { dicomDataset.SetFloatValue(element, new float[] { 3.2F }, 1); float[] value = dicomDataset.GetFloatValue(element, 0, 1); Debug.Assert(value[0] == 3.2F); } element = dicomDataset.InsertElement(null, false, DicomTag.InstanceCreationDate, DicomVRType.DA, false, 0); if (element != null) { DicomDateValue[] newvalue = new DicomDateValue[1]; newvalue[0].Year = 2004; newvalue[0].Month = 1; newvalue[0].Day = 8; dicomDataset.SetDateValue(element, newvalue); DicomDateValue[] value = dicomDataset.GetDateValue(element, 0, 1); Debug.Assert((value[0].Year == 2004) && (value[0].Month == 1) && (value[0].Day == 8)); // Or you can use the SetDateValue overload that takes a single DicomDateValue dicomDataset.SetDateValue(element, new DicomDateValue(1961, 6, 5)); value = dicomDataset.GetDateValue(element, 0, 1); Debug.Assert((value[0].Year == 1961) && (value[0].Month == 6) && (value[0].Day == 5)); } element = dicomDataset.InsertElement(null, false, DicomTag.InstanceCreationTime, DicomVRType.TM, false, 0); if (element != null) { DicomTimeValue[] newvalue = new DicomTimeValue[1]; newvalue[0].Hours = 2; newvalue[0].Minutes = 3; newvalue[0].Seconds = 5; dicomDataset.SetTimeValue(element, newvalue); DicomTimeValue[] value = dicomDataset.GetTimeValue(element, 0, 1); Debug.Assert((value[0].Hours == 2) && (value[0].Minutes == 3) && (value[0].Seconds == 5)); } element = dicomDataset.InsertElement(null, false, DicomTag.AcquisitionDateTime, DicomVRType.DT, false, 0); if (element != null) { DicomDateTimeValue[] newvalue = new DicomDateTimeValue[1]; newvalue[0].Year = 2004; newvalue[0].Month = 1; newvalue[0].Day = 8; newvalue[0].Hours = 2; newvalue[0].Minutes = 3; newvalue[0].Seconds = 5; dicomDataset.SetDateTimeValue(element, newvalue); DicomDateTimeValue[] value = dicomDataset.GetDateTimeValue(element, 0, 1); Debug.Assert((value[0].Hours == 2) && (value[0].Minutes == 3) && (value[0].Seconds == 5)); } element = dicomDataset.InsertElement(null, false, DicomTag.PatientAge, DicomVRType.AS, false, 0); if (element != null) { DicomAgeValue[] newvalue = new DicomAgeValue[1]; newvalue[0].Number = 25; newvalue[0].Reference = DicomAgeReferenceType.Days; dicomDataset.SetAgeValue(element, newvalue); DicomAgeValue[] value = dicomDataset.GetAgeValue(element, 0, 1); Debug.Assert((value[0].Number == 25)); } element = dicomDataset.InsertElement(null, false, DicomTag.PatientName, DicomVRType.PN, false, 0); if (element != null) { dicomDataset.FreeElementValue(element); dicomDataset.SetStringValue(element, "John Doe", DicomCharacterSetType.Default); Debug.Assert(dicomDataset.GetElementValueCount(element) == 1); Debug.Assert(dicomDataset.GetStringValue(element, 0) == "John Doe"); } byte[] inPreamble = new byte[128]; for (int i = 0; i < 128; i++) { inPreamble[i] = (byte)i; } dicomDataset.SetPreamble(inPreamble, 0, 128); byte[] outPreamble = dicomDataset.GetPreamble(128); Debug.Assert(inPreamble.Length == outPreamble.Length); element = dicomDataset.FindFirstElement(element, DicomTag.NumberOfRemainingSubOperations, true); if (element != null) { //We don't really need to do this dicomDataset.FreeElementValue(element); byte[] inBinaryValue = new byte[2]; inBinaryValue[0] = 0; inBinaryValue[1] = 1; dicomDataset.SetBinaryValue(element, inBinaryValue, 2); byte[] outBinaryValue = dicomDataset.GetBinaryValue(element, 2); Debug.Assert((outBinaryValue[0] == 0) && (outBinaryValue[1] == 1)); } element = dicomDataset.InsertElement(null, false, DicomTag.StudyDate, DicomVRType.DA, false, 0); if (element != null) { DicomDateValue date1 = new DicomDateValue(); date1.Day = 1; date1.Month = 2; date1.Year = 2005; DicomDateRangeValue[] newvalue = new DicomDateRangeValue[1]; newvalue[0].Date1 = date1; newvalue[0].Type = DicomRangeType.Lower; dicomDataset.SetDateRangeValue(element, newvalue); DicomDateRangeValue value = dicomDataset.GetDateRangeValue(element, 0); Debug.Assert((value.Type == DicomRangeType.Lower) && (value.Date1.Year == 2005)); } element = dicomDataset.InsertElement(null, false, DicomTag.StudyTime, DicomVRType.TM, false, 0); if (element != null) { DicomTimeValue time1 = new DicomTimeValue(); time1.Hours = 2; time1.Minutes = 1; time1.Seconds = 3; DicomTimeRangeValue[] newvalue = new DicomTimeRangeValue[1]; newvalue[0].Time1 = time1; newvalue[0].Type = DicomRangeType.Lower; dicomDataset.SetTimeRangeValue(element, newvalue); DicomTimeRangeValue value = dicomDataset.GetTimeRangeValue(element, 0); Debug.Assert((value.Type == DicomRangeType.Lower) && (value.Time1.Hours == 2)); } element = dicomDataset.InsertElement(null, false, DicomTag.PatientID, DicomVRType.LO, false, 0); if (element != null) { dicomDataset.SetConvertValue(element, "154-4485", 1); Debug.Assert(dicomDataset.GetConvertValue(element) == "154-4485"); } element = dicomDataset.InsertElement(null, false, DicomTag.SelectorULValue, DicomVRType.UL, false, 0); if (element != null) { // Set two unsigned integer values (minimum and maximum unsigned 32-bit values) long[] values = new long[] { 0, 4294967295 }; dicomDataset.SetLongValue(element, values, 2); string s = dicomDataset.GetConvertValue(element); Debug.Assert(dicomDataset.GetConvertValue(element) == "0\\4294967295"); } dicomDataset.Save(outputStream, DicomDataSetSaveFlags.None); } DicomEngine.Shutdown(); }
Imports Leadtools Imports Leadtools.Dicom Public Sub DicomSetGetValueTest(ByVal outputStream As Stream) 'Make sure to initialize the DICOM engine, this needs to be done only once 'In the whole application DicomEngine.Startup() Using dicomDataset As DicomDataSet = New DicomDataSet() dicomDataset.Reset() dicomDataset.Initialize(DicomClassType.Undefined, DicomDataSetInitializeType.ExplicitVRLittleEndian) Dim element As DicomElement = dicomDataset.InsertElement(Nothing, False, DicomTag.CineRate, DicomVRType.IS, False, 0) If Not element Is Nothing Then dicomDataset.SetIntValue(element, New Integer() {30}, 1) Dim value As Integer() = dicomDataset.GetIntValue(element, 0, 1) ' can also call GetLongValue Debug.Assert(value(0) = 30) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.ChannelMaximumValue, DicomVRType.OB, False, 0) If Not element Is Nothing Then dicomDataset.SetByteValue(element, New Byte() { 55 }, 1) Dim value As Byte() = dicomDataset.GetByteValue(element, 0, 1) Debug.Assert(value(0) = 55) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.NumberOfRemainingSubOperations, DicomVRType.US, False, 0) If Not element Is Nothing Then dicomDataset.SetShortValue(element, New Short() { 2 }, 1) Dim value As Short() = dicomDataset.GetShortValue(element, 0, 1) Debug.Assert(value(0) = 2) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.SliceLocation, DicomVRType.DS, False, 0) If Not element Is Nothing Then dicomDataset.SetDoubleValue(element, New Double() { 10.5 }, 1) Dim value As Double() = dicomDataset.GetDoubleValue(element, 0, 1) Debug.Assert(value(0) = 10.5) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.PresentationPixelMagnificationRatio, DicomVRType.FL, False, 0) If Not element Is Nothing Then dicomDataset.SetFloatValue(element, New Single() { 3.2F }, 1) Dim value As Single() = dicomDataset.GetFloatValue(element, 0, 1) Debug.Assert(value(0) = 3.2F) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.InstanceCreationDate, DicomVRType.DA, False, 0) If Not element Is Nothing Then Dim newvalue As DicomDateValue() = New DicomDateValue(0){} newvalue(0).Year = 2004 newvalue(0).Month = 1 newvalue(0).Day = 8 dicomDataset.SetDateValue(element, newvalue) Dim value As DicomDateValue() = dicomDataset.GetDateValue(element, 0, 1) Debug.Assert((value(0).Year = 2004) AndAlso (value(0).Month = 1) AndAlso (value(0).Day = 8)) ' Or you can use the SetDateValue overload that takes a single DicomDateValue dicomDataset.SetDateValue(element, New DicomDateValue(1961, 6, 5)) value = dicomDataset.GetDateValue(element, 0, 1) Debug.Assert((value(0).Year = 1961) AndAlso (value(0).Month = 6) AndAlso (value(0).Day = 5)) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.InstanceCreationTime, DicomVRType.TM, False, 0) If Not element Is Nothing Then Dim newvalue As DicomTimeValue() = New DicomTimeValue(0){} newvalue(0).Hours = 2 newvalue(0).Minutes = 3 newvalue(0).Seconds = 5 dicomDataset.SetTimeValue(element, newvalue) Dim value As DicomTimeValue() = dicomDataset.GetTimeValue(element, 0, 1) Debug.Assert((value(0).Hours = 2) AndAlso (value(0).Minutes = 3) AndAlso (value(0).Seconds = 5)) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.AcquisitionDateTime, DicomVRType.DT, False, 0) If Not element Is Nothing Then Dim newvalue As DicomDateTimeValue() = New DicomDateTimeValue(0){} newvalue(0).Year = 2004 newvalue(0).Month = 1 newvalue(0).Day = 8 newvalue(0).Hours = 2 newvalue(0).Minutes = 3 newvalue(0).Seconds = 5 dicomDataset.SetDateTimeValue(element, newvalue) Dim value As DicomDateTimeValue() = dicomDataset.GetDateTimeValue(element, 0, 1) Debug.Assert((value(0).Hours = 2) AndAlso (value(0).Minutes = 3) AndAlso (value(0).Seconds = 5)) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.PatientAge, DicomVRType.AS, False, 0) If Not element Is Nothing Then Dim newvalue As DicomAgeValue() = New DicomAgeValue(0){} newvalue(0).Number = 25 newvalue(0).Reference = DicomAgeReferenceType.Days dicomDataset.SetAgeValue(element, newvalue) Dim value As DicomAgeValue() = dicomDataset.GetAgeValue(element, 0, 1) Debug.Assert((value(0).Number = 25)) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.PatientName, DicomVRType.PN, False, 0) If Not element Is Nothing Then dicomDataset.FreeElementValue(element) dicomDataset.SetStringValue(element, "John Doe", DicomCharacterSetType.Default) Debug.Assert(dicomDataset.GetElementValueCount(element) = 1) Debug.Assert(dicomDataset.GetStringValue(element, 0) = "John Doe") End If Dim inPreamble As Byte() = New Byte(127){} For i As Integer = 0 To 127 inPreamble(i) = CByte(i) Next i dicomDataset.SetPreamble(inPreamble, 0, 128) Dim outPreamble As Byte() = dicomDataset.GetPreamble(128) Debug.Assert(inPreamble.Length = outPreamble.Length) element = dicomDataset.FindFirstElement(element, DicomTag.NumberOfRemainingSubOperations, True) If Not element Is Nothing Then 'We don't really need to do this dicomDataset.FreeElementValue(element) Dim inBinaryValue As Byte() = New Byte(1){} inBinaryValue(0) = 0 inBinaryValue(1) = 1 dicomDataset.SetBinaryValue(element, inBinaryValue, 2) Dim outBinaryValue As Byte() = dicomDataset.GetBinaryValue(element, 2) Debug.Assert((outBinaryValue(0) = 0) AndAlso (outBinaryValue(1) = 1)) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.StudyDate, DicomVRType.DA, False, 0) If Not element Is Nothing Then Dim date1 As DicomDateValue = New DicomDateValue() date1.Day = 1 date1.Month = 2 date1.Year = 2005 Dim newvalue As DicomDateRangeValue() = New DicomDateRangeValue(0){} newvalue(0).Date1 = date1 newvalue(0).Type = DicomRangeType.Lower dicomDataset.SetDateRangeValue(element, newvalue) Dim value As DicomDateRangeValue = dicomDataset.GetDateRangeValue(element, 0) Debug.Assert((value.Type = DicomRangeType.Lower) AndAlso (value.Date1.Year = 2005)) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.StudyTime, DicomVRType.TM, False, 0) If Not element Is Nothing Then Dim time1 As DicomTimeValue = New DicomTimeValue() time1.Hours = 2 time1.Minutes = 1 time1.Seconds = 3 Dim newvalue As DicomTimeRangeValue() = New DicomTimeRangeValue(0){} newvalue(0).Time1 = time1 newvalue(0).Type = DicomRangeType.Lower dicomDataset.SetTimeRangeValue(element, newvalue) Dim value As DicomTimeRangeValue = dicomDataset.GetTimeRangeValue(element, 0) Debug.Assert((value.Type = DicomRangeType.Lower) AndAlso (value.Time1.Hours = 2)) End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.PatientID, DicomVRType.LO, False, 0) If Not element Is Nothing Then dicomDataset.SetConvertValue(element, "154-4485", 1) Debug.Assert(dicomDataset.GetConvertValue(element) = "154-4485") End If element = dicomDataset.InsertElement(Nothing, False, DicomTag.SelectorULValue, DicomVRType.UL, False, 0) If Not element Is Nothing Then ' Set two unsigned integer values (minimum and maximum unsigned 32-bit values) Dim values() As Long = {0, 4294967295} dicomDataset.SetLongValue(element, values, 2) Dim s As String = dicomDataset.GetConvertValue(element) Debug.Assert(dicomDataset.GetConvertValue(element) = "0\4294967295") End If dicomDataset.Save(outputStream, DicomDataSetSaveFlags.None) End Using DicomEngine.Shutdown() End Sub
DicomDataSetクラス
DicomDataSetメンバ
オーバーロードリスト
SetValueメソッド
SetIntValue(DicomElement、Int32[]、Int32)メソッド
SetShortValue(DicomElement、Int16[]、Int32)メソッド
SetByteValue(DicomElement、Byte[]、Int32)メソッド
SetBinaryValue(DicomElement、Byte[]、Int32)メソッド
SetStringValue(DicomElement、String、DicomCharacterSetType)メソッド
SetStringValue(DicomElement、String[]、DicomCharacterSetType)メソッド
SetStringValue(DicomElement、String)メソッド
SetStringValue(DicomElement、String[])メソッド
SetStringValuePtr(DicomElement、IntPtr、Int32)メソッド
SetStringValuePtr(DicomElement、IntPtr、UInt32、DicomCharacterSetType)メソッド
SetFloatValue(DicomElement、シングル[]、Int32)メソッド
SetDoubleValue(DicomElement、Double[]、Int32)メソッド
SetAgeValueメソッド
SetDateValue(DicomElement、DicomDateValue[])メソッド
SetTimeValue(DicomElement、DicomTimeValue[])メソッド
SetDateTimeValue(DicomElement、DicomDateTimeValue[])メソッド
SetConvertValue(DicomElement、String、Int32)メソッド