Author Topic: Vectorization Example  (Read 28698 times)

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7121
    • View Profile
    • Cambam V1.0 French Doc
Vectorization Example
« on: June 16, 2015, 17:21:34 pm »
Hello,

A step by step vectorization test done with Illustrator CS3 and CamBam + scripts and plugin.

The source picture:



This picture is opened in Illustrator and is vectorized with the following settings:

Black&Withe , threshold 70, then saved to DXF (attached)

Play with the threshold value to reveal fewer or more details



The DXF is opened into CamBam and contains 858 splines ... but each exists 4 times.

- Select all splines -> convert to polylines  result: 858 polylines. 430 with CW and 428 with CCW direction

- Select all polylines with CW (or CCW) direction with the script that follow.
(first, select all, then run the script)

- Delete all the objects selected by the script.

Code: [Select]
' select CW/CCW polylines
' dh42 06/2015

sub main

'ask for CW/CCW

dim rep as string
dim p as polyline

CamBamConfig.Defaults.ReloadTreeAfterScript = false

rep = inputbox("1 - Select CW " & vbnewline & "2 - Select CCW ",, 1)

if rep <> 1 and rep <> 2 then exit sub

dim newselection as ArrayList = new ArrayList()

if view.SelectedEntities.Length > 0 then


for each ent as Entity in view.SelectedEntities

if typeof ent is Polyline

p = ent

if p.closed = true 'only if closed polyline
select case rep

case 1 'CW

if p.direction = -1 then
newselection.add(ent)
end if

case 2 'CCW

if p.direction = 1 then
newselection.add(ent)
end if

end select

end if

end if

next ent

view.Select(newselection)

view.RefreshView()

end if

end sub


It is important to not remove the overlaps between 2 identical polylines that have a different direction.

Because the routine that convert spline to polyline don't create "exactly" the same result for CW and CCW, when we use remove overlaps, this can cause unwanted lines (and also because calculation speed)

Now, all polylines exists twice (instead 4 times), but all with the same direction.

- Create a new layer, select all the polylines, then do a Remove Overlaps with 0.1 for tolerance.

232 polylines falls on the new layer, and you can delete the other layer with it's old polylines.

- Now, depending of the drawing, you can use the File Cleaner plugin to delete short polylines. In this case, I remove all polylines open/closed in the range 0-3 mm



the result after the treatment



attached, the source picture, the finished .cb file and the raw DXF from Illustrator.

++
David
« Last Edit: June 16, 2015, 17:24:07 pm by dh42 »

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5142
  • Made in England
    • View Profile
Re: Vectorization Example
« Reply #1 on: June 16, 2015, 18:07:19 pm »
David, it looks a good output but would it have been better to 'join' the polylines before running Dave's File Cleaner ?
Filmed in Supermarionation

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7121
    • View Profile
    • Cambam V1.0 French Doc
Re: Vectorization Example
« Reply #2 on: June 16, 2015, 18:27:03 pm »
Hello Eddy

Join do nothing in this case, all the remaining polylines are already closed and it seems that Illustrator don't create broken line that need to be joined .. the only problem is the duplicates polylines ... and depending of the setting in AI I can obtain more that 4 ... maybe there is a tool in AI to remove the overlaps, but I've a very small knowledge of this soft.

++
David

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5142
  • Made in England
    • View Profile
Re: Vectorization Example
« Reply #3 on: June 16, 2015, 18:32:25 pm »
Here's one I did in Inkscape. I followed your instructions other than the settings in Inkscape, I think those settings could have been better if I'd tried several versions.
As you say, join, did very little in this image.
Your script selected just a few lines, Dave's plugin removed quite a lot.
Filmed in Supermarionation

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7121
    • View Profile
    • Cambam V1.0 French Doc
Re: Vectorization Example
« Reply #4 on: June 16, 2015, 18:40:09 pm »
Quote
Your script selected just a few lines, Dave's plugin removed quite a lot.

Yes, certainly because the 2 softs works differently .. AI alway give a pair of polyline CW/CCW by color, maybe InkScape does not ? (and maybe all polyline are not repeated 2, 4 or more time ?)

if I use W&B setting (2 colors), I get 2 pair, with 4 colors I get 4 pair ...etc

++
David

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5142
  • Made in England
    • View Profile
