Class Image

Index Home MAE > MAE Architecture > MAE Data Types > Class Index > Class Image

Summary
Using Image
Graphics Commnds
setSize()
setOrigin()
setWindow()
drawBox()
drawLine()
drawCircle()
drawText()
drawArc()
drawPolygon()
drawPolyline()
Public Methods
Image(group_id, imageName, module)
Image(imagelib)
Image(data)
bool setSize(newWidth, newHeight, newUnitSize)
bool setOrigin(newOriginX, newOriginY)
bool setWindow(minX, minY, maxX, maxY, newUnitSize)
inline long getPixels(length) const
bool setLineWidth(width)
bool setLineType(linetype)
bool setClipBox(corner1, corner2)
bool clearClipBox()
bool drawBox(corner1, corner2, color, fill, link)
bool drawLine(pt1, pt2, color, link)
bool drawCircle(center, radius, color, fill, link)
bool drawArc(center, startang, endang, radius, color, fill, link)
bool drawPolygon(ptlist, color, fill, link)
inline bool drawPolygon(ptlist, size, color, fill, link)
bool drawPolyline(ptlist, color, link)
inline bool drawPolyline(ptlist, size, color, link)
bool drawText(start, text, color, link)
bool comment(comment)
bool drawImage(center, image, scaler, rotation)
string renderToString(format) const
bool renderToFile(f, format) const
bool addCommand(command)
XMLData getCommand(cmdPos) const
inline vector& getCommands()
string getId() const
inline int getGroupId() const
inline const string& getModule() const
inline const string& getName() const
inline ImageLibId getImageLibId() const
inline string getImageName() const
inline void getWindow(ll, ur)
bool setId(id)
bool setId(group_id, imageName, module)
inline void setGroupId(id)
inline void setImageLibId(id)
void setModule(newModule)
void setName(newName)
inline bool isSaved() const
inline bool isChanged() const
inline void setSaved()
inline void setChanged()
inline int size() const
inline double getWidth() const
inline int getWidthPixels() const
inline double getHeight() const
inline int getHeightPixels() const
inline double getUnitSize() const
inline Point getOrigin() const
inline int getPixelWidth() const
inline int getPixelHeight() const
void clear()
void clearImage()
void clearArea(corner1, corner2, whole)
inline bool valid() const
XMLData toXML() const
Image& fromXML(data, imageOnly)
static inline void setSVGTagFNs(start, end)
Private Properties
Private Methods
void transform(p, translate, scale, rotate)
void transform(p, translate, scale, rotate)
inline int px(x) const
inline int py(y) const
inline int dx(x) const
inline int dy(y) const
string svgLinkStart(link) const
string svgLinkEnd(link) const
string renderToStringGD() const
string renderToStringSVG() const
static bool pointInsideBox(pt, ll, ur)

#include <Image.h >

Summary

This class represents images within the MAE system.

Images may be drawn by the app or pulled from ImageLib database table.

Drawn images draw into a coordinate system with the size (height, width) and origin specified by the application.  For example, to create an image with a coordinate system that is 5 units wide and 4 units tall with the origin(0,0) in the center, you specify setSize(5, 4) and setOrigin(-2.5,-2).  How large the image is when it is displayed depends upon the unit size. If you'd like your 5 unit wide image to be 50 pixes wide, then specify setSize(5, 4, 10).

To display an image to the user, see the UserDevice class.

Use this class to communicate with imager, which renders them appropriately for the user.

Using Image

This data structure abstracts a vector image.  The API is used to describe the image.  It is not rendered into JPG, PNG, SVG, or other specific image technology until it is ready to be rendered to the end-user.  Rendering is performed by the imager daemon.

The API could be richer, but the API must be able to render to each of the ultimate image types.

The Image class may refer to an existing image file in a specific format via ImageLib class, which specifies where to retrieve the image and the image's size.

Graphics Commnds

setSize()

setSize(double newWidth, double newHeight, int newUnitSize)

Set the canvas dimensions and specify how many pixes per unit.  For example, a 4.0x5.0 image where unit size is 10 would create a 40x50 pixel image.

setOrigin()

setOrigin(double newOriginX, double newOriginY)

Specify how many units over the origin should be located if (0,0) is the lower left

setWindow()

setWindow(double minX, double minY, double maxX, double maxY, int newUnitSize)

Specify the width and origin implicitly by specifying the window into the view.  Use this instead of setSize() setOrigin()

drawBox()

