Parasolid Import

RedParasolid is the result of a prototype integration of HOOPS Luminate with Siemens Parasolid. It demonstrates that drawing Parasolid powered models is easy and efficient using Tech Soft 3D’s HOOPS Luminate at the cost of a small extra development.

The REDParasolid distribution is made of two main components:

  • The Core Library (Parasolid.m) that performs Parasolid to HOOPS Luminate part conversion (facets or edges)

  • The Viewer (ParasolidViewer.e) that lets the user navigate through the converted models and play with selection features

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 HOOPS Luminate shapes (see the HOOPS Luminate 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 HOOPS Luminate 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 HOOPS Luminate 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 HOOPS Luminate 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.

../../../_images/bk_id_parasolid_import_parasolid_file.png

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

The HOOPS Luminate Shape Attributes

Data converted to HOOPS Luminate 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:

  • Vertices Channel: each mesh vertex is defined as a 3d position made of 3 doubles (we chose to keep data in double precision for better numerical robustness)

  • Normals Channel: each vertex has a normal associated with in order to compute proper per-pixel lighting

  • Colours Channel: each vertex has a RGBA colour quadruplet associated with that is used as the diffuse colour while shading the geometry

For edges, a HOOPS Luminate 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 HOOPS Luminate RED::UserData class called PartData. Instances of this class can be freely associated with HOOPS Luminate 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 HOOPS Luminate, a few steps are required:

  • The class must have its own class ID (CID in HOOPS Luminate) that uniquely identifies it

  • The class must declare a chunk signature that will identify it inside RED streams (files)

  • The class must implement the HOOPS Luminate dynamic casting mechanism (known as ‘As’ mechanism)

  • Finally the class must defines implementations of some requested methods: UnlinkFrom (inherited from RED::UserData), Save (inherited from RED::IChunkSaver) for supporting saving to RED streams, and Interpret, a callback used to read from RED streams.

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 HOOPS Luminate shape corresponds to a given face or edge in Parasolid.

../../../_images/bk_id_parasolid_import_parasolid_face.png

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 HOOPS Luminate, we introduce a data structure that associates a range of HOOPS Luminate vertices with a Parasolid tag. We call this structure an ElementDefinition.

../../../_images/bk_id_parasolid_import_luminate_triangles.png

The same face as above as defined in the corresponding HOOPS Luminate 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.

../../../_images/bk_id_parasolid_import_luminate_geometry.png

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:

  • The HOOPS Luminate picking mechanism (providing mouse coordinates, one can retrieve all the primitives covered by the mouse cursor)

  • The PartData instances seen above

When the user moves the mouse cursor above the geometry, primitives under it are retrieved using the HOOPS Luminate 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 HOOPS Luminate shape associated to the Parasolid element by modifying its colour per vertex attributes.

The viewport shader

This sample application uses the HOOPS Luminate built-in viewport shader to render geometries (see RED::RenderShaderViewport in the HOOPS Luminate 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.

../../../_images/bk_id_parasolid_import_selection.png

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 HOOPS Luminate (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!