X-Git-Url: https://melusine.eu.org/syracuse/G/git/?a=blobdiff_plain;f=luamesh.lua;h=3ff737bcab6475117b605748cc47ef5cc693fbd7;hb=adce527b71c97f77a50a64f15a5e724006969db2;hp=af3da3109fb9cf72d1d8e2a14f5f433dad74b9d0;hpb=81576bf772cf5a397a9a380eb6f30b97270710c5;p=delaunay.git diff --git a/luamesh.lua b/luamesh.lua index af3da31..3ff737b 100644 --- a/luamesh.lua +++ b/luamesh.lua @@ -329,7 +329,17 @@ end -- trace Voronoi with MP -function traceVoronoiMP(listPoints, triangulation,listVoronoi, points, tri) +function traceVoronoiMP(listPoints, triangulation,listVoronoi, points, tri,styleD,styleV) + if(styleD == "dashed") then + sDelaunay = "dashed evenly" + else + sDelaunay = "" + end + if(styleV == "dashed") then + sVoronoi = "dashed evenly" + else + sVoronoi = "" + end listCircumC = listCircumCenter(listPoints,triangulation) output = ""; output = output .. " pair MeshPoints[];" @@ -346,16 +356,16 @@ function traceVoronoiMP(listPoints, triangulation,listVoronoi, points, tri) PointJ = listPoints[triangulation[i][2]] PointK = listPoints[triangulation[i][3]] if(triangulation[i].type == "bbox") then - output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolorBbox;" + output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle "..sDelaunay.." withcolor \\luameshmpcolorBbox;" else - output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle withcolor \\luameshmpcolor;" + output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u--("..PointK.x..",".. PointK.y ..")*u--cycle "..sDelaunay.." withcolor \\luameshmpcolor;" end end end for i=1,#listVoronoi do PointI = listCircumC[listVoronoi[i][1]] PointJ = listCircumC[listVoronoi[i][2]] - output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u withcolor \\luameshmpcolorVoronoi;" + output = output .. "draw (".. PointI.x ..",".. PointI.y ..")*u--("..PointJ.x..",".. PointJ.y ..")*u "..sVoronoi.." withcolor \\luameshmpcolorVoronoi;" end if(points=="points") then j=1 @@ -390,7 +400,17 @@ end -- trace Voronoi with TikZ -function traceVoronoiTikZ(listPoints, triangulation,listVoronoi, points, tri,color,colorBbox,colorVoronoi) +function traceVoronoiTikZ(listPoints, triangulation,listVoronoi, points, tri,color,colorBbox,colorVoronoi,styleD,styleV) + if(styleD == "dashed") then + sDelaunay = ",dashed" + else + sDelaunay = "" + end + if(styleV == "dashed") then + sVoronoi = ",dashed" + else + sVoronoi = "" + end listCircumC = listCircumCenter(listPoints,triangulation) output = "" for i=1,#listPoints do @@ -405,27 +425,25 @@ function traceVoronoiTikZ(listPoints, triangulation,listVoronoi, points, tri,col PointJ = listPoints[triangulation[i][2]] PointK = listPoints[triangulation[i][3]] if(triangulation[i].type == "bbox") then - output = output .. "\\draw[color="..colorBbox.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" + output = output .. "\\draw[color="..colorBbox..sDelaunay.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" else - output = output .. "\\draw[color="..color.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" + output = output .. "\\draw[color="..color..sDelaunay.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..")--("..PointK.x..",".. PointK.y ..")--cycle;" end end end for i=1,#listVoronoi do PointI = listCircumC[listVoronoi[i][1]] PointJ = listCircumC[listVoronoi[i][2]] - output = output .. "\\draw[color="..colorVoronoi.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..");" + output = output .. "\\draw[color="..colorVoronoi..sVoronoi.."] (".. PointI.x ..",".. PointI.y ..")--("..PointJ.x..",".. PointJ.y ..");" end if(points=="points") then j=1 for i=1,#listPoints do if(listPoints[i].type == "bbox") then - if(listPoints[i].type == "bbox") then - output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};" - j=j+1 - else - output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};" - end + output = output .. "\\draw[color="..colorBbox.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint^*_{" .. j .. "}$};" + j=j+1 + else + output = output .. "\\draw[color="..color.."] (" .. listPoints[i].x ..",".. listPoints[i].y .. ") node {$\\bullet$} node[anchor=north east] {$\\MeshPoint_{" .. i .. "}$};" end end for i=1,#listCircumC do @@ -451,26 +469,48 @@ end -- buildVoronoi with MP -function buildVoronoiMPBW(chaine,mode,points,bbox,scale,tri) +function buildVoronoiMPBW(chaine,mode,points,bbox,scale,tri,styleD,styleV) listPoints = buildList(chaine, mode) triangulation = BowyerWatson(listPoints,bbox) listVoronoi = buildVoronoi(listPoints, triangulation) - output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri) + output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV) output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}" tex.sprint(output) end -- buildVoronoi with TikZ -function buildVoronoiTikZBW(chaine,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi) +function buildVoronoiTikZBW(chaine,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi,styleD,styleV) listPoints = buildList(chaine, mode) triangulation = BowyerWatson(listPoints,bbox) listVoronoi = buildVoronoi(listPoints, triangulation) - output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi) + output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV) output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output) end +-- buildVoronoi with MP +function buildVoronoiMPBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri,styleD,styleV) + listPoints = buildList(chaine, mode) + triangulation = BowyerWatson(listPoints,bbox) + listVoronoi = buildVoronoi(listPoints, triangulation) + output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV) + output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}" + tex.sprint(output) +end + + +-- buildVoronoi with TikZ +function buildVoronoiTikZBWinc(chaine,beginning, ending,mode,points,bbox,scale,tri,color,colorBbox,colorVoronoi) + listPoints = buildList(chaine, mode,styleD,styleV) + triangulation = BowyerWatson(listPoints,bbox) + listVoronoi = buildVoronoi(listPoints, triangulation) + output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV) + output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}" + tex.sprint(output) +end + + -- trace a triangulation with TikZ function traceMeshTikZ(listPoints, triangulation,points,color,colorBbox) @@ -510,7 +550,6 @@ function traceMeshMP(listPoints, triangulation,points) for i=1,#listPoints do output = output .. "MeshPoints[".. i .. "] = (" .. listPoints[i].x .. "," .. listPoints[i].y .. ")*u;" end - for i=1,#triangulation do PointI = listPoints[triangulation[i][1]] PointJ = listPoints[triangulation[i][2]] @@ -1065,3 +1104,139 @@ function TeXOnePointMPBWinc(chaine,point,beginning,ending,step,scale,mode,bbox) output = "\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}" tex.sprint(output) end + + +function split(pString, pPattern) + local Table = {} -- NOTE: use {n = 0} in Lua-5.0 + local fpat = "(.-)" .. pPattern + local last_end = 1 + local s, e, cap = pString:find(fpat, 1) + while s do + if s ~= 1 or cap ~= "" then + table.insert(Table,cap) + end + last_end = e+1 + s, e, cap = pString:find(fpat, last_end) + end + if last_end <= #pString then + cap = pString:sub(last_end) + table.insert(Table, cap) + end + return Table +end + +function readGmsh(file) + io.input(file) -- open the file + text=io.read("*all") + local lines = split(text,"\n+") -- all the lines + listPoints={} + triangulation ={} + boolNodes = false + Jnodes = 0 + boolElements = false + Jelements = 0 + J=0 + for i=1,#lines-J do + if(lines[i+J] == "$EndNodes") then + boolNodes = false + -- go to the next line + end + if(boolNodes) then -- we are in the Nodes environment + xy=split(lines[i+J]," +") + table.insert(listPoints,{x=tonumber(xy[2]),y=tonumber(xy[3])}) + end + if(lines[i+J] == "$Nodes") then + boolNodes = true + -- go to the next line + J=J+1 + end + if(lines[i+J] == "$EndElements") then + boolElements = false + -- go to the next line + end + if(boolElements) then -- we are in the Nodes environment + xy=split(lines[i+J]," +") + if(tonumber(xy[2]) == 2) then -- if the element is a triangle + nbrTags = xy[3]+1 + table.insert(triangulation,{tonumber(xy[2+nbrTags+1]),tonumber(xy[2+nbrTags+2]),tonumber(xy[2+nbrTags+3])}) + end + end + if(lines[i+J] == "$Elements") then + boolElements = true + -- go to the next line + J=J+1 + end + end + return listPoints, triangulation +end + +function drawGmshMP(file,points,scale) + listPoints,triangulation = readGmsh(file) + output = traceMeshMP(listPoints,triangulation,points) + output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}" + tex.sprint(output) +end + +function drawGmshMPinc(file,beginning,ending,points,scale) + listPoints,triangulation = readGmsh(file) + output = traceMeshMP(listPoints,triangulation,points) + output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}" + tex.sprint(output) +end + + + +-- +function drawGmshTikZ(file,points,scale,color) + listPoints,triangulation = readGmsh(file) + output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox) + output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" + tex.sprint(output) +end + +-- +function drawGmshTikZinc(file,beginning, ending,points,scale,color) + listPoints,triangulation = readGmsh(file) + output = traceMeshTikZ(listPoints, triangulation,points,color,colorBbox) + output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}" + tex.sprint(output) +end + + +-- buildVoronoi with MP +function gmshVoronoiMP(file,points,scale,tri,styleD,styleV) + listPoints,triangulation = readGmsh(file) + listVoronoi = buildVoronoi(listPoints, triangulation) + output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV) + output = "\\leavevmode\\begin{mplibcode}beginfig(0);u:="..scale.. ";" .. output .."endfig;\\end{mplibcode}" + tex.sprint(output) +end + + +-- buildVoronoi with TikZ +function gmshVoronoiTikZ(file,points,scale,tri,color,colorVoronoi,styleD,styleV) + listPoints,triangulation = readGmsh(file) + listVoronoi = buildVoronoi(listPoints, triangulation) + output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV) + output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" .. output .."\\end{tikzpicture}" tex.sprint(output) +end + + +-- buildVoronoi with MP +function gmshVoronoiMPinc(file,beginning, ending,points,scale,tri,styleD,styleV) + listPoints,triangulation = readGmsh(file) + listVoronoi = buildVoronoi(listPoints, triangulation) + output = traceVoronoiMP(listPoints,triangulation,listVoronoi,points,tri,styleD,styleV) + output = "\\leavevmode\\begin{mplibcode}u:="..scale..";"..beginning .. output .. ending .. "\\end{mplibcode}" + tex.sprint(output) +end + + +-- buildVoronoi with TikZ +function gmshVoronoiTikZinc(file,beginning, ending,points,scale,tri,color,colorVoronoi,styleD,styleV) + listPoints,triangulation = readGmsh(file) + listVoronoi = buildVoronoi(listPoints, triangulation) + output = traceVoronoiTikZ(listPoints,triangulation,listVoronoi,points,tri,color,colorBbox,colorVoronoi,styleD,styleV) + output = "\\noindent\\begin{tikzpicture}[x=" .. scale .. ",y=" .. scale .."]" ..beginning.. output..ending .."\\end{tikzpicture}" + tex.sprint(output) +end