Skip to content

Commit

Permalink
Merge pull request #1 from BirgitPfarrkirchner/Extract_Slices
Browse files Browse the repository at this point in the history
Get three planes instead of the whole volume block
  • Loading branch information
BirgitPfarrkirchner authored Feb 22, 2018
2 parents 19676b4 + 49eab87 commit 69616cf
Showing 1 changed file with 51 additions and 14 deletions.
65 changes: 51 additions & 14 deletions TestViewer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,65 @@ private void DrawImages (uint frame)
Debug.Assert(m_source != null);

// retrieve image volume
Cart3dGeom bbox = m_source.GetBoundingBox();
ushort[] max_res = new ushort[]{ 128, 128, 128 };
Image3d image = m_source.GetFrame(frame, bbox, max_res);

FrameTime.Text = "Frame time: " + image.time;
ushort[] max_res = new ushort[] { 200, 300, 250 };

// get XY plane
Cart3dGeom bboxXY = m_source.GetBoundingBox();
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
Cart3dGeom bboxXZ = m_source.GetBoundingBox();
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
Cart3dGeom bboxYZ = m_source.GetBoundingBox();
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();

{
// extract center-Z slize (top-left)
WriteableBitmap bitmap = new WriteableBitmap(image.dims[0], image.dims[1], 96.0, 96.0, PixelFormats.Rgb24, null);
WriteableBitmap bitmap = new WriteableBitmap(imageXY.dims[0], imageXY.dims[1], 96.0, 96.0, PixelFormats.Rgb24, null);
bitmap.Lock();
unsafe
{
int z = image.dims[2] / 2;
for (int y = 0; y < bitmap.Height; ++y)
{
for (int x = 0; x < bitmap.Width; ++x)
{
byte val = image.data[x + y * image.stride0 + z * image.stride1];
byte val = imageXY.data[x + y * imageXY.stride0];
byte* pixel = (byte*)bitmap.BackBuffer + x * (bitmap.Format.BitsPerPixel / 8) + y * bitmap.BackBufferStride;
SetRGBVal(pixel, color_map[val]);
}
Expand All @@ -107,16 +146,15 @@ private void DrawImages (uint frame)
}
{
// extract center-Y slize (top-right)
WriteableBitmap bitmap = new WriteableBitmap(image.dims[0], image.dims[2], 96.0, 96.0, PixelFormats.Rgb24, null);
WriteableBitmap bitmap = new WriteableBitmap(imageXZ.dims[0], imageXZ.dims[1], 96.0, 96.0, PixelFormats.Rgb24, null);
bitmap.Lock();
unsafe
{
int y = image.dims[1] / 2;
for (int z = 0; z < bitmap.Height; ++z)
{
for (int x = 0; x < bitmap.Width; ++x)
{
byte val = image.data[x + y * image.stride0 + z * image.stride1];
byte val = imageXZ.data[x + z * imageXZ.stride0];
byte* pixel = (byte*)bitmap.BackBuffer + x * (bitmap.Format.BitsPerPixel / 8) + z * bitmap.BackBufferStride;
SetRGBVal(pixel, color_map[val]);
}
Expand All @@ -129,15 +167,14 @@ private void DrawImages (uint frame)
}
{
// extract center-X slize (bottom-left)
WriteableBitmap bitmap = new WriteableBitmap(image.dims[2], image.dims[1], 96.0, 96.0, PixelFormats.Rgb24, null);
WriteableBitmap bitmap = new WriteableBitmap(imageYZ.dims[0], imageYZ.dims[1], 96.0, 96.0, PixelFormats.Rgb24, null);
bitmap.Lock();
unsafe {
int x = image.dims[0] / 2;
for (int z = 0; z < bitmap.Height; ++z)
{
for (int y = 0; y < bitmap.Width; ++y)
{
byte val = image.data[x + y * image.stride0 + z * image.stride1];
byte val = imageYZ.data[y + z * imageYZ.stride0];
byte* pixel = (byte*)bitmap.BackBuffer + y * (bitmap.Format.BitsPerPixel / 8) + z * bitmap.BackBufferStride;
SetRGBVal(pixel, color_map[val]);
}
Expand Down

0 comments on commit 69616cf

Please sign in to comment.