wo80 / Triangle.NET

C# / .NET version of Jonathan Shewchuk's Triangle mesh generator.
472 stars 85 forks source link

using the library from IronPyton #41

Closed xyont closed 1 year ago

xyont commented 1 year ago

hi,

interesting library to use, i'm call and loading from IronPyton but failed at triangulation. Any hints or suggestion?

regards,

2023-10-27 11_23_42-test40 py - SciTE

wo80 commented 1 year ago

The polygon.Triangulate(...) methods are extension methods defined in Triangle/Geometry/ExtensionMethods.cs. I've never used IronPython, but you might need to do something like clr.ImportExtensions(TriangleNet.Geometry), see this stackoverflow question.

Alternatively, just use the GenericMesher class, as done by the extension methods.

xyont commented 1 year ago

many thanks for such as guidance, it seems to be working now. Next is related to save mesh results, any example?

2023-10-27 16_11_47-test40 py - SciTE

wo80 commented 1 year ago

Next is related to save mesh results, any example?

It depends on what you actually want to do. You can use FileProcessor.Write(mesh, filename), which uses the original Triangle format. Or access the data of the IMesh directly and write in any format you like using Python...

xyont commented 1 year ago

firstly, i need to save as default format (mesh file & SVG for viewing) but did not succeed in image format,

add commands, IO.SvgImage.Save(mesh, "box.svg", 500) shown a message, AttributeError: 'TriangleNet.IO' object has no attribute 'SvgImage

thanks again, add command IO.FileProcessor.Write(mesh, "box.ele") created output files of Triangle formats.

wo80 commented 1 year ago

NameError: global name 'SvgImage' is not defined

Have you built and added a reference to the Triangle.Rendering assembly? Imported the TriangleNet.Rendering.Text namespace?

xyont commented 1 year ago

add command, clr.ImportExtensions(TriangleNet.Rendering.Text)

shown a message, AttributeError: 'TriangleNet' object has no attribute 'Rendering'

wo80 commented 1 year ago

Have you built and added a reference to the Triangle.Rendering assembly?

You seem to have a Triangle.dll, since clr.AddReference("Triangle.dll") is working. Now you also need to build the src/Triangle.Rendering/Triangle.Rendering.csproj project, which will give you a Triangle.Rendering.dll. Then

clr.AddReference("Triangle.Rendering.dll")

import TriangleNet.Rendering # <- not sure if this one is needed
from TriangleNet.Rendering import *

Text.SvgImage.Save(mesh, "box.svg", 500)

As already mentioned, I don't use IronPython, so I haven't tested the code above, but that seems to be the way IronPython handles .NET assemblies...

xyont commented 1 year ago

hello again, i have some problem in saving .node file, were previously successful for .ele files. Request an output of *.node file did not show any error, but the file is not created or available in the directory.

any suggestion? thank you.

wo80 commented 1 year ago

By default, you should get the .ele file containing the triangle indices and a .poly file, which contains both nodes and segment indices. Please check, if the .poly file is present.