예제 #1
0
파일: scene_tree.cpp 프로젝트: 2php/pcl
void 
pcl::modeler::SceneTree::slotSavePointCloud()
{
  MainWindow* main_window = &MainWindow::getInstance();

  if (selectedTypeItems<CloudMeshItem>().empty())
  {
    QMessageBox::warning(main_window, 
      tr("Failed to Save Point Cloud"), 
      tr("Please specify the point cloud(s) you want to save"));
    return;
  }

  QString filename = QFileDialog::getSaveFileName(main_window,
    tr("Save Point Cloud"),
    main_window->getRecentFolder(),
    tr("Save Cloud(*.pcd)\n"));

  if (filename.isEmpty())
    return;

  savePointCloud(filename);

  return;
}
예제 #2
0
파일: converter.cpp 프로젝트: 2php/pcl
/**
 * Saves a mesh into the specified file and output type. The file format is automatically parsed.
 * @param input[in] The mesh to be saved
 * @param output_file[out] The output file to be written
 * @param output_type[in]  The output file type
 * @return True on success, false otherwise.
 */
bool
saveMesh (pcl::PolygonMesh& input,
          std::string output_file,
          int output_type)
{
  if (boost::filesystem::path (output_file).extension () == ".obj")
  {
    if (output_type == BINARY || output_type == BINARY_COMPRESSED)
      PCL_WARN ("OBJ file format only supports ASCII.\n");

    //TODO: Support precision
    //FIXME: Color is lost during conversion (OBJ supports color)
    PCL_INFO ("Saving file %s as ASCII.\n", output_file.c_str ());
    if (pcl::io::saveOBJFile (output_file, input) != 0)
      return (false);
  }
  else if (boost::filesystem::path (output_file).extension () == ".pcd")
  {
    if (!input.polygons.empty ())
      PCL_WARN ("PCD file format does not support meshes! Only points be saved.\n");
    pcl::PCLPointCloud2::Ptr cloud = boost::make_shared<pcl::PCLPointCloud2> (input.cloud);
    if (!savePointCloud (cloud, output_file, output_type))
      return (false);
  }
  else  // PLY, STL and VTK
  {
    if (output_type == BINARY_COMPRESSED)
      PCL_WARN ("PLY, STL and VTK file formats only supports ASCII and binary output file types.\n");

    if (input.polygons.empty() && boost::filesystem::path (output_file).extension () == ".stl")
    {
      PCL_ERROR ("STL file format does not support point clouds! Aborting.\n");
      return (false);
    }

    PCL_INFO ("Saving file %s as %s.\n", output_file.c_str (), (output_type == ASCII) ? "ASCII" : "binary");
    if (!pcl::io::savePolygonFile (output_file, input, (output_type == ASCII) ? false : true))
      return (false);
  }

  return (true);
}
//--------------------------------------------------------------
void testApp::update() {
    
    //////////////////////////////////////////////////////
    // General
    //////////////////////////////////////////////////////
    
    ofBackground(0, 0, 0);
    kinect.update();
    
    distanciaMinima = farThreshold*15;
    distanciaMaxima = nearThreshold*15;
    
    //////////////////////////////////////////////////////
    // Grabando
    //////////////////////////////////////////////////////
    
    // Guardamos la info del Mesh:
    
    if(recording) {
        savePointCloud();
    }
    
    //////////////////////////////////////////////////////
    // Reproduciendo
    ////////////////////////////////////////////////////// 
    
    if(playing) {
        frameToPlay += 1;
        if(frameToPlay >= meshRecorder.TotalFrames) frameToPlay = 0;
    }
    
    //////////////////////////////////////////////////////
    // Tracking / Playing
    ////////////////////////////////////////////////////// 
    
	// there is a new frame and we are connected
	if(kinect.isFrameNew()) {
		// load grayscale depth image from the kinect source
        if (!playing) 
            grayImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height);
        
        // we do two thresholds - one for the far plane and one for the near plane
		// we then do a cvAnd to get the pixels which are a union of the two thresholds
		if(bThreshWithOpenCV) {
			grayThreshNear = grayImage;
			grayThreshFar = grayImage;
			grayThreshNear.threshold(nearThreshold, true);
			grayThreshFar.threshold(farThreshold);
			cvAnd(grayThreshNear.getCvImage(), grayThreshFar.getCvImage(), grayImage.getCvImage(), NULL);
		} else {
			
			// or we do it ourselves - show people how they can work with the pixels
			unsigned char * pix = grayImage.getPixels();
			
			int numPixels = grayImage.getWidth() * grayImage.getHeight();
			for(int i = 0; i < numPixels; i++) {
				if(pix[i] < nearThreshold && pix[i] > farThreshold) {
					pix[i] = 255;
				} else {
					pix[i] = 0;
				}
			}
		}
		
		// update the cv images
		grayImage.flagImageChanged();
		
		// find contours which are between the size of 20 pixels and 1/3 the w*h pixels.
		// also, find holes is set to true so we will get interior contours as well....
		//contourFinder.findContours(grayImage, 10, (kinect.width*kinect.height)/2, 20, false);
	}
	
