Recent

Author Topic: Vector drawing with floating point coordinates & a zoomable canvas  (Read 8825 times)

trayres

  • Jr. Member
  • **
  • Posts: 92
I apologize if this question is overly broad, but I'm trying to piece together what I need and I'm hoping the discussion will help foment ideas to help nail down how to go about this.

I'm trying to implement something like a schematic capture system - so I know I need a translation between the world and viewport coordinates and I need a transform matrix to do pan/zoom - the way I had done it before (by scaling up the bitmap on the canvas) wasn't good.

So I need to take one of 5 graphics primitives (polygon, rectangle, circle, arc, and text) that is composed of a set of points, compose a class that holds a ragged array of these types that describes what is on the schematic page with methods to set and get collections of items based on if they're within the viewport or not, and then redraw the viewport with all the segments that are contained within the viewport (using something like a Cohen-Southerland algorithm for the polygons and rectangles, and something else to determine clipping for the other items).

This will allow me to pan/zoom arbitrarily and will prevent scaling issues. I also have to be able to resize the viewport when the user resizes the form, rather than scaling the bitmap that's within it (otherwise that'd be goofy behavior).

So I'm starting to work on this - does anyone have thoughts or input? Am I on the right track, or am I crackers?

Thanks all!

zamtmn

  • Hero Member
  • *****
  • Posts: 594

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Vector drawing with floating point coordinates & a zoomable canvas
« Reply #2 on: July 13, 2015, 11:53:59 pm »
I wouldn't use fpvectorial my self it gives me the filling of a half though solution but it has good functionality build in, any way, there is aggpas that is a renderer written in pascal with sub pixel accuracy and everything, as far as I understand it should be able to support everything you just described easily.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

zamtmn

  • Hero Member
  • *****
  • Posts: 594
