ImageGear for C and C++ on Windows v19.4 - Updated
CAD and Vector
User Guide > How to Work with... > Formats with Additional Functionality > CAD and Vector

ImageGear provides 3D vector graphics support. The vector data is stored as an internal object attached to HIGEAR image handle. Use the IG_image_is_vector function to check whether the image contains vector data.

Once you have a HIGEAR with vector data, you can display and print it, apply certain image processing operations, and save it to vector formats, using the same API that you use for raster images.

In the case of Vector/CAD images, ImageGear allows accessing vector data for image formats such as DWG, DWF, XPS, CGM, SVG, and others. It allows you to show the vector data using different viewpoints, as well as to change scale factors, position, and rotation angles. Use the IG_image_is_CAD function to find out whether the image is a CAD/Vector image.

The ImageGear Vector component provides base operations for reading such vector formats as CAD (DXF/DWG), DWF, DGN, CGM, and HPGL and drawing vector data during display operations. For information about the file formats, see CGM, DGN, DWF, DWG, DXF, HPGL, HPGL/2, and SVG.

This component allows you to switch between OpenGL and Direct3D rendering engines dynamically. By default, ImageGear uses the Automatic mode, which selects the actual render as follows:

This provides for a universal automated solution across different hardware and software configurations.

This section provides information about how to...

Load a Vector Drawing

Loading a vector drawing is done using the same functions used to load other types of images. See Loading Images for details.

However, before loading the drawing, you must first enable support for the vector components you want to use. See Attaching Components for details. ImageGear provides the following CAD/Vector Components:

Rasterize a Vector Drawing

When a vector image is loaded into HIGEAR, its DIB remains empty (it does not contain raster data). You can rasterize the vector image to be able to apply the whole set of raster image processing operations on it or save it to raster formats. Use IG_vector_data_to_dib for this.

Create and Modify a Vector Drawing

This section provides information about the following aspects of working with a vector drawing:

Coordinates

Every point in the vector data has three coordinates - x, y, z. If this is enough for the point description, then the point is defined by the simple structure IGVectPoint3D. The examples of such points are: start and end point of the easy line, the point of the easy surface, minimum and maximum coordinates of the viewport. But often the point must have some additional attributes. They are: visibility, bulge and thickness of the outgoing line or the weight if the point belongs to the NURBS curve or surface. In these cases the point is represented by the Vertex structure IGVectVertex. Vertexes are created and owned by the Vertex Container. The Vertex container controls all additional Vertex attributes.

Angles

All angles are measured in radians. So, if you have an angle in degrees, you have to translate it to radian using the formula:

Ang_rad = ang_degree / 180 * VECT_PI;

Where VECT_PI is defined in vectapi.h

Colors

All colors in a Drawing have four 8-bit components: red, green, blue, and alpha. Alpha provides transparency for the color. Alpha equal to 255 means fully opaque color; 0 means full transparency.

Also, the structure describing a color (IGVectColorEx) has a field defining the color source.

Text

Vector text is defined by the entity of type IG_VECT_ENT_TEXT. It has some common text attributes such as base line angle and the type of alignment. Moreover, the text string is separated to the several Text Objects which have they own attributes such as font, font width and height, char base and char up angles, color, char spacing and some additional effects. The Text Object is created, owned and destroyed by the Text entity. It can be accessed via the handle HIG_VECT_TEXTOBJ and functions with the prefix IG_vect_textobj_... .

Text strings are stored inside the Vector component as Unicode (UTF8). There are API functions that allow working with vector text as in Code Page, as in Unicode (UTF16) form.

The following functions work with the text as with Code Page:

The following functions work with the text as with Unicode (UTF16):

Fonts

Drawing can use two font types:

Gradients

Gradient filling properties are encapsulated by a HIG_VECT_GRADIENT handle. This handle is attached to a HIG_VECT_FILLTYPE object.

There are two types of gradient fillings:

The color of the gradient is defined by an array of stops. A stop is a pair of offset and color. Stop offsets are relative to gradient coordinates: 0.0 corresponds to the start point; 1.0 corresponds to the end points, in case of a linear gradient, or to a point at the outer circle, in case of radial gradient. If first stop offset is greater than 0.0, or last stop offset is less than 1.0, the gradient is expanded, according to its Spread method. Gradient color is linearly interpolated between the stops.

Gradient filling can be transformed with an affine matrix.

Add a U3D Annotation to a PDF Page

Refer to the U3D annotation to PDF page Sample for complete sample code that illustrates how to use this capability.

Insert a Raster Image into a Vector Drawing

ImageGear allows storage of raster entities with vector data. Some vector formats, such as CGM, allow embedding raster data in the vector image. Other formats, such as DWG and DXF, allow adding a reference to a raster image. SVG format allows both file reference and embedded raster data.

Use IG_vect_drwng_create_entity function to create a raster entity. Use IG_vect_raster_init function to initialize dimensions of the raster and allocate pixel data. Alternatively, you can initialize raster data from a HIGEAR image, using IG_vect_raster_init_from_HIGEAR.

Use IG_vect_raster_get_lefttop, IG_vect_raster_get_righttop, IG_vect_raster_get_leftbottom and IG_vect_raster_get_rightbottom functions to access world coordinates of the raster entity corners. The image can be stretched or skewed according to these coordinates.

