internal static void RenderNetworkFrame(CompasNetwork network, double[][] vertices, IRenderPackage package, TessellationParameters parameters) { // Vertices foreach (double[] p in vertices) { package.AddPointVertex(p[0], p[1], p[2]); package.AddPointVertexColor(255, 0, 0, 255); } if (network.edgesInt != null) { foreach (int[] ids in network.edgesInt) { double[] p0 = vertices[ids[0]]; double[] p1 = vertices[ids[1]]; package.AddLineStripVertexColor(0, 255, 0, 255); package.AddLineStripVertex(p0[0], p0[1], p0[2]); package.AddLineStripVertexColor(0, 0, 255, 255); package.AddLineStripVertex(p1[0], p1[1], p1[2]); package.AddLineStripVertexCount(2); } } }
public void Tessellate(IRenderPackage package, TessellationParameters parameters) { if (network.frames != null) { double[][] frame = network.frameDoubles[it % frameCount]; CompasNetwork.RenderNetworkFrame(network, frame, package, parameters); } }
public static Dictionary <string, object> CompasNetworkProperties(CompasNetwork network) { return(new Dictionary <string, object>() { { "PythonMesh", network.ToPythonNetwork() }, { "Vertices", 400 }, { "Edges", 12 } }); }
public static CompasNetwork CompasNetworkFromObj(string filePath = null, string IronPythonPath = @"C:\Program Files (x86)\IronPython 2.7") { string path = GetPackagePath() + @"bin"; var pySrc = @" import sys sys.path.append(r'" + IronPythonPath + @"') sys.path.append(r'" + IronPythonPath + @"\Lib') sys.path.append(r'" + IronPythonPath + @"\DLLs') sys.path.append(r'" + path + @"') import compas from compas.datastructures.network import Network # import List class to cast the type from System.Collections.Generic import * def NetworkFromObject(filepath): # import network network = Network.from_obj(filepath) # extract network vertices xyz = [network.vertex_coordinates(key) for key in network.vertices()] vertices = List[object]([List[object]([x, y, z]) for x, y, z in xyz]) # extract network edges key_index = network.key_index() edges = [(key_index[u], key_index[v]) for u, v in network.edges()] edges = List[object]([List[object](ij) for ij in edges]) return List[object]([network, str(network), vertices, edges]) "; if (filePath != null || filePath != "") { // host python and execute script var engine = IronPython.Hosting.Python.CreateEngine(); var scope = engine.CreateScope(); engine.Execute(pySrc, scope); var NetworkFromObject = scope.GetVariable <Func <string, List <object> > >("NetworkFromObject"); var networkList = NetworkFromObject(filePath); return(CompasNetwork.Create(networkList[0], networkList[1] as String, networkList[2] as List <object>, networkList[3] as List <object>)); } return(null); }
public static CompasNetwork Smooth(CompasNetwork network, int iterations = 100, bool shouldAnimate = false, string IronPythonPath = @"C:\Program Files (x86)\IronPython 2.7") { string path = GetPackagePath() + @"bin"; var pySrc = @" import sys sys.path.append(r'" + IronPythonPath + @"') sys.path.append(r'" + IronPythonPath + @"\Lib') sys.path.append(r'" + IronPythonPath + @"\DLLs') sys.path.append(r'" + path + @"') import compas from compas.datastructures.network import Network from compas.datastructures.network.algorithms import smooth_network_centroid # import List class to cast the type from System.Collections.Generic import * def SmoothNetwork(network, its, animate=False): def callback(network, k, args): frames = args[0] animate = args[1] if animate: frames.append([network.vertex_coordinates(key) for key in network.vertices()]) frames = [] smooth = network.copy() smooth_network_centroid(smooth, fixed = smooth.leaves(), kmax = its, callback=callback, callback_args=(frames, animate)) # extract network vertices xyz = [smooth.vertex_coordinates(key) for key in smooth.vertices()] vertices = List[object]([List[object]([x, y, z]) for x, y, z in xyz]) # extract network edges key_index = smooth.key_index() edges = [(key_index[u], key_index[v]) for u, v in smooth.edges()] edges = List[object]([List[object](ij) for ij in edges]) # extract animation frames frames = List[object]([List[object]([List[object](xyz) for xyz in frame]) for frame in frames]) return List[object]([smooth, str(smooth), vertices, edges, frames]) "; // REMEMBER: add initial zero frame to the frames animations if (network != null && network is CompasNetwork) { // host python and execute script var engine = IronPython.Hosting.Python.CreateEngine(); var scope = engine.CreateScope(); engine.Execute(pySrc, scope); var SmoothNetwork = scope.GetVariable <Func <object, int, bool, List <object> > >("SmoothNetwork"); var networkList = SmoothNetwork(network.ToPythonNetwork(), iterations, shouldAnimate); return(CompasNetwork.Create( networkList[0], networkList[1] as String, networkList[2] as List <object>, networkList[3] as List <object>, networkList[4] as List <object>)); } return(null); }
public static CompassNetworkAnimationViz AnimateNetwork(CompasNetwork network, int iteration = 0) { return(network == null ? null : new CompassNetworkAnimationViz(network, iteration)); }
internal CompassNetworkAnimationViz(CompasNetwork network, int it) { this.network = network; this.it = it; this.frameCount = network.frameDoubles.Length; }