public static vCube loadCube(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException();
            }

            FileStream fs = new FileStream(filename, FileMode.Open);
            try
            {
                fs.Seek(0, SeekOrigin.Begin);
                byte[] bytes = new byte[125];

                if( ((int)fs.Length) != 125)
                {
                    throw new ArgumentOutOfRangeException("Datei ist beschädigt");
                }

                //lesen
                for (int i = 0; i < 125; i++)
                {
                    bytes[i] = (byte)fs.ReadByte();
                }

                vCube cube = new vCube(bytes);

                fs.Close();
                return cube;
            }
            catch
            {
                throw;
            }
            finally
            {
                fs.Close();
            }
        }
        public static void saveCube(string filename, vCube cube)
        {
            byte[] bytes = cube.get_Bytes();

            FileStream fs = new FileStream(filename, FileMode.Create);

            try
            {
                foreach (byte b in bytes)
                {
                    fs.WriteByte(b);
                }

            }
            catch
            {
                throw;
            }
            finally
            {
                fs.Close();
            }
        }
Exemple #3
0
 public void writeCube(vCube cube)
 {
     setBufferCube(cube);
     Cobj.writeCube(cube);
 }
Exemple #4
0
 public void setBufferCube(vCube bCube)
 {
     this.bCube = bCube;
 }
Exemple #5
0
 public void Flush(vCube cube)
 {
     try
     {
         bCube = cube;
         Flush();
     }
     catch
     {
         throw;
     }
 }
Exemple #6
0
 public Cube()
 {
     bCube = new vCube();
     Cobj = new CommunicationInterface();
 }
        public void writeCube(vCube c)
        {
            for (byte layer = 0; layer < 10; layer++) //Für jedes Layer
            {
                byte[] b_layer = new byte[14];

                b_layer[0] = (byte)'v';

                for (int i = 0; i < 96; i++) //jeder Pixel, ausser letzten 4
                {
                    int x = i % 10; //x im vCube
                    int z = (int) Math.Floor(i / 10.0); //z im vCube

                    int position = (int) Math.Floor(i / 8.0) + 2; //immer 8 Bit in einer Speicherstelle !!+2 weil versetzt (0:'v', 1:layer + letzte 4 Pixel)
                    b_layer[position] = (byte)(b_layer[position] | ((c.get_Pixel(x, layer, z) ? 1 : 0) << (i % 8)) );
                }

                for (int x = 6; x < 10; x++) //Letzten 4 (z von 6 bis 9)
                {
                    b_layer[1] = (byte)(b_layer[1] | ((c.get_Pixel(x, layer, 9) ? 1 : 0) << (x-6) ));  //an speicherstelle 1
                }

                //layer einfügen
                b_layer[1] =  (byte) (b_layer[1] | ((byte)layer << 4));

                write(b_layer);

            }
        }