Board index » delphi » Storing vector graphics for fast retrieval

Storing vector graphics for fast retrieval

Hi Dave,

All operations with vectors should be done with float and the results displayed
on a TImage (or whatever) using conversion ratios for Integer results. For
Zooms, the vectors are clipped by the Image border and the ratio is increased .
For Pan, I did a in-memory bitmap of 3 * Height and 3* Width each time the user
click to pan. You cannot pan more than Full Image Width or Height each time you
cick and move a mouse . It gives a really nice pan .

To store the vectors (Lines, Arcs, Circles, Text, etc), I used records stored on
TList for each type of entitie.

Hope these hints will help...

Pierre

 

Re:Storing vector graphics for fast retrieval


Hi Garry,

 You're right, I should have put  "All operations with vectors COULD be done
with float" instead. Personnally, I find more appropriate for my needs to
work with  Reals, since speed is not an issue.

Pierre

Re:Storing vector graphics for fast retrieval


Not so much a VCL or graphics question for Delphi but a general question on
storing 2D vector graphics. (however the implementation will be in Delphi).

Say for example I'm storing lines, polylines, arcs, circles etc... (storing
in the sense of start point, end point, radius etc...).  I want to be able
to have an image larger than a scrollable canvas.  The image could be huge
(depending on scale).
The data structure / algorithm must be geared towards fast retrieval of
drawing elements when the user scrolls / pans the drawing or zooms in / out.
the way I envisaged doing it was when the user scrolled the drawing, using a
quadtree and querying it for all elements that intersected the rectangles to
be brought into view.  (ie. the user scrolls down to the bottom right,
request the quadtree return all elements that intersect with the 2
rectangles defining the new area on the right and the bottom of the canvas
(assuming not already at the edge)).

Is a quadtree the most efficient means of storing the elements?  The only
reason I wasn't planning on using a HUGE canvas (ie. TImage component) was I
assumed the memory demands would be enormous (not to mention it wouldn't
satisfy zooming).  I wouldn't be storing quadtree nodes down to the pixel
level, more like a grid (leaf size not yet determined).

Any ideas?
Thanks very much,
Dave.

Re:Storing vector graphics for fast retrieval


makes sense. But vectors have no pixel level.

Rene
--
Ing.Buero R.Tschaggelar - http://www.ibrtses.com

Quote
Dave Bullet wrote:

> Is a quadtree the most efficient means of storing the elements?  The only
> reason I wasn't planning on using a HUGE canvas (ie. TImage component) was I
> assumed the memory demands would be enormous (not to mention it wouldn't
> satisfy zooming).  I wouldn't be storing quadtree nodes down to the pixel
> level, more like a grid (leaf size not yet determined).

Re:Storing vector graphics for fast retrieval


| The data structure / algorithm must be geared towards fast retrieval of
| drawing elements when the user scrolls / pans the drawing or zooms in /
out.
| the way I envisaged doing it was when the user scrolled the drawing, using
a
| quadtree and querying it for all elements that intersected the rectangles
to
| be brought into view.  (ie. the user scrolls down to the bottom right,
| request the quadtree return all elements that intersect with the 2
| rectangles defining the new area on the right and the bottom of the canvas
| (assuming not already at the edge)).
|
| Is a quadtree the most efficient means of storing the elements?  The only
| reason I wasn't planning on using a HUGE canvas (ie. TImage component) was
I
| assumed the memory demands would be enormous (not to mention it wouldn't
| satisfy zooming).  I wouldn't be storing quadtree nodes down to the pixel
| level, more like a grid (leaf size not yet determined).

Store your coordinates in real world - Lat lon, UTM etc
Determine view port extents (top,left and bottom, right ) and
use this information to search your quad tree.

Render data by remapping your drawing element vertices.
Plot onto buffered bit map.
BitBlt to canvas.

Garry Kernan

Re:Storing vector graphics for fast retrieval


This may not be sufficient.
Consider a line from (-10000,-10000) to (10000,10000).
It goes through the origin.
Make sure a small window (-1,-1) to (1,1) displays it.

Rene
--
Ing.Buero R.Tschaggelar - http://www.ibrtses.com

Quote
Garry Kernan wrote:

> Store your coordinates in real world - Lat lon, UTM etc
> Determine view port extents (top,left and bottom, right ) and
> use this information to search your quad tree.

