Object2d

Sono nuovamente qui a rompere le scatole con il mio lettore DXF
Utilizzando Object2d visualizzo in un canvas un file .dxf
Solo che davvero davvero troppo troppo lento.
Un file da 2.7 mbyte viene elaborato in 8/9 minuti.
Cio viene disegnato in 7/8 minuti.
Un minuto per leggere il file e dividerlo nelle varie entit utilizzando degli array di classi. Una volta predisposto le varie classi con tutte le entit: cerchio, linea, arco, punto, testo, polilinea. Chiamo un metodo che ho chiamato drawdxfgeometry che alla fine crea tanti oggetti object2d raggruppati in oggetti group2d.
Quando ho creato tutte le entit object2d disegno nel canvas sfruttando un flag boolean e l’evento invalidate.
Non c’ un modo di rendere il disegno pi veloce ? 8/9 minuti sono davvero tanti.

Qui il link del progettino…

I have no quick answer but it is the DrawBezier routine that is slow.
remove it and the DXF renders quickly

try this setting and it reduces the time by a lot:

Non ho una risposta rapida ma la routine di DrawBezier che lento.
Rimuoverlo e il DXF rende rapidamente

Provare questa impostazione e riduce il tempo per un sacco:

	[quote]		'increase "10" to a bigger number for a smoother curve
			'note these are the *plotted* points, they have nothing to
			'do with how many control points there are in the curve

			points = [b]4[/b] *ubound(x)
			[/quote]

I did not think so, good!
By inserting 4 as a line entity, the drawing is generated much faster.
Now i try to find a way to read drawing entities faster using another system instead of a class array

Sorry, I don’t speak Italian, but I found your project nice to play with (and an impressive project). Of course it runs better with 64 Bit and looks better with HiDPI. But anyway, I included a few optimizations which make it a bit faster with all architectures. And I moved the drawBezier interpolation factor you talked about to a shared property “BezierDrawQuality”:
Download

I had copied the routines for bezier curve from an old project in vb5; and not remember the factor for number of lines in entity.
Hownewer ask your google drive access confirm for see your optimizations.
Thank

Sorry! I hope the link works now!

Now with your mods is fast but not furious…
Now going to study quadratic pline and block reference…
Do not you know a fast system to determine the size of several object2d objects?
I was thinking of drawing them first in a buffer to determine the size and the zoom factor.
Not all drawings because almost all have the specified dimensions. But not all.

Yes, like I wrote: Slightly optimized :wink:
I guess you are developing on Windows? The speed increased a lot on a Mac with 64 Bit enabled, but for Windows this could be no option yet. I guess you could still quench a bit more speed out of it by optimizing some calculations like

if entita(contatore).codice = "10" then f_arco.x1 = entita(contatore).descrizione.Val if entita(contatore).codice = "20" then f_arco.y1 = entita(contatore).descrizione.Val

into case selects or skipping unnecessary clauses in code like

if e_linee(contatore).x1 > x_max then x_max = e_linee(contatore).x1 if e_linee(contatore).x2 > x_max then x_max = e_linee(contatore).x2

maybe like

x_max = if (e_linee(contatore).x2 > x_max, e_linee(contatore).x, if (e_linee(contatore).x1 > x_max, e_linee(contatore).x1, x_max))

You should try to avoid having calculations in the exit condition for a loop and use a temporary variable wherever possible (I installed “limit As Integer” on several places – maybe overdone it – but could have missed a few places).
Depending on how often these loops are run, it could enhance the performance another bit.

But in general, as you are calculating most of the maths on the CPU (read that: in code), I am afraid there won’t be much to optimize as long as you don’t employ GPU-based math or drawing routines (which frankly would be a very different kind of beast).

Every once in a while I happen to use windows, but it’s like eating chestnuts in the fall …
Finished the fall, finished chestnuts …

I never really tried to measure the speed of a type IF instruction rather than a SELECT CASE type construct; I thought the second was much faster. Good ! Better so, thank you so much, I learned something new today too …

All code in domisure methos is only temporary, for see the drawing if in DXF file $EXTMIN and $EXTMAX is not present or not defined. ( Some CAD software does not export these references ).

Have another problem with ellipse, now going try to use figureshape or curveshape for emulate this…
For now work for move drawing with mouse and make zoom system.

I wouldn’t say so in general, but in the first piece of code I mentioned (if entita(contatore).codice = “10” etc.), entita(contatore).codice can only be one value. Your code runs though all the if clauses which is unnecessary, therefore a Select would be much better – or several if / elseifs (which are currently not advisable on 64 Bit due to a bug in the framework).

Another proposal for your color method would be build an array of colors in the order the colors are defined in advance or on the first run and then only return color(index). The impact would probably only noticeable on DXFs which use color beyond black.

So this is a Mac project or xplatform?

For color method, my proposal are add a layer selection ad color/hidden/visibility change.
Now have take part of ObjectsInCanvas xojo sample, with this sistem is possible use many object and modify

Late make code for select proper entity …
New Code

I noticed the performance is way down again, due to the loops in SelectedObject.
As this is a property in your class, there can only be one selected object at a time, right? Or will it be possible to selected several objects at once?

If the first is true, replace SelectedObject by

[code]Public Property SelectedObject as CanvasObject
Get
Return mSelectedObject
End Get

Set
if mSelectedObject <> nil then mSelectedObject.Selected = false
mSelectedObject = value
mSelectedObject.Selected = true
ObjectSelected(value)
Invalidate(False)
End Set
End Property[/code]

You don’t need to run the DeselectAll method which slows your project down that much.

If (later) several objects should be selectable, store these in an Array or Dictionary where you can change their selected status easily and add or remove them. Don’t run through all your CanvasObjects each time; this consumes too much time proportionally to the complexity of your drawing.

OOOK.
Now on github, link are here

Ulrich, if you help me finish it, we can put it on the Xojo project page.