refactor: migrate vtk classes to use ObjectWrapper for model management and update registration logic
This commit is contained in:
@@ -58,42 +58,42 @@ void TriangleMesh::vtk2uLib_update() {
|
||||
<< "number of polys = " << number_of_triangles << "\n"
|
||||
<< "//////\n";
|
||||
|
||||
m_content.Points().clear();
|
||||
this->m_model->Points().clear();
|
||||
for (int i = 0; i < number_of_points; ++i) {
|
||||
double *point = m_Poly->GetPoint(i);
|
||||
m_content.Points().push_back(Vector3f(point[0], point[1], point[2]));
|
||||
this->m_model->Points().push_back(Vector3f(point[0], point[1], point[2]));
|
||||
}
|
||||
|
||||
m_content.Triangles().resize(number_of_triangles);
|
||||
this->m_model->Triangles().resize(number_of_triangles);
|
||||
m_Poly->GetPolys()->InitTraversal();
|
||||
vtkSmartPointer<vtkIdList> idList = vtkSmartPointer<vtkIdList>::New();
|
||||
for (int i = 0; i < number_of_triangles; ++i) {
|
||||
m_Poly->GetPolys()->GetNextCell(idList);
|
||||
m_content.Triangles()[i](0) = idList->GetId(0);
|
||||
m_content.Triangles()[i](1) = idList->GetId(1);
|
||||
m_content.Triangles()[i](2) = idList->GetId(2);
|
||||
this->m_model->Triangles()[i](0) = idList->GetId(0);
|
||||
this->m_model->Triangles()[i](1) = idList->GetId(1);
|
||||
this->m_model->Triangles()[i](2) = idList->GetId(2);
|
||||
}
|
||||
m_Poly->Modified();
|
||||
m_Actor->GetMapper()->Update();
|
||||
}
|
||||
|
||||
void TriangleMesh::uLib2vtk_update() {
|
||||
vtkIdType number_of_points = m_content.Points().size();
|
||||
vtkIdType number_of_triangles = m_content.Triangles().size();
|
||||
vtkIdType number_of_points = this->m_model->Points().size();
|
||||
vtkIdType number_of_triangles = this->m_model->Triangles().size();
|
||||
|
||||
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
|
||||
points->SetNumberOfPoints(number_of_points);
|
||||
for (vtkIdType i = 0; i < number_of_points; i++) {
|
||||
Vector3f p = m_content.Points().at(i);
|
||||
Vector3f p = this->m_model->Points().at(i);
|
||||
points->SetPoint(i, p(0), p(1), p(2));
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkCellArray> polys = vtkSmartPointer<vtkCellArray>::New();
|
||||
for (vtkIdType i = 0; i < number_of_triangles; i++) {
|
||||
vtkIdType a, b, c;
|
||||
a = m_content.Triangles().at(i)(0);
|
||||
b = m_content.Triangles().at(i)(1);
|
||||
c = m_content.Triangles().at(i)(2);
|
||||
a = this->m_model->Triangles().at(i)(0);
|
||||
b = this->m_model->Triangles().at(i)(1);
|
||||
c = this->m_model->Triangles().at(i)(2);
|
||||
polys->InsertNextCell(3);
|
||||
polys->InsertCellPoint(a);
|
||||
polys->InsertCellPoint(b);
|
||||
@@ -113,7 +113,7 @@ void TriangleMesh::contentUpdate() {
|
||||
vmat = mat;
|
||||
}
|
||||
|
||||
Matrix4f transform = m_content.GetWorldMatrix();
|
||||
Matrix4f transform = this->m_model->GetWorldMatrix();
|
||||
Matrix4fToVtk(transform, vmat);
|
||||
|
||||
uLib2vtk_update();
|
||||
@@ -128,30 +128,30 @@ void TriangleMesh::Update() {
|
||||
if (!vmat) return;
|
||||
|
||||
Matrix4f transform = VtkToMatrix4f(vmat);
|
||||
m_content.SetMatrix(transform);
|
||||
m_content.Updated();
|
||||
this->m_model->SetMatrix(transform);
|
||||
this->m_model->Updated();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
||||
TriangleMesh::TriangleMesh(TriangleMesh::Content &content)
|
||||
: m_content(content), m_Poly(vtkPolyData::New()), m_Actor(vtkActor::New()) {
|
||||
TriangleMesh::TriangleMesh(TriangleMesh::Content *content)
|
||||
: ObjectWrapper(content), m_Poly(vtkPolyData::New()), m_Actor(vtkActor::New()) {
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputData(m_Poly);
|
||||
m_Actor->SetMapper(mapper);
|
||||
|
||||
vtkNew<vtkMatrix4x4> vmat;
|
||||
Matrix4fToVtk(m_content.GetWorldMatrix(), vmat);
|
||||
Matrix4fToVtk(this->m_model->GetWorldMatrix(), vmat);
|
||||
m_Actor->SetUserMatrix(vmat);
|
||||
|
||||
this->SetProp(m_Actor);
|
||||
Object::connect(&m_content, &Content::Updated, this, &TriangleMesh::contentUpdate);
|
||||
Object::connect(this->m_model.get(), &Content::Updated, this, &TriangleMesh::contentUpdate);
|
||||
this->contentUpdate();
|
||||
}
|
||||
|
||||
TriangleMesh::~TriangleMesh() {
|
||||
Object::disconnect(&m_content, &Content::Updated, this, &TriangleMesh::contentUpdate);
|
||||
Object::disconnect(this->m_model.get(), &Content::Updated, this, &TriangleMesh::contentUpdate);
|
||||
m_Poly->Delete();
|
||||
m_Actor->Delete();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user