Пример #1
0
void DistViewGUI::initSubscriptions()
{
	if (!ui->gv->isHidden()) {
		emit needBinning(type);
		emit subscribeRepresentation(this, type);
	}
}
Пример #2
0
void DistViewGUI::fold(bool folded)
{
	if (folded) { // fold
		GGDBGM(type << " folding" << endl);

		// let the controller know we do not need our image representation
		emit unsubscribeRepresentation(this, type);

		// fold GUI and set size policy for proper arrangement
		ui->gv->setHidden(true);
		ui->topBar->fold();
		frame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);

		// reset title
		setTitle(type);

		// TODO: send signals that will destroy unused data!

		// TODO: let viewport clean itself up!
		//(*binsets)->clear(); // clear the vector, not re-create shareddata!
		//viewport->shuffleIdx.clear();
		//viewport->vb.destroy();
		emit foldingStateChanged(type, true);

	} else { // unfold
		GGDBGM(type << " unfolding" << endl);

		emit needBinning(type);
		// let the controller know we need our image representation
		emit subscribeRepresentation(this, type);

		// unfold GUI and set size policy for proper arrangement
		ui->gv->setVisible(true);
		ui->topBar->unfold();
		QSizePolicy pol(QSizePolicy::Preferred, QSizePolicy::Expanding);
		pol.setVerticalStretch(1);
		frame->setSizePolicy(pol);

		emit foldingStateChanged(type, false);

		// TODO: trigger calculation of data?
	}
}
Пример #3
0
Controller::Controller(const QString &filename,
                       bool limited_mode,
                       const QString &labelfile,
                       QObject *parent)

    : QObject(parent),
      // initialize all pointers so we don't access them too early w/o notice
      im(nullptr), lm(nullptr), fm(nullptr), illumm(nullptr),
      gsm(nullptr),
#ifdef WITH_SEG_MEANSHIFT
      cm(nullptr),
