refactor: improve vtkContainerBox constructor flexibility and clean up code formatting
This commit is contained in:
@@ -25,7 +25,6 @@
|
||||
|
||||
#include "Vtk/uLibVtkViewer.h"
|
||||
|
||||
#include "Vtk/Math/vtkContainerBox.h"
|
||||
#include "Math/Units.h"
|
||||
#include "Vtk/Math/vtkContainerBox.h"
|
||||
|
||||
@@ -36,19 +35,23 @@ using namespace uLib;
|
||||
int main() {
|
||||
BEGIN_TESTING(vtk ContainerBox Test);
|
||||
|
||||
ContainerBox box;
|
||||
box.Scale(Vector3f(1_m,2_m,1_m));
|
||||
box.SetPosition(Vector3f(0,0,0));
|
||||
|
||||
Vtk::ContainerBox v_box(&box);
|
||||
v_box.Update();
|
||||
|
||||
// v_box.SetRepresentation(Vtk::Prop3D::Surface);
|
||||
// v_box.SetOpacity(0.5);
|
||||
// v_box.SetSelectable(true);
|
||||
|
||||
box.findOrAddSignal(&Object::Updated)->connect([&box](){
|
||||
std::cout << "box updated: " << box.GetWorldPoint(HPoint3f(1,1,1)) << std::endl;
|
||||
{
|
||||
ContainerBox box;
|
||||
box.Scale(Vector3f(1_m, 2_m, 1_m));
|
||||
box.SetPosition(Vector3f(0, 0, 0));
|
||||
|
||||
Vtk::ContainerBox v_box(&box);
|
||||
v_box.Update();
|
||||
|
||||
v_box.SetRepresentation(Vtk::Prop3D::Surface);
|
||||
v_box.SetOpacity(0.5);
|
||||
v_box.SetSelectable(true);
|
||||
}
|
||||
|
||||
Vtk::ContainerBox v_box;
|
||||
v_box.findOrAddSignal(&Object::Updated)->connect([&v_box]() {
|
||||
std::cout << "box updated: "
|
||||
<< v_box.get()->GetWorldPoint(HPoint3f(1, 1, 1)) << std::endl;
|
||||
});
|
||||
|
||||
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -42,11 +42,11 @@ class ContainerBox : public Prop3D,
|
||||
public Polydata,
|
||||
public uLib::ObjectWrapper<uLib::ContainerBox> {
|
||||
|
||||
uLibTypeMacro(ContainerBox, Prop3D, Polydata)
|
||||
typedef uLib::ContainerBox Content;
|
||||
uLibTypeMacro(ContainerBox, Prop3D,
|
||||
Polydata) typedef uLib::ContainerBox Content;
|
||||
|
||||
public:
|
||||
ContainerBox(Content *content);
|
||||
ContainerBox(Content *content = nullptr);
|
||||
~ContainerBox();
|
||||
|
||||
virtual class vtkPolyData *GetPolyData() const override;
|
||||
|
||||
Reference in New Issue
Block a user