07/06/12 4:34
maikarki
Buongiorno a tutti. Da due giorni sto impazzendo a cercare di scrivere in Vb.Net lo snippet di una libreria Open Source per effettuare Polygon clipping.
La libreria è allegata.
Si tratta di una semplice form con un Panel1.
Il codice in c# riportato da Angus (l'autore) è il seguente:
Il codice in Vb.Net che sembra non funzionare è il seguente
L'autore mi ha riferito che presumbilmente l'errore è da ricercare nel data type delle liste che devono essere INT64. Nel codice ho già tentato la conversione ma un errore InvalidOperationException sin dalle prime righe si manifesta nonappena avvio il debug.
Mi potreste dare una mano?
Vi ringrazio in anticipo.
La libreria è allegata.
Si tratta di una semplice form con un Panel1.
Il codice in c# riportato da Angus (l'autore) è il seguente:
using ClipperLib; using Polygon = List<IntPoint>; using Polygons = List<List<IntPoint>>; ... Polygons subj = new Polygons(2); subj.Add (new Polygon(4)); subj[0].Add(new IntPoint(180, 200)); subj[0].Add(new IntPoint(260, 200)); subj[0].Add(new IntPoint(260, 150)); subj[0].Add(new IntPoint(180, 150)); subj.Add(new Polygon(3)); subj[1].Add(new IntPoint(215, 160)); subj[1].Add(new IntPoint(230, 190)); subj[1].Add(new IntPoint(200, 190)); Polygons clip = new Polygons(1); clip.Add(new Polygon(4)); clip[0].Add(new IntPoint(190, 210)); clip[0].Add(new IntPoint(240, 210)); clip[0].Add(new IntPoint(240, 130)); clip[0].Add(new IntPoint(190, 130)); DrawPolygons(subj, Color.FromArgb(0x16, 0, 0, 0xFF), Color.FromArgb(0x60, 0, 0, 0xFF)); DrawPolygons(clip, Color.FromArgb(0x20, 0xFF, 0xFF, 0), Color.FromArgb(0x30, 0xFF, 0, 0)); Polygons solution = new Polygons(); Clipper c = new Clipper(); c.AddPolygons(subj, PolyType.ptSubject); c.AddPolygons(clip, PolyType.ptClip); c.Execute(ClipType.ctIntersection, solution, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd); DrawPolygons(solution, Color.FromArgb(0x30, 0, 0xFF, 0), Color.FromArgb(0xFF, 0, 0x66, 0));
Il codice in Vb.Net che sembra non funzionare è il seguente
Imports ClipperLib Public Class Form1 Public Polygon As New List(Of IntPoint) Public Polygons As New List(Of List(Of IntPoint)) Public subj = Convert.ToInt64(Polygons(2)) Public clip = Convert.ToInt64(Polygons(1)) Public solution = Convert.ToInt64(Polygons) Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load ' creazione del rettangolo ReDim Preserve subj(4) subj.Add(Polygon(4)) subj(0) = New IntPoint(180, 200) subj(0) = New IntPoint(260, 200) subj(0) = New IntPoint(260, 150) subj(0) = New IntPoint(180, 150) ' creazione del triangolo ReDim Preserve subj(3) subj.Add(Polygon(3)) subj(1) = New IntPoint(215, 160) subj(1) = New IntPoint(230, 190) subj(1) = New IntPoint(200, 190) ReDim Preserve clip(4) clip.Add(Polygon(4)) clip(0) = New IntPoint(190, 210) clip(0) = New IntPoint(240, 210) clip(0) = New IntPoint(240, 130) clip(0) = New IntPoint(190, 130) Dim c As New Clipper() c.AddPolygons(subj, PolyType.ptSubject) c.AddPolygons(clip, PolyType.ptClip) c.Execute(ClipType.ctIntersection, solution, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd) End Sub Private Sub Panel1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint e.Graphics.DrawPolygon(Pens.AliceBlue, subj) e.Graphics.DrawPolygon(Pens.AliceBlue, clip) Me.Invalidate() End Sub End Class
L'autore mi ha riferito che presumbilmente l'errore è da ricercare nel data type delle liste che devono essere INT64. Nel codice ho già tentato la conversione ma un errore InvalidOperationException sin dalle prime righe si manifesta nonappena avvio il debug.
Mi potreste dare una mano?
Vi ringrazio in anticipo.
Ultima modifica effettuata da maikarki 07/06/12 4:58
aaa