示例#1
0
文件: extracter.cpp 项目: aa755/cfg3d
    bool compute_object(const int i) {
        // Call get_plane, get_cylinder, get_sphere
        float plane_score = compute_plane(); // plane_inliers_ has the pc.
        float cylinder_score = compute_cylinder(); // cylinder_inliers_ has the pc

        // Select the lowest score and store it in object_inliers_.
        inliers_object_ = (plane_score > cylinder_score ? inliers_plane_ : inliers_cylinder_);

        // inliers_object_ = inliers_plane_;
        // inliers_object_ = inliers_cylinder_;

        // Test if the point cloud is too small
        if (inliers_object_->indices.size() < CUT_THRESHOLD) {
            std::cerr << "object inliers has "<< inliers_object_->indices.size()
                    << " < " << CUT_THRESHOLD <<" points. Aborting..." << std::endl;
            return false;
        }

        /*
        // Debugging info
        pcl::PointCloud<Point>::Ptr best_object_(new pcl::PointCloud<Point>);
        pcl::copyPointCloud(*cloud_filtered, *inliers_object_, *best_object_);
        std::stringstream debug_s0;
        debug_s0 << "no_cluster_object_" << i << ".pcd";
        pcl::io::savePCDFile(debug_s0.str(), *best_object_);
        */

        // Euclidean Clustering
        std::vector<pcl::PointIndices> clusters;
        cluster_.setInputCloud(cloud_filtered);
        cluster_.setIndices(inliers_object_);
        cluster_.extract(clusters);
        std::cout << "Number of Euclidian clusters found: " << clusters.size() << std::endl;

        // Check if there is no clusters
        if (clusters.size() == 0) {
            std::cerr << "No clusters found. Aborting..." << std::endl;
            return false;
        }

        main_cluster_.reset(new pcl::PointIndices(clusters.at(0)));

        // Extract the inliers from the input cloud
        extract.setInputCloud(cloud_filtered);
        extract.setIndices(main_cluster_);
        extract.setNegative(false);

        pcl::PointCloud<Point>::Ptr cloud_plane(new pcl::PointCloud<Point > ());
        extract.filter(*cloud_plane);

        // Test if cluster[0] is too small
        if (main_cluster_->indices.size() < CUT_THRESHOLD) {
            std::cerr << "object cluster[0] has "<< main_cluster_->indices.size()
                    << " < " << CUT_THRESHOLD <<" points. Not writing to disk..." << std::endl;
        } else {
          // Write the inliers to disk
          std::stringstream debug_s;
          if (inliers_object_ == inliers_cylinder_) {
            debug_s << "cylinder_object_" << i << ".pcd";
          } else if (inliers_object_ == inliers_plane_) {
            debug_s << "plane_object_" << i << ".pcd";
          } else {
            debug_s << "unknown_object_" << i << ".pcd";
          }
          pcl::io::savePCDFile(debug_s.str(), *cloud_plane);
          std::cout << "PointCloud representing the extracted component: " <<
            cloud_plane->points.size() << " data points." << std::endl;
        }

        // Remove cluster[0], update cloud_filtered and cloud_normals
        extract.setNegative(true);
        extract.filter(*cloud_filtered);
        extract_normals.setNegative(true);
        extract_normals.setInputCloud(cloud_normals);
        extract_normals.setIndices(main_cluster_);
        extract_normals.filter(*cloud_normals);

        return true;
    }
示例#2
0
  bool AnalyticFormFactor::compute(ShapeName shape, real_t tau, real_t eta, vector3_t transvec,
                                    std::vector<complex_t>& ff,
                                    shape_param_list_t& params, real_t single_layer_thickness,
                                    RotMatrix_t & rot
                                    #ifdef USE_MPI
                                      , woo::MultiNode& world_comm, std::string comm_key
                                    #endif
                                    ) {

    #ifdef FF_VERBOSE
      std::cout << "-- Computing form factor analytically ... " << std::endl;
    #endif
//    #ifdef TIME_DETAIL_1
      woo::BoostChronoTimer compute_timer;
      compute_timer.start();
//    #endif // TIME_DETAIL_1

    switch(shape) {
      case shape_cube:            // cube
        if(!compute_cube(nqx_, nqy_, nqz_, ff, params, tau, eta, transvec)) {
          std::cerr << "error: something went wrong while computing FF for a cube"
            << std::endl;
          return false;
        } // if
        break;
      case shape_box:            // cube or box
        if(!compute_box(nqx_, nqy_, nqz_, ff, shape, params, tau, eta, transvec)) {
          std::cerr << "error: something went wrong while computing FF for a box"
                << std::endl;
          return false;
        } // if
        break;
      case shape_cylinder:        // standing cylinder
        if(!compute_cylinder(params, tau, eta, ff, transvec)) {
          std::cerr << "error: something went wrong while computing FF for a cylinder"
                << std::endl;
          return false;
        } // if
        break;
      case shape_sphere:          // simple sphere
        if(!compute_sphere(params, ff, transvec)) {
          std::cerr << "error: something went wrong while computing FF for a sphere"
                << std::endl;
          return false;
        } // if
        break;
      case shape_prism3:          // triangular prism (prism with 3 sides)
        if(!compute_prism(params, ff, tau, eta, transvec)) {
          std::cerr << "error: something went wrong while computing FF for a prism3"
                << std::endl;
          return false;
        } // if
        break;
      case shape_prism6:          // hexagonal prism (prism with 6 sides)
        if(!compute_prism6(params, ff, tau, eta, transvec)) {
          std::cerr << "error: something went wrong while computing FF for a prism6"
                << std::endl;
          return false;
        } // if
        break;
      case shape_sawtooth_down:      // downwards sawtooth
        if(!compute_sawtooth_down()) {
          std::cerr << "error: something went wrong while computing FF for a sawtooth down"
                << std::endl;
          return false;
        } // if
        break;
      case shape_sawtooth_up:        // upwards sawtooth
        if(!compute_sawtooth_up()) {
          std::cerr << "error: something went wrong while computing FF for a sawtooth up"
                << std::endl;
          return false;
        } // if
        break;
      case shape_prism3x:          // triangular grating in x direction
        if(!compute_prism3x(params, ff, tau, eta, transvec)) {
          std::cerr << "error: something went wrong while computing FF for a prism3x"
                << std::endl;
          return false;
        } // if
        break;
      case shape_pyramid:          // pyramid
        if(!compute_pyramid(params, ff, tau, eta, transvec)){
          std::cerr << "error: something went wrong while computing FF for a pyramid"
                << std::endl;
          return false;
        } // if
        break;
      case shape_trunccone:        // truncated cone
        if(!compute_truncated_cone(params, tau, eta, ff, transvec)) {
          std::cerr << "error: something went wrong while computing FF for a truncated cone"
                << std::endl;
          return false;
        } // if
        break;
      default:
        std::cerr << "error: invalid shape. given shape is not supported" << std::endl;
        return false;
    } // switch

    #ifdef TIME_DETAIL_1
      compute_timer.stop();
      std::cout << "**               FF compute time: " << compute_timer.elapsed_msec() << " ms."
            << std::endl;
    #endif // TIME_DETAIL_1

    return true;
  } // AnalyticFormFactor::compute()