Exemplo n.º 1
0
chd_file *ldplayer_state::get_disc(laserdisc_device &device)
{
	bool found = false;
	// open a path to the ROMs and find the first CHD file
	file_enumerator path(machine().options().media_path());

	// iterate while we get new objects
	const osd::directory::entry *dir;
	while ((dir = path.next()) != NULL)
	{
		int length = strlen(dir->name);

		// look for files ending in .chd
		if (length > 4 &&
			dir->name[length - 4] == '.' &&
			tolower(dir->name[length - 3]) == 'c' &&
			tolower(dir->name[length - 2]) == 'h' &&
			tolower(dir->name[length - 1]) == 'd')
		{
			// open the file itself via our search path
			emu_file image_file(machine().options().media_path(), OPEN_FLAG_READ);
			osd_file::error filerr = image_file.open(dir->name);
			if (filerr == osd_file::error::NONE)
			{
				std::string fullpath(image_file.fullpath());
				image_file.close();

				// try to open the CHD

				if (machine().rom_load().set_disk_handle("laserdisc", fullpath.c_str()) == CHDERR_NONE)
				{
					m_filename.assign(dir->name);
					found = true;
					break;
				}
			}
		}
	}

	// if we failed, pop a message and exit
	if (found == false) {
		machine().ui().popup_time(10, "No valid image file found!\n");
		return nullptr;
	}

	return machine().rom_load().get_disk_handle("laserdisc");
}
Exemplo n.º 2
0
chd_file *ldplayer_state::get_disc()
{
	bool found = FALSE;
	// open a path to the ROMs and find the first CHD file
	file_enumerator path(machine().options().media_path());

	// iterate while we get new objects
	const osd_directory_entry *dir;
	while ((dir = path.next()) != NULL)
	{
		int length = strlen(dir->name);

		// look for files ending in .chd
		if (length > 4 &&
			dir->name[length - 4] == '.' &&
			tolower(dir->name[length - 3]) == 'c' &&
			tolower(dir->name[length - 2]) == 'h' &&
			tolower(dir->name[length - 1]) == 'd')
		{
			// open the file itself via our search path
			emu_file image_file(machine().options().media_path(), OPEN_FLAG_READ);
			file_error filerr = image_file.open(dir->name);
			if (filerr == FILERR_NONE)
			{
				astring fullpath(image_file.fullpath());
				image_file.close();

				// try to open the CHD

				if (set_disk_handle(machine(), "laserdisc", fullpath) == CHDERR_NONE)
				{
					m_filename.cpy(dir->name);
					found = TRUE;
					break;
				}
			}
		}
	}

	// if we failed, pop a message and exit
	if (found == FALSE)
		throw emu_fatalerror("No valid image file found!\n");

	return get_disk_handle(machine(), "laserdisc");
}
bool ImageCanvas::LoadObject(const QString & session, const QString & cam, const QString & img, const double & ux,
		const double & uy) {
	if ((current_session == session) && (current_cam == cam) && (current_img == img)) {
		CenterOnWorldPosition(ux, uy, 1.0);
		return true;
	}

	UnloadObject();

	QFileInfo image_file(db->GetImageLocation(session, cam, img));
	if(!image_file.isFile() || !image_file.isReadable())
		return false;

	image_layer = new QgsRasterLayer(image_file.filePath(),image_file.fileName());
	connect(image_layer,SIGNAL(progressUpdate(int)),this,SLOT(ShowProgress(int)));
	image_layer->setLayerName("image");
    image_provider = image_layer->dataProvider();
    if (!image_layer->isValid())
    	return false;

    QgsContrastEnhancement* qgsContrastEnhRed = new QgsContrastEnhancement(QGis::UInt16);
    QgsContrastEnhancement* qgsContrastEnhGreen = new QgsContrastEnhancement(QGis::UInt16);
    QgsContrastEnhancement* qgsContrastEnhBlue = new QgsContrastEnhancement(QGis::UInt16);

    QgsMultiBandColorRenderer* renderer = new QgsMultiBandColorRenderer( image_provider, 1, 2, 3,
                qgsContrastEnhRed, qgsContrastEnhGreen, qgsContrastEnhBlue);

    image_layer->setRenderer( renderer );

    layer_registry->addMapLayer(image_layer);

    QList<QgsMapCanvasLayer> layer_set;
    layer_set.append(image_layer);
	setLayerSet(layer_set);

	CenterOnWorldPosition(ux, uy, 1.0);

	current_session = session;
	current_cam = cam;
	current_img = img;

	return true;
}
Exemplo n.º 4
0
chd_file *ldplayer_state::get_disc()
{
	// open a path to the ROMs and find the first CHD file
	file_enumerator path(machine().options().media_path());

	// iterate while we get new objects
	const osd_directory_entry *dir;
	while ((dir = path.next()) != NULL)
	{
		int length = strlen(dir->name);

		// look for files ending in .chd
		if (length > 4 &&
			dir->name[length - 4] == '.' &&
			tolower(dir->name[length - 3]) == 'c' &&
			tolower(dir->name[length - 2]) == 'h' &&
			tolower(dir->name[length - 1]) == 'd')
		{
			// open the file itself via our search path
			emu_file image_file(machine().options().media_path(), OPEN_FLAG_READ);
			file_error filerr = image_file.open(dir->name);
			if (filerr == FILERR_NONE)
			{
				astring fullpath(image_file->fullpath();
				image_file.close();

				// try to open the CHD

				if (set_disk_handle(machine(), "laserdisc", fullpath) == CHDERR_NONE)
				{
					m_filename.cpy(dir->name);
					break;
				}
			}

			// close the file on failure
			auto_free(machine(), image_file);
			image_file = NULL;
		}
Exemplo n.º 5
0
int open_disk_image(emu_options &options, const game_driver *gamedrv, const rom_entry *romp, chd_file &image_chd, const char *locationtag)
{
	emu_file image_file(options.media_path(), OPEN_FLAG_READ);
	const rom_entry *region, *rom;
	file_error filerr;
	chd_error err;

	/* attempt to open the properly named file, scanning up through parent directories */
	filerr = FILERR_NOT_FOUND;
	for (int searchdrv = driver_list::find(*gamedrv); searchdrv != -1 && filerr != FILERR_NONE; searchdrv = driver_list::clone(searchdrv))
		filerr = common_process_file(options, driver_list::driver(searchdrv).name, ".chd", romp, image_file);

	if (filerr != FILERR_NONE)
		filerr = common_process_file(options, NULL, ".chd", romp, image_file);

	/* look for the disk in the locationtag too */
	if (filerr != FILERR_NONE && locationtag != NULL)
	{
		// check if we are dealing with softwarelists. if so, locationtag
		// is actually a concatenation of: listname + setname + parentname
		// separated by '%' (parentname being present only for clones)
		astring tag1(locationtag), tag2, tag3, tag4, tag5;
		bool is_list = FALSE;
		bool has_parent = FALSE;

		int separator1 = tag1.chr(0, '%');
		if (separator1 != -1)
		{
			is_list = TRUE;

			// we are loading through softlists, split the listname from the regiontag
			tag4.cpysubstr(tag1, separator1 + 1, tag1.len() - separator1 + 1);
			tag1.del(separator1, tag1.len() - separator1);
			tag1.cat(PATH_SEPARATOR);

			// check if we are loading a clone (if this is the case also tag1 have a separator '%')
			int separator2 = tag4.chr(0, '%');
			if (separator2 != -1)
			{
				has_parent = TRUE;

				// we are loading a clone through softlists, split the setname from the parentname
				tag5.cpysubstr(tag4, separator2 + 1, tag4.len() - separator2 + 1);
				tag4.del(separator2, tag4.len() - separator2);
			}

			// prepare locations where we have to load from: list/parentname (if any) & list/clonename
			astring swlist(tag1.cstr());
			tag2.cpy(swlist.cat(tag4));
			if (has_parent)
			{
				swlist.cpy(tag1);
				tag3.cpy(swlist.cat(tag5));
			}
		}

		if (tag5.chr(0, '%') != -1)
			fatalerror("We do not support clones of clones!\n");

		// try to load from the available location(s):
		// - if we are not using lists, we have locationtag only;
		// - if we are using lists, we have: list/clonename, list/parentname, clonename, parentname
		if (!is_list)
			filerr = common_process_file(options, locationtag, ".chd", romp, image_file);
		else
		{
			// try to load from list/setname
			if ((filerr != FILERR_NONE) && (tag2.cstr() != NULL))
				filerr = common_process_file(options, tag2.cstr(), ".chd", romp, image_file);
			// try to load from list/parentname (if any)
			if ((filerr != FILERR_NONE) && has_parent && (tag3.cstr() != NULL))
				filerr = common_process_file(options, tag3.cstr(), ".chd", romp, image_file);
			// try to load from setname
			if ((filerr != FILERR_NONE) && (tag4.cstr() != NULL))
				filerr = common_process_file(options, tag4.cstr(), ".chd", romp, image_file);
			// try to load from parentname (if any)
			if ((filerr != FILERR_NONE) && has_parent && (tag5.cstr() != NULL))
				filerr = common_process_file(options, tag5.cstr(), ".chd", romp, image_file);
			// only for CHD we also try to load from list/
			if ((filerr != FILERR_NONE) && (tag1.cstr() != NULL))
			{
				tag1.del(tag1.len() - 1, 1);    // remove the PATH_SEPARATOR
				filerr = common_process_file(options, tag1.cstr(), ".chd", romp, image_file);
			}
		}
	}

	/* did the file open succeed? */
	if (filerr == FILERR_NONE)
	{
		astring fullpath(image_file.fullpath());
		image_file.close();

		/* try to open the CHD */
		err = image_chd.open(fullpath);
		if (err == CHDERR_NONE)
			return err;
	}
	else
		err = CHDERR_FILE_NOT_FOUND;

	/* otherwise, look at our parents for a CHD with an identical checksum */
	/* and try to open that */
	hash_collection romphashes(ROM_GETHASHDATA(romp));
	for (int drv = driver_list::find(*gamedrv); drv != -1; drv = driver_list::clone(drv))
	{
		machine_config config(driver_list::driver(drv), options);
		device_iterator deviter(config.root_device());
		for (device_t *device = deviter.first(); device != NULL; device = deviter.next())
			for (region = rom_first_region(*device); region != NULL; region = rom_next_region(region))
				if (ROMREGION_ISDISKDATA(region))
					for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom))

						/* look for a differing name but with the same hash data */
						if (strcmp(ROM_GETNAME(romp), ROM_GETNAME(rom)) != 0 &&
							romphashes == hash_collection(ROM_GETHASHDATA(rom)))
						{
							/* attempt to open the properly named file, scanning up through parent directories */
							filerr = FILERR_NOT_FOUND;
							for (int searchdrv = drv; searchdrv != -1 && filerr != FILERR_NONE; searchdrv = driver_list::clone(searchdrv))
								filerr = common_process_file(options, driver_list::driver(searchdrv).name, ".chd", rom, image_file);

							if (filerr != FILERR_NONE)
								filerr = common_process_file(options, NULL, ".chd", rom, image_file);

							/* did the file open succeed? */
							if (filerr == FILERR_NONE)
							{
								astring fullpath(image_file.fullpath());
								image_file.close();

								/* try to open the CHD */
								err = image_chd.open(fullpath);
								if (err == CHDERR_NONE)
									return err;
							}
						}
	}
	return err;
}
Exemplo n.º 6
0
int main() {
  CGAL::Image_3 image(_createImage(2, 2, 2, 1,
				   1., 1., 1.,
				   1, WK_FIXED, SGN_UNSIGNED));
  
  Word data[8] = { 0, 0, 0, 0, 0, 0, 0, 0};

  ImageIO_free(image.data());
  image.set_data(&data[0]);

  std::cerr << std::setprecision(2) << std::fixed;

  const Word c_value = 100;

  for(int x = 0; x <= 1; ++x)
    for(int y = 0; y <= 1; ++y)
      for(int z = 0; z <= 1; ++z)
      {
	data[z * 4 + y * 2 + x] = c_value;

	std::cerr << "#### data"
		  << "[" << x << "]"
		  << "[" << y << "]"
		  << "[" << z << "]"
		  << " = " << c_value << "\n";
	for(double d_x = 0.; d_x <= 1.; d_x += 0.499999)
	  for(double d_y = 0.; d_y <= 1.; d_y += 0.499999)
	    for(double d_z = 0.; d_z <= 1.; d_z += 0.499999)
	    {
	      assert((int)d_x == 0);
	      assert((int)d_y == 0);
	      assert((int)d_z == 0);
	      const double value = 
		image.trilinear_interpolation<Word, double, double>(d_x,
								    d_y,
								    d_z,
								    255);

	      const Word label = 
		image.labellized_trilinear_interpolation<Word,
	          double>(d_x, d_y, d_z, 255);

	      std::cerr << "val(" << d_x << ", " << d_y << " , " << d_z << ") = "
			<< value << "   -- " 
			<< "label = " << (int)label << std::endl;

	      assert((label == c_value) == (value >= 0.5 * c_value));

	      const double sq_dist = 
		(d_x - x) * (d_x - x) +
		(d_y - y) * (d_y - y) +
		(d_z - z) * (d_z - z);

	      if(sq_dist <= 0.001) {
		assert(value >= 0.9 * c_value);
		assert(label == c_value);
	      }
	      else if(sq_dist <= 0.51*0.51/2.) {
		assert(value >= 0.79 * c_value);
		assert(label == c_value);
	      }
	      else if(sq_dist <= 0.51*0.51) {
		assert(value >= 0.49 * c_value);
	      }
	      else if(sq_dist <= 2*0.51*0.51) {
		assert(value >= 0.24 * c_value);
		assert(label == 0);
	      }
	      else if(sq_dist <= 3*0.51*0.51) {
		assert(value >= 0.12 * c_value);
		assert(label == 0);
	      }
	      else {
		assert(value <= 0.001 * c_value);
		assert(label == 0);
	      }

	      const float value2 = 
		image.trilinear_interpolation<Word, float, float>(d_x,
								  d_y,
								  d_z,
								  Word(0));

	      const float value3 = triLinInterp(image.image(),
						d_x, 
						d_y,
						d_z,
						0.f);
	      std::cerr << "tri(" << d_x << ", " << d_y << " , " << d_z << ") = "
			<< value3 << std::endl;
	      if(value2 != value3)
		std::cerr << std::setprecision(30)
			  << "   " << value2 << "\n!= " << value3 << std::endl;
	      assert(value2 == value3);
	    }

	data[z * 4 + y * 2 + x] = 0;
      }

  // BENCH
  std::cerr.precision(10);

  float max_diff = 0.f;
  CGAL::Timer timer_new_implementation;
  CGAL::Timer timer_old_implementation;

  for(int image_nb = 0; image_nb < 1000; ++image_nb)
  {
    // fill the 2x2x2 image
    for(int i = 0; i < 8; ++i) {
      data[i] = CGAL::default_random.get_int(0,255);
    }

    // test the difference between the two implementations
    for(double d_x = 0.; d_x < 0.9; d_x += 0.1)
      for(double d_y = 0.; d_y < 0.9; d_y += 0.1)
	for(double d_z = 0.; d_z < 0.9; d_z += 0.1)
	{

	  const float value1 = 
	    image.trilinear_interpolation<Word, float, float>(d_x,
							      d_y,
							      d_z,
							      0);
	  const float value2 = triLinInterp(image.image(),
					    d_x, 
					    d_y,
					    d_z,
					    0.f);
	  float diff = value1 - value2;
	  if(diff < 0) {
	    diff =-diff;
	  }
	  assert(diff < 0.1f);
	  if(diff > max_diff)
	    max_diff = diff;
	}
    // bench new implementation
    float sum = 0.f;
    timer_new_implementation.start();
    for(double d_x = 0.; d_x < 0.9; d_x += 0.05)
      for(double d_y = 0.; d_y < 0.9; d_y += 0.05)
	for(double d_z = 0.; d_z < 0.9; d_z += 0.05)
	{

	  sum += 
	    image.trilinear_interpolation<Word, float, float>(d_x,
							      d_y,
							      d_z,
							      0);
	}
    timer_new_implementation.stop();

    sum = 0.f;
    timer_old_implementation.start();
    // bench old implementation    
    for(double d_x = 0.; d_x < 0.9; d_x += 0.05)
      for(double d_y = 0.; d_y < 0.9; d_y += 0.05)
	for(double d_z = 0.; d_z < 0.9; d_z += 0.05)
	{
	  sum += triLinInterp(image.image(),
			      d_x, 
			      d_y,
			      d_z,
			      0.f);
	}
    timer_old_implementation.stop();
  }
  std::cerr << "max difference = " << max_diff << "\n"
	    << "timer new implementation: " << timer_new_implementation.time()
	    << "\ntimer old implementation: " << timer_old_implementation.time()
	    << "\n";
  image.set_data(0); // trick to avoid ~Image_3 segfault.


  const char* filenames[] = {
    "../../examples/Surface_mesher/data/skull_2.9.inr",
    "../../../Surface_mesher/examples/Surface_mesher/data/skull_2.9.inr",
    "../Surface_mesher_Examples/data/skull_2.9.inr" 
  };

  std::size_t file_index = 0;
  for(   ; file_index < sizeof(filenames); ++file_index)
  {
    std::ifstream image_file(filenames[file_index], std::ios_base::binary | std::ios_base::in );
    if(image_file) {
      break;
    }
  }

  assert(file_index < sizeof(filenames) );

  std::cerr << "Opening file " << filenames[file_index] << "...\n";

  CGAL::Image_3 image2;
  const bool result = image2.read(filenames[file_index]);
  assert(result);

  std::cerr << "Image info:"
	    << "\n  dim = " 
	    << image2.xdim() << "x" << image2.ydim() << "x" << image2.zdim() 
	    << "\n  v = ( " << image2.vx() << ", " 
	    << image2.vy() << ", " << image2.vz() 
	    << " )\n";

  int counter = 0;
  for(float d_x = 0.; d_x < image2.xdim() * image.vx(); d_x += 1.f/3)
    for(float d_y = 0.; d_y < image2.ydim() * image.vy(); d_y += 3.f/5)
      for(float d_z = 0.; d_z < image2.zdim() * image.vz(); d_z += 1.f/3)
      {
	++counter;
	const float value1 = 
	  ::triLinInterp(image2.image(),
			 d_x,
			 d_y,
			 d_z,
			 0);
	const float value2 = 
	  image2.trilinear_interpolation<float, float, float>(d_x,
							      d_y,
							      d_z,
							      0);

	float diff = value2 - value1;
	if(diff < 0) diff = -diff;
	if(diff > 0.0001 )
	{
	  std::cerr.precision(20);
	  const std::size_t i1 = static_cast<std::size_t>(d_z / image2.image()->vz);
	  const std::size_t j1 = static_cast<std::size_t>(d_y / image2.image()->vy);
	  const std::size_t k1 = static_cast<std::size_t>(d_x / image2.image()->vx);

	  std::cerr << "pos = (" << d_x << ", " << d_y << ", " << d_z << ") => ("
		    << i1 << ", " << j1 << ", " << k1 << ")\n";
	  std::cerr << "value1 = " << value1
		    << "\nvalue2 = " << value2 << std::endl;

	  for(std::size_t di = 0; di < 2 ; ++di)
	    for(std::size_t dj = 0; dj < 2 ; ++dj)
	      for(std::size_t dk = 0; dk < 2 ; ++dk)
	      {
		std::cerr << "value(" << i1 + di 
			  << ", " << j1 + dj
			  << ", " << k1 + dk << ") = "
			  << image2.value(i1 + di, j1+ dj, k1 + dk) << "\n";
	      }

	  assert(false);
	}
      }
  std::cerr << counter << " tests. OK.";
}