Не подтверждена Коммит 66e39d61 создал по автору Victor Doval's avatar Victor Doval Зафиксировано автором GitHub
Просмотр файлов

Output Numpy property to Field nodes (#4104)

* Vector Field Apply output numpy prop

* Vector Field Eval and Scalar Field Eval output numpy

* vector field lines output numpy
владелец ea520b4e
......@@ -14,6 +14,11 @@ This node has the following inputs:
* **Field**. The field to be evaluated. This input is mandatory.
* **Vertices**. The points at which the field is to be evaluated. The default value is `(0, 0, 0)`.
Parameters
----------
* **Output NumPy**. Outputs NumPy arrays in stead of regular python lists. Improves performance
Outputs
-------
......@@ -21,10 +26,14 @@ This node has the following output:
* **Value**. The values of the field at the specified points.
Performance Notes
-----------------
This node works faster when the vertices list are NumPy arrays
Example of usage
----------------
Use the values of scalar field to scale the cubes:
.. image:: https://user-images.githubusercontent.com/284644/79475246-dc352280-8020-11ea-8f8d-ddd3d6ca7a73.png
......@@ -24,6 +24,11 @@ This node has the following inputs:
will mean that the node returns the result of field application to the result
of first application. The default value is 1.
Parameters
----------
* **Output NumPy**. Outputs NumPy arrays in stead of regular python lists. Improves performance
Outputs
-------
......@@ -31,6 +36,11 @@ This node has the following output:
* **Vertices**. The result of the vector field application to the original points.
Performance Notes
-----------------
This node works faster when the vertices list are NumPy arrays
Examples of usage
-----------------
......@@ -41,4 +51,3 @@ Apply noise vector field to the points of straight line segment:
Apply the same field to the same points, by only by a small amount; then apply the same field to the resulting points, and repeat that 10 times:
.. image:: https://user-images.githubusercontent.com/284644/79487987-7b164a80-8032-11ea-8197-c78314843ffa.png
......@@ -16,6 +16,11 @@ This node has the following inputs:
* **Field**. The vector field to be evaluated. This input is mandatory.
* **Vertices**. The points at which to evaluate the field. The default value is `(0, 0, 0)`.
Parameters
----------
* **Output NumPy**. Outputs NumPy arrays in stead of regular python lists. Improves performance
Outputs
-------
......@@ -23,6 +28,11 @@ This node has the following output:
* **Vectors**. The vectors calculated at the provided points.
Performance Notes
-----------------
This node works faster when the vertices list are NumPy Arrays
Examples of usage
-----------------
......@@ -33,4 +43,3 @@ Replace each point of straight line segment with the result of noise vector fiel
Visualize vector field vectors by connecting original points of the line segment and the points obtained by moving the original points by the results of vector field evaluation:
.. image:: https://user-images.githubusercontent.com/284644/79476395-5d40e980-8022-11ea-846b-68da09ed2e41.png
......@@ -36,6 +36,8 @@ This node has the following parameters:
the same length (defined by **Steps** input). Otherwise, length of segments
will be proportional to vector norms. Checked by default.
* **Join**. If checked, join all lines into single mesh object. Checked by default.
* **Output NumPy**. Outputs NumPy arrays in stead of regular python lists. Improves performance
Outputs
-------
......@@ -43,10 +45,14 @@ Outputs
* **Vertices**. The vertices of generated lines.
* **Edges**. The edges of generated lines.
Performance Notes
-----------------
This node works faster when the vertices list are NumPy Arrays
Example of usage
----------------
Visualize some vector field:
.. image:: https://user-images.githubusercontent.com/284644/79495842-a56e0500-803e-11ea-91ed-611abf181ec2.png
......@@ -23,6 +23,12 @@ class SvScalarFieldEvaluateNode(bpy.types.Node, SverchCustomTreeNode):
bl_icon = 'OUTLINER_OB_EMPTY'
sv_icon = 'SV_EVAL_SCALAR_FIELD'
output_numpy: BoolProperty(
name='Output NumPy',
description='Output NumPy arrays (improves performance)',
default=False,
update=updateNode)
def sv_init(self, context):
self.inputs.new('SvScalarFieldSocket', "Field")
d = self.inputs.new('SvVerticesSocket', "Vertices")
......@@ -30,6 +36,11 @@ class SvScalarFieldEvaluateNode(bpy.types.Node, SverchCustomTreeNode):
d.default_property = (0.0, 0.0, 0.0)
self.outputs.new('SvStringsSocket', 'Value')
def draw_buttons_ext(self, context, layout):
layout.prop(self, 'output_numpy')
def rclick_menu(self, context, layout):
layout.prop(self, "output_numpy")
def process(self):
if not any(socket.is_linked for socket in self.outputs):
return
......@@ -49,11 +60,11 @@ class SvScalarFieldEvaluateNode(bpy.types.Node, SverchCustomTreeNode):
value = field.evaluate(*vertex)
new_values = [value]
else:
XYZ = np.array(vertices)
XYZ = vertices if isinstance(vertices, np.ndarray) else np.array(vertices)
xs = XYZ[:,0]
ys = XYZ[:,1]
zs = XYZ[:,2]
new_values = field.evaluate_grid(xs, ys, zs).tolist()
new_values = field.evaluate_grid(xs, ys, zs) if self.output_numpy else field.evaluate_grid(xs, ys, zs).tolist()
values_out.append(new_values)
self.outputs['Value'].sv_set(values_out)
......@@ -63,4 +74,3 @@ def register():
def unregister():
bpy.utils.unregister_class(SvScalarFieldEvaluateNode)
......@@ -19,16 +19,22 @@ class SvVectorFieldApplyNode(bpy.types.Node, SverchCustomTreeNode):
bl_icon = 'OUTLINER_OB_EMPTY'
sv_icon = 'SV_APPLY_VFIELD'
coefficient : FloatProperty(
name = "Coefficient",
default = 1.0,
update = updateNode)
iterations : IntProperty(
name = "Iterations",
default = 1,
min = 1,
update = updateNode)
coefficient: FloatProperty(
name="Coefficient",
default=1.0,
update=updateNode)
iterations: IntProperty(
name="Iterations",
default=1,
min=1,
update=updateNode)
output_numpy: BoolProperty(
name='Output NumPy',
description='Output NumPy arrays (improves performance)',
default=False,
update=updateNode)
def sv_init(self, context):
self.inputs.new('SvVectorFieldSocket', "Field")
......@@ -39,6 +45,11 @@ class SvVectorFieldApplyNode(bpy.types.Node, SverchCustomTreeNode):
self.inputs.new('SvStringsSocket', "Iterations").prop_name = 'iterations'
self.outputs.new('SvVerticesSocket', 'Vertices')
def draw_buttons_ext(self, context, layout):
layout.prop(self, 'output_numpy')
def rclick_menu(self, context, layout):
layout.prop(self, "output_numpy")
def process(self):
if not any(socket.is_linked for socket in self.outputs):
return
......@@ -81,7 +92,7 @@ class SvVectorFieldApplyNode(bpy.types.Node, SverchCustomTreeNode):
new_vectors = np.dstack((new_xs[:], new_ys[:], new_zs[:]))
new_vectors = np.array(coeffs)[np.newaxis].T * new_vectors[0]
vertices = vertices + new_vectors
new_verts = vertices.tolist()
new_verts = vertices if self.output_numpy else vertices.tolist()
verts_out.append(new_verts)
......@@ -92,4 +103,3 @@ def register():
def unregister():
bpy.utils.unregister_class(SvVectorFieldApplyNode)
......@@ -18,6 +18,12 @@ class SvVectorFieldEvaluateNode(bpy.types.Node, SverchCustomTreeNode):
bl_icon = 'OUTLINER_OB_EMPTY'
sv_icon = 'SV_EVAL_VECTOR_FIELD'
output_numpy: BoolProperty(
name='Output NumPy',
description='Output NumPy arrays (improves performance)',
default=False,
update=updateNode)
def sv_init(self, context):
self.inputs.new('SvVectorFieldSocket', "Field")
d = self.inputs.new('SvVerticesSocket', "Vertices")
......@@ -25,6 +31,11 @@ class SvVectorFieldEvaluateNode(bpy.types.Node, SverchCustomTreeNode):
d.default_property = (0.0, 0.0, 0.0)
self.outputs.new('SvVerticesSocket', 'Vectors')
def draw_buttons_ext(self, context, layout):
layout.prop(self, 'output_numpy')
def rclick_menu(self, context, layout):
layout.prop(self, "output_numpy")
def process(self):
if not any(socket.is_linked for socket in self.outputs):
return
......@@ -41,13 +52,13 @@ class SvVectorFieldEvaluateNode(bpy.types.Node, SverchCustomTreeNode):
value = field.evaluate(*vertex)
new_values = [tuple(value)]
else:
XYZ = np.array(vertices)
XYZ = vertices if isinstance(vertices, np.ndarray) else np.array(vertices)
xs = XYZ[:,0]
ys = XYZ[:,1]
zs = XYZ[:,2]
new_xs, new_ys, new_zs = field.evaluate_grid(xs, ys, zs)
new_vectors = np.dstack((new_xs[:], new_ys[:], new_zs[:]))
new_values = new_vectors[0].tolist()
new_values = new_vectors if self.output_numpy else new_vectors[0].tolist()
values_out.append(new_values)
......
......@@ -7,7 +7,7 @@ from bpy.props import FloatProperty, EnumProperty, BoolProperty, IntProperty, St
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode, zip_long_repeat, repeat_last_for_length, match_long_repeat, ensure_nesting_level
from sverchok.utils.logging import info, exception
from sverchok.utils.sv_mesh_utils import mesh_join
from sverchok.utils.mesh_functions import mesh_join
class SvVectorFieldLinesNode(bpy.types.Node, SverchCustomTreeNode):
"""
......@@ -19,32 +19,44 @@ class SvVectorFieldLinesNode(bpy.types.Node, SverchCustomTreeNode):
bl_icon = 'OUTLINER_OB_EMPTY'
sv_icon = 'SV_VECTOR_FIELD_LINES'
step : FloatProperty(
name = "Step",
default = 0.1,
min = 0.0,
update = updateNode)
iterations : IntProperty(
name = "Iterations",
default = 10,
min = 1,
update = updateNode)
normalize : BoolProperty(
name = "Normalize",
default = True,
update = updateNode)
join : BoolProperty(
name = "Join",
default = True,
update = updateNode)
step: FloatProperty(
name="Step",
default=0.1,
min=0.0,
update=updateNode)
iterations: IntProperty(
name="Iterations",
default=10,
min=1,
update=updateNode)
normalize: BoolProperty(
name="Normalize",
default=True,
update=updateNode)
join: BoolProperty(
name="Join",
default=True,
update=updateNode)
output_numpy: BoolProperty(
name='Output NumPy',
description='Output NumPy arrays (improves performance)',
default=False,
update=updateNode)
def draw_buttons(self, context, layout):
layout.prop(self, 'normalize', toggle=True)
layout.prop(self, 'join', toggle=True)
def draw_buttons_ext(self, context, layout):
self.draw_buttons(context, layout)
layout.prop(self, 'output_numpy')
def rclick_menu(self, context, layout):
layout.prop(self, "output_numpy")
def sv_init(self, context):
self.inputs.new('SvVectorFieldSocket', "Field")
self.inputs.new('SvVerticesSocket', "Vertices")
......@@ -53,7 +65,7 @@ class SvVectorFieldLinesNode(bpy.types.Node, SverchCustomTreeNode):
self.outputs.new('SvVerticesSocket', 'Vertices')
self.outputs.new('SvStringsSocket', 'Edges')
def generate_all(self, field, vertices, step, iterations):
def generate_all(self, field, vertices, step, iterations, output_numpy):
new_verts = np.empty((iterations, len(vertices), 3))
for i in range(iterations):
xs = vertices[:,0]
......@@ -68,7 +80,7 @@ class SvVectorFieldLinesNode(bpy.types.Node, SverchCustomTreeNode):
vertices = vertices + step * vectors
new_verts[i,:,:] = vertices
result = np.transpose(new_verts, axes=(1, 0, 2))
return result.tolist()
return result if output_numpy else result.tolist()
def process(self):
if not any(socket.is_linked for socket in self.outputs):
......@@ -101,16 +113,13 @@ class SvVectorFieldLinesNode(bpy.types.Node, SverchCustomTreeNode):
new_verts = []
new_edges = []
else:
new_verts = self.generate_all(field, np.array(vertices), step, iterations)
new_verts = self.generate_all(field, np.array(vertices), step, iterations, self.output_numpy)
new_edges = [[(i,i+1) for i in range(iterations-1)]] * len(vertices)
if self.join:
new_verts, new_edges, _ = mesh_join(new_verts, new_edges, [[]] * len(new_verts))
if self.join:
field_verts.append(new_verts)
field_edges.append(new_edges)
else:
field_verts.extend(new_verts)
field_edges.extend(new_edges)
field_verts.extend(new_verts)
field_edges.extend(new_edges)
verts_out.extend(field_verts)
edges_out.extend(field_edges)
......@@ -123,4 +132,3 @@ def register():
def unregister():
bpy.utils.unregister_class(SvVectorFieldLinesNode)
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать