3

I am developing an image viewer where graphics are rendered with antialiased mode. Images can be first edited using Autocad that generates DXF files.

The application is written by using Visual C++ and Direct2D.

Although I am able to load the image quite quickly, zoom and especially pan remain a problem for me if compared with the performance of Autocad for the same image (same number of shapes).

Following is the piece of code aimed to render graphics:

auto shapes = quadTree.get_visible_shapes();
shapes.sort_by_Zorder();

for each shape in shapes:
   shape.draw();

After profiling I can say that more than the 90% of the computational time is spent in the loop aimed to draw the shapes.

Drawing only the visible shapes, thanks to the implementation of the Quadtree, has been a huge performance improvement; I also render the graphics in aliased mode while panning, but there is still a big difference with Autocad.

I am wondering if Autocad draws a bitmap representation of the image, even if I didn't try this approach yet so I cannot tell if there could be an effective improvement in speed.

Considering these hypothesis are there any ways to improve the action of pan and zoom?

Nick
  • 10,309
  • 21
  • 97
  • 201

2 Answers2

3

There are few considerations when doing pan on 2D/3D scene, especially when redraw-world is expensive.

  1. Off-screen canvas

    Render your screen onto an off screen bitmap with slightly larger canvas (e.g. w+N * h+N), upon PAN you instantly put up the screen, and update the off-screen one in background. There are also many ways to further optimize on this direction.

    EDIT: More details:

    For example, the screen of your scene is 640x480, the scene itself is 1000x1000, you want to show the region (301, 301) ~ (940, 780). You would instead create an off-screen buffer with, say, 740x580 (ie. N=50) from (251,251) ~ (990, 830). so, if the PAN operation move less than 50 pixel, (e.g. PAN left 5 pixels) you already have such content to instantly render to screen. Also, after PAN you may want to prepare the new off-screen buffer in background (or when idle) so that subsequent PAN can be performed instantly. In case of PAN too far, you still have to wait for it, or reduce the quality of rendering for intermediate screens, and render full details only when PAN stopped - user won't notice details when moving anyway.

  2. Limit update frequency

    PAN operation is usually triggered by mouse (or gesture touch) which may comes at high volume of events. Instead of queue all the 20 mouse move events within that one second and spend 3 seconds redraw the world 20 times, you should limit the update frequency.

Non-maskable Interrupt
  • 3,841
  • 1
  • 19
  • 26
  • Thanks for your effort +1 – Nick Sep 13 '16 at 15:08
  • @Non-maskableInterrupt Very valuable insights. Do you have any suggestions for the time the user zooms out. Now we have all the details and drawing it in the background even to a bitmap will take time. Of course, we should not draw the details that are very small to be visible but how can we decide that to keep the quality of the drawing. – Vahid Nov 08 '18 at 21:20
3

In AutoCAD, there is a mechanism called Adaptive degradation which abort rendering when the FPS falls below a predefined value:

Adaptive degradation

And there is also a lot of optimization. You can not compete with a big program like this.

Maxence
  • 12,868
  • 5
  • 57
  • 69