148 lines
4.3 KiB
C++
148 lines
4.3 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 <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 "Vtk/Math/vtkDense.h"
|
|
|
|
namespace uLib {
|
|
namespace Vtk {
|
|
|
|
struct ContainerBoxData {
|
|
vtkSmartPointer<vtkActor> m_Cube;
|
|
vtkSmartPointer<vtkActor> m_Axes;
|
|
vtkSmartPointer<vtkAssembly> m_VtkAsm;
|
|
uLib::Connection m_UpdateSignal;
|
|
|
|
ContainerBoxData()
|
|
: m_Cube(vtkSmartPointer<vtkActor>::New()),
|
|
m_Axes(vtkSmartPointer<vtkActor>::New()),
|
|
m_VtkAsm(vtkSmartPointer<vtkAssembly>::New()) {}
|
|
~ContainerBoxData() {
|
|
m_UpdateSignal.disconnect();
|
|
}
|
|
};
|
|
|
|
ContainerBox::ContainerBox(ContainerBox::Content *content)
|
|
: d(new ContainerBoxData()),
|
|
ObjectWrapper(content ? content : new Content()) {
|
|
this->InstallPipe();
|
|
d->m_UpdateSignal = Object::connect(
|
|
this->m_model.get(), &uLib::Object::Updated, this, &ContainerBox::Update);
|
|
}
|
|
|
|
ContainerBox::~ContainerBox() { delete d; }
|
|
|
|
vtkPolyData *ContainerBox::GetPolyData() const {
|
|
// TODO
|
|
return NULL;
|
|
}
|
|
|
|
void ContainerBox::Update() {
|
|
RecursiveMutex::ScopedLock lock(this->m_UpdateMutex);
|
|
if (!this->m_model)
|
|
return;
|
|
|
|
vtkProp3D *prop = vtkProp3D::SafeDownCast(this->GetProp());
|
|
if (prop) {
|
|
// Apply the full volume matrix (TRS * m_LocalT)
|
|
vtkNew<vtkMatrix4x4> m;
|
|
Matrix4fToVtk(this->m_model->GetMatrix(), m);
|
|
prop->SetUserMatrix(m);
|
|
prop->Modified();
|
|
}
|
|
|
|
// Delegate rest of update (appearance, render, etc)
|
|
ConnectionBlock blocker(d->m_UpdateSignal);
|
|
this->Prop3D::Update();
|
|
}
|
|
|
|
|
|
|
|
void ContainerBox::InstallPipe() {
|
|
if (!this->m_model)
|
|
return;
|
|
Content *c = this->m_model;
|
|
|
|
// 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();
|
|
d->m_Cube->SetMapper(mapper);
|
|
d->m_Cube->GetProperty()->SetRepresentationToWireframe();
|
|
d->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();
|
|
d->m_Axes->SetMapper(mapper);
|
|
d->m_Axes->GetProperty()->SetLineWidth(3);
|
|
d->m_Axes->GetProperty()->SetAmbient(0.4);
|
|
d->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();
|
|
|
|
d->m_VtkAsm->AddPart(d->m_Cube);
|
|
d->m_VtkAsm->AddPart(d->m_Axes);
|
|
this->SetProp(d->m_VtkAsm);
|
|
|
|
// vtkProp3D* root = d->m_VtkAsm;
|
|
// if (root) {
|
|
// this->ApplyProp3DTransform(root);
|
|
// }
|
|
this->Update();
|
|
}
|
|
|
|
} // namespace Vtk
|
|
} // namespace uLib
|