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);
     }
 }
 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);
     }
 }
  void setUp()
  {
    m_VolumeProperties = createTestVolumeParameters();
    m_TestInSilicoVolume = mitk::pa::InSilicoTissueVolume::New(m_VolumeProperties);
    m_Test3DVolume = createTest3DVolume(5);
    itk::FileTools::CreateDirectory(TEST_FOLDER_PATH);
    itk::FileTools::CreateDirectory(TEST_QUALIFIED_FOLDER_PATH);
    itk::FileTools::CreateDirectory(TEST_FOLDER_PATH + FOLDER_FOLDER + FOLDER_FOLDER);
    itk::FileTools::CreateDirectory(FCM_PATH);
    CPPUNIT_ASSERT(itksys::SystemTools::FileIsDirectory(TEST_FOLDER_PATH));
    CPPUNIT_ASSERT(itksys::SystemTools::FileIsDirectory(TEST_QUALIFIED_FOLDER_PATH));
    CPPUNIT_ASSERT(itksys::SystemTools::FileIsDirectory(TEST_FOLDER_PATH + FOLDER_FOLDER + FOLDER_FOLDER));
    CPPUNIT_ASSERT(itksys::SystemTools::FileIsDirectory(FCM_PATH));

    mitk::IOUtil::Save(m_TestInSilicoVolume->ConvertToMitkImage(),
      TEST_FOLDER_PATH + TEST_IN_SILICO_VOLUME_PATH + TEST_FILE_ENDING);
    mitk::IOUtil::Save(m_Test3DVolume->AsMitkImage(),
      TEST_FOLDER_PATH + TEST_3D_Volume_PATH + TEST_FILE_ENDING);
    auto yo0 = createTest3DVolume(1)->AsMitkImage();
    auto yo1 = createTest3DVolume(2)->AsMitkImage();

    yo0->GetPropertyList()->SetStringProperty("y-offset", "0");
    yo1->GetPropertyList()->SetStringProperty("y-offset", "1");
    mitk::CoreServices::GetPropertyPersistence()->AddInfo(mitk::PropertyPersistenceInfo::New("y-offset"));

    mitk::IOUtil::Save(yo0, TEST_QUALIFIED_FOLDER_PATH + TEST_IN_SILICO_VOLUME_PATH + "_yo0" + TEST_FILE_ENDING);
    mitk::IOUtil::Save(yo1, TEST_QUALIFIED_FOLDER_PATH + TEST_IN_SILICO_VOLUME_PATH + "_yo1" + TEST_FILE_ENDING);
  }
  void testNoiseGenerator()
  {
    int size = 1000 * 100 * 100;
    auto* volume = new double[size];
    for (int i = 0; i < size; i++)
    {
      volume[i] = 1;
    }
    m_Volume = mitk::pa::Volume::New(volume, 1000, 100, 100, 1);
    mitk::pa::NoiseGenerator::ApplyNoiseModel(m_Volume, 0.75, 0.1);

    int negativecounter = 0;

    for (int i = 0; i < size; i++)
    {
      if (m_Volume->GetData()[i] <= 0)
      {
        negativecounter++;
      }
    }
    CPPUNIT_ASSERT_EQUAL_MESSAGE("More than one negative: " +
      std::to_string(negativecounter) + " (" +
      std::to_string((((double)negativecounter) / size) * 100) + "%)", negativecounter, 0);
  }
示例#5
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;
  }
}
 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);
       }
 }