Re:Storing vector graphics for fast retrieval


| This may not be sufficient.
| Consider a line from (-10000,-10000) to (10000,10000).
| It goes through the origin.
| Make sure a small window (-1,-1) to (1,1) displays it.

Oh it works alright. I've built a GIS engine.

Consider your viewport as screen coordinates (0,0) to (640,480) or
what ever you choose to size it. You map your drawing element
vertices to these pixels.

Conceptualize US Interstates. Let say the coordinates are in UTM
with a central meridian at zone 13, a false easting of 500,000 using
a standard 6 degree mercator strip and a know error factor of 0.9996.

This means the equator is at 0 and a central line running north to south
roughly in the middle of  contemporous USA is given a value of 500,000
meters

California is aprox -1,000,000 meters from the central meridian.
The east coast at aprox 3,400,000 from the central meridian.
Southern Texas is about 3,000,000 meters from the equator whereas
the Canadian border is somewher around 5,400,000 meters from equator

OK you want to zoom into an area in California. Determine the Zoom
extents in UTM while maintaining aspect ratio. Now determine scaling
factor and offsets. Calculate conversion factor to pixel coordinates.
Map points directly to screen extents.

Once you get your head around the math for remapping coordinates you
can simplify the math into a single process.

If you are using GDI you must realize it's buffering limits and allow for
it.

Garry Kernan

Re:Storing vector graphics for fast retrieval


| All operations with vectors should be done with float and the results
displayed
| on a TImage (or whatever) using conversion ratios for Integer results.

You can store vertices as float but you don't have to. Some GIS use
32 bit integer values complete with implied number of decimals to store
vertices (extra speed). If you are talking Lat Lon you can store world
coordinates down to sub meter levels.

Include the implied decimals when scaling.

Garry Kernan

Re:Storing vector graphics for fast retrieval


Quote
> Any ideas?

Try the VeCAD library http://www.comandor.khv.ru/vecad.htm

Re:Storing vector graphics for fast retrieval


For a similar problem, I store the data as integer, with 1 equal to
1/100 millimeter. Then I use SetMapMode to change Canvas units to 1/100
mm. Using this method, I can zoom just by changing SetMapMode (and
SetViewPortEx and SetWindowsEx) and nothing in my drawing part. To avoid
use of large TImage, I size the TImage to the screen size, manage myself
scrollbar and use SetViewportOrg to move the showed area.

I tried to do this with a TPaintBox but I get strange results. It look
like a bug betwenn TPaintBox and SetMapMode.

Advantage of this method : you only use integer.

I will put this project soon on my web site. If interesting, say it to
me.

--
Eric SIBERT
http://www.multimania.com/esibert

Re:Storing vector graphics for fast retrieval


Quote
In article <3A264746.3CDC2...@multimania.com>, Eric SIBERT wrote:
> I will put this project soon on my web site. If interesting, say it to
> me.

Interesting:)

Gordon

Re:Storing vector graphics for fast retrieval


Have you considered using a CAD system?  A product called Cadvance
(http://www.cadvance.com/) will handle all the data storage and image
display functions.  A Delphi DLL can be used to perform functions.  Custom
objects can be created also.  See http://idt.net/~compvent/cviAttr.html for
an application developed using Cadvance and Delphi.
--
Alexander Medwedew
http://visual-engineering.com/

Re:Storing vector graphics for fast retrieval


Quote
> In article <3A264746.3CDC2...@multimania.com>, Eric SIBERT wrote:
> > I will put this project soon on my web site. If interesting, say it to
> > me.

> Interesting:)

The project using SetMapmode to perform easy zoom function, printing and
print preview is on my web site :
http://www.multimania.com/esibert/informatique/graphic/graphic.htm

topic : application form

--
Eric SIBERT
http://www.multimania.com/esibert

Re:Storing vector graphics for fast retrieval


Quote
In article <3A2B5B6B.E2544...@multimania.com>, Eric SIBERT wrote:
> The project using SetMapmode to perform easy zoom function, printing and
> print preview is on my web site :

> http://www.multimania.com/esibert/informatique/graphic/graphic.htm

> topic : application form

Ok, thanks Eric I'll take a look.

Gordon

Other Threads