示例#1
0
        public void Delete(LinkedList <string> codes)
        {
            string[] Codes   = new string[codes.Count];
            int      counter = 0;

            foreach (string s in codes)
            {
                Codes[counter++] = s;
            }
            foreach (Sphere s in spheres)
            {
                if (CoordinatesActions.consist(Codes, s.position))
                {
                    s.visualize = false;
                }
            }
            foreach (Cylinder c in cylinders)
            {
                if (CoordinatesActions.consist(Codes, c.int_coordinates[0]) ||
                    CoordinatesActions.consist(Codes, c.int_coordinates[1]))
                {
                    c.visualize = false;
                }
            }
        }
示例#2
0
 private void изФайлаToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!hasChilds && cube != null)
     {
         hasChilds = true;
         OpenFileDialog subform = new OpenFileDialog();
         subform.ShowDialog();
         string filename = subform.FileName;
         if (filename != null && filename != "")
         {
             StreamReader sr = new StreamReader(filename);
             string       cubant;
             while ((cubant = sr.ReadLine()) != null)
             {
                 cubant = CoordinatesActions.CubantRecord2Code(cubant);
                 if (cubant.Length == Basis.Length)
                 {
                     cube.setCubant(cubant, Constants.CubantSphereColor, Constants.CubantCylinderColor, Constants.BordersColor);
                 }
             }
             sr.Close();
         }
         //cube.setCubant("22200", Constants.CubantSphereColor, Constants.CubantCylinderColor, Constants.BordersColor);
         //cube.setCubant("21220", Constants.CubantSphereColor, Constants.CubantCylinderColor, Constants.BordersColor);
     }
     hasChilds = false;
 }
示例#3
0
        public void pant(LinkedList <string> codes, Color SphereColor, Color CylinderColor)
        {
            string[] Codes   = new string[codes.Count];
            int      counter = 0;

            foreach (string s in codes)
            {
                Codes[counter++] = s;
            }
            foreach (Sphere s in spheres)
            {
                if (CoordinatesActions.consist(Codes, s.position))
                {
                    s.paint(SphereColor);
                }
            }
            foreach (Cylinder c in cylinders)
            {
                if (CoordinatesActions.consist(Codes, c.int_coordinates[0]) &&
                    CoordinatesActions.consist(Codes, c.int_coordinates[1]))
                {
                    c.paint(CylinderColor);
                }
            }
        }
