add assembly
This commit is contained in:
109
src/Math/Assembly.h
Normal file
109
src/Math/Assembly.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// 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 AffineTransform {
|
||||
public:
|
||||
virtual const char *GetClassName() const override { return "Assembly"; }
|
||||
|
||||
Assembly();
|
||||
Assembly(const Assembly ©);
|
||||
virtual ~Assembly();
|
||||
|
||||
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; // break signal recursion
|
||||
m_InUpdated = true;
|
||||
this->ComputeBoundingBox();
|
||||
ULIB_SIGNAL_EMIT(Assembly::Updated);
|
||||
m_InUpdated = false;
|
||||
}
|
||||
|
||||
private:
|
||||
Vector3f m_BBoxMin;
|
||||
Vector3f m_BBoxMax;
|
||||
bool m_ShowBoundingBox;
|
||||
bool m_GroupSelection;
|
||||
bool m_InUpdated = false;
|
||||
};
|
||||
|
||||
} // namespace uLib
|
||||
|
||||
#endif // U_ASSEMBLY_H
|
||||
Reference in New Issue
Block a user