energydata = Import["/Users/ccarter/People/Neri/butterfly_energy.csv","CSV"];

Length[energydata]

sheardata = Import["/Users/ccarter/People/Neri/butterfly_shear.csv","CSV"];

Length[sheardata]

zdata = Import["/Users/ccarter/People/Neri/butterfly_zdis.csv","CSV"];

Length[zdata]

pressuredata = Import["/Users/ccarter/People/Neri/butterfly_pressure.csv","CSV"];

Length[pressuredata]

efunc = Interpolation[energydata/.{a_,b_,c_}->{{b,a},c}];

efunc[[1]]

(*Plot3D[efunc[x,y],{x,0,496},{y,0,286}]*)

sfunc = Interpolation[sheardata/.{a_,b_,c_}->{{b,a},c}];
(*Plot3D[sfunc[x,y],{x,0,496},{y,0,286}]*)

zfunc = Interpolation[zdata/.{a_,b_,c_}->{{b,a},c}];
(*Plot3D[zfunc[x,y],{x,0,286},{y,0,496}]*)

pfunc = Interpolation[pressuredata/.{a_,b_,c_}->{{b,a},c}];
(*Plot3D[pfunc[x,y],{x,0,286},{y,0,496}]*)

pts = Import["/Users/ccarter/People/Neri/bfly_pnts.csv","CSV"];

pgons = Import["/Users/ccarter/People/Neri/bfly_pgons.csv","CSV"]+1;

Length[pts]
Length[pgons]

currentedge=1;

UniqueEdge[va_, vb_] :=Which[
ValueQ[edge[va,vb]],edge[va,vb],
ValueQ[edge[vb,va]],-edge[vb,va],
True,edge[va,vb] = currentedge;edgevertices[currentedge]={va,vb};currentedge++]

MakeEdges[ v_List] :=Module[{len=Length[v]},
Return[
Append[
 Table[UniqueEdge[v[[i]],v[[i+1]]],{i,1,len-1}],
UniqueEdge[v[[len]],v[[1]]]
]

]
]

Map[MakeEdges,pgons];

currentedge

elist =Table[{Hue[Mod[i,100]/400,.6,.4],Line[edgevertices[i]]},{i,1,currentedge-1}];

g2d1 =Graphics[GraphicsComplex[pts,elist],Axes-> True]

Export["~/ForNeri/bfly_meshonly_2D.svg",g2d1,"SVG"]

ContourPlot[pfunc[x,y],{x,0,286},{y,0,496}]

MidPoint[edge_] := Mean[pts[[edgevertices[edge]]]]

MidPoint[23]

p[edge_] :=Module[{pt=MidPoint[edge]},pfunc[pt[[2]],pt[[1]]]]

p[23]

pmax=Max[Table[p[i],{i,1,currentedge-1}]]

pmin=Min[Table[p[i],{i,1,currentedge-1}]]

zdata[[1,3]]

zvert[vt_] := zdata[[vt,3]]

zvals= Transpose[zdata][[3]];

Min[zvals]

Max[zvals]

zht[vtx_] :=Module[{pt=pts[[vtx]]},zfunc[pt[[2]],pt[[1]]]]

ptszht=Table[Append[pts[[i]],25*zht[i]],{i,1,Length[pts]}];

elist =Table[{
ColorData["PlumColors"][(p[i]-pmin)/(pmax-pmin)],
Line[edgevertices[i]]},{i,1,currentedge-1}];

g2d2=Graphics[GraphicsComplex[pts,elist]]

Export["~/ForNeri/bfly_mesh_presscol_2D.svg",g2d2,"SVG"]

g2d3=Graphics3D[GraphicsComplex[ptszht,elist],Boxed->False]

Export["~/ForNeri/bfly_mesh_press_zht_3D.dxf",g2d3,"DXF"]

(*elist =Table[{EdgeForm[],Hue[Mod[i,100]/400,.6,.4,RandomReal[]],Cylinder[edgevertices[i],.03]},{i,1,10}];*)

elist =Table[{EdgeForm[],
ColorData["AvocadoColors"][(p[i]-pmin)/(pmax-pmin)],
Cylinder[edgevertices[i],1]},{i,1,currentedge-1}];

g2d3cyl=Graphics3D[GraphicsComplex[ptszht,elist],Boxed->False];

Export["~/ForNeri/bfly_mesh_press_zht_cyls_3D.dxf",g2d3cyl,"DXF"]