Problems with vtkRenderWindowInteractor on macOS using Cocoa

Hi all,

I’m learning VTK reading the book VTKTextBook.
I’ve tried to execute the Cone example at link:
https://lorensen.github.io/VTKExamples/site/Cxx/GeometricObjects/Cone/

When I run it I’ve got a strange behavior that is difficult to explain
with words, but you can see it in the gif at the following link:

The code that I have used is a little different from the code of the
example but both of them give the same problem.

you can see the code of my .cpp file:

#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkConeSource.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>

int main(int, char* []) {
	vtkNew<vtkNamedColors> colors;
	
	vtkNew<vtkConeSource> cone;
	cone->SetHeight(3.0);
	cone->SetRadius(1.0);
	cone->SetResolution(10);
	
	vtkNew<vtkPolyDataMapper> coneMapper;
	coneMapper->SetInputConnection(cone->GetOutputPort());
	
	vtkNew<vtkActor> coneActor;
	coneActor->SetMapper(coneMapper);
	
	vtkNew<vtkRenderer> ren1;
	ren1->AddActor(coneActor);
	ren1->SetBackground(
	colors->GetColor3d("MidnightBlue").GetData());

	vtkNew<vtkRenderWindow> renWin;
	renWin->AddRenderer(ren1);
	renWin->SetSize(300, 300);

	vtkNew<vtkRenderWindowInteractor> interactor;
	interactor->SetRenderWindow(renWin);

	interactor->Start();
	for (auto i = 0; i < 360; ++i) {
		// render the image
		renWin->Render();
		// rotate the active camera by one degree
		ren1->GetActiveCamera()->Azimuth(1);
	}
	return EXIT_SUCCESS;
}

and my CMakeLists.txt:

cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

project(Cone)

set(VTK_USE_CARBON ON)

find_package(VTK COMPONENTS 
  vtkCommonCore
  vtkCommonDataModel
  vtkFiltersSources
  vtkInteractionStyle
  vtkRenderingCore
  vtkRenderingFreeType
  vtkRenderingOpenGL2 QUIET)
if (NOT VTK_FOUND)
  message("Skipping Cone: ${VTK_NOT_FOUND_MESSAGE}")
  return ()
endif()
message (STATUS "VTK_VERSION: ${VTK_VERSION}")
if (VTK_VERSION VERSION_LESS "8.90.0")
  # old system
  include(${VTK_USE_FILE})
  add_executable(Cone Cone.cpp)
  target_link_libraries(Cone PRIVATE ${VTK_LIBRARIES})
else ()
  # include all components
  add_executable(Cone Cone.cxx )
  target_link_libraries(Cone PRIVATE ${VTK_LIBRARIES})
  # vtk_module_autoinit is needed
  vtk_module_autoinit(
    TARGETS Cone
    MODULES ${VTK_LIBRARIES}
  )
endif ()

I have already asked the same question on the mailing list vtk-users, but I didn’t received an answer.
Where is the problem?

The code does exactly what it supposed to do. First rotate the cone using the interactor (interactor->Start()). Clicking X quits the interactor, so the short animation that you added (with the for loop) can run. When that’s done, the application exits.

It sounds like the joystick interaction mode is confusing to you (and I understand why). You can enter ‘trackball’ mode, which you might find more intuitive, by typing the ‘t’ key when the VTK window is in focus.