The following example creates a new raster entity and adds it to a drawing:

C and C++
Copy Code
HIG_VECT_DRWNG drawing;
HIG_ENTITY raster;
HIG_VECT_VIEW view;
HIG_VECT_ENTYTY content;
HIG_VECT_ENTYTYCONT entityContent;
IGVectPoint3D* leftTop;
IGVectPoint3D* leftBottom;
IGVectPoint3D* rightTop;
IGVectPoint3D* rightBottom;

// Create vector data and configure views, or load a vector image.

// Create raster entity
IG_vect_drwng_create_entity(drawing, IG_VECT_ENT_RASTER, "", & raster);
IG_vect_raster_init(raster, imageWidth, imageHeight);

// Set world coordinates for the raster entity.
IG_vect_raster_get_lefttop(raster, &leftTop);
IG_vect_raster_get_righttop(raster, &rightTop);
IG_vect_raster_get_leftbottom(raster, &leftBottom);
IG_vect_raster_get_rightbottom(raster, &rightBottom);
leftTop->m_x = 0;
leftTop->m_y = 0;
leftTop->m_z = 0;
rightTop->m_x = 100;
rightTop->m_y = 0;
rightTop->m_z = 0;
leftBottom->m_x = 0;
leftBottom->m_y = 100;
leftBottom->m_z = 0;
rightBottom->m_x = 100;
rightBottom->m_y = 100;
rightBottom->m_z = 0;

The following example initializes raster data from a HIGEAR handle:

C and C++
Copy Code
HIGEAR image;
HIG_VECT_DRWNG drawing;
HIG_ENTITY raster;
HIG_VECT_VIEW view;
HIG_VECT_ENTYTY content;
HIG_VECT_ENTYTYCONT entityContent;

// Create vector data and configure views, or load a vector image.

// Create raster entity.
IG_vect_drwng_create_entity(drawing, IG_VECT_ENT_RASTER, "", & raster);
// Initialize raster entity from a HIGEAR handle.
IG_vect_raster_init_from_HIGEAR(raster, image);

// Set world coordinates for the image.

// Add entity to the view to make it visible.
IG_vect_drwng_get_view(drawing, 0, &view);
IG_vect_view_get_content(view, &content);
IG_vect_block_get_entitycont(content, &entityContent);
IG_vect_entcont_add_entity(entityContent, raster);

Use IG_vect_raster_save_to_HIGEAR to save raster data to a new HIGEAR image.

Raster data is stored in 32 bpp RGBA format, and can be accessed as an array of IGVectColor structures. Use IG_vect_raster_get_data function to obtain the pointer to the raster data. Raster data does not have padding bytes at the end of raster, so it can be accessed as two-dimensional array of IGVectColor with size equal to width * height, where width and height are raster image dimensions.

If the vector file format allows embedding raster data into an image (to CGM or SVG formats), saving raster data to a file, together with the rest of the vector entities, does not require extra steps.

In order to save raster data as a reference (to DWG, DXF or SVG format), save raster data to a separate image file, and add file reference to the raster entity, using IG_vect_raster_set_filename function.

The following example demonstrates saving raster data to DXF format.

C and C++
Copy Code
// Vector image.
HIGEAR vectorImage;
// Raster image handle to export raster data to.
HIGEAR rasterImage;
// Raster entity within vector image.
HIG_ENTITY rasterContent;
CHAR rasterFileName[256];

// Create or load a vector image.

// Save raster entity as a separate raster file.
IG_vect_raster_save_to_HIGEAR(rasterContent, &rasterImage);
IG_save_file(rasterImage, rasterFileName, IG_SAVE_JPG);

IG_vect_raster_set_filename(rasterContent, rasterFileName);

// Save vector image.
IG_save_file(vectorImage, IG_FORMAT_DXF);

Access Vector Drawing Entities

Vector data (Drawing) is accessible via the handle HIG_VECT_DRWNG and the set of functions having the prefix IG_vect_drwng_... .

The content of the Drawing consists of vector primitives - Entities. The samples of the entities are: easy line, text, polyline, block and other. The Entity is created by the Drawing and accessible via the handle HIG_VECT_ENTITY.

Any Entity has some common attributes. They are: Identifier, type, Layer and some flags: Dirty, Selected, Deleted. Entity has also several optional attributes, which do not exist until they are created. These attributes are: draw color, fill color, line type, fill type, thickness, offset, rotation, scale and position. All common Entity features and attributes are accessible via HIG_VECT_ENTITY handle and functions with prefix IG_vect_ent_... .

There is a set of functions for access to the unique features of the entity. They all have the corresponding prefix. For example, the IG_vect_ellipse_get_radiusx function returns the radius along the x axes of the ellipse:

C and C++
Copy Code
IG_vect_ellipse_get_radiusx (HIG_VECT_ENTITY entity, float* radiusx);

The Layer is an object that contains attributes, which can be applied to the group of the entities. The Layer is created by the Drawing and accessed by the handle HIG_VECT_LAYER and functions with the prefix IG_vect_layer_... .

Drawing can have several Views, that is, different points of view to the set of Entities. Every View is represented by its Camera attributes such as position, scale, rotation, focus. A View can be created and destroyed.

Save a Vector Drawing

Use regular image saving functions to save a vector image into ImageGear. See Saving Images.