refactor using pimpl and fix test

This commit is contained in:
AndreaRigoni
2026-03-25 16:18:07 +00:00
parent a467b7385b
commit 7d4acaef6d
17 changed files with 479 additions and 412 deletions

View File

@@ -47,18 +47,25 @@
namespace uLib {
namespace Vtk {
struct ContainerBoxData {
vtkActor *m_Cube;
vtkActor *m_Axes;
ContainerBoxData() : m_Cube(vtkActor::New()), m_Axes(vtkActor::New()) {}
~ContainerBoxData() {
m_Cube->Delete();
m_Axes->Delete();
}
};
vtkContainerBox::vtkContainerBox(vtkContainerBox::Content *content)
: m_Cube(vtkActor::New()), m_Axes(vtkActor::New()),
// m_Pivot(vtkActor::New()),
m_Content(content) {
: d(new ContainerBoxData()), m_Content(content) {
this->InstallPipe();
Object::connect(m_Content, &Content::Updated, this, &vtkContainerBox::contentUpdate);
}
vtkContainerBox::~vtkContainerBox() {
m_Cube->Delete();
m_Axes->Delete();
// m_Pivot->Delete();
delete d;
}
vtkPolyData *vtkContainerBox::GetPolyData() const {
@@ -83,8 +90,8 @@ void vtkContainerBox::contentUpdate() {
vmat = mat;
}
m_Cube->SetUserMatrix(nullptr);
m_Axes->SetUserMatrix(nullptr);
d->m_Cube->SetUserMatrix(nullptr);
d->m_Axes->SetUserMatrix(nullptr);
Matrix4f transform = m_Content->GetMatrix();
Matrix4fToVtk(transform, vmat);
@@ -143,9 +150,9 @@ void vtkContainerBox::InstallPipe() {
cube->SetBounds(0, 1, 0, 1, 0, 1);
mapper->SetInputConnection(cube->GetOutputPort());
mapper->Update();
m_Cube->SetMapper(mapper);
m_Cube->GetProperty()->SetRepresentationToWireframe();
m_Cube->GetProperty()->SetAmbient(0.7);
d->m_Cube->SetMapper(mapper);
d->m_Cube->GetProperty()->SetRepresentationToWireframe();
d->m_Cube->GetProperty()->SetAmbient(0.7);
// AXES //
vtkSmartPointer<vtkAxes> axes = vtkSmartPointer<vtkAxes>::New();
@@ -153,10 +160,10 @@ void vtkContainerBox::InstallPipe() {
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(axes->GetOutputPort());
mapper->Update();
m_Axes->SetMapper(mapper);
m_Axes->GetProperty()->SetLineWidth(3);
m_Axes->GetProperty()->SetAmbient(0.4);
m_Axes->GetProperty()->SetSpecular(0);
d->m_Axes->SetMapper(mapper);
d->m_Axes->GetProperty()->SetLineWidth(3);
d->m_Axes->GetProperty()->SetAmbient(0.4);
d->m_Axes->GetProperty()->SetSpecular(0);
// PIVOT //
axes = vtkSmartPointer<vtkAxes>::New();
@@ -165,8 +172,8 @@ void vtkContainerBox::InstallPipe() {
mapper->SetInputConnection(axes->GetOutputPort());
mapper->Update();
this->SetProp(m_Cube);
this->SetProp(m_Axes);
this->SetProp(d->m_Cube);
this->SetProp(d->m_Axes);
vtkProp3D* root = vtkProp3D::SafeDownCast(this->GetProp());
if (root) {