Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: Yoann Courtois on January 30, 2019, 06:23:25 PM
-
Hi !
I'm currently trying to selected 3D model faces using their vertex coordinates, but I'm not able to find any link between faces (Metashape.Model.Face) and vertices (Metashape.Model.Vertex).
Indeed, the first one is included ".vertices", but it's only a tuple of three numbers (which looks to be vertices number or key) and no coordinates.
The second one is included ".coord", but no number (key ?).
Then, model vertices have coordinates but no link with faces, and so faces have no positioning informations.
Could someone help ?
Regards
-
Hello Yoann,
You can use the following script as a reference:
https://www.agisoft.com/forum/index.php?topic=7898.msg37698#msg37698
It selects/removed the polygons (faces) which vertices are outside the bounding box.
Looping though faces you can check the coordinates of their vertices and see, if they fit the conditions or not.
-
Hello Alexey,
After some investigations, I still don't understand how it could work like that.
At first : "checkFaceTask" is called :
def checkFaceTask(face):
global vertices
face_vertices = [vertices[v] for v in face.vertices]
checkFace(face, face_vertices)
But face.vertices is just a tuple of 3 integers.
So then, "checkFace" take as parameters "face", which is a model.face, and "face_vertices", which is a list of 3 integers:
def checkFace(face, face_vertices):
global region
R = region.rot # Bounding box rotation matrix
C = region.center # Bounding box center vector
size = region.size
remove_vertices = 0
for vertex in face_vertices:
v = vertex.coord
v.size = 3
v_c = v - C
v_r = R.t() * v_c
if abs(v_r.x) > abs(size.x / 2.):
remove_vertices += 1
elif abs(v_r.y) > abs(size.y / 2.):
remove_vertices += 1
elif abs(v_r.z) > abs(size.z / 2.):
remove_vertices += 1
else:
continue
if remove_vertices == 3:
face.selected = True
Then how it's possible to call vertex.coord for vertex in face_vertices, because vertex become an integer, so no .coord exist
After some test in Metashape console, I got the same fail.
Regards
-
Hello Yoann,
Here's is simple example:
import Metashape
x_min, x_max = 100, 200
y_min, y_max = 100, 200
z_min, z_max = 100, 200
chunk = Metashape.app.document.chunk
model = chunk.model
vertices = model.vertices
faces = model.faces
for face in faces:
face_vertices = [vertices[v] for v in face.vertices]
fit_vert = 0
for vertex in face_vertices:
v = vertex.coord
#may need to convert coordinates from internal to geographic:
#v = chunk.transform.matrix.mulp(v)
#v = chunk.crs.project(v)
if (x_min < v.x < x_max) and (y_min < v.y < y_max) and (z_min < v.z < z_max):
fit_vert += 1
if fit_vert == 3:
face.selected = True
it selects the polygons (faces) that have all their vertex coordinates fitting some pre-defined bounds.
The definition of face_vertices includes access to the array of vertices, so it is not just a list of the indices, it already contains the Vertex elements.
-
Okey ! Thank you, now I see !
It might be great to update the API documentation, and explain that chunk.model.faces- .vertices is indeed a tuple of integer, but those integers are the location of the 3 vertices in the chunk.model.vertices list !
Regards
-
Hello Yoann,
Basically speaking face.vertices tuple includes the indices of the related vertices and not the Vertex() class objects themselves.