181 lines
5.9 KiB
C++
181 lines
5.9 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.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////*/
|
|
|
|
#ifndef ULIBVTKINTERFACE_H
|
|
#define ULIBVTKINTERFACE_H
|
|
|
|
#include <iomanip>
|
|
#include <ostream>
|
|
#include <vector>
|
|
#include "Core/Object.h"
|
|
#include "Core/Property.h"
|
|
|
|
// vtk classes forward declaration //
|
|
class vtkProp;
|
|
class vtkPolyData;
|
|
class vtkPropCollection;
|
|
class vtkRenderer;
|
|
class vtkRendererCollection;
|
|
class vtkRenderWindowInteractor;
|
|
|
|
namespace uLib {
|
|
namespace Archive { class display_properties_archive; }
|
|
namespace Vtk { class Puppet; class Viewer; }
|
|
}
|
|
|
|
namespace uLib {
|
|
namespace Vtk {
|
|
|
|
class Puppet : public uLib::Object {
|
|
uLibTypeMacro(Puppet, uLib::Object)
|
|
public:
|
|
Puppet();
|
|
virtual ~Puppet();
|
|
|
|
virtual vtkProp *GetProp();
|
|
|
|
virtual vtkPropCollection *GetParts();
|
|
|
|
virtual vtkPropCollection *GetProps();
|
|
|
|
void ConnectRenderer(vtkRenderer *renderer);
|
|
|
|
void DisconnectRenderer(vtkRenderer *renderer);
|
|
|
|
void ConnectViewer(Viewer *viewer);
|
|
|
|
void DisonnectViewer(Viewer *viewer);
|
|
|
|
void SetColor(double r, double g, double b);
|
|
|
|
void SetOpacity(double alpha);
|
|
|
|
void SetSelectable(bool selectable = true);
|
|
bool IsSelectable() const;
|
|
|
|
void SetSelected(bool selected = true);
|
|
bool IsSelected() const;
|
|
|
|
virtual void Update();
|
|
|
|
enum Representation { Points, Wireframe, Surface };
|
|
void SetRepresentation(Representation mode);
|
|
void SetRepresentation(const char *mode);
|
|
|
|
virtual void PrintSelf(std::ostream &o) const;
|
|
|
|
void ShowBoundingBox(bool show);
|
|
void ShowScaleMeasures(bool show);
|
|
|
|
vtkRendererCollection *GetRenderers() const;
|
|
|
|
virtual void serialize(Archive::xml_oarchive & ar, const unsigned int version) override;
|
|
virtual void serialize(Archive::xml_iarchive & ar, const unsigned int version) override;
|
|
virtual void serialize(Archive::text_oarchive & ar, const unsigned int version) override;
|
|
virtual void serialize(Archive::text_iarchive & ar, const unsigned int version) override;
|
|
virtual void serialize(Archive::hrt_oarchive & ar, const unsigned int version) override;
|
|
virtual void serialize(Archive::hrt_iarchive & ar, const unsigned int version) override;
|
|
virtual void serialize(Archive::log_archive & ar, const unsigned int version) override;
|
|
|
|
const std::vector<uLib::PropertyBase*>& GetDisplayProperties() const { return m_DisplayProperties; }
|
|
void RegisterDisplayProperty(uLib::PropertyBase* prop) { m_DisplayProperties.push_back(prop); }
|
|
|
|
virtual void serialize_display(uLib::Archive::display_properties_archive & ar, const unsigned int version = 0);
|
|
|
|
virtual void ConnectInteractor(class vtkRenderWindowInteractor *interactor);
|
|
|
|
protected:
|
|
void SetProp(vtkProp *prop);
|
|
|
|
void RemoveProp(vtkProp *prop);
|
|
|
|
std::vector<uLib::PropertyBase*> m_DisplayProperties;
|
|
|
|
private:
|
|
Puppet(const Puppet&) = delete;
|
|
Puppet& operator=(const Puppet&) = delete;
|
|
|
|
friend class PuppetData;
|
|
class PuppetData *d;
|
|
};
|
|
|
|
} // namespace Vtk
|
|
} // namespace uLib
|
|
|
|
// -------------------------------------------------------------------------- //
|
|
|
|
namespace uLib {
|
|
namespace Archive {
|
|
|
|
/**
|
|
* @brief Specialized archive for registering display-only properties in Puppets.
|
|
*/
|
|
class display_properties_archive : public boost::archive::detail::common_oarchive<display_properties_archive> {
|
|
public:
|
|
display_properties_archive(Vtk::Puppet* puppet) :
|
|
boost::archive::detail::common_oarchive<display_properties_archive>(boost::archive::no_header),
|
|
m_Puppet(puppet) {}
|
|
|
|
template<class T>
|
|
void save_override(const boost::serialization::hrp<T> &t) {
|
|
if (m_Puppet) {
|
|
m_Puppet->RegisterDisplayProperty(
|
|
new uLib::Property<T>(m_Puppet, t.name(), &const_cast<boost::serialization::hrp<T>&>(t).value())
|
|
);
|
|
}
|
|
}
|
|
|
|
template<class T> void save_override(const boost::serialization::nvp<T> &t) {
|
|
boost::archive::detail::common_oarchive<display_properties_archive>::save_override(t.const_value());
|
|
}
|
|
|
|
template<class T> void save_override(const T &t) {}
|
|
|
|
void save_override(const boost::archive::object_id_type & t) {}
|
|
void save_override(const boost::archive::object_reference_type & t) {}
|
|
void save_override(const boost::archive::version_type & t) {}
|
|
void save_override(const boost::archive::class_id_type & t) {}
|
|
void save_override(const boost::archive::class_id_optional_type & t) {}
|
|
void save_override(const boost::archive::class_id_reference_type & t) {}
|
|
void save_override(const boost::archive::class_name_type & t) {}
|
|
void save_override(const boost::archive::tracking_type & t) {}
|
|
|
|
private:
|
|
Vtk::Puppet* m_Puppet;
|
|
};
|
|
|
|
} // namespace Archive
|
|
|
|
// This macro MUST be defined after both Puppet and display_properties_archive are fully defined.
|
|
#define ULIB_ACTIVATE_DISPLAY_PROPERTIES \
|
|
{ \
|
|
uLib::Archive::display_properties_archive dar(this); \
|
|
this->serialize_display(dar, 0); \
|
|
}
|
|
|
|
} // namespace uLib
|
|
|
|
#endif // ULIBVTKINTERFACE_H
|