Ejemplo n.º 1
0
CLuaImage::CLuaImage(const char *file) : CBaseLuaWidget(""), m_iImageW(0), m_iImageH(0)
{
    Fl_Shared_Image *img = Fl_Shared_Image::get(file);
    
    if (img)
    {
        if ((img->w() > MaxImageW()) || (img->h() > MaxImageH()))
        {
            int neww, newh;
            GetScaledImageSize(img->w(), img->h(), MaxImageW(), MaxImageH(), neww, newh);
            Fl_Image *temp = img->copy(neww, newh);
            img->release();
            img = (Fl_Shared_Image *)temp;
        }

        Fl_Box *imgbox = new Fl_Box(0, 0, img->w(), img->h());
        imgbox->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
        imgbox->image(img);
        GetGroup()->add(imgbox);
        
        m_iImageW = img->w();
        m_iImageH = img->h();
    }
    else
        GetGroup()->hide();
}
FltkImage * FltkImage::load(char const * filename) const {
	if (SLStringUtil::empty(filename))
		return 0;
	Fl_Shared_Image *sharedImage = Fl_Shared_Image::get(filename);
	Fl_Image * image = sharedImage->copy();
	sharedImage->release();
	if ( image->h() == 0 ) {
		delete image;
		return 0;
	}
	FltkImage * result = new FltkImage(image);
	result->setFilename(filename);
	return result;
}
Ejemplo n.º 3
0
void UserInterface::doGenJob(void* d)
{
    UserInterface* ui = static_cast<UserInterface*>(d);

    if (!ProgressDialog::isVisible())
    {
        // canceled by user
        ui->genJobs_.clear();
        ProgressDialog::close();
        ui->openMapsWindow_ = false;
    }
    else if (ui->genJobs_.empty())
    {
        if (ui->openMapsWindow_)
        {
            ProgressDialog::close();
            ui->mapsWindow_->show();
            ui->openMapsWindow_ = false;
        }
        else
        {
            // show Done for a short time
            ProgressDialog::progress(100, "Done");
            Fl::add_timeout(0.5, closeProgressDialog, d);
        }
    }
    else
    {
        float const percentage = 100*static_cast<float>(ui->genJobsCount_ - ui->genJobs_.size())/ui->genJobsCount_;
        GenJob const job = ui->genJobs_.front();
        ui->genJobs_.pop_front();
        ProgressDialog::progress(percentage, job.name_);
        Fl::check();

        try
        {
            Fl_Shared_Image * img;
            switch (job.type_)
            {
            case GEN_INFO:
                ui->cache_->getMapInfo(job.name_);
                break;

            case GEN_MAP:
                img = ui->cache_->getMapImage(job.name_);
                if (img) img->release();
                break;

            case GEN_METAL:
                img = ui->cache_->getMetalImage(job.name_);
                if (img) img->release();
                break;

            case GEN_HEIGHT:
                img = ui->cache_->getHeightImage(job.name_);
                if (img) img->release();
                break;
            }
        }
        catch (std::exception const & e)
        {
            LOG(WARNING) << e.what();
        }

        Fl::add_timeout(0.01, doGenJob, d);
    }
}
Ejemplo n.º 4
0
void OnStartCalib(class Fl_Button* b, void*)
{
	CalibUI* ui = reinterpret_cast<CalibUI*>(b->window()->user_data());
	if (ui != nullptr)
	{
		ui->calibImageBox->SetImagePoints(nullptr);
		cv::Size imageSize;
		cv::Size boardSize(static_cast<int>(ui->vertCornersInput->value()),
							static_cast<int>(ui->horizCornersInput->value()));
		
		ui->appData->imagesPoints.clear();
		ui->appData->imagesPointsMap.clear();
		ui->calibTextResult->buffer(ui->appData->resultTextBuff.get());

		ui->appData->resultTextBuff->text("Calibration in progress ...");
		ui->calibTextResult->redraw();
		Fl::wait();

		for (int i = 1; i <= ui->calibImageBrowser->size(); ++i)
		{
			Fl::wait();
			const char* fileName = ui->calibImageBrowser->text(i);
			Fl_Shared_Image *img = Fl_Shared_Image::get(fileName);
			cv::Mat mat = FLImageToMat(img);

			imageSize = mat.size();

			std::vector<cv::Point2f> pointbuf;
			bool found = cv::findChessboardCorners(mat, boardSize, pointbuf, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS);

			Fl::wait();
			cv::Mat matGray;
			cv::cvtColor(mat, matGray, CV_BGR2GRAY);
			if(found)
			{
				cv::cornerSubPix(matGray, pointbuf, cv::Size(11,11),
							cv::Size(-1,-1), cv::TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1 ));
				ui->appData->imagesPoints.push_back(pointbuf);
				ui->appData->imagesPointsMap.insert(std::make_pair(fileName, ui->appData->imagesPoints.size() - 1));
			}
			img->release();
		}

		if (!ui->appData->imagesPoints.empty())
		{
			double squareSize = ui->cellSizeInput->value();
			bool ok = runCalibration(ui->appData->imagesPoints, imageSize, boardSize, squareSize,
									ui->appData->cameraMatrix, ui->appData->distCoeffs);
			if (ok)
			{
				std::stringstream buf;
				double pixelSize = 0;
				buf << "Focal length X (pixel rel. units) : " << ui->appData->cameraMatrix.at<double>(0,0) << "\n";
				buf << "Focal length Y (pixel rel. units) : " << ui->appData->cameraMatrix.at<double>(1,1) << "\n";
				buf << "Principal point x : " << ui->appData->cameraMatrix.at<double>(0,2) << "\n";
				buf << "Principal point y : " << ui->appData->cameraMatrix.at<double>(1,2) << "\n";

				buf << "K1 : " << ui->appData->distCoeffs.at<double>(0, 0) << "\n";
				buf << "K2 : " << ui->appData->distCoeffs.at<double>(1, 0) << "\n";
				buf << "K3 : " << ui->appData->distCoeffs.at<double>(4, 0) << "\n";
				buf << "P1 : " << ui->appData->distCoeffs.at<double>(2, 0) << "\n";
				buf << "P2 : " << ui->appData->distCoeffs.at<double>(3, 0) << "\n";

				ui->appData->resultTextBuff->text(buf.str().c_str());
				OnCalibImageSelected(ui->calibImageBrowser, nullptr);
				return;
			}
		}
	}
	ui->appData->resultTextBuff->text("Calibration failed!");
}
Ejemplo n.º 5
0
int DeRotatorGraphics::load_texture(const char* fname, GLuint& tex_id)
{
  using namespace logging::trivial;
  src::severity_logger< severity_level > lg;
  
 // initialize the texture map
  glGenTextures(1, &tex_id);
  glBindTexture(GL_TEXTURE_2D, tex_id);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

  Fl_Shared_Image *image;  
  // check that the fname exists
  using namespace boost::filesystem;
  path p(fname);
  if(exists(p)){
    image = Fl_Shared_Image::get(fname);
  }
  else {
    // fname does not exist in the current directory.
    // Check whether this file exists in the Resources directory of
    // a Mac bundle
    
    #ifdef __APPLE__
      unsigned short ufname[64];
      for(int i=0; i<strlen(fname); i++){
	ufname[i] = fname[i];
      }
      CFStringRef s = CFStringCreateWithCharacters(NULL, ufname, strlen(fname));
      CFURLRef appUrlRef;
      appUrlRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), s, NULL, NULL);

      CFStringRef filePathRef = CFURLCopyPath(appUrlRef);
      const char* filePath = CFStringGetCStringPtr(filePathRef, kCFStringEncodingUTF8);

      path p1(filePath);
      if(exists(p1)){
	image = Fl_Shared_Image::get(filePath);
	CFRelease(filePathRef);
	CFRelease(appUrlRef);
      }
      else {
	LOG_ERROR << "DeRotator::load_texture(): " << filePath
		  << " does not exist\n";
	CFRelease(filePathRef);
	CFRelease(appUrlRef);	
	return -1;	
      }
      
    #endif
  }

  if(image == NULL){
    LOG_ERROR << "DeRotator::load_texture(): " << fname
	      << " has an unknown format\n";
    return -1;
  }

  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image->w(), image->h(), 0,
	       GL_RGBA, GL_UNSIGNED_BYTE, image->data()[0]);
  image->release();

  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glEnable(GL_TEXTURE_2D);

  return 0;
}