/*////////////////////////////////////////////////////////////////////////////// // 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 #include "vtkContainerBox.h" #include #include #include #include #include #include #include #include #include #include #include "Vtk/Math/vtkDense.h" namespace uLib { namespace Vtk { struct ContainerBoxData { vtkSmartPointer m_Cube; vtkSmartPointer m_Axes; vtkSmartPointer m_VtkAsm; uLib::Connection m_UpdateSignal; ContainerBoxData() : m_Cube(vtkSmartPointer::New()), m_Axes(vtkSmartPointer::New()), m_VtkAsm(vtkSmartPointer::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 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 cube = vtkSmartPointer::New(); vtkSmartPointer mapper = vtkSmartPointer::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 axes = vtkSmartPointer::New(); axes->SetOrigin(0, 0, 0); mapper = vtkSmartPointer::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::New(); axes->SetOrigin(0, 0, 0); mapper = vtkSmartPointer::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