Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
Version 4.1.1 (development)
===========================

- Added the option to cut a portion of the interiors of 3D faces to expose more
of the mesh. Useful as an alternative to transparency. See keys Ctrl+F3/F4.

- Added 3D scene export to glTF format (https://www.khronos.org/gltf) which is
bound to the key 'G'. This can be used to import GLVis scenes for rendering in
Blender, as well as for augmented reality, see https://modelviewer.dev/editor.
Expand Down
113 changes: 113 additions & 0 deletions lib/openglvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ VisualizationScene::VisualizationScene()
ViewCenterX = 0.0;
ViewCenterY = 0.0;

cut_lambda = 0.0;
cut_updated = false;

background = BG_WHITE;
GetAppWindow()->getRenderer().setClearColor(1.f, 1.f, 1.f, 1.f);
_use_cust_l0_pos = false;
Expand All @@ -137,6 +140,116 @@ VisualizationScene::VisualizationScene()

VisualizationScene::~VisualizationScene() {}


void VisualizationScene
:: DrawCutTriangle(gl3::GlDrawable& buff,
const double (&p)[4][3], const double (&cv)[4],
const double minv, const double maxv)
{
// element center
double c[3];
c[0] = c[1] = c[2] = 0.0;
for (int j = 0; j < 3; j++)
{
c[0] += p[j][0]; c[1] += p[j][1]; c[2] += p[j][2];
}
c[0] /= 3.0; c[1] /= 3.0; c[2] /= 3.0;

double l = cut_lambda;
double q[3][3];

// corners of the cut frame
for (int j = 0; j < 3; j++)
{
q[j][0] = l*p[j][0] + (1.0-l)*c[0];
q[j][1] = l*p[j][1] + (1.0-l)*c[1];
q[j][2] = l*p[j][2] + (1.0-l)*c[2];
}

double d[4][3];
double cvv[4];

// bottom trapezoid
for (int k = 0; k < 3; k++)
{
d[0][k] = p[0][k]; d[1][k] = p[1][k]; d[2][k] = q[1][k]; d[3][k] = q[0][k];
}
DrawQuad(buff, d, cvv, minv, maxv);

// diagonal trapezoid
for (int k = 0; k < 3; k++)
{
d[0][k] = p[1][k]; d[1][k] = p[2][k]; d[2][k] = q[2][k]; d[3][k] = q[1][k];
}
DrawQuad(buff, d, cvv, minv, maxv);

// left trapezoid
for (int k = 0; k < 3; k++)
{
d[0][k] = p[2][k]; d[1][k] = p[0][k]; d[2][k] = q[0][k]; d[3][k] = q[2][k];
}
DrawQuad(buff, d, cvv, minv, maxv);
}


void VisualizationScene
:: DrawCutQuad(gl3::GlDrawable& buff,
const double (&p)[4][3], const double (&cv)[4],
const double minv, const double maxv)
{
// element center
double c[3];
c[0] = c[1] = c[2] = 0.0;
for (int j = 0; j < 4; j++)
{
c[0] += p[j][0]; c[1] += p[j][1]; c[2] += p[j][2];
}
c[0] /= 4.0; c[1] /= 4.0; c[2] /= 4.0;

double l = cut_lambda;
double q[4][3];

// corners of the cut frame
for (int j = 0; j < 4; j++)
{
q[j][0] = l*p[j][0] + (1.0-l)*c[0];
q[j][1] = l*p[j][1] + (1.0-l)*c[1];
q[j][2] = l*p[j][2] + (1.0-l)*c[2];
}

double d[4][3];
double cvv[4];

// bottom trapezoid
for (int k = 0; k < 3; k++)
{
d[0][k] = p[0][k]; d[1][k] = p[1][k]; d[2][k] = q[1][k]; d[3][k] = q[0][k];
}
DrawQuad(buff, d, cvv, minv, maxv);

// right trapezoid
for (int k = 0; k < 3; k++)
{
d[0][k] = p[1][k]; d[1][k] = p[2][k]; d[2][k] = q[2][k]; d[3][k] = q[1][k];
}
DrawQuad(buff, d, cvv, minv, maxv);

// top trapezoid
for (int k = 0; k < 3; k++)
{
d[0][k] = p[2][k]; d[1][k] = p[3][k]; d[2][k] = q[3][k]; d[3][k] = q[2][k];
}
DrawQuad(buff, d, cvv, minv, maxv);

// left trapezoid
for (int k = 0; k < 3; k++)
{
d[0][k] = p[3][k]; d[1][k] = p[0][k]; d[2][k] = q[0][k]; d[3][k] = q[3][k];
}
DrawQuad(buff, d, cvv, minv, maxv);
}


void VisualizationScene
::DrawTriangle(gl3::GlDrawable& buff,
const double (&pts)[4][3], const double (&cv)[4],
Expand Down
20 changes: 19 additions & 1 deletion lib/openglvis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class VisualizationScene
int light_mat_idx;
bool use_light;


gl3::RenderParams GetMeshDrawParams();
glm::mat4 GetModelViewMtx();

Expand Down Expand Up @@ -126,6 +125,20 @@ class VisualizationScene
const double (&pts)[4][3], const double (&cv)[4],
const double minv, const double maxv);

/// Draw a 3D triangle in physical space with a central triangle removed. The
/// cut is controlled by value of cut_lambda. See keys Ctrl+F3/F4. Similar to
/// CutReferenceTriangle in lib/vssolution3d.cpp.
void DrawCutTriangle(gl3::GlDrawable& buff,
const double (&pts)[4][3], const double (&cv)[4],
const double minv, const double maxv);

/// Draw a 3D quad in physical space with a central square removed. The cut
/// is controlled by the value of cut_lambda. See keys Ctrl+F3/F4. Similar to
/// CutReferenceSquare in lib/vssolution3d.cpp.
void DrawCutQuad(gl3::GlDrawable& buff,
const double (&pts)[4][3], const double (&cv)[4],
const double minv, const double maxv);

void DrawPatch(gl3::GlDrawable& buff, const mfem::DenseMatrix &pts,
mfem::Vector &vals, mfem::DenseMatrix &normals,
const int n, const mfem::Array<int> &ind, const double minv,
Expand Down Expand Up @@ -167,6 +180,11 @@ class VisualizationScene
/// Bounding box.
double x[2], y[2], z[2];

/// Amount of face cutting with keys Ctrl-F3/F4 (0: no cut, 1: cut to edges)
double cut_lambda;
/// Have the reference geometries been updated for the cut?
bool cut_updated;

glm::mat4 rotmat;
glm::mat4 translmat;

Expand Down
Loading