Skip to content

Add direct cutting-plane control to GLVis scripts#374

Open
arotem3 wants to merge 5 commits into
GLVis:masterfrom
arotem3:cutting-plane-script
Open

Add direct cutting-plane control to GLVis scripts#374
arotem3 wants to merge 5 commits into
GLVis:masterfrom
arotem3:cutting-plane-script

Conversation

@arotem3

@arotem3 arotem3 commented Jul 16, 2026

Copy link
Copy Markdown

Motivation

Today, the only way to position the 3D cutting plane from a GLVis script is to replay raw keystrokes via keys. Even a modest plane orientation requires several keystrokes:

keys xxxxxyyyyyyyyi

(5 x presses to rotate phi by 25°, 8 y presses to rotate theta by 40°, then i to enable the plane). Each individual keystroke triggers a full cutting-plane geometry recomputation, not just the final one. On a large mesh that's a lot of wasted computation just to reach a state that could be stated directly in one line.

What this adds

A single script command:

cutting_plane <phi> <theta> <translation> <kind:optional> <alg:optional>

which sets the plane's orientation (degrees), translation, kind (cut-through-elements / solid-cut-behind / off), and algorithm (accurate / fast) directly, in one shot reproducing exactly what the equivalent keystroke sequence would have produced, without the redundant intermediate recomputations. kind defaults to 1 (cut through elements) so the plane is visible immediately; alg is optional and leaves the current value unchanged when omitted.

Implementation

  • Plane::SetPlane : new direct setter on the existing Plane class (previously only relative Increase/Decrease mutators existed).
  • VisualizationSceneScalarData::SetCuttingPlane : empty-default virtual hook (2D scenes no-op safely).
    VisualizationSceneSolution3d::SetCuttingPlane — override combining plane move + kind + algorithm changes, mirroring the existing key-handler logic.
  • cutting_plane registered in the script command table.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new cutting_plane GLVis script command to set cutting-plane orientation, translation, kind, and algorithm directly in one call, avoiding the expensive step-by-step recomputation caused by replaying multiple keystrokes.

Changes:

  • Introduces Plane::SetPlane() to set cutting-plane orientation/position directly.
  • Adds a virtual VisualizationSceneScalarData::SetCuttingPlane() hook and implements it for VisualizationSceneSolution3d.
  • Registers and parses a new cutting_plane command in the script controller (degrees in scripts, converted to radians internally).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/vssolution3d.hpp Declares VisualizationSceneSolution3d::SetCuttingPlane(...) override.
lib/vssolution3d.cpp Implements SetCuttingPlane(...) to update plane, kind, algorithm, and trigger recomputation.
lib/vsdata.hpp Adds Plane::SetPlane(...) and a default no-op SetCuttingPlane(...) hook in the base scene class.
lib/vsdata.cpp Implements Plane::SetPlane(...) using stored bounding-box center + translation along the plane normal.
lib/script_controller.cpp Adds the cutting_plane script command, parses optional args, and calls vs->SetCuttingPlane(...).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/vssolution3d.cpp
Comment on lines +1199 to +1222
CuttingPlane->SetPlane(phi, theta, translation);
FindNodePos();

if (kind != -1 && kind != cplane)
{
if (cplane == 2 && cp_drawmesh == 3)
{
cp_drawmesh = 2;
}
cplane = kind;
}

if (algo != -1)
{
cp_algo = algo;
}

CPPrepare();
if (cplane == 0 || cplane == 2)
{
Prepare();
PrepareLines();
PrepareOrderingCurve();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it is right, but the suggestion is unnecessarily convoluted:

  • cplane_old makes sense to save
  • cplane_changed does not make sense, it is trivial to compare cplane and cplane_old
  • the test condition is correct if (cplane_old == 2 || cplane == 2)
  • the inner test for the ordering curve makes sense to do, but it should be only if (cplane != cplane_old)
  • the second branch does not make sense, because it does not realize that it was just the leaving case in the toggling procedure as (2+1) % 3 == 0 🙃 .

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix attempted at cc8b16a

Comment thread lib/script_controller.cpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@najlkin

najlkin commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Btw, do not mind the failing CI on mac, it is happening on master as well (https://github.com/GLVis/glvis/actions/runs/29534330078/job/87741910839) 🫣 .

@arotem3

arotem3 commented Jul 16, 2026

Copy link
Copy Markdown
Author

@najlkin or @camierjs , I am not familiar enough with the GLVis flow control to resolve this copilot comment. Could you please help with this?

Comment thread lib/script_controller.cpp Outdated
int kind = 1, algo = -1;
scr >> ws;
int ch = scr.peek();
if (ch != std::char_traits<char>::eof() && (isdigit(ch) || ch == '-'))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the EOF check, it does not make sense - EOF is not a digit nor minus sign 🤪 .

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. See 4a22f38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants