Parasolid import

RedParasolid is the result of a prototype integration of REDsdk with Siemens Parasolid. It demonstrates that drawing Parasolid powered models is easy and efficient using Redway3d's REDsdk at the cost of a small extra development.

The REDParasolid distribution is made of two main components:

Source codes for both components are provided as is. Note that you'll need Qt in order to be able to recompile the source code of the viewer (version 4.4.2 was used here).

The core library (Parasolid.m)

The core library exposes very few API calls to convert Parasolid models to REDsdk shapes (see the REDsdk documentation for further information about the concepts). It gives the ability to the user to convert Parasolid part files to RED streamable data (i.e writable to RED files) while preserving sufficient topology information to allow features selection.

It comes with a Microsoft Visual Studio 2010 solution to let you modify and rebuild the library. Be aware that if you change the library's DLL API, you will not be able to use it any more with the pre-compiled viewer. To make it work you'll need to download Nokia's Qt from the web and recompile the viewer too.

The data conversion process

As demonstrated in the Parasolid example applications, we use the Graphical Output (GO) mechanism to retrieve tessellated data from the modeller. Facets data are converted to RED::IMeshShape instances (see the REDsdk documentation for further details about interfaces and concepts) and edges data are converted to RED::ILineShape.

The API

The library exposes three main functions:

  1. Setup, this function must be called at least once and prior any call to others library functions. It ensures that needed initializations are performed including default colours, custom error handler and Parasolid schemas files path settings.
  2. ConvertFromParasolidFile, this function converts the content of a Parasolid 'x_t' file to one or several REDsdk shapes. The user can choose to retrieve triangles, segments or both data from the file. If both types are requested, they are returned as successive pairs inside the list.
  3. ConvertFromParasolidPart, this function converts directly from a Parasolid part instead of a file.

Whatever the type of data is, additional topological information are stored using the RED::UserData mechanism of REDsdk and linked with each created shapes. This makes interactive triangles and edges selection possible using only the graphic representation of the data right inside the viewport.

A Parasolid file as seen in the sample viewer. Faces are rendered Phong-shaded while edges are rendered in solid blue.

The REDsdk shape attributes

Data converted to REDsdk shapes have different sets of attributes depending on the source data type (faces or edges). In the case of faces, a triangular mesh is generated with three data channels:

For edges, a REDsdk line shape is generated including the same information than above except the normals channel that has no meaning in this case.

The topological information

The library declares and exposes a custom implementation of the REDsdk RED::UserData class called PartData. Instances of this class can be freely associated with REDsdk shapes and automatically saved and restored to/from RED files as long as reading/writing methods implementations are provided. To achieve the seamless integration of this custom class with REDsdk, a few steps are required:

Implementations for those methods are given in the PartData.cpp file.

In Parasolid, edges and faces are marked with tags when output through the GO mechanism (see the figure below). We use those tags to identify which part of a REDsdk shape corresponds to a given face or edge in Parasolid.

A face in Parasolid has a tag (16 in this case).

As a Parasolid face or edge can be composed of several triangles or segments in REDsdk, we introduce a data structure that associates a range of REDsdk vertices with a Parasolid tag. We call this structure an ElementDefinition.

The same face as above as defined in the corresponding REDsdk shape (two triangles along with their vertices indexes).

This way, all the vertices belonging to the triangles of a Parasolid face are marked with the tag of that face. The same occurs for segments. The ElementDefinition instances are then added to the PartData which stores them in a smart way for later quick access.

The resulting shape attributes and element definition for the previous Parasolid face.

The selection mechanism

The selection performed on graphical data (instead of modeler ones) relies on two features:

mouse cursor)

When the user moves the mouse cursor above the geometry, primitives under it are retrieved using the REDsdk picking feature. Once retrieved, the closest one to the viewer is selected and used as input to the corresponding PartData to get back the associated Parasolid element (face or edge). Once done, we highlight the subpart of the REDsdk shape associated to the Parasolid element by modifying its colour per vertex attributes.

The viewport shader

This sample application uses the REDsdk built-in viewport shader to render geometries (see RED::RenderShaderViewport in the REDsdk documentation). This shader features a complete while simple shading model suitable for quick viewport rendering of per-pixel lit meshes. It also features a 'highlighting' capability. Using it, one can render selected vertices using a different colour than the one computed with the shading model.

The same shader can be used for segments as well as triangles with the difference that the former will be rendered unshaded (i.e using the vertex and ambient colours to compute a constant colour) while the latter will benefit of a complete shading model (thanks to its normals channel). Both can still benefit of the shader highlight feature.

The highlight feature of the viewport shader in action. Selected edges are rendered in green, selected triangles in red.

The viewer (ParasolidViewer.e)

The viewer is a Qt-based application. Using it, you can convert Parasolid models, navigate, select, export to RED/reload from RED files. It demonstrates reference implementations of several core concepts of REDsdk (Interfaces, RED file format customization, dynamic casting, mesh edition, picking, materials & lighting...) in a small and easy to read package.

The viewer lets you load Parasolid .x_t files as well as .red ones. Loaded files can be export to RED file format embedding the custom topological information described in the topological information section.

Once loaded you can navigate through the data by using the mouse. A left click set the focus point under the cursor. Moving the mouse with the left button pressed lets you pan the view; with the right button pressed, you rotate around the focus point. Finally, the mouse wheel lets you zoom in/out the model. When no button is pressed, the primitive under the mouse cursor is highlighted with priority given to edges.

The viewer source code demonstrates the implementation of a custom model navigation, RED file loading & saving, interfacing the RedParasolid module, material creation and more!