Пример #1
0
void SceneWidget::slotImportMeshModels(void) {
  MainWindow* main_window = MainWindow::getInstance();

  QStringList filenames = QFileDialog::getOpenFileNames(main_window, "Import Mesh Models", main_window->getWorkspace().c_str(),
      "Mesh Models (*.off *.ply *.obj)");
  if (filenames.isEmpty())
    return;

  bool flag = true;
  std::string failed_list;
  for (QStringList::iterator it = filenames.begin(); it != filenames.end(); ++it) {
    osg::ref_ptr<MeshModel> mesh_model(new MeshModel());
    if (mesh_model->load(it->toStdString())) {
      mesh_models_.push_back(mesh_model);
      addSceneChild(mesh_model);
    } else {
      flag = false;
      LOG(ERROR) << "Importing " << it->toStdString() << " failed!" << std::endl;
      failed_list += it->toStdString() + " ";
    }
  }

  if (!flag) {
    main_window->showMessageBox("Some mesh importing failed!", failed_list);
  }

  centerScene();

  return;
}
Пример #2
0
void TaskDispatcher::dispatchScaleModelsTasks(void)
{
	MainWindow* main_window = MainWindow::getInstance();
	if (!scale_models_tasks_.isEmpty())
	{
		QMessageBox::warning(main_window, "Scale Models Warning",
			"Run scale models task after the previous one has finished");
		return;
	}

	QString directory = QFileDialog::getExistingDirectory(main_window, "Scale Models in Directory", main_window->getWorkspace().c_str(), QFileDialog::ShowDirsOnly);
	if (directory.isEmpty())
		return;

	QDir dir(directory);
	QStringList obj_list = dir.entryList(QStringList("*.obj"), QDir::Files);
	if (obj_list.empty())
		return;

	double expected_height;
	if (!ParameterManager::getInstance().getExpectedHeightParameters(expected_height))
		return;

	int mesh_model_id = 0;
	std::ofstream fout(directory.toStdString()+"/mapping.txt");
	for (QStringList::iterator it = obj_list.begin(); it != obj_list.end(); ++ it)
	{
		QString filename = directory+"/"+*it;
		fout << QFileInfo(filename).baseName().toStdString() << "\t" << Common::int2String(mesh_model_id, 4) << std::endl;
		scale_models_tasks_.push_back(Task(new TaskScaleModels(mesh_model_id++, filename.toStdString(), expected_height)));
	}
	fout.close();

	// workaround boost filesystem path bug.
	osg::ref_ptr<MeshModel> mesh_model(new MeshModel(0));
	mesh_model->load((directory+"/"+obj_list.first()).toStdString());

	runTasksInParallel(scale_models_tasks_, "Scale Models");

	return;
}
Пример #3
0
  bool generateDistanceFields(void) {
    if(FLAGS_df_list.empty()) {
      return false;
    }
    if (!boost::filesystem::exists(FLAGS_df_list)) {
      return false;
    }

    std::vector<DFItem> df_list;
    std::ifstream fin(FLAGS_df_list);
    std::string source, target;
    int resolution;
    std::set<std::string> folder_set;
    while (fin >> source >> resolution >> target) {
      df_list.push_back(std::make_tuple(source, resolution, target));
      std::string folder = boost::filesystem::path(target).parent_path().string();
      if(folder_set.find(folder) == folder_set.end()) {
        if (!boost::filesystem::exists(folder)) {
          boost::filesystem::create_directories(folder);
          folder_set.insert(folder);
        }
      }
    }
    LOG(INFO) <<  df_list.size() << " items to be processed!" << std::endl;

    if(!FLAGS_skip_converting) {
      int step = 100;
      for (int i = 0, i_end = df_list.size(); i < i_end; i ++) {
        const std::string filename_df = std::get<2>(df_list[i]);
        boost::filesystem::path path(filename_df);
        std::string filename_pcd = path.parent_path().string()+"/"+path.stem().string()+".pcd";

        osg::ref_ptr <PointCloud> point_cloud(new PointCloud);
        if(point_cloud->load(filename_pcd)) {
          LOG(INFO) << "Skipping generating " << filename_pcd << " as it exists and reads well..." << std::endl;
          continue;
        }

        const std::string filename_mesh = std::get<0>(df_list[i]);
        LOG(INFO) << "Converting " << filename_mesh << " into point cloud..." << std::endl;
        osg::ref_ptr <MeshModel> mesh_model(new MeshModel);
        if(!mesh_model->load(filename_mesh)) {
          LOG(ERROR) << "Reading " << filename_mesh << " failed! Skipping it..." << std::endl;
          continue;
        }

        point_cloud->data()->clear();
        double grid_size = mesh_model->sampleScan(point_cloud->data(), 100, 0.0);
        point_cloud->buildTree();
        point_cloud->voxelGridFilter(grid_size/2, true);
        point_cloud->save(filename_pcd);

        if ((i+1)%step == 0) {
          LOG(INFO) << "Converted " << (i+1) << " items! (total item number: " << i_end << ")" << std::endl;
        }
      }
    }

    if (!FLAGS_skip_generation) {
      unsigned int n = std::thread::hardware_concurrency()-4;
      LOG(INFO) << n << " threads will be used!" << std::endl;

      std::vector<std::thread> threads;
      for (unsigned int i = 0; i < n; ++ i) {
        std::thread thread_obj(generateDistanceField, df_list, n, i);
        threads.push_back(std::move(thread_obj));
      }

      for (unsigned int i = 0; i < n; ++ i) {
        threads[i].join();
      }
      LOG(INFO) << "Distance field generation done!" << std::endl;
    }

    return true;
  }