#endif
      dvc(nullptr),
      queuethread(nullptr),
      subs(new Subscriptions)
{
	// reset internal ROI state tracking
	resetROISpawned();

	// start background task queue thread
	connect(&queue, SIGNAL(exception(std::exception_ptr, bool)),
	        GerbilApplication::instance(),
	        SLOT(handle_exception(std::exception_ptr,bool)),
	        Qt::BlockingQueuedConnection);
	startQueue();

	im = new ImageModel(queue, limited_mode, this);
	// load image
	cv::Rect dimensions = im->loadImage(filename);
	imgSize = cv::Size(dimensions.width, dimensions.height);

	// create gui (perform initUI before connecting signals!)
	window = new MainWindow();
	window->initUI(filename);

	// initialize models
	initImage();
	fm = new FalseColorModel();
	initFalseColor(); // depends on ImageModel / initImage()

	// The order of connection is crucial for fm and Controller.
	// fm needs to get the signal first. Otherwise it will
	// hand out invalid cached data.
	connect(im, SIGNAL(imageUpdate(representation::t,SharedMultiImgPtr,bool)),
	        fm, SLOT(processImageUpdate(representation::t,SharedMultiImgPtr,bool)));
	connect(im, SIGNAL(imageUpdate(representation::t,SharedMultiImgPtr,bool)),
	        this, SLOT(processImageUpdate(representation::t,SharedMultiImgPtr,bool)));

	lm = new LabelingModel(this);
	initLabeling(dimensions);
	illumm = new IllumModel(&queue, this);
	initIlluminant();
	gsm = new GraphSegmentationModel(&queue, this);
	initGraphSegmentation(); // depends on ImageModel / initImage()
#ifdef WITH_SEG_MEANSHIFT
	cm = new ClusteringModel(this);
#endif /* WITH_SEG_MEANSHIFT */

	// initialize sub-controllers (after initializing the models...)
	dvc = new DistViewController(this, &queue, im);
	dvc->init();

	// init dock widgets
	initDocks();

	// connect slots/signals
	window->initSignals(this, dvc);

	/* TODO: better place. But do not use init model functions:
	 * dvc are created after these are called
	 */
	connect(dvc, SIGNAL(requestOverlay(cv::Mat1b)),
	        this, SIGNAL(requestOverlay(cv::Mat1b)));
	connect(lm,
	        SIGNAL(newLabeling(const cv::Mat1s&, const QVector<QColor>&, bool)),
	        dvc, SLOT(updateLabels(cv::Mat1s,QVector<QColor>,bool)));
	connect(lm, SIGNAL(partialLabelUpdate(const cv::Mat1s&,const cv::Mat1b&)),
			dvc, SLOT(updateLabelsPartially(const cv::Mat1s&,const cv::Mat1b&)));
	connect(dvc, SIGNAL(alterLabelRequested(short,cv::Mat1b,bool)),
	        lm, SLOT(alterLabel(short,cv::Mat1b,bool)));
	connect(illumm, SIGNAL(newIlluminantCurve(QVector<multi_img::Value>)),
	        dvc, SIGNAL(newIlluminantCurve(QVector<multi_img::Value>)));
	connect(illumm, SIGNAL(newIlluminantApplied(QVector<multi_img::Value>)),
	        dvc, SIGNAL(newIlluminantApplied(QVector<multi_img::Value>)));

#ifdef WITH_SEG_MEANSHIFT
	connect(cm, SIGNAL(subscribeRepresentation(QObject*,representation::t)),
	        this, SLOT(subscribeRepresentation(QObject*,representation::t)));
	connect(cm, SIGNAL(unsubscribeRepresentation(QObject*,representation::t)),
	        this, SLOT(unsubscribeRepresentation(QObject*,representation::t)));
	connect(im, SIGNAL(imageUpdate(representation::t,SharedMultiImgPtr,bool)),
	        cm, SLOT(processImageUpdate(representation::t,SharedMultiImgPtr,bool)));
#endif

	connect(this, SIGNAL(preROISpawn(cv::Rect,cv::Rect,std::vector<cv::Rect>,std::vector<cv::Rect>,bool)),
	        dvc, SLOT(processPreROISpawn(cv::Rect,cv::Rect,std::vector<cv::Rect>,std::vector<cv::Rect>,bool)));
	connect(this, SIGNAL(postROISpawn(cv::Rect,cv::Rect,std::vector<cv::Rect>,std::vector<cv::Rect>,bool)),
	        dvc, SLOT(processPostROISpawn(cv::Rect,cv::Rect,std::vector<cv::Rect>,std::vector<cv::Rect>,bool)));

	/* start with initial label or provided labeling
	 * Do this after all signals are connected, and before initial ROI spawn!
	 */
	if (labelfile.isEmpty()) {
		lm->addLabel();
	} else {
		lm->loadLabeling(labelfile);
	}

	/* Initial ROI images spawning. Do it before showing the window but after
	 * all signals were connected! */
	//GGDBGM("dimensions " << dimensions << endl);
	roi = dimensions; // initial ROI is image size, except:
	if (roi.area() > 262144) {
		// image is bigger than 512x512, start with a smaller ROI in center
		roi.width = std::min(roi.width, 512);
		roi.height = std::min(roi.height, 512);
		roi.x = 0.5*(dimensions.width - roi.width);
		roi.y = 0.5*(dimensions.height - roi.height);
	}

	GGDBGM("roi " << roi  << endl);
	spawnROI();

	// The IMG representation must always be subscribed. Otherwise all the logic
	// in ImageModel fails. So we subscribe the Controller forever.
	subscribeRepresentation(this, representation::IMG);

	GGDBGM("init distview subscriptions" << endl);
	dvc->initSubscriptions();

	GGDBGM("init done, showing mainwindow" << endl);

	// we're done! show window
	window->show();
}