Пример #1
0
/* mode 0 new file
 * mode 1 edit file
 */
int wama_file(int mode)
{
	char path[128];
	clean_screen();
	printf("Ruta del archivo: ");
	gets_s(path, 128);
	clean_screen();
	if (path[0] != '/') {
		char dev_path[128] = "/dev/";
		strcat(dev_path, path);
		strcpy(path, dev_path);
	}
	/* creamos el archivo 'path' */
	if ((touch(path, S_IRUSR | S_IWUSR)) < 0 && mode == NEW_FILE_MODE) {
		return -1;
	}
	int line_count = 1;
	char line[128];
	int fd;
	if ((fd = open(path, O_WRONLY)) < 0) {
		return -1;
	}
	if (mode == EDIT_FILE_MODE) {
		char *ch = read_file(path);
		write(fd, ch, strlen(ch));
		line_count = linecounter(ch);
		line_count++;
	}
	printf("\n\n\n %d ", line_count);
	char *data;
	while ( 1 ) {
		setwindow();
		subwindow(line_count);
		gets_s(line, 128);
		switch (checkWamaCommand(line)) {
			case 0:
				write(fd, line, strlen(line));
				write(fd, "\n", 1);
				break;
			case 1:
				close(fd);
				if (goto_wama_command(path, line_count) < 0) {
					return -1;
				}
				data = read_file(path);
				if ((fd = open(path, O_WRONLY)) < 0) {
					return -1;
				}
				write(fd, data, strlen(data));
				line_count--;
				break;
			case 2:
				close(fd);
				return 0;
				break;
		}
		line_count++;
		printf(" %d ", line_count);
	}
}
Пример #2
0
//____________________________________________________________________________________
bool MdiWindowShadowFactory::registerWidget( QWidget* widget )
{

    // check widget type
    QMdiSubWindow* subwindow( qobject_cast<QMdiSubWindow*>( widget ) );
    if( !subwindow ) return false;
    if( subwindow->widget() && subwindow->widget()->inherits( "KMainWindow" ) ) return false;

    // make sure widget is not already registered
    if( isRegistered( widget ) ) return false;

    // store in set
    _registeredWidgets.insert( widget );

    widget->installEventFilter( this );

    // catch object destruction
    connect( widget, SIGNAL(destroyed(QObject*)), SLOT(widgetDestroyed(QObject*)) );

    return true;

}
cv::Mat_<cv::Vec2b> adaptive_window_size(const cv::Mat& image, const cv::Mat_<int>& labels, float threshold, int minsize, int maxsize, const std::vector<disparity_region>& regions, lambda_type func)
{
	assert(minsize > 0);
	assert(maxsize > 0);

	std::vector<short> disparities(regions.size());
	for(std::size_t i = 0; i < regions.size(); ++i)
		disparities[i] = regions[i].disparity;

	cv::Mat_<cv::Vec2b> result = cv::Mat::zeros(labels.size(), CV_8UC2);
	const int onesidesizeMin = (minsize-1)/2;
	const int onesidesizeMax = (maxsize-1)/2;
	#pragma omp parallel for default(none) shared(labels, image, result, disparities, threshold, func, minsize, maxsize)
	for(int y = onesidesizeMin; y < labels.rows - onesidesizeMin; ++y)
	{
		int lastWindowSize = onesidesizeMin*2+1;

		for(int x = onesidesizeMin; x < labels.cols - onesidesizeMin; ++x)
		{
			int clabel = labels(y,x);
			int maxposs = std::min( std::min(labels.cols - x-1, labels.rows - y-1), onesidesizeMax );
			maxposs = std::min( maxposs, std::min( std::min(y-1, x-1), onesidesizeMax ) );

			maxposs = maxposs*2+1;

			int windowsizeX = std::min(lastWindowSize, maxposs);
			int windowsizeY = std::min(lastWindowSize, maxposs);

			bool grow = (lastWindowSize == minsize) ? true : false;

			while(true)
			{
				float measured = func(subwindow(labels, x,y, windowsizeX, windowsizeY), clabel, disparities);
				if(grow)
				{
					if(measured < threshold)
					{
						//shrink each direction seperatly
						float measured_altY = func(subwindow(labels, x,y, windowsizeX, windowsizeY-2), clabel, disparities);
						float measured_altX = func(subwindow(labels, x,y, windowsizeX-2, windowsizeY), clabel, disparities);

						if(measured_altY > threshold)
							windowsizeY -= 2;
						else if(measured_altX > threshold)
							windowsizeX -= 2;
						else {
							windowsizeX -= 2;
							windowsizeY -= 2;
							break;
						}
					}
					if(windowsizeX < maxposs && windowsizeY < maxposs)
					{
						windowsizeX += 2;
						windowsizeY += 2;
					} else
						break;
				} else {
					if(measured >= threshold)
					{
						grow = true;
						continue;
					}
					if( windowsizeX > minsize && windowsizeY > minsize) {
						windowsizeX -= 2;
						windowsizeY -= 2;
					} else
						break;
				}
			}
			lastWindowSize = std::min(windowsizeX, windowsizeY);
			result(y,x) = cv::Vec2b(std::max(windowsizeY, minsize), std::max(windowsizeX, minsize));
		}
	}

	return result;
}