#ifdef USE_TWO_KINECTS
	kinect2.update();
#endif
    
}
예제 #4
0
파일: converter.cpp 프로젝트: 2php/pcl
/**
 * Parse input files and options. Calls the right conversion function.
 * @param argc[in]
 * @param argv[in]
 * @return 0 on success, any other value on failure.
 */
int
main (int argc,
      char** argv)
{
  // Display help
  if (pcl::console::find_switch (argc, argv, "-h") != 0 || pcl::console::find_switch (argc, argv, "--help") != 0)
  {
    displayHelp (argc, argv);
    return (0);
  }

  // Parse all files and options
  std::vector<std::string> supported_extensions;
  supported_extensions.push_back("obj");
  supported_extensions.push_back("pcd");
  supported_extensions.push_back("ply");
  supported_extensions.push_back("stl");
  supported_extensions.push_back("vtk");
  std::vector<int> file_args;
  for (int i = 1; i < argc; ++i)
    for (size_t j = 0; j < supported_extensions.size(); ++j)
      if (boost::algorithm::ends_with(argv[i], supported_extensions[j]))
      {
        file_args.push_back(i);
        break;
      }

  std::string parsed_output_type;
  pcl::console::parse_argument (argc, argv, "-f", parsed_output_type);
  pcl::console::parse_argument (argc, argv, "--format", parsed_output_type);
  bool cloud_output (false);
  if (pcl::console::find_switch (argc, argv, "-c") != 0 ||
      pcl::console::find_switch (argc, argv, "--cloud") != 0)
    cloud_output = true;

  // Make sure that we have one input and one output file only
  if (file_args.size() != 2)
  {
    PCL_ERROR ("Wrong input/output file count!\n");
    displayHelp (argc, argv);
    return (-1);
  }

  // Convert parsed output type to output type
  int output_type (BINARY);
  if (!parsed_output_type.empty ())
  {
    if (parsed_output_type == "ascii")
      output_type = ASCII;
    else if (parsed_output_type == "binary")
      output_type = BINARY;
    else if (parsed_output_type == "binary_compressed")
      output_type = BINARY_COMPRESSED;
    else
    {
      PCL_ERROR ("Wrong output type!\n");
      displayHelp (argc, argv);
      return (-1);
    }
  }

  // Try to load as mesh
  pcl::PolygonMesh mesh;
  if (boost::filesystem::path (argv[file_args[0]]).extension () != ".pcd" &&
      pcl::io::loadPolygonFile (argv[file_args[0]], mesh) != 0)
  {
    PCL_INFO ("Loaded a mesh with %d points (total size is %d) and the following channels:\n%s\n",
             mesh.cloud.width * mesh.cloud.height, mesh.cloud.data.size (), pcl::getFieldsList (mesh.cloud).c_str ());

    if (cloud_output)
      mesh.polygons.clear();

    if (saveMesh (mesh, argv[file_args[1]], output_type))
      return (-1);
  }
  else if (boost::filesystem::path (argv[file_args[0]]).extension () == ".stl")
  {
    PCL_ERROR ("Unable to load %s.\n", argv[file_args[0]]);
    return (-1);
  }
  else
  {
    // PCD, OBJ, PLY or VTK
    if (boost::filesystem::path (argv[file_args[0]]).extension () != ".pcd")
      PCL_WARN ("Could not load %s as a mesh, trying as a point cloud instead.\n", argv[file_args[0]]);

    //Eigen::Vector4f origin; // TODO: Support origin/orientation
    //Eigen::Quaternionf orientation;
    pcl::PCLPointCloud2::Ptr cloud (new pcl::PCLPointCloud2);
    if (pcl::io::load (argv[file_args[0]], *cloud) < 0)
    {
      PCL_ERROR ("Unable to load %s.\n", argv[file_args[0]]);
      return (-1);
    }

    PCL_INFO ("Loaded a point cloud with %d points (total size is %d) and the following channels:\n%s\n", cloud->width * cloud->height, cloud->data.size (),
              pcl::getFieldsList (*cloud).c_str ());

    if (!savePointCloud (cloud, argv[file_args[1]], output_type))
    {
      PCL_ERROR ("Failed to save %s.\n", argv[file_args[1]]);
      return (-1);
    }
  }
  return (0);
}