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 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 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);
        }