コード例 #1
0
ファイル: exr.cpp プロジェクト: nathanbeddes/pbrt-v3
TEST(EXR, BasicRoundTrip) {
   int width = 289;
   int height = 1 + 65536 / width;

   float *buf = new float[width * height];
   for (int i = 0; i < 65536; ++i) {
     FP16 half;
     half.u = i;
     buf[i] = half_to_float_full(half).f;
   }
   for (int i = 65536; i < width * height; ++i)
     buf[i] = 0;

   EXRImage image;
   image.num_channels = 1;
   const char *channels[] = { "R" };
   image.channel_names = channels;
   unsigned char *images[] = { (unsigned char *)buf };
   image.images = images;
   int pixel_types[] = { TINYEXR_PIXELTYPE_HALF };
   image.pixel_types = pixel_types;
   image.width = width;
   image.height = height;

   const char *err = nullptr;
   EXPECT_EQ(0, SaveMultiChannelEXRToFile(&image, "test.exr", &err)) << err;

   EXRImage readImage;
   EXPECT_EQ(0, LoadMultiChannelEXRFromFile(&readImage, "test.exr", &err))
       << err;

   CompareImages(image, readImage, false);
}
コード例 #2
0
ファイル: mitkFiberFitTest.cpp プロジェクト: m4271n/MITK
  void Fit6()
  {
    omp_set_num_threads(1);
    fitter->SetLambda(10);
    fitter->SetFilterOutliers(false);
    fitter->SetRegularization(VnlCostFunction::GROUP_LASSO);
    fitter->Update();

    std::vector< mitk::FiberBundle::Pointer > output_tracts = fitter->GetTractograms();
    mitk::FiberBundle::Pointer test = mitk::FiberBundle::New();
    test = test->AddBundles(output_tracts);
    mitk::FiberBundle::Pointer ref = LoadFib("out/GroupLasso_fitted.fib");
    CompareFibs(test, ref, "GroupLasso_fitted.fib");
    CompareImages(fitter->GetFittedImage(), "GroupLasso_fitted_image.nrrd");
    CompareImages(fitter->GetResidualImage(), "GroupLasso_residual_image.nrrd");
  }
コード例 #3
0
ファイル: mitkFiberFitTest.cpp プロジェクト: m4271n/MITK
  void Fit4()
  {
    omp_set_num_threads(1);
    fitter->SetLambda(0.1);
    fitter->SetFilterOutliers(false);
    fitter->SetRegularization(VnlCostFunction::VOXEL_VARIANCE);
    fitter->Update();

    std::vector< mitk::FiberBundle::Pointer > output_tracts = fitter->GetTractograms();
    mitk::FiberBundle::Pointer test = mitk::FiberBundle::New();
    test = test->AddBundles(output_tracts);
    mitk::FiberBundle::Pointer ref = LoadFib("out/LocalMSE_fitted.fib");
    CompareFibs(test, ref, "LocalMSE_fitted.fib");
    CompareImages(fitter->GetFittedImage(), "LocalMSE_fitted_image.nrrd");
    CompareImages(fitter->GetResidualImage(), "LocalMSE_residual_image.nrrd");
  }
コード例 #4
0
ファイル: exr.cpp プロジェクト: nathanbeddes/pbrt-v3
TEST(EXR, Randoms) {
   int width = 1024;
   int height = 1024;

   RNG rng;
   float *buf = new float[4 * width * height];
   for (int i = 0; i < 4 * width * height; ++i) {
     buf[i] = -20 + 20. * rng.UniformFloat();
   }

   EXRImage image;
   image.num_channels = 4;
   const char *channels[] = { "B", "G", "R", "A" };
   image.channel_names = channels;
   unsigned char *images[] = { (unsigned char *)buf,
                               (unsigned char *)(buf + width * height),
                               (unsigned char *)(buf + 2 * width * height),
                               (unsigned char *)(buf + 3 * width * height) };
   image.images = images;
   int pixel_types[] = { TINYEXR_PIXELTYPE_HALF, TINYEXR_PIXELTYPE_HALF,
                         TINYEXR_PIXELTYPE_HALF, TINYEXR_PIXELTYPE_HALF };
   image.pixel_types = pixel_types;
   image.width = width;
   image.height = height;

   const char *err = nullptr;
   EXPECT_EQ(0, SaveMultiChannelEXRToFile(&image, "test.exr", &err)) << err;

   EXRImage readImage;
   EXPECT_EQ(0, LoadMultiChannelEXRFromFile(&readImage, "test.exr", &err))
       << err;

   CompareImages(image, readImage, true);
}
コード例 #5
0
//----------------------------------------------------------------------------
void vtkXRayVolumeMapperTest::TestExposureCorrection()
//----------------------------------------------------------------------------
{
	///////////////// render stuff /////////////////////////

	m_Renderer->SetBackground(0.1, 0.1, 0.1);
	m_RenderWindow->AddRenderer(m_Renderer);
	m_RenderWindow->SetSize(320, 240);
	m_RenderWindow->SetPosition(400,0);

	m_RenderWindowInteractor->SetRenderWindow(m_RenderWindow);

	///////////// end render stuff /////////////////////////


	////// import vtkData ////////////////////
	vtkDataSetReader *Importer;
	vtkNEW(Importer);
	mafString filename=MED_DATA_ROOT;
	filename<<"/VTK_Volumes/volume.vtk";
	Importer->SetFileName(filename);
	Importer->Update();

	vtkVolumeProperty *volumeProperty = NULL;
	vtkNEW(volumeProperty);  
	//volumeProperty->SetColor(m_ColorTransferFunction);
	volumeProperty->SetInterpolationTypeToLinear();


	vtkXRayVolumeMapper *volumeMapper;
	vtkNEW(volumeMapper);
	volumeMapper->SetInput(vtkImageData::SafeDownCast(Importer->GetOutput()));
	double *val = new double[2];
	val[0] = 0.1;
	val[1] = 0.4;
	volumeMapper->SetExposureCorrection(val);

	CPPUNIT_ASSERT(volumeMapper->GetExposureCorrection()[0] == val[0] && volumeMapper->GetExposureCorrection()[1] == val[1]);
  
	volumeMapper->SetCroppingRegionPlanes(0, 1, 0, 1, 0, 1);
	volumeMapper->Update();	

	vtkVolume *volume;
	vtkNEW(volume);
	volume->SetMapper(volumeMapper);
	volume->SetProperty(volumeProperty);
	volume->PickableOff();

	m_Renderer->AddVolume(volume);
	m_RenderWindow->Render();
	CompareImages(ID_TEST_EXPOSURE_CORRECTION);

	vtkDEL(volumeProperty);
	vtkDEL(volume);
	vtkDEL(volumeMapper);
	vtkDEL(Importer);
  delete val;
	delete wxLog::SetActiveTarget(NULL);
}
コード例 #6
0
/**Documentation
 *  test for the class "ToFOpenCVImageGrabber".
 */
int mitkToFOpenCVImageGrabberTest(int /* argc */, char* /*argv*/[])
{
  MITK_TEST_BEGIN("ToFOpenCVImageGrabber");

  std::string dirName = MITK_TOF_DATA_DIR;
  mitk::ToFImageGrabber::Pointer tofImageGrabber = mitk::ToFImageGrabber::New();
  tofImageGrabber->SetCameraDevice(mitk::ToFCameraMITKPlayerDevice::New());
  std::string distanceFileName = dirName + "/PMDCamCube2_MF0_IT0_1Images_DistanceImage.pic";
  tofImageGrabber->SetProperty("DistanceImageFileName",mitk::StringProperty::New(distanceFileName));
  std::string amplitudeFileName = dirName + "/PMDCamCube2_MF0_IT0_1Images_AmplitudeImage.pic";
  tofImageGrabber->SetProperty("AmplitudeImageFileName",mitk::StringProperty::New(amplitudeFileName));
  std::string intensityFileName = dirName + "/PMDCamCube2_MF0_IT0_1Images_IntensityImage.pic";
  tofImageGrabber->SetProperty("IntensityImageFileName",mitk::StringProperty::New(intensityFileName));
  tofImageGrabber->Update();

  mitk::Image::Pointer image = dynamic_cast<mitk::Image*>(mitk::IOUtil::Load(distanceFileName)[0].GetPointer());

  try
  {
    mitk::ToFOpenCVImageGrabber::Pointer tofOpenCVImageGrabber = mitk::ToFOpenCVImageGrabber::New();
    tofOpenCVImageGrabber->SetToFImageGrabber(tofImageGrabber);
    MITK_TEST_CONDITION_REQUIRED(tofImageGrabber==tofOpenCVImageGrabber->GetToFImageGrabber(),"Test Set/GetToFImageGrabber()");
    MITK_TEST_OUTPUT(<<"Call StartCapturing()");
    tofOpenCVImageGrabber->StartCapturing();
    cv::Mat cvImage = tofOpenCVImageGrabber->GetImage();
    MITK_TEST_CONDITION_REQUIRED(CompareImages(image,cvImage),"Test distance image");
    image = dynamic_cast<mitk::Image*>(mitk::IOUtil::Load(amplitudeFileName)[0].GetPointer());
    tofOpenCVImageGrabber->SetImageType(1);
    cvImage = tofOpenCVImageGrabber->GetImage();
    MITK_TEST_CONDITION_REQUIRED(CompareImages(image,cvImage),"Test amplitude image");
    image = dynamic_cast<mitk::Image*>(mitk::IOUtil::Load(intensityFileName)[0].GetPointer());
    tofOpenCVImageGrabber->SetImageType(2);
    cvImage = tofOpenCVImageGrabber->GetImage();
    MITK_TEST_CONDITION_REQUIRED(CompareImages(image,cvImage),"Test intensity image");
    MITK_TEST_OUTPUT(<<"Call StopCapturing()");
    tofOpenCVImageGrabber->StopCapturing();
  }
  catch(std::exception &e)
  {
    MITK_INFO << "Exception is: " << e.what();
  }

  MITK_TEST_END();

}
コード例 #7
0
//----------------------------------------------------------------------------
void vtkXRayVolumeMapperTest::TestEnableAutoLOD()
//----------------------------------------------------------------------------
{
	///////////////// render stuff /////////////////////////

	m_Renderer->SetBackground(0.1, 0.1, 0.1);
	m_RenderWindow->AddRenderer(m_Renderer);
	m_RenderWindow->SetSize(320, 240);
	m_RenderWindow->SetPosition(400,0);

	m_RenderWindowInteractor->SetRenderWindow(m_RenderWindow);

	///////////// end render stuff /////////////////////////


	////// import vtkData ////////////////////
	vtkDataSetReader *Importer;
	vtkNEW(Importer);
	mafString filename=MED_DATA_ROOT;
	filename<<"/VTK_Volumes/volume.vtk";
	Importer->SetFileName(filename);
	Importer->Update();

	vtkVolumeProperty *volumeProperty = NULL;
	vtkNEW(volumeProperty);  
	//volumeProperty->SetColor(m_ColorTransferFunction);
	volumeProperty->SetInterpolationTypeToLinear();


	vtkXRayVolumeMapper *volumeMapper;
	vtkNEW(volumeMapper);
	volumeMapper->SetInput(vtkImageData::SafeDownCast(Importer->GetOutput()));

	volumeMapper->EnableAutoLODOn();
	CPPUNIT_ASSERT(volumeMapper->GetEnableAutoLOD() == TRUE);

	volumeMapper->SetCroppingRegionPlanes(0, 1, 0, 1, 0, 1);
	volumeMapper->Update();	

	vtkVolume *volume;
	vtkNEW(volume);
	volume->SetMapper(volumeMapper);
	volume->SetProperty(volumeProperty);
	volume->PickableOff();

	m_Renderer->AddVolume(volume);
	m_RenderWindow->Render();
	CompareImages(ID_TEST_ENABLE_AUTOLOAD);

	vtkDEL(volumeProperty);
	vtkDEL(volume);
	vtkDEL(volumeMapper);
	vtkDEL(Importer);

	delete wxLog::SetActiveTarget(NULL);
}
コード例 #8
0
/**Documentation
 *  test for the class "ToFOpenCVImageGrabber".
 */