drawBox([[#Point]] corner1, Point corner2, string color, bool fill, string link)

Draw a rectangle with the corners specified.  Default color is black.  The box may be an outline or solid/fiilled.

An optional link (e.g. URL) may be provided if resulting image supports linking.

drawLine()

drawLine([[#Point]] p1, Point p2, string color, string link)

Draw a line from p1 to p2 of the color specified.

An optional link (e.g. URL) may be provided if resulting image supports linking.

drawCircle()

drawCircle([[#Point]] center, double radius, string color, bool fill, string link)

Draw a full circle with the specified center and radius.  The default color is black.  The circle may be an outline or solid/fiilled.

An optional link (e.g. URL) may be provided if resulting image supports linking.

drawText()

drawText([[#Point]] start, string text, string color, string link)

Draw text into the image with the lower left corner of the text at the start point.

drawArc()

bool drawArc([[#Point]] center, double startang, double endang, double radius, string color, bool fill)

drawPolygon()

drawPolygon([[#Point]]List p, string color, bool fill, string link)

Given a series of points, draw the enclosed polygon.  The default color is black.  The polygon may be an outline or solid/fiilled.

An optional link (e.g. URL) may be provided if resulting image supports linking.

drawPolyline()

drawPolyline([[#Point]]List p, string color, string link)

Given a series of points, the the line that connects them from start to end.  The default color is black.

An optional link (e.g. URL) may be provided if resulting image supports linking.

Public Methods

Image(group_id, imageName, module)

int group_id

this is an application-specific number to differentiate this image name from others; it is used to help create a unique image name for the user's display device

Default value: 0

const string& imageName

this is the application-specific name given to the image

Default value: ""

const string& module

this is the application-specific category for the image, such as the application's name

Default value: ""


Construct an empty image.

Image(imagelib)

const ImageLib& imagelib

image library image; see ImageLib


Construct an image from the ImageLib database table.

Image(data)

const XMLData& data

XML data that describes how to create the image, from toXML()


Construct an image from data.

bool setSize(newWidth, newHeight, newUnitSize)

double newWidth

the width of the image in your defined coordinate system

double newHeight

the height of the image in your defined coordinate system

double newUnitSize

number of pixels that represents a unit in your defined coordinate system; the width in pixels will be newWidth * newUnitSize; if you specify 0, then the previous value will hold

Default value: 0


Specify how many units wide and tall the image is; specify how many pixels are in a unit

bool setOrigin(newOriginX, newOriginY)

double newOriginX

specify how many units to the left from the right side is x=0

double newOriginY

specify how many units to the down from the top side is y=0


Specify how many units over the origin should be located if (0,0) is the upper right

Return value: true if successfully set

bool setWindow(minX, minY, maxX, maxY, newUnitSize)

double minX

The value of x at the leftmost side of the image

double minY

The value of y at the bottom side of the image

double maxX

The value of x at the rightmost side of the image

double maxY

The value of x at the top side of the image

double newUnitSize

Default value: 0


Specify the width and origin implicitly by specifying the window into the view.

Use this instead of setSize() & setOrigin()

Return value: true if new window accepted

inline long getPixels(length) const

double length

length in image's coordinate system


When you need to know display size, you can query how many pixels it takes to draw the provided length.

This can be helpful to understand how much detail to draw into an image.

Return value: number of pixels

bool setLineWidth(width)

double width

line thickness (in coordinate system units)

Default value: 0.0


Specify the thickness of a line (if too small, it will still be one pixel wide)

Return value: true if successfully added to the image

bool setLineType(linetype)

const string& linetype

the line type to use to draw, e.g. solid, dotted, dashed, dotdash

Default value: "solid"


Specify the type of line, e.g. solid, dotted, dashed, dotdash - if supported

Return value: true if successfully added to the image

bool setClipBox(corner1, corner2)

const Point& corner1

(x,y) coordinates of a corner of the box

const Point& corner2

(x,y) coordinates of the opposite corner


Clip the commands that follow so only what is inside the provided box is visible.

Return value: true if successfully added to the image

bool clearClipBox()

Turn off the clip box so all is drawn again.

Return value: true if successfully added to the image

const Point& corner1

(x,y) coordinates of a corner of the box

const Point& corner2

(x,y) coordinates of the opposite corner

const string& color

the color to use to draw this

Default value: "black"

bool fill

true to fill in the shape; false to draw only the outline

Default value: true

const string& link

address of where to go if the user clicks on this shape

Default value: ""


Draw a rectangle of a color, solid or outline

Return value: true if successfully added to the image

const Point& pt1

(x,y) coordinates of the start of the line segment

const Point& pt2

(x,y) coordinates of the end of the line segment

const string& color

the color to use to draw this

Default value: "black"

const string& link

address of where to go if the user clicks on this shape

Default value: ""


Draw a line segment between two points of a color

Return value: true if successfully added to the image

const Point& center

(x,y) coordinates of center of the circle

double radius

the radius of the circle from its center out to its perimeter

const string& color

the color to use to draw this

Default value: "black"

bool fill

true to fill in the shape; false to draw only the outline

Default value: true

const string& link

address of where to go if the user clicks on this shape

Default value: ""


Draw a circle with a center and radius of a color, solid or outline

Return value: true if successfully added to the image

const Point& center

(x,y) coordinates of center of the arc

double startang

the start angle of the arc, in radians

double endang

the ending angle of the arc, in radians

double radius

the radius of the arc from its center out to its perimeter

const string& color

the color to use to draw this

Default value: "black"

bool fill

true to fill in the shape; false to draw only the outline

Default value: true

const string& link

address of where to go if the user clicks on this shape

Default value: ""


Draw an arc with a center and radius of a color, solid or outline

Return value: true if successfully added to the image

const PointList& ptlist

a list of points that specifies a polygon's outline; the last point will automatically be connected to the first point

const string& color

the color to use to draw this

Default value: "black"

bool fill

true to fill in the shape; false to draw only the outline

Default value: true

const string& link

address of where to go if the user clicks on this shape

Default value: ""


Draw a polygon from a series of points of a color, solid or outline

Return value: true if successfully added to the image

Point* ptlist

a list of points that specifies a polygon's outline; the last point will automatically be connected to the first point

int size

the number of points in ptlist

const string& color

the color to use to draw this

Default value: "black"

bool fill

true to fill in the shape; false to draw only the outline

Default value: true

const string& link

address of where to go if the user clicks on this shape

Default value: ""


Draw a polygon from a series of points of a color, solid or outline

Return value: true if successfully added to the image

const PointList& ptlist

a list of points that specifies a polygon's outline; the last point will automatically be connected to the first point

const string& color

the color to use to draw this

Default value: "black"

const string& link

address of where to go if the user clicks on this shape

Default value: ""


Draw a series of line segments from a series of points of a color, solid or outline

Return value: true if successfully added to the image

Point* ptlist

a list of points that specifies a polygon's outline; the last point will automatically be connected to the first point

int size

the number of points in ptlist

const string& color

the color to use to draw this

Default value: "black"

const string& link

address of where to go if the user clicks on this shape

Default value: ""


Draw a series of line segments from a series of points of a color, solid or outline

Return value: true if successfully added to the image

const Point& start

(x,y) location where the text starts; this is the lower left corner of the first character

string text

the text to display

const string& color

the color to use to draw this

Default value: "black"

const string& link

address of where to go if the user clicks on this shape

Default value: ""


Write text into the image of a color

Return value: true if successfully added to the image

bool comment(comment)

const string& comment

the text of the comment


Add a comment, that may or may not appear in the final image source as a comment.

Return value: true if successfully added to the image

bool drawImage(center, image, scaler, rotation)

Point center

the target (x,y) location where the new image will be centered

const Image& image

the image to draw

double scaler

as the new image is draw, it can be scalled up ( >1.0) or down (0.0-1.0)

Default value: 1

double rotation

how much to rotate the image before it is drawn, in radians

Default value: 0


Put an image into an image, possibly scaled or rotated

Return value: true if successfully added to the image

string renderToString(format) const

const string& format

the binary format of the image, e.g. svg, gdplot

Default value: "gdplot"


Convert the image into representation as text in a string

Return value: true if successfully added to the image

bool renderToFile(f, format) const

FILE* f

the file where the image representation will be written

const string& format

the binary format of the image, e.g. svg, gdplot

Default value: "gdplot"


Convert the image into representation as text in a file

Return value: true if successfully added to the image

bool addCommand(command)

const XMLData& command

an XML representation of a drawing command to add


Add a command into the image.  This is provided so images can be transmitted and reconstructed. An app should not construct its own commands and add them.

Return value: true if successfully added to the image

XMLData getCommand(cmdPos) const

int cmdPos

location of command to get


Query a specific drawing command from the image.  This is provided so images can be transmitted and reconstructed.

Return value: an XML representation of a drawing command

inline vector <XMLData >& getCommands()

Get all the commands used to create the drawing.  This is provided so images can be transmitted and reconstructed.

Return value: the full drawing as XML commands

string getId() const

Get the image's id, which is contructed from its group id, name, and module.

Return value: the image's id

inline int getGroupId() const

Get the group id of the image

Return value: the group id

inline const string& getModule() const

Get the module name of the image

Return value: the module name

inline const string& getName() const

Get the name of the image

Return value: the image name

inline ImageLibId getImageLibId() const

Get the image record id in ImageLib database table.

Return value: 0 if no record, otherwise the record id

inline string getImageName() const

Get the image full name (include group id and module).

inline void getWindow(ll, ur)

Point& ll

(output) the lower left (x,y) coordinates of the image

Point& ur

(output) the upper right (x,y) coordinates of the image


Query the window corners in the image; this is the drawable area.

This is not the clipped region.

bool setId(id)

const string& id

the id for the image


Set an image's id.

Return value: image id

bool setId(group_id, imageName, module)

int group_id

this is an application-specific number to differentiate this image name from others; it is used to help create a unique image name for the user's display device

const string& imageName

this is the application-specific name given to the image

const string& module

this is the application-specific category for the image, such as the application's name


Set the id by its parts - group id, image name, and module

inline void setGroupId(id)

DbRecNum id

new group id


Set the group id

inline void setImageLibId(id)

ImageLibId id

record id: 0 if none, 1+ for the record


Set the image record id in ImageLib database table.

void setModule(newModule)

const string& newModule

the module/category for image


Set the module for the image

void setName(newName)

const string& newName

image name


Set the name of the image

inline bool isSaved() const

Determine if image has been saved

Return value: true if image has been saved; false if image needs to be saved

inline bool isChanged() const

Determine if image has been changed and needs to be saved

Return value: true if image needs to be saved; false if image unchanged

inline void setSaved()

Make note that the image has saved.

inline void setChanged()

Make note that the image has changed and needs to be saved.

inline int size() const

Query the size of the image, as measured by number of commands.

Return value: number of commands / image size

inline double getWidth() const

Query the width of the image in image-defined units.

Return value: width of image

inline int getWidthPixels() const

Query the width of the image in pixels.

Return value: width of image in pixels

inline double getHeight() const

Query the height of the image in image-defined units.

Return value: height of image

inline int getHeightPixels() const

Query the height of the image in pixels.

Return value: height of image in pixels

inline double getUnitSize() const

Get the unit size - the number of pixels per unit.

Return value: pixels in a unit

inline Point getOrigin() const

Query the location of the origin in the image

Return value: the (x,y) offset from the upper right corner

inline int getPixelWidth() const

Get the full width of the image in pixels.

inline int getPixelHeight() const

Get the full height of the image in pixels.

void clear()

Reset the image back to a blank, empty image.

void clearImage()

Clear all the commands that make the image (but keep the drawing window and settings)

void clearArea(corner1, corner2, whole)

const Point& corner1

One corner of the box to erase

const Point& corner2

The opposite corner of the box to erase

bool whole

true if whole component to erase is drawn within the box; false if just part of a component is drawn within the box to erase it

Default value: true


Clear all commands that draw in the area specified. You can specify whether the whole image or just part of the image must be in the box to be erased.

inline bool valid() const

Query if the current image is valid.

Return value: true if valid; false if invalid

XMLData toXML() const

Convert the image to XML.

Return value: XML representation of the image

Image& fromXML(data, imageOnly)

const XMLData& data

XML representation

bool imageOnly

true to copy only the commands; false to copy commands, window, and setings

Default value: false


Create an image from XML representation, appended into current image

Return value: the image instance

static inline void setSVGTagFNs(start, end)

svgTagFN start

method to call to create start of SVG tag text

svgTagFN end

method to call to create end of SVG tag text


Override the default SVG tag generators

Private Properties

int group_id

The image's group id

string name

The image's name

string module

The image's module/category

ImageLibId imageLibId

If from the ImageLib library, its id

bool changed

Flag: has our data changed?

double width

The window size in app-define coordinates

double height

The window size in app-define coordinates

Point origin

The origin as measured from the lower left

double unit_size

The number of pixes per coordinate system unit

vector <XMLData > commands

The command needed to construct the image

static svgTagFN svgStartTag

method for starting an SVG image

static svgTagFN svgEndTag

method for starting an SVG image

svgEndTag; svgEndTag

method for finishing an SVG image


Private Methods

void transform(p, translate, scale, rotate)

Point& p

the point to transform

Point translate

the amount to translate (shift) the point

double scale

the amount to scale the point (distance from origin)

double rotate

the amount to rotate the point around the origin


Transform a point by translating, scaling, and rotating it.

void transform(p, translate, scale, rotate)

PointList& p

the list of points to transform

Point translate

the amount to translate (shift) the points

double scale

the amount to scale the points (distance from origin)

double rotate

the amount to rotate the points around the origin


Transform a series of points by translating, scaling, and rotating them.

inline int px(x) const

double x

x-axis distance to convert


Get the horizontal pixel distance from the origin for the x coordinate

Return value: number of pixels

inline int py(y) const

double y

y-axis distance to convert


Get the vertical pixel distance from the origin for the y coordinate

Return value: number of pixels

inline int dx(x) const

double x

x-axis distance to convert


The number of pixels to move amount along x direction

Return value: number of pixels

inline int dy(y) const

double y

y-axis distance to convert


The number of pixels to move amount along y direction

const string& link


Create the start of a SVG link.

const string& link


Create the end of a SVG link.

string renderToStringGD() const

Render to GD image library.

string renderToStringSVG() const

Render to an SVG image.

static bool pointInsideBox(pt, ll, ur)

const Point& pt

const Point& ll

const Point& ur


Determine if the provided point lands inside the specified box.