fixed most ( still units error )
This commit is contained in:
@@ -11,6 +11,7 @@ set(MATH_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkContainerBox.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkCylinder.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkAssembly.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkPolydata.cpp
|
||||
PARENT_SCOPE)
|
||||
|
||||
set(MATH_HEADERS
|
||||
@@ -22,6 +23,7 @@ set(MATH_HEADERS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkContainerBox.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkCylinder.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkAssembly.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkPolydata.h
|
||||
PARENT_SCOPE)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
|
||||
@@ -92,13 +92,12 @@ void Assembly::InstallPipe() {
|
||||
void Assembly::contentUpdate() {
|
||||
if (m_InUpdate) return;
|
||||
m_InUpdate = true;
|
||||
|
||||
m_BlockUpdate = false;
|
||||
this->UpdateTransform();
|
||||
this->UpdateBoundingBox();
|
||||
if (m_ChildContext)
|
||||
m_ChildContext->Update();
|
||||
|
||||
m_BlockUpdate = true;
|
||||
Puppet::Update();
|
||||
m_InUpdate = false;
|
||||
}
|
||||
@@ -106,25 +105,29 @@ void Assembly::contentUpdate() {
|
||||
// ------------------------------------------------------------------ //
|
||||
void Assembly::Update() {
|
||||
if (m_InUpdate) return;
|
||||
if (!m_Content || !m_VtkAsm) return;
|
||||
m_InUpdate = true;
|
||||
this->contentUpdate();
|
||||
m_InUpdate = false;
|
||||
}
|
||||
|
||||
if (m_BlockUpdate) {
|
||||
m_BlockUpdate = false;
|
||||
return;
|
||||
}
|
||||
void Assembly::SyncFromVtk() {
|
||||
if (m_InUpdate) return;
|
||||
if (!m_Content || !m_VtkAsm) return;
|
||||
|
||||
m_InUpdate = true;
|
||||
|
||||
// Pull VTK transform back into the uLib model
|
||||
vtkMatrix4x4* vmat = m_VtkAsm->GetUserMatrix();
|
||||
if (vmat) {
|
||||
Matrix4f transform = VtkToMatrix4f(vmat);
|
||||
m_Content->SetMatrix(transform);
|
||||
}
|
||||
double pos[3], ori[3], scale[3];
|
||||
m_VtkAsm->GetPosition(pos);
|
||||
m_VtkAsm->GetOrientation(ori);
|
||||
m_VtkAsm->GetScale(scale);
|
||||
|
||||
m_Content->SetPosition(Vector3f(pos[0], pos[1], pos[2]));
|
||||
m_Content->SetOrientation(Vector3f(ori[0], ori[1], ori[2]) * CLHEP::degree);
|
||||
m_Content->SetScale(Vector3f(scale[0], scale[1], scale[2]));
|
||||
|
||||
this->UpdateBoundingBox();
|
||||
if (m_ChildContext)
|
||||
m_ChildContext->Update();
|
||||
m_ChildContext->SyncFromVtk();
|
||||
|
||||
m_Content->Updated(); // Notify change in model
|
||||
|
||||
@@ -135,10 +138,7 @@ void Assembly::Update() {
|
||||
void Assembly::UpdateTransform() {
|
||||
if (!m_Content || !m_VtkAsm) return;
|
||||
|
||||
Matrix4f mat = m_Content->GetMatrix();
|
||||
vtkNew<vtkMatrix4x4> vmat;
|
||||
Matrix4fToVtk(mat, vmat);
|
||||
m_VtkAsm->SetUserMatrix(vmat);
|
||||
this->ApplyTransform(m_VtkAsm);
|
||||
m_VtkAsm->Modified();
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,9 @@ public:
|
||||
/** @brief Updates the VTK representation from the model (model→VTK). */
|
||||
virtual void Update() override;
|
||||
|
||||
/** @brief Synchronizes the model from the VTK representation (VTK→model). */
|
||||
virtual void SyncFromVtk() override;
|
||||
|
||||
virtual uLib::Object* GetContent() const override { return (uLib::Object*)m_Content; }
|
||||
|
||||
/** @brief Called when the model signals an update (model→VTK push). */
|
||||
|
||||
@@ -80,54 +80,38 @@ void vtkContainerBox::contentUpdate() {
|
||||
vtkProp3D* root = vtkProp3D::SafeDownCast(this->GetProp());
|
||||
if (!root) return;
|
||||
|
||||
vtkMatrix4x4* vmat = root->GetUserMatrix();
|
||||
if (!vmat) {
|
||||
// Should have been set in InstallPipe, but let's be safe
|
||||
vtkNew<vtkMatrix4x4> mat;
|
||||
root->SetUserMatrix(mat);
|
||||
vmat = mat;
|
||||
}
|
||||
|
||||
d->m_Cube->SetUserMatrix(nullptr);
|
||||
d->m_Axes->SetUserMatrix(nullptr);
|
||||
|
||||
Matrix4f transform = m_Content->GetMatrix();
|
||||
Matrix4fToVtk(transform, vmat);
|
||||
TRS trs(*m_Content);
|
||||
this->ApplyTransform(root);
|
||||
|
||||
root->Modified();
|
||||
m_BlockUpdate = true;
|
||||
m_BlockUpdate = false;
|
||||
Puppet::Update();
|
||||
}
|
||||
|
||||
|
||||
void vtkContainerBox::Update() {
|
||||
this->contentUpdate();
|
||||
}
|
||||
|
||||
void vtkContainerBox::SyncFromVtk() {
|
||||
RecursiveMutex::ScopedLock lock(this->m_UpdateMutex);
|
||||
if (!m_Content) return;
|
||||
|
||||
if (m_BlockUpdate) {
|
||||
m_BlockUpdate = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Use Targeted Blocking: only block the feedback connection to this puppet
|
||||
// boost::signals2::shared_connection_block block(m_Connection);
|
||||
|
||||
vtkProp3D* assembly = vtkProp3D::SafeDownCast(this->GetProp());
|
||||
if (!assembly) return;
|
||||
|
||||
vtkMatrix4x4* vmat = assembly->GetUserMatrix();
|
||||
if (!vmat) return;
|
||||
double pos[3], ori[3], scale[3];
|
||||
assembly->GetPosition(pos);
|
||||
assembly->GetOrientation(ori);
|
||||
assembly->GetScale(scale);
|
||||
|
||||
m_Content->SetPosition(Vector3f(pos[0], pos[1], pos[2]));
|
||||
m_Content->SetOrientation(Vector3f(ori[0], ori[1], ori[2]) * CLHEP::degree);
|
||||
m_Content->SetScale(Vector3f(scale[0], scale[1], scale[2]));
|
||||
|
||||
Matrix4f transform = VtkToMatrix4f(vmat);
|
||||
|
||||
// Update uLib model's affine transform
|
||||
// if (m_Content->GetParent()) {
|
||||
// Matrix4f localT = m_Content->GetParent()->GetWorldMatrix().inverse() * transform;
|
||||
// m_Content->SetMatrix(localT);
|
||||
// } else {
|
||||
m_Content->SetMatrix(transform);
|
||||
// }
|
||||
|
||||
m_Content->Updated(); // Notify change
|
||||
}
|
||||
|
||||
@@ -175,9 +159,11 @@ void vtkContainerBox::InstallPipe() {
|
||||
|
||||
vtkProp3D* root = vtkProp3D::SafeDownCast(this->GetProp());
|
||||
if (root) {
|
||||
vtkNew<vtkMatrix4x4> vmat;
|
||||
Matrix4fToVtk(c->GetMatrix(), vmat);
|
||||
root->SetUserMatrix(vmat);
|
||||
TRS trs(*c);
|
||||
root->SetPosition(trs.position.x(), trs.position.y(), trs.position.z());
|
||||
root->SetOrientation(trs.rotation.x(), trs.rotation.y(), trs.rotation.z());
|
||||
root->SetScale(trs.scaling.x(), trs.scaling.y(), trs.scaling.z());
|
||||
root->SetUserMatrix(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,8 @@ public:
|
||||
|
||||
virtual void contentUpdate();
|
||||
|
||||
virtual void Update();
|
||||
virtual void Update() override;
|
||||
virtual void SyncFromVtk() override;
|
||||
|
||||
virtual uLib::Object* GetContent() const override { return (uLib::Object*)m_Content; }
|
||||
|
||||
|
||||
70
src/Vtk/Math/vtkPolydata.cpp
Normal file
70
src/Vtk/Math/vtkPolydata.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
#include <vtkVersion.h>
|
||||
#include <vtkPolyData.h>
|
||||
#include <vtkPolyDataWriter.h>
|
||||
#include <vtkXMLPolyDataWriter.h>
|
||||
#include <vtkSmartPointer.h>
|
||||
|
||||
#include "vtkPolydata.h"
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
void Polydata::SaveToFile(const char *vtk_file)
|
||||
{
|
||||
vtkSmartPointer<vtkPolyDataWriter> writer =
|
||||
vtkSmartPointer<vtkPolyDataWriter>::New();
|
||||
writer->SetFileName(vtk_file);
|
||||
vtkPolyData * data = GetPolyData();
|
||||
if(data) {
|
||||
# if VTK_MAJOR_VERSION <= 5
|
||||
writer->SetInputConnection(data->GetProducerPort());
|
||||
# else
|
||||
writer->SetInputData(data);
|
||||
# endif
|
||||
writer->Update();
|
||||
}
|
||||
}
|
||||
|
||||
void Polydata::SaveToXMLFile(const char *vtp_file)
|
||||
{
|
||||
vtkSmartPointer<vtkXMLPolyDataWriter> writer =
|
||||
vtkSmartPointer<vtkXMLPolyDataWriter>::New();
|
||||
writer->SetFileName(vtp_file);
|
||||
vtkPolyData * data = GetPolyData();
|
||||
if(data) {
|
||||
# if VTK_MAJOR_VERSION <= 5
|
||||
writer->SetInputConnection(data->GetProducerPort());
|
||||
# else
|
||||
writer->SetInputData(data);
|
||||
# endif
|
||||
writer->Update();
|
||||
}
|
||||
}
|
||||
|
||||
} // Vtk
|
||||
} // uLib
|
||||
52
src/Vtk/Math/vtkPolydata.h
Normal file
52
src/Vtk/Math/vtkPolydata.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
------------------------------------------------------------------
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
|
||||
|
||||
#ifndef VTKPOLYDATA_H
|
||||
#define VTKPOLYDATA_H
|
||||
|
||||
class vtkPolyData;
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
class Polydata {
|
||||
public:
|
||||
virtual vtkPolyData *GetPolyData() const { return NULL; }
|
||||
|
||||
virtual void SaveToFile(const char *vtk_file);
|
||||
|
||||
virtual void SaveToXMLFile(const char *vtp_file);
|
||||
|
||||
protected:
|
||||
virtual ~Polydata() {}
|
||||
};
|
||||
|
||||
} // namespace Vtk
|
||||
} // namespace uLib
|
||||
|
||||
|
||||
#endif // VTKPOLYDATA_H
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
#include "Math/QuadMesh.h"
|
||||
#include "Vtk/uLibVtkInterface.h"
|
||||
#include "Vtk/vtkPolydata.h"
|
||||
#include "Vtk/Math/vtkPolydata.h"
|
||||
|
||||
class vtkPolyData;
|
||||
class vtkActor;
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
#include "Math/TriangleMesh.h"
|
||||
#include "Vtk/uLibVtkInterface.h"
|
||||
#include "Vtk/vtkPolydata.h"
|
||||
#include "Vtk/Math/vtkPolydata.h"
|
||||
|
||||
class vtkPolyData;
|
||||
class vtkActor;
|
||||
|
||||
Reference in New Issue
Block a user