예제 #1
0
파일: video.cpp 프로젝트: verzhak/platform
CVideo::CVideo(const QString video_fname, const QString metadata_fname) :
	video_fl(video_fname.toStdString()), metadata_fl(metadata_fname)
{
	throw_if(! video_fl.isOpened());
	throw_if(! metadata_fl.open(QIODevice::ReadOnly | QIODevice::Text));

	stream.setDevice(& metadata_fl);

	throw_if(! stream.readNextStartElement());
	throw_if(stream.name() != "amv");
}
예제 #2
0
bool parse_number(const char*& c, const char* const end, float& x)
{
    if(!number_p(*c))
        return false;

    const auto begin = c;

    errno = 0;
    x = strtof(c, const_cast<char**>(&c));
    throw_if(c == begin || errno, "expected number");
    throw_if(c > end, "unexpected eof; strtof consumed too much");
    return true;
}
예제 #3
0
void CSetupDialog::on_apply_button_clicked()
{
	try
	{
		throw_if(texture_size_edit->text().toUInt() % 4, "Размер текстуры должен быть кратен четырем");

		// ############################################################################ 
		// Применение изменений

#define APPLY_UNSIGNED_EDIT(widget, var, var_old)\
		var = var_old = widget->text().toUInt();

#define APPLY_UNSIGNED_LIST(widget, var, var_old, type)\
		var = var_old = (type) widget->currentIndex();

#define APPLY_BOOLEAN_CHECK(widget, var, var_old)\
		var = var_old = widget->isChecked();

		APPLY_UNSIGNED_EDIT(height_edit, parent->main_loop.vector_map.height, height_old);
		APPLY_UNSIGNED_EDIT(width_edit, parent->main_loop.vector_map.width, width_old);
		APPLY_UNSIGNED_EDIT(texture_size_edit, parent->main_loop.vector_map.texture_size, texture_size_old);
		APPLY_UNSIGNED_EDIT(texture_per_row_edit, parent->main_loop.vector_map.texture_per_row, texture_per_row_old);
		APPLY_UNSIGNED_LIST(accuracy_box, parent->main_loop.vector_map.accuracy, accuracy_old, EMapAccuracy);
		APPLY_UNSIGNED_LIST(palette_box, parent->main_loop.vector_map.palette, palette_old, EPalette);
		APPLY_BOOLEAN_CHECK(is_polygon_as_a_line_box, parent->main_loop.vector_map.is_polygon_as_a_line, is_polygon_as_a_line_old);

		// ############################################################################ 

		editing_finished();
	}
	catch(...)
	{
		;
	}
}
예제 #4
0
CMainLoop::CMainLoop(int argc, char * argv[], const uint16_t port) :
	QCoreApplication(argc, argv), height(0), width(0), client_sock(NULL)
{
	throw_if(! server_sock.listen(QHostAddress::AnyIPv4, port));

	connect(& server_sock, SIGNAL(newConnection()), this, SLOT(new_connection()));
	connect(this, SIGNAL(arinc_write(const uint8_t *, const unsigned, const unsigned)), this, SLOT(__arinc_write(const uint8_t *, const unsigned, const unsigned)));
	connect(this, SIGNAL(arinc_done()), this, SLOT(__arinc_done()));
}
예제 #5
0
CSuperStendXmlLoader::CSuperStendXmlLoader(const QString fname) :
	CLoader(), fl(fname)
{
	throw_if(! fl.open(QIODevice::WriteOnly));

	stream.setDevice(& fl);
	stream.setAutoFormatting(true);
	stream.writeStartDocument();
	stream.writeStartElement("amv");
}
예제 #6
0
void CMainLoop::image(CQtSocket & sock, CXML & packet)
{
	try
	{
		const unsigned current_height = packet["height"].uint(), current_width = packet["width"].uint();
		const unsigned buf_size = current_height * current_width;
		unsigned size, block_size;
		uint8_t * ptr;
		shared_ptr<uint8_t> block_buffer;

		ind = packet["ind"].uint();

		if(height != current_height || width != current_width)
		{
			img.reset(new uint8_t[buf_size], std::default_delete<uint8_t[]>());

			height = current_height;
			width = current_width;
		}

		throw_null(ptr = img.get());

		for(size = 0; size < buf_size; )
		{
			CXML block = sock.recv();

			throw_if(block["command"].uint() != CARD_COMMAND_IMAGE_BLOCK);
			throw_if(block["ind"].uint() != ind);

			protocol::decode_base64(block["data"].value, block_buffer, block_size);

			memcpy(ptr + size, block_buffer.get(), block_size);
			size += block_size;
		}

		emit arinc_write(img.get(), height, width);
	}
	catch(...)
	{
		;
	}
}
예제 #7
0
int run_module(lua_State * state)
{
	QString name = (const char *) lua_tostring(state, 1);
	CScriptEngine * p_script = (CScriptEngine *) lua_touserdata(state, lua_upvalueindex(1));
	CMeasure * p_measure = (CMeasure *) lua_touserdata(state, lua_upvalueindex(3));
	
	throw_if(! p_script->modules.count(name), "Вызываемый модуль не загружен");
	p_measure->run_module(name);

	return p_script->modules[name]->run(state);
}
예제 #8
0
파일: core.cpp 프로젝트: verzhak/stend
CConsole::CConsole(int argc, char * argv[]) :
	QObject(NULL)
{
	throw_if(argc != 8, "Недостаточное количество аргументов");

	script_fname = argv[1];
	src_video_fname = argv[2];
	src_metadata_fname = argv[3];
	dst_video_fname = argv[4];
	map_fname = argv[5];
	height_map_fname = argv[6];
	classifier_fname = argv[7];
}
예제 #9
0
matrix CScriptEngine::run(matrix src)
{
	matrix dst;

	lua_getglobal(state, "main");
    lua_pushlightuserdata(state, src);

	throw_if(lua_pcall(state, 1, 1, 0) != LUA_OK, "Не удалось запустить скрипт на выполнение");

	dst = (matrix) lua_touserdata(state, 1);
	lua_pop(state, 1);

	return dst;
}
예제 #10
0
파일: lua.cpp 프로젝트: LomtevaO/stend
Mat * CLua::run(const Mat & src)
{
	s_image * _dst;
	CImage _src(src);

	lua_getglobal(state, "main");
    lua_pushlightuserdata(state, & _src.img);

	throw_if(lua_pcall(state, 1, 1, 0) != LUA_OK);

	_dst = (s_image *) lua_touserdata(state, 1);
	lua_pop(state, 1);

	return (Mat *) _dst->mat;
}
예제 #11
0
int main(int argc, char * argv[])
{
	int ret = 0;

	try
	{
		qInstallMessageHandler(message_handler);
		Q_INIT_RESOURCE(scripts);

		throw_if(argc != 4, "Недостаточное количество аргументов");

		const QString script_fname = argv[1];
		const QString src_video_fname = argv[2];
		const QString dst_video_fname = argv[3];

		// ############################################################################ 

		CDisplay::init();
		CMatrix::init();
		CImage::init();

		CLua lua;
		CMainLoop main_loop(lua);

		lua.load_module("/home/natalya/Science/super_stend/src/stend_modules/build/demo_image/libdemo_image.so");

		lua.load_script(script_fname);
		main_loop.start(src_video_fname, dst_video_fname);

		main_loop.stats["sec_per_frame"]->display();
		main_loop.stats["sec_per_frame"]->save("/home/amv/trash/sec_per_frame");
	}
	catch(...)
	{
		ret = -1;
	}

	CDisplay::destroy();
	CMatrix::destroy();
	CImage::destroy();

	return ret;
}
예제 #12
0
파일: kml.cpp 프로젝트: verzhak/dji_naza
CKmlLoader::CKmlLoader(const QString fname) :
	CLoader(), fl(fname)
{
	throw_if(! fl.open(QIODevice::WriteOnly));

	stream.setDevice(& fl);
	stream.setAutoFormatting(true);
	stream.writeStartDocument();

	stream.writeStartElement("kml");
	stream.writeAttribute("xmlns", "http://www.opengis.net/kml/2.2");

	stream.writeStartElement("Placemark");
	stream.writeTextElement("name", "iOSD Naza-M v2 log data - flight path (GPS/absolute)");
	stream.writeStartElement("MultiGeometry");
	stream.writeStartElement("LineString");

	stream.writeTextElement("extrude", "1");
	stream.writeTextElement("altitudeMode", "absolute");

	stream.writeStartElement("coordinates");
}
예제 #13
0
void execute(string fname)
{
	const unsigned mem_size = 4096;
	int v, u, t;
	char next_dir, dir = 'r';
	unsigned char mem[mem_size];
	unsigned char * pnt = mem;
	Mat src;
	Vec3b color, next_color;

	memset(mem, 0, sizeof(unsigned char) * mem_size);

	src = imread(fname);
	throw_null(src.data);

	v = 0;
	u = 0;
	
	do
	{
		color = src.at<Vec3b>(v, u);

		if((color[0] == 0x00) && (color[1] == 0xFF) && (color[2] == 0x00))
			(* pnt)++;
		else if((color[0] == 0x00) && (color[1] == 0x80) && (color[2] == 0x00))
			(* pnt)--;
		else if((color[0] == 0xFF) && (color[1] == 0x00) && (color[2] == 0x00))
		{
			pnt++;

			throw_if((mem + mem_size <= pnt))
		}
		else if((color[0] == 0x80) && (color[1] == 0x00) && (color[2] == 0x00))
		{
			pnt--;

			throw_if((pnt < mem));
		}
		else if((color[0] == 0xFF) && (color[1] == 0xFF) && (color[2] == 0x00))
		{
			if((* pnt) <= 0)
			{
				t = 0;
				
				next_color[0] = 0x80;
				next_color[1] = 0x80;
				next_color[2] = 0x00;

				do
				{
					throw_if(step(dir, v, u, src.size()));

					if(src.at<Vec3b>(v, u) == color)
						t++;
					else if(src.at<Vec3b>(v, u) == next_color)
						t--;
				}
				while(t >= 0);
			}
		}
		else if((color[0] == 0x80) && (color[1] == 0x80) && (color[2] == 0x00))
		{
			switch(dir)
			{
				case 'r':
				{
					next_dir = 'l';

					break;
				}
				case 'l':
				{
					next_dir = 'r';

					break;
				}
				case 't':
				{
					next_dir = 'b';

					break;
				}
				case 'b':
				{
					next_dir = 't';

					break;
				}
			}

			t = 0;
				
			next_color[0] = 0xFF;
			next_color[1] = 0xFF;
			next_color[2] = 0x00;

			do
			{
				throw_if(step(next_dir, v, u, src.size()));

				if(src.at<Vec3b>(v, u) == color)
					t++;
				else if(src.at<Vec3b>(v, u) == next_color)
					t--;
			}
			while(t >= 0);

			step(next_dir, v, u, src.size());
		}
		else if((color[0] == 0x00) && (color[1] == 0x00) && (color[2] == 0xFF))
			printf("%c", * pnt);
		else if((color[0] == 0x00) && (color[1] == 0x00) && (color[2] == 0x80))
			scanf("%c\n", pnt);
		else if((color[0] == 0x00) && (color[1] == 0xFF) && (color[2] == 0xFF))
		{
			// Поворот против часовой стрелки

			switch(dir)
			{
				case 'r':
				{
					next_dir = 't';

					break;
				}
				case 'l':
				{
					next_dir = 'b';

					break;
				}
				case 't':
				{
					next_dir = 'l';

					break;
				}
				case 'b':
				{
					next_dir = 'r';

					break;
				}
			}

			dir = next_dir;
		}
		else if((color[0] == 0x00) && (color[1] == 0x80) && (color[2] == 0x80))
		{
			// Поворот по часовой стрелке

			switch(dir)
			{
				case 'r':
				{
					next_dir = 't';

					break;
				}
				case 'l':
				{
					next_dir = 't';

					break;
				}
				case 't':
				{
					next_dir = 'r';

					break;
				}
				case 'b':
				{
					next_dir = 'l';

					break;
				}
			}

			dir = next_dir;
		}
		else
			throw_if(1);
	}
예제 #14
0
파일: lua.cpp 프로젝트: LomtevaO/stend
void CLua::load_script(const QString fname)
{
	throw_if(luaL_dofile(state, fname.toStdString().c_str()) != LUA_OK);
}
예제 #15
0
파일: file.cpp 프로젝트: verzhak/sxf
void CFile::operator()(void * buf, const size_t size)
{
	throw_if(fread(buf, 1, size, fl) != size);
}
예제 #16
0
파일: file.cpp 프로젝트: verzhak/sxf
void CFile::seek(const uint32_t offset)
{
	throw_if(fseek(fl, offset, SEEK_SET));
}
예제 #17
0
void CScriptEngine::load(const QString fname)
{
	throw_if(luaL_dofile(state, fname.toLocal8Bit().constData()) != LUA_OK, "Не удалось загрузить скрипт");
}
예제 #18
0
static inline void throw_unless(bool cond, std::string const& reason)
{ throw_if(!cond,reason); }
예제 #19
0
void error_info::throw_if_null(void const* p)
{
  throw_if(!p);
}
예제 #20
0
int main(const int argc, const char * argv[])
{
	int ret = 0;

	try
	{
		char fname[4096];
		unsigned u, prog_nip_num = 0;
		vector<string> prog;
		vector<unsigned> height;
		vector<unsigned> width;

		// Hello, World!
		prog.push_back("++++++[>++++++++++++<-]>.>++++++++++[>++++++++++<-]>+.+++++++..+++.>++++[>+++++++++++<-]>.<+++[>----<-]>.<<<<<+++[>+++++<-]>.>>.+++.------.--------.>>+.");
		height.push_back(1);
		width.push_back((prog.end() - 1)->size());

		// Числа Фибоначчи
		prog.push_back("+++++++++++>+>>>>++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>+<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-<-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<-]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<+>>[-]]<<<<<<<]>>>>>[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++++++++++++++++++++++++++++++++++++++++++++++.[-]<<<<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<[-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]");
		height.push_back(1);
		width.push_back((prog.end() - 1)->size());

		// Факториал
		prog.push_back("+++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++>++++++>>+<<[>++++++++++++++++++++++++++++++++++++++++++++++++.------------------------------------------------<<<<.-.>.<.+>>>>>>>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>[<+>-]>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]<[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]<<<++++++++++++++++++++++++++++++++++++++++++++++++.[-]<<<<<<.>>+>[>>+<<-]>>[<<<[>+>+<<-]>>[<<+>>-]>-]<<<<-]");
		height.push_back(1);
		width.push_back((prog.end() - 1)->size());

		// 99 бутылок пива
		prog.push_back(">+++++++++[<+++++++++++>-]<[>[-]>[-]<<[>+>+<<-]>>[<<+>>-]>>>[-]<<<+++++++++<[>>>+<<[>+>[-]<<-]>[<+>-]>[<<++++++++++>>>+<-]<<-<-]+++++++++>[<->-]>>+>[<[-]<<+>>>-]>[-]+<<[>+>-<<-]<<<[>>+>+<<<-]>>>[<<<+>>>-]>[<+>-]<<-[>[-]<[-]]>>+<[>[-]<-]<++++++++[<++++++<++++++>>-]>>>[>+>+<<-]>>[<<+>>-]<[<<<<<.>>>>>-]<<<<<<.>>[-]>[-]++++[<++++++++>-]<.>++++[<++++++++>-]<++.>+++++[<+++++++++>-]<.><+++++..--------.-------.>>[>>+>+<<<-]>>>[<<<+>>>-]<[<<<<++++++++++++++.>>>>-]<<<<[-]>++++[<++++++++>-]<.>+++++++++[<+++++++++>-]<--.---------.>+++++++[<---------->-]<.>++++++[<+++++++++++>-]<.+++..+++++++++++++.>++++++++[<---------->-]<--.>+++++++++[<+++++++++>-]<--.-.>++++++++[<---------->-]<++.>++++++++[<++++++++++>-]<++++.------------.---.>+++++++[<---------->-]<+.>++++++++[<+++++++++++>-]<-.>++[<----------->-]<.+++++++++++..>+++++++++[<---------->-]<-----.---.>>>[>+>+<<-]>>[<<+>>-]<[<<<<<.>>>>>-]<<<<<<.>>>++++[<++++++>-]<--.>++++[<++++++++>-]<++.>+++++[<+++++++++>-]<.><+++++..--------.-------.>>[>>+>+<<<-]>>>[<<<+>>>-]<[<<<<++++++++++++++.>>>>-]<<<<[-]>++++[<++++++++>-]<.>+++++++++[<+++++++++>-]<--.---------.>+++++++[<---------->-]<.>++++++[<+++++++++++>-]<.+++..+++++++++++++.>++++++++++[<---------->-]<-.---.>+++++++[<++++++++++>-]<++++.+++++++++++++.++++++++++.------.>+++++++[<---------->-]<+.>++++++++[<++++++++++>-]<-.-.---------.>+++++++[<---------->-]<+.>+++++++[<++++++++++>-]<--.+++++++++++.++++++++.---------.>++++++++[<---------->-]<++.>+++++[<+++++++++++++>-]<.+++++++++++++.----------.>+++++++[<---------->-]<++.>++++++++[<++++++++++>-]<.>+++[<----->-]<.>+++[<++++++>-]<..>+++++++++[<--------->-]<--.>+++++++[<++++++++++>-]<+++.+++++++++++.>++++++++[<----------->-]<++++.>+++++[<+++++++++++++>-]<.>+++[<++++++>-]<-.---.++++++.-------.----------.>++++++++[<----------->-]<+.---.[-]<<<->[-]>[-]<<[>+>+<<-]>>[<<+>>-]>>>[-]<<<+++++++++<[>>>+<<[>+>[-]<<-]>[<+>-]>[<<++++++++++>>>+<-]<<-<-]+++++++++>[<->-]>>+>[<[-]<<+>>>-]>[-]+<<[>+>-<<-]<<<[>>+>+<<<-]>>>[<<<+>>>-]<>>[<+>-]<<-[>[-]<[-]]>>+<[>[-]<-]<++++++++[<++++++<++++++>>-]>>>[>+>+<<-]>>[<<+>>-]<[<<<<<.>>>>>-]<<<<<<.>>[-]>[-]++++[<++++++++>-]<.>++++[<++++++++>-]<++.>+++++[<+++++++++>-]<.><+++++..--------.-------.>>[>>+>+<<<-]>>>[<<<+>>>-]<[<<<<++++++++++++++.>>>>-]<<<<[-]>++++[<++++++++>-]<.>+++++++++[<+++++++++>-]<--.---------.>+++++++[<---------->-]<.>++++++[<+++++++++++>-]<.+++..+++++++++++++.>++++++++[<---------->-]<--.>+++++++++[<+++++++++>-]<--.-.>++++++++[<---------->-]<++.>++++++++[<++++++++++>-]<++++.------------.---.>+++++++[<---------->-]<+.>++++++++[<+++++++++++>-]<-.>++[<----------->-]<.+++++++++++..>+++++++++[<---------->-]<-----.---.+++.---.[-]<<<]");
		height.push_back(1);
		width.push_back((prog.end() - 1)->size());

		// Треугольник
		prog.push_back(">++++[<++++++++>-]>++++++++[>++++<-]>>++>>>+>>>+<<<<<<<<<<[-[->+<]>[-<+>>>.<<]>>>[[->++++++++[>++++<-]>.<<[->+<]+>[->++++++++++<<+>]>.[-]>]]+<<<[-[->+<]+>[-<+>>>-[->+<]++>[-<->]<<<]<<<<]++++++++++.+++.[-]<]+++++");
		height.push_back(1);
		width.push_back((prog.end() - 1)->size());

		// Квайн
		prog.push_back("-->+++>+>+>+>+++++>++>++>->+++>++>+>>>>>>>>>>>>>>>>->++++>>>>->+++>+++>+++>+++>+++>+++>+>+>>>->->>++++>+>>>>->>++++>+>+>>->->++>++>++>++++>+>++>->++>++++>+>+>++>++>->->++>++>++++>+>+>>>>>->>->>++++>++>++>++++>>>>>->>>>>+++>->++++>->->->+++>>>+>+>+++>+>++++>>+++>->>>>>->>>++++>++>++>+>+++>->++++>>->->+++>+>+++>+>++++>>>+++>->++++>>->->++>++++>++>++++>>++[-[->>+[>]++[<]<]>>+[>]<--[++>++++>]+[<]<<++]>>>[>]++++>++++[--[+>+>++++<<[-->>--<<[->-<[--->>+<<[+>+++<[+>>++<<]]]]]]>+++[>+++++++++++++++<-]>--.<<<]");
		height.push_back(1);
		width.push_back((prog.end() - 1)->size());

		throw_if(argc != 2);

		if(! (strcmp(argv[1], "translate") && strcmp(argv[1], "t")))
		{
			for(u = 0; u < prog.size(); u++)
			{
				sprintf(fname, "%s/program/%u.png", DATA_DIR, prog_nip_num + u + 1);

				translate(fname, prog[u], height[u], width[u]);
			}
		}
		else if(! (strcmp(argv[1], "execute") && strcmp(argv[1], "e")))
		{
			for(u = 0; u < prog_nip_num + prog.size(); u++)
			{
				sprintf(fname, "%s/program/%u.png", DATA_DIR, u + 1);

				printf("\n### RUN %s ###\n", fname);
				execute(fname);
			}

			printf("\n#########\n\n");
		}
		else
			throw_if(1);
	}
	catch(...)
	{
		ret = -1;

		printf("\nФормат вызова: ./program ACTION\n\nГде:\n\n\tACTION - действие (t, translate - трансляция всех программ из символьной записи в запись на языке brainloller; e, execute - выполнение всех программ).\n\n");
	}

	return ret;
}