Re: Vectorization Example
« Reply #5 on: June 16, 2015, 18:49:31 pm »
These were my settings in Inkscape, I did not choose them, they were set just as the program loaded, that's why I think they could be made better.
Filmed in Supermarionation

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7121
    • View Profile
    • Cambam V1.0 French Doc
Re: Vectorization Example
« Reply #6 on: June 16, 2015, 19:00:51 pm »
and the CNC version  ;D ;D

++
David


Offline Bubba

  • CNC Jedi
  • *****
  • Posts: 3287
    • View Profile
Re: Vectorization Example
« Reply #7 on: June 16, 2015, 19:59:16 pm »
Nice work and instructions David. Thanks.

Now, I'm trying this in Inscape because that the only program I have to my disposal.. ;D

Currently I'm waiting for the computer to do the "remove overlaps" deal, it takes its sweet time with it. Detail follow shortly. ;D

No Joy! This file is simply to much for my computer.. >:(

One would think this computer have enough ooph.. to do this.. ;D
« Last Edit: June 16, 2015, 20:51:27 pm by Bubba »
My 2¢

Win11, CB(1.0)rc 1(64 bit) Mach3, ESS, G540, 4th Axis, Endurance Laser.

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7121
    • View Profile
    • Cambam V1.0 French Doc
Re: Vectorization Example
« Reply #8 on: June 16, 2015, 20:15:19 pm »
on the last file (cnc), CB takes 45 min to convert 3000 splines to polylines !!

InkSkape give also splines as result ?
 
++
David

Offline Bubba

  • CNC Jedi
  • *****
  • Posts: 3287
    • View Profile
Re: Vectorization Example
« Reply #9 on: June 16, 2015, 21:04:02 pm »
InkSkape give also splines as result ?
*********************
Yes, not all are splines, found handful polylines as well.
My 2¢

Win11, CB(1.0)rc 1(64 bit) Mach3, ESS, G540, 4th Axis, Endurance Laser.

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5142
  • Made in England
    • View Profile
Re: Vectorization Example
« Reply #10 on: June 16, 2015, 21:08:07 pm »
Just for comparison my pc has a windows experience rating of 7.3
Filmed in Supermarionation

Offline Bubba

  • CNC Jedi
  • *****
  • Posts: 3287
    • View Profile
Re: Vectorization Example
« Reply #11 on: June 16, 2015, 21:10:43 pm »
- Select all polylines with CW (or CCW) direction with the script that follow.
(first, select all, then run the script)

- Delete all the objects selected by the script.
**************************
The script does not select anything, no matter what I select #1 or #2 when I hit F5..

My 2¢

Win11, CB(1.0)rc 1(64 bit) Mach3, ESS, G540, 4th Axis, Endurance Laser.

Offline Bubba

  • CNC Jedi
  • *****
  • Posts: 3287
    • View Profile
Re: Vectorization Example
« Reply #12 on: June 16, 2015, 21:19:05 pm »
Just for comparison my pc has a windows experience rating of 7.3
***********

So now what Eddy, we starting "my is bigger than yours" thing? ;D ;D

(Just messing with you Eddy) ;D ;D

I know full well that that my machine is older one,but it does have enough memory to be able to process a couple of vectors. Unless I'm doing something wrong.. ;)
« Last Edit: June 16, 2015, 22:29:20 pm by Bubba »
My 2¢

Win11, CB(1.0)rc 1(64 bit) Mach3, ESS, G540, 4th Axis, Endurance Laser.

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7121
    • View Profile
    • Cambam V1.0 French Doc
Re: Vectorization Example
« Reply #13 on: June 16, 2015, 21:35:20 pm »
Quote
The script does not select anything, no matter what I select #1 or #2 when I hit F5..

The script act only on selected objects ; (and only on polyline, of course) ... you must select all first.

But not sure that the CW/CCW his useful with files that comes from InkScape ..

++
David

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7121
    • View Profile
    • Cambam V1.0 French Doc
Re: Vectorization Example
« Reply #14 on: June 16, 2015, 21:57:22 pm »
Quote
Just for comparison my pc has a windows experience rating of 7.3

I restart on W7 to have a look about this.

It's an old quad core (Q9450) 2.66 Ghz overclocked to 3.2 ghz

Only one core works when converting spline to polyline.

++
David