Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions lib/script_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <array>
#include <algorithm>
#include <thread>
#include <cmath>
#include <cctype>

using namespace std;
using namespace mfem;
Expand Down Expand Up @@ -63,6 +65,7 @@ enum class Command
PlotCaption,
PointLine,
Headless,
CuttingPlane,
//----------
Max
};
Expand Down Expand Up @@ -128,6 +131,7 @@ ScriptCommands::ScriptCommands()
(*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."};
Comment thread
arotem3 marked this conversation as resolved.
Outdated
}

int ScriptController::ScriptReadSolution(istream &scr, DataState &state)
Expand Down Expand Up @@ -859,6 +863,34 @@ bool ScriptController::ExecuteScriptCommand()
case Command::Headless:
cout << "The session cannot become headless after initialization" << endl;
break;
case Command::CuttingPlane:
{
double phi_deg, theta_deg, translation;
scr >> phi_deg >> theta_deg >> translation;

int kind = 1, algo = -1;
scr >> ws;
if (isdigit((unsigned char)scr.peek()) || scr.peek() == '-')
{
scr >> kind;
scr >> ws;
if (isdigit((unsigned char)scr.peek()) || scr.peek() == '-')
{
scr >> algo;
}
}

cout << "Script: cutting_plane: " << phi_deg << ' ' << theta_deg
<< ' ' << translation << ' ' << kind;
if (algo != -1) { cout << ' ' << algo; }
cout << endl;
Comment thread
arotem3 marked this conversation as resolved.

win.vs->SetCuttingPlane(phi_deg * M_PI / 180.0,
theta_deg * M_PI / 180.0,
translation, kind, algo);
MyExpose();
}
break;
case Command::Max: //dummy
break;
}
Expand Down
17 changes: 17 additions & 0 deletions lib/vsdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,7 @@ Plane::Plane(const double (&eqn_)[4], const VisualizationScene::Box &bb)
x0 = (x[0]+x[1])/2.0;
y0 = (y[0]+y[1])/2.0;
z0 = (z[0]+z[1])/2.0;
cx = x0; cy = y0; cz = z0;

phi_step = M_PI / 36;
theta_step = M_PI / 36;
Expand Down Expand Up @@ -2050,3 +2051,19 @@ void Plane::DecreaseDistance()
eqn[3] -= rho_step;
CartesianToSpherical();
}

void Plane::SetPlane(double phi_, double theta_, double translation)
{
phi = phi_;
theta = theta_;
rho = 1.0;

double nx = cos(phi) * cos(theta);
double ny = cos(phi) * sin(theta);
double nz = sin(phi);
x0 = cx + translation * nx;
y0 = cy + translation * ny;
z0 = cz + translation * nz;

SphericalToCartesian();
}
8 changes: 8 additions & 0 deletions lib/vsdata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Plane
double eqn[4];
double phi, theta, rho;
double x0,y0,z0;
double cx, cy, cz; // fixed mesh bounding-box center
void CartesianToSpherical();
void SphericalToCartesian();

Expand All @@ -44,6 +45,7 @@ class Plane
void DecreaseTheta();
void IncreaseDistance();
void DecreaseDistance();
void SetPlane(double phi_, double theta_, double translation);
};


Expand Down Expand Up @@ -263,6 +265,12 @@ class VisualizationSceneScalarData : public VisualizationScene
virtual void AutoRefine() = 0;
virtual void ToggleAttributes(mfem::Array<int> &attr_list) = 0;

// 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".
Comment thread
arotem3 marked this conversation as resolved.
Outdated
virtual void SetCuttingPlane(double phi, double theta, double translation,
int kind, int algo) { }
Comment thread
arotem3 marked this conversation as resolved.
Outdated

virtual void PrintState();

mfem::Mesh *GetMesh() { return mesh; }
Expand Down
30 changes: 30 additions & 0 deletions lib/vssolution3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,36 @@ void VisualizationSceneSolution3d::ToggleCPAlgorithm()
}
}

void VisualizationSceneSolution3d::SetCuttingPlane(double phi, double theta,
double translation,
int kind, int algo)
{
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();
}
Comment thread
najlkin marked this conversation as resolved.
}

void VisualizationSceneSolution3d::MoveLevelSurf(int move)
{
drawlsurf += move;
Expand Down
2 changes: 2 additions & 0 deletions lib/vssolution3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ class VisualizationSceneSolution3d : public VisualizationSceneScalarData
void ToggleCPDrawElems();
void ToggleCPDrawMesh();
void ToggleCPAlgorithm();
void SetCuttingPlane(double phi, double theta, double translation,
int kind, int algo) override;
Comment thread
arotem3 marked this conversation as resolved.
void MoveLevelSurf(int);
void NumberOfLevelSurf(int);
void EventUpdateColors() override;
Expand Down
Loading