// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkSmartPointer.h"

#include "vtkActor.h"
#include "vtkAppendPolyData.h"
#include "vtkBillboardTextActor3D.h"
#include "vtkBoundedPlanePointPlacer.h"
#include "vtkCommand.h"
#include "vtkConeSource.h"
#include "vtkCoordinate.h"
#include "vtkCubeSource.h"
#include "vtkCutter.h"
#include "vtkGlyph3D.h"
#include "vtkHandleWidget.h"
#include "vtkInteractorEventRecorder.h"
#include "vtkLODActor.h"
#include "vtkMeasurementCubeHandleRepresentation3D.h"
#include "vtkNew.h"
#include "vtkOutlineFilter.h"
#include "vtkPlane.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
#include "vtkTestUtilities.h"
#include "vtkTextProperty.h"

int TestMeasurementCubeHandleRepresentation3D(int vtkNotUsed(argc), char* vtkNotUsed(argv)[])
{
  double bounds[6] = { -1., 1., -1., 1., -1., 1. };

  // Create the RenderWindow and Renderer
  //
  vtkSmartPointer<vtkRenderer> ren1 = vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
  renWin->SetMultiSamples(0);
  renWin->AddRenderer(ren1);

  vtkSmartPointer<vtkRenderWindowInteractor> iren =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  iren->SetRenderWindow(renWin);

  // VTK widgets consist of two parts: the widget part that handles event
  // processing, and the widget representation that defines how the widget
  // appears in the scene (i.e., matters pertaining to geometry).
  vtkSmartPointer<vtkHandleWidget> handleWidget = vtkSmartPointer<vtkHandleWidget>::New();
  handleWidget->SetInteractor(iren);

  // Use a vtkMeasurementCubeHandleRepresentation3D to represent the handle widget
  vtkSmartPointer<vtkMeasurementCubeHandleRepresentation3D> unitCubeRep =
    vtkSmartPointer<vtkMeasurementCubeHandleRepresentation3D>::New();
  unitCubeRep->PlaceWidget(bounds);
  unitCubeRep->SetHandleSize(30);
  handleWidget->SetRepresentation(unitCubeRep);
  double p[3] = { 1., 0., 0. };
  unitCubeRep->SetWorldPosition(p);

  {
    // Create a sphere
    vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
    sphereSource->Update();

    // Create a mapper and actor
    vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputConnection(sphereSource->GetOutputPort());
    vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);

    // Set the color of the sphere
    actor->GetProperty()->SetColor(1.0, 0.0, 0.0); //(R,G,B)

    // Add the actor to the scene
    ren1->AddActor(actor);
  }

  // Set some defaults.
  //
  iren->Initialize();
  renWin->Render();
  handleWidget->EnabledOn();

  ren1->SetBackground(0.1, 0.2, 0.4);
  renWin->SetSize(400, 400);
  ren1->ResetCamera();
  ren1->ResetCameraClippingRange();
  renWin->Render();

  iren->Start();

  return EXIT_SUCCESS;
}
