Updated glStencilViewer for InfSharpPatches

Added a toggle to enable the use of infinitely sharp
patches and also implemented fitFrame ('f' keypress).
This commit is contained in:
David G Yu 2016-10-07 17:40:58 -07:00
parent 086213bd3c
commit 705e144fb5

View File

@ -102,7 +102,8 @@ enum HudCheckBox { kHUD_CB_DISPLAY_CONTROL_MESH_EDGES,
kHUD_CB_DISPLAY_CONTROL_MESH_VERTS,
kHUD_CB_ANIMATE_VERTICES,
kHUD_CB_FREEZE,
kHUD_CB_BILINEAR };
kHUD_CB_ADAPTIVE,
kHUD_CB_INF_SHARP_PATCH };
int g_kernel = kCPU,
g_isolationLevel = 5; // max level of extraordinary feature isolation
@ -118,7 +119,8 @@ int g_running = 1,
g_freeze=0,
g_repeatCount;
bool g_bilinear=false;
bool g_adaptive=true,
g_infSharpPatch=false;
float g_rotate[2] = {0, 0},
g_dolly = 5,
@ -310,13 +312,30 @@ createMesh(ShapeDesc const & shapeDesc, int level) {
// save rest pose
g_orgPositions = shape->verts;
if (g_bilinear) {
// compute model bounding
float min[3] = { FLT_MAX, FLT_MAX, FLT_MAX};
float max[3] = {-FLT_MAX, -FLT_MAX, -FLT_MAX};
for (size_t i=0; i <g_orgPositions.size()/3; ++i) {
for(int j=0; j<3; ++j) {
float v = g_orgPositions[i*3+j];
min[j] = std::min(min[j], v);
max[j] = std::max(max[j], v);
}
}
for (int j=0; j<3; ++j) {
g_center[j] = (min[j] + max[j]) * 0.5f;
g_size += (max[j]-min[j])*(max[j]-min[j]);
}
g_size = sqrtf(g_size);
if (!g_adaptive) {
Far::TopologyRefiner::UniformOptions options(level);
options.fullTopologyInLastLevel = true;
refiner->RefineUniform(options);
} else {
Far::TopologyRefiner::AdaptiveOptions options(level);
options.useSingleCreasePatch = false;
options.useInfSharpPatch = g_infSharpPatch;
refiner->RefineAdaptive(options);
}
@ -833,6 +852,14 @@ setSamples(bool add) {
rebuildMesh();
}
//------------------------------------------------------------------------------
static void
fitFrame() {
g_pan[0] = g_pan[1] = 0;
g_dolly = g_size;
}
//------------------------------------------------------------------------------
static void
keyboard(GLFWwindow *, int key, int /* scancode */, int event, int /* mods */) {
@ -843,6 +870,8 @@ keyboard(GLFWwindow *, int key, int /* scancode */, int event, int /* mods */) {
switch (key) {
case 'Q': g_running = 0; break;
case 'F': fitFrame(); break;
case '=': setSamples(true); break;
case '-': setSamples(false); break;
@ -916,8 +945,11 @@ callbackCheckBox(bool checked, int button) {
case kHUD_CB_FREEZE:
g_freeze = checked;
break;
case kHUD_CB_BILINEAR:
g_bilinear = checked;
case kHUD_CB_ADAPTIVE:
g_adaptive = checked;
rebuildMesh();
case kHUD_CB_INF_SHARP_PATCH:
g_infSharpPatch = checked;
rebuildMesh();
}
}
@ -947,8 +979,11 @@ initHUD() {
10, 50, callbackCheckBox, kHUD_CB_ANIMATE_VERTICES, 'm');
g_hud.AddCheckBox("Freeze (spc)", g_freeze != 0,
10, 70, callbackCheckBox, kHUD_CB_FREEZE, ' ');
g_hud.AddCheckBox("Bilinear Stencils (`)", g_bilinear != 0,
10, 190, callbackCheckBox, kHUD_CB_BILINEAR, '`');
g_hud.AddCheckBox("Adaptive (`)", g_adaptive != 0,
10, 190, callbackCheckBox, kHUD_CB_ADAPTIVE, '`');
g_hud.AddCheckBox("Inf Sharp Patch (I)", g_infSharpPatch != 0,
10, 210, callbackCheckBox, kHUD_CB_INF_SHARP_PATCH, 'i');
int compute_pulldown = g_hud.AddPullDown("Compute (K)", 250, 10, 300, callbackKernel, 'k');
g_hud.AddPullDownButton(compute_pulldown, "CPU", kCPU);
@ -978,7 +1013,7 @@ initHUD() {
for (int i = 1; i < 11; ++i) {
char level[16];
sprintf(level, "Lv. %d", i);
g_hud.AddRadioButton(3, level, i==g_isolationLevel, 10, 210+i*20, callbackLevel, i, '0'+(i%10));
g_hud.AddRadioButton(3, level, i==g_isolationLevel, 10, 250+i*20, callbackLevel, i, '0'+(i%10));
}
int pulldown_handle = g_hud.AddPullDown("Shape (N)", -300, 10, 300, callbackModel, 'n');