Part 1 of 2: Using the Geometry Sectioning Callback

Andrew Markovich

October 17, 2019

Previously on the blog we demonstrated the ability to customize output behavior of section geometry and cut geometry. OdGiSectionGeometryOutput and OdGiCuttedGeometryOutput interfaces contain basic functionality to control the behavior of section and cut geometry output. These abilities are limited to changing geometry properties such as color, transparency, materials and so on. If this base functionality isn’t enough, client applications can override any geometry output methods in these classes and implement their own geometry output logic.

Geometry sectioning can be set together with clipping during entity vectorization using the OdGiGeometry::pushModelTransform method. But typically geometry sectioning is set according to the entire viewport using the OdGsView::setViewport3dClipping method, so this clipping is applied to all objects inside a graphics scene. This is an easy solution, but what if the graphics scene contains objects that should have behavior other than output section or cut geometry? Setting separate clipping boundaries with various output geometry behavior according to each object in a scene isn’t a very fast solution. To simplify processing of objects with different section or cut geometry behavior, there is a special callback method that can be called for each sectionable object in a graphics scene.

OdGiClippedGeometryOutput interface
virtual void OdGiClippedGeometryOutput::setupDrawableProcessing();

This method can be overridden for OdGiSectionGeometryOutput and OdGiCuttedGeometryOutput classes to set up the correct geometry output settings for each object. This is an easy way if you already use your own inherited classes for some reason. But the OdGiClippedGeometryOutput interface provides an even more simple way to process the callback without having to override the setupDrawableProcessing() method.

The OdGiClippedGeometryOutputCallback interface class contains a single method which must be overridden by an inherited class:

virtual bool clippedGeometryOutputCallbackProc(OdGiClippedGeometryOutput &pGeomOutput, const OdGiConveyorContext &pDrawContext) = 0;

Inside this method, client code can invoke data from pDrawContext to check the current drawable object and apply the necessary settings into pGeomOutput. Return true to process section or cut geometry output or false to disable output geometry processing.

The following methods of the OdGiConveyorContext class are helpful in analyzing drawables:

  • const OdGiDrawable* currentDrawable() const — Gets the drawable that is currently vectorizing.
  • const OdGiPathNode* currentGiPath() const — Gets the entire drawables path up to the current drawable (helpful if geometry behavior doesn’t only depend on the current drawable but also on their parent drawables).
  • const OdGiViewport* giViewport() const — Returns the current viewport settings which may be helpful if geometry output behavior depends on the viewing direction, etc.

Finally, a constructed class with a callback implementation can be set to your OdGiSectionGeometryOutput or OdGiCuttedGeometryOutput classes using the setGeometryProcessingCallback(OdGiClippedGeometryOutputCallback *pCallback) method. The default implementation of the OdGiClippedGeometryOutput::setupDrawableProcessing() method calls the setGeometryProcessingCallback() method for you after that.

Watch the blog for the next article in this series, which will be a detailed example of using the geometry sectioning callback.