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

@@ -38,13 +38,13 @@ BOOST_AUTO_TEST_CASE(vtkDetectorChamberTest) {
DetectorChamber d1, d2; DetectorChamber d1, d2;
// d1.SetSize(Vector3f(1, 1, 1)); // d1.SetSize(Vector3f(1, 1, 1));
// d1.SetPosition(Vector3f(0, 0, 0)); // d1.SetPosition(Vector3f(0, 0, 0));
d1.Scale(Vector3f(5_m, 10_m, 2_m)); d1.Scale(Vector3f(1000, 2000, 200));
d1.Translate(Vector3f(0, 0, 0)); d1.Translate(Vector3f(0, 0, 0));
// d2.SetSize(Vector3f(1, 1, 1)); // d2.SetSize(Vector3f(1, 1, 1));
// d2.SetPosition(Vector3f(0, 0, 0)); // d2.SetPosition(Vector3f(0, 0, 0));
d2.Scale(Vector3f(5_m, 10_m, 2_m)); d2.Scale(Vector3f(1000, 2000, 200));
d2.Translate(Vector3f(0, 0, 10_m)); d2.Translate(Vector3f(0, 0, 10));
Vtk::vtkDetectorChamber v_d1(&d1); Vtk::vtkDetectorChamber v_d1(&d1);

View File

@@ -84,9 +84,6 @@ void vtkStructuredGrid::Update() {
} }
m_Content->Updated(); // Notify others (like raytracer) m_Content->Updated(); // Notify others (like raytracer)
// Debug output
std::cout << "vtkStructuredGrid::Update matrix:\n" << transform << std::endl;
} }
void vtkStructuredGrid::InstallPipe() { void vtkStructuredGrid::InstallPipe() {

View File

@@ -115,9 +115,6 @@ void vtkContainerBox::Update() {
} }
m_Content->Updated(); // Notify change m_Content->Updated(); // Notify change
// Debug output
std::cout << "vtkContainerBox::Update matrix:\n" << transform << std::endl;
} }

View File

@@ -438,9 +438,6 @@ void vtkHandlerWidget::OnMouseMove() {
this->Prop3D->Modified(); this->Prop3D->Modified();
this->UpdateGizmoPosition(); this->UpdateGizmoPosition();
// HIGH VISIBILITY LOG
std::printf("--- WIDGET Interaction: %d, Mag: %f, Pos: %f %f %f\n", Interaction, mag, gpos[0], gpos[1], gpos[2]);
this->InvokeEvent(::vtkCommand::InteractionEvent, nullptr); this->InvokeEvent(::vtkCommand::InteractionEvent, nullptr);
this->Interactor->Render(); this->Interactor->Render();
} }

View File

@@ -215,6 +215,9 @@ void Viewport::SetupPipeline(vtkRenderWindowInteractor* iren)
self->m_HandlerWidget->SetReferenceFrame(vtkHandlerWidget::CENTER_LOCAL); self->m_HandlerWidget->SetReferenceFrame(vtkHandlerWidget::CENTER_LOCAL);
std::cout << "Widget Frame: CENTER_LOCAL" << std::endl; std::cout << "Widget Frame: CENTER_LOCAL" << std::endl;
} }
else if (key == "s") {
self->ZoomSelected();
}
iren->Render(); 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) void Viewport::AddPuppet(Puppet& prop)
{ {
m_Puppets.push_back(&prop); m_Puppets.push_back(&prop);

View File

@@ -43,6 +43,7 @@ public:
virtual void Render() = 0; virtual void Render() = 0;
void Reset(); void Reset();
void ZoomAuto(); void ZoomAuto();
void ZoomSelected();
// Puppet / prop management // Puppet / prop management
void AddPuppet(Puppet &prop); void AddPuppet(Puppet &prop);