Skip to content

Commit

Permalink
Added orthographic projection by pressing 5 (#1235)
Browse files Browse the repository at this point in the history
Added orthographic projection by pressing 5
  • Loading branch information
kidharb authored Mar 15, 2024
1 parent e554e26 commit 6c8d6e3
Show file tree
Hide file tree
Showing 24 changed files with 141 additions and 22 deletions.
2 changes: 2 additions & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,8 @@ f3d_test(NAME TestInteractionGroupGeometriesLoadParentDirectory DATA mb/mb_0_0.v
f3d_test(NAME TestInteractionInvertZoom DATA suzanne.ply ARGS --invert-zoom INTERACTION DEFAULT_LIGHTS)
f3d_test(NAME TestInteractionCameraHotkeys DATA cow.vtp INTERACTION DEFAULT_LIGHTS)
f3d_test(NAME TestInteractionZoomToMouse DATA cow.vtp INTERACTION DEFAULT_LIGHTS)
f3d_test(NAME TestInteractionOrthographicProjection DATA cow.vtp INTERACTION DEFAULT_LIGHTS) #5;5
f3d_test(NAME TestInteractionZoomToggleOrthographicProjection DATA cow.vtp INTERACTION DEFAULT_LIGHTS) #MouseWheel;5;Mousewheelx6;5

# Progress test
f3d_test(NAME TestProgress DATA cow.vtp ARGS --progress NO_BASELINE)
Expand Down
1 change: 1 addition & 0 deletions doc/libf3d/OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ scene.animation.speed-factor|double<br>1<br>render|Set the animation speed facto
scene.animation.frame-rate|double<br>60<br>render|Set the animation frame rate used to play the animation interactively.|\-\-animation-frame-rate
scene.camera.index|int<br>-1<br>load|Select the scene camera to use when available in the file.<br>Any negative value means automatic camera.<br>The default scene always uses automatic camera.|\-\-camera-index
scene.up-direction|string<br>+Y<br>load|Define the Up direction|\-\-up
camera.orthographic|bool<br>false<br>load|Toggles between orthographic projection and parallel mode.|\-\-orthographic

## Interactor Options

Expand Down
1 change: 1 addition & 0 deletions doc/user/INTERACTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Note that some hotkeys can be available or not depending on the file being loade
Camera Hotkeys:
* <kbd>1</kbd>: front view camera.
* <kbd>3</kbd>: right view camera.
* <kbd>5</kbd>: toggle orthographic projection.
* <kbd>7</kbd>: top view camera.
* <kbd>9</kbd>: isometric view camera.
* <kbd>Enter</kbd>: reset the camera to its initial parameters.
Expand Down
1 change: 1 addition & 0 deletions library/src/interactor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const std::vector<std::pair<std::string, std::string> >& interactor::getDefaultI
{ "?", "Dump camera state to the terminal" },
{ "1", "Front View camera" },
{ "3", "Left View camera" },
{ "5", "Toggle Orthographic Projection" },
{ "7", "Top View camera" },
{ "9", "Isometric View camera" },
{ "Escape", "Quit" },
Expand Down
4 changes: 4 additions & 0 deletions library/src/interactor_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ class interactor_impl::internals
self->SetViewOrbit(ViewType::VT_RIGHT, self);
render = true;
break;
case '5':
self->Options.toggle("camera.orthographic");
render = true;
break;
case '7':
self->SetViewOrbit(ViewType::VT_TOP, self);
render = true;
Expand Down
3 changes: 3 additions & 0 deletions library/src/options.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ options::options()
this->Internals->init("model.volume.enable", false);
this->Internals->init("model.volume.inverse", false);

// Camera projection
this->Internals->init("camera.orthographic", false);

// Interactor
this->Internals->init("interactor.axis", false);
this->Internals->init("interactor.trackball", false);
Expand Down
6 changes: 6 additions & 0 deletions library/src/window_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,12 @@ void window_impl::UpdateDynamicOptions()
this->Internals->Options.getAsBool("render.grid.absolute"));
this->Internals->Renderer->ShowGrid(this->Internals->Options.getAsBool("render.grid.enable"));

if (this->Internals->Options.getAsInt("scene.camera.index") == -1)
{
this->Internals->Renderer->SetUseOrthographicProjection(
this->Internals->Options.getAsBool("camera.orthographic"));
}

if (this->Internals->WithColoring)
{
this->Internals->Renderer->SetSurfaceColor(
Expand Down
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCameraHotkeys.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetBlackBG.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetRaytracing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetScalars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionCheatsheetWhiteBG.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestInteractionNoFileCheatsheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/baselines/TestInteractionOrthographicProjection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions testing/recordings/TestInteractionOrthographicProjection.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# StreamVersion 1.2
ExposeEvent 0 599 0 0 0 0 0
RenderEvent 0 599 0 0 0 0 0
KeyPressEvent 1129 70 0 53 1 5 0
CharEvent 1129 70 0 53 1 5 0
KeyReleaseEvent 1129 70 0 53 1 5 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# StreamVersion 1.2
ExposeEvent 0 599 0 0 0 0 0
RenderEvent 0 599 0 0 0 0 0
EnterEvent 555 367 0 0 0 0 0
MouseWheelBackwardEvent 555 367 0 0 0 0 0
StartInteractionEvent 555 367 0 0 0 0 0
RenderEvent 555 367 0 0 0 0 0
EndInteractionEvent 555 367 0 0 0 0 0
RenderEvent 555 367 0 0 0 0 0
KeyPressEvent 555 367 0 53 1 5 0
CharEvent 555 367 0 53 1 5 0
KeyReleaseEvent 555 367 0 53 1 5 0
MouseWheelBackwardEvent 555 367 0 0 0 5 0
StartInteractionEvent 555 367 0 0 0 5 0
RenderEvent 555 367 0 0 0 5 0
EndInteractionEvent 555 367 0 0 0 5 0
RenderEvent 555 367 0 0 0 5 0
MouseWheelBackwardEvent 555 367 0 0 1 5 0
StartInteractionEvent 555 367 0 0 1 5 0
RenderEvent 555 367 0 0 1 5 0
EndInteractionEvent 555 367 0 0 1 5 0
RenderEvent 555 367 0 0 1 5 0
MouseWheelBackwardEvent 555 367 0 0 0 5 0
StartInteractionEvent 555 367 0 0 0 5 0
RenderEvent 555 367 0 0 0 5 0
EndInteractionEvent 555 367 0 0 0 5 0
RenderEvent 555 367 0 0 0 5 0
MouseWheelBackwardEvent 555 367 0 0 1 5 0
StartInteractionEvent 555 367 0 0 1 5 0
RenderEvent 555 367 0 0 1 5 0
EndInteractionEvent 555 367 0 0 1 5 0
RenderEvent 555 367 0 0 1 5 0
MouseWheelBackwardEvent 555 367 0 0 0 5 0
StartInteractionEvent 555 367 0 0 0 5 0
RenderEvent 555 367 0 0 0 5 0
EndInteractionEvent 555 367 0 0 0 5 0
RenderEvent 555 367 0 0 0 5 0
MouseWheelBackwardEvent 555 367 0 0 1 5 0
StartInteractionEvent 555 367 0 0 1 5 0
RenderEvent 555 367 0 0 1 5 0
EndInteractionEvent 555 367 0 0 1 5 0
RenderEvent 555 367 0 0 1 5 0
KeyPressEvent 555 367 0 53 1 5 0
CharEvent 555 367 0 53 1 5 0
KeyReleaseEvent 555 367 0 53 1 5 0
LeaveEvent 1902 -203 0 0 0 5 0
38 changes: 38 additions & 0 deletions vtkext/private/Rendering/vtkF3DRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,8 @@ void vtkF3DRenderer::ConfigureCheatSheet()
cheatSheetText << " DOWN : Add files from dir of current file\n";
cheatSheetText << "\n 1: Front View camera\n";
cheatSheetText << " 3: Right View camera\n";
cheatSheetText << " 5: Toggle Orthographic Projection "
<< (this->UseOrthographicProjection ? "[ON]" : "[OFF]") << "\n";
cheatSheetText << " 7: Top View camera\n";
cheatSheetText << " 9: Isometric View camera\n";
cheatSheetText << " ENTER: Reset camera to initial parameters\n";
Expand Down Expand Up @@ -1340,6 +1342,42 @@ void vtkF3DRenderer::ShowEdge(bool show)
}
}

//----------------------------------------------------------------------------
void vtkF3DRenderer::SetUseOrthographicProjection(bool use)
{
// if the internal state is already the same as the target state there's nothing to do
if (this->UseOrthographicProjection == use)
{
return;
}

vtkCamera* camera = GetActiveCamera();
const double angle = vtkMath::RadiansFromDegrees(camera->GetViewAngle());
const double* position = camera->GetPosition();
const double* focal = camera->GetFocalPoint();

if (use)
{
const double distance = std::sqrt(vtkMath::Distance2BetweenPoints(position, focal));
const double parallelScale = distance * tan(angle / 2);
camera->SetParallelScale(parallelScale);
}
else
{
const double distance = camera->GetParallelScale() / tan(angle / 2);
double direction[3];
vtkMath::Subtract(position, focal, direction);
vtkMath::Normalize(direction);
vtkMath::MultiplyScalar(direction, distance);
double newPosition[3];
vtkMath::Add(focal, direction, newPosition);
camera->SetPosition(newPosition);
}
this->UseOrthographicProjection = use;
camera->SetParallelProjection(use);
this->ResetCameraClippingRange();
}

//----------------------------------------------------------------------------
void vtkF3DRenderer::SetUseTrackball(bool use)
{
Expand Down
5 changes: 5 additions & 0 deletions vtkext/private/Rendering/vtkF3DRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class vtkF3DRenderer : public vtkOpenGLRenderer
///@}

///@{
/**
* Set SetUseOrthographicProjection
*/
void SetUseOrthographicProjection(bool use);
/**
* Set/Get UseTrackball
*/
Expand Down Expand Up @@ -277,6 +281,7 @@ class vtkF3DRenderer : public vtkOpenGLRenderer
bool UseSSAOPass = false;
bool UseToneMappingPass = false;
bool UseBlurBackground = false;
bool UseOrthographicProjection = false;
bool UseTrackball = false;
bool InvertZoom = false;

Expand Down

0 comments on commit 6c8d6e3

Please sign in to comment.