int mitkToFOpenCVImageGrabberTest(int /* argc */, char* /*argv*/[])
{
    MITK_TEST_BEGIN("ToFOpenCVImageGrabber");

    std::string dirName = MITK_TOF_DATA_DIR;
    mitk::ToFImageGrabber::Pointer tofImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetMITKPlayerImageGrabber();
    std::string distanceFileName = dirName + "/PMDCamCube2_MF0_IT0_1Images_DistanceImage.pic";
    tofImageGrabber->SetProperty("DistanceImageFileName",mitk::StringProperty::New(distanceFileName));
    std::string amplitudeFileName = dirName + "/PMDCamCube2_MF0_IT0_1Images_AmplitudeImage.pic";
    tofImageGrabber->SetProperty("AmplitudeImageFileName",mitk::StringProperty::New(amplitudeFileName));
    std::string intensityFileName = dirName + "/PMDCamCube2_MF0_IT0_1Images_IntensityImage.pic";
    tofImageGrabber->SetProperty("IntensityImageFileName",mitk::StringProperty::New(intensityFileName));

    mitk::PicFileReader::Pointer mitkFileReader = mitk::PicFileReader::New();
    mitkFileReader->SetFileName(distanceFileName);
    mitkFileReader->Update();
    mitk::Image::Pointer image = mitkFileReader->GetOutput();

    mitk::ToFOpenCVImageGrabber::Pointer tofOpenCVImageGrabber = mitk::ToFOpenCVImageGrabber::New();
    tofOpenCVImageGrabber->SetToFImageGrabber(tofImageGrabber);
    MITK_TEST_CONDITION_REQUIRED(tofImageGrabber==tofOpenCVImageGrabber->GetToFImageGrabber(),"Test Set/GetToFImageGrabber()");
    MITK_TEST_OUTPUT(<<"Call StartCapturing()");
    tofOpenCVImageGrabber->StartCapturing();
    cv::Mat cvImage = tofOpenCVImageGrabber->GetImage();
    MITK_TEST_CONDITION_REQUIRED(CompareImages(image,cvImage),"Test distance image");
    mitkFileReader->SetFileName(amplitudeFileName);
    mitkFileReader->Update();
    image = mitkFileReader->GetOutput();
    tofOpenCVImageGrabber->SetImageType(1);
    cvImage = tofOpenCVImageGrabber->GetImage();
    MITK_TEST_CONDITION_REQUIRED(CompareImages(image,cvImage),"Test amplitude image");
    mitkFileReader->SetFileName(intensityFileName);
    mitkFileReader->Update();
    image = mitkFileReader->GetOutput();
    tofOpenCVImageGrabber->SetImageType(2);
    cvImage = tofOpenCVImageGrabber->GetImage();
    MITK_TEST_CONDITION_REQUIRED(CompareImages(image,cvImage),"Test intensity image");
    MITK_TEST_OUTPUT(<<"Call StopCapturing()");
    tofOpenCVImageGrabber->StopCapturing();

    MITK_TEST_END();

}
コード例 #9
0
//----------------------------------------------------------------------------
void medOpMML3ParameterViewTest::TestRender()
//----------------------------------------------------------------------------
{
  medOpMML3ParameterView *view = new medOpMML3ParameterView(m_RenderWindow, m_Renderer);

  view->SetRangeX(10);
  view->SetRangeY(0,5,10);

  view->AddPoint(1,1);
  view->AddPoint(2,2);
  
  m_Renderer->ResetCamera();
  view->Render();
  CompareImages("TestRender");

  cppDEL(view);
}
コード例 #10
0
ファイル: gdtest.c プロジェクト: AlexandreBurel/pwiz-mzdb
int
main (int argc, char **argv)
{
#ifdef HAVE_LIBPNG
  gdImagePtr im, ref, im2, im3;
  FILE *in, *out;
  void *iptr;
  int sz;
  char of[256];
  int colRed, colBlu;
  gdSource imgsrc;
  gdSink imgsnk;
  int foreground;
  int i;
  if (argc != 2)
    {
      fprintf (stderr, "Usage: gdtest filename.png\n");
      exit (1);
    }
  in = fopen (argv[1], "rb");
  if (!in)
    {
      fprintf (stderr, "Input file does not exist!\n");
      exit (1);
    }
  im = gdImageCreateFromPng (in);

  rewind (in);
  ref = gdImageCreateFromPng (in);

  fclose (in);

  printf ("Reference File has %d Palette entries\n", ref->colorsTotal);

  CompareImages ("Initial Versions", ref, im);


  /* */
  /* Send to PNG File then Ptr */
  /* */
#ifdef VMS
  sprintf (of, "%s-png", argv[1]);
#else
  sprintf (of, "%s.png", argv[1]);
#endif
  out = fopen (of, "wb");
  gdImagePng (im, out);
  fclose (out);

  in = fopen (of, "rb");
  if (!in)
    {
      fprintf (stderr, "PNG Output file does not exist!\n");
      exit (1);
    }
  im2 = gdImageCreateFromPng (in);
  fclose (in);

  CompareImages ("GD->PNG File->GD", ref, im2);

  unlink (of);
  gdImageDestroy (im2);

  /* 2.0.21: use the new From*Ptr functions */
  iptr = gdImagePngPtr (im, &sz);
  im2 = gdImageCreateFromPngPtr (sz, iptr);
  gdFree (iptr);
  CompareImages ("GD->PNG ptr->GD", ref, im2);

  gdImageDestroy (im2);

  /* */
  /* Send to GD2 File then Ptr */
  /* */
#ifdef VMS
  sprintf (of, "%s-gd2", argv[1]);
#else
  sprintf (of, "%s.gd2", argv[1]);
#endif
  out = fopen (of, "wb");
  gdImageGd2 (im, out, 128, 2);
  fclose (out);

  in = fopen (of, "rb");
  if (!in)
    {
      fprintf (stderr, "GD2 Output file does not exist!\n");
      exit (1);
    }
  im2 = gdImageCreateFromGd2 (in);
  fclose (in);

  CompareImages ("GD->GD2 File->GD", ref, im2);

  unlink (of);
  gdImageDestroy (im2);

  iptr = gdImageGd2Ptr (im, 128, 2, &sz);
  /*printf("Got ptr %d (size %d)\n",iptr, sz); */
  im2 = gdImageCreateFromGd2Ptr (sz, iptr);
  gdFree (iptr);
  /*printf("Got img2 %d\n",im2); */

  CompareImages ("GD->GD2 ptr->GD", ref, im2);

  gdImageDestroy (im2);

  /* */
  /* Send to GD File then Ptr */
  /* */
#ifdef VMS
  sprintf (of, "%s-gd", argv[1]);
#else
  sprintf (of, "%s.gd", argv[1]);
#endif
  out = fopen (of, "wb");
  gdImageGd (im, out);
  fclose (out);

  in = fopen (of, "rb");
  if (!in)
    {
      fprintf (stderr, "GD Output file does not exist!\n");
      exit (1);
    }
  im2 = gdImageCreateFromGd (in);
  fclose (in);

  CompareImages ("GD->GD File->GD", ref, im2);

  unlink (of);
  gdImageDestroy (im2);

  iptr = gdImageGdPtr (im, &sz);
  /*printf("Got ptr %d (size %d)\n",iptr, sz); */
  im2 = gdImageCreateFromGdPtr (sz, iptr);
  gdFree (iptr);
  /*printf("Got img2 %d\n",im2); */

  CompareImages ("GD->GD ptr->GD", ref, im2);

  gdImageDestroy (im2);

  /*
   * Test gdImageCreateFromPngSource'
   */

  in = fopen (argv[1], "rb");

  imgsrc.source = freadWrapper;
  imgsrc.context = in;
  im2 = gdImageCreateFromPngSource (&imgsrc);
  fclose (in);

  if (im2 == NULL)
    {
      printf
	("GD Source: ERROR Null returned by gdImageCreateFromPngSource\n");
    }
  else
    {
      CompareImages ("GD Source", ref, im2);
      gdImageDestroy (im2);
    };


  /*
   * Test gdImagePngToSink'
   */
#ifdef VMS
  sprintf (of, "%s-snk", argv[1]);
#else
  sprintf (of, "%s.snk", argv[1]);
#endif
  out = fopen (of, "wb");
  imgsnk.sink = fwriteWrapper;
  imgsnk.context = out;
  gdImagePngToSink (im, &imgsnk);
  fclose (out);
  in = fopen (of, "rb");
  if (!in)
    {
      fprintf (stderr,
	       "GD Sink: ERROR - GD Sink Output file does not exist!\n");
    }
  else
    {
      im2 = gdImageCreateFromPng (in);
      fclose (in);

      CompareImages ("GD Sink", ref, im2);
      gdImageDestroy (im2);
    };

  unlink (of);

  /* */
  /*  Test Extraction */
  /* */
  in = fopen ("test/gdtest_200_300_150_100.png", "rb");
  if (!in)
    {
      fprintf (stderr, "gdtest_200_300_150_100.png does not exist!\n");
      exit (1);
    }
  im2 = gdImageCreateFromPng (in);
  fclose (in);


  in = fopen ("test/gdtest.gd2", "rb");
  if (!in)
    {
      fprintf (stderr, "gdtest.gd2 does not exist!\n");
      exit (1);
    }
  im3 = gdImageCreateFromGd2Part (in, 200, 300, 150, 100);
  fclose (in);

  CompareImages ("GD2Part (gdtest_200_300_150_100.png, gdtest.gd2(part))",
		 im2, im3);

  gdImageDestroy (im2);
  gdImageDestroy (im3);

  /* */
  /*  Copy Blend */
  /* */
  in = fopen ("test/gdtest.png", "rb");
  if (!in)
    {
      fprintf (stderr, "gdtest.png does not exist!\n");
      exit (1);
    }
  im2 = gdImageCreateFromPng (in);
  fclose (in);

  im3 = gdImageCreate (100, 60);
  colRed = gdImageColorAllocate (im3, 255, 0, 0);
  colBlu = gdImageColorAllocate (im3, 0, 0, 255);
  gdImageFilledRectangle (im3, 0, 0, 49, 30, colRed);
  gdImageFilledRectangle (im3, 50, 30, 99, 59, colBlu);

  gdImageCopyMerge (im2, im3, 150, 200, 10, 10, 90, 50, 50);
  gdImageCopyMerge (im2, im3, 180, 70, 10, 10, 90, 50, 50);

  gdImageCopyMergeGray (im2, im3, 250, 160, 10, 10, 90, 50, 50);
  gdImageCopyMergeGray (im2, im3, 80, 70, 10, 10, 90, 50, 50);

  gdImageDestroy (im3);

  in = fopen ("test/gdtest_merge.png", "rb");
  if (!in)
    {
      fprintf (stderr, "gdtest_merge.png does not exist!\n");
      exit (1);
    }
  im3 = gdImageCreateFromPng (in);
  fclose (in);

  printf ("[Merged Image has %d colours]\n", im2->colorsTotal);
  CompareImages ("Merged (gdtest.png, gdtest_merge.png)", im2, im3);

  gdImageDestroy (im2);
  gdImageDestroy (im3);

#ifdef HAVE_LIBJPEG
  out = fopen ("test/gdtest.jpg", "wb");
  if (!out)
    {
      fprintf (stderr, "Can't create file test/gdtest.jpg.\n");
      exit (1);
    }
  gdImageJpeg (im, out, -1);
  fclose (out);
  in = fopen ("test/gdtest.jpg", "rb");
  if (!in)
    {
      fprintf (stderr, "Can't open file test/gdtest.jpg.\n");
      exit (1);
    }
  im2 = gdImageCreateFromJpeg (in);
  fclose (in);
  if (!im2)
    {
      fprintf (stderr, "gdImageCreateFromJpeg failed.\n");
      exit (1);
    }
  gdImageDestroy (im2);
  printf ("Created test/gdtest.jpg successfully. Compare this image\n"
	  "to the input image manually. Some difference must be\n"
	  "expected as JPEG is a lossy file format.\n");
#endif /* HAVE_LIBJPEG */
  /* Assume the color closest to black is the foreground
     color for the B&W wbmp image. */
  fprintf (stderr,
	   "NOTE: the WBMP output image will NOT match the original unless the original\n"
	   "is also black and white. This is OK!\n");
  foreground = gdImageColorClosest (im, 0, 0, 0);
  fprintf (stderr, "Foreground index is %d\n", foreground);
  if (foreground == -1)
    {
      fprintf (stderr, "Source image has no colors, skipping wbmp test.\n");
    }
  else
    {
      out = fopen ("test/gdtest.wbmp", "wb");
      if (!out)
	{
	  fprintf (stderr, "Can't create file test/gdtest.wbmp.\n");
	  exit (1);
	}
      gdImageWBMP (im, foreground, out);
      fclose (out);
      in = fopen ("test/gdtest.wbmp", "rb");
      if (!in)
	{
	  fprintf (stderr, "Can't open file test/gdtest.wbmp.\n");
	  exit (1);
	}
      im2 = gdImageCreateFromWBMP (in);
      fprintf (stderr, "WBMP has %d colors\n", gdImageColorsTotal (im2));
      fprintf (stderr, "WBMP colors are:\n");
      for (i = 0; (i < gdImageColorsTotal (im2)); i++)
	{
	  fprintf (stderr, "%02X%02X%02X\n",
		   gdImageRed (im2, i),
		   gdImageGreen (im2, i), gdImageBlue (im2, i));
	}
      fclose (in);
      if (!im2)
	{
	  fprintf (stderr, "gdImageCreateFromWBMP failed.\n");
	  exit (1);
	}
      CompareImages ("WBMP test (gdtest.png, gdtest.wbmp)", ref, im2);
      out = fopen ("test/gdtest_wbmp_to_png.png", "wb");
      if (!out)
	{
	  fprintf (stderr,
		   "Can't create file test/gdtest_wbmp_to_png.png.\n");
	  exit (1);
	}
      gdImagePng (im2, out);
      fclose (out);
      gdImageDestroy (im2);
    }
  gdImageDestroy (im);
  gdImageDestroy (ref);
#else
  fprintf (stderr, "No PNG library support.\n");
#endif /* HAVE_LIBPNG */

  return 0;
}
コード例 #11
0
//----------------------------------------------------------------------------
void mafPipeMeshSlice_BESTest::TestPipeExecution()
//----------------------------------------------------------------------------
{

  ///////////////// render stuff /////////////////////////
  
  m_Renderer->SetBackground(0.1, 0.1, 0.1);

  m_RenderWindow->AddRenderer(m_Renderer);
  m_RenderWindow->SetSize(320, 240);
  m_RenderWindow->SetPosition(400,0);

  

  m_RenderWindowInteractor->SetRenderWindow(m_RenderWindow);

  ///////////// end render stuff /////////////////////////



  ////// Create VME (import vtkData) ////////////////////
  mafVMEStorage *storage = mafVMEStorage::New();
  storage->GetRoot()->SetName("root");
  storage->GetRoot()->Initialize();
  mafOpImporterVTK *Importer=new mafOpImporterVTK("importer");
  mafString filename=MED_DATA_ROOT;
  filename<<"/FEM/pipemesh/hex8.vtk";
  Importer->TestModeOn();
  Importer->SetFileName(filename);
  Importer->SetInput(storage->GetRoot());
  Importer->ImportVTK();
  mafVMEMesh *mesh;
  mesh =mafVMEMesh::SafeDownCast(Importer->GetOutput());
	mesh->GetMaterial();
  mesh->GetMaterial()->m_MaterialType = mmaMaterial::USE_LOOKUPTABLE;
  mesh->Update();
  

  double center[3];
  mesh->GetOutput()->GetVTKData()->GetCenter(center);

  //Assembly will be create when instancing mafSceneNode
  mafSceneNode *sceneNode;
  sceneNode = new mafSceneNode(NULL,NULL,mesh, NULL);

  /////////// Pipe Instance and Creation ///////////
  mafPipeMeshSlice_BES *pipeMeshSlice = new mafPipeMeshSlice_BES;
  pipeMeshSlice->SetScalarMapActive(1);
  double origin[3], normal[3];

  //set origin and normal value
  origin[0] = 0.0;
  origin[1] = 0.0;
  origin[2] = 0.3;

  normal[0] = 0.0;
  normal[1] = 0.0; 
  normal[2] = 1.0;

  //pipeMeshSlice->SetNormal(normal);
  pipeMeshSlice->SetSlice(origin,normal);
  pipeMeshSlice->Create(sceneNode);
  
  ////////// ACTORS List ///////////////
  vtkPropCollection *actorList = vtkPropCollection::New();
  pipeMeshSlice->GetAssemblyFront()->GetActors(actorList);
  
  actorList->InitTraversal();
  vtkProp *actor = actorList->GetNextProp();
  while(actor)
  { 
    m_Renderer->AddActor(actor);
    m_RenderWindow->Render();

    actor = actorList->GetNextProp();
  }
	
	const char *strings[5];
	strings[0] = "id"; //point 

	strings[1] = "material"; //cell 
	strings[2] = "EX";
	strings[3] = "NUXY";
	strings[4] = "DENS";

  for(int arrayIndex=0; arrayIndex<pipeMeshSlice->GetNumberOfArrays(); arrayIndex++)
  {
    double controlValues[2] = {-9999,-9999};
    switch(arrayIndex)
    {
    case 0:
      {
        controlValues[0] = 1.0;
        controlValues[1] = 12.0;
      }
      break;
    case 1:
      {
        controlValues[0] = 2.0; 
        controlValues[1] = 3.0;
      }
      break;
    case 2:
      {
        controlValues[0] = 1000.0;
        controlValues[1] = 200000.0;
      }
      break;
    case 3:
      {
        controlValues[0] = 0.33;
        controlValues[1] =  0.39 ;
      }
      break;
    case 4:
      {
        controlValues[0] = 0.107;
        controlValues[1] = 1.07;
      }
      break;
    }
    pipeMeshSlice->SetActiveScalar(arrayIndex);
    pipeMeshSlice->OnEvent(&mafEvent(this, mafPipeMeshSlice_BES::ID_SCALARS));

    vtkActor *meshActor;
    meshActor = (vtkActor *) SelectActorToControl(actorList, PIPE_MESH_ACTOR);
    CPPUNIT_ASSERT(meshActor != NULL);

    ProceduralControl(controlValues, meshActor);
    m_RenderWindow->Render();
		printf("\n Visualizzazione: %s \n", strings[arrayIndex]);
    mafSleep(500);
    CompareImages(ID_TEST_PIPEEXECUTION+arrayIndex);
  }

  vtkDEL(actorList);

  delete pipeMeshSlice;

  cppDEL(Importer);
  mafDEL(storage);

  delete sceneNode;
}
コード例 #12
0
//----------------------------------------------------------------------------
void medPipeVolumeMIPTest::TestPipeExecution()
//----------------------------------------------------------------------------
{
  ///////////////// render stuff /////////////////////////

  m_Renderer->SetBackground(0.1, 0.1, 0.1);
  m_RenderWindow->AddRenderer(m_Renderer);
  m_RenderWindow->SetSize(320, 240);
  m_RenderWindow->SetPosition(400,0);

  m_RenderWindowInteractor->SetRenderWindow(m_RenderWindow);

  ///////////// end render stuff /////////////////////////


  ////// Create VME (import vtkData) ////////////////////
  ////// Create VME (import vtkData) ////////////////////
  vtkDataSetReader *Importer;
  vtkNEW(Importer);
  mafString filename=MED_DATA_ROOT;
  filename<<"/VTK_Volumes/volume.vtk";
  Importer->SetFileName(filename);
  Importer->Update();
  mafVMEVolumeGray *volume;
  mafNEW(volume);
  volume->SetData((vtkImageData*)Importer->GetOutput(),0.0);
  volume->GetOutput()->Update();
  volume->Update();
  
  //Assembly will be create when instancing mafSceneNode
  mafSceneNode *sceneNode;
  sceneNode = new mafSceneNode(NULL,NULL,volume, NULL);

  /////////// Pipe Instance and Creation ///////////
  medPipeVolumeMIP *pipeGizmo = new medPipeVolumeMIP;
  pipeGizmo->Create(sceneNode);
  
  ////////// ACTORS List ///////////////
  vtkPropCollection *actorList = vtkPropCollection::New();
  pipeGizmo->GetAssemblyFront()->GetVolumes(actorList);
  
  actorList->InitTraversal();
  vtkProp *actor = actorList->GetNextProp();
  while(actor)
  {   
    m_Renderer->AddVolume(actor);
    m_RenderWindow->Render();

    actor = actorList->GetNextProp();
  }

  vtkVolume *surfaceActor;
  surfaceActor = (vtkVolume *) SelectActorToControl(actorList, 0);
  CPPUNIT_ASSERT(surfaceActor != NULL);

  m_RenderWindow->Render();
  mafSleep(800);
  CompareImages(0);
  

  vtkDEL(actorList);

  delete pipeGizmo;
  delete sceneNode;

  mafDEL(volume);
  vtkDEL(Importer);
  
  delete wxLog::SetActiveTarget(NULL);
}
コード例 #13
0
//----------------------------------------------------------------------------
void medPipeWrappedMeterTest::TestPipeExecution()
//----------------------------------------------------------------------------
{
  mafVMEStorage *storage = mafVMEStorage::New();
  storage->GetRoot()->SetName("root");
  storage->GetRoot()->Initialize();

  ///////////////// render stuff /////////////////////////

  m_Renderer->SetBackground(0.1, 0.1, 0.1);
  m_RenderWindow->AddRenderer(m_Renderer);
  m_RenderWindow->SetSize(600, 600);
  m_RenderWindow->SetPosition(0,0);

  m_RenderWindowInteractor->SetRenderWindow(m_RenderWindow);
  ///////////// end render stuff /////////////////////////


  ////// Create VME ////////////////////
  mafVMESurfaceParametric *vmeParametricSurfaceSTART;
  mafNEW(vmeParametricSurfaceSTART);	
  vmeParametricSurfaceSTART->GetOutput()->GetVTKData()->Update();
  vmeParametricSurfaceSTART->SetParent(storage->GetRoot());
  vmeParametricSurfaceSTART->Update();

  mafVMESurfaceParametric *vmeParametricSurfaceEND1;
  mafNEW(vmeParametricSurfaceEND1);	
  vmeParametricSurfaceEND1->GetOutput()->GetVTKData()->Update();
  vmeParametricSurfaceEND1->SetParent(storage->GetRoot());
  vmeParametricSurfaceEND1->Update();


  mafMatrix *matrix = vmeParametricSurfaceEND1->GetOutput()->GetAbsMatrix();
  matrix->SetElement(0,3,4); //set a translation value on x axis of 4.0
  matrix->SetElement(1,3,3); //set a translation value on x axis of 3.0


  mafSmartPointer<medVMEWrappedMeter> meter;
  meter->SetMeterLink("StartVME",vmeParametricSurfaceSTART);
  meter->SetMeterLink("EndVME1",vmeParametricSurfaceEND1);
  meter->SetParent(storage->GetRoot());
  meter->GetOutput()->GetVTKData()->Update();
  meter->Modified();
  meter->Update();


  //Assembly will be create when instancing mafSceneNode
  mafSceneNode *sceneNode;
  sceneNode = new mafSceneNode(NULL,NULL,meter, NULL);
  sceneNode->m_RenFront = m_Renderer;

  /////////// Pipe Instance and Creation ///////////
  medPipeWrappedMeter *pipeMeter = new medPipeWrappedMeter;
  pipeMeter->Create(sceneNode);
  
  ////////// ACTORS List ///////////////
  vtkPropCollection *actorList = vtkPropCollection::New();
  pipeMeter->GetAssemblyFront()->GetActors(actorList);
  
  actorList->InitTraversal();
  vtkProp *actor = actorList->GetNextProp();
  while(actor)
  {   
    m_Renderer->AddActor(actor);
    m_RenderWindow->Render();

    actor = actorList->GetNextProp();
    break;
  }

  vtkActor *vectorActor;
  vectorActor = (vtkActor *) SelectActorToControl(actorList, 0);
  CPPUNIT_ASSERT(vectorActor != NULL);

  m_RenderWindow->Render();
  mafSleep(800);
  CompareImages(0);

  vtkDEL(actorList);

  delete pipeMeter;
  sceneNode->m_RenFront = NULL;
  delete sceneNode;

  meter->SetParent(NULL);
  vmeParametricSurfaceSTART->SetParent(NULL);
  vmeParametricSurfaceEND1->SetParent(NULL);
  mafDEL(vmeParametricSurfaceSTART);
  mafDEL(vmeParametricSurfaceEND1);

  mafDEL(storage);


  delete wxLog::SetActiveTarget(NULL);
}
コード例 #14
0
//----------------------------------------------------------------------------
void medVisualPipePolylineGraphTest::TestPipeExecution()
//----------------------------------------------------------------------------
{
    ///////////////// render stuff /////////////////////////

    m_Renderer->SetBackground(0.1, 0.1, 0.1);
    m_RenderWindow->AddRenderer(m_Renderer);
    m_RenderWindow->SetSize(320, 240);
    m_RenderWindow->SetPosition(400,0);

    m_RenderWindowInteractor->SetRenderWindow(m_RenderWindow);

    ///////////// end render stuff /////////////////////////


    ////// Create VME ////////////////////

    CreateExamplePolydata();

    mafSmartPointer<medVMEPolylineGraph> poly;
    poly->SetData(m_Polydata,0.0);
    poly->GetOutput()->Update();
    poly->Update();

    //Assembly will be create when instancing mafSceneNode
    mafSceneNode *sceneNode;
    sceneNode = new mafSceneNode(NULL,NULL,poly, NULL);

    /////////// Pipe Instance and Creation ///////////
    medVisualPipePolylineGraph *pipe = new medVisualPipePolylineGraph;
    pipe->Create(sceneNode);
    pipe->m_RenFront = m_Renderer;

    ////////// ACTORS List ///////////////
    vtkPropCollection *actorList = vtkPropCollection::New();
    pipe->GetAssemblyFront()->GetActors(actorList);


    actorList->InitTraversal();
    vtkProp *actor = actorList->GetNextProp();
    while(actor)
    {
        m_Renderer->AddVolume(actor);
        m_RenderWindow->Render();

        actor = actorList->GetNextProp();
    }

    vtkActor *surfaceActor;
    surfaceActor = (vtkActor *) SelectActorToControl(actorList, 0);
    CPPUNIT_ASSERT(surfaceActor != NULL);

    m_Renderer->ResetCamera();
    m_RenderWindow->Render();

    mafSleep(800);
    CompareImages(1);


    vtkDEL(actorList);

    delete pipe;
    delete sceneNode;

    delete wxLog::SetActiveTarget(NULL);
}
コード例 #15
0
//----------------------------------------------------------------------------
void medPipeTrajectoriesTest::TestPipeExecution()
//----------------------------------------------------------------------------
{
  ///////////////// render stuff /////////////////////////

  m_Renderer->SetBackground(0.1, 0.1, 0.1);
  m_RenderWindow->AddRenderer(m_Renderer);
  m_RenderWindow->SetSize(600, 600);
  m_RenderWindow->SetPosition(0,0);

  m_RenderWindowInteractor->SetRenderWindow(m_RenderWindow);
  ///////////// end render stuff /////////////////////////


  ////// Create VME ////////////////////
  mafSmartPointer<mafVMELandmarkCloud> cloud;
  cloud->AppendLandmark(0.0,0.0,0.0,"first");
  double x = 0;
  double y = 0;
  double z = 0;

  for (int i = 0; i < 15; i++)
  {
    x += 2.0;
    y += 5.5;
    z += 10;

    cloud->SetLandmark("first",x,y,z, i);
  }
  cloud->Update();
  cloud->TestModeOn();
  cloud->Open();

  mafSmartPointer<mafVMELandmark> landmark;
  landmark = cloud->GetLandmark("first");
  landmark->SetTimeStamp(5);
  
  //Assembly will be create when instancing mafSceneNode
  mafSceneNode *sceneNode;
  sceneNode = new mafSceneNode(NULL,NULL,landmark, NULL);
  sceneNode->m_RenFront = m_Renderer;

  /////////// Pipe Instance and Creation ///////////
  medPipeTrajectories *pipeTrajecotries = new medPipeTrajectories;
  pipeTrajecotries->Create(sceneNode);
  pipeTrajecotries->SetInterval(10);
  pipeTrajecotries->UpdateProperty();
  
  ////////// ACTORS List ///////////////
  vtkPropCollection *actorList = vtkPropCollection::New();
  pipeTrajecotries->GetAssemblyFront()->GetActors(actorList);
  
  actorList->InitTraversal();
  vtkProp *actor = actorList->GetNextProp();
  while(actor)
  {   
    m_Renderer->AddActor(actor);
    m_RenderWindow->Render();

    actor = actorList->GetNextProp();
    break;
  }

  vtkActor *cloudActor;
  cloudActor = (vtkActor *) SelectActorToControl(actorList, 0);
  CPPUNIT_ASSERT(cloudActor != NULL);

  m_RenderWindow->Render();
  mafSleep(800);
  CompareImages(0);

  vtkDEL(actorList);

  delete pipeTrajecotries;
  sceneNode->m_RenFront = NULL;
  delete sceneNode;

  delete wxLog::SetActiveTarget(NULL);
}
コード例 #16
0
/**Documentation
 *  test for the class "ToFImageGrabber".
 */
