refactor: improve vtkContainerBox constructor flexibility and clean up code formatting
This commit is contained in:
@@ -43,50 +43,43 @@
|
||||
|
||||
#include "Vtk/Math/vtkDense.h"
|
||||
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
struct ContainerBoxData {
|
||||
vtkSmartPointer<vtkActor> m_Cube;
|
||||
vtkSmartPointer<vtkActor> m_Axes;
|
||||
vtkSmartPointer<vtkAssembly> m_VtkAsm;
|
||||
uLib::Connection m_UpdateSignal;
|
||||
vtkSmartPointer<vtkActor> m_Cube;
|
||||
vtkSmartPointer<vtkActor> m_Axes;
|
||||
vtkSmartPointer<vtkAssembly> m_VtkAsm;
|
||||
uLib::Connection m_UpdateSignal;
|
||||
|
||||
|
||||
ContainerBoxData() : m_Cube(vtkSmartPointer<vtkActor>::New()),
|
||||
m_Axes(vtkSmartPointer<vtkActor>::New()),
|
||||
m_VtkAsm(vtkSmartPointer<vtkAssembly>::New()) {}
|
||||
~ContainerBoxData() {
|
||||
}
|
||||
ContainerBoxData()
|
||||
: m_Cube(vtkSmartPointer<vtkActor>::New()),
|
||||
m_Axes(vtkSmartPointer<vtkActor>::New()),
|
||||
m_VtkAsm(vtkSmartPointer<vtkAssembly>::New()) {}
|
||||
~ContainerBoxData() {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ContainerBox::ContainerBox(ContainerBox::Content *content)
|
||||
: d(new ContainerBoxData()), ObjectWrapper(content) {
|
||||
: d(new ContainerBoxData()),
|
||||
ObjectWrapper(content ? content : new Content()) {
|
||||
this->InstallPipe();
|
||||
d->m_UpdateSignal =
|
||||
Object::connect(this->m_model.get(), &uLib::Object::Updated, this, &ContainerBox::Update);
|
||||
d->m_UpdateSignal = Object::connect(
|
||||
this->m_model.get(), &uLib::Object::Updated, this, &ContainerBox::Update);
|
||||
}
|
||||
|
||||
ContainerBox::~ContainerBox() {
|
||||
delete d;
|
||||
}
|
||||
ContainerBox::~ContainerBox() { delete d; }
|
||||
|
||||
vtkPolyData *ContainerBox::GetPolyData() const {
|
||||
// TODO
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void ContainerBox::Update() {
|
||||
RecursiveMutex::ScopedLock lock(this->m_UpdateMutex);
|
||||
if (!this->m_model) return;
|
||||
if (!this->m_model)
|
||||
return;
|
||||
|
||||
vtkProp3D* prop = vtkProp3D::SafeDownCast(this->GetProp());
|
||||
vtkProp3D *prop = vtkProp3D::SafeDownCast(this->GetProp());
|
||||
if (prop) {
|
||||
// Apply the full volume matrix (TRS * m_LocalT)
|
||||
vtkNew<vtkMatrix4x4> m;
|
||||
@@ -100,32 +93,28 @@ void ContainerBox::Update() {
|
||||
this->Prop3D::Update();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ContainerBox::SyncFromVtk() {
|
||||
RecursiveMutex::ScopedLock lock(this->m_UpdateMutex);
|
||||
if (!this->m_model) return;
|
||||
if (!this->m_model)
|
||||
return;
|
||||
|
||||
vtkProp3D* root = this->GetProxyProp();
|
||||
if (!root) return;
|
||||
vtkProp3D *root = this->GetProxyProp();
|
||||
if (!root)
|
||||
return;
|
||||
|
||||
// VTK -> Model: Extract new world TRS from proxy, which matches the model's TRS center
|
||||
vtkMatrix4x4* rootMat = root->GetUserMatrix();
|
||||
// VTK -> Model: Extract new world TRS from proxy, which matches the model's
|
||||
// TRS center
|
||||
vtkMatrix4x4 *rootMat = root->GetUserMatrix();
|
||||
Matrix4f vtkWorld = VtkToMatrix4f(rootMat);
|
||||
|
||||
|
||||
// Synchronize TRS property members from the updated local matrix
|
||||
this->m_model->FromMatrix(vtkWorld);
|
||||
|
||||
// Since we modified the model, notify observers, but block the loop back to VTK
|
||||
// ConnectionBlock blocker(d->m_UpdateSignal);
|
||||
// Since we modified the model, notify observers, but block the loop back to
|
||||
// VTK ConnectionBlock blocker(d->m_UpdateSignal);
|
||||
this->m_model->Updated();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void ContainerBox::InstallPipe() {
|
||||
if (!this->m_model)
|
||||
return;
|
||||
@@ -133,7 +122,7 @@ void ContainerBox::InstallPipe() {
|
||||
|
||||
// CUBE
|
||||
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
|
||||
|
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
cube->SetBounds(0, 1, 0, 1, 0, 1);
|
||||
@@ -160,11 +149,11 @@ void ContainerBox::InstallPipe() {
|
||||
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputConnection(axes->GetOutputPort());
|
||||
mapper->Update();
|
||||
|
||||
|
||||
d->m_VtkAsm->AddPart(d->m_Cube);
|
||||
d->m_VtkAsm->AddPart(d->m_Axes);
|
||||
this->SetProp(d->m_VtkAsm);
|
||||
|
||||
|
||||
// vtkProp3D* root = d->m_VtkAsm;
|
||||
// if (root) {
|
||||
// this->ApplyProp3DTransform(root);
|
||||
|
||||
Reference in New Issue
Block a user