add zoom to selected

This commit is contained in:
AndreaRigoni
2026-03-18 23:35:51 +00:00
parent 3b02bb26ac
commit 176a82f108
6 changed files with 46 additions and 12 deletions

View File

@@ -215,6 +215,9 @@ void Viewport::SetupPipeline(vtkRenderWindowInteractor* iren)
self->m_HandlerWidget->SetReferenceFrame(vtkHandlerWidget::CENTER_LOCAL);
std::cout << "Widget Frame: CENTER_LOCAL" << std::endl;
}
else if (key == "s") {
self->ZoomSelected();
}
iren->Render();
});
@@ -235,6 +238,45 @@ void Viewport::ZoomAuto()
}
}
void Viewport::ZoomSelected()
{
if (!m_Renderer) return;
Puppet* selected = nullptr;
for (auto* p : m_Puppets) {
if (p->IsSelected()) {
selected = p;
break;
}
}
if (!selected) return;
vtkProp* prop = selected->GetProp();
if (!prop) return;
double* b = prop->GetBounds();
if (!b) return;
double bounds[6];
std::copy(b, b + 6, bounds);
if (bounds[0] > bounds[1]) return; // Invalid bounds
// Expand bounds by 1.5 from center
double center[3] = {(bounds[0] + bounds[1]) / 2.0, (bounds[2] + bounds[3]) / 2.0, (bounds[4] + bounds[5]) / 2.0};
double h_ext[3] = {(bounds[1] - bounds[0]) / 2.0, (bounds[3] - bounds[2]) / 2.0, (bounds[5] - bounds[4]) / 2.0};
double newBounds[6];
for (int i=0; i<3; ++i) {
newBounds[2*i] = center[i] - 1.5 * h_ext[i];
newBounds[2*i+1] = center[i] + 1.5 * h_ext[i];
}
m_Renderer->ResetCamera(newBounds);
m_Renderer->ResetCameraClippingRange();
this->Render();
}
void Viewport::AddPuppet(Puppet& prop)
{
m_Puppets.push_back(&prop);