Visualization using AIS


I am trying OCCT's visualization capabilities for the first time for a C++ based application on Mac OS Big Sur. I followed the user guide at

However, I was unable to get any visualization or display pop up after I run my code. Here is a snippet:

#include "iostream"
#include "STEPControl_Controller.hxx"
#include "V3d_Viewer.hxx"
#include "OpenGl_GraphicDriver.hxx"
#include "Block.h"
#include "Path.h"
#include "OCCUtils.h"
#include "FilesystemUtils.h"
#include "AIS_InteractiveContext.hxx"
#include "AIS_Shape.hxx"

void createBlockInDirectory(std::string directory){

Block block(length, width, height);
writeSTEP(block.getShape(), directory);

//display code begins
 Handle(Aspect_DisplayConnection) aDispConnection = new Aspect_DisplayConnection();
 Handle(OpenGl_GraphicDriver) aGraphicDriver = new OpenGl_GraphicDriver (aDispConnection);
 Handle(V3d_Viewer) aViewer = new V3d_Viewer (aGraphicDriver);
 aViewer->SetDefaultBackgroundColor (Quantity_NOC_DARKVIOLET);
 Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (aViewer);
 Handle(AIS_Shape) aShapePrs = new AIS_Shape (block.getShape()); // creation of the presentable object
 aContext->Display (aShapePrs, AIS_Shaded, 0, true);


int main() {
std::string directory = "whatever is the path";

The block gets created and the code runs without errors, but I don't see any visualization. In the project's CMAKE, I have only included OpenCASCADE libraries and include directories, nothing from OpenGL or VTK separately.

Any piece of advice will be helpful. Any links to full code examples implementing AIS based visualization will be useful as well!

Kirill Gavrilov's picture

Your code creates only a V3d_Viewer with not a single window (V3d_View).

Window creation (Aspect_Window or Cocoa_Window in case of macOS) is very platform-specific and involving code. Normally, you don't need just a plain 3D viewer window, but have to handle user input events (mouse clicks, window resizes, etc.). As OCCT doesn't provide any library for GUI development, this functionality is normally developed using some other framework - Qt, glfw, SDL or something other.

You may find samples creating OCCT 3D Viewer using Qt and glfw within OCCT. glfw might be a good choice in case if 3D viewer with simple interactions is everything you need. Unfortunately, there is no dedicated sample using Cocoa framework directly - you may find a sample Cocoa project attached to the following bug, which would require some minor porting efforts to be built with up-to-date OCCT. This sample is very close to ios/UIKitSample, which can be found in OCCT for iOS platform as UIKit and Cocoa are very close APIs.