Bitmaping from files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nemisis
    New Member
    • May 2007
    • 61

    Bitmaping from files

    I want to create a class from a file which
    1) has parameters width and height.
    2) Stores pixel data in dynamically allocated 2-dimensional array
    3)By default all pixel colours are black (red, green and blue
    values equal to 0).

    This is the file
    Code:
    image BMP 300 300
    
    colour <255 0 0>
    draw Polygon 3 <10 10> <10 90> <90 10>
    
    colour <0 255 0>
    draw Polygon 3 <110 110> <110 190> <190 110>
    
    colour <0 0 255>
    draw Polygon 3 <210 210> <210 290> <290 210>
    image-statement, BMP-file format, 300 300- Width Height of file

    Colour-statement, 255-red, 0- green, 0-blue

    draw-statement, Polygon-shape, 3-no. of vertices, 10 10-x1 y1, 10 90-x2 y2, 90 10- x3 y3

    ............

    This is what i ahve written so far

    [code=cpp]
    class image
    {
    friend std::ostream &operator << (std::ostream &output, void writeBitmap() )

    private:
    int width, height

    public:
    inline image(int X = 0, int Y = 0): width(X), height(Y){}
    inline image(){}
    inline void getpixel()
    inline void setpixel()

    int **pixels(int rows, int cols)// dyanmiccally allocated array
    {
    pixel = new int * [rows];
    for(int i=0; i< rows; i++)
    matrix[i] = new int [cols];

    return pixel;
    }
    }


    using namespace std;

    void image:getpixel( )
    {
    string line[i];

    ifstream inFile("example .vec"); // opens the file


    if (inFile) //Verify Open and reads from file
    {
    for(int i=0; !inFile.eof(); i++)
    inFile >> string[i];// read into an array( but has to be 2D instead

    inFile.close();

    }
    [/code]

    So i need to know how to read the file into a 2D array where the pixel data x1 y1, x2 y2 ,..... goes into the 2D array and seperate the other parameter (width, height) in some other variables.
  • nemisis
    New Member
    • May 2007
    • 61

    #2
    so i modified a bit of my coding in the class image and here is what i have got so far

    [code=cpp]

    #ifndef IMAGE_H
    #define IMAGE_H

    #include <iostream>
    #include "bitmap.h"

    class Image
    {
    friend std::istream &operator >> (std::istream &input, Image &img );
    {
    ifstream inFile("polygon s.vec"); // opens the file
    if (!inFile) //Verify Open
    {
    cerr<< "Error Occurs... "<<endl;
    exit(1);
    }

    string line = input.img;


    }
    private:
    int width, height;
    Colour **pixel;// dynamically allocated 2D array

    public:
    Image(int X, int Y);
    void getpixel();
    void setpixel();
    void colour();

    }

    #endif

    [/code]

    and its source file has

    [code=cpp]
    #include <iostream>

    #include "bitmap.h"
    #include "image.h"

    using namespace std;



    Image:Image(int X, int Y)
    {
    width = X;
    height = y;

    for(int x = 0; x < width; x++)
    {
    for(int y = 0; y < height; y++)
    {
    pixels[x][y].red = x;
    pixels[x][y].green = y;
    pixels[x][y].blue = 0;
    }
    }
    }

    void image:getpixel( )
    {
    string line[i];

    ifstream inFile("example .vec"); // opens the file


    if (inFile) //Verify Open and reads from file
    {
    for(int i=0; !inFile.eof(); i++)
    inFile >> string[i];// read into an array( but has to be 2D instead with array pixel)

    inFile.close();

    }
    }

    void image:setpixel( )
    {
    ofstream outFile(Filenam e.bmp);

    if (!outFile) //Verify Open
    {
    cerr<< "Error Occurs... "<<endl;
    exit(1);
    }

    outFile<<pixel< <endl;
    }

    [/code]

    But i still havent finished it, so anyone knows what to do next in it?

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Originally posted by nemisis
      class Image
      {
      friend std::istream &operator >> (std::istream &input, Image &img );
      {
      ifstream inFile("polygon s.vec"); // opens the file
      if (!inFile) //Verify Open
      {
      cerr<< "Error Occurs... "<<endl;
      exit(1);
      }

      string line = input.img;


      }
      private:
      int width, height;
      Colour **pixel;// dynamically allocated 2D array

      public:
      Image(int X, int Y);
      void getpixel();
      void setpixel();
      void colour();

      }
      I noticed these items:
      1) why is the friend function inside the class??
      2) why is the file name hard-coded??
      3) never use exit() in the middle of a function.
      You have to a) throw an exception or b) return an error code that
      indicates failure
      4) never put hard-coded messages in your class. Use an error code.
      You will never be able to manage your screen layout if messages
      pop up unbidden from anywhere.
      5) a Colour** is not the address of a 2D array. It is the address
      of a Colour* which is the address of a single Colour object.
      6) there is no constructor to intialize the pixel*
      7) there is no destructor to clean the pixel* up.
      8) C++ does not have multi-dimensional arrays.

      Read this:
      Originally posted by weaknessforcats
      First, there are only one-dimensional arrays in C or C++. The number of elements in put between brackets:
      [code=c]
      int array[5];
      [/code]

      That is an array of 5 elements each of which is an int.

      [code=c]
      int array[];
      [/code]

      won't compile. You need to declare the number of elements.

      Second, this array:
      [code=c]
      int array[5][10];
      [/code]

      is still an array of 5 elements. Each element is an array of 10 int.

      [code=c]
      int array[5][10][15];
      [/code]

      is still an array of 5 elements. Each element is an array of 10 elements where each element is an array of 15 int.


      [code=c]
      int array[][10];
      [/code]

      won't compile. You need to declare the number of elements.

      Third, the name of an array is the address of element 0
      [code=c]
      int array[5];
      [/code]

      Here array is the address of array[0]. Since array[0] is an int, array is the address of an int. You can assign the name array to an int*.

      [code=c]
      int array[5][10];
      [/code]

      Here array is the address of array[0]. Since array[0] is an array of 10 int, array is the address of an array of 10 int. You can assign the name array to a pointer to an array of 10 int:
      [code=c]
      int array[5][10];

      int (*ptr)[10] = array;
      [/code]

      Fourth, when the number of elements is not known at compile time, you create the array dynamically:

      [code=c]
      int* array = new int[value];
      int (*ptr)[10] = new int[value][10];
      int (*ptr)[10][15] = new int[value][10][15];
      [/code]

      In each case value is the number of elements. Any other brackets only describe the elements.

      Using an int** for an array of arrays is incorrect and produces wrong answers using pointer arithmetic. The compiler knows this so it won't compile this code:

      [code=c]
      int** ptr = new int[value][10]; //ERROR
      [/code]

      new returns the address of an array of 10 int and that isn't the same as an int**.

      Likewise:
      [code=c]
      int*** ptr = new int[value][10][15]; //ERROR
      [/code]

      new returns the address of an array of 10 elements where each element is an array of 15 int and that isn't the same as an int***.

      With the above in mind this array:
      [code=cpp]
      int array[10] = {0,1,2,3,4,5,6, 7,8,9};
      [/code]
      has a memory layout of

      0 1 2 3 4 5 6 7 8 9

      Wheras this array:
      [code=cpp]
      int array[5][2] = {0,1,2,3,4,5,6, 7,8,9};
      [/code]
      has a memory layout of

      0 1 2 3 4 5 6 7 8 9

      Kinda the same, right?

      So if your disc file contains

      0 1 2 3 4 5 6 7 8 9

      Does it make a difference wheher you read into a one-dimensional array or a two-dimensional array? No.

      Therefore, when you do your read use the address of array[0][0] and read as though you have a
      one-dimensional array and the values will be in the correct locations.
      The class constructor should have an argument for the file name. Then
      1) it opens the file and throws an exception of the file won't open
      2) it read the file into an array of Colour objects.

      getpixel does not use the file. It should retreive a value from the array
      read in by the constructor.

      ditto for setpixel. Make the change in memory only

      write a serialize method that writes your memory array back to disc. Perhaps, the class has conveniently saved the file name it got the data from.

      If you are really using BMP files, then the funcitons to read an write these things have already been written.

      That said, you now need a graphical constext in which to display the map.

      That's all I have for now.

      Comment

      • nemisis
        New Member
        • May 2007
        • 61

        #4
        well I do hv the syntax to create BMP files write pixel data into it.....


        The header file-
        [code=cpp]
        /**
        * bitmap.h
        *
        * Provides functionality for writing pixel data to an ostream
        * in .bmp format.
        *
        */

        #ifndef BITMAP_H
        #define BITMAP_H

        #include <ostream>

        /**
        * Represents a colour.
        */
        struct Colour
        {
        unsigned char red;
        unsigned char green;
        unsigned char blue;
        };


        /**
        * Writes pixel data to an ostream in .bmp format.
        *
        * @param output The stream to write to.
        * The stream must be opened in binary mode.
        * For example:
        * std::ofstream file("filename. bmp", ios_base::binar y);
        * @param pixels The pixel data as a dynamically allocated
        * two-dimentional array: pixels[width][height].
        * @param width The width of the image.
        * @param height The height of the image.
        *
        * @return output.
        */
        void writeBitmap(std ::ostream & output, const Colour * const * const pixels, int width, int height) throw();

        #endif
        [/code]

        The source .cc file-
        [code=cpp]
        #include "bitmap.h"

        using namespace std;

        // Bitmap Constants:

        static const unsigned int COMPRESSION_RGB = 0;

        static const unsigned int BYTES_PER_PIXEL = 3;

        static const char * TYPE = "BM";
        static const short RESERVED1 = 0;
        static const short RESERVED2 = 0;

        static const unsigned short PLANES = 1;
        static const unsigned short BIT_COUNT = 24;
        static const unsigned int COMPRESSION = COMPRESSION_RGB ;
        static const unsigned int SIZE_IMAGE = 0;
        static const int X_PELS_PER_METE R = 0;
        static const int Y_PELS_PER_METE R = 0;
        static const unsigned int CLR_USED = 0;
        static const unsigned int CLR_IMPORTANT = 0;

        // Bitmap Structures:

        /**
        * Bitmap File Header.
        */
        struct BmpFileHeader
        {
        unsigned int size; // File size in bytes
        unsigned short reserved1; // Unused
        unsigned short reserved2; // Unused
        unsigned int offBits; // Offset to image data
        };

        /**
        * Bitmap Info Header.
        */
        struct BmpInfoHeader
        {
        unsigned int size; // Size of this structure in bytes
        int width; // Width of the bitmap
        int height; // Height of the bitmap
        unsigned short planes; // Number of planes, must equal 1
        unsigned short bitCount; // Number of bits per pixel
        unsigned int compression; // Compression used
        unsigned int sizeImage; // Image data size in bytes, can be zero for RGB images
        int xPelsPerMeter; // Image resolution in pixels-per-meter
        int yPelsPerMeter; // Image resolution in pixels-per-meter
        unsigned int clrUsed; // Indexed colours used
        unsigned int clrImportant; // Indexed colours needed to display bitmap
        };

        /**
        * Writes pixel data to an ostream in .bmp format.
        *
        * @param output The stream to write to.
        * The stream must be opened in binary mode.
        * For example:
        * std::ofstream file("filename. bmp", ios_base::binar y);
        * @param pixels The pixel data as a dynamically allocated
        * two-dimentional array: pixels[width][height].
        * @param width The width of the image.
        * @param height The height of the image.
        *
        * @return output.
        */
        void writeBitmap(ost ream & output, const Colour * const * const pixels, int width, int height) throw()
        {
        BmpFileHeader bmpFileHeader;
        BmpInfoHeader bmpInfoHeader;

        // Populate Bitmap File Header:
        bmpFileHeader.s ize = 2 + sizeof(BmpFileH eader) + sizeof(BmpInfoH eader) + (width * height * BYTES_PER_PIXEL );
        bmpFileHeader.r eserved1 = RESERVED1;
        bmpFileHeader.r eserved2 = RESERVED2;
        bmpFileHeader.o ffBits = 2 + sizeof(BmpFileH eader) + sizeof(BmpInfoH eader);

        // Populate Bitmap Information Header:
        bmpInfoHeader.s ize = sizeof(BmpInfoH eader);
        bmpInfoHeader.w idth = width;
        bmpInfoHeader.h eight = height;
        bmpInfoHeader.p lanes = PLANES;
        bmpInfoHeader.b itCount = BIT_COUNT;
        bmpInfoHeader.c ompression = COMPRESSION;
        bmpInfoHeader.s izeImage = SIZE_IMAGE;
        bmpInfoHeader.x PelsPerMeter = X_PELS_PER_METE R;
        bmpInfoHeader.y PelsPerMeter = Y_PELS_PER_METE R;
        bmpInfoHeader.c lrUsed = CLR_USED;
        bmpInfoHeader.c lrImportant = CLR_IMPORTANT;

        // Write Bitmap Identifier:
        output << TYPE;

        // Write Bitmap File Header:
        output.write(re interpret_cast< const char *>(&bmpFileHead er), sizeof(BmpFileH eader));

        // Write Bitmap Information Header:
        output.write(re interpret_cast< const char *>(&bmpInfoHead er), sizeof(BmpInfoH eader));

        // Write pixel data:
        for(int y = (height - 1); y >= 0; y--)
        {
        for(int x = 0; x < width; x++)
        {
        output.put(pixe ls[x][y].blue);
        output.put(pixe ls[x][y].green);
        output.put(pixe ls[x][y].red);
        }
        }
        }
        [/code]

        and the main driver file-
        [code=cpp]
        #include <iostream>
        #include <fstream>
        #include "bitmap.h"

        using namespace std;

        static const int WIDTH = 256;
        static const int HEIGHT = 256;

        int main()
        {
        Colour * * pixels;

        // TODO: Dynamically allocate a 2D array (WIDTH by HEIGHT)
        // of Colour instances.
        pixels = ...

        cout << "Opening file 'test.bmp'... ";
        ofstream file("test.bmp" , ios_base::binar y);
        cout << "done." << endl;

        cout << "Setting pixels... ";
        for(int x = 0; x < WIDTH; x++)
        {
        for(int y = 0; y < HEIGHT; y++)
        {
        pixels[x][y].red = x;
        pixels[x][y].green = y;
        pixels[x][y].blue = 0;
        }
        }
        cout << "done." << endl;

        cout << "Writing bitmap to 'test.bmp'... ";
        writeBitmap(fil e, pixels, WIDTH, HEIGHT);
        cout << "done." << endl;

        // TODO: Delete pixels:

        }
        [/code]

        so i need a similar array called pixel which stores the data from the .vec files into it and which can be read later on by the above code.

        I am working on what u said abt dynamically allocated 2D array, will post as soon as its ready..... meanwhile if u can have a look at the above code

        EDIT- I got help on the codes on these files so dont have much idea about the code , but do know what they do

        Comment

        • nemisis
          New Member
          • May 2007
          • 61

          #5
          ok going ahead, I have done as WFC said and finished quite a lot.

          Now I am getting errors in a particular file regarding functions.
          [code=cpp]
          #ifndef SHAPEFACTORY_H
          #define SHAPEFACTORY_H

          #include <iostream>
          #include <fstream>
          #include "Shape.h"
          #include "Point.h"
          //#include "Polygon.h"
          #include "Rectangle. h"
          #include "Line.h"
          #include "FilledRectangl e.h"



          class ShapeFactory

          {
          protected:
          // Default Constructor
          inline ShapeFactory() {}

          public:
          //pass an input stream, and return a new instance of Shape
          static Shape *getshape(const std::istream &in);


          // Destructor
          virtual ~ShapeFactory() ;

          };

          #endif
          [/code]

          and the source file is

          [code=cpp]
          #include <iostream>
          #include <fstream>
          #include "Shape.h"
          #include "ShapeFactory.h "

          //Function return newShape
          static Shape *ShapeFactory:: getShape(const std::istream &in)
          {
          if(in == "point")
          return new Point;
          if(in == "line")
          return new Line;
          if(in == "polygon")
          return new Polygon;
          if(in == "rectangle" )
          return new Rectangle;
          if(in == "filledrectangl e")
          return new FilledRectangle ;
          return NULL;
          }


          ShapeFactory::~ ShapeFactory()

          {
          }
          [/code]

          and this is the error---


          ShapeFactory.cc (12) : error C2039: 'getShape' : is not a member of 'ShapeFactory'
          ShapeFactory.h( 22) : see declaration of 'ShapeFactory'

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            That;s right getShape is not a member of ShaoeFactory but getshape is.

            Maybe the function name has been misspelled.

            Also, do not define the function as static. If you do, you can only call it from insside the cpp file where you define it. Remember, the static keyword in the class does not mean a static function. All it means is that the static function in the class does not need an object to be be called.

            While we're on this point, I would not have this function be static in the ShapeFactory. This code will compile fine:
            [code=c]
            int main()
            {
            ShapeFactory::g etShape(string ("Point"));
            }
            [/code]

            and there is no ShapeFactory object. Not a good sign.

            Make ShapeFactory::g etShape a regular member function so you have to:
            [code=c]
            int main()
            {
            ShapeFactory* f = new ShapeFactory;
            Shape* s = f.getShape(stri ng ("Point"));
            }
            [/code]
            and you have your Point object.

            Comment

            • nemisis
              New Member
              • May 2007
              • 61

              #7
              Thanks WFC that worked perfectly well !!


              OK now when i compile the whole project in linux I get this error in the shell

              gccmakedep -- -Wall -pedantic-errors -g -- Rectangle.cc Bitmap.cc Image.cc Shape.cc ShapeFactory.cc Point.cc Line.cc FilledRectangle .cc Vector.cc
              make: *** No rule to make target `Makefile', needed by `vector.exe'. Stop.

              any idea what it means? i cant make head or tail out of it

              Comment

              • weaknessforcats
                Recognized Expert Expert
                • Mar 2007
                • 9214

                #8
                I'm not a gcc user. Don't know a thing about it.

                I would post this problem as a new thread so others will look at it that know gcc.

                Comment

                • nemisis
                  New Member
                  • May 2007
                  • 61

                  #9
                  Problem solved, the name of the file was "Makefile" and the target was to "makefile", so just had to change that........... ...

                  I am trying to read from a file and pass the values to their respective classes.

                  [code=cpp]
                  int main(void)

                  {
                  int width, height,red, green, blue;



                  //Declare filename variable
                  string inVec;
                  string outBmp;

                  //keyword
                  string keyword, keyword1, keyword2, keyword3, keyword4, keyword5;

                  //Get input.vec and output.bmp files from user
                  getFiles(keywor d,inVec,outBmp) ;

                  //Declare input,output streams to read and write files
                  ifstream inFile(inVec.c_ str());
                  ofstream outFile(outBmp. c_str(),ios_bas e::binary);

                  //veirfy
                  if ( failedOpen(inFi le,outFile) == true )
                  {
                  cerr<<"Error open files... "<<endl;
                  cerr<<"Done..." <<endl;
                  exit(1);
                  }
                  else
                  {
                  //Declare Image and Colour
                  //Image myImage;
                  //Colour myColour;
                  inFile >> keyword1;
                  inFile >> keyword2;
                  inFile >> width;
                  inFile >> height;


                  inFile >> keyword3;
                  inFile >> ws;
                  char ch = inFile.get();
                  inFile >> red;
                  inFile >> green;
                  inFile >> blue;
                  ch = inFile.get();

                  inFile >> keyword4;
                  inFile >> keyword5;

                  Colour c;
                  c.blue = blue;
                  c.green = green;
                  c.red = red;

                  Image b;
                  b.setPixel(c , width, height);

                  ShapeFactory a;
                  a.Shape *getShape(std:: istream keyword5);

                  cout << "Writing bitmap to "<< outBmp <<".bmp" << endl ;
                  writeBitmap(out File, pixels, width, height);
                  cout << "done." << endl;



                  }

                  return 0;
                  }

                  bool failedOpen(ifst ream &in,ofstream &out)
                  {
                  if( (!in) || (!out))
                  {
                  return true;
                  }
                  else
                  return false;
                  }

                  void getFiles(std::s tring keyw,std::strin g &inF,std::strin g &outF)
                  {
                  cout<<"PROGRAM CONVERTS (AN IMAGE) FROM .VEC FORMAT TO .BMP FORMAT"<<endl;
                  cout<<"Please Enter the input and output filenames as format:"<<endl;
                  cout<<"vector [input file].vec [output file].bmp"<<endl;
                  getline(cin,key w,' ');
                  getline(cin,inF ,' ');
                  getline(cin,out F);
                  }
                  [/code]


                  The problem is i want it to pass to functions in different classes in line 57 and 60. these are the errors i am getting.

                  error C2248: 'ShapeFactory:: ShapeFactory' : cannot access protected member declared in class 'ShapeFactory'
                  ShapeFactory.h( 24) : see declaration of 'ShapeFactory:: ShapeFactory'
                  Vector.cc(101) : error C2039: 'Shape' : is not a member of 'ShapeFactory'
                  ShapeFactory.h( 21) : see declaration of 'ShapeFactory'
                  error C2275: 'std::istream' : illegal use of this type as an expression

                  the class ShapeFactory is as such

                  [code=cpp]
                  class ShapeFactory
                  {
                  protected:
                  // Default Constructor
                  inline ShapeFactory() {}

                  public:
                  //pass an input stream, and return a new instance of Shape
                  Shape *getShape(const std::istream &in);


                  // Destructor
                  virtual ~ShapeFactory() ;

                  };[/code]

                  [code=cpp]
                  #include "ShapeFactory.h "

                  //Function return newShape
                  Shape *ShapeFactory:: getShape(const std::istream &in)
                  {
                  if(in == "Point")
                  return new Point;
                  if(in == "Line")
                  return new Line;
                  //if(in == "polygon")
                  //return new Polygon;
                  if(in == "rectangle" )
                  return new Rectangle;
                  if(in == "Filledrectangl e")
                  return new FilledRectangle ;
                  return NULL;
                  }


                  ShapeFactory::~ ShapeFactory()

                  {
                  }[/code]


                  So how do i get the value from the main function to class Shapefactory so that it can then pass it to the respective shape?

                  Comment

                  • nemisis
                    New Member
                    • May 2007
                    • 61

                    #10
                    Also in the following code generates some errors too
                    [code=cpp]
                    #include "ShapeFactory.h "

                    //Function return newShape
                    Shape *ShapeFactory:: getShape(const std::string &in)
                    {

                    if(in == "Point")
                    return new Point;
                    if(in == "Line")
                    return new Line;
                    //if(in == "polygon")
                    //return new Polygon;
                    if(in == "rectangle" )
                    return new Rectangle;
                    if(in == "Filledrectangl e")
                    return new FilledRectangle ;
                    return NULL;
                    }


                    ShapeFactory::~ ShapeFactory()

                    {
                    }

                    [/code]

                    ShapeFactory.cc (15) : error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion)
                    could be 'built-in C++ operator==(cons t char [6], const char [6])'

                    error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion)
                    could be 'built-in C++ operator==(cons t char [5], const char [5])'

                    Comment

                    • nemisis
                      New Member
                      • May 2007
                      • 61

                      #11
                      Help!

                      file to read from points.vec, its format is described in the very first post . But just to say it again, Point- shape to make,<50 145> - <x,y>

                      Code:
                      image BMP 300 300
                      
                      colour <255 50 0>
                      draw Point <50 145>
                      draw Point <50 155>
                      
                      colour <255 52 0>
                      draw Point <52 145>
                      draw Point <52 155>
                      
                      colour <255 54 0>
                      draw Point <54 145>
                      draw Point <54 155>
                      
                      colour <255 56 0>
                      draw Point <56 145>
                      draw Point <56 155>
                      
                      colour <255 58 0>
                      draw Point <58 145>
                      draw Point <58 155>
                      
                      colour <255 60 0>
                      draw Point <60 145>
                      draw Point <60 155>
                      
                      colour <255 62 0>
                      draw Point <62 145>
                      draw Point <62 155>
                      
                      colour <255 64 0>
                      draw Point <64 145>
                      draw Point <64 155>
                      
                      colour <255 66 0>
                      draw Point <66 145>
                      draw Point <66 155>
                      
                      colour <255 68 0>
                      draw Point <68 145>
                      draw Point <68 155>
                      
                      colour <255 70 0>
                      draw Point <70 145>
                      draw Point <70 155>
                      
                      colour <255 72 0>
                      draw Point <72 145>
                      draw Point <72 155>
                      
                      colour <255 74 0>
                      draw Point <74 145>
                      draw Point <74 155>
                      
                      colour <255 76 0>
                      draw Point <76 145>
                      draw Point <76 155>
                      
                      colour <255 78 0>
                      draw Point <78 145>
                      draw Point <78 155>
                      
                      colour <255 80 0>
                      draw Point <80 145>
                      draw Point <80 155>
                      
                      colour <255 82 0>
                      draw Point <82 145>
                      draw Point <82 155>
                      
                      colour <255 84 0>
                      draw Point <84 145>
                      draw Point <84 155>
                      
                      colour <255 86 0>
                      draw Point <86 145>
                      draw Point <86 155>
                      
                      colour <255 88 0>
                      draw Point <88 145>
                      draw Point <88 155>
                      
                      colour <255 90 0>
                      draw Point <90 145>
                      draw Point <90 155>
                      
                      colour <255 92 0>
                      draw Point <92 145>
                      draw Point <92 155>
                      
                      colour <255 94 0>
                      draw Point <94 145>
                      draw Point <94 155>
                      
                      colour <255 96 0>
                      draw Point <96 145>
                      draw Point <96 155>
                      
                      colour <255 98 0>
                      draw Point <98 145>
                      draw Point <98 155>
                      
                      colour <255 100 0>
                      draw Point <100 145>
                      draw Point <100 155>
                      
                      colour <255 102 0>
                      draw Point <102 145>
                      draw Point <102 155>
                      
                      colour <255 104 0>
                      draw Point <104 145>
                      draw Point <104 155>
                      
                      colour <255 106 0>
                      draw Point <106 145>
                      draw Point <106 155>
                      
                      colour <255 108 0>
                      draw Point <108 145>
                      draw Point <108 155>
                      
                      colour <255 110 0>
                      draw Point <110 145>
                      draw Point <110 155>
                      
                      colour <255 112 0>
                      draw Point <112 145>
                      draw Point <112 155>
                      
                      colour <255 114 0>
                      draw Point <114 145>
                      draw Point <114 155>
                      
                      colour <255 116 0>
                      draw Point <116 145>
                      draw Point <116 155>
                      
                      colour <255 118 0>
                      draw Point <118 145>
                      draw Point <118 155>
                      
                      colour <255 120 0>
                      draw Point <120 145>
                      draw Point <120 155>
                      
                      colour <255 122 0>
                      draw Point <122 145>
                      draw Point <122 155>
                      
                      colour <255 124 0>
                      draw Point <124 145>
                      draw Point <124 155>
                      
                      colour <255 126 0>
                      draw Point <126 145>
                      draw Point <126 155>
                      
                      colour <255 128 0>
                      draw Point <128 145>
                      draw Point <128 155>
                      
                      colour <255 130 0>
                      draw Point <130 145>
                      draw Point <130 155>
                      
                      colour <255 132 0>
                      draw Point <132 145>
                      draw Point <132 155>
                      
                      colour <255 134 0>
                      draw Point <134 145>
                      draw Point <134 155>
                      
                      colour <255 136 0>
                      draw Point <136 145>
                      draw Point <136 155>
                      
                      colour <255 138 0>
                      draw Point <138 145>
                      draw Point <138 155>
                      
                      colour <255 140 0>
                      draw Point <140 145>
                      draw Point <140 155>
                      
                      colour <255 142 0>
                      draw Point <142 145>
                      draw Point <142 155>
                      
                      colour <255 144 0>
                      draw Point <144 145>
                      draw Point <144 155>
                      
                      colour <255 146 0>
                      draw Point <146 145>
                      draw Point <146 155>
                      
                      colour <255 148 0>
                      draw Point <148 145>
                      draw Point <148 155>
                      
                      colour <255 150 0>
                      draw Point <150 145>
                      draw Point <150 155>
                      
                      colour <255 152 0>
                      draw Point <152 145>
                      draw Point <152 155>
                      
                      colour <255 154 0>
                      draw Point <154 145>
                      draw Point <154 155>
                      
                      colour <255 156 0>
                      draw Point <156 145>
                      draw Point <156 155>
                      
                      colour <255 158 0>
                      draw Point <158 145>
                      draw Point <158 155>
                      
                      colour <255 160 0>
                      draw Point <160 145>
                      draw Point <160 155>
                      
                      colour <255 162 0>
                      draw Point <162 145>
                      draw Point <162 155>
                      
                      colour <255 164 0>
                      draw Point <164 145>
                      draw Point <164 155>
                      
                      colour <255 166 0>
                      draw Point <166 145>
                      draw Point <166 155>
                      
                      colour <255 168 0>
                      draw Point <168 145>
                      draw Point <168 155>
                      
                      colour <255 170 0>
                      draw Point <170 145>
                      draw Point <170 155>
                      
                      colour <255 172 0>
                      draw Point <172 145>
                      draw Point <172 155>
                      
                      colour <255 174 0>
                      draw Point <174 145>
                      draw Point <174 155>
                      
                      colour <255 176 0>
                      draw Point <176 145>
                      draw Point <176 155>
                      
                      colour <255 178 0>
                      draw Point <178 145>
                      draw Point <178 155>
                      
                      colour <255 180 0>
                      draw Point <180 145>
                      draw Point <180 155>
                      
                      colour <255 182 0>
                      draw Point <182 145>
                      draw Point <182 155>
                      
                      colour <255 184 0>
                      draw Point <184 145>
                      draw Point <184 155>
                      
                      colour <255 186 0>
                      draw Point <186 145>
                      draw Point <186 155>
                      
                      colour <255 188 0>
                      draw Point <188 145>
                      draw Point <188 155>
                      
                      colour <255 190 0>
                      draw Point <190 145>
                      draw Point <190 155>
                      
                      colour <255 192 0>
                      draw Point <192 145>
                      draw Point <192 155>
                      
                      colour <255 194 0>
                      draw Point <194 145>
                      draw Point <194 155>
                      
                      colour <255 196 0>
                      draw Point <196 145>
                      draw Point <196 155>
                      
                      colour <255 198 0>
                      draw Point <198 145>
                      draw Point <198 155>
                      
                      colour <255 200 0>
                      draw Point <200 145>
                      draw Point <200 155>
                      
                      colour <255 202 0>
                      draw Point <202 145>
                      draw Point <202 155>
                      
                      colour <255 204 0>
                      draw Point <204 145>
                      draw Point <204 155>
                      
                      colour <255 206 0>
                      draw Point <206 145>
                      draw Point <206 155>
                      
                      colour <255 208 0>
                      draw Point <208 145>
                      draw Point <208 155>
                      
                      colour <255 210 0>
                      draw Point <210 145>
                      draw Point <210 155>
                      
                      colour <255 212 0>
                      draw Point <212 145>
                      draw Point <212 155>
                      
                      colour <255 214 0>
                      draw Point <214 145>
                      draw Point <214 155>
                      
                      colour <255 216 0>
                      draw Point <216 145>
                      draw Point <216 155>
                      
                      colour <255 218 0>
                      draw Point <218 145>
                      draw Point <218 155>
                      
                      colour <255 220 0>
                      draw Point <220 145>
                      draw Point <220 155>
                      
                      colour <255 222 0>
                      draw Point <222 145>
                      draw Point <222 155>
                      
                      colour <255 224 0>
                      draw Point <224 145>
                      draw Point <224 155>
                      
                      colour <255 226 0>
                      draw Point <226 145>
                      draw Point <226 155>
                      
                      colour <255 228 0>
                      draw Point <228 145>
                      draw Point <228 155>
                      
                      colour <255 230 0>
                      draw Point <230 145>
                      draw Point <230 155>
                      
                      colour <255 232 0>
                      draw Point <232 145>
                      draw Point <232 155>
                      
                      colour <255 234 0>
                      draw Point <234 145>
                      draw Point <234 155>
                      
                      colour <255 236 0>
                      draw Point <236 145>
                      draw Point <236 155>
                      
                      colour <255 238 0>
                      draw Point <238 145>
                      draw Point <238 155>
                      
                      colour <255 240 0>
                      draw Point <240 145>
                      draw Point <240 155>
                      
                      colour <255 242 0>
                      draw Point <242 145>
                      draw Point <242 155>
                      
                      colour <255 244 0>
                      draw Point <244 145>
                      draw Point <244 155>
                      
                      colour <255 246 0>
                      draw Point <246 145>
                      draw Point <246 155>
                      
                      colour <255 248 0>
                      draw Point <248 145>
                      draw Point <248 155>
                      
                      colour <255 250 0>
                      draw Point <250 145>
                      draw Point <250 155>
                      my code--

                      Bitmap.h
                      [code=cpp]
                      #ifndef BITMAP_H
                      #define BITMAP_H

                      #include <ostream>

                      /**
                      * Represents a colour.
                      */
                      struct Colour
                      {
                      unsigned char red;
                      unsigned char green;
                      unsigned char blue;
                      };


                      /**
                      * Writes pixel data to an ostream in .bmp format.
                      *
                      * @param output The stream to write to.
                      * The stream must be opened in binary mode.
                      * For example:
                      * std::ofstream file("filename. bmp", ios_base::binar y);
                      * @param pixels The pixel data as a dynamically allocated
                      * two-dimentional array: pixels[width][height].
                      * @param width The width of the image.
                      * @param height The height of the image.
                      *
                      * @return output.
                      */
                      void writeBitmap(std ::ostream & output, const Colour * const * const pixels, int width, int height) throw();

                      #endif

                      [/code]

                      Bitmap.cc
                      [code=cpp]
                      #include "Bitmap.h"

                      using namespace std;

                      // Bitmap Constants:

                      static const unsigned int COMPRESSION_RGB = 0;

                      static const unsigned int BYTES_PER_PIXEL = 3;

                      static const char * TYPE = "BM";
                      static const short RESERVED1 = 0;
                      static const short RESERVED2 = 0;

                      static const unsigned short PLANES = 1;
                      static const unsigned short BIT_COUNT = 24;
                      static const unsigned int COMPRESSION = COMPRESSION_RGB ;
                      static const unsigned int SIZE_IMAGE = 0;
                      static const int X_PELS_PER_METE R = 0;
                      static const int Y_PELS_PER_METE R = 0;
                      static const unsigned int CLR_USED = 0;
                      static const unsigned int CLR_IMPORTANT = 0;

                      // Bitmap Structures:

                      /**
                      * Bitmap File Header.
                      */
                      struct BmpFileHeader
                      {
                      unsigned int size; // File size in bytes
                      unsigned short reserved1; // Unused
                      unsigned short reserved2; // Unused
                      unsigned int offBits; // Offset to image data
                      };

                      /**
                      * Bitmap Info Header.
                      */
                      struct BmpInfoHeader
                      {
                      unsigned int size; // Size of this structure in bytes
                      int width; // Width of the bitmap
                      int height; // Height of the bitmap
                      unsigned short planes; // Number of planes, must equal 1
                      unsigned short bitCount; // Number of bits per pixel
                      unsigned int compression; // Compression used
                      unsigned int sizeImage; // Image data size in bytes, can be zero for RGB images
                      int xPelsPerMeter; // Image resolution in pixels-per-meter
                      int yPelsPerMeter; // Image resolution in pixels-per-meter
                      unsigned int clrUsed; // Indexed colours used
                      unsigned int clrImportant; // Indexed colours needed to display bitmap
                      };

                      /**
                      * Writes pixel data to an ostream in .bmp format.
                      *
                      * @param output The stream to write to.
                      * The stream must be opened in binary mode.
                      * For example:
                      * std::ofstream file("filename. bmp", ios_base::binar y);
                      * @param pixels The pixel data as a dynamically allocated
                      * two-dimentional array: pixels[width][height].
                      * @param width The width of the image.
                      * @param height The height of the image.
                      *
                      * @return output.
                      */
                      void writeBitmap(ost ream & output, const Colour * const * const pixels, int width, int height) throw()
                      {
                      BmpFileHeader bmpFileHeader;
                      BmpInfoHeader bmpInfoHeader;

                      // Populate Bitmap File Header:
                      bmpFileHeader.s ize = 2 + sizeof(BmpFileH eader) + sizeof(BmpInfoH eader) + (width * height * BYTES_PER_PIXEL );
                      bmpFileHeader.r eserved1 = RESERVED1;
                      bmpFileHeader.r eserved2 = RESERVED2;
                      bmpFileHeader.o ffBits = 2 + sizeof(BmpFileH eader) + sizeof(BmpInfoH eader);

                      // Populate Bitmap Information Header:
                      bmpInfoHeader.s ize = sizeof(BmpInfoH eader);
                      bmpInfoHeader.w idth = width;
                      bmpInfoHeader.h eight = height;
                      bmpInfoHeader.p lanes = PLANES;
                      bmpInfoHeader.b itCount = BIT_COUNT;
                      bmpInfoHeader.c ompression = COMPRESSION;
                      bmpInfoHeader.s izeImage = SIZE_IMAGE;
                      bmpInfoHeader.x PelsPerMeter = X_PELS_PER_METE R;
                      bmpInfoHeader.y PelsPerMeter = Y_PELS_PER_METE R;
                      bmpInfoHeader.c lrUsed = CLR_USED;
                      bmpInfoHeader.c lrImportant = CLR_IMPORTANT;

                      // Write Bitmap Identifier:
                      output << TYPE;

                      // Write Bitmap File Header:
                      output.write(re interpret_cast< const char *>(&bmpFileHead er), sizeof(BmpFileH eader));

                      // Write Bitmap Information Header:
                      output.write(re interpret_cast< const char *>(&bmpInfoHead er), sizeof(BmpInfoH eader));

                      // Write pixel data:
                      for(int y = (height - 1); y >= 0; y--)
                      {
                      for(int x = 0; x < width; x++)
                      {
                      output.put(pixe ls[x][y].blue);
                      output.put(pixe ls[x][y].green);
                      output.put(pixe ls[x][y].red);
                      }
                      }
                      }
                      [/code]

                      Image.h
                      [code=cpp]
                      #ifndef IMAGE_H
                      #define IMAGE_H

                      #include <fstream>
                      #include "Bitmap.h"

                      class Image
                      {
                      private:
                      int width;
                      int height;
                      Colour * * pixels;

                      public:
                      //Constructor
                      Image(int,int);

                      //Default Constructor
                      inline Image() {}

                      //Stream insertion operator that uses to output Image to .bmp file
                      void operator<<(std: :ostream &out);

                      //Get information from a speccific location
                      Colour getPixel(int,in t);

                      //Set a speccific pixel
                      void setPixel(Colour &Co,int,int) ;

                      //Destructor
                      ~Image();
                      };

                      #endif
                      [/code]

                      Image.cc
                      [code=cpp]
                      #include <iostream>
                      #include "Bitmap.h"
                      #include "Image.h"

                      Image::Image (int widthIn, int heightIn)
                      {
                      width = widthIn;
                      height = heightIn;

                      //Dynamic memory allocate
                      pixels = new Colour*[width];

                      for(int i=0; i<height; i++)
                      {
                      pixels[i] = new Colour[height];
                      }

                      //Set defaul colour (black)
                      for(int x = 0; x < width; x++)
                      {
                      for(int y = 0; y < height; y++)
                      {
                      pixels[x][y].red = 0;
                      pixels[x][y].green = 0;
                      pixels[x][y].blue = 0;
                      }
                      }

                      }

                      Colour Image::getPixel (int x,int y)
                      {

                      //Check the location(pixel)
                      if ((x <= width) && (y <= height))
                      return pixels[x][y];
                      else
                      {
                      // Define colour black
                      Colour black;
                      black.red = 0;
                      black.green = 0;
                      black.blue = 0;
                      return black;
                      }
                      }

                      void Image::setPixel (Colour &Co,int x,int y)
                      {
                      //Check if (x,y) is still inside the Image
                      if ((x >= width) || (y >= height) || ( x < 0 ) || (y < 0))
                      return;
                      else
                      {
                      pixels[x][y].red = Co.red;
                      pixels[x][y].green = Co.green;
                      pixels[x][y].blue = Co.blue;
                      }

                      }

                      void Image::operator <<(std::ostre am &out)
                      {
                      writeBitmap(out ,pixels,width,h eight);
                      }

                      Image::~Image()
                      {
                      for(int i=0;i< height;i++)
                      {
                      delete pixels[i];
                      }
                      delete[] pixels;
                      }
                      [/code]

                      Shape.h
                      [code=cpp]
                      #ifndef SHAPE_H
                      #define SHAPE_H


                      #include "Image.h"
                      #include "Bitmap.h"

                      class Shape

                      {
                      //protected:
                      // Default Constructor
                      //inline Shape() {}

                      public:
                      inline Shape() {}

                      // Pure virtual function
                      virtual void draw(Image &Im,Colour &Co) const = 0;
                      // Destructor
                      virtual ~Shape();

                      };

                      #endif
                      [/code]

                      Shape.cc
                      [code=cpp]
                      #include "Shape.h"

                      Shape::~Shape() {}
                      [/code]

                      ShapeFactor.h
                      [code=cpp]
                      #ifndef SHAPEFACTORY_H
                      #define SHAPEFACTORY_H

                      #include <iostream>
                      #include <fstream>
                      #include "Shape.h"
                      #include "Point.h"
                      //#include "Polygon.h"
                      //#include "Rectangle. h"
                      //#include "Line.h"
                      //#include "FilledRectangl e.h"



                      class ShapeFactory
                      {
                      //protected:
                      // Default Constructor
                      //inline ShapeFactory() {}

                      public:
                      //pass an input stream, and return a new instance of Shape
                      Shape *getShape(std:: string &in);
                      inline ShapeFactory() {}
                      //Shape *callPoint(int &Xaxis,int &Yaxis,int &r,int g,int &b);

                      // Destructor
                      virtual ~ShapeFactory() ;

                      };

                      #endif
                      [/code]

                      ShapeFactory.cc
                      [code=cpp]
                      #include <iostream>
                      #include <fstream>
                      #include "Shape.h"
                      #include "ShapeFactory.h "
                      #include "Image.h"
                      #include <string>

                      using namespace std;

                      //Function return newShape
                      Shape *ShapeFactory:: getShape(std::s tring &in)
                      {
                      Image Im;
                      Colour Co;
                      Point p;

                      int width, height, red,green,blue, x1,y1,x2,y2;
                      string keyword1,keywor d2,keyword3,key word4,keyword5, keyword6,keywor d7,keyword8,key word9;
                      string s1 = "Point";
                      string s2 = "Line";
                      string s3 = "Rectangle" ;
                      string s4 = "Polygon";
                      string s5 = "Filledrectangl e";


                      if(in.compare(s 1)==0)
                      {

                      fstream myFile ("points.vec ");
                      myFile >> keyword1;
                      cout<<keyword1< <endl;
                      myFile >> keyword2;
                      cout<<keyword2< <endl;
                      myFile >> width;
                      cout<<width<<en dl;
                      myFile >> height;
                      cout<<height<<e ndl;

                      myFile >> keyword3;
                      cout<<keyword3< <endl;

                      //lour * * pixels;



                      //fo int k=0; k<3; k++)

                      string s ="colour";
                      myFile >> ws;
                      char ch = myFile.get();
                      myFile >> red;
                      myFile >>green;
                      myFile >>blue;
                      ch = myFile.get();

                      myFile >> keyword4;
                      cout<<keyword4< <endl;
                      myFile >> keyword5;
                      myFile>>ws;
                      ch = myFile.get();
                      myFile >>x1;
                      myFile >>y1;
                      ch = myFile.get();

                      Co=Im.getPixel (x1,y1);
                      p.draw(Im,Co);

                      myFile >> keyword6;
                      myFile >> keyword7;
                      myFile>>ws;
                      ch = myFile.get();
                      myFile >> x2;
                      myFile >> y2;
                      cout<<y2<<endl;
                      ch = myFile.get();
                      Im.getPixel (x2,y2);
                      p.draw(Im,Co);


                      }
                      /* if(in.compare(s 2)==0)
                      // return new Line();
                      //if(in.compare(s 4)==0)
                      //return new Polygon();
                      if(in.compare(s 3)==0)
                      // return new Rectangle();
                      if(in.compare(s 5)==0)
                      // return new FilledRectangle ();*/
                      return NULL;
                      }


                      ShapeFactory::~ ShapeFactory()
                      {

                      }/*Shape *ShapeFactory:: callPoint(int &Xaxis,int &Yaxis,int &r,int g,int &b)
                      {
                      Point a;
                      Colour Co;
                      Co.red = r;
                      Co.blue = b;
                      Co.green = g;
                      //a.drawImage(Col our &Co, int x, int y);

                      }*/
                      [/code]

                      Point.h
                      [code=cpp]
                      #ifndef POINT_H
                      #define POINT_H


                      #include "Shape.h"
                      #include "Image.h"

                      class Point : public Shape

                      {
                      friend std::ostream & operator << (std::ostream &out, const Point &);
                      friend std::istream & operator >> (std::istream &in, Point &);

                      protected:
                      // Coordinator
                      int x;
                      int y;

                      public:
                      //Constructor
                      inline Point(int x0,int y0)
                      : x(x0) , y(y0) {}

                      //Default Constructor
                      inline Point() {}

                      virtual void draw(Image &Im,Colour &Co) const;
                      void drawImage(Colou r &Co, int x, int y);
                      //Destructor
                      virtual ~Point();
                      };

                      #endif
                      [/code]

                      Point.cc
                      [code=cpp]
                      #include <iostream>
                      #include "Image.h"
                      #include "Shape.h"
                      #include "Point.h"

                      using namespace std;

                      istream & operator >> (istream &in, Point &point0)

                      {
                      int x0,y0;


                      in >> ws;//whitespace
                      char ch = in.get();//obtain brackets
                      in >> x0;
                      in >> y0;
                      ch = in.get();
                      point0.x = x0;
                      point0.y = y0;


                      return in;

                      }

                      // outputs a Point instance to stream

                      ostream & operator << (ostream &out, const Point &point0)
                      {
                      out << "(" << point0.x << "," <<point0.y << ")"<<endl;
                      return out;
                      }

                      void Point::drawImag e(Colour &Co, int x, int y)
                      {

                      //Point::draw(&Im ,&Co)
                      cout << "i point cPP";


                      }
                      void Point::draw(Ima ge &Im,Colour &Co) const
                      {
                      //Draw point with specific Colour
                      Im.setPixel(Co, x,y);
                      }

                      Point::~Point() {}


                      [/code]

                      Vector.cc
                      [code=cpp]
                      #include <iostream>
                      #include <fstream>
                      #include <string>

                      using namespace std;
                      using std::ifstream;

                      //Struct Colour, writeBitmap()
                      #include "Bitmap.h"

                      //Image class
                      #include "Image.h"
                      #include "ShapeFactory.h "

                      //Shape class
                      #include "Shape.h"
                      #include "Point.h"
                      //#include "Line.h"
                      //#include "Rectangle. h"
                      //#include "FilledRectangl e.h"
                      //#include "Polygon.h"

                      //Functions Parameter
                      void getFiles(string keyw,string &inF,string &outF);
                      //bool failedOpen(ifst ream &in,ofstream &out);


                      int main(void)

                      {
                      int width, height,r, g, b, Xaxis, Yaxis;



                      //Declare filename variable
                      string inVec;
                      string outBmp;

                      //keyword
                      string keyword, keyword1, keyword2, keyword3, keyword4,keywor d5;


                      //Get input.vec and output.bmp files from user
                      getFiles(keywor d,inVec,outBmp) ;

                      //Declare input,output streams to read and write files
                      ifstream inFile(inVec.c_ str());
                      ofstream outFile(outBmp. c_str(),ios_bas e::binary);

                      //verify
                      //if ( failedOpen(inFi le,outFile) == true )
                      if(!inFile)
                      {
                      cout<<"Error open files... "<<endl;

                      }
                      else
                      {
                      //Declare Image and Colour
                      Image myImage;
                      Colour myColour;


                      inFile >> keyword1;
                      inFile >> keyword2;
                      inFile >> width;
                      inFile >> height;


                      inFile >> keyword3;


                      string s ="colour";
                      if(keyword3.com pare(s) == 0)
                      {inFile >> ws;
                      char ch = inFile.get();
                      inFile >> r;
                      inFile >> g;
                      inFile >> b;
                      ch = inFile.get();}

                      inFile >> keyword4;
                      inFile >> keyword5;





                      /*string s1 = "Point";
                      string s2 = "Rectangle" ;
                      if(keyword5.com pare(s1) == 0)
                      {
                      //code for point
                      cout << "i am in point"<<endl;
                      ch = inFile.get();
                      inFile >> Xaxis;
                      inFile >> Yaxis;
                      ch = inFile.get();
                      }*/


                      Colour * * pixels;

                      // Dynamically allocate a 2D array (width by height)
                      // of Colour instances.

                      pixels = new Colour*[width];

                      for(int i=0; i<height; i++)
                      {
                      pixels[i] = new Colour[height];

                      }



                      cout << "Creating "<< outBmp << endl ;
                      writeBitmap(out File, pixels, width, height);
                      cout << "done" << endl;

                      /*for(int x = 0; x < width; x++)
                      {
                      for(int y = 0; y < height; y++)
                      {
                      pixels[x][y].red = r;
                      pixels[x][y].green = g;
                      pixels[x][y].blue = b;
                      }
                      }
                      */

                      ShapeFactory a;
                      a.getShape(keyw ord5);
                      //a.callPoint(Xax is,Yaxis,r,g,b) ;

                      //myImage.getPixe l( , );

                      cout<< "finished drawing a point"<<endl;

                      for(int i=0;i< height;i++)
                      {
                      delete pixels[i];
                      }
                      delete[] pixels;



                      }

                      return 0;
                      }

                      /*bool failedOpen(ifst ream &in,ofstream &out)
                      {
                      if( (!in) || (!out))
                      {
                      return true;
                      }
                      else
                      return false;
                      }*/

                      void getFiles(std::s tring keyw,std::strin g &inF,std::strin g &outF)
                      {
                      cout<<"PROGRAM CONVERTS (AN IMAGE) FROM .VEC FORMAT TO .BMP FORMAT"<<endl;
                      cout<<"Please Enter the input and output filenames as format:"<<endl;
                      cout<<"vector [input file].vec [output file].bmp"<<endl;
                      getline(cin,key w,' ');
                      getline(cin,inF ,' ');
                      getline(cin,out F);
                      }
                      [/code]

                      All this does is create a bmp file but doesnt draws the points into it. most of my code is just trial and error but the functions defined are well good. basically i hv to use the draw() function to draw the point into the bmp file.

                      Comment

                      • nemisis
                        New Member
                        • May 2007
                        • 61

                        #12
                        anyone? anything? something?

                        Comment

                        • Banfa
                          Recognized Expert Expert
                          • Feb 2006
                          • 9067

                          #13
                          Could you give a quick summary (i.e. something that fits on a screen without needing to scroll) of what the problem you where trying to describe in post 11 of this thread is please?

                          Comment

                          • nemisis
                            New Member
                            • May 2007
                            • 61

                            #14
                            ok in the main function where object of Shapefactory is called, after its function returns a new shape, i need to read the file from the line where the shape's coordinates are described.


                            Using the stream operator of the specific shape i hv to read the rest of the file from the pace where it says " draw Point <50 50>" and output this to the .bmp file using the 'draw()' function.

                            Here is a description of each of the classes....

                            struct Colour
                            Represents a colour as three values between 0 (no contribution) and 255 (full contribution) for each of
                            red, green and blue.
                            Colour must provide stream operators to read from and write to a stream in the format:
                            <red green blue>
                            For example, a Colour object representing red would be written to a stream as:
                            <255 0 0>


                            class Image
                            Stores pixel data for an image that is to be written to an output bitmap (.bmp) file.
                            Image must have a constructor that takes two int parameters: width and height.
                            Image must maintain pixel data as a dynamically allocated 2-dimensional array of Colour objects. It
                            must create the array, populate it with initial values and delete it when no longer needed. By default all pixel colours must be set to black (red, green and blue
                            values equal to 0).
                            Image must have getPixel() and setPixel() member functions that get and set the Colour at a
                            specified pixel location. If setPixel() is called with an invalid pixel location (one outside the
                            image) it should do nothing and return without error. If getPixel() is called with an invalid pixel
                            location it should return a Colour object representing black.
                            The Image class must also have a stream insertion operator that uses the provided writeBitmap()
                            to output itself in bitmap (.bmp) format.

                            class Shape
                            Represents a drawable vector shape. All shapes used within the project must be a sub-class of Shape.
                            Shape itself must have a pure virtual draw() member function that is used to draw Shape sub-classes
                            to an Image. The draw() member function must be passed an Image object to draw onto and a Colour
                            object representing the colour that the shape should be drawn in. Shape and its sub-classes must not
                            keep an instance variable representing its own colour. This is not known until the draw() member
                            function is called..
                            Each sub-class of Shape must also be able to read itself from and write itself to a stream using the
                            stream operators.

                            class ShapeFactory
                            Constructs shapes from an input stream.
                            ShapeFactory must have a member function called getShape() that is passed an input stream
                            (std::istream) and returns a new instance of Shape (or more accurately, one of its sub-classes) that is
                            read from the stream. The ShapeFactory must therefore be aware of the keywords used within the input
                            vector (.vec) file for each of the different Shape sub-classes. It is responsible for reading these
                            keywords from the stream, creating an instance of the appropriate Shape sub-class and populating it
                            from the stream by using the Shape’s own stream extraction operator.

                            Comment

                            Working...