Skip to content
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

Shader API improvements #561

Merged
merged 16 commits into from Apr 20, 2022
Merged

Conversation

guaje
Copy link
Contributor

@guaje guaje commented Mar 28, 2022

This PR includes the following improvements:

  • Improved docstrings for the shaders API.
  • Increased test coverage for the shaders functions.
    • Removed duplicated tests.
  • Fixed No replacement option for Geometry Shaders #546.
  • Fixed billboard actor (Only actor affected by the described changes).

@codecov
Copy link

codecov bot commented Mar 28, 2022

Codecov Report

Merging #561 (3ee06f4) into master (24eddc7) will increase coverage by 0.16%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #561      +/-   ##
==========================================
+ Coverage   88.88%   89.04%   +0.16%     
==========================================
  Files          55       54       -1     
  Lines       11367    11515     +148     
  Branches     1120     1129       +9     
==========================================
+ Hits        10103    10253     +150     
+ Misses        965      962       -3     
- Partials      299      300       +1     
Impacted Files Coverage Δ
fury/fury/shaders/__init__.py 100.00% <0.00%> (ø)
fury/fury/tests/test_window.py 93.73% <0.00%> (ø)
fury/fury/tests/test_primitive.py 100.00% <0.00%> (ø)
fury/fury/tests/test_shaders.py
fury/fury/tests/test_io.py 98.62% <0.00%> (+0.10%) ⬆️
fury/fury/tests/test_actors.py 91.66% <0.00%> (+0.14%) ⬆️
fury/fury/primitive.py 95.23% <0.00%> (+0.28%) ⬆️
fury/fury/actor.py 88.66% <0.00%> (+0.50%) ⬆️
fury/fury/io.py 82.06% <0.00%> (+0.60%) ⬆️
fury/fury/shaders/base.py 92.78% <0.00%> (+2.92%) ⬆️
... and 1 more

@skoudoro
Copy link
Contributor

Hi @guaje,

Why this PR is a draft? Do you plan to add more stuff in here?

@guaje
Copy link
Contributor Author

guaje commented Mar 28, 2022

Why this PR is a draft? Do you plan to add more stuff in here?

Yes, I'm planning to move the get_code function out of the billboard actor. And add some tests to that and the replace_shader_in_actor function.

@guaje guaje changed the title Fix geometry shader replacement Shader API improvements Apr 6, 2022
@guaje guaje marked this pull request as ready for review April 6, 2022 17:56
@guaje guaje requested a review from skoudoro April 6, 2022 17:59
Copy link
Contributor

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @guaje,

Thank you for this update. See below for my comments

"geometry": Shader.Geometry,
"fragment": Shader.Fragment,
}
from os.path import join as pjoin, dirname, isfile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pep8: import order. see https://peps.python.org/pep-0008/#imports for more information

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed, but PTAL.

fury/shaders/tests/test_base.py Show resolved Hide resolved
fury/shaders/tests/test_base.py Outdated Show resolved Hide resolved
Comment on lines +161 to +190
def generate_points():
centers = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])

scene = window.Scene()
scene.add(cube)
if interactive:
scene.add(actor.axes())
window.show(scene)
colors = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) * 255

arr = window.snapshot(scene)
report = window.analyze_snapshot(arr)
npt.assert_equal(report.objects, 1)
vtk_vertices = Points()
# Create the topology of the point (a vertex)
vtk_faces = CellArray()
# Add points
for i in range(len(centers)):
p = centers[i]
id = vtk_vertices.InsertNextPoint(p)
vtk_faces.InsertNextCell(1)
vtk_faces.InsertCellPoint(id)
# Create a polydata object
polydata = PolyData()
# Set the vertices and faces we created as the geometry and topology of the
# polydata
polydata.SetPoints(vtk_vertices)
polydata.SetVerts(vtk_faces)

# test errors
npt.assert_raises(ValueError, shader_to_actor, cube, "error",
vertex_impl)
npt.assert_raises(ValueError, shader_to_actor, cube, "vertex",
vertex_impl, block="error")
npt.assert_raises(ValueError, replace_shader_in_actor, cube, "error",
vertex_impl)
set_polydata_colors(polydata, colors)

mapper = PolyDataMapper()
mapper.SetInputData(polydata)
mapper.SetVBOShiftScaleMethod(False)

point_actor = Actor()
point_actor.SetMapper(mapper)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why restart from scratch and not use a point actor?

To reduce the maintenance, you should try to reduce as much as possible code duplication

fury/shaders/tests/test_base.py Outdated Show resolved Hide resolved
fury/shaders/tests/test_base.py Outdated Show resolved Hide resolved
fury/shaders/tests/test_base.py Show resolved Hide resolved
Copy link
Contributor

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @guaje,

thank you for the update. merging

@skoudoro skoudoro merged commit 17587bd into fury-gl:master Apr 20, 2022
@guaje guaje deleted the fix_geometry_replacement branch April 29, 2022 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No replacement option for Geometry Shaders
2 participants