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 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
Comment thread lib/vsdata.hpp
Comment on lines +268 to +270
// Set the cutting-plane orientation (radians), translation, kind, and
// algorithm in one shot. No-op by default; only meaningful for 3D scenes.
// kind == -1 / algo == -1 mean "leave unchanged".

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.

Please use doxygen style. We do not publish it anymore on the webpage, but you can still build it locally.

Comment thread lib/vsdata.hpp
Comment on lines +271 to +272
virtual void SetCuttingPlane(double phi, double theta, double translation,
int kind, int algo) { }

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.

Suggested change
virtual void SetCuttingPlane(double phi, double theta, double translation,
int kind, int algo) { }
virtual void SetCuttingPlane(double phi, double theta, double translation,
int kind = -1, int algo = -1) { }

Comment thread lib/vssolution3d.hpp
Comment on lines +221 to +222
void SetCuttingPlane(double phi, double theta, double translation,
int kind, int algo) override;

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.

Suggested change
void SetCuttingPlane(double phi, double theta, double translation,
int kind, int algo) override;
void SetCuttingPlane(double phi, double theta, double translation,
int kind = -1, int algo = -1) override;

Comment thread lib/script_controller.cpp
<< " (expected -1..2)" << endl;
kind = 1;
}
if (algo != -1 && (algo < 0 || algo > 1))

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.

Suggested change
if (algo != -1 && (algo < 0 || algo > 1))
if (algo < -1 || algo > 1)

Comment thread lib/script_controller.cpp
if (algo != -1 && (algo < 0 || algo > 1))
{
cerr << "Script: cutting_plane: invalid alg " << algo
<< " (expected 0 or 1)" << endl;

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.

Fix this message please to include -1.

Comment thread lib/script_controller.cpp
(*this)[Command::PlotCaption] = {"plot_caption", "'<caption>'", "Set the plot caption."};
(*this)[Command::PointLine] = {"pointline", "<num_points> <x y z>...", "Set point line overlay coordinates."};
(*this)[Command::Headless] = {"headless", "", "Change the session to headless."};
(*this)[Command::CuttingPlane] = {"cutting_plane", "<phi> <theta> <translation> <kind:optional, default 1> <alg:optional>", "Set the cutting plane orientation (degrees), translation, kind, and algorithm."};

@najlkin najlkin Jul 20, 2026

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.

Suggested change
(*this)[Command::CuttingPlane] = {"cutting_plane", "<phi> <theta> <translation> <kind:optional, default 1> <alg:optional>", "Set the cutting plane orientation (degrees), translation, kind, and algorithm."};
(*this)[Command::CuttingPlane] = {"cutting_plane", "<phi> <theta> <translation> [<kind> [<alg>]]", "Set the cutting plane orientation (degrees), translation, kind (default: 1), and algorithm."};

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