Closed Bobkk-k closed 12 months ago
else if (key == GLFW_KEY_I && modifiers == 0) {
for (auto m : models_) {
for (auto d : m->renderer()->points_drawables())
{
auto cloud = dynamic_cast<PointCloud*>(m);
if (cloud)
{
auto colors = cloud->add_vertex_property<vec3>("v:color");
auto categories = cloud->get_vertex_property<int>("v:category");
for (auto v : cloud->vertices()) {
std::cout << v <<std::endl;
int category = categories[v];
/*srand(category);*/
colors[v] = random_color();
}
}
d->set_coloring(Drawable::COLOR_PROPERTY, Drawable::VERTEX, "v:color");
}
}
}
What are the errors did you see? Better to post the error messages or snapshots here.
Besides, your code also has logical errors.
colors[v] = random_color()
is apparently not correct, because it assigns a random color for each vertex.
The correct way to do it is to first generate a unique color for each category. Then for each vertex you assign the predefined color queried based on its category.
What are the errors did you see? Better to post the error messages or snapshots here.
Besides, your code also has logical errors.
colors[v] = random_color()
is apparently not correct, because it assigns a random color for each vertex. The correct way to do it is to first generate a unique color for each category. Then for each vertex you assign the predefined color queried based on its category.
Thanks to your reply. I'm sorry I didn't express my problem clearly, I main problem is I don't know which function to use to make vertexs colorize by its color property. set_coloring
function seems dosen't work. But I have find a function to do this, it is update_color_buffer().
now I met a new problem. The update_color_buffer()
function dosen't work, after I use set_uniform_coloring
function. It seems once I use set uniform_coloring
function, I can't colorize my vertexs by different colors. Thanks again!
Your previous question:
You can call Drawable::update()
function after calling to set_coloring(...)
to actually transfer the color information to GPU. You will also need to call your viewer's update()
function to update the display.
Your second question:
Of course, because you asked to use uniform color for all vertices (because of the call to set_uniform_coloring()
).
I got it. Thank you so much!!
I want to implement the point cloud to be colored by categories, this is I currently according to the tutorial to write, but always report errors, can you help me?