Ejemplo n.º 1
0
        internal PFace(PBaseFace bas)
        {
            Base = bas;
            Pole = bas.Pole;
            int dim = Pole.Length;

            Matrix  = PGeom.MatrixIdentity(dim);
            RefAxis = 0;
        }
Ejemplo n.º 2
0
        private void FillFromStrings(string[] descr)
        {
            int       naxis = 0;
            int       caxis = 0;
            PBaseAxis ax    = null;
            int       state = 0;
            int       nv;
            int       fline = 0;

            QSimplified = false;
            try {
                while (state >= 0)
                {
                    if (fline == descr.Length)
                    {
                        if (state != 7)
                        {
                            throw new Exception("Unexpected end");
                        }
                        break;
                    }
                    string line = descr[fline++];
                    if (line == "" || line == null || line[0] == '#')
                    {
                        continue;
                    }
                    string[] str = line.Split(' ', '\t');
                    if (str.Length == 0 || str[0] == "" || str[0] == null)
                    {
                        continue;
                    }
                    string cmd = str[0].ToLowerInvariant();
                    switch (state)
                    {
                    case 0:
                        if (cmd != "dim")
                        {
                            throw new Exception("'Dim' required");
                        }
                        Dim = int.Parse(str[1]);
                        break;

                    case 1:
                        if (cmd != "naxis")
                        {
                            throw new Exception("'NAxis' required");
                        }
                        naxis    = int.Parse(str[1]);
                        BaseAxes = new PBaseAxis[naxis];
                        break;

                    case 2:
                        if (cmd != "faces")
                        {
                            throw new Exception("'Faces' required");
                        }
                        nv        = str.Length - 1;
                        BaseFaces = new PBaseFace[nv];
                        for (int i = 0; i < nv; i++)
                        {
                            BaseFaces[i] = new PBaseFace(GetVector(str[i + 1], Dim));
                        }
                        break;

                    case 3:
                        if (cmd == "simplified")
                        {
                            QSimplified = true; state--; break;
                        }
                        if (cmd != "group")
                        {
                            throw new Exception("'Group' required");
                        }
                        nv    = str.Length - 1;
                        Group = new double[nv][];
                        for (int i = 0; i < nv; i++)
                        {
                            Group[i] = GetVector(str[i + 1], 2 * Dim);
                            PGeom.GetOrder(Group[i]);
                        }
                        if (naxis == 0)
                        {
                            state = -2;
                        }
                        break;

                    case 4:
                        if (cmd != "axis")
                        {
                            throw new Exception("'Axis' required");
                        }
                        ax = new PBaseAxis(GetVector(str[1], Dim));
                        break;

                    case 5:
                        if (cmd != "twists")
                        {
                            throw new Exception("'Twists' required");
                        }
                        nv        = str.Length - 1;
                        ax.Twists = new PBaseTwist[nv];
                        for (int i = 0; i < nv; i++)
                        {
                            ax.Twists[i] = new PBaseTwist(GetVector(str[i + 1], 2 * Dim));
                        }
                        break;

                    case 6:
                        if (cmd != "cuts")
                        {
                            throw new Exception("'Cuts' required");
                        }
                        nv     = str.Length - 1;
                        ax.Cut = new double[nv];
                        for (int i = 0; i < nv; i++)
                        {
                            ax.Cut[i] = double.Parse(str[i + 1], CultureInfo.InvariantCulture);
                        }
                        ax.AdjustCuts();
                        BaseAxes[caxis++] = ax;
                        ax = null;
                        break;

                    case 7: {
                        if (cmd == "fixedmask")
                        {
                            BaseAxes[caxis - 1].FixedMask = int.Parse(str[1]);
                            if (caxis == naxis)
                            {
                                state = -2;
                            }
                            else
                            {
                                state = 3;
                            }
                            break;
                        }
                        if (caxis != naxis)
                        {
                            state = 4; goto case 4;
                        }
                        state = -2;
                        break;
                    }
                    }
                    state++;
                }
            } catch (Exception e) {
                throw new Exception("Error: " + e.Message + " in line " + fline + ": " + (descr[fline] ?? "{null}"));
            }
        }
Ejemplo n.º 3
0
        private unsafe void SortStickersForAxes()
        {
            int[] S = new int[1000];
            foreach (PBaseAxis Ax in BaseAxes)
            {
                int nl   = Ax.NLayers;
                int mask = Ax.FixedMask;
                Ax.Layers = new int[nl][];
                for (int i = 0; i < nl; i++)
                {
                    if (((mask >> i) & 1) == 0)
                    {
                        int ps = 0;
                        foreach (PFace F in Faces)
                        {
                            int  ax = FindAxisInv(Ax.Dir, F.Matrix);
                            bool qr = ax < 0;
                            ax = Math.Abs(ax) - 1;
                            PBaseFace BF   = F.Base;
                            int       i1   = qr ? nl - 1 - i : i;
                            int       h    = BF.AxisLayers[ax];
                            int       nstk = BF.NStickers;
                            int       fstk = F.FirstSticker;
                            if (h >= 0)
                            {
                                if (i1 != h)
                                {
                                    continue;
                                }
                                for (int j = 0; j < nstk; j++)
                                {
                                    S = SetInt(S, ps++, fstk + j);
                                }
                            }
                            else
                            {
                                int r = Array.IndexOf <int>(BF.CutAxes, ax);
                                if (r < 0)
                                {
                                    throw new Exception("Can't find CutAxis");
                                }
                                byte[,] aa = BF.StickerMask;
                                for (int j = 0; j < nstk; j++)
                                {
                                    if (aa[j, r] == i1)
                                    {
                                        S = SetInt(S, ps++, fstk + j);
                                    }
                                }
                            }
                        }
                        int[] ar = new int[ps];
                        Buffer.BlockCopy(S, 0, ar, 0, sizeof(int) * ps);
                        Ax.Layers[i] = ar;
                    }
                }
            }
            PermByMatr perm = new PermByMatr(Axes.Length, Faces.Length);

            foreach (PAxis Ax in Axes)
            {
                Ax.Layers = ConvertStickersFromLayers(Ax.Base, Ax.Matrix, perm);
            }
        }
Ejemplo n.º 4
0
 internal PFace(PFace src, double[] tw)
 {
     Base   = src.Base;
     Pole   = PGeom.ApplyTwist(tw, src.Pole);
     Matrix = PGeom.ApplyTwist(tw, src.Matrix);
 }