Merge pull request #27 from mlavik1/issue24-dicomfixes
Issue24: Misc dicomfixes
This commit is contained in:
Коммит
6a43f45471
|
@ -83,15 +83,15 @@ namespace openDicom.Encoding
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new EncodingException(
|
||||
"Date time format is invalid.", Tag,
|
||||
Name + "/item", item);
|
||||
UnityEngine.Debug.LogWarning($"Date time format is invalid. tag: {Tag}, name: {Name}");
|
||||
dateTime[i] = System.DateTime.Now;
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new EncodingException(
|
||||
"Date time format is invalid.", Tag, Name + "/item",
|
||||
item);
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"Date time format is invalid. tag: {Tag}, name: {Name}");
|
||||
dateTime[i] = System.DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
return dateTime;
|
||||
|
@ -123,30 +123,30 @@ namespace openDicom.Encoding
|
|||
string second = "0";
|
||||
if (item.Length > 12) second = item.Substring(12, 2);
|
||||
string millisecond = "0";
|
||||
if (item.Length > 14)
|
||||
if (item.Length > 14)
|
||||
millisecond = item.Substring(14, 6);
|
||||
string timeZone = "+0";
|
||||
if (item.Length > 20)
|
||||
if (item.Length > 20)
|
||||
timeZone = item.Substring(20, 5);
|
||||
// TODO: What to do with the time zone?
|
||||
try
|
||||
{
|
||||
dateTime[i] = new System.DateTime(int.Parse(year),
|
||||
dateTime[i] = new System.DateTime(int.Parse(year),
|
||||
int.Parse(month), int.Parse(day), int.Parse(hour),
|
||||
int.Parse(minute), int.Parse(second),
|
||||
int.Parse(millisecond));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new EncodingException(
|
||||
"Date time format is invalid.", Tag,
|
||||
Name + "/item", item);
|
||||
UnityEngine.Debug.LogWarning($"Date time format is invalid. tag: {Tag}, name: {Name}");
|
||||
dateTime[i] = System.DateTime.Now;
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new EncodingException(
|
||||
"Date time format is invalid.", Tag, Name + "/item",
|
||||
item);
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"Date time format is invalid. tag: {Tag}, name: {Name}");
|
||||
dateTime[i] = System.DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
return dateTime;
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace UnityVolumeRendering
|
|||
public float location = 0;
|
||||
public float intercept = 0.0f;
|
||||
public float slope = 1.0f;
|
||||
public float pixelSpacing = 0.0f;
|
||||
}
|
||||
|
||||
private string diroctoryPath;
|
||||
|
@ -108,6 +109,13 @@ namespace UnityVolumeRendering
|
|||
}
|
||||
}
|
||||
|
||||
if(files[0].pixelSpacing > 0.0f)
|
||||
{
|
||||
dataset.scaleX = files[0].pixelSpacing * dataset.dimX;
|
||||
dataset.scaleY = files[0].pixelSpacing * dataset.dimY;
|
||||
dataset.scaleZ = Mathf.Abs(files[files.Count - 1].location - files[0].location);
|
||||
}
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
|
@ -149,6 +157,13 @@ namespace UnityVolumeRendering
|
|||
}
|
||||
else
|
||||
Debug.LogWarning($"The file {filePath} is missing the intercept element. As a result, the default transfer function might not look good.");
|
||||
// Read pixel spacing
|
||||
Tag pixelSpacingTag = new Tag("(0028,0030)");
|
||||
if (file.DataSet.Contains(pixelSpacingTag))
|
||||
{
|
||||
DataElement elemPixelSpacing = file.DataSet[pixelSpacingTag];
|
||||
slice.pixelSpacing = (float)Convert.ToDouble(elemPixelSpacing.Value[0]);
|
||||
}
|
||||
|
||||
return slice;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ namespace UnityVolumeRendering
|
|||
public int[] data = null;
|
||||
[SerializeField]
|
||||
public int dimX, dimY, dimZ;
|
||||
[SerializeField]
|
||||
public float scaleX = 0.0f, scaleY = 0.0f, scaleZ = 0.0f;
|
||||
|
||||
[SerializeField]
|
||||
public string datasetName;
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace UnityVolumeRendering
|
|||
private void Update()
|
||||
{
|
||||
meshRenderer.sharedMaterial.SetMatrix("_parentInverseMat", transform.parent.worldToLocalMatrix);
|
||||
meshRenderer.sharedMaterial.SetMatrix("_planeMat", Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one)); // TODO: allow changing scale
|
||||
meshRenderer.sharedMaterial.SetMatrix("_planeMat", Matrix4x4.TRS(transform.position, transform.rotation, transform.parent.lossyScale)); // TODO: allow changing scale
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,12 @@ namespace UnityVolumeRendering
|
|||
meshRenderer.sharedMaterial.DisableKeyword("MODE_MIP");
|
||||
meshRenderer.sharedMaterial.DisableKeyword("MODE_SURF");
|
||||
|
||||
if(dataset.scaleX != 0.0f && dataset.scaleY != 0.0f && dataset.scaleZ != 0.0f)
|
||||
{
|
||||
float maxScale = Mathf.Max(dataset.scaleX, dataset.scaleY, dataset.scaleZ);
|
||||
volObj.transform.localScale = new Vector3(dataset.scaleX / maxScale, dataset.scaleY / maxScale, dataset.scaleZ / maxScale);
|
||||
}
|
||||
|
||||
return volObj;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,13 +29,14 @@ namespace UnityVolumeRendering
|
|||
sliceRenderingPlane.transform.parent = transform;
|
||||
sliceRenderingPlane.transform.localPosition = Vector3.zero;
|
||||
sliceRenderingPlane.transform.localRotation = Quaternion.identity;
|
||||
sliceRenderingPlane.transform.localScale = Vector3.one * 0.1f; // TODO: Change the plane mesh instead and use Vector3.one
|
||||
MeshRenderer sliceMeshRend = sliceRenderingPlane.GetComponent<MeshRenderer>();
|
||||
sliceMeshRend.material = new Material(sliceMeshRend.sharedMaterial);
|
||||
Material sliceMat = sliceRenderingPlane.GetComponent<MeshRenderer>().sharedMaterial;
|
||||
sliceMat.SetTexture("_DataTex", dataset.GetDataTexture());
|
||||
sliceMat.SetTexture("_TFTex", transferFunction.GetTexture());
|
||||
sliceMat.SetMatrix("_parentInverseMat", transform.worldToLocalMatrix);
|
||||
sliceMat.SetMatrix("_planeMat", Matrix4x4.TRS(sliceRenderingPlane.transform.position, sliceRenderingPlane.transform.rotation, Vector3.one)); // TODO: allow changing scale
|
||||
sliceMat.SetMatrix("_planeMat", Matrix4x4.TRS(sliceRenderingPlane.transform.position, sliceRenderingPlane.transform.rotation, transform.lossyScale)); // TODO: allow changing scale
|
||||
|
||||
return sliceRenderingPlane.GetComponent<SlicingPlane>();
|
||||
}
|
||||
|
|
|
@ -36,16 +36,18 @@ Shader "VolumeRendering/SliceRenderingShader"
|
|||
|
||||
sampler3D _DataTex;
|
||||
sampler2D _TFTex;
|
||||
// Parent's inverse transform (used to convert from world space to volume space)
|
||||
uniform float4x4 _parentInverseMat;
|
||||
// Plane transform
|
||||
uniform float4x4 _planeMat;
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
float3 vert = float3(-v.uv.x, 0.0f, -v.uv.y) + float3(0.5f, 0.0f, 0.5f);
|
||||
vert = mul(_planeMat, float4(vert, 1.0f));
|
||||
//o.vertex = mul(UNITY_MATRIX_VP, float4(vert, 1.0f));
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
// Calculate plane vertex world position.
|
||||
float3 vert = mul(_planeMat, float4(0.5f -v.uv.x, 0.0f, 0.5f -v.uv.y, 1.0f));
|
||||
// Convert from world space to volume space.
|
||||
o.relVert = mul(_parentInverseMat, float4(vert, 1.0f));
|
||||
o.uv = v.uv;
|
||||
return o;
|
||||
|
@ -53,12 +55,21 @@ Shader "VolumeRendering/SliceRenderingShader"
|
|||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
float3 dataCoord = i.relVert +float3(0.5f, 0.5f, 0.5f);
|
||||
float dataVal = tex3D(_DataTex, dataCoord);
|
||||
float4 col = tex2D(_TFTex, float2(dataVal, 0.0f));
|
||||
col.a = 1.0f;
|
||||
|
||||
return col;
|
||||
float3 dataCoord = i.relVert + float3(0.5f, 0.5f, 0.5f);
|
||||
// If the current fragment is outside the volume, simply colour it black.
|
||||
// Note: Unity does not seem to have support for clamping texture coordinates to a border value, so we have to do this manually
|
||||
if (dataCoord.x > 1.0f || dataCoord.y > 1.0f || dataCoord.z > 1.0f || dataCoord.x < 0.0f || dataCoord.y < 0.0f || dataCoord.z < 0.0f)
|
||||
{
|
||||
return float4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Sample the volume texture.
|
||||
float dataVal = tex3D(_DataTex, dataCoord);
|
||||
float4 col = tex2D(_TFTex, float2(dataVal, 0.0f));
|
||||
col.a = 1.0f;
|
||||
return col;
|
||||
}
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче