fixed most ( still units error )
This commit is contained in:
@@ -63,6 +63,7 @@
|
||||
#include "uLibVtkInterface.h"
|
||||
#include "vtkHandlerWidget.h"
|
||||
#include "Math/Dense.h"
|
||||
#include "Vtk/Math/vtkDense.h"
|
||||
#include "Core/Property.h"
|
||||
|
||||
|
||||
@@ -75,12 +76,6 @@ namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// PUPPET //
|
||||
|
||||
// PIMPL -------------------------------------------------------------------- //
|
||||
|
||||
class PuppetData {
|
||||
@@ -98,9 +93,6 @@ public:
|
||||
m_Dragable(true)
|
||||
{
|
||||
m_Color[0] = m_Color[1] = m_Color[2] = -1.0;
|
||||
m_Position = Vector3d::Zero();
|
||||
m_Orientation = Vector3d::Zero();
|
||||
m_Scale = Vector3d::Ones();
|
||||
}
|
||||
|
||||
~PuppetData() {
|
||||
@@ -126,9 +118,7 @@ public:
|
||||
bool m_Selected;
|
||||
bool m_Visibility;
|
||||
bool m_Dragable;
|
||||
Vector3d m_Position;
|
||||
Vector3d m_Orientation;
|
||||
Vector3d m_Scale;
|
||||
TRS m_Transform;
|
||||
|
||||
void ApplyAppearance(vtkProp *p) {
|
||||
p->SetVisibility(m_Visibility);
|
||||
@@ -154,13 +144,19 @@ public:
|
||||
actor->GetProperty()->SetOpacity(m_Opacity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle transformation if it's a Prop3D
|
||||
if (auto* p3d = vtkProp3D::SafeDownCast(p)) {
|
||||
// NOTE: Usually managed by Puppet::Update from model, but here for direct prop manipulation
|
||||
// p3d->SetPosition(m_Position.data());
|
||||
// p3d->SetOrientation(m_Orientation.data());
|
||||
// p3d->SetScale(m_Scale.data());
|
||||
void ApplyTransform(vtkProp3D* p3d) {
|
||||
if (p3d) {
|
||||
p3d->SetPosition(m_Transform.position.x(), m_Transform.position.y(), m_Transform.position.z());
|
||||
|
||||
// Convert Model Radians to VTK Degrees
|
||||
p3d->SetOrientation(m_Transform.rotation.x() / CLHEP::degree,
|
||||
m_Transform.rotation.y() / CLHEP::degree,
|
||||
m_Transform.rotation.z() / CLHEP::degree);
|
||||
|
||||
p3d->SetScale(m_Transform.scaling.x(), m_Transform.scaling.y(), m_Transform.scaling.z());
|
||||
p3d->SetUserMatrix(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,6 +199,7 @@ public:
|
||||
}
|
||||
|
||||
if (root) {
|
||||
// Now that we use internal TRS, the prop's total matrix is GetMatrix()
|
||||
m_HighlightActor->SetUserMatrix(root->GetMatrix());
|
||||
}
|
||||
|
||||
@@ -227,6 +224,15 @@ public:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Puppet::Puppet() : Object(), pd(new PuppetData) {
|
||||
ULIB_ACTIVATE_DISPLAY_PROPERTIES;
|
||||
for (auto* p : this->GetDisplayProperties()) {
|
||||
@@ -278,6 +284,16 @@ void Puppet::RemoveProp(vtkProp *prop)
|
||||
// TODO
|
||||
}
|
||||
|
||||
void Puppet::ApplyAppearance(vtkProp* prop)
|
||||
{
|
||||
pd->ApplyAppearance(prop);
|
||||
}
|
||||
|
||||
void Puppet::ApplyTransform(vtkProp3D* p3d)
|
||||
{
|
||||
pd->ApplyTransform(p3d);
|
||||
}
|
||||
|
||||
|
||||
vtkPropCollection *Puppet::GetParts()
|
||||
{
|
||||
@@ -485,7 +501,7 @@ void Puppet::SetSelected(bool selected)
|
||||
if (!pd->m_Selectable) return;
|
||||
if (pd->m_Selected == selected) return;
|
||||
pd->m_Selected = selected;
|
||||
pd->UpdateHighlight();0
|
||||
pd->UpdateHighlight();
|
||||
}
|
||||
|
||||
bool Puppet::IsSelected() const
|
||||
@@ -497,31 +513,15 @@ void Puppet::Update()
|
||||
{
|
||||
vtkProp* root = this->GetProp();
|
||||
if (root) {
|
||||
pd->ApplyAppearance(root);
|
||||
|
||||
// Handle transformation synchronization from content
|
||||
if (auto* content = dynamic_cast<uLib::AffineTransform*>(GetContent())) {
|
||||
pd->m_Position = content->GetPosition().cast<double>();
|
||||
pd->m_Orientation = content->GetOrientation().cast<double>();
|
||||
pd->m_Scale = content->GetScale().cast<double>();
|
||||
pd->m_Transform = *content; // Uses TRS(const AffineTransform&)
|
||||
}
|
||||
|
||||
if (auto* p3d = vtkProp3D::SafeDownCast(root)) {
|
||||
vtkNew<vtkMatrix4x4> vmat;
|
||||
const Matrix4f& emat = content->GetMatrix();
|
||||
for(int i=0; i<4; ++i) for(int j=0; j<4; ++j) vmat->SetElement(i, j, emat(i,j));
|
||||
p3d->SetUserMatrix(vmat);
|
||||
|
||||
// Clear base transform to avoid double-application
|
||||
p3d->SetPosition(0,0,0);
|
||||
p3d->SetOrientation(0,0,0);
|
||||
p3d->SetScale(1,1,1);
|
||||
}
|
||||
}
|
||||
else if (auto* p3d = vtkProp3D::SafeDownCast(root)) {
|
||||
p3d->SetPosition(pd->m_Position.data());
|
||||
p3d->SetOrientation(pd->m_Orientation.data());
|
||||
p3d->SetScale(pd->m_Scale.data());
|
||||
if (auto* p3d = vtkProp3D::SafeDownCast(root)) {
|
||||
pd->ApplyTransform(p3d);
|
||||
}
|
||||
pd->ApplyAppearance(root);
|
||||
}
|
||||
|
||||
vtkProp3DCollection *props = pd->m_Assembly->GetParts();
|
||||
@@ -564,32 +564,29 @@ void Puppet::SyncFromVtk()
|
||||
if (auto* p3d = vtkProp3D::SafeDownCast(root)) {
|
||||
// Handle content synchronization if it's an AffineTransform
|
||||
if (auto* content = dynamic_cast<uLib::AffineTransform*>(GetContent())) {
|
||||
vtkMatrix4x4* vmat = p3d->GetUserMatrix();
|
||||
if (vmat) {
|
||||
Matrix4f emat;
|
||||
for (int i=0; i<4; ++i)
|
||||
for (int j=0; j<4; ++j)
|
||||
emat(i, j) = vmat->GetElement(i, j);
|
||||
content->SetMatrix(emat);
|
||||
|
||||
// Re-sync internal puppet properties from the now-updated content
|
||||
pd->m_Position = content->GetPosition().cast<double>();
|
||||
pd->m_Orientation = content->GetOrientation().cast<double>();
|
||||
pd->m_Scale = content->GetScale().cast<double>();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Update internal puppet properties directly from base components
|
||||
// only if no content exists (old behavior)
|
||||
double pos[3], ori[3], scale[3];
|
||||
p3d->GetPosition(pos);
|
||||
p3d->GetOrientation(ori);
|
||||
p3d->GetScale(scale);
|
||||
for (int i=0; i<3; ++i) {
|
||||
pd->m_Position(i) = pos[i];
|
||||
pd->m_Orientation(i) = ori[i];
|
||||
pd->m_Scale(i) = scale[i];
|
||||
}
|
||||
|
||||
// Convert VTK Degrees to Model Radians
|
||||
content->SetPosition(Vector3f(pos[0], pos[1], pos[2]));
|
||||
content->SetOrientation(Vector3f(ori[0], ori[1], ori[2]) * CLHEP::degree);
|
||||
content->SetScale(Vector3f(scale[0], scale[1], scale[2]));
|
||||
|
||||
// Re-sync internal puppet properties from the now-updated content
|
||||
pd->m_Transform = *content;
|
||||
}
|
||||
else {
|
||||
// Update internal puppet TRS directly from VTK components
|
||||
double pos[3], ori[3], scale[3];
|
||||
p3d->GetPosition(pos);
|
||||
p3d->GetOrientation(ori);
|
||||
p3d->GetScale(scale);
|
||||
pd->m_Transform.position = Vector3f(pos[0], pos[1], pos[2]);
|
||||
// Convert VTK Degrees to internal Radians
|
||||
pd->m_Transform.rotation = Vector3f(ori[0], ori[1], ori[2]) * CLHEP::degree;
|
||||
pd->m_Transform.scaling = Vector3f(scale[0], scale[1], scale[2]);
|
||||
}
|
||||
|
||||
// Notify puppet properties updated
|
||||
@@ -609,9 +606,7 @@ struct TransformProxy {
|
||||
PuppetData* pd;
|
||||
template<class Archive>
|
||||
void serialize(Archive & ar, const unsigned int version) {
|
||||
ar & boost::serialization::make_hrp("Position", pd->m_Position, "mm");
|
||||
ar & boost::serialization::make_hrp("Orientation", pd->m_Orientation, "deg");
|
||||
ar & boost::serialization::make_hrp("Scale", pd->m_Scale, "");
|
||||
ar & boost::serialization::make_nvp("Transform", pd->m_Transform);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user