void ClearUI() { FrameSelector.Minimum = 0; FrameSelector.Maximum = 0; FrameSelector.IsEnabled = false; FrameSelector.Value = 0; FrameCount.Text = ""; ProbeInfo.Text = ""; InstanceUID.Text = ""; ImageXY.Source = null; ImageXZ.Source = null; ImageZY.Source = null; m_bboxXY = new Cart3dGeom(); m_bboxXZ = new Cart3dGeom(); m_bboxZY = new Cart3dGeom(); ECG.Data = null; if (m_source != null) { Marshal.ReleaseComObject(m_source); m_source = null; } }
/** Scale bounding-box, so that all axes share the same length. * Also update the origin to keep the bounding-box centered. */ static void ExtendBoundingBox(ref Cart3dGeom g) { float dir1_len = VecLen(g, 1); float dir2_len = VecLen(g, 2); float dir3_len = VecLen(g, 3); float max_len = Math.Max(dir1_len, Math.Max(dir2_len, dir3_len)); if (dir1_len < max_len) { float delta = max_len - dir1_len; float dx, dy, dz; ScaleVector(g.dir1_x, g.dir1_y, g.dir1_z, delta, out dx, out dy, out dz); // scale up dir1 so that it becomes the same length as the other axes g.dir1_x += dx; g.dir1_y += dy; g.dir1_z += dz; // move origin to keep the bounding-box centered g.origin_x -= dx / 2; g.origin_y -= dy / 2; g.origin_z -= dz / 2; } if (dir2_len < max_len) { float delta = max_len - dir2_len; float dx, dy, dz; ScaleVector(g.dir2_x, g.dir2_y, g.dir2_z, delta, out dx, out dy, out dz); // scale up dir2 so that it becomes the same length as the other axes g.dir2_x += dx; g.dir2_y += dy; g.dir2_z += dz; // move origin to keep the bounding-box centered g.origin_x -= dx / 2; g.origin_y -= dy / 2; g.origin_z -= dz / 2; } if (dir3_len < max_len) { float delta = max_len - dir3_len; float dx, dy, dz; ScaleVector(g.dir3_x, g.dir3_y, g.dir3_z, delta, out dx, out dy, out dz); // scale up dir3 so that it becomes the same length as the other axes float factor = max_len / dir3_len; g.dir3_x += dx; g.dir3_y += dy; g.dir3_z += dz; // move origin to keep the bounding-box centered g.origin_x -= dx / 2; g.origin_y -= dy / 2; g.origin_z -= dz / 2; } }
private void InitializeSlices() { Debug.Assert(m_source != null); Cart3dGeom bbox = m_source.GetBoundingBox(); if (Math.Abs(bbox.dir3_y) > Math.Abs(bbox.dir2_y)) { // swap 2nd & 3rd axis, so that the 2nd becomes predominately "Y" SwapVals(ref bbox.dir2_x, ref bbox.dir3_x); SwapVals(ref bbox.dir2_y, ref bbox.dir3_y); SwapVals(ref bbox.dir2_z, ref bbox.dir3_z); } // extend bounding-box axes, so that dir1, dir2 & dir3 have equal length ExtendBoundingBox(ref bbox); // get XY plane (assumes 1st axis is "X" and 2nd is "Y") m_bboxXY = bbox; m_bboxXY.origin_x = m_bboxXY.origin_x + m_bboxXY.dir3_x / 2; m_bboxXY.origin_y = m_bboxXY.origin_y + m_bboxXY.dir3_y / 2; m_bboxXY.origin_z = m_bboxXY.origin_z + m_bboxXY.dir3_z / 2; m_bboxXY.dir3_x = 0; m_bboxXY.dir3_y = 0; m_bboxXY.dir3_z = 0; // get XZ plane (assumes 1st axis is "X" and 3rd is "Z") m_bboxXZ = bbox; m_bboxXZ.origin_x = m_bboxXZ.origin_x + m_bboxXZ.dir2_x / 2; m_bboxXZ.origin_y = m_bboxXZ.origin_y + m_bboxXZ.dir2_y / 2; m_bboxXZ.origin_z = m_bboxXZ.origin_z + m_bboxXZ.dir2_z / 2; m_bboxXZ.dir2_x = m_bboxXZ.dir3_x; m_bboxXZ.dir2_y = m_bboxXZ.dir3_y; m_bboxXZ.dir2_z = m_bboxXZ.dir3_z; m_bboxXZ.dir3_x = 0; m_bboxXZ.dir3_y = 0; m_bboxXZ.dir3_z = 0; // get ZY plane (assumes 2nd axis is "Y" and 3rd is "Z") m_bboxZY = bbox; m_bboxZY.origin_x = bbox.origin_x + bbox.dir1_x / 2; m_bboxZY.origin_y = bbox.origin_y + bbox.dir1_y / 2; m_bboxZY.origin_z = bbox.origin_z + bbox.dir1_z / 2; m_bboxZY.dir1_x = bbox.dir3_x; m_bboxZY.dir1_y = bbox.dir3_y; m_bboxZY.dir1_z = bbox.dir3_z; m_bboxZY.dir2_x = bbox.dir2_x; m_bboxZY.dir2_y = bbox.dir2_y; m_bboxZY.dir2_z = bbox.dir2_z; m_bboxZY.dir3_x = 0; m_bboxZY.dir3_y = 0; m_bboxZY.dir3_z = 0; }
static float VecLen(Cart3dGeom g, int idx) { if (idx == 1) { return(VecLen(g.dir1_x, g.dir1_y, g.dir1_z)); } else if (idx == 2) { return(VecLen(g.dir2_x, g.dir2_y, g.dir2_z)); } else if (idx == 3) { return(VecLen(g.dir3_x, g.dir3_y, g.dir3_z)); } throw new Exception("unsupported direction index"); }
private void DrawImages(uint frame) { Debug.Assert(m_source != null); // retrieve image volume ushort[] max_res = new ushort[] { 128, 128, 128 }; Cart3dGeom bbox = m_source.GetBoundingBox(); if (Math.Abs(bbox.dir3_y) > Math.Abs(bbox.dir2_y)) { // swap 2nd & 3rd axis, so that the 2nd becomes predominately "Y" SwapVals(ref bbox.dir2_x, ref bbox.dir3_x); SwapVals(ref bbox.dir2_y, ref bbox.dir3_y); SwapVals(ref bbox.dir2_z, ref bbox.dir3_z); } // get XY plane (assumes 1st axis is "X" and 2nd is "Y") Cart3dGeom bboxXY = bbox; ushort[] max_resXY = new ushort[] { max_res[0], max_res[1], 1 }; bboxXY.origin_x = bboxXY.origin_x + bboxXY.dir3_x / 2; bboxXY.origin_y = bboxXY.origin_y + bboxXY.dir3_y / 2; bboxXY.origin_z = bboxXY.origin_z + bboxXY.dir3_z / 2; bboxXY.dir3_x = 0; bboxXY.dir3_y = 0; bboxXY.dir3_z = 0; Image3d imageXY = m_source.GetFrame(frame, bboxXY, max_resXY); // get XZ plane (assumes 1st axis is "X" and 3rd is "Z") Cart3dGeom bboxXZ = bbox; ushort[] max_resXZ = new ushort[] { max_res[0], max_res[2], 1 }; bboxXZ.origin_x = bboxXZ.origin_x + bboxXZ.dir2_x / 2; bboxXZ.origin_y = bboxXZ.origin_y + bboxXZ.dir2_y / 2; bboxXZ.origin_z = bboxXZ.origin_z + bboxXZ.dir2_z / 2; bboxXZ.dir2_x = bboxXZ.dir3_x; bboxXZ.dir2_y = bboxXZ.dir3_y; bboxXZ.dir2_z = bboxXZ.dir3_z; bboxXZ.dir3_x = 0; bboxXZ.dir3_y = 0; bboxXZ.dir3_z = 0; Image3d imageXZ = m_source.GetFrame(frame, bboxXZ, max_resXZ); // get YZ plane (assumes 2nd axis is "Y" and 3rd is "Z") Cart3dGeom bboxYZ = bbox; ushort[] max_resYZ = new ushort[] { max_res[1], max_res[2], 1 }; bboxYZ.origin_x = bboxYZ.origin_x + bboxYZ.dir1_x / 2; bboxYZ.origin_y = bboxYZ.origin_y + bboxYZ.dir1_y / 2; bboxYZ.origin_z = bboxYZ.origin_z + bboxYZ.dir1_z / 2; bboxYZ.dir1_x = bboxYZ.dir2_x; bboxYZ.dir1_y = bboxYZ.dir2_y; bboxYZ.dir1_z = bboxYZ.dir2_z; bboxYZ.dir2_x = bboxYZ.dir3_x; bboxYZ.dir2_y = bboxYZ.dir3_y; bboxYZ.dir2_z = bboxYZ.dir3_z; bboxYZ.dir3_x = 0; bboxYZ.dir3_y = 0; bboxYZ.dir3_z = 0; Image3d imageYZ = m_source.GetFrame(frame, bboxYZ, max_resYZ); FrameTime.Text = "Frame time: " + imageXY.time; uint[] color_map = m_source.GetColorMap(); ImageXY.Source = GenerateBitmap(imageXY, color_map); ImageXZ.Source = GenerateBitmap(imageXZ, color_map); ImageYZ.Source = GenerateBitmap(imageYZ, color_map); }
private void DrawImages(uint frame) { Debug.Assert(m_source != null); // retrieve image slices const ushort HORIZONTAL_RES = 256; const ushort VERTICAL_RES = 256; Cart3dGeom bbox = m_source.GetBoundingBox(); if (Math.Abs(bbox.dir3_y) > Math.Abs(bbox.dir2_y)) { // swap 2nd & 3rd axis, so that the 2nd becomes predominately "Y" SwapVals(ref bbox.dir2_x, ref bbox.dir3_x); SwapVals(ref bbox.dir2_y, ref bbox.dir3_y); SwapVals(ref bbox.dir2_z, ref bbox.dir3_z); } // extend bounding-box axes, so that dir1, dir2 & dir3 have equal length ExtendBoundingBox(ref bbox); // get XY plane (assumes 1st axis is "X" and 2nd is "Y") Cart3dGeom bboxXY = bbox; bboxXY.origin_x = bboxXY.origin_x + bboxXY.dir3_x / 2; bboxXY.origin_y = bboxXY.origin_y + bboxXY.dir3_y / 2; bboxXY.origin_z = bboxXY.origin_z + bboxXY.dir3_z / 2; bboxXY.dir3_x = 0; bboxXY.dir3_y = 0; bboxXY.dir3_z = 0; Image3d imageXY = m_source.GetFrame(frame, bboxXY, new ushort[] { HORIZONTAL_RES, VERTICAL_RES, 1 }); // get XZ plane (assumes 1st axis is "X" and 3rd is "Z") Cart3dGeom bboxXZ = bbox; bboxXZ.origin_x = bboxXZ.origin_x + bboxXZ.dir2_x / 2; bboxXZ.origin_y = bboxXZ.origin_y + bboxXZ.dir2_y / 2; bboxXZ.origin_z = bboxXZ.origin_z + bboxXZ.dir2_z / 2; bboxXZ.dir2_x = bboxXZ.dir3_x; bboxXZ.dir2_y = bboxXZ.dir3_y; bboxXZ.dir2_z = bboxXZ.dir3_z; bboxXZ.dir3_x = 0; bboxXZ.dir3_y = 0; bboxXZ.dir3_z = 0; Image3d imageXZ = m_source.GetFrame(frame, bboxXZ, new ushort[] { HORIZONTAL_RES, VERTICAL_RES, 1 }); // get ZY plane (assumes 2nd axis is "Y" and 3rd is "Z") Cart3dGeom bboxZY = bbox; bboxZY.origin_x = bbox.origin_x + bbox.dir1_x / 2; bboxZY.origin_y = bbox.origin_y + bbox.dir1_y / 2; bboxZY.origin_z = bbox.origin_z + bbox.dir1_z / 2; bboxZY.dir1_x = bbox.dir3_x; bboxZY.dir1_y = bbox.dir3_y; bboxZY.dir1_z = bbox.dir3_z; bboxZY.dir2_x = bbox.dir2_x; bboxZY.dir2_y = bbox.dir2_y; bboxZY.dir2_z = bbox.dir2_z; bboxZY.dir3_x = 0; bboxZY.dir3_y = 0; bboxZY.dir3_z = 0; Image3d imageZY = m_source.GetFrame(frame, bboxZY, new ushort[] { HORIZONTAL_RES, VERTICAL_RES, 1 }); FrameTime.Text = "Frame time: " + imageXY.time; uint[] color_map = m_source.GetColorMap(); ImageXY.Source = GenerateBitmap(imageXY, color_map); ImageXZ.Source = GenerateBitmap(imageXZ, color_map); ImageZY.Source = GenerateBitmap(imageZY, color_map); }