Q_INVOKABLE void PointCloudProcessor::euclideanClusterExtraction(const QString & cloudName)
	{
		auto cloud = cloudsMap[cloudName];
		_doEuclideanClusterExtraction(cloud);
		setCloudsIndex(clouds().indexOf(EUCLIDEAN_CLUSTERS));
		ModelViewer::draw(cloudsMap[EUCLIDEAN_CLUSTERS]);
	}
	void PointCloudProcessor::readModel(const QUrl & url)
	{
		if (ModelIO::readModel(url))
		{
			setCloudsIndex(clouds().indexOf(INPUT_CLOUD));
			ModelViewer::draw(cloudsMap[INPUT_CLOUD]);
		}
	}
Esempio n. 3
0
void clouds::SpawnClouds()
{
	
	for (int i = 0; i < 80; i++)
	{
		for (int j = 0; j < 60; j++)
		{
			clouds();
		}
	}
}
Esempio n. 4
0
void Assignment1::Init()
{
	// Init VBO here
	glClearColor(0.0f, 0.7f, 1.0f, 0.0f);
	//enable depth test 
	glEnable(GL_DEPTH_TEST);

	rotateAngle = 1;
	translateX = 1;
	scaleAll = 1;
	flyBack = 1;
	cloudMovement = 1;
	explosionRotation = 1;
	explosionSize = 1;
	sizeValue;
	//Generate a default VAO for now 
	glGenVertexArrays(1, &m_vertexArrayID);
	glBindVertexArray(m_vertexArrayID);

	//generate buffers
	glGenBuffers(NUM_GEOMETRY, &m_vertexBuffer[0]);
	glGenBuffers(NUM_GEOMETRY, &m_colorBuffer[0]);

	landScape();
	clouds();
	sun();
	explosion();
	cactus();

	//Load vertex and fragment shaders
	m_programID = LoadShaders(
		"Shader//TransformVertexShader.vertexshader",
		//"Shader//SimpleVertexShader.vertexshader",
		"Shader//SimpleFragmentShader.fragmentshader"
		);

	//Get a handle for our "MVP" uniform
	m_parameters[U_MVP] = glGetUniformLocation(m_programID, "MVP");
	// Use our shader
	glUseProgram(m_programID);

}
int main(int argc, char *argv[])
{
  std::cout << "Syntax is: " << argv[0] << " [-processor 0|1|2] -processor options 0,1,2,3 correspond to CPU, OPENCL, OPENGL, CUDA respectively" << std::endl;
  std::cout << "followed by the kinect2 serials and a last 1 for mirroring" << std::endl;
  std::cout << "Press \'s\' to store both clouds and color images." << std::endl;
  std::cout << "Press \'x\' to store both calibrations." << std::endl;

  if(argc < 3){
    std::cout << "Wrong syntax! specify at least processor and one serial" << std::endl;
    return -1;
  }


  // Set te processor to input value or to default OPENGL
  Processor freenectprocessor = OPENGL;
  freenectprocessor = static_cast<Processor>(atoi(argv[1]));

  // check if mirroring is enabled
  bool mirroring = atoi(argv[argc - 1]) == 1 ? true : false;
  if(mirroring)
  	std::cout << "mirroring enabled" << std::endl;

  // Count number of input serials which represent the number of active kinects
  int kinect2_count = mirroring ? argc - 3 : argc - 2;
  std::cout << "loading " << kinect2_count << " devices" << std::endl;

  // Initialize container structures
  std::vector<K2G *> kinects(kinect2_count);
  std::vector<boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGB>>> clouds(kinect2_count);
  boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer ("3D viewer"));
  viewer->setBackgroundColor (0, 0, 0);

  // Generate all the kinect grabbers
  K2G_generator kinect_generator(freenectprocessor, mirroring, argv);
  std::generate(kinects.begin(), kinects.end(), kinect_generator);

  // Initialize clouds and viewer viewpoints
  for(size_t i = 0; i < kinect2_count; ++i)
  {
  	clouds[i] = kinects[i]->getCloud();

  	clouds[i]->sensor_orientation_.w() = 0.0;
  	clouds[i]->sensor_orientation_.x() = 1.0;
  	clouds[i]->sensor_orientation_.y() = 0.0;
  	clouds[i]->sensor_orientation_.z() = 0.0; 

  	viewer->addPointCloud<pcl::PointXYZRGB>(clouds[i], pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB>(clouds[i]), "sample cloud_" + i);
  	viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud_" + i);
  }

  // Add keyboards callbacks
  PlySaver ps(clouds, false, false, kinects);
  viewer->registerKeyboardCallback(KeyboardEventOccurred, (void*)&ps);
  std::cout << "starting cycle" << std::endl;

  std::chrono::high_resolution_clock::time_point tnow, tpost;

  // Start visualization cycle
  while(!viewer->wasStopped()){

    viewer->spinOnce ();

    tnow = std::chrono::high_resolution_clock::now();

    for(size_t i = 0; i < kinect2_count; ++i)
    	clouds[i] = kinects[i]->updateCloud(clouds[i]);

    tpost = std::chrono::high_resolution_clock::now();
    std::cout << "delta " << std::chrono::duration_cast<std::chrono::duration<float>>(tpost - tnow).count() * 1000 << std::endl;

    for(size_t i = 0; i < kinect2_count; ++i)
    	viewer->updatePointCloud<pcl::PointXYZRGB>(clouds[i], pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> (clouds[i]), "sample cloud_" + i);
  }

  // Close all kinect grabbers
  for(auto & k : kinects)
  	k->shutDown();

  return 0;
}
int main(int argc, const char * argv[]) {
    std::string test_dir, out_dir;
    float chop_z = std::numeric_limits<float>::max();
    bool visualize=false;

    google::InitGoogleLogging(argv[0]);

    v4r::NMBasedCloudIntegration<pcl::PointXYZRGB>::Parameter nm_int_param;
    nm_int_param.min_points_per_voxel_ = 1;
    nm_int_param.octree_resolution_ = 0.002f;

    v4r::NguyenNoiseModel<pcl::PointXYZRGB>::Parameter nm_param;

    int normal_method = 2;

    po::options_description desc("Noise model based cloud integration\n======================================\n**Allowed options");
    desc.add_options()
            ("help,h", "produce help message")
            ("input_dir,i", po::value<std::string>(&test_dir)->required(), "directory containing point clouds")
            ("out_dir,o", po::value<std::string>(&out_dir), "output directory where the registered cloud will be stored. If not set, nothing will be written to distk")
            ("resolution,r", po::value<float>(&nm_int_param.octree_resolution_)->default_value(nm_int_param.octree_resolution_), "")
            ("min_points_per_voxel", po::value<int>(&nm_int_param.min_points_per_voxel_)->default_value(nm_int_param.min_points_per_voxel_), "")
            ("threshold_explained", po::value<float>(&nm_int_param.threshold_explained_)->default_value(nm_int_param.threshold_explained_), "")
            ("use_depth_edges", po::value<bool>(&nm_param.use_depth_edges_)->default_value(nm_param.use_depth_edges_), "")
            ("edge_radius", po::value<int>(&nm_param.edge_radius_)->default_value(nm_param.edge_radius_), "")
            ("normal_method,n", po::value<int>(&normal_method)->default_value(normal_method), "method used for normal computation")
            ("chop_z,z", po::value<float>(&chop_z)->default_value(chop_z), "cut of distance in m ")
            ("visualize,v", po::bool_switch(&visualize), "turn visualization on")
    ;
    po::variables_map vm;
    po::store(po::parse_command_line(argc, argv, desc), vm);
    if (vm.count("help"))
    {
        std::cout << desc << std::endl;
        return false;
    }

    try
    {
        po::notify(vm);
    }
    catch(std::exception& e)
    {
        std::cerr << "Error: " << e.what() << std::endl << std::endl << desc << std::endl;
        return false;
    }


    std::vector< std::string> folder_names  = v4r::io::getFoldersInDirectory( test_dir );

    if( folder_names.empty() )
        folder_names.push_back("");

    int vp1, vp2;
    boost::shared_ptr<pcl::visualization::PCLVisualizer> vis;
    if(visualize)
    {
        vis.reset( new pcl::visualization::PCLVisualizer("registered cloud") );
        vis->createViewPort(0,0,0.5,1,vp1);
        vis->createViewPort(0.5,0,1,1,vp2);
    }

    for (const std::string &sub_folder : folder_names)
    {
        const std::string test_seq = test_dir + "/" + sub_folder;
        std::vector< std::string > views = v4r::io::getFilesInDirectory(test_seq, ".*.pcd", false);

        pcl::PointCloud<pcl::PointXYZRGB>::Ptr big_cloud_unfiltered (new pcl::PointCloud<pcl::PointXYZRGB>);
        std::vector< pcl::PointCloud<pcl::PointXYZRGB>::Ptr > clouds (views.size());
        std::vector< pcl::PointCloud<pcl::Normal>::Ptr > normals (views.size());
        std::vector<std::vector<std::vector<float> > > pt_properties (views.size());
        std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > camera_transforms (views.size());

        for (size_t v_id=0; v_id<views.size(); v_id++)
        {
            clouds[v_id].reset ( new pcl::PointCloud<pcl::PointXYZRGB>);
            normals[v_id].reset ( new pcl::PointCloud<pcl::Normal>);

            pcl::io::loadPCDFile(test_seq + "/" + views[ v_id ], *clouds[v_id]);

            camera_transforms[v_id] = v4r::RotTrans2Mat4f(clouds[v_id]->sensor_orientation_, clouds[v_id]->sensor_origin_);

            // reset view point otherwise pcl visualization is potentially messed up
            Eigen::Vector4f zero_origin; zero_origin[0] = zero_origin[1] = zero_origin[2] = zero_origin[3] = 0.f;
            clouds[v_id]->sensor_orientation_ = Eigen::Quaternionf::Identity();
            clouds[v_id]->sensor_origin_ = zero_origin;

            pcl::PassThrough<pcl::PointXYZRGB> pass;
            pass.setInputCloud (clouds[v_id]);
            pass.setFilterFieldName ("z");
            pass.setFilterLimits (0.f, chop_z);
            pass.setKeepOrganized(true);
            pass.filter (*clouds[v_id]);

            v4r::computeNormals<pcl::PointXYZRGB>( clouds[v_id], normals[v_id], normal_method);

            v4r::NguyenNoiseModel<pcl::PointXYZRGB> nm (nm_param);
            nm.setInputCloud(clouds[v_id]);
            nm.setInputNormals(normals[v_id]);
            nm.compute();
            pt_properties[v_id] = nm.getPointProperties();

            pcl::PointCloud<pcl::PointXYZRGB> cloud_aligned;
            pcl::transformPointCloud( *clouds[v_id], cloud_aligned, camera_transforms[v_id]);
            *big_cloud_unfiltered += cloud_aligned;
        }

        pcl::PointCloud<pcl::PointXYZRGB>::Ptr octree_cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
        v4r::NMBasedCloudIntegration<pcl::PointXYZRGB> nmIntegration (nm_int_param);
        nmIntegration.setInputClouds(clouds);
        nmIntegration.setPointProperties(pt_properties);
        nmIntegration.setTransformations(camera_transforms);
        nmIntegration.setInputNormals(normals);
        nmIntegration.compute(octree_cloud);

        std::cout << "Size cloud unfiltered: " << big_cloud_unfiltered->points.size() << ", filtered: " << octree_cloud->points.size() << std::endl;

        if(visualize)
        {
            vis->removeAllPointClouds(vp1);
            vis->removeAllPointClouds(vp2);
            vis->addPointCloud(big_cloud_unfiltered, "unfiltered_cloud", vp1);
            vis->addPointCloud(octree_cloud, "filtered_cloud", vp2);
            vis->spin();
        }

        if(vm.count("out_dir"))
        {
            const std::string out_path = out_dir + "/" + sub_folder;
            v4r::io::createDirIfNotExist(out_path);
            pcl::io::savePCDFileBinary(out_path + "/registered_cloud_filtered.pcd", *octree_cloud);
            pcl::io::savePCDFileBinary(out_path + "/registered_cloud_unfiltered.pcd", *big_cloud_unfiltered);
        }
    }
}
Esempio n. 7
0
// Create Objects
void TestScene::SetupObjects()
{    
    spObject sun(new Object);
    sun->SetVO(MakeShareable(new PrimitiveUVSphere(256, 128)));
    sun->GetTransform().SetScale(Vector3(2.f, 2.f, 2.f));
    Texture sunTexture;
    LoadTexture(sunTexture, "textures/texture_sun.png");
    sun->GetVO()->GetTexture() = sunTexture;
    sun->SetGLMode(GL_TRIANGLES);
    sun->EnableTexture();
    sun->SetName(L"Sun");
    objects.push_back(sun);
    objectMap.insert(std::make_pair(sun->GetName(), sun));

    spObject world(new Object);
    world->SetVO(MakeShareable(new PrimitiveUVSphere(256, 128)));
    world->GetTransform().SetPosition(Vector3(5.f, 0.f, 0.f));
    Texture worldTexture;
    LoadTexture(worldTexture, "textures/4kworld.png");
    world->GetVO()->GetTexture() = worldTexture;
    world->SetGLMode(GL_TRIANGLES);
    world->EnableTexture();
    world->SetName(L"Earth");
    world->SetParent(sun.Get(), TransformInheritance(true, false, true, false));
    objects.push_back(world);
    objectMap.insert(std::make_pair(world->GetName(), world));


    spObject clouds(new Object);
    clouds->SetVO(MakeShareable(new PrimitiveUVSphere(256, 128)));
    clouds->GetTransform().SetScale(Vector3(1.01f, 1.01f, 1.01f));
    Texture cloudTexture;
    LoadTexture(cloudTexture, "textures/clouds.png");
    clouds->GetVO()->GetTexture() = cloudTexture;
    clouds->SetGLMode(GL_TRIANGLES);
    clouds->EnableTexture();
    clouds->EnableTransparency();
    clouds->SetName(L"Clouds");
    clouds->SetParent(world.Get(), TransformInheritance(true, false, true, false));
    objects.push_back(clouds);
    objectMap.insert(std::make_pair(clouds->GetName(), clouds));

    //spObject disc(new Object);
    //disc->SetVO(new PrimitiveDisc(64));
    //Texture discTexture;
    //LoadTexture(discTexture, "crate.png");
    //disc->GetVO()->GetTexture() = discTexture;
    //disc->SetGLMode(GL_TRIANGLE_FAN);
    //disc->GetTransform().SetPosition(Vector3(2.5f, 0.0f, 0.0f));
    //disc->EnableTexture();
    //disc->SetName(L"Disc");
    //objects.push_back(disc);

    spObject moon(new Object);
    moon->SetVO(MakeShareable(new PrimitiveUVSphere(256, 128)));
    moon->GetTransform().SetScale(Vector3(0.27f, 0.27f, 0.27f));
    moon->GetTransform().SetPosition(Vector3(0.f, 0.f, -2.2f));
    Texture moonTexture;
    LoadTexture(moonTexture, "textures/moonmap1k.png");
    moon->GetVO()->GetTexture() = moonTexture;
    moon->SetGLMode(GL_TRIANGLES);
    moon->EnableTexture();
    moon->SetName(L"Moon");
    moon->SetParent(world.Get(), TransformInheritance(true, false, true, false));
    objects.push_back(moon);
    objectMap.insert(std::make_pair(moon->GetName(), moon));

    spObject hst(new Object);
    hst->SetVO(MakeShareable(new Model));
    static_cast<Model*>(hst->GetVO().Get())->Load("models/hst.obj", "textures/hst.png");
    hst->GetTransform().SetScale(Vector3(0.0001f, 0.0001f, 0.0001f)); // This thing is yuge!
    hst->GetTransform().SetPosition(Vector3(-1.1f, 0.f, 0.f));
    hst->GetTransform().SetPreRotation(Rotation(0.f, Vector3(0.25f, 0.25f, -0.25f)));
    hst->GetTransform().SetRotation(Rotation(0.f, Vector3(-0.2f, 0.8f, -0.2f)));
    hst->SetGLMode(GL_TRIANGLES);
    hst->SetName(L"HST");
    hst->EnableTexture();
    hst->SetParent(world.Get(), TransformInheritance(true, false, true, false));
    objects.push_back(hst);
    objectMap.insert(std::make_pair(hst->GetName(), hst));

    spObject iss(new Object);
    iss->SetVO(MakeShareable(new Model));
    static_cast<Model*>(iss->GetVO().Get())->Load("models/iss.obj", "textures/iss.png");
    iss->GetTransform().SetScale(Vector3(0.01f, 0.01f, 0.01f));
    iss->GetTransform().SetPreRotation(Rotation(0.f, Vector3(0.f, 0.5f, 0.f)));
    iss->GetTransform().SetRotation(Rotation(0.f, Vector3(0.25f, 0.5f, 0.25f)));
    iss->GetTransform().SetPosition(Vector3(0.f, 0.f, 1.2f));
    iss->SetGLMode(GL_TRIANGLES);
    iss->SetName(L"ISS");
    iss->EnableTexture();
    iss->SetParent(world.Get(), TransformInheritance(true, false, true, false));
    objects.push_back(iss);
    objectMap.insert(std::make_pair(iss->GetName(), iss));

    spObject teapot(new Object);
    teapot->SetVO(MakeShareable(new Model));
    static_cast<Model*>(teapot->GetVO().Get())->Load("Models/teapot.obj", "textures/teapot.png");
    teapot->GetTransform().SetPosition(Vector3(5.f, 5.f, -3.f));
    teapot->GetTransform().SetPreRotation(Rotation(0.f, Vector3(1.f, 0.f, 0.f)));
    teapot->GetTransform().SetRotation(Rotation(0.f, Vector3(0.f, 0.f, 1.f)));
    teapot->GetTransform().SetScale(Vector3(0.05f, 0.05f, 0.05f));
    teapot->SetGLMode(GL_TRIANGLES);
    teapot->SetName(L"Teapot");
    teapot->EnableTexture();
    teapot->SetParent(iss.Get(), TransformInheritance(true, true, true, false));
    objects.push_back(teapot);
    objectMap.insert(std::make_pair(teapot->GetName(), teapot));
}