-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/nortikin/sverchok
- Loading branch information
Showing
16 changed files
with
464 additions
and
31 deletions.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
Polygon Inscribed Circle | ||
======================== | ||
|
||
Dependencies | ||
------------ | ||
|
||
This node requires SciPy library to work. | ||
|
||
Functionality | ||
------------- | ||
|
||
This node calculates the center and the radius of inscribed circle for each | ||
convex face of the input mesh. Obviously, it is not always possible to inscribe | ||
a circle into a polygon, if polygon is not a triangle. For non-tiangular | ||
polygons, this node calculates the biggest circle which can be inscribed into | ||
the polygon, i.e. the circle which touches as many polygon edges as possible. | ||
|
||
Inputs | ||
------ | ||
|
||
This node has the following inputs: | ||
|
||
- **Vertices**. The vertices of the input mesh. This input is mandatory. | ||
- **Faces**. The faces of the input mesh. This input is mandatory. | ||
|
||
Parameters | ||
---------- | ||
|
||
This node has the following parameters: | ||
|
||
- **Flat Matrix output**. If checked, the node will generate a single flat list | ||
of matrices in the **Matrix** output, for all input meshes. Checked by default. | ||
- **On concave faces**. This parameter is available in the N panel only. | ||
Defines what the node should do if it encounters a concave face. There are | ||
the following options available: | ||
|
||
- **Skip**. Just skip such faces - do not generate inscribed circles for them. | ||
- **Error**. Stop processing and give an error (turn the node red). | ||
- **As Is**. Try to generate an inscribed circle for such face anyway. In | ||
many cases, the generated circle will be incorrect (will be too small or | ||
even outside the polygon), but in some simple cases it can be valid. | ||
|
||
The default option is **Skip**. | ||
|
||
Outputs | ||
------- | ||
|
||
This node has the following outputs: | ||
|
||
- **Center**. For each inscribed circle, this contains a matrix, Z axis of | ||
which points along face normal, and the translation component equals to the | ||
center of the inscribed circle. This output can be used to actually place | ||
circles at their places. | ||
- **Radius**. Radiuses of the inscribed circles. | ||
|
||
Examples of Usage | ||
----------------- | ||
|
||
In many cases inscribed circle can touch only two or three polygon edges: | ||
|
||
.. image:: ../../../docs/assets/nodes/analyzer/inscribed_circle_1.png | ||
:target: ../../../docs/assets/nodes/analyzer/inscribed_circle_1.png | ||
|
||
If the polygon is almost regular, the circle will touch more edges: | ||
|
||
.. image:: ../../../docs/assets/nodes/analyzer/inscribed_circle_2.png | ||
:target: ../../../docs/assets/nodes/analyzer/inscribed_circle_2.png | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# This file is part of project Sverchok. It's copyrighted by the contributors | ||
# recorded in the version control history of the file, available from | ||
# its original location https://github.com/nortikin/sverchok/commit/master | ||
# | ||
# SPDX-License-Identifier: GPL3 | ||
# License-Filename: LICENSE | ||
|
||
import numpy as np | ||
import bpy | ||
from bpy.props import BoolProperty, EnumProperty | ||
from sverchok.node_tree import SverchCustomTreeNode | ||
from sverchok.utils.inscribed_circle import calc_inscribed_circle, ERROR, RETURN_NONE, ASIS | ||
from sverchok.data_structure import updateNode, zip_long_repeat, ensure_nesting_level, get_data_nesting_level | ||
|
||
class SvSemiInscribedCircleNode(SverchCustomTreeNode, bpy.types.Node): | ||
""" | ||
Triggers: Polygon Inscribed Circle | ||
Tooltip: Inscribed circle for an arbitrary convex polygon | ||
""" | ||
bl_idname = 'SvSemiInscribedCircleNode' | ||
bl_label = 'Polygon Inscribed Circle' | ||
bl_icon = 'OUTLINER_OB_EMPTY' | ||
sv_icon = 'SV_POLY_INSCRIBED_CIRCLE' | ||
sv_dependencies = {'scipy'} | ||
|
||
def sv_init(self, context): | ||
self.inputs.new('SvVerticesSocket', "Vertices") | ||
self.inputs.new('SvStringsSocket', "Faces") | ||
self.outputs.new('SvMatrixSocket', "Center") | ||
self.outputs.new('SvStringsSocket', "Radius") | ||
|
||
flat_output : BoolProperty( | ||
name = "Flat Matrix output", | ||
description = "Output single flat list of matrices", | ||
default = True, | ||
update = updateNode) | ||
|
||
concave_modes = [ | ||
(RETURN_NONE, "Skip", "Skip concave faces - do not generate output for them", 0), | ||
(ERROR, "Error", "Generate an error if encounter a concave face", 1), | ||
(ASIS, "As Is", "Try to calculate inscribed circle anyway (it probably will be incorrect)", 2) | ||
] | ||
|
||
on_concave : EnumProperty( | ||
name = "On concave face", | ||
description = "What to do if encounter a concave face", | ||
default = RETURN_NONE, | ||
items = concave_modes, | ||
update = updateNode) | ||
|
||
def draw_buttons(self, context, layout): | ||
layout.prop(self, 'flat_output') | ||
|
||
def draw_buttons_ext(self, context, layout): | ||
self.draw_buttons(context, layout) | ||
layout.label(text = "On concave faces:") | ||
layout.prop(self, 'on_concave', text='') | ||
|
||
def process(self): | ||
if not any(socket.is_linked for socket in self.outputs): | ||
return | ||
|
||
vertices_s = self.inputs['Vertices'].sv_get() | ||
vertices_s = ensure_nesting_level(vertices_s, 4) | ||
faces_s = self.inputs['Faces'].sv_get() | ||
faces_s = ensure_nesting_level(faces_s, 4) | ||
|
||
matrix_out = [] | ||
radius_out = [] | ||
for params in zip_long_repeat(vertices_s, faces_s): | ||
new_matrix = [] | ||
new_radius = [] | ||
for vertices, faces in zip_long_repeat(*params): | ||
vertices = np.array(vertices) | ||
for face in faces: | ||
face = np.array(face) | ||
circle = calc_inscribed_circle(vertices[face], | ||
on_concave = self.on_concave) | ||
if circle is not None: | ||
new_matrix.append(circle.get_matrix()) | ||
new_radius.append(circle.radius) | ||
if self.flat_output: | ||
matrix_out.extend(new_matrix) | ||
else: | ||
matrix_out.append(new_matrix) | ||
radius_out.append(new_radius) | ||
|
||
self.outputs['Center'].sv_set(matrix_out) | ||
self.outputs['Radius'].sv_set(radius_out) | ||
|
||
def register(): | ||
bpy.utils.register_class(SvSemiInscribedCircleNode) | ||
|
||
def unregister(): | ||
bpy.utils.unregister_class(SvSemiInscribedCircleNode) | ||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.