115 lines
3.6 KiB
C++
115 lines
3.6 KiB
C++
/*//////////////////////////////////////////////////////////////////////////////
|
|
// 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 "Math/StructuredGrid.h"
|
|
#include "Vtk/Math/vtkStructuredGrid.h"
|
|
|
|
#include "Vtk/Math/vtkDense.h"
|
|
|
|
namespace uLib {
|
|
namespace Vtk {
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
////// VTK STRUCTURED GRID /////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
vtkStructuredGrid::vtkStructuredGrid(Content &content)
|
|
: m_Content(&content), m_Actor(vtkActor::New()),
|
|
m_Transform(vtkTransform::New()) {
|
|
|
|
this->InstallPipe();
|
|
}
|
|
|
|
vtkStructuredGrid::~vtkStructuredGrid() {
|
|
m_Actor->Delete();
|
|
m_Transform->Delete();
|
|
}
|
|
|
|
void vtkStructuredGrid::SetTransform(vtkTransform *t) {
|
|
vtkMatrix4x4 *vmat = t->GetMatrix();
|
|
Matrix4f mat = VtkToMatrix4f(vmat);
|
|
m_Content->SetMatrix(mat);
|
|
|
|
vtkSmartPointer<vtkMatrix4x4> vmat2 = vtkSmartPointer<vtkMatrix4x4>::New();
|
|
mat = m_Content->GetWorldMatrix();
|
|
Matrix4fToVtk(mat, vmat2);
|
|
m_Transform->SetMatrix(vmat2);
|
|
m_Transform->Update();
|
|
this->Update();
|
|
}
|
|
|
|
void vtkStructuredGrid::Update() {
|
|
if (!m_Content) return;
|
|
|
|
vtkProp3D* actor = vtkProp3D::SafeDownCast(this->GetProp());
|
|
if (!actor) return;
|
|
|
|
vtkMatrix4x4* vmat = actor->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 others (like raytracer)
|
|
}
|
|
|
|
void vtkStructuredGrid::InstallPipe() {
|
|
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
|
|
|
|
Vector3i dims = m_Content->GetDims();
|
|
cube->SetBounds(0, dims(0), 0, dims(1), 0, dims(2));
|
|
cube->Update();
|
|
|
|
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
|
vtkSmartPointer<vtkPolyDataMapper>::New();
|
|
mapper->SetInputConnection(cube->GetOutputPort());
|
|
|
|
m_Actor->SetMapper(mapper);
|
|
m_Actor->GetProperty()->SetRepresentationToSurface();
|
|
m_Actor->GetProperty()->SetEdgeVisibility(true);
|
|
m_Actor->GetProperty()->SetOpacity(0.4);
|
|
m_Actor->GetProperty()->SetAmbient(0.7);
|
|
|
|
vtkNew<vtkMatrix4x4> vmat;
|
|
Matrix4fToVtk(m_Content->GetWorldMatrix(), vmat);
|
|
m_Actor->SetUserMatrix(vmat);
|
|
|
|
this->SetProp(m_Actor);
|
|
}
|
|
|
|
} // namespace Vtk
|
|
} // namespace uLib
|