generating point cloud views from CAD with renderview function

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

generating point cloud views from CAD with renderview function

pandamonium
This post has NOT been accepted by the mailing list yet.
Hello,

I am reviewing some existing code for a project. In this code there is a function that is supposed to generate model views from a CAD model of a pallet. By talking with the autor I know (and I can see it from what he has given to me) that He was able to generate a certain number of .pcd files, but if I execute the same code in output I have a strange file with a lot of points, but that I am not able to see.
Here is one of the .pcd views that I am supposed to receive after executing the program: supposed_output.png

Here is what I get: real_output.png

The "supposed" .pcd file weights a bunch of kB and contains roughly 800 points, while the one that I get from my program weights 3MB and "contains" 60k points (even if I can't see anything).

At the bottom of this post you will find the code of the function I am talking about. Now my question: this code was written in 2010, is there any change in the renderView function that I am not aware of? Have you experienced such a strange behaviour before?

Thanks

int generateModelViewsFromCAD(string CADFilename, string viewsDir)
{
        vector<ObjectPointCloud<pcl::PointXYZ> > modelClouds;

        string filename = CADFilename;
        boost::shared_ptr<pcl::rec_3d_framework::MeshSource<pcl::PointXYZ> > mesh_source(new pcl::rec_3d_framework::MeshSource<pcl::PointXYZ>);

        if (filename.find(".obj") != filename.npos)
        {
                cout << "Generate syntetic views from CAD: " << CADFilename << endl;
                vtkSmartPointer < vtkOBJReader > readerQuery = vtkSmartPointer < vtkOBJReader > ::New();
                readerQuery->SetFileName(CADFilename.c_str()); //"/home/adryll/Desktop/impulso_dataset/pallet2.obj");
                vtkSmartPointer < vtkPolyData > polydata = readerQuery->GetOutput();
                polydata->Update();
               
                cout << "CAD FILENAME: " << CADFilename.c_str() << endl;
               
                int viewport;
                pcl::visualization::PCLVisualizer vis("Visualizer");

                vis.addModelFromPolyData(polydata, "mesh1", 0);

                vector<double> angles;
                double angle = 0;
                int num_views=10;
               
                for (int i = 0; i < num_views; i++)
                {
                        pcl::visualization::Camera camera;
                        ObjectPointCloud<pcl::PointXYZ> cloud_out;

                        camera.pos[0] = 2;
                        camera.pos[1] = 1;
                        camera.pos[2] = i * 0.05 - 2.5;
                        camera.view[0] = 0;
                        camera.view[1] = 1;
                        camera.view[2] = 0;
                        camera.window_size[0] = 640;
                        camera.window_size[1] = 480;
                        camera.focal[0] = camera.focal[1] = camera.focal[2] = 0;

                        vis.setCameraParameters(camera);
                       
                        vis.updateCamera();
                        vis.resetCamera();
                       
                        vis.setRepresentationToSurfaceForAllActors();
                        pcl::PointCloud<pcl::PointXYZ>::Ptr cloud = cloud_out.getPointCloudPtr();
                       
                        vis.renderView(32, 32, cloud);
                        sleep(1);

                        angle = atan2(camera.pos[2], camera.pos[0]);
                        modelClouds.push_back(cloud_out);
                        angles.push_back(angle);
                }

                string dir = viewsDir;
                stringstream str2;
                str2 << dir.c_str() << "/" << "model_files.txt";
                std::ofstream out_stream(str2.str().c_str(), ifstream::out);
                for (int i = 0; i < modelClouds.size(); i++)
                {
                        stringstream str;
                        str << dir.c_str() << "/" << "model_" << i << ".pcd";
                        cout << str.str().c_str() << endl;

                        modelClouds[i].SavePointCloud(str.str());
                       
                        out_stream << str.str() << "\t" << angles[i] << endl;
                }
                out_stream.close();

        }
        else
        {
                mesh_source->setPath(CADFilename);
                mesh_source->setResolution(150);
                mesh_source->setTesselationLevel(1);
                mesh_source->setViewAngle(57.f);
                mesh_source->setRadiusSphere(1.5f);
                mesh_source->setModelScale(1.0f);
                cout << "Generating in: " << viewsDir << endl;
                mesh_source->generate(viewsDir);
                cout << "Generated  in: " << viewsDir << endl;

        }
}

Reply | Threaded
Open this post in threaded view
|

Re: generating point cloud views from CAD with renderview function

pandamonium
This post has NOT been accepted by the mailing list yet.
Sorry if I write again just to tell you that I am at my first experience with a big project using the PCL library. Up to now I used it only for academic purposes.
Reply | Threaded
Open this post in threaded view
|

Re: generating point cloud views from CAD with renderview function

pandamonium
This post has NOT been accepted by the mailing list yet.
I solved the issue by replacing renderView with the new renderTesselatedSphere function.
Reply | Threaded
Open this post in threaded view
|

Re: generating point cloud views from CAD with renderview function

Tomanlon
This post has NOT been accepted by the mailing list yet.
hi i am using renderViewTesselatedSphere for training cad model to object recognition and pose estimation,but i cant know the meaning of pose,can you share me your  experience。 thank you in advance!