简体   繁体   English

我是否需要担心画布上的最佳绘图?

[英]Do I need to worry about optimal drawing on canvas?

I've to draw a graph on a canvas (bound by a scrollviewer). 我要在画布上绘制一个图形(由scrollviewer绑定)。 And there are about 200 or so nodes in memory. 内存中大约有200个节点。

To keep the things simple, I have derived the nodes from a usercontrol which can render itself. 为了简单起见,我从一个可以自我渲染的usercontrol派生出节点。

But I've not created the lines between the nodes. 但我没有在节点之间创建线条。 I know from MSDN that, 我从MSDN了解到,

On the surface, the Geometry class and the Shape class are quite similar. 在表面上,Geometry类和Shape类非常相似。 Both are used in the rendering of 2D graphics and both have similar concrete classes which derive from them, for example, EllipseGeometry and Ellipse. 两者都用于2D图形的渲染,并且都具有从它们派生的类似的具体类,例如,EllipseGeometry和Ellipse。 However, there are important differences between these two sets of classes. 但是,这两组课程之间存在重要差异。 For one, the Geometry class lacks some of the functionality of the Shape class, such as the ability to draw itself. 首先,Geometry类缺少Shape类的一些功能,例如绘制自身的能力。

Because there can be lot many more nodes, the system may render things slowly. 因为可能有更多的节点,系统可能会慢慢渲染。 Hence, to increase performance, I feel the best choice would be Geometry (custom rendering). 因此,为了提高性能,我觉得最好的选择是Geometry(自定义渲染)。

My questions: 我的问题:

  1. Should I go with Shape or Geometry to draw the lines? 我应该使用Shape或Geometry绘制线条吗?

  2. Should I render only the current viewport area of the scrollviewer to speed up the display (in which case I would have to convert the nodes from controls to geometry objects), or should I just iterate over ALL the nodes and draw lines between them? 我应该只渲染scrollviewer的当前视口区域以加快显示速度(在这种情况下我必须将节点从控件转换为几何对象),还是应该迭代所有节点并在它们之间绘制线条?

  3. Should I render the graph in memory on a bitmap and then flip it? 我应该在位图上的内存中渲染图形然后翻转吗? It sounds more like game programming that general application programming! 听起来更像是一般应用程序编程的游戏编程! :D :d

  4. Doesn't WPF automatically takes care of rendering what's in view and what not for better performance? WPF不会自动处理渲染视图中的内容以及不能获得更好性能的内容吗?

A few points to ponder... 几点要思考......

From your topic I get that you dont want the ability of nodes to redraw themselves as that may make them slower. 从你的主题我得到你不希望节点重绘自己的能力,因为这可能会使它们变慢。 Instead, you want to decide when and which node to draw. 相反,您想要决定何时以及绘制哪个节点。 Am I correct? 我对么?

Well that looks ok to me, however Canvas is never virtualized. 嗯,这看起来不错,但Canvas从未虚拟化。 I recommend going through the codeplex website and download the WPFToolkit source code. 我建议通过codeplex网站下载WPFToolkit源代码。 Under DataVisualization namespace you have several charting controls (even ScatterredChart which is similar to yours where lines are not drawn between nodes) and their source code. DataVisualization命名空间下,您有几个图表控件(甚至ScatterredChart类似于您的节点之间没有绘制线条的ScatterredChart)及其源代码。 Observe what they have done. 观察他们做了什么。 How have they increased performance of their graph tools. 他们如何提高图表工具的性能。

I also came across this artical of how to implement a Scrollable Virtualized Canvas . 我还遇到了关于如何实现Scrollable Virtualized Canvas的技巧 Probably that can help you to achieve fast rendering of nodes over canvas. 可能这可以帮助您在画布上实现节点的快速渲染。

Personally... 亲身...

1] Geometries are lightweight and I like them. 几何是轻量级的,我喜欢它们。

2] Visual HitTesting can help you understand if an item is under rendered region ie within the bounds of the scroll view. 2] Visual HitTesting可以帮助您了解项目是否在渲染区域下,即在滚动视图的范围内。 Otherwise make it hidden so that it doesn draw itself. 否则将其隐藏,以便它不会自己绘制。 "Hidden" and not "Collapsed" because hueristic for scrolling would work fine. “隐藏”而不是“崩溃”,因为滚动的表现会很好。

3] I remember my colleague using even the virtualizing stackpanel with horizontal orientation so that it renders nodes and the unit view ie the region specific to one point on X axis so that such repeating regions would automatially fit together to produce a monolithic graph. 3]我记得我的同事甚至使用具有水平方向的虚拟化堆叠面板,以便渲染节点和单位视图,即特定于X轴上的一个点的区域,以便这样的重复区域将自动地配合在一起以产生单片图形。

Wonderful that impelemntation was! 很棒的是故障!

All the best and keep us posted of your progress on this. 一切顺利,并告诉我们您的进展情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我是否需要担心阻止任务? - Do I need to worry about blocking tasks? 我是否需要担心foreach循环中的Process - Do I need to worry about Process in foreach loop 如果没有静态字段,我是否需要担心对象是线程安全的? - Do I need to worry about an object being thread safe if it has no static fields? x:FieldModifier =“ Private”是做什么的,我应该为此担心吗? - What does x:FieldModifier=“Private” do and should I worry about it? 当我使用以下 SqlDataAdapter 时,是否需要担心插入/更新/删除/注入攻击? - Do I have to worry about inserts/updates/deletes/injection attacks when I use the following SqlDataAdapter? 我应该担心位顺序吗? - Should I worry about bit order? 在这个c#EF场景中我是否需要担心垃圾收集? - Do I have to worry about garbage collection in this c# EF scenario? 我是否需要担心 Rx.NET FromEventPattern 会导致 memory 泄漏? - Do I have to worry about memory leaks with Rx.NET FromEventPattern? 我应该担心这个DateTime数学会失去精度吗? - Should I worry about losing precision with this DateTime math? 我应该担心我的软件被反编译吗? - Should I worry about my software being decompiled?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM