/**
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is part of The iWear Framework.
 * In particular this file is part of the Framework Core Library
 *
 * The iWear Framework is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the
 * Free Software Foundation as in version 2 of the License.

 *
 * The iWear Framework is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * The iWear Framework; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __IMGGRAPHICS_H
#define __IMGGRAPHICS_H

#include <math.h>
#include <Magick++.h>

using namespace std;
using namespace Magick;

namespace iwear {
namespace utils {
namespace images {

struct P3D {
    double x, y, z;
};
    
enum positioning {XY_PLAIN, XZ_PLAIN, YZ_PLAIN};
enum viewdir {POS, NEG};
enum colorname {BLUE, RED, GREY};

class ImgGraphics {

    private:

	// The image
	Image img;

	// fields for oplacing the picture in the world
	P3D p_ll, p_ur;
	positioning pos;
	viewdir view;
	
    public:

	static ColorRGB getColorRGB(colorname c);

	/**
	 * Constructor
	 */
	ImgGraphics();
	
	/**
	 * Destructor
	 */
	~ImgGraphics();
	
	/**
	 * Open an existing image
	 * @param filename The filename of the image
	 */
	void read(char* filename);
	
	void read_str(string filename);
	
	/**
	 * Save the image
	 * @param filename The filename of the image
	 */
	void write(char* filename);
	
	/**
	 * Draw a filled circle into the image at position (px,py) with diameter r and the Color color
	 * @param img The image into which a circle has to be drawn
	 * @param px The x position of the centre point of the circle
	 * @param py The y position of the centre point of the circle
	 * @param r The diameter of the circle
	 * @param color The border and fill color of the circle
	 */
	void draw_filled_circle(int px, int py, int r, ColorRGB color);

	/**
	 * Crop the image to the given ratio between width and height
	 * @param image The image has to be cropped
	 * @param ratio The ratio between width and height of the image after cropping
	 */
	void crop_image(const double ratio);

	/**
	 * Add a new image at the (middle) left of actual image
	 * @param img_new The new image to be added
	 */
	void add_left(Image& img_new);

	/**
	 * Add a new image at the (middle) right of actual image
	 * @param img_new The new image to be added
	 */
	void add_right(Image& img_new);

	/**
	 * Add a new image at the (center) top of actual image
	 * @param img_new The new image to be added
	 */
	void add_top(Image& img_new);

	/**
	 * Add a new image at the (center) bottom of actual image
	 * @param img_new The new image to be added
	 */
	void add_bottom(Image& img_new);

	/**
	 * Scale the image to the given xsize and ysize
	 * @param xsize the new pixel width of the image
	 * @param ysize the new pixel height of the image
	 */
	void scale(int xsize, int ysize);

	/**
	 * Put another image into this image at given position
	 * @param img_new The Image to put in
	 * @param xoffset The x position where the image should put to
	 * @param yoffset The y position where the image should put to
	 */
	void composite(Image img_new, int xoffset, int yoffset);

	/**
	 * Place the image in the world. Example: p=XY_PLAIN, v=NEG means the
	 * image is parallel to the XY_PLAIN and is to be viewed from the 
	 * negative y-side.
	 * @param p The plain the image is parallel to (XY_PLAIN, XZ_PLAIN, YZ_PLAIN)
	 * @param v The direction the image is to be viewed from (POS, NEG)
	 */
        void set_image_placing(positioning p, viewdir v);
	
	/**
	 * Set coords of the lower left vertex of the image in real
	 * world for marking points in the image
	 * @param x The x coord of the lower left vertex
	 * @param y The y coord of the lower left vertex
	 * @param z The z coord of the lower left vertex
	 */
        void set_lower_left(double x, double y, double z);

	/**
	 * Set coords of the upper right vertex of the image in real
	 * world for marking points in the image
	 * @param x The x coord of the upper right vertex
	 * @param y The y coord of the upper right vertex
	 * @param z The z coord of the upper right vertex
	 */
        void set_upper_right(double x, double y, double z);

	/**
	 * Mark a point on the image, if the image has its position
	 * in the world
	 * @param x The x coord of the upper right vertex
	 * @param y The y coord of the upper right vertex
	 * @param z The z coord of the upper right vertex
	 * @param size The size/radius of the point
	 * @param color The color of the point, get it by getColorRGB
	 */
        void mark_point(double x, double y, double z, int size, ColorRGB color);
};
    
} // namespace images
} // namespace utils
} // namespace iwear

#endif // __IMGGRAPHICS_H

