GPU-Based Sections Visualization

Andrew Markovich

December 19, 2019

Starting with ODA SDKs version 2020 Update 1, you can draw geometry sections in real-time. This functionality can be used by different products that require the ability to investigate object geometry structure. Compared with sections calculated on the CPU side, GPU-based sections don’t generate any output geometry or analytical section information; they can be used only for visual representation of sectioning results.

 

example sectioning results


This kind of sectioning is processed completely by the GPU. This is means that the CPU is free for other tasks during section rendering. Section rendering performance depends only on the GPU capabilities.

GPU-based sectioning is supported only for the OpenGL ES2 renderer. There are no current plans to support older renderers, but in the future the sectioning solution is planned for the Metal renderer too.

OdHardwareSectionsInterface API

Since hardware-accelerated section functionality completely depends on rendering device specifics, the interface for communication with hardware sectioning functionality can be obtained only from the vectorization device directly, using the Gs properties API (login required)

To invoke the OdHardwareSectionsInterface API class, include the following header file:

#include "ExHardwareSections.h"

It is available in the .\main\Kernel\Extensions\ExRender directory.

Now we need a pointer to the active OdGsDevice. You can create a new OdGsDevice and prepare it for rendering or get an existing OdGsDevice. This depends on application specifics.

Note: The OdGsDevice needs to be created from the WinGLES2.txv vectorization module. Other vectorization modules don’t support hardware sectioning, and the device property described later is not available for them.

You can access the hardware section interface as shown in the following code snippet:

OdHardwareSectionsInterface *pHwSections = NULL;
if (pGsDevice && !pGsDevice->properties().isNull() && pGsDevice->properties()->has(OD_T("HardwareSections")))
  pHwSections = static_cast<OdHardwareSectionsInterface*>(pGsDevice->properties()->getAt(OD_T("HardwareSections")).get());

Now, if (pHwSections != NULL), you can invoke hardware section functionality.

The OdHardwareSectionsInterface API class provides the ability to add new section planes; transform, remove, and access existing section planes; and customize the section geometry appearance. All section planes are unique for separate OdGsView’s, so each OdGsView can contain its own set of section planes.

The next example removes existing section planes in the first device view (if they are present) and adds a new section plane:

OdHardwareSectionsInterface *pHwSections = getHwSectionsIface(pGsDevice);

if (pHwSections)
{
  OdGsView *pView = pGsDevice->viewAt(0);
  // Remove existing section planes if present
  if (pHwSections->numSectionPlanes(pView))
    pHwSections->clearSectionPlanes(pView);
  // Add new section plane
  pHwSections->addSectionPlane(pView, OdHardwareSectionsInterface::SectionDef(m_position, m_normal));
  // Enable section plane filling and set up filling color
  pHwSections->setEnableSectionsFill(pView, true);
  pHwSections->setSectionsFillColor(pView, ODRGBA(255, 0, 0, 255));
}

Each section plane is specified by the plane position (as OdGePoint3d) and normal (as OdGeVector3d). This is a classic plane specification. By default, section filling is disabled (done by simple clipping of geometry), so it is enabled using the OdHardwareSectionsInterface::setEnableSectionsFill() method. The last call sets up the opaque red color for section filling. If the plane orientation is specified correctly, we get the following section image:
 

section image

 

Now try to customize the section behavior using the following calls:

pHwSections->setSectionsFillColor(pView, ODRGBA(255, 0, 0, 128));
pHwSections->setEnableSectionsFillPattern(pView, true);
pHwSections->setSectionsFillPattern(pView, OdPs::kFsSlantRight);
pHwSections->setSectionsFillPatternColor(pView, ODRGBA(0, 0, 255, 255));

First we set up the semi-transparent red color for section filling. The next calls are used to enable rendering of the pattern onto section geometry, set up the pattern type, and set up the pattern color as blue. The final image:

 

enable rendering of the pattern onto section geometry

 

And finally add one more section plane to show the behavior of multiple section planes:

pHwSections->addSectionPlane(pView, OdHardwareSectionsInterface::SectionDef(m_position, m_normal));
pHwSections->addSectionPlane(pView, OdHardwareSectionsInterface::SectionDef(m_position, m_normal.rotateBy(OdaPI2, OdGeVector3d::kZAxis)));

The secondary section plane normal is rotated 90° about the z-axis. The final image:

 

secondary section plane normal is rotated 90° about the z-axis

 

Note: If section filling is disabled, we get simple clipping by section plane:


 

If section filling is disabled, we get simple clipping by section plane

 

Conclusion

GPU-based sections have the following features:

  • Hardware section generation is a completely GPU-based solution, so performance depends only on GPU capabilities. This effect invokes multiple rendering passes, so rendering performance with and without sectioning can differ a little.
  • Appearance of sections can be customized.
  • Multiple section planes are completely supported.
  • Works with self-intersected and overlapped geometry:
self-intersected and overlapped geometry
  • The sectioning algorithm works correctly only with valid closed models (without unpaired holes), otherwise section rendering can produce unpredictable artifacts:This picture shows two small red triangles on the bottom of the model – artifacts produced by the incorrectness of a 3D model

    This picture shows two small red triangles on the bottom of the model – artifacts produced by the incorrectness of a 3D model.
  • Hardware sectioning is provided for the most recent graphic devices only: OpenGL ES2 and soon available for Metal.

GPU-sectioning can be processed effectively with good results on common modern hardware.