示例#4
0
        public void VisualizeOnly(LinkedList <string> codes, bool drawEdge)
        {
            string[] Codes   = new string[codes.Count];
            int      counter = 0;

            foreach (string s in codes)
            {
                Codes[counter++] = s;
            }
            foreach (Sphere s in spheres)
            {
                if (!CoordinatesActions.consist(Codes, s.position))
                {
                    s.visualize = false;
                }
                else
                {
                    s.visualize = true;
                }
            }
            if (drawEdge)
            {
                foreach (Cylinder c in cylinders)
                {
                    if (!CoordinatesActions.consist(Codes, c.int_coordinates[0]) ||
                        !CoordinatesActions.consist(Codes, c.int_coordinates[1]))
                    {
                        c.visualize = false;
                    }
                    else
                    {
                        c.visualize = true;
                    }
                }
            }
            else
            {
                foreach (Cylinder c in cylinders)
                {
                    if (!CoordinatesActions.consist(Codes, c.int_coordinates[0], c.int_coordinates[1]))
                    {
                        c.visualize = false;
                    }
                    else
                    {
                        c.visualize = true;
                    }
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string str  = textBox1.Text;
            string code = CoordinatesActions.CubantRecord2Code(str);

            if (code.Length == MainForm.Basis.Length)
            {
                for (int i = 0; i < code.Length; i++)
                {
                    if (code[i] != '0' && code[i] != '1' && code[i] != '2')
                    {
                        return;
                    }
                }
                MainForm.cube.setCubant(code, Constants.CubantSphereColor, Constants.CubantCylinderColor, Constants.BordersColor);
                button2_Click(this, new EventArgs());
            }
        }
示例#6
0
        public Hypercube(Color SphereColor, Color CylinderColor, Device dev)
        {
            device        = dev;
            spheres       = new LinkedList <Sphere>();
            cylinders     = new LinkedList <Cylinder>();
            cubants       = new LinkedList <string>();
            cubantColors  = new LinkedList <Color>();
            squares       = new LinkedList <Square>();
            BasisElements = new int[Basis.Length][];
            for (int i = 0; i < BasisElements.Length; i++)
            {
                BasisElements[i] = new int[Basis.Length];
                for (int j = 0; j < BasisElements[i].Length; j++)
                {
                    if (i != j)
                    {
                        BasisElements[i][j] = 0;
                    }
                    else
                    {
                        BasisElements[i][j] = 1;
                    }
                }
            }
            int[]  nullcoord = CoordinatesActions.getNullIntCoord(Basis.Length);
            Sphere first     = new Sphere(nullcoord, Constants.SphereRadius,
                                          Constants.SphereSlices, Constants.SphereStacks, dev);

            first.paint(SphereColor);
            spheres.AddLast(first);
            for (int i = 0; i < Basis.Length; i++)
            {
                LinkedList <Sphere>   newSpheres   = new LinkedList <Sphere>();
                LinkedList <Cylinder> newCylinders = new LinkedList <Cylinder>();
                foreach (Sphere s in spheres)
                {
                    Sphere newsphere = new Sphere(CoordinatesActions.add(s.position, BasisElements[i]), Constants.SphereRadius,
                                                  Constants.SphereSlices, Constants.SphereStacks, device);
                    newsphere.paint(SphereColor);
                    newSpheres.AddLast(newsphere);
                    Cylinder newcylinder = new Cylinder(s.position, CoordinatesActions.add(s.position, BasisElements[i]),
                                                        Constants.CylinderRadius, Constants.CylinderRadius, Constants.CylinderSlices, Constants.CylinderStacks,
                                                        device);
                    newcylinder.paint(CylinderColor);
                    newCylinders.AddLast(newcylinder);
                }
                foreach (Cylinder c in cylinders)
                {
                    Cylinder newCylinder = new Cylinder(CoordinatesActions.add(c.int_coordinates[0], BasisElements[i]),
                                                        CoordinatesActions.add(c.int_coordinates[1], BasisElements[i]),
                                                        Constants.CylinderRadius, Constants.CylinderRadius, Constants.CylinderSlices, Constants.CylinderStacks,
                                                        device);
                    newCylinder.paint(CylinderColor);
                    newCylinders.AddLast(newCylinder);
                }
                foreach (Sphere s in newSpheres)
                {
                    spheres.AddLast(s);
                }
                foreach (Cylinder c in newCylinders)
                {
                    cylinders.AddLast(c);
                }
            }

            float[] camerapos = new float[Basis.Length];
            if (setCamera)
            {
                for (int i = 0; i < camerapos.Length; i++)
                {
                    camerapos[i] = 0.5f;
                }
                Vector3 cameraposition = CoordinatesActions.getVector(camerapos, Basis);
                Vector3 tmp1           = new Vector3(-cameraposition.X, cameraposition.Y, -cameraposition.Z);
                Camera.Position = tmp1;
                Camera.Target   = cameraposition;
            }
            setCamera = false;
        }
示例#7
0
 public void setCubant(string str, Color SphereColor, Color CylinderColor, Color BorderColor)
 {
     if (str.Length != Basis.Length)
     {
         throw new Exception("Размерность кубанта не соответствует размерности гиперкуба.");
     }
     int[] code = new int[str.Length];
     for (int i = 0; i < str.Length; i++)
     {
         if (str[i] == '0')
         {
             code[i] = 0;
         }
         else
         if (str[i] == '1')
         {
             code[i] = 1;
         }
         else
         if (str[i] == '2')
         {
             code[i] = 2;
         }
         else
         {
             throw new Exception("Код кубанта содержит недопустимые символы: " + str[i]);
         }
     }
     foreach (Sphere s in spheres)
     {
         if (CoordinatesActions.consist(s.position, code))
         {
             s.paint(SphereColor);
         }
     }
     foreach (Cylinder c in cylinders)
     {
         if (CoordinatesActions.consist(c.int_coordinates[0], code) && CoordinatesActions.consist(c.int_coordinates[1], code))
         {
             c.paint(CylinderColor);
         }
     }
     if (Constants.UseBordersOption == BordersOption.OnlyDoors)
     {
         foreach (string s in cubants)
         {
             int[] cubantCode = CoordinatesActions.getCode(s);
             int[] per        = CoordinatesActions.peresechenie(cubantCode, code);
             if (per != null && CoordinatesActions.isSquare(per))
             {
                 addSquare(per, BorderColor);
             }
         }
     }
     if (Constants.UseBordersOption == BordersOption.All)
     {
         try
         {
             LinkedList <int[]> squares = CoordinatesActions.getAllSquares(code);
             foreach (int[] squarecode in squares)
             {
                 addSquare(squarecode, BorderColor);
             }
         }
         catch (Exception)
         {
             //nothing to do here
         }
     }
     cubants.AddLast(str);
     cubantColors.AddLast(SphereColor);
     cubantColors.AddLast(CylinderColor);
     cubantColors.AddLast(BorderColor);
 }