Meshlab按颜色选择顶点的方法及脚本编写咨询
Why Your Black Vertex Selection Failed
First off, you’re absolutely right about the color range! Meshlab uses normalized RGB values (0.0 to 1.0) instead of the 0-255 integer scale we often use in image editors. That’s why your r=0 and g=0 and b=0 expression didn’t work—plus, floating-point precision quirks mean some "black" vertices might have tiny non-zero values (like 0.0001) that slip past an exact match.
Correct Expression for Black Vertices (0,0,0)
Use this reliable expression in the Select by Expression filter (found under Filters > Selection > Select by Expression):
r < 0.001 && g < 0.001 && b < 0.001
The small threshold accounts for minor floating-point inaccuracies common in mesh data. If you’re 100% sure your mesh has perfectly precise black values, you can use r == 0 && g == 0 && b == 0, but the threshold version is way more robust.
Selecting White Vertices (255,255,255)
Since 255/255 = 1.0, use this thresholded expression for white vertices:
r > 0.999 && g > 0.999 && b > 0.999
Or for exact matches (if you trust the precision):
r == 1 && g == 1 && b == 1
Selecting Any Custom RGB Color
For a color like (128, 0, 255), first convert each component to the 0-1 scale by dividing by 255:
- R: 128/255 ≈ 0.502
- G: 0/255 = 0.0
- B: 255/255 = 1.0
Then use a range check to avoid missing vertices due to precision:
abs(r - 0.502) < 0.001 && abs(g - 0.0) < 0.001 && abs(b - 1.0) < 0.001
The abs() function checks if the vertex’s color falls within a tiny window of your target value, which catches almost all intended matches.
Quick Step-by-Step to Apply
- Load your mesh in Meshlab.
- Navigate to
Filters > Selection > Select by Expression. - Paste your custom RGB expression into the text field.
- Hit
Applyto select all matching vertices.
内容的提问来源于stack exchange,提问作者user9350618

