modified triangulation method
This commit is contained in:
parent
074156f464
commit
62d0fc23fd
|
@ -9,6 +9,7 @@ from __future__ import annotations
|
||||||
import math
|
import math
|
||||||
import sys
|
import sys
|
||||||
from typing import List
|
from typing import List
|
||||||
|
from hub.hub_logger import logger
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from trimesh import Trimesh
|
from trimesh import Trimesh
|
||||||
import trimesh.intersections
|
import trimesh.intersections
|
||||||
|
@ -242,24 +243,32 @@ class Polygon:
|
||||||
|
|
||||||
polygon = shapley_polygon(coordinates)
|
polygon = shapley_polygon(coordinates)
|
||||||
|
|
||||||
vertices_2d, faces = trimesh.creation.triangulate_polygon(polygon, engine='triangle')
|
try:
|
||||||
mesh = Trimesh(vertices=vertices, faces=faces)
|
vertices_2d, faces = trimesh.creation.triangulate_polygon(polygon, engine='triangle')
|
||||||
|
mesh = Trimesh(vertices=vertices, faces=faces)
|
||||||
|
|
||||||
# check orientation
|
# check orientation
|
||||||
normal_sum = 0
|
normal_sum = 0
|
||||||
for i in range(0, 3):
|
for i in range(0, 3):
|
||||||
normal_sum += normal[i] + mesh.face_normals[0][i]
|
normal_sum += normal[i] + mesh.face_normals[0][i]
|
||||||
|
|
||||||
if abs(normal_sum) <= 1E-10:
|
if abs(normal_sum) <= 1E-10:
|
||||||
new_faces = []
|
new_faces = []
|
||||||
for face in faces:
|
for face in faces:
|
||||||
new_face = []
|
new_face = []
|
||||||
for i in range(0, len(face)):
|
for i in range(0, len(face)):
|
||||||
new_face.append(face[len(face)-i-1])
|
new_face.append(face[len(face)-i-1])
|
||||||
new_faces.append(new_face)
|
new_faces.append(new_face)
|
||||||
mesh = Trimesh(vertices=vertices, faces=new_faces)
|
mesh = Trimesh(vertices=vertices, faces=new_faces)
|
||||||
|
|
||||||
return mesh
|
return mesh
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
logger.error(f'Not able to triangulate polygon\n')
|
||||||
|
sys.stderr.write(f'Not able to triangulate polygon\n')
|
||||||
|
_vertices = [[0, 0, 0], [0, 0, 1], [0, 1, 0]]
|
||||||
|
_faces = [[0, 1, 2]]
|
||||||
|
return Trimesh(vertices=_vertices, faces=_faces)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def triangles(self) -> List[Polygon]:
|
def triangles(self) -> List[Polygon]:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user