예제 #1
0
 void assertEqual(mitk::pa::Volume::Pointer first, mitk::pa::Volume::Pointer second)
 {
   CPPUNIT_ASSERT(first->GetXDim() == second->GetXDim());
   CPPUNIT_ASSERT(first->GetYDim() == second->GetYDim());
   CPPUNIT_ASSERT(first->GetZDim() == second->GetZDim());
   for (unsigned int x = 0; x < first->GetXDim(); ++x)
     for (unsigned int y = 0; y < first->GetYDim(); ++y)
       for (unsigned int z = 0; z < first->GetZDim(); ++z)
       {
         std::string message = "Expected " + std::to_string(first->GetData(x, y, z)) + " but was " + std::to_string(second->GetData(x, y, z));
         CPPUNIT_ASSERT_MESSAGE(message, abs(first->GetData(x, y, z) - second->GetData(x, y, z)) < 1e-6);
       }
 }
예제 #2
0
 void FillYSliceWith(mitk::pa::Volume::Pointer fluenceVolume, double ySlice, double value)
 {
   for (unsigned int x = 0; x < fluenceVolume->GetXDim(); ++x)
     for (unsigned int z = 0; z < fluenceVolume->GetZDim(); ++z)
     {
       fluenceVolume->SetData(value, x, ySlice, z);
     }
 }
예제 #3
0
 void AssertYSliceValue(mitk::pa::Volume::Pointer fluenceVolume, double ySlice, double value)
 {
   for (unsigned int x = 0; x < fluenceVolume->GetXDim(); ++x)
     for (unsigned int z = 0; z < fluenceVolume->GetZDim(); ++z)
     {
       std::string msg = "Expected: " + std::to_string(value) + " actual: " + std::to_string(fluenceVolume->GetData(x, ySlice, z));
       CPPUNIT_ASSERT_MESSAGE(msg, std::abs(fluenceVolume->GetData(x, ySlice, z) - value) < mitk::eps);
     }
 }
예제 #4
0
/**
* @brief Fast 3D Gaussian convolution IIR approximation
* @param paVolume
* @param sigma
* @author Pascal Getreuer <*****@*****.**>
*
* Copyright (c) 2011, Pascal Getreuer
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the simplified BSD license.
*
* You should have received a copy of these licenses along with this program.
* If not, see <http://www.opensource.org/licenses/bsd-license.html>.
*/
void mitk::pa::VolumeManipulator::GaussianBlur3D(mitk::pa::Volume::Pointer paVolume, double sigma)
{
  double* volume = paVolume->GetData();
  long width = paVolume->GetYDim();
  long height = paVolume->GetXDim();
  long depth = paVolume->GetZDim();
  const long plane = width*height;
  const long numel = plane*depth;
  double lambda, dnu;
  double nu, boundaryscale, postscale;
  double *ptr;
  long i, x, y, z;
  int step;

  if (sigma <= 0)
    return;

  lambda = (sigma*sigma) / (8.0);
  dnu = (1.0 + 2.0*lambda - sqrt(1.0 + 4.0*lambda)) / (2.0*lambda);
  nu = dnu;
  boundaryscale = 1.0 / (1.0 - dnu);
  postscale = pow(dnu / lambda, 12);

  /* Filter horizontally along each row */
  for (z = 0; z < depth; z++)
  {
    for (y = 0; y < height; y++)
    {
      for (step = 0; step < 4; step++)
      {
        ptr = volume + width*(y + height*z);
        ptr[0] *= boundaryscale;

        /* Filter rightwards */
        for (x = 1; x < width; x++)
        {
          ptr[x] += nu*ptr[x - 1];
        }

        ptr[x = width - 1] *= boundaryscale;
        /* Filter leftwards */
        for (; x > 0; x--)
        {
          ptr[x - 1] += nu*ptr[x];
        }
      }
    }
  }
  /* Filter vertically along each column */
  for (z = 0; z < depth; z++)
  {
    for (x = 0; x < width; x++)
    {
      for (step = 0; step < 4; step++)
      {
        ptr = volume + x + plane*z;
        ptr[0] *= boundaryscale;

        /* Filter downwards */
        for (i = width; i < plane; i += width)
        {
          ptr[i] += nu*ptr[i - width];
        }

        ptr[i = plane - width] *= boundaryscale;

        /* Filter upwards */
        for (; i > 0; i -= width)
        {
          ptr[i - width] += nu*ptr[i];
        }
      }
    }
  }

  /* Filter along z-dimension */
  for (y = 0; y < height; y++)
  {
    for (x = 0; x < width; x++)
    {
      for (step = 0; step < 4; step++)
      {
        ptr = volume + x + width*y;
        ptr[0] *= boundaryscale;

        for (i = plane; i < numel; i += plane)
        {
          ptr[i] += nu*ptr[i - plane];
        }

        ptr[i = numel - plane] *= boundaryscale;

        for (; i > 0; i -= plane)
        {
          ptr[i - plane] += nu*ptr[i];
        }
      }
    }
  }

  for (i = 0; i < numel; i++)
  {
    volume[i] *= postscale;
  }
}