LiangliangNan / Easy3D

A lightweight, easy-to-use, and efficient C++ library for processing and rendering 3D data
GNU General Public License v3.0
1.35k stars 243 forks source link

[Question] Having issues rendering PointsDrawable and LinesDrawable with custom code and the Tutorial_301_Drawables #149

Closed joeybinz closed 1 year ago

joeybinz commented 1 year ago

I am trying to use Easy3D to visualize a graph, and eventually build models from different kinds of graphs, however I seem to be unable to get any PointsDrawable to render. I have tried several approaches and so far been unable to figure out what is causing this.

Firstly, I attempted to run the Tutorial_301_Drawable, and only get a rendering of a rabbit with around 1/3 of the polygons missing with no spheres for vertices or bounding box visible. I copied and pasted the entire file ([https://3d.bk.tudelft.nl/liangliang/software/easy3d_doc/html/_tutorial_301__drawables-example.html] and ran it without making any adjustments. Pressing v or b to hide or show vertices and boundaries does not do anything.

Result:

image

Additionally I have tried to add a graph model to the viewer with vertices and a few edges, when I run Tutorial_108_graph I get three vertices plotted & three lines between them (however the lines do seem to fade in and out of existence as I rotate the graph around). However anytime I try to put my own points in the graph (by creating vertices from a point cloud file) and then add a few edges, nothing renders in the viewer. I have posted my code below:

The beginning is loading a pcl file containing the point cloud data using the Point Cloud Library.

`int main(int argc, char **argv) {

// Read in point cloud files
//take in filtered ground & tree clouds, 
std::string groundfilename = "";
std::string treefilename = "";

// check and read Command line arguments
if( argc != 3 ) {
pcl::console::print_error("Invalid CLI arguments, ./segment <groundfile.pcd> <treefile.pcd>");
return -1;
}

else {
groundfilename = argv[1];
groundfilename = "../pcdFiles/" + groundfilename;

treefilename = argv[2];
treefilename = "../pcdFiles/" + treefilename;

}

pcl::PointCloud<pcl::PointXYZ>::Ptr ground_cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr tree_cloud (new pcl::PointCloud<pcl::PointXYZ>);

pcl::PCDReader reader;

reader.read(groundfilename, *ground_cloud);
reader.read(treefilename, *tree_cloud);

auto data = tree_cloud->points;

// Initialize Easy3D.
initialize();
Graph* g = new Graph;

//Vector to keep track of vertexes
std::vector<Graph::Vertex> vtxs;

//Add vertices
for( int i = 0; i < data.size(); i++ ) {

    vtxs.push_back(g->add_vertex(vec3(data[i].x, data[i].y, data[i].z)));

}

// Add some edges
g->add_edge(vtxs[0], vtxs[1]); // e0
g->add_edge(vtxs[0], vtxs[3]); // e1
g->add_edge(vtxs[1], vtxs[4]); // e2

Viewer viewer("viewer");

viewer.add_model(g, true);

viewer.fit_screen();

return viewer.run();

} `

Is there something I am doing wrong with how I am trying to model the graph? To me it seems like I am doing almost exactly the same thing as the example was but it is not working. Thank you for any help!

LiangliangNan commented 1 year ago

Tutorial_301_Drawable is to show how to create different types of drawables, so shortcuts of the viewers won't work. I have just disabled the viewer usage in the console window (The shortcuts only work for instances of Models, like SurfaceMeshes).

For graph visualization, have you tried to load the graph.ply (in the resources/data folder) to the default viewer (Tutorial_201_Viewer_default)? What does it look like?

From the description, it seems the depth test is corrupted (and it also seems your GPU doesn't support geometry shader, which is required to render points as spheres, and lines as cylinders). To figure it out, try to build Tutorial_301_Drawable from the source code (instead of copying it from anywhere else), and change the first line of code in the main() function to initialize(true); (add true to the argument list). This will log your GPU information in a log file stored next to your exe file. Please post this log file here, and then we can further investigate.

joeybinz commented 1 year ago

What would be the easiest way to build the tutorial directly from the source code? Is there a cmake flag I need to turn on when building the entire library for that?

LiangliangNan commented 1 year ago

Nothing has to be set. Built it like other software, and you will see them after building it.

joeybinz commented 1 year ago

Sorry for the later response, here is the log file you asked for

================================================================= program started ... V 10/01/2023 11:39:18.264 logging.cpp:203] executable path: /home/jbinz/repos/Easy3D/tutorials/bin V 10/01/2023 11:39:18.264 logging.cpp:204] current working dir: /home/jbinz/repos/Easy3D/tutorials/bin V 10/01/2023 11:39:18.348 viewer.cpp:298] OpenGL vendor: VMware, Inc. V 10/01/2023 11:39:18.348 viewer.cpp:299] OpenGL renderer: llvmpipe (LLVM 9.0.1, 256 bits) V 10/01/2023 11:39:18.348 viewer.cpp:300] OpenGL version requested: 3.2 V 10/01/2023 11:39:18.348 viewer.cpp:301] OpenGL version received: 3.3 (Core Profile) Mesa 20.0.4 V 10/01/2023 11:39:18.348 viewer.cpp:302] GLSL version received: 3.30 W 10/01/2023 11:39:18.348 viewer.cpp:311] MSAA is not available (4 samples requested) V 10/01/2023 11:39:18.348 viewer.cpp:321] viewer size (width/height): 800/600 V 10/01/2023 11:39:18.348 viewer.cpp:326] DPI scaling: 1 V 10/01/2023 11:39:18.351 resource.cpp:49] resource directory: /home/jbinz/repos/Easy3D/resources V 10/01/2023 11:39:18.351 text_renderer.cpp:756] loaded font 'en_Earth-Normal.ttf' in texture (512 x 512) V 10/01/2023 11:39:18.351 text_renderer.cpp:756] loaded font 'en_Roboto-Medium.ttf' in texture (512 x 512) I 10/01/2023 11:39:21.635 viewer.cpp:560] viewer terminated. Bye!

Additionally when I try to load graph.ply in Tutorial_201 nothing seems to render (the viewer is empty).

joeybinz commented 1 year ago

Tutorial_301_Drawables.log

Reposting the log with better formatting

LiangliangNan commented 1 year ago

Oh, the log shows that the renderer was not the GPU, but a software rasterizer. I think the reason was the graphics driver was not (properly) installed, or the right GPU was not found. If that was the reason, you might also experience very low framerate if you run other 3D graphics application. I suggest you update your graphics driver and build the program again (a clean build) and see if that solves the problem. If still the same problem, please also post here your type of the GPU and the CMake log file.

joeybinz commented 1 year ago

Currently updating my graphics drivers, I'm running Easy3D off of my WSL2 on my windows 11 machine (RTX 3070) Would wsl be causing these issues?

LiangliangNan commented 1 year ago

I believe that is the problem (due to the lack of GPU driver for WSL, and thus it uses Mesa for software rasterization). If you run it on the native windows, it will take advantage of your powerful GPU.

joeybinz commented 1 year ago

Ah I see, I'll have to look into how difficult it would be to move the project I'm working on to windows since it is currently based in Linux, Thank you for all of your help though

joeybinz commented 1 year ago

Just wanted to send a quick update, I managed to get my project moved over & all the necessary dependencies installed natively on windows and everything seems to be working now! image

LiangliangNan commented 1 year ago

Glad to hear that :-) Running natively the performance benefits from your powerful GPU. BTW, the same code will also work on Linux and Mac.

Since the issue has been solved, I will close it. Good luck with your project!