refactor using pimpl and fix test
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -29,12 +29,15 @@
|
||||
#include "Math/ContainerBox.h"
|
||||
#include "uLibVtkInterface.h"
|
||||
#include "vtkPolydata.h"
|
||||
#include <vtkActor.h>
|
||||
#include <boost/signals2/connection.hpp>
|
||||
|
||||
class vtkActor;
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
struct ContainerBoxData;
|
||||
|
||||
class vtkContainerBox : public Puppet, public Polydata {
|
||||
typedef ContainerBox Content;
|
||||
|
||||
@@ -51,13 +54,9 @@ public:
|
||||
protected:
|
||||
virtual void InstallPipe();
|
||||
|
||||
vtkActor *m_Cube;
|
||||
vtkActor *m_Axes;
|
||||
// vtkActor *m_Pivot;
|
||||
|
||||
Content *m_Content;
|
||||
bool m_BlockUpdate = false;
|
||||
// boost::signals2::connection m_Connection;
|
||||
struct ContainerBoxData *d;
|
||||
Content *m_Content;
|
||||
bool m_BlockUpdate = false;
|
||||
};
|
||||
|
||||
} // namespace Vtk
|
||||
|
||||
Reference in New Issue
Block a user