qadmesh affine transform parenting
This commit is contained in:
@@ -43,6 +43,17 @@ BOOST_AUTO_TEST_CASE(vtkQuadMeshConstruction) {
|
||||
mesh.AddQuad(Vector4i(0, 1, 2, 3));
|
||||
|
||||
Vtk::vtkQuadMesh v_mesh(mesh);
|
||||
|
||||
Object::connect(&mesh, &QuadMesh::Updated, [&mesh]() {
|
||||
Vector3f points[4];
|
||||
points[0] = mesh.GetPoint(0);
|
||||
points[1] = mesh.GetPoint(1);
|
||||
points[2] = mesh.GetPoint(2);
|
||||
points[3] = mesh.GetPoint(3);
|
||||
std::cout << "mesh updated: " << points[0] << " " << points[1]
|
||||
<< " " << points[2] << " " << points[3] << std::endl;
|
||||
});
|
||||
|
||||
v_mesh.Update();
|
||||
|
||||
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {
|
||||
|
||||
@@ -40,6 +40,9 @@
|
||||
#include <vtkPolyData.h>
|
||||
#include <vtkPolyDataMapper.h>
|
||||
|
||||
#include <vtkMatrix4x4.h>
|
||||
#include <vtkNew.h>
|
||||
#include "Math/vtkDense.h"
|
||||
#include "Vtk/Math/vtkQuadMesh.h"
|
||||
#include <iostream>
|
||||
|
||||
@@ -55,12 +58,10 @@ void vtkQuadMesh::vtk2uLib_update() {
|
||||
<< "number of quads = " << number_of_quads << "\n"
|
||||
<< "//////\n";
|
||||
|
||||
m_content.Points().resize(number_of_points);
|
||||
m_content.Points().clear();
|
||||
for (int i = 0; i < number_of_points; ++i) {
|
||||
double *point = m_Poly->GetPoint(i);
|
||||
m_content.Points()[i](0) = point[0];
|
||||
m_content.Points()[i](1) = point[1];
|
||||
m_content.Points()[i](2) = point[2];
|
||||
m_content.Points().push_back(Vector3f(point[0], point[1], point[2]));
|
||||
}
|
||||
|
||||
m_content.Quads().resize(number_of_quads);
|
||||
@@ -86,11 +87,8 @@ void vtkQuadMesh::uLib2vtk_update() {
|
||||
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
|
||||
points->SetNumberOfPoints(number_of_points);
|
||||
for (vtkIdType i = 0; i < number_of_points; i++) {
|
||||
double x, y, z;
|
||||
x = m_content.Points().at(i)(0);
|
||||
y = m_content.Points().at(i)(1);
|
||||
z = m_content.Points().at(i)(2);
|
||||
points->SetPoint(i, x, y, z);
|
||||
Vector3f p = m_content.Points().at(i);
|
||||
points->SetPoint(i, p(0), p(1), p(2));
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkCellArray> polys = vtkSmartPointer<vtkCellArray>::New();
|
||||
@@ -110,7 +108,33 @@ void vtkQuadMesh::uLib2vtk_update() {
|
||||
m_Poly->SetPoints(points);
|
||||
m_Poly->SetPolys(polys);
|
||||
m_Poly->Modified();
|
||||
}
|
||||
|
||||
void vtkQuadMesh::contentUpdate() {
|
||||
vtkMatrix4x4 *vmat = m_Actor->GetUserMatrix();
|
||||
if (!vmat) {
|
||||
vtkNew<vtkMatrix4x4> mat;
|
||||
m_Actor->SetUserMatrix(mat);
|
||||
vmat = mat;
|
||||
}
|
||||
|
||||
Matrix4f transform = m_content.GetWorldMatrix();
|
||||
Matrix4fToVtk(transform, vmat);
|
||||
|
||||
uLib2vtk_update();
|
||||
|
||||
m_Poly->Modified();
|
||||
m_Actor->GetMapper()->Update();
|
||||
Puppet::Update();
|
||||
}
|
||||
|
||||
void vtkQuadMesh::Update() {
|
||||
vtkMatrix4x4 *vmat = m_Actor->GetUserMatrix();
|
||||
if (!vmat) return;
|
||||
|
||||
Matrix4f transform = VtkToMatrix4f(vmat);
|
||||
m_content.SetMatrix(transform);
|
||||
m_content.Updated();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
@@ -121,10 +145,18 @@ vtkQuadMesh::vtkQuadMesh(vtkQuadMesh::Content &content)
|
||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputData(m_Poly);
|
||||
m_Actor->SetMapper(mapper);
|
||||
|
||||
vtkNew<vtkMatrix4x4> vmat;
|
||||
Matrix4fToVtk(m_content.GetWorldMatrix(), vmat);
|
||||
m_Actor->SetUserMatrix(vmat);
|
||||
|
||||
this->SetProp(m_Actor);
|
||||
Object::connect(&m_content, &Content::Updated, this, &vtkQuadMesh::contentUpdate);
|
||||
this->contentUpdate();
|
||||
}
|
||||
|
||||
vtkQuadMesh::~vtkQuadMesh() {
|
||||
Object::disconnect(&m_content, &Content::Updated, this, &vtkQuadMesh::contentUpdate);
|
||||
m_Poly->Delete();
|
||||
m_Actor->Delete();
|
||||
}
|
||||
@@ -165,7 +197,5 @@ void vtkQuadMesh::ReadFromStlFile(const char *filename) {
|
||||
|
||||
vtkPolyData *vtkQuadMesh::GetPolyData() const { return m_Poly; }
|
||||
|
||||
void vtkQuadMesh::Update() { uLib2vtk_update(); }
|
||||
|
||||
} // namespace Vtk
|
||||
} // namespace uLib
|
||||
|
||||
@@ -53,7 +53,9 @@ public:
|
||||
|
||||
virtual class vtkPolyData *GetPolyData() const;
|
||||
|
||||
void Update();
|
||||
virtual void contentUpdate();
|
||||
|
||||
virtual void Update();
|
||||
|
||||
private:
|
||||
void vtk2uLib_update();
|
||||
|
||||
Reference in New Issue
Block a user