move vtk containerbox in math
This commit is contained in:
178
src/Vtk/Math/vtkContainerBox.cpp
Normal file
178
src/Vtk/Math/vtkContainerBox.cpp
Normal file
@@ -0,0 +1,178 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// 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.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "vtkContainerBox.h"
|
||||
#include <vtkActor.h>
|
||||
#include <vtkAssembly.h>
|
||||
#include <vtkAxes.h>
|
||||
#include <vtkCubeSource.h>
|
||||
#include <vtkLineSource.h>
|
||||
#include <vtkMatrix4x4.h>
|
||||
#include <vtkPolyDataMapper.h>
|
||||
#include <vtkProperty.h>
|
||||
#include <vtkSmartPointer.h>
|
||||
#include <vtkTransform.h>
|
||||
|
||||
#include "Math/vtkDense.h"
|
||||
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
vtkContainerBox::vtkContainerBox(vtkContainerBox::Content *content)
|
||||
: m_Cube(vtkActor::New()), m_Axes(vtkActor::New()),
|
||||
// m_Pivot(vtkActor::New()),
|
||||
m_Content(content) {
|
||||
this->InstallPipe();
|
||||
Object::connect(m_Content, &Content::Updated, this, &vtkContainerBox::contentUpdate);
|
||||
}
|
||||
|
||||
vtkContainerBox::~vtkContainerBox() {
|
||||
m_Cube->Delete();
|
||||
m_Axes->Delete();
|
||||
// m_Pivot->Delete();
|
||||
}
|
||||
|
||||
vtkPolyData *vtkContainerBox::GetPolyData() const {
|
||||
// TODO
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void vtkContainerBox::contentUpdate() {
|
||||
if (!m_Content)
|
||||
return;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
m_Cube->SetUserMatrix(nullptr);
|
||||
m_Axes->SetUserMatrix(nullptr);
|
||||
|
||||
Matrix4f transform = m_Content->GetMatrix();
|
||||
Matrix4fToVtk(transform, vmat);
|
||||
|
||||
root->Modified();
|
||||
m_BlockUpdate = true;
|
||||
Puppet::Update();
|
||||
}
|
||||
|
||||
|
||||
void vtkContainerBox::Update() {
|
||||
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;
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void vtkContainerBox::InstallPipe() {
|
||||
if (!m_Content)
|
||||
return;
|
||||
Content *c = m_Content;
|
||||
|
||||
// CUBE
|
||||
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
|
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
cube->SetBounds(0, 1, 0, 1, 0, 1);
|
||||
mapper->SetInputConnection(cube->GetOutputPort());
|
||||
mapper->Update();
|
||||
m_Cube->SetMapper(mapper);
|
||||
m_Cube->GetProperty()->SetRepresentationToWireframe();
|
||||
m_Cube->GetProperty()->SetAmbient(0.7);
|
||||
|
||||
// AXES //
|
||||
vtkSmartPointer<vtkAxes> axes = vtkSmartPointer<vtkAxes>::New();
|
||||
axes->SetOrigin(0, 0, 0);
|
||||
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputConnection(axes->GetOutputPort());
|
||||
mapper->Update();
|
||||
m_Axes->SetMapper(mapper);
|
||||
m_Axes->GetProperty()->SetLineWidth(3);
|
||||
m_Axes->GetProperty()->SetAmbient(0.4);
|
||||
m_Axes->GetProperty()->SetSpecular(0);
|
||||
|
||||
// PIVOT //
|
||||
axes = vtkSmartPointer<vtkAxes>::New();
|
||||
axes->SetOrigin(0, 0, 0);
|
||||
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputConnection(axes->GetOutputPort());
|
||||
mapper->Update();
|
||||
|
||||
this->SetProp(m_Cube);
|
||||
this->SetProp(m_Axes);
|
||||
|
||||
vtkProp3D* root = vtkProp3D::SafeDownCast(this->GetProp());
|
||||
if (root) {
|
||||
vtkNew<vtkMatrix4x4> vmat;
|
||||
Matrix4fToVtk(c->GetMatrix(), vmat);
|
||||
root->SetUserMatrix(vmat);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Vtk
|
||||
} // namespace uLib
|
||||
Reference in New Issue
Block a user