示例#1
0
void FileLoader::loadMVS(const char *fileName, MVS &mvs) {
	vector<Camera>  &cameras = mvs.cameras;
	map<int, Patch> &patches = mvs.patches;

	// reset container
	cameras.clear();
	patches.clear();

	// open mvs file
	ifstream file(fileName, ifstream::in | ifstream::binary);

	if ( !file.is_open() ) {
		printf("Can't open MVS file: %s\n", fileName);
		return;
	}

	char *strip = NULL;
	char strbuf[STRING_BUFFER_LENGTH];
	int num;
	bool loadCamera = false;
	bool loadPatch  = false;
	while ( !file.eof() ) {

		file.getline(strbuf, STRING_BUFFER_LENGTH);
		strip = strtok(strbuf, DELIMITER);

		if (strip == NULL) continue; // skip blank line

		// start load camera
		if (strcmp(strip, "MVS_V2") == 0) {
			loadCamera = true;
			continue;
		}

		// set config and start load camera
		if (strcmp(strip, "MVS_V3") == 0) {
			MvsConfig config = loadMvsConfig(file);
			mvs.setConfig(config);
			loadCamera = true;
			continue;
		}

		if (loadCamera) {
			strip = strtok(NULL, DELIMITER);
			num = atoi(strip);
			for (int i = 0; i < num; ++i) {
				printf("\rloading cameras: %d / %d", i+1, num);
				cameras.push_back( loadMvsCamera(file) );
			}
			printf("\n");
			loadCamera = false;
			loadPatch  = true;
			continue;
		}

		if (loadPatch) {
			strip = strtok(NULL, DELIMITER);
			num = atoi(strip);
			for (int i = 0; i < num; ++i) {
				printf("\rloading patches: %d / %d", i+1, num);
				Patch pth = loadMvsPatch(file);
				patches.insert( pair<int, Patch>(pth.getId(), pth) );
			}
			printf("\n");
			loadPatch = false;
		}
	}

	file.close();
}
示例#2
0
void FileLoader::loadNVM2(const char *fileName, MVS &mvs) {
	vector<Camera>  &cameras = mvs.cameras;
	map<int, Patch> &patches = mvs.patches;

	// reset container
	cameras.clear();
	patches.clear();

	// open nvm file
	ifstream file(fileName, ifstream::in);

	if ( !file.is_open() ) {
		printf("Can't open NVM2 file: %s\n", fileName);
		return;
	}

	// get file path
	char filePath [MAX_FILE_NAME_LENGTH];
	getDir(fileName, filePath);

	char *strip = NULL;
	char strbuf[STRING_BUFFER_LENGTH];
	int num;
	bool loadCamera = false;
	bool loadPatch  = false;

	while ( !file.eof() ) {

		file.getline(strbuf, STRING_BUFFER_LENGTH);
		strip = strtok(strbuf, DELIMITER);

		if (strip == NULL) continue; // skip blank line

		// start load camera
		if (strcmp(strip, "NVM_V3") == 0) {
			loadCamera = true;
			continue;
		}

		if (loadCamera) {
			// get number of cameras
			strip = strtok(strbuf, DELIMITER);
			num = atoi(strip);

			cameras.reserve(num);
			for (int i = 0; i < num; i++) {
				printf("\rloading cameras: %d / %d", i+1, num);
				cameras.push_back( loadNvm2Camera(file, filePath) );
			}
			printf("\n");
			loadCamera = false;
			loadPatch  = true;

			continue;
		}

		if (loadPatch) {
			// get number of points
			strip = strtok(strbuf, DELIMITER);
			num = atoi(strip);

			for (int i = 0; i < num; i++) {
				printf("\rloading patches: %d / %d", i+1, num);
				Patch p = loadNvmPatch(file, mvs);
				patches.insert( pair<int, Patch>(p.getId(), p) );
			}
			printf("\n");
			loadPatch = false;

			break;
		}
	}

	file.close();
}