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
Reorganize visuals layer #564
Conversation
If we're going to have
or so? Unless there would be a difference between |
The point of (3) is to avoid
..but I'm not really attached to any particular answer. It's just something that should be settled before I rewrite the imports in the examples. |
Makes sense. I'm torn because I don't like having I guess it depends on how we want to think of I think I'm moving toward thinking everything should just stay in |
This is a good point. If we do want Other opinions out there? So far this PR is about 5 minutes of effort, so I won't fuss if we decide to can it :) |
same answer as the answer to "Can transforms be used without the scene graph? Idem for visuals. If they can be used without the scene graph, let them be in In the short term, I'll probably be using visuals, transforms, and the shader chaining system for my work, but not the scene graph, so AFAIC it would make sense to have those things well-separated. |
The dependency graph looks something like this:
So there are many opportunities to break things up, but I'm not sure these all need to be top-level packages. |
I do like the idea of |
For Luke's point of the many import lines, it helps to write Nevertheless, I also think we should keep scene as it is (except maybe for some internal refactoring). Visuals depend on stuff inside the scenegraph. Placing them in a separate subpackage is not going to make that go away. We now found that having a separate subpackage would actually be confusing for most users. For users that only need visuals, I don't think |
Can you precise that? Looking at Luke's dependency graph (but without having much knowledge about the details about the architecture), it would make sense to have:
If we do this, nothing external depends on |
I mean that Visuals depend on things in the scenegraph. Most importantly, Visual is a subclass of Although we could move transforms and shaders out of
I think that separating the visuals out, with |
What things specifically? Having visuals depend on stuff in the scene graph seems dangerous. From a logical standpoint, visuals should bundle GLSL code together to represent graphical objects. All visual objects should be independent. The scene graph is completely different: it gathers many visuals within a transform hierarchy. I see no logical reason for visuals to depend on stuff in the scene graph. It looks like a red flag to me... Besides, @lcampagn's dependency graph does not support this fact that visuals depend on the scene graph... Maybe it is incomplete then?
That's precisely the problem: visuals should not depend on scene (and I used this assumption, supported by Luke's graph, to propose the structure for the packages).
It's not really a problem of import, it's more of a logical issue. The point of having subpackages is to decouple the functionality of a big project like Vispy into different components. Having too many dependencies between those components is bad design. Bidirectional dependencies are particularly dangerous, and I really think that the scene graph should depend on visuals, but not the other way around. |
Ok, so it seems that the core of the issue is that Visuals depend on the scenegraph, or specifically, the fact that Visual is a subclass of Entity. Some history on that: early on we actually did have a separate subpackage for visuals and scenegraph. Entities were wrapping visuals in that approach. But this turned out to result in complex code and code repetition, which is why we refactored towards the current design. Personally, I don't find this a problem. In part because most users will use the visuals in a scenegraph anyway. For other users (like you) importing the visuals from scene should not have any bad side-effects; the library of visuals will consist of much more code than the core of the scenegraph. Maybe we should see |
Yes I can understand that. But I persist to think that it's a bad idea to have such dependency just for a minor technical issue (Visual needs to derive from Entity). IMO it would be worth thinking about how we can resolve this issue by keeping visuals "independent" from the scene graph.
|
Looking at the code if Here is how I see a Visual: "I give you a coordinate system, and you draw something". The scene graph: "Maintain a hierarchy of coordinate systems (entities)" Ideally, we would follow something similar to the entity component system (and I think that's actually where the Entity name comes from in the first place). The scene graph does nothing apart from handling the relationships between the entities. It offers a system where different components can "plug" into entities to provide functionality. The visual component would plug into the transforms, and use that information to draw things in the scene. Someone may want to implement a collision detection system: it would plug into the scene graph and use that information to detect colisions. Separating visuals from the scene graph ensures that each system stays focused on its main task. The visual to draw stuff, the scene graph to maintain a hierarchy of entities. Having visuals being tightly coupled to the scene graph would destroy the entity component design pattern, and it wouldn't make any sense to use entities at all then. |
You have got a point there. Although I am not sure how strict we should follow that pattern. Maybe an example use case:
|
Can |
How would you then modify the transform or parenting etc? |
|
On Mon, Sep 15, 2014 at 4:47 AM, Almar Klein notifications@github.com
|
I would argue that shaders could be a top-level package (composition system + library of reusable GLSL snippets?). Not sure about transforms.
+1 |
Moving Entity along solves the problem, but it's still a bit awkward to have that class there... @rossant Mmm, giving Visual an
I am starting to like this. |
BTW, should all visuals have a |
On Mon, Sep 15, 2014 at 8:04 AM, Cyrille Rossant notifications@github.com
|
On Mon, Sep 15, 2014 at 8:10 AM, Almar Klein notifications@github.com
This is interesting, but too verbose for such a commonly-accessed feature. |
If they inherit from Entity (as is this PR) they should and the have. If they are entity components, then not, since the entity already provides this functionality. |
Doesn't look so good to me... :( |
On Mon, Sep 15, 2014 at 8:11 AM, Cyrille Rossant notifications@github.com
|
Example of how things might work under the hood with the entity component system:
|
We could give the Visual a parent and transform property, but in that case we might as well just inherit from Entity :P This whole discussion is about the compromise between purity and practicality :) |
app.process_events() | ||
app.process_events() | ||
sleep(0.2) | ||
app.process_events() |
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.
This fixed the Travis problem? I wish I knew how to do a confused+flabbergasted emoticon.
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.
Hey, I just noticed that Timer is never stored!
This appears to have a number of good changes -- to make sure I understand, here's what I see:
Is that right? Also, it looked like there were some changes to how Tests pass (other than size), and the changes look reasonable to me (other than my minor comments). It also looks like this was probably a PITA to get right -- thanks for tackling this! I'll let @almarklein and/or @rossant have a look before merge. |
Awesome! I have a look first thing tomorrow morning! |
The changes I made to config are mostly just a reorganization of the module such that the config keys and CLI flags are all defined at the top of the module. This should make it easier to add new keys/flags in the future. |
# Allow any type of object to be converted to ShaderObject if it | ||
# provides a magic method: | ||
if hasattr(obj, '_shader_object'): | ||
obj = obj._shader_object() |
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.
Yeah this looks reasonable to me, I like it being private.
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.
maybe _to_shader_object()
would make it even more clear?
Crap, looks like there were conflicts with @almarklein's last PR, so this will need another rebase. Sorry about that :( |
Err I guess merge instead of rebase since you merged earlier. |
Conflicts: vispy/app/canvas.py vispy/util/config.py
clsname = clsname[:-6] | ||
|
||
# Generate new docstring | ||
doc = _doc_template % (clsname, clsname) |
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.
What about we append the docs of the visual, so that the user can see all possible arguments? Otherwise users must switch back and forth in the docs. The doc template could also be shorter IMO, and instead add some of this more detailed information in the module docstring.
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.
Docstring is now based on the original visual docstring with an extra note about VisualNode inheritance and extra args added to Parameters section.
In examples/basics/scene/nested_viewbox.py In the mesh.py examples the spheres only take up the second half of the screen; the top half is just black. Apart from this and my nitpick comments, this is looking good! |
|
||
def generate_docstring(subclass, clsname): | ||
# Generate a VisualNode docstring by modifying the Visual's docstring | ||
# to include information about VisualNode inheritance and extra init args. |
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.
wow, this apparantly harder then I thought, thanks for going through this :)
Ready for merge, if there are no more comments? |
+1 for me! (side note: is the "size difference" test in Travis of any use??) |
Thanks a lot Luke! I especially like how we were able to converge to a solution that everybody is happy with. That's golden! |
@rossant: let's say a new developer adds a 100MB file to their topic branch and then deletes it right before making a PR. Who is actually going to notice that the repository just took on an extra 100MB of history? We have had this problem in the past and it is a huge ordeal to correct. |
@lcampagn hmm makes sense! |
Reorganization to make visuals a top-level package. Fixes #448.
Only one example currently works; I'll deal with the rest after feed back on a couple of issues:
transforms
be top-level as well?scene.__init__
, but it's a mess. I'd like to make many of the examples look like:vispy.plot
should do something similar, but with a more extensive set of imports aimed toward scientific vis.