When performing operations that modify Parasolid entities, it is necessary to keep the HOOPS representation of the model synchronized with its Parasolid representation. Because such operations are typically initiated by selecting (hit-testing) HOOPS geometric objects, it is necessary to determine what Parasolid entity(s) correspond with the selected HOOPS entities, and vice versa. The HOOPS/Parasolid integration includes routines which support this requirement.
HOOPS geometric entities are identified by HOOPS 'keys'. Keys are renumbered within the integration code to have Parasolid-specific values after being created as a result of the Parasolid PK_TOPOL_render_XXX routines. Recall that Parasolid entities are referred to by a Parasolid 'tagID'. Given a HOOPS key, the HP_Compute_TagID function will return the Parasolid tagID for the Parasolid entity that the specified HOOPS geometric entity is associated with. Conversely, given a Parasolid tagID, the HP_Compute_Geometry_Keys function will return all the HOOPS keys for the tessellated geometry or the HOOPS segment associated with the Parasolid entity. (Recall that a Parasolid entity might be represented by more than one HOOPS geometric entity.)
Selection on the HOOPS scene returns the key(s) of HOOPS geometry, requiring us to find the Parasolid entity that the selected HOOPS geometry is associated with. If we wanted to access the Parasolid 'body' entity given the key of a selected HOOPS geometric primitive, we would call:
We can now use the tagID of the Parasolid entity to perform Parasolid operations, or to access the HOOPS geometric primitives which represent the Parasolid entity.
Highlighting a Parasolid entity involves performing a selection on the HOOPS scene and highlighting the HOOPS geometry associated with the Parasolid entity. After identifying the Parasolid entity associated with the selected HOOPS geometry (described in the previous section), we need to access the HOOPS geometry or segment which represents the entity.
In the following code example, we compute all the HOOPS geometry that is associated with the 'edges' and 'faces' of the selected Parasolid entity. This may also be referred to as 'Parasolid body-level selection'. (Recall that Parasolid entities are composed of PK_FACE and PK_EDGE entities, whose tessellated representations are sent to HOOPS via the HP_Render_Entity call. HP_Render_Entity encapsulates calls to the PK_TOPOL_render_facet and PK_TOPOL_render_line routines.)
This returns the number of HOOPS keys associated with the given Parasolid entity, and places their values into the 'keys' array. Alternately, the call to HP_Compute_Geometry_Key_Count could be omitted, and HP_Compute_Geometry_Keys could be called using the 'max_count' parameter, which specifies the maximum number of keys desired. In the following code example, the last argument in the function call instructs HOOPS to limit the number of returned keys to 40000:
If the mapping option "create body segments" is true and we are dealing with a Parasolid 'body', we know that there is a unique HOOPS segment which contains all the geometry associated with a Parasolid 'body' entity. Therefore, in this case we can simply ask for the key of the HOOPS segment associated with the body and highlight the entire segment, rather than individually compute and highlight each geometric primitive:
The HOOPS primitives can be highlighted by moving them from their current HOOPS segment into a segment with different rendering attributes (color, linestyle, etc...). A HOOPS segment can be highlighted by directly modifying its rendering attributes. Using the HOOPS/MVO HSelectionSet class as a base, we can utilize defined geometry and segment selection (highlight) methods to create a Parasolid-application-specific SelectionSet class and 'Select' function as follows.
This derived class will not only support body level selection, but will also support several 'selection levels' as indicated by the m_SelectLevel variable. It also adds another variable of type HVarray, in order to store the list of selected Parasolid entities; the base class only deals with storing the list of selected HOOPS primitives that are associated with the selected Parasolid entity.
The HOOPS/Parasolid Reference Application contains an implementation of HPSelectionSet, which includes the above Select function and definition of the m_SelectLevel type. Refer to HSSelectionSet.h and HSSelectionSet.cpp for the interface and implementation of the class.
Identification, and selection (highlighting) of the HOOPS geometry associated with a particular Parasolid entity is usually an intermediate step in performing a useful modeling operation. This section provides an example of how to perform a Boolean operation.
The Parasolid Boolean function, PK_BODY_Boolean_2, operates at the level of a Parasolid 'body'. It requires the definition of a 'target' body entity, the 'tool' body entities that will operate on the target, and a description of the Boolean operation to be performed. After the function is called, the HP_Render_Entity function needs to be called to send the tessellated representation of the final target body to HOOPS. (See the section on Creating and Rendering Parasolid Entities.)
The syntax of the function is as follows:
The result of the Boolean operation is returned as an array of bodies. We can create a utility function called 'parasolid_Boolean', which encapsulates the Parasolid Boolean function call and associated rendering function call as follows.
Recall that the HOOPS geometric primitives that are created as a result of the HP_Render_Entity function will be placed into the currently open HOOPS segment, requiring us to open a segment first. Additionally, given a list of selected HOOPS geometry, we need to determine the corresponding Parasolid 'target' and 'tool' entities to be passed to the 'parasolid_Boolean' function. The following function is a method of the HParaView class (HSolidView.h and HSolidView.cpp), which is part of the HOOPS/Parasolid Reference Application. It performs the following operations:
- Walks the solid selection list object (HSSelectionSet) to locate the 'target' and 'tool' bodies to be used in the Boolean operation. The first entity in the solid selection list is the 'target', and the remaining entities are the 'tools'.
- Deselects all the items in the selection list. The DeSelectAll() function call will clear out the solid selection list that was added to the derived class, and also call the base class' DeSelectAll function which deselects all the associated HOOPS primitives that have been selected/highlighted.
- Deletes the HOOPS primitives associated with the target and tool bodies from the HOOPS database. This is necessary since the Parasolid 'target' and 'tool' bodies will be removed from the database after the Boolean, and a new body will be created and rendered. Therefore, we need to remove the HOOPS geometry that represented the target and tool bodies. As discussed in the previous section (Deleting Parasolid and HOOPS Geometry) we call HP_Delete_Entity_Geometry to delete the HOOPS geometry associated with the Parasolid entities.
- Opens a HOOPS segment in the model object and calls the 'parasolid_Boolean' function previously discussed.
Many other Parasolid modeling operations that delete and create new Parasolid entities would require a similar procedure of identifying and deleting the HOOPS geometric primitives associated with the Parasolid entities. In any case, the process outlined above must be followed through in order to synchronize the HOOPS database's segments and primitives with the Parasolid kernel.
Other Parasolid operations on Parasolid entities may not require deletion of corresponding HOOPS geometry, but rather they may require that a HOOPS attribute be modified to keep the two systems in sync. For example, a transformation to a Parasolid BODY (using PK_BODY_transform) needs to be reflected in HOOPS by setting the corresponding HOOPS modeling matrix in the segment containing the geometric representation of the BODY. Such an operation is handled in the HOOPS/Parasolid Reference Application's HPOpObjectTranslate class. (HPOpObjectTranslate.h and HPOpObjectTranslate.cpp).