refactor: migrate vtk classes to use ObjectWrapper for model management and update registration logic
This commit is contained in:
@@ -61,13 +61,13 @@ namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
void VoxImage::UpdateFromContent() {
|
||||
Vector3i ev_dims = m_Content.GetDims();
|
||||
Vector3i ev_dims = this->m_model->GetDims();
|
||||
m_Image->SetDimensions(ev_dims.data());
|
||||
|
||||
Vector3f ev_spacing = m_Content.GetSpacing();
|
||||
Vector3f ev_spacing = this->m_model->GetSpacing();
|
||||
m_Image->SetSpacing(ev_spacing(0), ev_spacing(1), ev_spacing(2));
|
||||
|
||||
Vector3f ev_pos = m_Content.GetPosition();
|
||||
Vector3f ev_pos = this->m_model->GetPosition();
|
||||
m_Image->SetOrigin(ev_pos(0), ev_pos(1), ev_pos(2));
|
||||
|
||||
vtkFloatArray *array =
|
||||
@@ -78,14 +78,14 @@ void VoxImage::UpdateFromContent() {
|
||||
array->Delete();
|
||||
}
|
||||
|
||||
array->SetNumberOfTuples(m_Content.GetDims().prod());
|
||||
array->SetNumberOfTuples(this->m_model->GetDims().prod());
|
||||
Vector3i index(0, 0, 0);
|
||||
int i = 0;
|
||||
for (int zv = 0; zv < ev_dims(2); ++zv) {
|
||||
for (int yv = 0; yv < ev_dims(1); ++yv) {
|
||||
for (int xv = 0; xv < ev_dims(0); ++xv) {
|
||||
index << xv, yv, zv;
|
||||
array->SetValue(i++, m_Content.GetValue(index));
|
||||
array->SetValue(i++, this->m_model->GetValue(index));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,13 +94,13 @@ void VoxImage::UpdateFromContent() {
|
||||
void VoxImage::UpdateToContent() {
|
||||
int *ext = m_Image->GetExtent();
|
||||
int dims[3] = {ext[1] - ext[0] + 1, ext[3] - ext[2] + 1, ext[5] - ext[4] + 1};
|
||||
m_Content.SetDims(Vector3i(dims[0], dims[1], dims[2]));
|
||||
this->m_model->SetDims(Vector3i(dims[0], dims[1], dims[2]));
|
||||
|
||||
double *spacing = m_Image->GetSpacing();
|
||||
m_Content.SetSpacing(Vector3f(spacing[0], spacing[1], spacing[2]));
|
||||
this->m_model->SetSpacing(Vector3f(spacing[0], spacing[1], spacing[2]));
|
||||
|
||||
double *pos = m_Image->GetOrigin();
|
||||
m_Content.SetPosition(Vector3f(pos[0], pos[1], pos[2]));
|
||||
this->m_model->SetPosition(Vector3f(pos[0], pos[1], pos[2]));
|
||||
|
||||
vtkFloatArray *array =
|
||||
vtkFloatArray::SafeDownCast(m_Image->GetPointData()->GetScalars());
|
||||
@@ -111,7 +111,7 @@ void VoxImage::UpdateToContent() {
|
||||
for (int yv = 0; yv < dims[1]; ++yv) {
|
||||
for (int xv = 0; xv < dims[0]; ++xv) {
|
||||
index << xv, yv, zv;
|
||||
m_Content.SetValue(index, array->GetValue(i++));
|
||||
this->m_model->SetValue(index, array->GetValue(i++));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,8 +124,8 @@ void VoxImage::UpdateToContent() {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// VTK VOXIMAGE
|
||||
|
||||
VoxImage::VoxImage(Content &content)
|
||||
: m_Content(content), m_Actor(vtkVolume::New()),
|
||||
VoxImage::VoxImage(Content *content)
|
||||
: ObjectWrapper(content), m_Actor(vtkVolume::New()),
|
||||
m_Asm(vtkAssembly::New()),
|
||||
m_Image(vtkImageData::New()), m_Outline(vtkCubeSource::New()),
|
||||
m_OutlineActor(vtkActor::New()),
|
||||
@@ -134,7 +134,7 @@ VoxImage::VoxImage(Content &content)
|
||||
// Transfer functions
|
||||
m_ColorFun = vtkColorTransferFunction::New();
|
||||
m_OpacityFun = vtkPiecewiseFunction::New();
|
||||
m_UpdateConnection = Object::connect(&m_Content, &uLib::Object::Updated, this, &VoxImage::Update);
|
||||
m_UpdateConnection = Object::connect(this->m_model.get(), &uLib::Object::Updated, this, &VoxImage::Update);
|
||||
|
||||
UpdateFromContent();
|
||||
InstallPipe();
|
||||
@@ -314,8 +314,8 @@ void VoxImage::SyncFromVtk() {
|
||||
if (rootMat) {
|
||||
Matrix4f vtkLocal = VtkToMatrix4f(rootMat);
|
||||
// Synchronize TRS from VTK, compensating for local volume offset
|
||||
m_Content.FromMatrix(vtkLocal); // * m_Content.GetLocalMatrix().inverse());
|
||||
m_Content.Updated();
|
||||
this->m_model->FromMatrix(vtkLocal); // * this->m_model->GetLocalMatrix().inverse());
|
||||
this->m_model->Updated();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -323,11 +323,11 @@ void VoxImage::SyncFromVtk() {
|
||||
void VoxImage::Update() {
|
||||
if (auto *root = vtkProp3D::SafeDownCast(this->GetProp())) {
|
||||
vtkNew<vtkMatrix4x4> m;
|
||||
Matrix4fToVtk(m_Content.GetMatrix(), m); // * m_Content.GetLocalMatrix(), m);
|
||||
Matrix4fToVtk(this->m_model->GetMatrix(), m); // * this->m_model->GetLocalMatrix(), m);
|
||||
root->SetUserMatrix(m);
|
||||
root->Modified();
|
||||
// std::cout << "[VoxImage::Update] Set Proxy UserMatrix:" << std::endl;
|
||||
// std::cout << m_Content.GetMatrix() << std::endl;
|
||||
// std::cout << this->m_model->GetMatrix() << std::endl;
|
||||
}
|
||||
setShadingPreset(m_ShadingPreset);
|
||||
m_Actor->Update();
|
||||
|
||||
Reference in New Issue
Block a user