Ejemplo n.º 1
0
/**
 * @brief Calculates the curvature (divergence of normalized gradient)
 *        of the level set:
 *        @f[
 *        \kappa=
 * \Delta_x^-\left(\frac{\Delta_x^+u_{i,j}}
 * {\sqrt{\eta^2+(\Delta_x^+u_{i,j})^2+(\Delta_y^0u_{i,j})^2}}\right)+
 * \Delta_y^-\left(\frac{\Delta_y^+u_{i,j}}
 * {\sqrt{\eta^2+(\Delta_x^0u_{i,j})^2+(\Delta_y^+u_{i,j})^2}}\right)\,,
 *        @f]
 * where
 *   - @f$ \Delta_x^{\pm} @f$ and @f$ \Delta_y^{\pm} @f$ correspond to forward (@f$+@f$)
 *     and backward (@f$-@f$) difference in @f$x@f$ and @f$y@f$ direction, respectively
 *   - @f$\Delta_x^0@f$ and @f$\Delta_y^0@f$ correspond to central differences in
 *     @f$x@f$ and @f$y@f$ direction, respectively
 *   - @f$\eta@f$ is a small parameter to avoid division by zero
 *   - @f$u_{i,j}@f$ is the level set for @f$m\times n@f$ image
 * The curvature is calculated by convoluting forward, backward and central difference
 * kernels with the level set. The method assumes duplicating the pixels near the border:
 * @f[ u_{-1,j}=u_{0,j}\,,\quad u_{m,j}=u_{m-1,j}\,,\quad
 *     u_{i,-1}=u_{i,0}\,,\quad u_{i,n}=u_{n-1,j}\,. @f]
 * This method ensures that the curvature is centered at a given point and only one
 * extra pixel is needed per calculation.
 * @param u       The level set, @f$u_{i,j}@f$
 * @param h       Height of the level set matrix
 * @param w       Width of the level set matrix
 * @return Curvature
 */
