MoI discussion forum
MoI discussion forum

Full Version: Costa's minimal surface

From: bemfarmer
17 Oct 2015   [#1]
Not having javascript code for a Weierstrass function: :-)

Data for a Costa minimal surface for PovRay were downloaded from here:
https://github.com/andrejbauer/costa-surface
After much effort and learning, the .csv file was converted to an .obj file.
The file costa-object.inc, a simple PovRay include file with vertices and triangle corner indices,
proved to be convenient to use with Excel and Notepad++,
to convert it first to a comma delimited .csv file, and then to a simple .obj file.

Using Notepad++, the ">," were Replaced with "blank".
Also, the "blank <" were converted first to "<," for use in Excel as a .csv,
Excel was then used to remove some decimals,(unnecessary?), and more importantly, increment
the face indices numbers by 1, as PovRay uses zero indexing face numbers,
whereas .obj apparently uses indexing starting at "1".
In the excel Developer tab, an excel macro was used to do the +1 to all of the face indices..
The Excel command button code, using cells G1:G10 for testing is:

Private Sub CommandButton1_Click()
On Error Resume Next
Set C = Range("G1:G10").Cells.SpecialCells(xlCellTypeConstants)
For Each cc In C
cc.Value = cc.Value + 1
Next
End Sub

The macro command button was explained here:
http://www.excel-easy.com/vba/create-a-macro.html
The increment macro was a variation with (face indices) cells B1:B3408, C1:C3408, and D1:C3408, from here:
http://www.mrexcel.com/forum/excel-questions/468109-macro-increment-cell-value-one.html

(To save the working file, the Excel macro command button file has to be saved in macro enabled xlsm file.)
(Very puzzling at the time, note that when ImportObj script encountered a 0 face index, it quit at 6 faces, also, Obj23dm.exe did better, but produced ~30% incorrect triangles with the 0 indexing.)
This strange behavior was corrected by adding +1 to the indices.
The vertex normals were discarded, but could have been converted also. Later Moi can export an .obj with vertex normals.

After deleting the command button, and saving file as .csv, Notepad++ was then used again.
The exponential notations such as 3.12E-14 were replaced by 0 (probably unneccesary?),
using Replace with Checkbox Regular Expressions selected, with the search
(\d\.\d\d)E-14 replaced with "0" (Similarly for E-15, E-16, and E-17.)
The "<," were replaced by either "v " for the vertices, or "f " for the faces.
(vertex normals would have been "vn " if they had been included.) (note space(s))
The csv delimiter "," were replaced by " ". (note space)
The .csv file is now renamed to .obj. It is a barebones .obj, with vertex x,y,z list,
and also face indice triplets, indicating the vertex of each triangle.
Michaels obj23dm.exe can be used on th .obj now, or the new script of Max Smirnov,

ImportObj can be used to get the .obj into Moi as a .3dm. This file is ~10mb.
SubdivBeta9 can be run on the .3dm, for a file of ~14mb. There is still some "creasing."
Rendering was done on both the re-exported Moi .3dm, and the subdivBeta9 .3dm, in KeyShot5.

- Brian


Attachments:
CostaMinSurface.obj

Image Attachments:
CostaSurface2.png 


From: bemfarmer
17 Oct 2015   [#2] In reply to [#1]
The prior image used a Moi object export from the subdivBeta9 costa.
This image is Moi object export of the original costa surface.
Default Moi obj saves were done in both cases.

- Brian



From: amur (STEFAN)
18 Oct 2015   [#3]
Great work Brian!

Thank you also for providing the model! :-) I hope you don't mind that i reworked your triangle mesh a bit to get a smooth surface. Maybe you can render this too, or thicken it and 3d print it.. ;-)

Best regards
Stefan




Image Attachments:
CostaMinSurface2.png 


From: bemfarmer
19 Oct 2015   [#4] In reply to [#3]
Thanks Stefan,
Your mesh is much better.
I imported to Moi, joined, and ran subdivbeta9.
It took awhile, but ended up at 117,116 kb
Exported obj at 8.37 degrees, quads and triangles, was 182,273 kb, and looked superb in keyshot5.

- Brian
From: amur (STEFAN)
19 Oct 2015   [#5] In reply to [#4]
You`re welcome, Brian!

What i did with your mesh was to make from the long small triangles big ones and then i applied a LS3 Loop subdivision in Meshlab, to obtain a smooth surface. Here's one derived mesh from yours, after modifying it, and with Dual remeshing applied.

Regards
Stefan


Image Attachments:
Costa_Dual.jpg 


From: Frenchy Pilou (PILOU)
19 Oct 2015   [#6]
Elegant!
From: amur (STEFAN)
19 Oct 2015   [#7]
Thank you Pilou!

Regards
Stefan
From: amur (STEFAN)
20 Oct 2015   [#8]
Hi Brian,

just a small update... I wanted to make a NURBS surface and noodled a lot with some solutions, which were not satisfactory, until i downloaded today a Trial of ZBRush... I think i need to buy me a copy of ZBrush in the future due to it's fantastic ZRemesher, for example. Simply amazing, imho. After that i converted with Fusion360 T-Splines.

I attach the files, both quad mesh and NURBS model.

Best regards
Stefan


Image Attachments:
ZRemesher_T-Splines.png 


From: bemfarmer
20 Oct 2015   [#9] In reply to [#8]
Thank you Stefan for the excellent information.
I think I will try for a Nurbs Costa surface script this winter, LOL.
Gang or Elliptic may have Weierstrass code.
There is also the L. Baker book with some old C code...
I'm not sure how the math works.
There are also higher Genus Costa surfaces, with 2+ holes.

- Brian
From: amur (STEFAN)
23 Oct 2015   [#10]
Hi Brian,

a script would be interesting. Wish i could program. Would help me often in some scenarios.

Regards
Stefan
From: bemfarmer
28 Oct 2020   [#11]
Found some code for Weierstrass functions in C++11

https://github.com/bluescarni/w_elliptic
http://bluescarni.github.io/w_elliptic/

I wonder if this library could be "Included" or linked to in a MoI script?

- Brian

Besides a possible Costa surface script, the functions could be used for other projects.
From: Michael Gibson
28 Oct 2020   [#12] In reply to [#11]
Hi Brian,

re:
> I wonder if this library could be "Included" or linked to in a MoI script?

Hmmm, well the only method that I can think of for that would be to compile the library into its own standalone executable program. A script in MoI could then run the program and pass command line parameters to it and receive any output that the program wrote to stdout.

That can be done by the moi.filesystem.shellExecute method, which as of the Sep-10 v4 beta has a "wait for finished" option in it:

quote:

moi.filesystem.shellExecute(), added wait for finished parameter.
moi.filesystem.shellExecute( path, params, wait ) now takes an optional 3rd boolean parameter for whether to wait until the called process has exited before returning. When used, the return value from shellExecute() is an object containing an .exitCode property for the integer exit code of the called process and an .output string parameter for any text written by the called process to stdout.
Example:
var res = moi.filesystem.shellExecute( 'cmd /c dir c:\\', '', true );
if ( res.output ) moi.ui.alert( res.output );


- Michael
From: bemfarmer
28 Oct 2020   [#13] In reply to [#12]
Michael, thank you for the guidance.

- Brian