Skip to content

Commit df6e137

Browse files
committed
add option to set ground plane location in world coords
1 parent b48cc3a commit df6e137

File tree

5 files changed

+67
-2
lines changed

5 files changed

+67
-2
lines changed

include/polyscope/options.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ extern bool hideWindowAfterShow;
6464

6565
// Behavior of the ground plane
6666
extern GroundPlaneMode groundPlaneMode;
67+
extern GroundPlaneHeightMode groundPlaneHeightMode;
6768
extern bool groundPlaneEnabled; // deprecated, but kept and respected for compatability. use groundPlaneMode.
6869
extern ScaledValue<float> groundPlaneHeightFactor;
70+
extern float groundPlaneHeight;
6971
extern int shadowBlurIters;
7072
extern float shadowDarkness;
7173

include/polyscope/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ enum class BackgroundView { None = 0 };
1313
enum class ProjectionMode { Perspective = 0, Orthographic };
1414
enum class TransparencyMode { None = 0, Simple, Pretty };
1515
enum class GroundPlaneMode { None, Tile, TileReflection, ShadowOnly };
16+
enum class GroundPlaneHeightMode { Relative = 0, Absolute };
1617
enum class BackFacePolicy { Identical, Different, Custom, Cull };
1718

1819
enum class PointRenderMode { Sphere = 0, Quad };

src/options.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ std::string screenshotExtension = ".png";
3131
// Ground plane / shadows
3232
bool groundPlaneEnabled = true;
3333
GroundPlaneMode groundPlaneMode = GroundPlaneMode::TileReflection;
34+
GroundPlaneHeightMode groundPlaneHeightMode = GroundPlaneHeightMode::Relative;
3435
ScaledValue<float> groundPlaneHeightFactor = 0;
36+
float groundPlaneHeight = 0.;
3537
int shadowBlurIters = 2;
3638
float shadowDarkness = 0.25;
3739

src/render/ground_plane.cpp

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,18 @@ void GroundPlane::draw(bool isRedraw) {
196196
double bboxBottom = sign == 1.0 ? std::get<0>(state::boundingBox)[iP] : std::get<1>(state::boundingBox)[iP];
197197
double bboxHeight = std::get<1>(state::boundingBox)[iP] - std::get<0>(state::boundingBox)[iP];
198198
double heightEPS = state::lengthScale * 1e-4;
199-
double groundHeight = bboxBottom - sign * (options::groundPlaneHeightFactor.asAbsolute() + heightEPS);
199+
200+
double groundHeight = -777;
201+
switch (options::groundPlaneHeightMode) {
202+
case GroundPlaneHeightMode::Relative: {
203+
groundHeight = bboxBottom - sign * (options::groundPlaneHeightFactor.asAbsolute() + heightEPS);
204+
break;
205+
}
206+
case GroundPlaneHeightMode::Absolute: {
207+
groundHeight = options::groundPlaneHeight;
208+
break;
209+
}
210+
}
200211

201212
// Viewport
202213
glm::vec4 viewport = render::engine->getCurrentViewport();
@@ -387,6 +398,16 @@ void GroundPlane::buildGui() {
387398
return "";
388399
};
389400

401+
auto heightModeName = [](const GroundPlaneHeightMode& m) -> std::string {
402+
switch (m) {
403+
case GroundPlaneHeightMode::Relative:
404+
return "Relative";
405+
case GroundPlaneHeightMode::Absolute:
406+
return "Absolute";
407+
}
408+
return "";
409+
};
410+
390411
ImGui::SetNextItemOpen(false, ImGuiCond_FirstUseEver);
391412
if (ImGui::TreeNode("Ground Plane")) {
392413

@@ -404,7 +425,39 @@ void GroundPlane::buildGui() {
404425
}
405426
ImGui::PopItemWidth();
406427

407-
if (ImGui::SliderFloat("Height", options::groundPlaneHeightFactor.getValuePtr(), -1.0, 1.0)) requestRedraw();
428+
// Height
429+
ImGui::PushItemWidth(80);
430+
switch (options::groundPlaneHeightMode) {
431+
case GroundPlaneHeightMode::Relative:
432+
if (ImGui::SliderFloat("##HeightValue", options::groundPlaneHeightFactor.getValuePtr(), -1.0, 1.0))
433+
requestRedraw();
434+
break;
435+
case GroundPlaneHeightMode::Absolute:
436+
int iP;
437+
float sign;
438+
std::tie(iP, sign) = getGroundPlaneAxisAndSign();
439+
double bboxBottom = sign == 1.0 ? std::get<0>(state::boundingBox)[iP] : std::get<1>(state::boundingBox)[iP];
440+
double bboxHeight = std::get<1>(state::boundingBox)[iP] - std::get<0>(state::boundingBox)[iP];
441+
if (ImGui::SliderFloat("##HeightValue", &options::groundPlaneHeight, bboxBottom - 0.5 * bboxHeight,
442+
bboxBottom + bboxHeight)) {
443+
requestRedraw();
444+
}
445+
break;
446+
}
447+
ImGui::PopItemWidth();
448+
ImGui::SameLine();
449+
ImGui::PushItemWidth(100);
450+
if (ImGui::BeginCombo("Height##Mode", heightModeName(options::groundPlaneHeightMode).c_str())) {
451+
for (GroundPlaneHeightMode m : {GroundPlaneHeightMode::Relative, GroundPlaneHeightMode::Absolute}) {
452+
std::string mName = heightModeName(m);
453+
if (ImGui::Selectable(mName.c_str(), options::groundPlaneHeightMode == m)) {
454+
options::groundPlaneHeightMode = m;
455+
requestRedraw();
456+
}
457+
}
458+
ImGui::EndCombo();
459+
}
460+
ImGui::PopItemWidth();
408461

409462
switch (options::groundPlaneMode) {
410463
case GroundPlaneMode::None:

test/src/basics_test.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,12 @@ TEST_F(PolyscopeTest, GroundPlaneTest) {
134134
polyscope::refresh();
135135
polyscope::show(3);
136136

137+
polyscope::options::groundPlaneHeightMode = polyscope::GroundPlaneHeightMode::Absolute;
138+
polyscope::options::groundPlaneHeight = -0.3;
139+
polyscope::show(3);
140+
141+
polyscope::options::groundPlaneHeightMode = polyscope::GroundPlaneHeightMode::Relative;
142+
polyscope::show(3);
143+
137144
polyscope::removeAllStructures();
138145
}

0 commit comments

Comments
 (0)