cv::Mat
curvature(const cv::Mat & u,
          int h,
          int w)
{
  const double eta = 1E-8;
  const double eta2 = std::pow(eta, 2);
  cv::Mat upx (h, w, CV_64FC1), upy (h, w, CV_64FC1),
          ucx (h, w, CV_64FC1), ucy (h, w, CV_64FC1);
  cv::filter2D(u, upx, CV_64FC1, ChanVese::Kernel::fwd_x, cv::Point(-1, -1), 0, cv::BORDER_REPLICATE);
  cv::filter2D(u, upy, CV_64FC1, ChanVese::Kernel::fwd_y, cv::Point(-1, -1), 0, cv::BORDER_REPLICATE);
  cv::filter2D(u, ucx, CV_64FC1, ChanVese::Kernel::ctr_x, cv::Point(-1, -1), 0, cv::BORDER_REPLICATE);
  cv::filter2D(u, ucy, CV_64FC1, ChanVese::Kernel::ctr_y, cv::Point(-1, -1), 0, cv::BORDER_REPLICATE);

  double * const upx_ptr = reinterpret_cast<double *>(upx.data);
  double * const upy_ptr = reinterpret_cast<double *>(upy.data);
  const double * const ucx_ptr = reinterpret_cast<double *>(ucx.data);
  const double * const ucy_ptr = reinterpret_cast<double *>(ucy.data);

#pragma omp parallel for num_threads(NUM_THREADS)
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j)
      {
        upx_ptr[i * w + j] = upx_ptr[i * w + j] /
                             std::sqrt(std::pow(upx_ptr[i * w + j], 2) + std::pow(ucx_ptr[i * w + j], 2) + eta2);
        upy_ptr[i * w + j] = upy_ptr[i * w + j] /
                             std::sqrt(std::pow(upy_ptr[i * w + j], 2) + std::pow(ucy_ptr[i * w + j], 2) + eta2);
      }

  cv::filter2D(upx, upx, CV_64FC1, ChanVese::Kernel::bwd_x, cv::Point(-1, -1), 0, cv::BORDER_REPLICATE);
  cv::filter2D(upy, upy, CV_64FC1, ChanVese::Kernel::bwd_y, cv::Point(-1, -1), 0, cv::BORDER_REPLICATE);
  upx += upy;
  return upx;
}
Ejemplo n.º 2
0
void XSettingsModel::load_last_profile(QString profile)
{
	_loading = true;
	
	QString filename = profile;
	QSettings settings(filename,QSettings::IniFormat);
	
	outLog("*** FGx loading last used profile:"+filename);
	
	bool ena;
	for(int row_idx=0; row_idx < rowCount(); row_idx++){
		//= loop rows and load each "option" as an [ini section] with enabled, value as values
		settings.beginGroup(item(row_idx, C_OPTION)->text());
		ena = settings.value("enabled").toBool() ;
		item(row_idx, C_ENABLED)->setText( ena ? "1" : "0");
		QString val = settings.value("value").toString();
		if(val == ""){
			val = item(row_idx, C_DEFAULT)->text();
		}
		item(row_idx, C_VALUE)->setText(val );
		set_row_bg(row_idx, ena ? QColor(200,255,200) : QColor(240,240,240));
		//= Broadcast changes
		emit upx(item(row_idx, C_OPTION)->text(),
				 item(row_idx, C_ENABLED)->text() == "1",
				 item(row_idx, C_VALUE)->text()
				 );
		settings.endGroup();
	}
	_loading = false;
	emit updated(get_fgfs_list());
	
}
Ejemplo n.º 3
0
bool XSettingsModel::load_profile()
{
	_loading = true;
    // get lastused profile name
    QString previous = getLastUsed();   // or default if none

#ifdef USE_ALTERNATE_GETFILE
    QString filename = util_getFileName(0,  "Load Profiles",  previous, QStringList("*.ini") );
#else // !#ifdef USE_ALTERNATE_GETFILE
    QString filename = QFileDialog::getOpenFileName(0,  "Load Profiles",  previous, "Profile files (*.ini)" );
#endif // #ifdef USE_ALTERNATE_GETFILE y/n

    QFile file;
    if ((filename.length() == 0) || (!file.exists(filename))) {
        outLog("*** Profile load abandonned!");
        _loading = false;
        return false;   // NO LOAD POSSIBLE
    }

	QSettings settings(filename,QSettings::IniFormat);
	
	bool ena;
	for(int row_idx=0; row_idx < rowCount(); row_idx++){
		//= loop rows and load each "option" as an [ini section] with enabled, value as values
		settings.beginGroup(item(row_idx, C_OPTION)->text());
		ena = settings.value("enabled").toBool() ;
		item(row_idx, C_ENABLED)->setText( ena ? "1" : "0");
		QString val = settings.value("value").toString();
		if(val == ""){
			val = item(row_idx, C_DEFAULT)->text();
		}
		item(row_idx, C_VALUE)->setText(val );
		set_row_bg(row_idx, ena ? QColor(200,255,200) : QColor(240,240,240));
		//= Broadcast changes
		emit upx(item(row_idx, C_OPTION)->text(),
				 item(row_idx, C_ENABLED)->text() == "1",
				 item(row_idx, C_VALUE)->text()
				 );
		settings.endGroup();
	}
	emit updated(get_fgfs_list());
	outLog("*** Profile loaded: "+filename);

    setLastUsed(filename);  // store lastused profile name
    return true;

}
Ejemplo n.º 4
0
void XSettingsModel::read_default_ini()
{
	QString defaultSettings("");
	switch (mainObject->runningOs()) {
		case OS_MAC:
			defaultSettings = ":/default/osx_default.ini";
			break;
		case OS_WINDOWS:
			defaultSettings = ":/default/win_default.ini";
			break;
		case OS_LINUX:
			defaultSettings = ":/default/x_default.ini";
			break;
		default:
			outLog("*** FGx shout: No default settings for this system");
			break;
	}
	
	QSettings settings(defaultSettings,QSettings::IniFormat);

	bool ena;
	for(int row_idx=0; row_idx < rowCount(); row_idx++){
		//= loop rows and load each "option" as an [ini section] with enabled, value as values
		settings.beginGroup(item(row_idx, C_OPTION)->text());
			ena = settings.value("enabled").toBool() ;
			item(row_idx, C_ENABLED)->setText( ena ? "1" : "0");
			QString val = settings.value("value").toString();
			if(val == ""){
				val = item(row_idx, C_DEFAULT)->text();
			}
			item(row_idx, C_VALUE)->setText(val );
			set_row_bg(row_idx, ena ? QColor(200,255,200) : QColor(240,240,240));
			//= Broadcast changes
			emit upx(item(row_idx, C_OPTION)->text(),
					 item(row_idx, C_ENABLED)->text() == "1",
					 item(row_idx, C_VALUE)->text()
					 );
		settings.endGroup();
	}
	//qDebug() << "Read ini";
	emit updated(get_fgfs_list());
	
}
Ejemplo n.º 5
0
//==================================================
// == Set An Option's  Value
void XSettingsModel::set_value(QString option, QString value)
{
	//qDebug() << "set " << option << _loading;
	if(_loading){
		return;
	}
	//= Find item matching the "option"
	QList<QStandardItem *>items = findItems(option, Qt::MatchExactly,C_OPTION);
	//qDebug() << "opts" << items;

	//TODO handle error if not found

	//= Get/update the "enabled" item in the same row
	QStandardItem *vItem = item(items[0]->row(),C_VALUE);
	vItem->setText(value);

	QStandardItem *eItem = item(items[0]->row(),C_ENABLED);



	emit upx(option, eItem->text() == "1",  value);
	emit updated(get_fgfs_list());
}
Ejemplo n.º 6
0
//==================================================
// == Set An Option Enabled or Disabled
void XSettingsModel::set_enabled(QString option, bool enabled)
{
	//qDebug() << "set " << option << _loading;
	if(_loading){
		return;
	}
	//= Find item matching the "option"
	QList<QStandardItem *>items = findItems(option, Qt::MatchExactly,C_OPTION);
	//qDebug() << "opts" << items;

	//TODO handle error if not found

	//= Get/update the "enabled" item in the same row
	QStandardItem *eItem = item(items[0]->row(),C_ENABLED);
	eItem->setText(enabled ? "1" : "0");

	set_row_bg(items[0]->row(), enabled ? QColor(200,255,200) : QColor(240,240,240));

	QStandardItem *vItem = item(items[0]->row(),C_VALUE);

	emit upx(option, enabled, vItem->text());
	emit updated(get_fgfs_list());
}