int mitkToFImageGrabberTest(int /* argc */, char* /*argv*/[])
{
  MITK_TEST_BEGIN("ToFImageGrabber");

  std::string dirName = MITK_TOF_DATA_DIR;
  mitk::ToFImageGrabber::Pointer tofImageGrabber = mitk::ToFImageGrabber::New();
  mitk::ToFCameraMITKPlayerDevice::Pointer tofCameraMITKPlayerDevice = mitk::ToFCameraMITKPlayerDevice::New();
  tofImageGrabber->SetCameraDevice(tofCameraMITKPlayerDevice);
  MITK_TEST_CONDITION_REQUIRED(tofCameraMITKPlayerDevice==tofImageGrabber->GetCameraDevice(),"Test Set/GetCameraDevice()");
  int modulationFrequency = 20;
  tofImageGrabber->SetModulationFrequency(modulationFrequency);
  MITK_TEST_CONDITION_REQUIRED(modulationFrequency==tofImageGrabber->GetModulationFrequency(),"Test Set/GetModulationFrequency()");
  int integrationTime = 500;
  tofImageGrabber->SetIntegrationTime(integrationTime);
  MITK_TEST_CONDITION_REQUIRED(integrationTime==tofImageGrabber->GetIntegrationTime(),"Test Set/GetIntegrationTime()");
  MITK_TEST_OUTPUT(<<"Test methods with invalid file name");
  MITK_TEST_FOR_EXCEPTION(std::logic_error, tofImageGrabber->ConnectCamera());
  MITK_TEST_OUTPUT(<<"Call StartCamera()");
  tofImageGrabber->StartCamera();
  MITK_TEST_OUTPUT(<<"Call StopCamera()");
  tofImageGrabber->StopCamera();
  MITK_TEST_CONDITION_REQUIRED(!tofImageGrabber->DisconnectCamera(),"Test DisconnectCamera() with no file name set");

  std::string distanceFileName = dirName + "/PMDCamCube2_MF0_IT0_1Images_DistanceImage.pic";
  tofImageGrabber->SetProperty("DistanceImageFileName",mitk::StringProperty::New(distanceFileName));
  std::string amplitudeFileName = dirName + "/PMDCamCube2_MF0_IT0_1Images_AmplitudeImage.pic";
  tofImageGrabber->SetProperty("AmplitudeImageFileName",mitk::StringProperty::New(amplitudeFileName));
  std::string intensityFileName = dirName + "/PMDCamCube2_MF0_IT0_1Images_IntensityImage.pic";
  tofImageGrabber->SetProperty("IntensityImageFileName",mitk::StringProperty::New(intensityFileName));

  // Load images with PicFileReader for comparison
  mitk::PicFileReader::Pointer picFileReader = mitk::PicFileReader::New();
  mitk::Image::Pointer expectedResultImage = NULL;

  MITK_TEST_OUTPUT(<<"Test ToFImageGrabber using ToFCameraMITKPlayerDevice");
  MITK_TEST_CONDITION_REQUIRED(tofImageGrabber->ConnectCamera(),"Test ConnectCamera()");
  MITK_TEST_CONDITION_REQUIRED(!tofImageGrabber->IsCameraActive(),"IsCameraActive() before StartCamera()");
  MITK_TEST_OUTPUT(<<"Call StartCamera()");
  tofImageGrabber->StartCamera();
  MITK_TEST_CONDITION_REQUIRED(tofImageGrabber->IsCameraActive(),"IsCameraActive() after StartCamera()");
  picFileReader->SetFileName(distanceFileName);
  picFileReader->Update();
  expectedResultImage = picFileReader->GetOutput();
  int captureWidth = expectedResultImage->GetDimension(0);
  int captureHeight = expectedResultImage->GetDimension(1);
  MITK_TEST_CONDITION_REQUIRED(tofImageGrabber->GetCaptureWidth()==captureWidth,"Test GetCaptureWidth()");
  MITK_TEST_CONDITION_REQUIRED(tofImageGrabber->GetCaptureHeight()==captureHeight,"Test GetCaptureHeight()");
  MITK_TEST_OUTPUT(<<"Call Update()");
  tofImageGrabber->Update();
  mitk::Image::Pointer distanceImage = tofImageGrabber->GetOutput(0);
  MITK_TEST_CONDITION_REQUIRED(CompareImages(expectedResultImage,distanceImage),"Test GetOutput(0)");
  picFileReader->SetFileName(amplitudeFileName);
  picFileReader->Update();
  mitk::Image::Pointer amplitudeImage = tofImageGrabber->GetOutput(1);
  MITK_TEST_CONDITION_REQUIRED(CompareImages(expectedResultImage,amplitudeImage),"Test GetOutput(1)");
  picFileReader->SetFileName(intensityFileName);
  picFileReader->Update();
  mitk::Image::Pointer intensityImage = tofImageGrabber->GetOutput(2);
  MITK_TEST_CONDITION_REQUIRED(CompareImages(expectedResultImage,intensityImage),"Test GetOutput(2)");
  MITK_TEST_OUTPUT(<<"Call StopCamera()");
  tofImageGrabber->StopCamera();
  MITK_TEST_CONDITION_REQUIRED(!tofImageGrabber->IsCameraActive(),"IsCameraActive() after StopCamera()");
  MITK_TEST_CONDITION_REQUIRED(tofImageGrabber->DisconnectCamera(),"Test DisconnectCamera()");
  MITK_TEST_CONDITION_REQUIRED(!tofImageGrabber->IsCameraActive(),"IsCameraActive() after DisconnectCamera()");

  MITK_TEST_END();;
}
コード例 #17
0
//----------------------------------------------------------------------------
void vtkMAFVolumeTextureMapper2DTest::TestPipeExecution()
//----------------------------------------------------------------------------
{
  ///////////////// render stuff /////////////////////////

  m_Renderer->SetBackground(0.1, 0.1, 0.1);
  m_RenderWindow->AddRenderer(m_Renderer);
  m_RenderWindow->SetSize(320, 240);
  m_RenderWindow->SetPosition(400,0);

  m_RenderWindowInteractor->SetRenderWindow(m_RenderWindow);

  
  ///////////// end render stuff /////////////////////////


  ////// import vtkData ////////////////////
  vtkDataSetReader *Importer;
  vtkNEW(Importer);
  mafString filename=MED_DATA_ROOT;
  filename<<"/VTK_Volumes/volume.vtk";
  Importer->SetFileName(filename);
  Importer->Update();
  
  vtkVolumeProperty *volumeProperty = NULL;
  vtkNEW(volumeProperty);  
  //volumeProperty->SetColor(m_ColorTransferFunction);
  volumeProperty->SetInterpolationTypeToLinear();

  vtkMAFVolumeTextureMapper2D *volumeMapper;
  vtkNEW(volumeMapper);
  volumeMapper->SetInput(vtkImageData::SafeDownCast(Importer->GetOutput()));

  volumeMapper->SetMaximumNumberOfPlanes(100);
  volumeMapper->SetTargetTextureSize(512,512);
  volumeMapper->SetMaximumStorageSize(64*1024*1024);  //BES 2.6.2008 - enable texture saving using up to 64 MB

  volumeMapper->Update();	

  vtkColorTransferFunction *colorTransferFunction = vtkColorTransferFunction::New();
  vtkPiecewiseFunction *piecewiseFunction = vtkPiecewiseFunction::New();

  double MaxR;
  double unsignRange[2];
  Importer->GetOutput()->GetScalarRange(unsignRange);
  if (unsignRange[1] < 256.0)
  {    
    piecewiseFunction->AddPoint(  0, 0.0);
    piecewiseFunction->AddPoint(255,1.0);

    MaxR = 255.0;
  }
  else if (unsignRange[1] < 4096.0)
  {
    piecewiseFunction->AddPoint(   0,0.0);
    piecewiseFunction->AddPoint(128,0.0);    
    piecewiseFunction->AddPoint(4095,1.0);

    MaxR = 4095.0;
  }
  else
  {
    piecewiseFunction->AddPoint(    0,0.0);
    piecewiseFunction->AddPoint(22737,0.0);
    piecewiseFunction->AddPoint(44327,1.0);
    piecewiseFunction->AddPoint(65535,1.0);

    MaxR = 65535.0;  
  }

  colorTransferFunction->AddRGBPoint(    0, 0.00, 0.00, 0.00);
  colorTransferFunction->AddRGBPoint((11655 / 65535.0)*MaxR, 0.74, 0.19, 0.14);
  colorTransferFunction->AddRGBPoint((31908 / 65535.0)*MaxR, 0.96, 0.64, 0.42);
  colorTransferFunction->AddRGBPoint((33818 / 65535.0)*MaxR, 0.76, 0.78, 0.25);
  colorTransferFunction->AddRGBPoint((41843 / 65535.0)*MaxR, 1.00, 1.00, 1.00);
  colorTransferFunction->AddRGBPoint((65535 / 65535.0)*MaxR, 1.00, 1.00, 1.00); 

  volumeProperty->SetColor(colorTransferFunction);
  volumeProperty->SetScalarOpacity(piecewiseFunction);

  vtkVolume *volume;
  vtkNEW(volume);
  volume->SetMapper(volumeMapper);
  volume->SetProperty(volumeProperty);
  volume->PickableOff();

  m_Renderer->AddVolume(volume);
  //m_RenderWindow->Render();

  vtkCamera *camera = m_Renderer->GetActiveCamera();
  camera->Azimuth(60);
  camera->Elevation(30);

  m_RenderWindow->Render();

  //m_RenderWindowInteractor->Start();
  CompareImages(0);

  vtkDEL(volumeProperty);
  vtkDEL(volume);
  vtkDEL(colorTransferFunction);
  vtkDEL(piecewiseFunction);
  vtkDEL(volumeMapper);
  vtkDEL(Importer);
  
  delete wxLog::SetActiveTarget(NULL);
}
コード例 #18
0
ファイル: compare.c プロジェクト: DINKIN/ImageMagick
WandExport MagickBooleanType CompareImagesCommand(ImageInfo *image_info,
  int argc,char **argv,char **metadata,ExceptionInfo *exception)
{
#define CompareEpsilon  (1.0e-06)
#define DefaultDissimilarityThreshold  0.31830988618379067154
#define DefaultSimilarityThreshold  (-1.0)
#define DestroyCompare() \
{ \
  if (similarity_image != (Image *) NULL) \
    similarity_image=DestroyImageList(similarity_image); \
  if (difference_image != (Image *) NULL) \
    difference_image=DestroyImageList(difference_image); \
  DestroyImageStack(); \
  for (i=0; i < (ssize_t) argc; i++) \
    argv[i]=DestroyString(argv[i]); \
  argv=(char **) RelinquishMagickMemory(argv); \
}
#define ThrowCompareException(asperity,tag,option) \
{ \
  if (exception->severity < (asperity)) \
    (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag, \
      "`%s'",option); \
  DestroyCompare(); \
  return(MagickFalse); \
}
#define ThrowCompareInvalidArgumentException(option,argument) \
{ \
  (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
    "InvalidArgument","'%s': %s",option,argument); \
  DestroyCompare(); \
  return(MagickFalse); \
}

  char
    *filename,
    *option;

  const char
    *format;

  double
    dissimilarity_threshold,
    distortion,
    similarity_metric,
    similarity_threshold;

  Image
    *difference_image,
    *image,
    *reconstruct_image,
    *similarity_image;

  ImageStack
    image_stack[MaxImageStackDepth+1];

  MagickBooleanType
    fire,
    pend,
    respect_parenthesis,
    subimage_search;

  MagickStatusType
    status;

  MetricType
    metric;

  RectangleInfo
    offset;

  register ssize_t
    i;

  ssize_t
    j,
    k;

  /*
    Set defaults.
  */
  assert(image_info != (ImageInfo *) NULL);
  assert(image_info->signature == MagickCoreSignature);
  if (image_info->debug != MagickFalse)
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
  assert(exception != (ExceptionInfo *) NULL);
  if (argc == 2)
    {
      option=argv[1];
      if ((LocaleCompare("version",option+1) == 0) ||
          (LocaleCompare("-version",option+1) == 0))
        {
          ListMagickVersion(stdout);
          return(MagickFalse);
        }
    }
  if (argc < 3)
    return(CompareUsage());
  difference_image=NewImageList();
  similarity_image=NewImageList();
  dissimilarity_threshold=DefaultDissimilarityThreshold;
  similarity_threshold=DefaultSimilarityThreshold;
  distortion=0.0;
  format=(char *) NULL;
  j=1;
  k=0;
  metric=UndefinedErrorMetric;
  NewImageStack();
  option=(char *) NULL;
  pend=MagickFalse;
  reconstruct_image=NewImageList();
  respect_parenthesis=MagickFalse;
  status=MagickTrue;
  subimage_search=MagickFalse;
  /*
    Compare an image.
  */
  ReadCommandlLine(argc,&argv);
  status=ExpandFilenames(&argc,&argv);
  if (status == MagickFalse)
    ThrowCompareException(ResourceLimitError,"MemoryAllocationFailed",
      GetExceptionMessage(errno));
  for (i=1; i < (ssize_t) (argc-1); i++)
  {
    option=argv[i];
    if (LocaleCompare(option,"(") == 0)
      {
        FireImageStack(MagickTrue,MagickTrue,pend);
        if (k == MaxImageStackDepth)
          ThrowCompareException(OptionError,"ParenthesisNestedTooDeeply",
            option);
        PushImageStack();
        continue;
      }
    if (LocaleCompare(option,")") == 0)
      {
        FireImageStack(MagickTrue,MagickTrue,MagickTrue);
        if (k == 0)
          ThrowCompareException(OptionError,"UnableToParseExpression",option);
        PopImageStack();
        continue;
      }
    if (IsCommandOption(option) == MagickFalse)
      {
        Image
          *images;

        /*
          Read input image.
        */
        FireImageStack(MagickFalse,MagickFalse,pend);
        filename=argv[i];
        if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
          filename=argv[++i];
        images=ReadImages(image_info,filename,exception);
        status&=(images != (Image *) NULL) &&
          (exception->severity < ErrorException);
        if (images == (Image *) NULL)
          continue;
        AppendImageStack(images);
        continue;
      }
    pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
    switch (*(option+1))
    {
      case 'a':
      {
        if (LocaleCompare("alpha",option+1) == 0)
          {
            ssize_t
              type;

            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,argv[i]);
            if (type < 0)
              ThrowCompareException(OptionError,"UnrecognizedAlphaChannelOption",
                argv[i]);
            break;
          }
        if (LocaleCompare("authenticate",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            break;
          }
        ThrowCompareException(OptionError,"UnrecognizedOption",option);
      }
      case 'c':
      {
        if (LocaleCompare("cache",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            if (IsGeometry(argv[i]) == MagickFalse)
              ThrowCompareInvalidArgumentException(option,argv[i]);
            break;
          }
        if (LocaleCompare("channel",option+1) == 0)
          {
            ssize_t
              channel;

            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            channel=ParseChannelOption(argv[i]);
            if (channel < 0)
              ThrowCompareException(OptionError,"UnrecognizedChannelType",
                argv[i]);
            (void) SetPixelChannelMask(image,(ChannelType) channel);
            break;
          }
        if (LocaleCompare("colorspace",option+1) == 0)
          {
            ssize_t
              colorspace;

            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
              argv[i]);
            if (colorspace < 0)
              ThrowCompareException(OptionError,"UnrecognizedColorspace",
                argv[i]);
            break;
          }
        if (LocaleCompare("compose",option+1) == 0)
          {
            ssize_t
              compose;

            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            compose=ParseCommandOption(MagickComposeOptions,MagickFalse,
              argv[i]);
            if (compose < 0)
              ThrowCompareException(OptionError,"UnrecognizedComposeOperator",
                argv[i]);
            break;
          }
        if (LocaleCompare("compress",option+1) == 0)
          {
            ssize_t
              compress;

            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
              argv[i]);
            if (compress < 0)
              ThrowCompareException(OptionError,"UnrecognizedImageCompression",
                argv[i]);
            break;
          }
        if (LocaleCompare("concurrent",option+1) == 0)
          break;
        ThrowCompareException(OptionError,"UnrecognizedOption",option)
      }
      case 'd':
      {
        if (LocaleCompare("debug",option+1) == 0)
          {
            LogEventType
              event_mask;

            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            event_mask=SetLogEventMask(argv[i]);
            if (event_mask == UndefinedEvents)
              ThrowCompareException(OptionError,"UnrecognizedEventType",
                argv[i]);
            break;
          }
        if (LocaleCompare("decipher",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            break;
          }
        if (LocaleCompare("define",option+1) == 0)
          {
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            if (*option == '+')
              {
                const char
                  *define;

                define=GetImageOption(image_info,argv[i]);
                if (define == (const char *) NULL)
                  ThrowCompareException(OptionError,"NoSuchOption",argv[i]);
                break;
              }
            break;
          }
        if (LocaleCompare("density",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            if (IsGeometry(argv[i]) == MagickFalse)
              ThrowCompareInvalidArgumentException(option,argv[i]);
            break;
          }
        if (LocaleCompare("depth",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            if (IsGeometry(argv[i]) == MagickFalse)
              ThrowCompareInvalidArgumentException(option,argv[i]);
            break;
          }
        if (LocaleCompare("dissimilarity-threshold",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            if (IsGeometry(argv[i]) == MagickFalse)
              ThrowCompareInvalidArgumentException(option,argv[i]);
            if (*option == '+')
              dissimilarity_threshold=DefaultDissimilarityThreshold;
            else
              dissimilarity_threshold=StringToDouble(argv[i],(char **) NULL);
            break;
          }
        if (LocaleCompare("duration",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            if (IsGeometry(argv[i]) == MagickFalse)
              ThrowCompareInvalidArgumentException(option,argv[i]);
            break;
          }
        ThrowCompareException(OptionError,"UnrecognizedOption",option)
      }
      case 'e':
      {
        if (LocaleCompare("encipher",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            break;
          }
        if (LocaleCompare("extract",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            if (IsGeometry(argv[i]) == MagickFalse)
              ThrowCompareInvalidArgumentException(option,argv[i]);
            break;
          }
        ThrowCompareException(OptionError,"UnrecognizedOption",option)
      }
      case 'f':
      {
        if (LocaleCompare("format",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            format=argv[i];
            break;
          }
        if (LocaleCompare("fuzz",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            if (IsGeometry(argv[i]) == MagickFalse)
              ThrowCompareInvalidArgumentException(option,argv[i]);
            break;
          }
        ThrowCompareException(OptionError,"UnrecognizedOption",option)
      }
      case 'h':
      {
        if ((LocaleCompare("help",option+1) == 0) ||
            (LocaleCompare("-help",option+1) == 0))
          return(CompareUsage());
        if (LocaleCompare("highlight-color",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            break;
          }
        ThrowCompareException(OptionError,"UnrecognizedOption",option)
      }
      case 'i':
      {
        if (LocaleCompare("identify",option+1) == 0)
          break;
        if (LocaleCompare("interlace",option+1) == 0)
          {
            ssize_t
              interlace;

            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
              argv[i]);
            if (interlace < 0)
              ThrowCompareException(OptionError,"UnrecognizedInterlaceType",
                argv[i]);
            break;
          }
        ThrowCompareException(OptionError,"UnrecognizedOption",option)
      }
      case 'l':
      {
        if (LocaleCompare("limit",option+1) == 0)
          {
            char
              *p;

            double
              value;

            ssize_t
              resource;

            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
              argv[i]);
            if (resource < 0)
              ThrowCompareException(OptionError,"UnrecognizedResourceType",
                argv[i]);
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            value=StringToDouble(argv[i],&p);
            (void) value;
            if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
              ThrowCompareInvalidArgumentException(option,argv[i]);
            break;
          }
        if (LocaleCompare("list",option+1) == 0)
          {
            ssize_t
              list;

            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
            if (list < 0)
              ThrowCompareException(OptionError,"UnrecognizedListType",argv[i]);
            status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
              argv+j,exception);
            DestroyCompare();
            return(status == 0 ? MagickTrue : MagickFalse);
          }
        if (LocaleCompare("log",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL))
              ThrowCompareException(OptionError,"MissingArgument",option);
            break;
          }
        if (LocaleCompare("lowlight-color",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            break;
          }
        ThrowCompareException(OptionError,"UnrecognizedOption",option)
      }
      case 'm':
      {
        if (LocaleCompare("matte",option+1) == 0)
          break;
        if (LocaleCompare("metric",option+1) == 0)
          {
            ssize_t
              type;

            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            type=ParseCommandOption(MagickMetricOptions,MagickTrue,argv[i]);
            if (type < 0)
              ThrowCompareException(OptionError,"UnrecognizedMetricType",
                argv[i]);
            metric=(MetricType) type;
            break;
          }
        if (LocaleCompare("monitor",option+1) == 0)
          break;
        ThrowCompareException(OptionError,"UnrecognizedOption",option)
      }
      case 'p':
      {
        if (LocaleCompare("profile",option+1) == 0)
          {
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            break;
          }
        ThrowCompareException(OptionError,"UnrecognizedOption",option)
      }
      case 'q':
      {
        if (LocaleCompare("quality",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            if (IsGeometry(argv[i]) == MagickFalse)
              ThrowCompareInvalidArgumentException(option,argv[i]);
            break;
          }
        if (LocaleCompare("quantize",option+1) == 0)
          {
            ssize_t
              colorspace;

            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            colorspace=ParseCommandOption(MagickColorspaceOptions,
              MagickFalse,argv[i]);
            if (colorspace < 0)
              ThrowCompareException(OptionError,"UnrecognizedColorspace",
                argv[i]);
            break;
          }
        if (LocaleCompare("quiet",option+1) == 0)
          break;
        ThrowCompareException(OptionError,"UnrecognizedOption",option)
      }
      case 'r':
      {
        if (LocaleCompare("regard-warnings",option+1) == 0)
          break;
        if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
          {
            respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
            break;
          }
        ThrowCompareException(OptionError,"UnrecognizedOption",option)
      }
      case 's':
      {
        if (LocaleCompare("sampling-factor",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            if (IsGeometry(argv[i]) == MagickFalse)
              ThrowCompareInvalidArgumentException(option,argv[i]);
            break;
          }
        if (LocaleCompare("seed",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            if (IsGeometry(argv[i]) == MagickFalse)
              ThrowCompareInvalidArgumentException(option,argv[i]);
            break;
          }
        if (LocaleCompare("set",option+1) == 0)
          {
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            break;
          }
        if (LocaleCompare("similarity-threshold",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            if (IsGeometry(argv[i]) == MagickFalse)
              ThrowCompareInvalidArgumentException(option,argv[i]);
            if (*option == '+')
              similarity_threshold=DefaultSimilarityThreshold;
            else
              similarity_threshold=StringToDouble(argv[i],(char **) NULL);
            break;
          }
        if (LocaleCompare("size",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            if (IsGeometry(argv[i]) == MagickFalse)
              ThrowCompareInvalidArgumentException(option,argv[i]);
            break;
          }
        if (LocaleCompare("subimage-search",option+1) == 0)
          {
            if (*option == '+')
              {
                subimage_search=MagickFalse;
                break;
              }
            subimage_search=MagickTrue;
            break;
          }
        if (LocaleCompare("synchronize",option+1) == 0)
          break;
        ThrowCompareException(OptionError,"UnrecognizedOption",option)
      }
      case 't':
      {
        if (LocaleCompare("taint",option+1) == 0)
          break;
        if (LocaleCompare("transparent-color",option+1) == 0)
          {
            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            break;
          }
        if (LocaleCompare("type",option+1) == 0)
          {
            ssize_t
              type;

            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
            if (type < 0)
              ThrowCompareException(OptionError,"UnrecognizedImageType",
                argv[i]);
            break;
          }
        ThrowCompareException(OptionError,"UnrecognizedOption",option)
      }
      case 'v':
      {
        if (LocaleCompare("verbose",option+1) == 0)
          break;
        if ((LocaleCompare("version",option+1) == 0) ||
            (LocaleCompare("-version",option+1) == 0))
          {
            ListMagickVersion(stdout);
            break;
          }
        if (LocaleCompare("virtual-pixel",option+1) == 0)
          {
            ssize_t
              method;

            if (*option == '+')
              break;
            i++;
            if (i == (ssize_t) argc)
              ThrowCompareException(OptionError,"MissingArgument",option);
            method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
              argv[i]);
            if (method < 0)
              ThrowCompareException(OptionError,
                "UnrecognizedVirtualPixelMethod",argv[i]);
            break;
          }
        ThrowCompareException(OptionError,"UnrecognizedOption",option)
      }
      case '?':
        break;
      default:
        ThrowCompareException(OptionError,"UnrecognizedOption",option)
    }
    fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
      FireOptionFlag) == 0 ?  MagickFalse : MagickTrue;
    if (fire != MagickFalse)
      FireImageStack(MagickTrue,MagickTrue,MagickTrue);
  }
  if (k != 0)
    ThrowCompareException(OptionError,"UnbalancedParenthesis",argv[i]);
  if (i-- != (ssize_t) (argc-1))
    ThrowCompareException(OptionError,"MissingAnImageFilename",argv[i]);
  if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
    ThrowCompareException(OptionError,"MissingAnImageFilename",argv[i]);
  FinalizeImageSettings(image_info,image,MagickTrue);
  if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
    ThrowCompareException(OptionError,"MissingAnImageFilename",argv[i]);
  image=GetImageFromList(image,0);
  reconstruct_image=GetImageFromList(image,1);
  offset.x=0;
  offset.y=0;
  if (subimage_search != MagickFalse)
    {
      similarity_image=SimilarityImage(image,reconstruct_image,metric,
        similarity_threshold,&offset,&similarity_metric,exception);
      if (similarity_metric > dissimilarity_threshold)
        ThrowCompareException(ImageError,"ImagesTooDissimilar",image->filename);
    }
  if ((reconstruct_image->columns == image->columns) &&
       (reconstruct_image->rows == image->rows))
    difference_image=CompareImages(image,reconstruct_image,metric,&distortion,
      exception);
  else
    if (similarity_image == (Image *) NULL)
      {
        if (metric == PerceptualHashErrorMetric)
          difference_image=CompareImages(image,reconstruct_image,metric,
            &distortion,exception);
        else
          ThrowCompareException(OptionError,"ImageWidthsOrHeightsDiffer",
            image->filename);
      }
    else
      {
        Image
          *composite_image;

        /*
          Determine if reconstructed image is a subimage of the image.
        */
        composite_image=CloneImage(image,0,0,MagickTrue,exception);
        if (composite_image == (Image *) NULL)
          difference_image=CompareImages(image,reconstruct_image,metric,
            &distortion,exception);
        else
          {
            Image
              *distort_image;

            RectangleInfo
              page;

            (void) CompositeImage(composite_image,reconstruct_image,
              CopyCompositeOp,MagickTrue,offset.x,offset.y,exception);
            difference_image=CompareImages(image,composite_image,metric,
              &distortion,exception);
            if (difference_image != (Image *) NULL)
              {
                difference_image->page.x=offset.x;
                difference_image->page.y=offset.y;
              }
            composite_image=DestroyImage(composite_image);
            page.width=reconstruct_image->columns;
            page.height=reconstruct_image->rows;
            page.x=offset.x;
            page.y=offset.y;
            distort_image=CropImage(image,&page,exception);
            if (distort_image != (Image *) NULL)
              {
                Image
                  *sans_image;

                sans_image=CompareImages(distort_image,reconstruct_image,metric,
                  &distortion,exception);
                distort_image=DestroyImage(distort_image);
                if (sans_image != (Image *) NULL)
                  sans_image=DestroyImage(sans_image);
              }
          }
        if (difference_image != (Image *) NULL)
          {
            AppendImageToList(&difference_image,similarity_image);
            similarity_image=(Image *) NULL;
          }
      }
  if (difference_image == (Image *) NULL)
    status=0;
  else
    {
      if (image_info->verbose != MagickFalse)
        (void) SetImageColorMetric(image,reconstruct_image,exception);
      if (*difference_image->magick == '\0')
        (void) CopyMagickString(difference_image->magick,image->magick,
          MagickPathExtent);
      if (image_info->verbose == MagickFalse)
        {
          switch (metric)
          {
            case FuzzErrorMetric:
            case MeanAbsoluteErrorMetric:
            case MeanSquaredErrorMetric:
            case PeakAbsoluteErrorMetric:
            case RootMeanSquaredErrorMetric:
            {
              (void) FormatLocaleFile(stderr,"%g (%g)",QuantumRange*distortion,
                (double) distortion);
              break;
            }
            case AbsoluteErrorMetric:
            case NormalizedCrossCorrelationErrorMetric:
            case PeakSignalToNoiseRatioErrorMetric:
            case PerceptualHashErrorMetric:
            {
              (void) FormatLocaleFile(stderr,"%g",distortion);
              break;
            }
            case MeanErrorPerPixelErrorMetric:
            {
              (void) FormatLocaleFile(stderr,"%g (%g, %g)",distortion,
                image->error.normalized_mean_error,
                image->error.normalized_maximum_error);
              break;
            }
            case UndefinedErrorMetric:
              break;
          }
          if (subimage_search != MagickFalse)
            (void) FormatLocaleFile(stderr," @ %.20g,%.20g",(double)
              difference_image->page.x,(double) difference_image->page.y);
        }
      else
        {
          double
            *channel_distortion;

          channel_distortion=GetImageDistortions(image,reconstruct_image,
            metric,exception);
          (void) FormatLocaleFile(stderr,"Image: %s\n",image->filename);
          if ((reconstruct_image->columns != image->columns) ||
              (reconstruct_image->rows != image->rows))
            (void) FormatLocaleFile(stderr,"Offset: %.20g,%.20g\n",(double)
              difference_image->page.x,(double) difference_image->page.y);
          (void) FormatLocaleFile(stderr,"  Channel distortion: %s\n",
            CommandOptionToMnemonic(MagickMetricOptions,(ssize_t) metric));
          switch (metric)
          {
            case FuzzErrorMetric:
            case MeanAbsoluteErrorMetric:
            case MeanSquaredErrorMetric:
            case PeakAbsoluteErrorMetric:
            case RootMeanSquaredErrorMetric:
            {
              switch (image->colorspace)
              {
                case RGBColorspace:
                default:
                {
                  (void) FormatLocaleFile(stderr,"    red: %g (%g)\n",
                    QuantumRange*channel_distortion[RedPixelChannel],
                    channel_distortion[RedPixelChannel]);
                  (void) FormatLocaleFile(stderr,"    green: %g (%g)\n",
                    QuantumRange*channel_distortion[GreenPixelChannel],
                    channel_distortion[GreenPixelChannel]);
                  (void) FormatLocaleFile(stderr,"    blue: %g (%g)\n",
                    QuantumRange*channel_distortion[BluePixelChannel],
                    channel_distortion[BluePixelChannel]);
                  if (image->alpha_trait != UndefinedPixelTrait)
                    (void) FormatLocaleFile(stderr,"    alpha: %g (%g)\n",
                      QuantumRange*channel_distortion[AlphaPixelChannel],
                      channel_distortion[AlphaPixelChannel]);
                  break;
                }
                case CMYKColorspace:
                {
                  (void) FormatLocaleFile(stderr,"    cyan: %g (%g)\n",
                    QuantumRange*channel_distortion[CyanPixelChannel],
                    channel_distortion[CyanPixelChannel]);
                  (void) FormatLocaleFile(stderr,"    magenta: %g (%g)\n",
                    QuantumRange*channel_distortion[MagentaPixelChannel],
                    channel_distortion[MagentaPixelChannel]);
                  (void) FormatLocaleFile(stderr,"    yellow: %g (%g)\n",
                    QuantumRange*channel_distortion[YellowPixelChannel],
                    channel_distortion[YellowPixelChannel]);
                  (void) FormatLocaleFile(stderr,"    black: %g (%g)\n",
                    QuantumRange*channel_distortion[BlackPixelChannel],
                    channel_distortion[BlackPixelChannel]);
                  if (image->alpha_trait != UndefinedPixelTrait)
                    (void) FormatLocaleFile(stderr,"    alpha: %g (%g)\n",
                      QuantumRange*channel_distortion[AlphaPixelChannel],
                      channel_distortion[AlphaPixelChannel]);
                  break;
                }
                case GRAYColorspace:
                {
                  (void) FormatLocaleFile(stderr,"    gray: %g (%g)\n",
                    QuantumRange*channel_distortion[GrayPixelChannel],
                    channel_distortion[GrayPixelChannel]);
                  if (image->alpha_trait != UndefinedPixelTrait)
                    (void) FormatLocaleFile(stderr,"    alpha: %g (%g)\n",
                      QuantumRange*channel_distortion[AlphaPixelChannel],
                      channel_distortion[AlphaPixelChannel]);
                  break;
                }
              }
              (void) FormatLocaleFile(stderr,"    all: %g (%g)\n",
                QuantumRange*channel_distortion[MaxPixelChannels],
                channel_distortion[MaxPixelChannels]);
              break;
            }
            case AbsoluteErrorMetric:
            case NormalizedCrossCorrelationErrorMetric:
            case PeakSignalToNoiseRatioErrorMetric:
            case PerceptualHashErrorMetric:
            {
              switch (image->colorspace)
              {
                case RGBColorspace:
                default:
                {
                  (void) FormatLocaleFile(stderr,"    red: %g\n",
                    channel_distortion[RedPixelChannel]);
                  (void) FormatLocaleFile(stderr,"    green: %g\n",
                    channel_distortion[GreenPixelChannel]);
                  (void) FormatLocaleFile(stderr,"    blue: %g\n",
                    channel_distortion[BluePixelChannel]);
                  if (image->alpha_trait != UndefinedPixelTrait)
                    (void) FormatLocaleFile(stderr,"    alpha: %g\n",
                      channel_distortion[AlphaPixelChannel]);
                  break;
                }
                case CMYKColorspace:
                {
                  (void) FormatLocaleFile(stderr,"    cyan: %g\n",
                    channel_distortion[CyanPixelChannel]);
                  (void) FormatLocaleFile(stderr,"    magenta: %g\n",
                    channel_distortion[MagentaPixelChannel]);
                  (void) FormatLocaleFile(stderr,"    yellow: %g\n",
                    channel_distortion[YellowPixelChannel]);
                  (void) FormatLocaleFile(stderr,"    black: %g\n",
                    channel_distortion[BlackPixelChannel]);
                  if (image->alpha_trait != UndefinedPixelTrait)
                    (void) FormatLocaleFile(stderr,"    alpha: %g\n",
                      channel_distortion[AlphaPixelChannel]);
                  break;
                }
                case GRAYColorspace:
                {
                  (void) FormatLocaleFile(stderr,"    gray: %g\n",
                    channel_distortion[GrayPixelChannel]);
                  if (image->alpha_trait != UndefinedPixelTrait)
                    (void) FormatLocaleFile(stderr,"    alpha: %g\n",
                      channel_distortion[AlphaPixelChannel]);
                  break;
                }
              }
              (void) FormatLocaleFile(stderr,"    all: %g\n",
                channel_distortion[MaxPixelChannels]);
              break;
            }
            case MeanErrorPerPixelErrorMetric:
            {
              (void) FormatLocaleFile(stderr,"    %g (%g, %g)\n",
                channel_distortion[MaxPixelChannels],
                image->error.normalized_mean_error,
                image->error.normalized_maximum_error);
              break;
            }
            case UndefinedErrorMetric:
              break;
          }
          channel_distortion=(double *) RelinquishMagickMemory(
            channel_distortion);
          if (subimage_search != MagickFalse)
            (void) FormatLocaleFile(stderr,"   Offset: %.20g,%.20g\n",(double)
              difference_image->page.x,(double) difference_image->page.y);
        }
      status&=WriteImages(image_info,difference_image,argv[argc-1],exception);
      if ((metadata != (char **) NULL) && (format != (char *) NULL))
        {
          char
            *text;

          text=InterpretImageProperties(image_info,difference_image,format,
            exception);
          if (text == (char *) NULL)
            ThrowCompareException(ResourceLimitError,"MemoryAllocationFailed",
              GetExceptionMessage(errno));
          (void) ConcatenateString(&(*metadata),text);
          text=DestroyString(text);
        }
      difference_image=DestroyImageList(difference_image);
    }
  DestroyCompare();
  if ((metric == NormalizedCrossCorrelationErrorMetric) ||
      (metric == UndefinedErrorMetric))
    {
      if (fabs(distortion-1.0) > CompareEpsilon)
        (void) SetImageOption(image_info,"compare:dissimilar","true");
    }
  else
    if (fabs(distortion) > CompareEpsilon)
      (void) SetImageOption(image_info,"compare:dissimilar","true");
  return(status != 0 ? MagickTrue : MagickFalse);
}
コード例 #19
0
int mitkToFImageRecorderTest(int /* argc */, char* /*argv*/[])
{
  MITK_TEST_BEGIN("ToFImageRecorder");

  mitk::ToFImageRecorder::Pointer tofImageRecorder = mitk::ToFImageRecorder::New();

  MITK_TEST_OUTPUT(<< "Test itk-Set/Get-Makros");
  std::string testFileName_Distance = "test_DistanceImage.nrrd";
  std::string testFileName_Amplitude = "test_AmplitudeImage.nrrd";
  std::string testFileName_Intensity = "test_IntensityImage.nrrd";
  std::string requiredName_Distance;
  std::string requiredName_Amplitude;
  std::string requiredName_Intensity;

  tofImageRecorder->SetDistanceImageFileName(testFileName_Distance);
  requiredName_Distance = tofImageRecorder->GetDistanceImageFileName();
  MITK_TEST_CONDITION_REQUIRED(requiredName_Distance==testFileName_Distance,"Test for distance image file name");

  tofImageRecorder->SetAmplitudeImageFileName(testFileName_Amplitude);
  requiredName_Amplitude = tofImageRecorder->GetAmplitudeImageFileName();
  MITK_TEST_CONDITION_REQUIRED(requiredName_Amplitude==testFileName_Amplitude,"Test for amplitude image file name");

  tofImageRecorder->SetIntensityImageFileName(testFileName_Intensity);
  requiredName_Intensity = tofImageRecorder->GetIntensityImageFileName();
  MITK_TEST_CONDITION_REQUIRED(requiredName_Intensity==testFileName_Intensity,"Test for intensity image file name");

  bool distanceImageSelected = false;
  bool amplitudeImageSelected = false;
  bool intensityImageSelected = false;
  bool requiredDistanceImageSelected = false;
  bool requiredAmplitudeImageSelected = false;
  bool requiredIntensityImageSelected = false;

  tofImageRecorder->SetDistanceImageSelected(distanceImageSelected);
  requiredDistanceImageSelected = tofImageRecorder->GetDistanceImageSelected();
  MITK_TEST_CONDITION_REQUIRED(distanceImageSelected==requiredDistanceImageSelected,"Test for distance selection");

  tofImageRecorder->SetAmplitudeImageSelected(amplitudeImageSelected);
  requiredAmplitudeImageSelected = tofImageRecorder->GetAmplitudeImageSelected();
  MITK_TEST_CONDITION_REQUIRED(amplitudeImageSelected==requiredAmplitudeImageSelected,"Test for amplitude selection");

  tofImageRecorder->SetIntensityImageSelected(intensityImageSelected);
  requiredIntensityImageSelected = tofImageRecorder->GetIntensityImageSelected();
  MITK_TEST_CONDITION_REQUIRED(intensityImageSelected==requiredIntensityImageSelected,"Test for intensity selection");

  int numOfFrames = 7;
  tofImageRecorder->SetNumOfFrames(numOfFrames);
  MITK_TEST_CONDITION_REQUIRED(numOfFrames==tofImageRecorder->GetNumOfFrames(),"Test for get/set number of frames");

  std::string fileFormat = ".nrrd";
  tofImageRecorder->SetFileFormat(fileFormat);
  MITK_TEST_CONDITION_REQUIRED(fileFormat==tofImageRecorder->GetFileFormat(),"Test for get/set the file format");



  MITK_TEST_OUTPUT(<< "Test other methods");

  tofImageRecorder->SetRecordMode(mitk::ToFImageRecorder::Infinite);
  MITK_TEST_CONDITION_REQUIRED(mitk::ToFImageRecorder::Infinite==tofImageRecorder->GetRecordMode(),"Test for get/set the record mode");

  mitk::ToFCameraDevice* testDevice = NULL;
  tofImageRecorder->SetCameraDevice(testDevice);
  MITK_TEST_CONDITION_REQUIRED(testDevice == tofImageRecorder->GetCameraDevice(),"Test for get/set the camera device");


  tofImageRecorder->SetToFImageType(mitk::ToFImageWriter::ToFImageType2DPlusT);
  MITK_TEST_CONDITION_REQUIRED(mitk::ToFImageWriter::ToFImageType2DPlusT==tofImageRecorder->GetToFImageType(), "Testing set/get ToFImageType");

  tofImageRecorder->SetToFImageType(mitk::ToFImageWriter::ToFImageType3D);
  MITK_TEST_CONDITION_REQUIRED(mitk::ToFImageWriter::ToFImageType3D==tofImageRecorder->GetToFImageType(), "Testing set/get ToFImageType");



  MITK_TEST_OUTPUT(<< "Test recording");

  tofImageRecorder = mitk::ToFImageRecorder::New();
  std::string dirName = MITK_TOF_DATA_DIR;
  mitk::ToFCameraMITKPlayerDevice::Pointer tofCameraMITKPlayerDevice = mitk::ToFCameraMITKPlayerDevice::New();
  tofImageRecorder->SetCameraDevice(tofCameraMITKPlayerDevice);
  MITK_TEST_CONDITION_REQUIRED(tofCameraMITKPlayerDevice == tofImageRecorder->GetCameraDevice(), "Testing set/get CameraDevice with ToFCameraPlayerDevice");

  std::string distanceFileName = dirName + "/PMDCamCube2_MF0_IT0_20Images_DistanceImage.pic";
  std::string amplitudeFileName = dirName + "/PMDCamCube2_MF0_IT0_20Images_AmplitudeImage.pic";
  std::string intensityFileName = dirName + "/PMDCamCube2_MF0_IT0_20Images_IntensityImage.pic";

  tofCameraMITKPlayerDevice->SetProperty("DistanceImageFileName",mitk::StringProperty::New(distanceFileName));
  tofCameraMITKPlayerDevice->SetProperty("AmplitudeImageFileName",mitk::StringProperty::New(amplitudeFileName));
  tofCameraMITKPlayerDevice->SetProperty("IntensityImageFileName",mitk::StringProperty::New(intensityFileName));

  MITK_TEST_OUTPUT(<< "Test ConnectCamera()");
  tofCameraMITKPlayerDevice->ConnectCamera();
  MITK_TEST_OUTPUT(<< "Test StartCamera()");
  tofCameraMITKPlayerDevice->StartCamera();

  std::string distanceTestFileName = dirName + "test_distance.nrrd";
  std::string amplitudeTestFileName = dirName + "test_amplitude.nrrd";
  std::string intensityTestFileName = dirName + "test_intensity.nrrd";

  tofImageRecorder->SetDistanceImageFileName(distanceTestFileName);
  MITK_TEST_CONDITION_REQUIRED(tofImageRecorder->GetDistanceImageFileName() == distanceTestFileName, "Testing Set/GetDistanceImageFileName()");
  tofImageRecorder->SetAmplitudeImageFileName(amplitudeTestFileName);
  MITK_TEST_CONDITION_REQUIRED(tofImageRecorder->GetAmplitudeImageFileName() == amplitudeTestFileName, "Testing Set/GetAmplitudeImageFileName()");
  tofImageRecorder->SetIntensityImageFileName(intensityTestFileName);
  MITK_TEST_CONDITION_REQUIRED(tofImageRecorder->GetIntensityImageFileName() == intensityTestFileName, "Testing Set/GetIntensityImageFileName()");
  tofImageRecorder->SetRecordMode(mitk::ToFImageRecorder::PerFrames);
  MITK_TEST_CONDITION_REQUIRED(tofImageRecorder->GetRecordMode() == mitk::ToFImageRecorder::PerFrames, "Testing Set/GetRecordMode()");
  tofImageRecorder->SetNumOfFrames(20);
  MITK_TEST_CONDITION_REQUIRED(tofImageRecorder->GetNumOfFrames() == 20, "Testing Set/GetNumOfFrames()");
  tofImageRecorder->SetFileFormat(".nrrd");
  MITK_TEST_OUTPUT(<< "Test StartRecording()");
  tofImageRecorder->StartRecording();
  tofImageRecorder->WaitForThreadBeingTerminated(); // wait to allow recording
  MITK_TEST_OUTPUT(<< "Test StopRecording()");
  tofImageRecorder->StopRecording();

  MITK_TEST_OUTPUT(<< "Test StopCamera()");
  tofCameraMITKPlayerDevice->StopCamera();
  MITK_TEST_OUTPUT(<< "Test DisconnectCamera()");
  tofCameraMITKPlayerDevice->DisconnectCamera();

  // Load images (recorded and original ones) with PicFileReader for comparison
  mitk::ItkImageFileReader::Pointer nrrdReader = mitk::ItkImageFileReader::New();
  mitk::PicFileReader::Pointer picFileReader = mitk::PicFileReader::New();
  mitk::Image::Pointer originalImage = NULL;
  mitk::Image::Pointer recordedImage = NULL;
  
  MITK_TEST_OUTPUT(<< "Read original distance image using PicFileReader");
  picFileReader->SetFileName(distanceFileName);
  picFileReader->Update();
  originalImage = picFileReader->GetOutput()->Clone();

  MITK_TEST_OUTPUT(<< "Read recorded distance image using ItkImageFileReader");
  nrrdReader->SetFileName(distanceTestFileName);
  nrrdReader->Update();
  recordedImage = nrrdReader->GetOutput()->Clone();

  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(0) == tofImageRecorder->GetToFCaptureWidth(), "Testing capture width");
  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(1) == tofImageRecorder->GetToFCaptureHeight(), "Testing capture height");
  int numFramesOrig = originalImage->GetDimension(2);
  int numFramesRec = recordedImage->GetDimension(2);
  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(2) == recordedImage->GetDimension(2), "Testing number of frames");

  MITK_TEST_CONDITION_REQUIRED(CompareImages(originalImage, recordedImage), "Compare original and saved distance image");


  MITK_TEST_OUTPUT(<< "Read original amplitude image using PicFileReader");
  picFileReader->SetFileName(amplitudeFileName);
  picFileReader->Update();
  originalImage = picFileReader->GetOutput()->Clone();

  MITK_TEST_OUTPUT(<< "Read recorded amplitude image using ItkImageFileReader");
  nrrdReader->SetFileName(amplitudeTestFileName);
  nrrdReader->Update();
  recordedImage = nrrdReader->GetOutput()->Clone();

  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(0) == tofImageRecorder->GetToFCaptureWidth(), "Testing capture width");
  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(1) == tofImageRecorder->GetToFCaptureHeight(), "Testing capture height");
  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(2) == recordedImage->GetDimension(2), "Testing number of frames");

  MITK_TEST_CONDITION_REQUIRED(CompareImages(originalImage, recordedImage), "Compare original and saved amplitude image");


  MITK_TEST_OUTPUT(<< "Read original intensity image using PicFileReader");
  picFileReader->SetFileName(intensityFileName);
  picFileReader->Update();
  originalImage = picFileReader->GetOutput()->Clone();

  MITK_TEST_OUTPUT(<< "Read recorded intensity image using ItkImageFileReader");
  nrrdReader->SetFileName(intensityTestFileName);
  nrrdReader->Update();
  recordedImage = nrrdReader->GetOutput()->Clone();

  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(0) == tofImageRecorder->GetToFCaptureWidth(), "Testing capture width");
  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(1) == tofImageRecorder->GetToFCaptureHeight(), "Testing capture height");
  MITK_TEST_CONDITION_REQUIRED(originalImage->GetDimension(2) == recordedImage->GetDimension(2), "Testing number of frames");

  MITK_TEST_CONDITION_REQUIRED(CompareImages(originalImage, recordedImage), "Compare original and saved intensity image");

  //clean up and delete saved image files
  if( remove( distanceTestFileName.c_str() ) != 0 )
  {
    MITK_ERROR<<"File: test_distance.nrrd not successfully deleted!";
  }
  if( remove( amplitudeTestFileName.c_str() ) != 0 )
  {
    MITK_ERROR<<"File: test_amplitude.nrrd not successfully deleted!";
  }
  if( remove( intensityTestFileName.c_str() ) != 0 )
  {
    MITK_ERROR<<"File: test_intensity.nrrd not successfully deleted!";
  }

  MITK_TEST_END();
}
コード例 #20
0
int mitkToFCompositeFilterTest(int /* argc */, char* /*argv*/[])
{
  MITK_TEST_BEGIN("ToFCompositeFilter");

  //initialize composite filter
  mitk::ToFCompositeFilter::Pointer compositeFilter = mitk::ToFCompositeFilter::New();

  //Initialize threshold filter
  ThresholdFilterType::Pointer thresholdFilter = ThresholdFilterType::New();
  int threshold_min = 5;
  int threshold_max = 100;
  thresholdFilter->SetOutsideValue(0.0);
  thresholdFilter->SetLower(threshold_min);
  thresholdFilter->SetUpper(threshold_max);
  compositeFilter->SetThresholdFilterParameter(threshold_min, threshold_max);

  //Initialize spatial median filter
  MedianFilterType::Pointer medianFilter = MedianFilterType::New();

  //Initialize bilateral filter
  BilateralImageFilterType::Pointer bilateralFilter = BilateralImageFilterType::New();
  float domainSigma = 4;
  float rangeSigma = 50;
  float kernelRadius = 3;
  bilateralFilter->SetDomainSigma(domainSigma);
  bilateralFilter->SetRangeSigma(rangeSigma);
  bilateralFilter->SetRadius(kernelRadius);
  compositeFilter->SetBilateralFilterParameter(domainSigma,rangeSigma,kernelRadius);

  //Initialize pipeline
  ItkImageType_2D::Pointer itkInputImage = ItkImageType_2D::New();
  mitk::Image::Pointer mitkInputImage = mitk::Image::New();
  CreateRandomDistanceImage(100,100,itkInputImage,mitkInputImage);
  ItkImageType_2D::Pointer itkOutputImage;
  compositeFilter->SetInput(mitkInputImage);
  mitk::Image::Pointer mitkOutputImage = compositeFilter->GetOutput();


  //-------------------------------------------------------------------------------------------------------

  //Apply first filter only (threshold)

  //standard variant
  thresholdFilter->SetInput(itkInputImage);
  itkOutputImage = thresholdFilter->GetOutput();
  itkOutputImage->Update();

  //variant with composite filter
  compositeFilter->SetApplyThresholdFilter(true);
  compositeFilter->SetApplyMedianFilter(false);
  compositeFilter->SetApplyTemporalMedianFilter(false);
  compositeFilter->SetApplyBilateralFilter(false);
  mitkOutputImage->Update();

  //compare output
  mitk::Image::Pointer itkOutputImageConverted;
  mitk::CastToMitkImage(itkOutputImage,itkOutputImageConverted);

  bool pipelineSuccess = CompareImages(itkOutputImageConverted,mitkOutputImage);
  MITK_TEST_CONDITION_REQUIRED(pipelineSuccess,"Test threshold filter in pipeline");

  //-------------------------------------------------------------------------------------------------------

  //Apply first and second filter

  //standard variant
  medianFilter->SetInput(thresholdFilter->GetOutput());
  itkOutputImage = medianFilter->GetOutput();
  itkOutputImage->Update();

  //variant with composite filter
  compositeFilter->SetApplyMedianFilter(true);
  mitkOutputImage->Update();

  //compare output
  mitk::CastToMitkImage(itkOutputImage,itkOutputImageConverted);

  pipelineSuccess = CompareImages(itkOutputImageConverted,mitkOutputImage);
  MITK_TEST_CONDITION_REQUIRED(pipelineSuccess,"Test threshold and median filter in pipeline");


  //-------------------------------------------------------------------------------------------------------

  //Apply first three filters

  //standard variant
  bilateralFilter->SetInput(medianFilter->GetOutput());
  itkOutputImage = bilateralFilter->GetOutput();
  itkOutputImage->Update();

  //variant with composite filter
  compositeFilter->SetApplyBilateralFilter(true);
  mitkOutputImage->Update();

  //compare output
  mitk::CastToMitkImage(itkOutputImage,itkOutputImageConverted);

  pipelineSuccess = CompareImages(itkOutputImageConverted,mitkOutputImage);
  MITK_TEST_CONDITION_REQUIRED(pipelineSuccess,"Test threshold filter, bilateral filter and temporal median filter in pipeline");


  //-------------------------------------------------------------------------------------------------------

  //Apply all filters

  //generate image stack
  ItkImageType_3D::Pointer itkInputImage3D = ItkImageType_3D::New();
  mitk::Image::Pointer mitkImage3D = mitk::Image::New();
  CreateRandomDistanceImageStack(100,100,12,itkInputImage3D,mitkImage3D);

  //standard variant
  ItkImageType_2D::Pointer medianFilteredImage = ItkImageType_2D::New();
  ApplyTemporalMedianFilter(mitkImage3D,medianFilteredImage);
  thresholdFilter->SetInput(medianFilteredImage);
  itkOutputImage->Update();

  //variant with composite filter
  compositeFilter->SetApplyTemporalMedianFilter(true);
  mitkOutputImage->Update();

  //compare output
  mitk::CastToMitkImage(itkOutputImage,itkOutputImageConverted);
  pipelineSuccess = CompareImages(itkOutputImageConverted,mitkOutputImage);
  MITK_TEST_CONDITION_REQUIRED(pipelineSuccess,"Test all filters in pipeline");


//-------------------------------------------------------------------------------------------------------

  //Check set/get functions
  mitk::Image::Pointer newImage = mitk::Image::New();
  mitk::Image::Pointer returnedImage;
  compositeFilter->SetInput(newImage);
  returnedImage = compositeFilter->GetInput();
  MITK_TEST_CONDITION_REQUIRED(newImage == returnedImage,"Get/Set empty image");

  compositeFilter->SetApplyTemporalMedianFilter(false);
  MITK_TEST_CONDITION_REQUIRED(compositeFilter->GetApplyTemporalMedianFilter()==false,"Get/Set ApplyTemporalMedianFilter");

  compositeFilter->SetApplyMedianFilter(false);
  MITK_TEST_CONDITION_REQUIRED(compositeFilter->GetApplyMedianFilter()==false,"Get/Set ApplyMedianFilter");

  compositeFilter->SetApplyThresholdFilter(false);
  MITK_TEST_CONDITION_REQUIRED(compositeFilter->GetApplyThresholdFilter()==false,"Get/Set ApplyThresholdFilter");

  compositeFilter->SetApplyBilateralFilter(false);
  MITK_TEST_CONDITION_REQUIRED(compositeFilter->GetApplyBilateralFilter()==false,"Get/Set ApplyBilateralFilter");

//-------------------------------------------------------------------------------------------------------

  MITK_TEST_END();

}
コード例 #21
0
//----------------------------------------------------------------------------
void medPipePolylineGraphEditorTest::TestPipeExecution()
//----------------------------------------------------------------------------
{
    ///////////////// render stuff /////////////////////////

    m_Renderer->SetBackground(0.1, 0.1, 0.1);
    m_RenderWindow->AddRenderer(m_Renderer);
    m_RenderWindow->SetSize(320, 240);
    m_RenderWindow->SetPosition(400,0);

    m_RenderWindowInteractor->SetRenderWindow(m_RenderWindow);

    ///////////// end render stuff /////////////////////////


    ////// Create VME ////////////////////

    CreateExamplePolydata();

    vtkMAFSmartPointer<vtkDoubleArray> scalars;
    scalars->SetName("SCALARS");

    int nPoints = m_Polydata->GetNumberOfPoints();
    for (int i=0; i<nPoints; i++)
    {
        scalars->InsertNextTuple1(0.0);
    }

    m_Polydata->GetPointData()->AddArray(scalars);
    m_Polydata->GetPointData()->SetActiveScalars("SCALARS");
    m_Polydata->Update();

    vtkMAFSmartPointer<vtkSphereSource> sphere;
    sphere->SetRadius(0.5);
    sphere->Update();
    vtkMAFSmartPointer<vtkGlyph3D> glyph;
    glyph->SetInput(m_Polydata);
    glyph->SetSource(sphere->GetOutput());
    glyph->SetScaleModeToDataScalingOff();//without this with a scalar value equal to 0 the sphere disappears
    glyph->Update();

    vtkMAFSmartPointer<vtkTubeFilter> tube;
    tube->SetInput(m_Polydata);
    tube->SetRadius(0.2);
    tube->Update();

    int n = glyph->GetOutput()->GetNumberOfPoints();
    vtkMAFSmartPointer<vtkAppendPolyData> append;
    append->SetInput(glyph->GetOutput());
    append->AddInput(tube->GetOutput());
    append->Update();

    mafSmartPointer<medVMEPolylineEditor> surface;
    surface->SetData(append->GetOutput(),0.0);
    surface->GetOutput()->Update();
    surface->Update();

    //Assembly will be create when instancing mafSceneNode
    mafSceneNode *sceneNode;
    sceneNode = new mafSceneNode(NULL,NULL,surface, NULL);

    /////////// Pipe Instance and Creation ///////////
    medPipePolylineGraphEditor *pipe = new medPipePolylineGraphEditor;
    pipe->Create(sceneNode);
    pipe->m_RenFront = m_Renderer;

    ////////// ACTORS List ///////////////
    vtkPropCollection *actorList = vtkPropCollection::New();
    pipe->GetAssemblyFront()->GetActors(actorList);

    const char *strings[NUMBER_OF_TEST];
    strings[0] = "BASE_TEST";
    strings[1] = "SELECT_TEST";
    strings[2] = "CUT_TEST";

    for(int i=0; i<NUMBER_OF_TEST; i++)
    {
        if(i == BASE_TEST)
        {
            actorList->InitTraversal();
            vtkProp *actor = actorList->GetNextProp();
            while(actor)
            {
                m_Renderer->AddVolume(actor);
                m_RenderWindow->Render();

                actor = actorList->GetNextProp();
            }

        }
        else if(i == SELECT_TEST)
        {

            vtkMAFSmartPointer<vtkDoubleArray> scalars;
            scalars->SetName("SCALARS");

            int nPoints = m_Polydata->GetNumberOfPoints();
            for (int i=0; i<nPoints; i++)
            {

                if (i == 0)//Select the 0th point
                {
                    scalars->InsertNextTuple1((double)1.0);
                }
                else
                {
                    scalars->InsertNextTuple1((double)0.0);
                }

            }

            m_Polydata->GetPointData()->AddArray(scalars);
            m_Polydata->GetPointData()->SetActiveScalars("SCALARS");
            m_Polydata->Update();

            vtkMAFSmartPointer<vtkSphereSource> sphere;
            sphere->SetRadius(0.5);
            sphere->Update();
            vtkMAFSmartPointer<vtkGlyph3D> glyph;
            glyph->SetInput(m_Polydata);
            glyph->SetSource(sphere->GetOutput());
            glyph->SetScaleModeToDataScalingOff();//without this with a scalar value equal to 0 the sphere disappears
            glyph->Update();

            surface->SetData(glyph->GetOutput(),0.0);
            surface->GetOutput()->Update();
            surface->Update();

            actorList->InitTraversal();
            vtkProp *actor = actorList->GetNextProp();
            while(actor)
            {
                m_Renderer->AddVolume(actor);
                m_RenderWindow->Render();

                actor = actorList->GetNextProp();
            }

        }
        else if(i == CUT_TEST)
        {

            vtkMAFSmartPointer<vtkDoubleArray> scalars;
            scalars->SetName("SCALARS");

            int nPoints = m_Polydata->GetNumberOfPoints();
            for (int i=0; i<nPoints; i++)
            {
                scalars->InsertNextTuple1((double)0.0);
            }

            m_Polydata->GetPointData()->AddArray(scalars);
            m_Polydata->GetPointData()->SetActiveScalars("SCALARS");
            m_Polydata->Update();

            vtkMAFSmartPointer<vtkTubeFilter> tube;
            tube->SetInput(m_Polydata);
            tube->SetRadius(0.5);
            tube->Update();

            surface->SetData(tube->GetOutput(),0.0);
            surface->GetOutput()->Update();
            surface->Update();

            double origin[3] = {5,2,0};
            double normal[3] = {0,0,1};
            pipe->SetSlice(origin,normal);
            pipe->SetModalitySlice();

            actorList->InitTraversal();
            vtkProp *actor = actorList->GetNextProp();
            while(actor)
            {
                m_Renderer->AddVolume(actor);
                m_RenderWindow->Render();

                actor = actorList->GetNextProp();
            }

        }

        vtkActor *surfaceActor;
        surfaceActor = (vtkActor *) SelectActorToControl(actorList, 0);
        CPPUNIT_ASSERT(surfaceActor != NULL);

        m_Renderer->ResetCamera();
        m_RenderWindow->Render();
        printf("\n Visualizzazione: %s \n", strings[i]);
        mafSleep(800);
        CompareImages(i);

    }


    vtkDEL(actorList);

    delete pipe;
    delete sceneNode;

    delete wxLog::SetActiveTarget(NULL);
}