public void boxInteractionCallback(vtkObject sender, vtkObjectEventArgs e)
        {
            vtkBoxWidget2 wid = vtkBoxWidget2.SafeDownCast(sender);

            if (wid != null)
            {
                vtkTransform         vtk_transform = vtkTransform.New();
                vtkBoxRepresentation rep           = (vtkBoxRepresentation)wid.GetRepresentation();
                rep.GetTransform(vtk_transform);
                sphereActorList[RegionsListBox.SelectedIndex].SetUserTransform(vtk_transform);
                int reg_idx = RegionsListBox.SelectedIndex;
                this.TransferVTKBoxWidgetTransformToMatrix(this.configurator.SimConfig.scenario.regions[reg_idx].region_box_spec);
            }
        }
        private void SetUpRenderWindow()
        {
            // create a VTK output control and make the forms host point to it
            rwc = new RenderWindowControl();
            rwc.CreateGraphics();
            windowsFormsHost.Child = rwc;

            // set up basic viewing
            vtkRenderer ren = rwc.RenderWindow.GetRenderers().GetFirstRenderer();

            // background color
            ren.SetBackground(0.0, 0.0, 0.0);

            // interactor style
            vtkInteractorStyleSwitch istyle = vtkInteractorStyleSwitch.New();

            rwc.RenderWindow.GetInteractor().SetInteractorStyle(istyle);
            rwc.RenderWindow.GetInteractor().SetPicker(vtkCellPicker.New());
            (istyle).SetCurrentStyleToTrackballCamera();

            // Demonstrate how to use the vtkBoxWidget 3D widget,
            vtkSphereSource sphere = vtkSphereSource.New();

            sphere.SetRadius(0.25);

            vtkPolyDataMapper sphereMapper = vtkPolyDataMapper.New();

            sphereMapper.SetInputConnection(sphere.GetOutputPort());

            vtkActor      sphereActor;
            vtkTransform  widgetTransform = vtkTransform.New();
            List <Region> region_list     = configurator.SimConfig.scenario.regions.ToList();

            for (int ii = 0; ii < region_list.Count; ++ii)
            {
                this.TransferMatrixToVTKTransform(region_list[ii].region_box_spec.transform_matrix, widgetTransform);
                sphereActor = vtkActor.New();
                sphereActor.SetMapper(sphereMapper);
                sphereActor.SetUserTransform(widgetTransform);
                sphereActor.GetProperty().SetOpacity(0.5);
                sphereActor.SetVisibility(region_list[ii].region_visibility ? 1 : 0);
                sphereActorList.Add(sphereActor);
                ren.AddActor(sphereActorList[ii]);
            }

            vtkCubeSource cube = vtkCubeSource.New();

            cube.SetXLength(5.0);
            cube.SetYLength(5.0);
            cube.SetZLength(5.0);

            vtkOutlineSource outline = vtkOutlineSource.New();

            outline.SetBounds(-2, 2, -2, 2, -2, 2);

            vtkPolyDataMapper cubeMapper = vtkPolyDataMapper.New();

            cubeMapper.SetInputConnection(outline.GetOutputPort());

            vtkLODActor cubeActor = vtkLODActor.New();

            cubeActor.SetMapper(cubeMapper);
            cubeActor.VisibilityOn();

            ren.AddActor(cubeActor);

            boxRep = vtkBoxRepresentation.New();
            boxRep.SetTransform(widgetTransform);

            boxWidget = vtkBoxWidget2.New();
            boxWidget.SetInteractor(rwc.RenderWindow.GetInteractor());
            boxWidget.SetRepresentation(boxRep);
            boxWidget.SetPriority(1);
            boxWidget.InteractionEvt += this.boxInteractionCallback;

            ren.ResetCamera();
        }
        private void SetUpRenderWindow()
        {
            // create a VTK output control and make the forms host point to it
            rwc = new RenderWindowControl();
            rwc.CreateGraphics();
            windowsFormsHost.Child = rwc;

            // set up basic viewing
            vtkRenderer ren = rwc.RenderWindow.GetRenderers().GetFirstRenderer();

            // background color
            ren.SetBackground(0.0, 0.0, 0.0);

            // interactor style
            vtkInteractorStyleSwitch istyle = vtkInteractorStyleSwitch.New();
            rwc.RenderWindow.GetInteractor().SetInteractorStyle(istyle);
            rwc.RenderWindow.GetInteractor().SetPicker(vtkCellPicker.New());
            (istyle).SetCurrentStyleToTrackballCamera();

            // Demonstrate how to use the vtkBoxWidget 3D widget,
            vtkSphereSource sphere = vtkSphereSource.New();
            sphere.SetRadius(0.25);

            vtkPolyDataMapper sphereMapper = vtkPolyDataMapper.New();
            sphereMapper.SetInputConnection(sphere.GetOutputPort());

            vtkActor sphereActor;
            vtkTransform widgetTransform = vtkTransform.New();
            List<Region> region_list = configurator.SimConfig.scenario.regions.ToList();
            for (int ii = 0; ii < region_list.Count; ++ii)
            {
                this.TransferMatrixToVTKTransform(region_list[ii].region_box_spec.transform_matrix, widgetTransform);
                sphereActor = vtkActor.New();
                sphereActor.SetMapper(sphereMapper);
                sphereActor.SetUserTransform(widgetTransform);
                sphereActor.GetProperty().SetOpacity(0.5);
                sphereActor.SetVisibility(region_list[ii].region_visibility ? 1 : 0);
                sphereActorList.Add(sphereActor);
                ren.AddActor(sphereActorList[ii]);
            }

            vtkCubeSource cube = vtkCubeSource.New();
            cube.SetXLength(5.0);
            cube.SetYLength(5.0);
            cube.SetZLength(5.0);

            vtkOutlineSource outline = vtkOutlineSource.New();
            outline.SetBounds(-2, 2, -2, 2, -2, 2);

            vtkPolyDataMapper cubeMapper = vtkPolyDataMapper.New();
            cubeMapper.SetInputConnection(outline.GetOutputPort());

            vtkLODActor cubeActor = vtkLODActor.New();
            cubeActor.SetMapper(cubeMapper);
            cubeActor.VisibilityOn();

            ren.AddActor(cubeActor);

            boxRep = vtkBoxRepresentation.New();
            boxRep.SetTransform(widgetTransform);

            boxWidget = vtkBoxWidget2.New();
            boxWidget.SetInteractor( rwc.RenderWindow.GetInteractor() );
            boxWidget.SetRepresentation( boxRep );
            boxWidget.SetPriority(1);
            boxWidget.InteractionEvt += this.boxInteractionCallback;

            ren.ResetCamera();
        }