-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add polydata conversors to edges and faces #759
Draft
AlejandroFernandezLuces
wants to merge
12
commits into
main
Choose a base branch
from
feat/named-selections-plot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
94ffc46
feat: Add polydata conversors to edges and faces
AlejandroFernandezLuces b3527f6
Merge branch 'main' into feat/named-selections-plot
AlejandroFernandezLuces dab83c9
Add return to selections
AlejandroFernandezLuces 017adfa
Merge branch 'feat/named-selections-plot' of https://github.com/ansys…
AlejandroFernandezLuces 4d9f56f
Merge branch 'main' into feat/named-selections-plot
AlejandroFernandezLuces 88309c1
Merge branch 'main' into feat/named-selections-plot
AlejandroFernandezLuces f6e5bca
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a00e06f
feat(wip): Add circles and ellipses polydata to edges
AlejandroFernandezLuces fbac463
Merge branch 'feat/named-selections-plot' of https://github.com/ansys…
AlejandroFernandezLuces fa80782
feat(wip): Circle edges working
AlejandroFernandezLuces 1b61381
feat(wip): Ellipse edges working
AlejandroFernandezLuces 2643fd9
feat(wip): Add surface polydata
AlejandroFernandezLuces File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -28,13 +28,15 @@ | |||||
from ansys.api.geometry.v0.faces_pb2 import CreateIsoParamCurvesRequest | ||||||
from ansys.api.geometry.v0.faces_pb2_grpc import FacesStub | ||||||
from ansys.api.geometry.v0.models_pb2 import Edge as GRPCEdge | ||||||
from beartype.typing import TYPE_CHECKING, List | ||||||
from beartype.typing import TYPE_CHECKING, List, Union | ||||||
from pint import Quantity | ||||||
import pyvista as pv | ||||||
|
||||||
from ansys.geometry.core.connection.client import GrpcClient | ||||||
from ansys.geometry.core.connection.conversions import grpc_curve_to_curve, grpc_surface_to_surface | ||||||
from ansys.geometry.core.designer.edge import Edge | ||||||
from ansys.geometry.core.errors import protect_grpc | ||||||
from ansys.geometry.core.logger import LOG | ||||||
from ansys.geometry.core.math.point import Point3D | ||||||
from ansys.geometry.core.math.vector import UnitVector3D | ||||||
from ansys.geometry.core.misc.checks import ensure_design_is_active | ||||||
|
@@ -358,6 +360,72 @@ def __grpc_edges_to_edges(self, edges_grpc: List[GRPCEdge]) -> List[Edge]: | |||||
) | ||||||
return edges | ||||||
|
||||||
def _to_polydata(self) -> Union[pv.PolyData, None]: | ||||||
""" | ||||||
Return the face as polydata. | ||||||
|
||||||
This is useful to represent the face in a PyVista plotter. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Returns | ||||||
------- | ||||||
Union[pv.PolyData, None] | ||||||
Face as polydata | ||||||
""" | ||||||
if self.surface_type == SurfaceType.SURFACETYPE_PLANE: | ||||||
# get vertices from edges | ||||||
vertices = [ | ||||||
vertice | ||||||
for edge in self.edges | ||||||
for vertice in [edge.start_point.flat, edge.end_point.flat] | ||||||
] | ||||||
# TODO remove duplicate vertices | ||||||
# build the PyVista face | ||||||
vertices_order = [len(vertices)] | ||||||
vertices_order.extend(range(len(vertices))) | ||||||
|
||||||
return pv.PolyData(vertices, faces=vertices_order, n_faces=1) | ||||||
elif self.surface_type == SurfaceType.SURFACETYPE_CYLINDER: | ||||||
cyl_pl = pv.Cylinder( | ||||||
center=list(self.shape.geometry.origin), | ||||||
direction=[ | ||||||
self.shape.geometry.dir_x, | ||||||
self.shape.geometry.dir_y, | ||||||
self.shape.geometry.dir_z, | ||||||
], | ||||||
radius=self.shape.geometry.radius.magnitude, | ||||||
) | ||||||
return cyl_pl | ||||||
elif self.surface_type == SurfaceType.SURFACETYPE_CONE: | ||||||
cone_pl = pv.Cone( | ||||||
center=list(self.shape.geometry.origin), | ||||||
direction=[ | ||||||
self.shape.geometry.dir_x, | ||||||
self.shape.geometry.dir_y, | ||||||
self.shape.geometry.dir_z, | ||||||
], | ||||||
height=self.shape.geometry.height.magnitude, | ||||||
radius=self.shape.geometry.radius.magnitude, | ||||||
angle=self.shape.geometry.half_angle.magnitude, | ||||||
) | ||||||
return cone_pl | ||||||
elif self.surface_type == SurfaceType.SURFACETYPE_TORUS: | ||||||
torus_pl = pv.ParametricTorus( | ||||||
ringradius=self.shape.geometry.major_radius.magnitude, | ||||||
crosssectionradius=self.shape.geometry.minor_radius.magnitude, | ||||||
) | ||||||
torus_pl.translate(self.shape.geometry.origin) | ||||||
return torus_pl | ||||||
|
||||||
elif self.surface_type == SurfaceType.SURFACETYPE_SPHERE: | ||||||
sphere_pl = pv.Sphere( | ||||||
center=list(self.shape.geometry.origin), | ||||||
radius=self.shape.geometry.radius.magnitude, | ||||||
) | ||||||
return sphere_pl | ||||||
else: | ||||||
LOG.warning("Cannot convert non-planar faces to polydata.") | ||||||
return None | ||||||
|
||||||
def create_isoparametric_curves( | ||||||
self, use_u_param: bool, parameter: float | ||||||
) -> List[TrimmedCurve]: | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.