public IndexedViewableAlpha GetSelection(Vec3f[] match, bool applymodifiers) { SnapshotModel modeledit = GetEditModel(); if (modeledit != null) { return(modeledit.GetSelection(match, applymodifiers)); } IndexedViewableAlpha viewable = null; foreach (SnapshotModel model in Models) { if (!model.objselected || !model.objvisible) { continue; } IndexedViewableAlpha nview = model.GetSelection(match, applymodifiers, true); viewable = IndexedViewableAlpha.Attach(viewable, nview); } return(viewable); /*IndexedViewableAlpha viewable = null; * foreach( SnapshotModel model in Models ) * { * IndexedViewableAlpha viewadd = model.GetSelection( match, applymodifiers ); * viewable = IndexedViewableAlpha.CombineFat( viewable, viewadd ); * } * return viewable;*/ }
public IndexedViewableAlpha GetComposition_Add() { ModelTree last = GetLastNonFiltered(); IndexedViewableAlpha viewable = last.GetViewable(); viewable.RecolorGroups((int i, int[] inds) => (inds.Sum((int ind) => (viewable.Selected[ind] ? 1 : 0)) > 0 ? (Vec4f?)recoloradd[inds.Length - 1] : (Vec4f?)null)); return(viewable); }
public IndexedViewableAlpha GetViewablesAttached(Vec3f[] match, bool applymods) { IndexedViewableAlpha viewable = null; foreach (SnapshotModel model in Models) { viewable = IndexedViewableAlpha.Attach(viewable, model.GetViewable(match, applymods)); } return(viewable); }
public IndexedViewableAlpha GetViewables(Vec3f[] match, bool applymodifiers) { IndexedViewableAlpha viewable = null; foreach (SnapshotModel model in Models) { IndexedViewableAlpha viewadd = null; //Timer.PrintTimeToExecute( "getviewable", delegate { viewadd = model.GetViewable(match, applymodifiers); //} ); //Timer.PrintTimeToExecute( "adding", delegate { viewable = IndexedViewableAlpha.CombineFat(viewable, viewadd); //viewable += viewadd; //} ); } return(viewable); }
public IndexedViewableAlpha GetComposition_SelectTopo() { int itopo = GetLastIndexOfNonFiltered(); ModelTree ttopo = lst[itopo]; ModelTree tselect = lst[itopo - 1]; IndexedViewableAlpha viewselect = tselect.GetViewable(); IndexedViewableAlpha viewtopo = ttopo.GetViewable(); IndexedViewableAlpha viewadd = viewtopo - viewselect; IndexedViewableAlpha viewdel = viewselect - viewtopo; IndexedViewableAlpha viewsame = viewselect % viewtopo; viewadd.RecolorGroups((int i, int[] inds) => recoloradd[inds.Length - 1]); viewdel.RecolorGroups((int i, int[] inds) => recolordel[inds.Length - 1]); return(viewsame + viewadd + viewdel); }
public static IndexedViewableAlpha MeshDiff(SnapshotScene snapshot0, SnapshotScene snapshot1, Vec3f[] verts, bool applymods) { SnapshotModel[] models0 = snapshot0.Models; SnapshotModel[] models1 = snapshot1.Models; IndexedViewableAlpha viewable = null; int i; int c = models1.Length; foreach (SnapshotModel model0 in models0) { int uid = model0.objuid; for (i = 0; i < c; i++) { if (models1[i].objuid == uid) { break; } } if (i == c) { viewable += model0.GetViewable(verts, applymods); continue; } SnapshotModel model1 = models1[i]; if (model0.GetEditCount() == model1.GetEditCount()) { continue; } IndexedViewableAlpha diff = SnapshotModel.MeshDiff(model0, model1, verts, applymods); viewable += diff; //IndexedViewableAlpha view0 = model0.GetViewable( verts, applymods ); //IndexedViewableAlpha view1 = model1.GetViewable( verts, applymods ); //viewable += view0 - view1; } return(viewable); }
public static IndexedViewableAlpha MeshIntersectAttach(SnapshotScene snapshot0, SnapshotScene snapshot1, Vec3f[] verts, bool applymods) { SnapshotModel[] models0 = snapshot0.Models; SnapshotModel[] models1 = snapshot1.Models; IndexedViewableAlpha viewable = null; int i; int c = models1.Length; foreach (SnapshotModel model0 in models0) { int uid = model0.objuid; for (i = 0; i < c; i++) { if (models1[i].objuid == uid) { break; } } if (i == c) { continue; } SnapshotModel model1 = models1[i]; if (model0.GetEditCount() == model1.GetEditCount()) { viewable = IndexedViewableAlpha.Attach(viewable, model0.GetViewable(verts, applymods)); } else { viewable = IndexedViewableAlpha.Attach(viewable, SnapshotModel.MeshIntersect(model0, model1, verts, applymods)); } } return(viewable); }
public static IndexedViewableAlpha MeshIntersect(SnapshotModel model0, SnapshotModel model1, Vec3f[] match, bool applymods) { int nverts = model0.nverts; Vec3f[] verts = null; int[] vertuids = null; bool[] vsel = null; int[][] visiblegroups = null; Vec4f[][] colors = { new Vec4f[nverts], new Vec4f[nverts], new Vec4f[nverts], new Vec4f[nverts] }; float[] pointsizes = (model0.objedit ? pointsizes_edit : pointsizes_view).DeepCopy(); float[] linewidths = (model0.objedit ? linewidths_edit : (model0.objselected ? linewidths_selected : linewidths_unselected)).DeepCopy(); IndexedViewableAlpha viewable = null; for (int i = 0; i < nverts; i++) { if (!model0.objvisible) { colors[0][i] = colorobjhidden; colors[1][i] = colorobjhidden; colors[2][i] = colorobjhidden; colors[3][i] = colorobjhidden; } else if (model0.objedit) { colors[0][i] = colorvertunselected; //( isvertselected[i] ? colorvertselected : colorvertunselected ); colors[1][i] = colorvertunselected; //( isvertselected[i] ? colorvertselected : colorvertunselected ); colors[2][i] = colorface; colors[3][i] = colorface; } else if (model0.objselected) { if (model0.objactive) { colors[0][i] = colorobjactive; colors[1][i] = colorobjactive; colors[2][i] = colorface; colors[3][i] = colorface; } else { colors[0][i] = colorobjselected; colors[1][i] = colorobjselected; colors[2][i] = colorface; colors[3][i] = colorface; } } else { colors[0][i] = colorobjunselected; colors[1][i] = colorobjunselected; colors[2][i] = colorface; colors[3][i] = colorface; } } List <GroupInfo>[] groups0 = model0.GetGroups(); List <GroupInfo>[] groups1 = model1.GetGroups(); List <int>[] lstvisiblegroups = new List <int>[] { new List <int>(groups0[0].Count), new List <int>(groups0[1].Count * 2), new List <int>(groups0[2].Count * 3), new List <int>(groups0[3].Count * 4) }; int[] uids0 = model0.GetVertUIDs(); int[] uids1 = model1.GetVertUIDs(); for (int igroups = 0; igroups < 4; igroups++) { List <int> lstcurrent = lstvisiblegroups[igroups]; int i0 = 0; int i1 = 0; List <GroupInfo> grps0 = groups0[igroups]; List <GroupInfo> grps1 = groups1[igroups]; int c0 = grps0.Count; int c1 = grps1.Count; while (i0 < c0 && i1 < c1) { GroupInfo g0 = grps0[i0]; GroupInfo g1 = grps1[i1]; string k0 = g0.GetKeyNoVis(uids0); string k1 = g1.GetKeyNoVis(uids1); int comp = k0.CompareTo(k1); if (comp == 1) { i1++; continue; } if (comp == -1) { i0++; continue; } lstcurrent.AddRange(g0.inds); i0++; i1++; } } visiblegroups = new int[][] { lstvisiblegroups[0].ToArray(), lstvisiblegroups[1].ToArray(), lstvisiblegroups[2].ToArray(), lstvisiblegroups[3].ToArray() }; verts = model0.GetVerts().CloneArray(); vertuids = model0.GetVertUIDs().CloneArray(); if (model0.objedit) { vsel = model0.isvertselected.CloneArray(); } else { vsel = new bool[nverts]; } viewable = new IndexedViewableAlpha(verts, colors, visiblegroups, pointsizes, linewidths, groupsizes.CloneArray(), vertuids, vsel); if (match != null) { viewable = history.MakeVertsConsistent(viewable, match); } if (applymods) { foreach (Modifier m in model0.modifiers) { if (m is ModifierMirror) { ModifierMirror mirror = (ModifierMirror)m; viewable += viewable.CreateMirrorData_Each(mirror.usex, mirror.usey, mirror.usez, mirror.mergethreshold); } } } return(viewable); }
public IndexedViewableAlpha GetViewable(Vec3f[] match, bool applymodifiers) { //if( !objvisible ) return null; Vec3f[] verts = null; int[] vertuids = null; bool[] vsel = null; int[][] visiblegroups = null; Vec4f[][] colors = { new Vec4f[nverts], new Vec4f[nverts], new Vec4f[nverts], new Vec4f[nverts] }; float[] pointsizes = (this.objedit ? pointsizes_edit : pointsizes_view).DeepCopy(); float[] linewidths = (this.objedit ? linewidths_edit : (this.objselected ? linewidths_selected : linewidths_unselected)).DeepCopy(); IndexedViewableAlpha viewable = null; //Timer.PrintTimeToExecute( "coloring", delegate { for (int i = 0; i < nverts; i++) { if (!objvisible) { colors[0][i] = colorobjhidden; colors[1][i] = colorobjhidden; colors[2][i] = colorobjhidden; colors[3][i] = colorobjhidden; } else if (objedit) { colors[0][i] = colorvertunselected; //( isvertselected[i] ? colorvertselected : colorvertunselected ); colors[1][i] = colorvertunselected; //( isvertselected[i] ? colorvertselected : colorvertunselected ); colors[2][i] = colorface; colors[3][i] = colorface; } else if (objselected) { if (objactive) { colors[0][i] = colorobjactive; colors[1][i] = colorobjactive; colors[2][i] = colorface; colors[3][i] = colorface; } else { colors[0][i] = colorobjselected; colors[1][i] = colorobjselected; colors[2][i] = colorface; colors[3][i] = colorface; } } else { colors[0][i] = colorobjunselected; colors[1][i] = colorobjunselected; colors[2][i] = colorface; colors[3][i] = colorface; } } //} ); //Timer.PrintTimeToExecute( "visgrps", delegate { List <GroupInfo>[] groups = GetGroups(); List <int>[] lstvisiblegroups = new List <int>[] { new List <int>(groups[0].Count), new List <int>(groups[1].Count * 2), new List <int>(groups[2].Count * 3), new List <int>(groups[3].Count * 4) }; for (int igroups = 0; igroups < 4; igroups++) { List <int> lstcurrent = new List <int>(); foreach (GroupInfo grp in groups[igroups]) //if( grp.visible ) { lstcurrent.AddRange(grp.inds); } lstvisiblegroups[igroups] = lstcurrent; } visiblegroups = new int[][] { lstvisiblegroups[0].ToArray(), lstvisiblegroups[1].ToArray(), lstvisiblegroups[2].ToArray(), lstvisiblegroups[3].ToArray() }; //} ); //Timer.PrintTimeToExecute( "cloning", delegate { verts = GetVerts().CloneArray(); vertuids = GetVertUIDs().CloneArray(); if (objedit) { vsel = isvertselected.CloneArray(); } else { vsel = new bool[verts.Length]; } //} ); //Timer.PrintTimeToExecute( "creating", delegate { viewable = new IndexedViewableAlpha(verts, colors, visiblegroups, pointsizes, linewidths, groupsizes.CloneArray(), vertuids, vsel); //} ); if (match != null) //Timer.PrintTimeToExecute( "matching", delegate { { viewable = history.MakeVertsConsistent(viewable, match); } //} ); if (applymodifiers) //Timer.PrintTimeToExecute( "mod", delegate { { foreach (Modifier m in modifiers) { if (m is ModifierMirror) { ModifierMirror mirror = (ModifierMirror)m; viewable += viewable.CreateMirrorData_Each(mirror.usex, mirror.usey, mirror.usez, mirror.mergethreshold); } } } //} ); return(viewable); }
public IndexedViewableAlpha GetSelection(Vec3f[] match, bool applymods, bool allselected) { Vec3f[] verts = GetVerts(); int[] vertuids = GetVertUIDs(); List <GroupInfo>[] groups = GetGroups(); Vec3f[] norms = GetVertNormals(); int newnverts = nverts * 2; Vec3f[] newverts = new Vec3f[newnverts]; int[] newvuids = new int[newnverts]; Vec4f colface = new Vec4f(colorvertselected.x * 0.75f, colorvertselected.y * 0.75f, colorvertselected.z * 0.75f, 1.0f); Vec4f[][] newcolors = new Vec4f[][] { Enumerable.Repeat(colorvertselected, nverts * 2).ToArray(), Enumerable.Repeat(colorvertselected, nverts * 2).ToArray(), Enumerable.Repeat(colface, nverts * 2).ToArray(), Enumerable.Repeat(colface, nverts * 2).ToArray(), }; List <int>[] newgroups = new List <int>[] { new List <int>(), new List <int>(), new List <int>(), new List <int>() }; bool[] newsel = new bool[newnverts]; float[] newptsizes = { 10.0f, 0.1f, 0.1f, 0.1f }; float[] newlnwidths = { 0.1f, 2.0f, 0.1f, 0.1f }; for (int i = 0; i < nverts; i++) { newverts[i * 2 + 0] = verts[i] + norms[i] * 2.0f; newverts[i * 2 + 1] = verts[i] - norms[i] * 2.0f; newvuids[i * 2 + 0] = vertuids[i]; newvuids[i * 2 + 1] = vertuids[i]; } for (int igroups = 0; igroups < 4; igroups++) { List <GroupInfo> cgroups = groups[igroups]; foreach (GroupInfo grp in cgroups) { if (!allselected) { bool sel = true; foreach (int ind in grp.inds) { sel &= isvertselected[ind]; } if (!sel) { continue; } } foreach (int ind in grp.inds) { newgroups[igroups].Add(ind * 2 + 0); } foreach (int ind in grp.inds) { newgroups[igroups].Add(ind * 2 + 1); } } } int[][] newagroups = new int[][] { newgroups[0].ToArray(), newgroups[1].ToArray(), newgroups[2].ToArray(), newgroups[3].ToArray() }; IndexedViewableAlpha viewable = new IndexedViewableAlpha(newverts, newcolors, newagroups, newptsizes, newlnwidths, groupsizes.CloneArray(), newvuids, newsel); if (match != null) //Timer.PrintTimeToExecute( "matching", delegate { { viewable = history.MakeVertsConsistent(viewable, match); } //} ); if (applymods) //Timer.PrintTimeToExecute( "mod", delegate { { foreach (Modifier m in modifiers) { if (m is ModifierMirror) { ModifierMirror mirror = (ModifierMirror)m; viewable += viewable.CreateMirrorData_Each(mirror.usex, mirror.usey, mirror.usez, mirror.mergethreshold); } } } //} ); return(viewable); }
protected void RenderViewable(IndexedViewableAlpha v, bool wireframe) { BeginMode mode; GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.ColorArray); while (v != null) { GL.VertexPointer(3, VertexPointerType.Float, 0, v.Verts); int indsetcount = v.Indices.Length; for (int iIndSet = 0; iIndSet < indsetcount; iIndSet++) { int[] indset = v.Indices[iIndSet]; int count = indset.Count(); if (count == 0) { continue; } switch (v.GroupSizes[iIndSet]) { case 1: mode = BeginMode.Points; break; case 2: mode = BeginMode.Lines; break; case 3: mode = BeginMode.Triangles; break; case 4: mode = BeginMode.Quads; break; default: throw new ArgumentException("ViewerControl.RenderViewable: Unimplemented group size: " + v.GroupSizes[iIndSet]); } if (wireframe && v.GroupSizes[iIndSet] > 2) { continue; } GL.ColorPointer(4, ColorPointerType.Float, 0, v.Colors[iIndSet]); if (v.PointSizes != null) { float mult = Math.Min((float)m_Camera.Scale / 6.0f, 2.0f); if (m_Camera.Ortho) { GL.PointSize(v.PointSizes[iIndSet] * mult); } else { GL.PointSize(v.PointSizes[iIndSet]); } } if (v.LineWidths != null) { GL.LineWidth(v.LineWidths[iIndSet]); } GL.DrawElements(mode, count, DrawElementsType.UnsignedInt, indset); } v = v.attached; } GL.DisableClientState(ArrayCap.ColorArray); GL.DisableClientState(ArrayCap.VertexArray); GL.PointSize(2.5f); }
protected void RenderViewable(IndexedViewableAlpha v) { RenderViewable(v, false); }
public IndexedViewableAlpha GetComposition_VertPosition() { ColorGradient4f cg = new ColorGradient4f(ColorGradient4f.ROYGBIV); List <Vec3f> verts = new List <Vec3f>(); List <Vec4f> ptcolors = new List <Vec4f>(); List <Vec4f> lncolors = new List <Vec4f>(); List <int> points = new List <int>(); List <int> edges = new List <int>(); List <int> vertuids = new List <int>(); List <bool> selected = new List <bool>(); int npts = 0; int tot = lst.Where((ModelTree t) => !(t is ModelTreeFilter)).Count(); int cur = 0; int lper = 0; Random rnd = new Random(); Dictionary <int, Vec4f> ucolors = new Dictionary <int, Vec4f>(); lst.Each(delegate(ModelTree t, int index) { float per0 = (float)cur / (float)(tot + 1); float per1 = (float)(cur + 1) / (float)(tot + 1); Vec4f lncolor0 = cg.GetColor(per0) * 0.5f; Vec4f lncolor1 = cg.GetColor(per1) * 0.5f; Vec4f ucolor; int uid, k; if (t is ModelTreeFilter) { return; } IndexedViewableAlpha viewable = t.GetViewable(); for (int i = 0; i < viewable.nVerts; i++) { uid = viewable.VertUIDs[i]; if (vertuids.Count == 0) { k = -1; } else { k = vertuids.LastIndexOf(uid); } if (ucolors.ContainsKey(uid)) { ucolor = ucolors[uid]; } else { ucolor = new Vec4f((float)rnd.NextDouble(), (float)rnd.NextDouble(), (float)rnd.NextDouble(), 1.0f); ucolors.Add(uid, ucolor); } verts.Add(viewable.Verts[i]); ptcolors.Add(ucolor); points.Add(npts); vertuids.Add(uid); selected.Add(false); if (k != -1) { edges.Add(k); edges.Add(npts); lncolors.Add(lncolor0); lncolors.Add(lncolor1); } npts++; } cur++; if ((int)(per1 * 10.0f) != lper) { lper = (int)(per1 * 10.0f); System.Console.Write(" " + (lper * 10)); } }); System.Console.WriteLine(); Vec3f[] averts = verts.ToArray(); Vec4f[][] acolors = new Vec4f[][] { ptcolors.ToArray(), lncolors.ToArray() }; int[][] agroups = new int[][] { points.ToArray(), edges.ToArray() }; int[] avertuids = vertuids.ToArray(); bool[] aselected = selected.ToArray(); float[] ptsizes = new float[] { 1.0f, 0.0f }; float[] lnwidths = new float[] { 0.0f, 1.0f }; int[] groupszs = new int[] { 1, 2 }; return(new IndexedViewableAlpha(averts, acolors, agroups, ptsizes, lnwidths, groupszs, avertuids, aselected)); }