Re: Vector drawing with floating point coordinates & a zoomable canvas
« Reply #3 on: July 14, 2015, 12:37:51 am »
>>as far as I understand it should be able to support everything you just described easily.
easily and beautifully, but unfortunately very slow and not leaving hope for at least some piece hardware acceleration.
Generally it is not a rasterizer problem, it is necessary to do so that he could be anything - standart canvas, OpenGL context or aggcanvas.

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Vector drawing with floating point coordinates & a zoomable canvas
« Reply #4 on: July 14, 2015, 01:11:31 am »
Take a look at AggPas [https://github.com/graemeg/fpGUI/tree/master/src/corelib/render/software]. From what you describe, AggPas already supports a lot of what you need. vector based graphics, floating point coordinates, transform and rotate, viewports, zoom & rotate, sub-pixel accuracy drawing etc. It should be easy to implement what you need with AggPas.

Some AggPas docs:
  https://github.com/graemeg/fpGUI/tree/master/docs/aggpas
« Last Edit: July 14, 2015, 01:24:46 am by Graeme »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: Vector drawing with floating point coordinates & a zoomable canvas
« Reply #5 on: July 14, 2015, 01:20:27 am »
You can try:

https://github.com/jmpessoa/tfpnoguigraphicsbridge
                           +
https://github.com/jmpessoa/tfpdxfbridge

[real (and floating) world coordinate,  viewport, "dxf" export format, ... ]
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Signal

  • New Member
  • *
  • Posts: 41
Re: Vector drawing with floating point coordinates & a zoomable canvas
« Reply #6 on: July 14, 2015, 02:06:11 am »
Would cairo work for you?

http://cairographics.org/

There is a cairo wrapper included in https://code.google.com/p/luipack/

zamtmn

  • Hero Member
  • *****
  • Posts: 594
Re: Vector drawing with floating point coordinates & a zoomable canvas
« Reply #7 on: July 14, 2015, 10:26:31 am »
So I'm starting to work on this - does anyone have thoughts or input? Am I on the right track, or am I crackers?
For entirely the right way will be better at once lay spatial indexs and primitives lod (level of detail) features

circular

  • Hero Member
  • *****
  • Posts: 4196
    • Personal webpage
Re: Vector drawing with floating point coordinates & a zoomable canvas
« Reply #8 on: July 14, 2015, 07:46:02 pm »
With BGRABitmap, you've got Canvas2d property, where you can set a transformation matrix before rendering. Also there is the TBGRAPath object that can contain a shape, and also you can define a transformation. So for example, each object could have its path object, and you could then draw it on Canvas2d.

To have a surface on the screen, you can use TBGRAVirtualScreen component. In the OnRedraw event, you can draw the current position by setting the matrix and drawing the shapes.
Conscience is the debugger of the mind

trayres

  • Jr. Member
  • **
  • Posts: 92
Re: Vector drawing with floating point coordinates & a zoomable canvas
« Reply #9 on: July 15, 2015, 07:48:32 am »
Hi everyone!

There are a lot of options and it's taking me some time to digest them all; these are all great references and I thank everyone for their input!

I'm looking at OpenGL, but I don't see (any?) modern references to OpenGL for Delphi/Lazarus (everything is for C++), and OpenGL looks very complicated.

The Cairo wrapper in luipack looks great - I'll have to check it out more.

Sorry it is taking so long to formulate a response, I'm trying to check out each thing in turn.  :D

[Edit]For TCairoPaintBox, is it not normally a part of the standard LCL? I'd like something that was part of the standard LCL because I worry about the component becoming unsupported by the mainline developers.
« Last Edit: July 15, 2015, 10:30:42 pm by trayres »

trayres

  • Jr. Member
  • **
  • Posts: 92
Re: Vector drawing with floating point coordinates & a zoomable canvas
« Reply #10 on: July 16, 2015, 10:38:04 pm »
So it looks like I'll be forced to do all the drawing myself - I'm not really sophisticated enough to do OpenGL, so that's out. I need to implement a series of algorithms for transforms of matrices - is there a library that provides this already? Like a Lazarus Math or Lazmath or something that might be useful?

Then I need to get the pixel count of the monitor, find the extent of the window, take the user's current schematic size, determine what items are in the window (including those partially occluded) and draw those bits that are not occluded.

That's what I've worked out so far; this is so much fun!

[EDIT]

I bought "Pascal Plus Data Structures" by Nell Dale and Susan C. Lilly - there is some good material in there that will even go into the matrix math I need. I'll post updates as it goes along.
« Last Edit: July 19, 2015, 09:24:16 pm by trayres »

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Vector drawing with floating point coordinates & a zoomable canvas
« Reply #11 on: July 20, 2015, 07:04:51 am »
I can guide you with OpenGL if that's needed, referring to my nxPascal game engine.

https://github.com/Zaflis/nxpascal/blob/master/src/nxGL.pas#L1312
Code: [Select]
  glGetIntegerv(GL_VIEWPORT, @pdetails^.viewPort);
  glGetDoublev(GL_PROJECTION_MATRIX, @pdetails^.projM);
  glGetDoublev(GL_MODELVIEW_MATRIX, @pdetails^.modelM);
OpenGL has sets of glGet... and glSet... functions. Those lines work both ways if you want to set matrices.

But nxPascal has ready functions you can use to easier set window size and scaling.

Quote
pixel count of the monitor
Screen.Width and Height.

Quote
find the extent of the window
Form1.Width and .Height

Quote
algorithms for transforms of matrices
Yeah there are many functions for matrices:
https://github.com/Zaflis/nxpascal/blob/master/src/nxMath3D.pas#L843

Lastly, to draw a single triangle with OpenGL you can do it with:
Code: [Select]
glBegin(GL_TRIANGLE);
glVertex3f(10, 0, 0); // top
glVertex3f(0, 20, 0); // bottom left
glVertex3f(20, 20, 0); // bottom right
glEnd;

zamtmn

  • Hero Member
  • *****
  • Posts: 594
Re: Vector drawing with floating point coordinates & a zoomable canvas
« Reply #12 on: July 20, 2015, 09:39:58 am »
trayres
You offered a lot of options. I think it would be better to join one of them and not to duplicate work. Although Yes, it's fun))

 

TinyPortal © 2005-2018