123 lines
3.9 KiB
C++
123 lines
3.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 U_ASSEMBLY_H
|
|
#define U_ASSEMBLY_H
|
|
|
|
#include "Core/ObjectsContext.h"
|
|
#include "Math/ContainerBox.h"
|
|
#include "Math/Transform.h"
|
|
|
|
namespace uLib {
|
|
|
|
/**
|
|
* @brief Assembly groups geometric objects (ContainerBox, Cylinder, etc.)
|
|
* under a common transformation.
|
|
*
|
|
* Assembly derives from ObjectsContext so objects can be added/removed
|
|
* dynamically. It also inherits AffineTransform to provide a group-level
|
|
* transformation that is applied on top of each child's own transform.
|
|
*
|
|
* A bounding box is automatically computed from all contained objects and
|
|
* can be queried or shown/hidden through the VTK puppet.
|
|
*/
|
|
class Assembly : public ObjectsContext, public TRS {
|
|
public:
|
|
uLibTypeMacro(Assembly, ObjectsContext, TRS)
|
|
|
|
|
|
Assembly();
|
|
Assembly(const Assembly ©);
|
|
virtual ~Assembly();
|
|
|
|
template <class ArchiveT>
|
|
void serialize(ArchiveT & ar, const unsigned int version) {
|
|
ar & boost::serialization::make_nvp("TRS", boost::serialization::base_object<TRS>(*this));
|
|
ar & boost::serialization::make_hrp("GroupSelection", m_GroupSelection);
|
|
}
|
|
|
|
virtual void AddObject(Object* obj) override;
|
|
virtual void RemoveObject(Object* obj) override;
|
|
|
|
/**
|
|
* @brief Recomputes the axis-aligned bounding box enclosing all children.
|
|
* Stores the result internally.
|
|
*/
|
|
void ComputeBoundingBox();
|
|
|
|
/**
|
|
* @brief Returns the bounding box as min/max corners (in assembly-local
|
|
* coordinates).
|
|
*/
|
|
void GetBoundingBox(Vector3f &bbMin, Vector3f &bbMax) const;
|
|
|
|
/**
|
|
* @brief Returns the bounding box as a ContainerBox (positioned
|
|
* at bbMin, sized bbMax-bbMin, parented to this transform).
|
|
*/
|
|
ContainerBox GetBoundingBoxAsContainer() const;
|
|
|
|
/**
|
|
* @brief Controls whether the bounding box wireframe should be shown
|
|
* in the viewer (used by the VTK puppet).
|
|
*/
|
|
void SetShowBoundingBox(bool show);
|
|
bool GetShowBoundingBox() const;
|
|
|
|
/**
|
|
* @brief Controls selection behavior.
|
|
* If true (default), clicking any child within the assembly will select
|
|
* the assembly itself. If false, individual children can be picked.
|
|
*/
|
|
void SetGroupSelection(bool group);
|
|
bool GetGroupSelection() const;
|
|
|
|
signals:
|
|
virtual void Updated() override {
|
|
if (m_InUpdated) return;
|
|
m_InUpdated = true;
|
|
|
|
// Synchronize TRS part
|
|
this->TRS::Updated();
|
|
|
|
this->ComputeBoundingBox();
|
|
m_InUpdated = false;
|
|
}
|
|
|
|
private:
|
|
Vector3f m_BBoxMin;
|
|
Vector3f m_BBoxMax;
|
|
bool m_ShowBoundingBox;
|
|
bool m_GroupSelection;
|
|
bool m_InUpdated = false;
|
|
std::map<Object*, Connection> m_ChildConnections;
|
|
|
|
ULIB_DECLARE_PROPERTIES(Assembly)
|
|
};
|
|
|
|
} // namespace uLib
|
|
|
|
#endif // U_ASSEMBLY_H
|