diff --git a/code_fragments/entity/gfx_symmetry.py b/code_fragments/entity/gfx_symmetry.py index a0d795ece75923058688a6a3ebabc2c9a3f8012e..bfef9fb1b8ba5511e32e970fdd244e572b86aa7e 100644 --- a/code_fragments/entity/gfx_symmetry.py +++ b/code_fragments/entity/gfx_symmetry.py @@ -8,7 +8,7 @@ ent=io.LoadEntity(filename) edi=ent.RequestXCSEditor() m=geom.Mat4() -m.PasteTranslation(-ent.GetGeometricStart()) +m.PasteTranslation(-ent.bounds.min) edi.ApplyTransform(m) edi.UpdateICS() frag=gfx.Entity('frag', ent) diff --git a/demos/bbox.py b/demos/bbox.py index 1e4215f456887ce75341d2a2ac6ff8074dc6a054..242ba49b1b5b5bb6092728ef6a59a42154e6ad1f 100644 --- a/demos/bbox.py +++ b/demos/bbox.py @@ -10,8 +10,6 @@ def RenderBBox(bbox): bb.SetFillColor(gfx.Color(0.5, 0.8, 0.5, 0.2)) scene.Add(bb) -print 'Center:',(helix.GetGeometricStart()+helix.GetGeometricEnd())*.5 - RenderBBox(bbox) scene.center=go.center print 'Demo2: Translucent bounding box around an OpenStructure entity' diff --git a/modules/geom/pymod/export_composite3.cc b/modules/geom/pymod/export_composite3.cc index bf269d55258f21ba21a56c010654ae3a3ab9e47d..ed69d1ae49011918f196cce57ac6e22cc8f06955 100644 --- a/modules/geom/pymod/export_composite3.cc +++ b/modules/geom/pymod/export_composite3.cc @@ -161,6 +161,12 @@ scope PlaneScope = return_value_policy<copy_const_reference>()) .def("GetMax", &AlignedCuboid::GetMax, return_value_policy<copy_const_reference>()) + .def("GetCenter", &AlignedCuboid::GetCenter) + .add_property("max", make_function(&AlignedCuboid::GetMax, + return_value_policy<copy_const_reference>())) + .add_property("min", make_function(&AlignedCuboid::GetMin, + return_value_policy<copy_const_reference>())) + .add_property("center", &AlignedCuboid::GetCenter) ; } diff --git a/modules/geom/src/vec3.cc b/modules/geom/src/vec3.cc index 1e48f270c9417419adeb1096ca02acbc049d0740..e84c2b64a73f5bfe4a4d712028b1454127474f59 100644 --- a/modules/geom/src/vec3.cc +++ b/modules/geom/src/vec3.cc @@ -34,6 +34,12 @@ Vec3::Vec3(Real x, Real y, Real z) this->set(x,y,z); } +Vec3::Vec3(Real v) +{ + this->set(v, v, v); +} + + //#if OST_DOUBLE_PRECISION //Vec3::Vec3(float x, float y, float z) //{ diff --git a/modules/geom/src/vec3.hh b/modules/geom/src/vec3.hh index fecac337051c6b0f8fbe05eab6212ba6eef8fac8..1e534f1d100d4f3bca4b74ca87b21f36982acb5a 100644 --- a/modules/geom/src/vec3.hh +++ b/modules/geom/src/vec3.hh @@ -64,6 +64,8 @@ public: //! explicit initialization with an array of doubles explicit Vec3(const Real[3]); + explicit Vec3(Real v); + #if OST_DOUBLE_PRECISION //! explicit initialization with an array of floats explicit Vec3(const float[3]); diff --git a/modules/gui/src/scene_menu.cc b/modules/gui/src/scene_menu.cc index ceba5546acd05db0131eacfb4dc359d14216af6d..59706446935595833c11ecd2732556c3c855451e 100644 --- a/modules/gui/src/scene_menu.cc +++ b/modules/gui/src/scene_menu.cc @@ -102,20 +102,20 @@ void SceneMenu::CenterOnResidue() void SceneMenu::CenterOnChain() { mol::ChainHandle chain=picked_.second.GetResidue().GetChain(); - gfx::Scene::Instance().SetCenter(chain.GetGeometricCenter()); + gfx::Scene::Instance().SetCenter(chain.GetBounds().GetCenter()); } void SceneMenu::CenterOnView() { mol::ResidueHandle res=picked_.second.GetResidue(); - gfx::Scene::Instance().SetCenter(res.GetGeometricCenter()); + gfx::Scene::Instance().SetCenter(res.GetBounds().GetCenter()); } void SceneMenu::CenterOnSelection() { gfx::EntityP e=dyn_cast<gfx::Entity>(picked_.first); if (e->GetSelection() && e->GetSelection().GetAtomCount()>0) { - geom::Vec3 center=e->GetSelection().GetGeometricCenter(); + geom::Vec3 center=e->GetSelection().GetBounds().GetCenter(); gfx::Scene::Instance().SetCenter(center); } } diff --git a/modules/mol/base/pymod/bounds.hh b/modules/mol/base/pymod/bounds.hh new file mode 100644 index 0000000000000000000000000000000000000000..9182f67ee274e924e18ce2bd2538bcac55672c06 --- /dev/null +++ b/modules/mol/base/pymod/bounds.hh @@ -0,0 +1,36 @@ +#ifndef OST_MOL_EXPORT_BOUNDS_HH +#define OST_MOL_EXPORT_BOUNDS_HH + +#include <ost/log.hh> + +template <typename H> +geom::Vec3 geom_center(const H& h) +{ + return h.GetBounds().GetCenter(); +} + +template <typename H> +geom::Vec3 geom_size(const H& h) +{ + LOGN_MESSAGE("GetBoundarySize()/boundary_size is deprecated. Use bounds.size" + " instead") + return h.GetBounds().GetSize(); +} + +template <typename H> +geom::Vec3 geom_start(const H& h) +{ + LOGN_MESSAGE("GetGeometricStart()/geometric_start is deprecated. Use " + "bounds.min instead") + return h.GetBounds().GetMin(); +} + +template <typename H> +geom::Vec3 geom_end(const H& h) +{ + LOGN_MESSAGE("GetGeometricEnd()/geometric_end is deprecated. Use " + "bounds.max instead") + return h.GetBounds().GetMax(); +} + +#endif diff --git a/modules/mol/base/pymod/export_chain.cc b/modules/mol/base/pymod/export_chain.cc index a0c603fd799f3aea911aab9bba8bc661e405cb6d..1e2e59285e209914f56789b6545ab195bd8af489 100644 --- a/modules/mol/base/pymod/export_chain.cc +++ b/modules/mol/base/pymod/export_chain.cc @@ -25,6 +25,7 @@ using namespace boost::python; using namespace ost; using namespace ost::mol; #include <ost/export_helper/generic_property_def.hh> +#include "bounds.hh" namespace { typedef void (ChainHandle::*RnumMethod)(const ResNum&); @@ -83,15 +84,17 @@ void export_Chain() .def("GetMass", &ChainHandle::GetMass) .def("GetCenterOfMass", &ChainHandle::GetCenterOfMass) .def("GetCenterOfAtoms", &ChainHandle::GetCenterOfAtoms) - .def("GetGeometricCenter", &ChainHandle::GetGeometricCenter) - .add_property("geometric_center", &ChainHandle::GetGeometricCenter) + .def("GetGeometricCenter", geom_center<ChainHandle>) + .add_property("geometric_center", geom_center<ChainHandle>) .add_property("mass", &ChainHandle::GetMass) .add_property("center_of_mass", &ChainHandle::GetCenterOfMass) .add_property("center_of_atoms", &ChainHandle::GetCenterOfAtoms) .add_property("in_sequence", &ChainHandle::InSequence) .add_property("valid", &ChainHandle::IsValid) - .def("GetGeometricStart", &ChainHandle::GetGeometricStart) - .def("GetGeometricEnd", &ChainHandle::GetGeometricEnd) + .def("GetBounds", &ChainHandle::GetBounds) + .add_property("bounds", &ChainHandle::GetBounds) + .def("GetGeometricStart", geom_start<ChainHandle>) + .def("GetGeometricEnd", geom_end<ChainHandle>) ; class_<ChainHandleList>("ChainHandleList", no_init) diff --git a/modules/mol/base/pymod/export_chain_view.cc b/modules/mol/base/pymod/export_chain_view.cc index ee6753b52d420cf3ae5ef360425a5390132cd464..471b592a13421b259427e56a8d0ce4939f45bed1 100644 --- a/modules/mol/base/pymod/export_chain_view.cc +++ b/modules/mol/base/pymod/export_chain_view.cc @@ -27,6 +27,7 @@ using namespace boost::python; #include <ost/export_helper/vector.hh> using namespace ost; using namespace ost::mol; +#include "bounds.hh" namespace { typedef ResidueView (ChainView::*RnumMethod)(const ResNum&) const; @@ -92,15 +93,17 @@ void export_ChainView() .def("GetMass", &ChainView::GetMass) .def("GetCenterOfMass", &ChainView::GetCenterOfMass) .def("GetCenterOfAtoms", &ChainView::GetCenterOfAtoms) - .def("GetGeometricCenter", &ChainView::GetGeometricCenter) - .add_property("geometric_center", &ChainView::GetGeometricCenter) + .def("GetGeometricCenter", geom_center<ChainView>) + .add_property("geometric_center", geom_center<ChainView>) .add_property("mass", &ChainView::GetMass) .add_property("center_of_mass", &ChainView::GetCenterOfMass) .add_property("center_of_atoms", &ChainView::GetCenterOfAtoms) .add_property("valid", &ChainView::IsValid) .add_property("in_sequence", &ChainView::InSequence) - .def("GetGeometricStart", &ChainView::GetGeometricStart) - .def("GetGeometricEnd", &ChainView::GetGeometricEnd) + .def("GetGeometricStart", geom_start<ChainView>) + .def("GetGeometricEnd", geom_end<ChainView>) + .def("GetBounds", &ChainView::GetBounds) + .add_property("bounds", &ChainView::GetBounds) ; diff --git a/modules/mol/base/pymod/export_entity.cc b/modules/mol/base/pymod/export_entity.cc index a8fa1c8d86ff6990c1e4ae838c0c24915e3dc0c2..b0df16c0c9065f8084127b48a1055cd29090d849 100644 --- a/modules/mol/base/pymod/export_entity.cc +++ b/modules/mol/base/pymod/export_entity.cc @@ -23,7 +23,7 @@ using namespace boost::python; #include <ost/mol/entity_view.hh> #include <ost/mol/query.hh> #include <ost/mol/mol.hh> - +#include "bounds.hh" using namespace ost; using namespace ost::mol; @@ -55,6 +55,7 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_xcs_editor_overloads, BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_ics_editor_overloads, EntityHandle::RequestICSEditor, 0, 1) + } void export_Entity() @@ -81,11 +82,13 @@ void export_Entity() .def("GetMass", &EntityHandle::GetMass) .def("GetCenterOfMass", &EntityHandle::GetCenterOfMass) .def("GetCenterOfAtoms", &EntityHandle::GetCenterOfAtoms) - .def("GetGeometricCenter", &EntityHandle::GetGeometricCenter) - .add_property("geometric_center", &EntityHandle::GetGeometricCenter) - .def("GetGeometricStart", &EntityHandle::GetGeometricStart) - .def("GetGeometricEnd", &EntityHandle::GetGeometricEnd) - .def("GetBoundarySize", &EntityHandle::GetBoundarySize) + .def("GetGeometricCenter", geom_center<EntityHandle>) + .add_property("geometric_center", geom_center<EntityHandle>) + .add_property("geometric_end", geom_end<EntityHandle>) + .add_property("geometric_start", geom_start<EntityHandle>) + .def("GetGeometricStart", geom_start<EntityHandle>) + .def("GetGeometricEnd", geom_end<EntityHandle>) + .def("GetBoundarySize", geom_size<EntityHandle>) .def("GetResidueCount", &EntityHandle::GetResidueCount) .def("GetAtomCount", &EntityHandle::GetAtomCount) .def("GetBondCount", &EntityHandle::GetBondCount) @@ -111,6 +114,8 @@ void export_Entity() .add_property("chains", &EntityHandle::GetChainList) .add_property("bonds", &EntityHandle::GetBondList) .add_property("valid", &EntityHandle::IsValid) + .def("GetBounds", &EntityHandle::GetBounds) + .add_property("bounds", &EntityHandle::GetBounds) .def("GetTransformationMatrix", &EntityHandle::GetTransformationMatrix, return_value_policy<copy_const_reference>()) .add_property("transform", diff --git a/modules/mol/base/pymod/export_entity_view.cc b/modules/mol/base/pymod/export_entity_view.cc index aaa75efb730ad624934bb3d1c1cf510bf6fa915e..3b3eadab25854ee278194bd82119bfb2861e291e 100644 --- a/modules/mol/base/pymod/export_entity_view.cc +++ b/modules/mol/base/pymod/export_entity_view.cc @@ -26,6 +26,7 @@ using namespace boost::python; #include <ost/mol/view_op.hh> using namespace ost; using namespace ost::mol; +#include "bounds.hh" namespace { @@ -90,10 +91,10 @@ void export_EntityView() .def("FindAtom", find_atom_a) .def("FindAtom", find_atom_b) .def("GetAtomCount", &EntityView::GetAtomCount) - .def("GetGeometricStart", &EntityView::GetGeometricStart) - .def("GetGeometricEnd", &EntityView::GetGeometricEnd) - .def("GetGeometricCenter", &EntityView::GetGeometricCenter) - .add_property("geometric_center", &EntityView::GetGeometricCenter) + .def("GetGeometricStart", geom_start<EntityView>) + .def("GetGeometricEnd", geom_end<EntityView>) + .def("GetGeometricCenter", geom_center<EntityView>) + .add_property("geometric_center", geom_center<EntityView>) .def("GetCenterOfMass", &EntityView::GetCenterOfMass) .def("GetCenterOfAtoms", &EntityView::GetCenterOfAtoms) .def("GetMass", &EntityView::GetMass) @@ -153,6 +154,8 @@ void export_EntityView() .def(self==self) .def(self!=self) .def("Dump", &EntityView::Dump) + .def("GetBounds", &EntityView::GetBounds) + .add_property("bounds", &EntityView::GetBounds) ; def("Union", &Union); def("Difference", &Difference); diff --git a/modules/mol/base/pymod/export_residue.cc b/modules/mol/base/pymod/export_residue.cc index 532f4b0a2b2d3e23a79ea73f8c59d130ab15685a..ef844831cb222c399cf5a4405803be9224c2c48e 100644 --- a/modules/mol/base/pymod/export_residue.cc +++ b/modules/mol/base/pymod/export_residue.cc @@ -27,7 +27,7 @@ using namespace ost; using namespace ost::mol; #include <ost/export_helper/generic_property_def.hh> - +#include "bounds.hh" namespace { @@ -165,20 +165,22 @@ void export_Residue() .def("GetMass", &ResidueHandle::GetMass) .def("GetCenterOfMass", &ResidueHandle::GetCenterOfMass) .def("GetCenterOfAtoms", &ResidueHandle::GetCenterOfAtoms) - .def("GetGeometricCenter", &ResidueHandle::GetGeometricCenter) + .def("GetGeometricCenter", geom_center<ResidueHandle>) .add_property("mass", &ResidueHandle::GetMass) .add_property("center_of_mass", &ResidueHandle::GetCenterOfMass) .add_property("center_of_atoms", &ResidueHandle::GetCenterOfAtoms) - .add_property("geometric_center", &ResidueHandle::GetGeometricCenter) + .add_property("geometric_center", geom_center<ResidueHandle>) .add_property("phi_torsion", &ResidueHandle::GetPhiTorsion) .add_property("psi_torsion", &ResidueHandle::GetPsiTorsion) .add_property("omega_torsion", &ResidueHandle::GetOmegaTorsion) .add_property("valid", &ResidueHandle::IsValid) - .def("GetGeometricStart", &ResidueHandle::GetGeometricStart) - .def("GetGeometricEnd", &ResidueHandle::GetGeometricEnd) + .def("GetGeometricStart", geom_start<ResidueHandle>) + .def("GetGeometricEnd", geom_end<ResidueHandle>) .def(self==self) .def(self!=self) .def("__hash__", &ResidueHandle::GetHashCode) + .def("GetBounds", &ResidueHandle::GetBounds) + .add_property("bounds", &ResidueHandle::GetBounds) ; class_<ResidueHandleList>("ResidueHandleList", no_init) diff --git a/modules/mol/base/pymod/export_residue_view.cc b/modules/mol/base/pymod/export_residue_view.cc index 63bd1c746a19ad3135852649cc25eebf6c7f9725..f8dbd089628879641e24731629afe92a108e4403 100644 --- a/modules/mol/base/pymod/export_residue_view.cc +++ b/modules/mol/base/pymod/export_residue_view.cc @@ -25,6 +25,7 @@ using namespace boost::python; #include <ost/export_helper/vector.hh> using namespace ost; using namespace ost::mol; +#include "bounds.hh" namespace { typedef AtomView (ResidueView::*StringMethod)(const String&) const; @@ -79,14 +80,16 @@ void export_ResidueView() .def("GetMass", &ResidueView::GetMass) .def("GetCenterOfMass", &ResidueView::GetCenterOfMass) .def("GetCenterOfAtoms", &ResidueView::GetCenterOfAtoms) - .def("GetGeometricCenter", &ResidueView::GetGeometricCenter) + .def("GetGeometricCenter", geom_center<ResidueView>) .add_property("mass", &ResidueView::GetMass) .add_property("center_of_mass", &ResidueView::GetCenterOfMass) .add_property("center_of_atoms", &ResidueView::GetCenterOfAtoms) - .add_property("geometric_center", &ResidueView::GetGeometricCenter) + .add_property("geometric_center", geom_center<ResidueView>) .add_property("valid", &ResidueView::IsValid) - .def("GetGeometricStart", &ResidueView::GetGeometricStart) - .def("GetGeometricEnd", &ResidueView::GetGeometricEnd) + .def("GetGeometricStart", geom_start<ResidueView>) + .def("GetGeometricEnd", geom_end<ResidueView>) + .def("GetBounds", &ResidueView::GetBounds) + .add_property("bounds", &ResidueView::GetBounds) ; diff --git a/modules/mol/base/src/bounding_box.cc b/modules/mol/base/src/bounding_box.cc index 8fd6a49d80e043d7a82618b54a6ec58603dddbf0..15473b5def7f392e90962d048e1a2bde18e35a74 100644 --- a/modules/mol/base/src/bounding_box.cc +++ b/modules/mol/base/src/bounding_box.cc @@ -36,7 +36,7 @@ public: PrincipalAxisCalc(const EntityHandle& ent): natoms_(ent.GetAtomCount()) { - mean_=ent.GetGeometricCenter(); + mean_=ent.GetBounds().GetCenter(); cov_.setZero(); } PrincipalAxisCalc(const AtomHandleList& atoms): @@ -55,7 +55,7 @@ public: PrincipalAxisCalc(const EntityView& ent): natoms_(ent.GetAtomCount()) { - mean_=ent.GetGeometricCenter(); + mean_=ent.GetBounds().GetCenter(); cov_.setZero(); } virtual bool VisitAtom(const AtomHandle& atom) diff --git a/modules/mol/base/src/chain_handle.cc b/modules/mol/base/src/chain_handle.cc index 842017ae4ba00bee32ec4238239f211a39786f90..1f0e8094c10c8f95f5e6e71d48fb675f9ee63091 100644 --- a/modules/mol/base/src/chain_handle.cc +++ b/modules/mol/base/src/chain_handle.cc @@ -197,22 +197,10 @@ void ChainHandle::AssignSecondaryStructure(SecStructure ss, Impl()->AssignSecondaryStructure(ss, start, end); } -geom::Vec3 ChainHandle::GetGeometricCenter() const +geom::AlignedCuboid ChainHandle::GetBounds() const { this->CheckValidity(); - return Impl()->GetGeometricCenter(); -} - -geom::Vec3 ChainHandle::GetGeometricStart() const -{ - this->CheckValidity(); - return Impl()->GetGeometricStart(); -} - -geom::Vec3 ChainHandle::GetGeometricEnd() const -{ - this->CheckValidity(); - return Impl()->GetGeometricEnd(); + return Impl()->GetBounds(); } geom::Vec3 ChainHandle::GetCenterOfMass() const diff --git a/modules/mol/base/src/chain_handle.hh b/modules/mol/base/src/chain_handle.hh index 0faa7ee8fc2f691b3acc86d539300b93ca211843..6337818deeebc8356c1a08421173edc39da076ee 100644 --- a/modules/mol/base/src/chain_handle.hh +++ b/modules/mol/base/src/chain_handle.hh @@ -166,18 +166,7 @@ public: /// similar to GetCenterOfMass(), but the atoms are not mass weighted geom::Vec3 GetCenterOfAtoms() const; - /// \brief Get entity's geometric center - /// - /// Returns the geometric center of the entity's bounding box - /// by calculating (GetGeometricStart()+GetGeometricEnd())/2 - geom::Vec3 GetGeometricCenter() const; - - /// \brief Get entity's minimum cartesian coordinates - geom::Vec3 GetGeometricStart() const; - - /// \brief Get entity's maximum cartesian coordinates - geom::Vec3 GetGeometricEnd() const; - + geom::AlignedCuboid GetBounds() const; /// \brief assign secondary structure to the inclusive residue range /// start, end void AssignSecondaryStructure(SecStructure ss, diff --git a/modules/mol/base/src/chain_view.cc b/modules/mol/base/src/chain_view.cc index fac143b8527ef1c880c615f9fc5ff47808516fb9..1c5ba252e6c3d526ac711bb99f8031d860bda5e5 100644 --- a/modules/mol/base/src/chain_view.cc +++ b/modules/mol/base/src/chain_view.cc @@ -327,44 +327,29 @@ Real ChainView::GetMass() const { return mass; } -geom::Vec3 ChainView::GetGeometricStart() const +geom::AlignedCuboid ChainView::GetBounds() const { this->CheckValidity(); - geom::Vec3 minimum(std::numeric_limits<Real>::max(), - std::numeric_limits<Real>::max(), - std::numeric_limits<Real>::max()); - ResidueViewList::const_iterator i; - for (i=data_->residues.begin(); i!=data_->residues.end(); ++i) { - ResidueView r=*i; - for (AtomViewList::const_iterator j=r.GetAtomList().begin(), - e2=r.GetAtomList().end(); j!=e2; ++j) { - minimum=geom::Min(minimum, j->GetPos()); - } - } - return minimum; -} + geom::Vec3 mmin( std::numeric_limits<Real>::max()); + geom::Vec3 mmax(-std::numeric_limits<Real>::max()); -geom::Vec3 ChainView::GetGeometricEnd() const -{ - this->CheckValidity(); - geom::Vec3 maximum(-std::numeric_limits<Real>::max(), - -std::numeric_limits<Real>::max(), - -std::numeric_limits<Real>::max()); - ResidueViewList::const_iterator i; - for (i=data_->residues.begin(); i!=data_->residues.end(); ++i) { + + bool atoms=false; + for (ResidueViewList::const_iterator + i=data_->residues.begin(); i!=data_->residues.end(); ++i) { ResidueView r=*i; for (AtomViewList::const_iterator j=r.GetAtomList().begin(), e2=r.GetAtomList().end(); j!=e2; ++j) { - maximum=geom::Max(maximum, j->GetPos()); + mmin=geom::Min(mmin, j->GetPos()); + mmax=geom::Max(mmax, j->GetPos()); + atoms=true; } } - return maximum; -} - -geom::Vec3 ChainView::GetGeometricCenter() const -{ - this->CheckValidity(); - return (this->GetGeometricStart() + this->GetGeometricEnd())/2; + if (atoms) { + return geom::AlignedCuboid(mmin, mmax); + } else { + return geom::AlignedCuboid(geom::Vec3(), geom::Vec3()); + } } geom::Vec3 ChainView::GetCenterOfAtoms() const diff --git a/modules/mol/base/src/chain_view.hh b/modules/mol/base/src/chain_view.hh index 3be942a5648cbb4f51a5a909e577a1e255c1d4e4..800d1fc82434898e2cd1bd436e8df4dfb1f5be8b 100644 --- a/modules/mol/base/src/chain_view.hh +++ b/modules/mol/base/src/chain_view.hh @@ -143,14 +143,8 @@ public: /// similar to GetCenterOfMass(), but the atoms are not mass weighted geom::Vec3 GetCenterOfAtoms() const; - /// \brief Get entity's geometric center - /// - /// Returns the geometric center of the entity's bounding box - /// by calculating (GetGeometricStart()+GetGeometricEnd())/2 - geom::Vec3 GetGeometricCenter() const; - - geom::Vec3 GetGeometricStart() const; - geom::Vec3 GetGeometricEnd() const; + /// \brief Get entity's axis aligned bounding box + geom::AlignedCuboid GetBounds() const; /// /// \brief remove all residues from the view void RemoveResidues(); diff --git a/modules/mol/base/src/entity_handle.cc b/modules/mol/base/src/entity_handle.cc index b7fad67139096c0e07aa5323cb0fcf1929870b72..17c47cd81112c92ef308c598cf7c03202a1c6648 100644 --- a/modules/mol/base/src/entity_handle.cc +++ b/modules/mol/base/src/entity_handle.cc @@ -55,25 +55,12 @@ geom::Vec3 EntityHandle::GetCenterOfAtoms() const { return Impl()->GetCenterOfAtoms(); } -geom::Vec3 EntityHandle::GetGeometricCenter() const { - this->CheckValidity(); - return Impl()->GetGeometricCenter(); -} - -geom::Vec3 EntityHandle::GetGeometricStart() const { - this->CheckValidity(); - return Impl()->GetGeometricStart(); -} - -geom::Vec3 EntityHandle::GetGeometricEnd() const { +geom::AlignedCuboid EntityHandle::GetBounds() const +{ this->CheckValidity(); - return Impl()->GetGeometricEnd(); + return Impl()->GetBounds(); } -geom::Vec3 EntityHandle::GetBoundarySize() const { - this->CheckValidity(); - return Impl()->GetBoundarySize(); -} EntityHandle::EntityHandle(const impl::EntityImplPtr& e) : EntityBase(e) diff --git a/modules/mol/base/src/entity_handle.hh b/modules/mol/base/src/entity_handle.hh index 9bb291d8ea21cd21907ee65ec4d20b09ed1d99e7..540425c70219e49396c29ce19ef54850712edd70 100644 --- a/modules/mol/base/src/entity_handle.hh +++ b/modules/mol/base/src/entity_handle.hh @@ -84,20 +84,8 @@ public: /// \brief Get entity's center of mass (mass weighted) geom::Vec3 GetCenterOfMass() const; - /// \brief Get entity's geometric center - /// - /// Returns the geometric center of the entity's bounding box - /// by calculating (GetGeometricStart()+GetGeometricEnd())/2 - geom::Vec3 GetGeometricCenter() const; - - /// \brief Get entity's minimum cartesian coordinates - geom::Vec3 GetGeometricStart() const; - - /// \brief Get entity's maximum cartesian coordinates - geom::Vec3 GetGeometricEnd() const; - /// \brief Get size of the entity - geom::Vec3 GetBoundarySize() const; + geom::AlignedCuboid GetBounds() const; //@} /// \brief diff --git a/modules/mol/base/src/entity_view.cc b/modules/mol/base/src/entity_view.cc index b6c5deabc1defba0b2c8cf3976b449fd53d0ff4c..6be3145f35ac93cdfe8c4432a6978098b395aa42 100644 --- a/modules/mol/base/src/entity_view.cc +++ b/modules/mol/base/src/entity_view.cc @@ -171,13 +171,6 @@ geom::Vec3 EntityView::GetCenterOfAtoms() const return center; } -geom::Vec3 EntityView::GetGeometricCenter() const -{ - geom::Vec3 center; - center = (this->GetGeometricEnd() + this->GetGeometricStart())/2; - return center; -} - geom::Vec3 EntityView::GetCenterOfMass() const { geom::Vec3 center; @@ -726,17 +719,6 @@ AtomView EntityView::FindXAtom(const AtomHandle& ah) } #endif -geom::Vec3 EntityView::GetGeometricStart() const -{ - this->CheckValidity(); - geom::Vec3 m(std::numeric_limits<Real>::max(), - std::numeric_limits<Real>::max(), - std::numeric_limits<Real>::max()); - for(AtomViewIter it=AtomsBegin(); it!=this->AtomsEnd(); ++it) { - m=geom::Min(m, (*it).GetPos()); - } - return m; -} AtomView EntityView::FindAtom(const String& chain_name, const ResNum& num, @@ -749,16 +731,20 @@ AtomView EntityView::FindAtom(const String& chain_name, } return AtomView(); } -geom::Vec3 EntityView::GetGeometricEnd() const +geom::AlignedCuboid EntityView::GetBounds() const { this->CheckValidity(); - geom::Vec3 m(-std::numeric_limits<Real>::max(), - -std::numeric_limits<Real>::max(), - -std::numeric_limits<Real>::max()); - for(AtomViewIter it=AtomsBegin(); it!=this->AtomsEnd(); ++it) { - m=geom::Max(m, (*it).GetPos()); + geom::Vec3 mmin( std::numeric_limits<Real>::max()); + geom::Vec3 mmax(-std::numeric_limits<Real>::max()); + if (this->GetAtomCount()) { + for(AtomViewIter it=AtomsBegin(); it!=this->AtomsEnd(); ++it) { + mmax=geom::Max(mmax, (*it).GetPos()); + mmin=geom::Min(mmin, (*it).GetPos()); + } + return geom::AlignedCuboid(mmin, mmax); + } else { + return geom::AlignedCuboid(geom::Vec3(), geom::Vec3()); } - return m; } diff --git a/modules/mol/base/src/entity_view.hh b/modules/mol/base/src/entity_view.hh index e55894da5fa97e37911942c0151abd01f8ce2eab..6e3aa7bf8b07f102436f172e0ce1ff2ce618c724 100644 --- a/modules/mol/base/src/entity_view.hh +++ b/modules/mol/base/src/entity_view.hh @@ -108,14 +108,8 @@ public: /// similar to GetCenterOfMass(), but the atoms are not mass weighted geom::Vec3 GetCenterOfAtoms() const; - /// \brief Get entity's geometric center - /// - /// Returns the geometric center of the entity's bounding box - /// by calculating (GetGeometricStart()+GetGeometricEnd())/2 - geom::Vec3 GetGeometricCenter() const; - - geom::Vec3 GetGeometricStart() const; - geom::Vec3 GetGeometricEnd() const; + geom::AlignedCuboid GetBounds() const; + public: /// \name Internal //@{ diff --git a/modules/mol/base/src/impl/chain_impl.cc b/modules/mol/base/src/impl/chain_impl.cc index 02f4636c1cc5e60865ad92b5e7ddcd3901a23ed0..8b9d74876df5e0ad9e98f7fdcfd3dfc327efd49a 100644 --- a/modules/mol/base/src/impl/chain_impl.cc +++ b/modules/mol/base/src/impl/chain_impl.cc @@ -363,41 +363,27 @@ Real ChainImpl::GetMass() const return mass; } -geom::Vec3 ChainImpl::GetGeometricStart() const +geom::AlignedCuboid ChainImpl::GetBounds() const { - geom::Vec3 minimum(std::numeric_limits<Real>::infinity(), - std::numeric_limits<Real>::infinity(), - std::numeric_limits<Real>::infinity()); + geom::Vec3 mmin( std::numeric_limits<Real>::infinity()); + geom::Vec3 mmax(-std::numeric_limits<Real>::infinity()); + bool atoms=false; for (ResidueImplList::const_iterator i=residue_list_.begin(); i!=residue_list_.end(); ++i) { ResidueImplPtr r=*i; for (AtomImplList::iterator j=r->GetAtomList().begin(); j!=r->GetAtomList().end(); ++j) { - minimum=geom::Min(minimum,(*j)->GetPos()); + mmin=geom::Min(mmin, (*j)->GetPos()); + mmax=geom::Max(mmax, (*j)->GetPos()); + atoms=true; } } - return minimum; -} - -geom::Vec3 ChainImpl::GetGeometricEnd() const { - geom::Vec3 maximum(-std::numeric_limits<Real>::infinity(), - -std::numeric_limits<Real>::infinity(), - -std::numeric_limits<Real>::infinity()); - for (ResidueImplList::const_iterator i=residue_list_.begin(); - i!=residue_list_.end(); ++i) { - ResidueImplPtr r=*i; - for (AtomImplList::iterator j=r->GetAtomList().begin(); - j!=r->GetAtomList().end(); ++j) { - maximum=geom::Max(maximum,(*j)->GetPos()); - } + if (!atoms) { + return geom::AlignedCuboid(geom::Vec3(), geom::Vec3()); } - return maximum; + return geom::AlignedCuboid(mmin, mmax); } -geom::Vec3 ChainImpl::GetGeometricCenter() const -{ - return (this->GetGeometricStart() + this->GetGeometricEnd()) / 2; -} geom::Vec3 ChainImpl::GetCenterOfAtoms() const { diff --git a/modules/mol/base/src/impl/chain_impl.hh b/modules/mol/base/src/impl/chain_impl.hh index 644bed1e734d8594620164051c80060eb1a33295..1737ca4f587a76e52d99617809cd3e148f8598d5 100644 --- a/modules/mol/base/src/impl/chain_impl.hh +++ b/modules/mol/base/src/impl/chain_impl.hh @@ -81,9 +81,10 @@ public: Real GetMass() const; geom::Vec3 GetCenterOfMass() const; geom::Vec3 GetCenterOfAtoms() const; - geom::Vec3 GetGeometricCenter() const; - geom::Vec3 GetGeometricStart() const; - geom::Vec3 GetGeometricEnd() const; + + /// \brief returns the axis-aligned bounding box of the entity + geom::AlignedCuboid GetBounds() const; + ///\brief Get residue by number. Returns a invalid pointer if the chain /// does not have any residue with this number. diff --git a/modules/mol/base/src/impl/entity_impl.cc b/modules/mol/base/src/impl/entity_impl.cc index e717342227cc929559b261a672fed9ea26b181f4..8d17d4a133d641a88afb3cd81a5722223105eb9a 100644 --- a/modules/mol/base/src/impl/entity_impl.cc +++ b/modules/mol/base/src/impl/entity_impl.cc @@ -262,60 +262,29 @@ EntityImpl::~EntityImpl() it->second->OnDestroy(); } } - -geom::Vec3 EntityImpl::GetGeometricStart() const +geom::AlignedCuboid EntityImpl::GetBounds() const { - geom::Vec3 minimum(std::numeric_limits<Real>::infinity(), - std::numeric_limits<Real>::infinity(), - std::numeric_limits<Real>::infinity()); - if (this->GetAtomCount()>0) { - for(AtomImplMap::const_iterator it = atom_map_.begin();it!=atom_map_.end();++it) { - minimum=geom::Min(minimum,it->second->GetPos()); - } - } - return minimum; -} - -geom::Vec3 EntityImpl::GetGeometricEnd() const { - geom::Vec3 maximum(-std::numeric_limits<Real>::infinity(), - -std::numeric_limits<Real>::infinity(), - -std::numeric_limits<Real>::infinity()); - if (this->GetAtomCount()>0) { - for(AtomImplMap::const_iterator it = atom_map_.begin();it!=atom_map_.end();++it) { - maximum=geom::Max(maximum,it->second->GetPos()); - } - } - return maximum; -} -geom::Vec3 EntityImpl::GetBoundarySize() const { - geom::Vec3 size; - geom::Vec3 minimum(std::numeric_limits<Real>::infinity(), - std::numeric_limits<Real>::infinity(), - std::numeric_limits<Real>::infinity()); - geom::Vec3 maximum(-std::numeric_limits<Real>::infinity(), - -std::numeric_limits<Real>::infinity(), - -std::numeric_limits<Real>::infinity()); if (this->GetAtomCount()>0) { - for(AtomImplMap::const_iterator it = atom_map_.begin();it!=atom_map_.end();++it) { - minimum=geom::Min(minimum,it->second->GetPos()); - maximum=geom::Max(maximum,it->second->GetPos()); + geom::Vec3 mmin, mmax; + AtomImplMap::const_iterator it=atom_map_.begin(); + mmin=mmax=it->second->GetPos(); + for (++it; it!=atom_map_.end();++it) { + mmin=geom::Min(mmin,it->second->GetPos()); + mmax=geom::Min(mmax,it->second->GetPos()); } + return geom::AlignedCuboid(mmin, mmax); + } else { + return geom::AlignedCuboid(geom::Vec3(), geom::Vec3()); } - size=maximum-minimum; - return size; -} -geom::Vec3 EntityImpl::GetGeometricCenter() const { - geom::Vec3 center; - center = (this->GetGeometricEnd() + this->GetGeometricStart())/2; - return center; } geom::Vec3 EntityImpl::GetCenterOfAtoms() const { geom::Vec3 center; if (this->GetAtomCount()>0) { - for(AtomImplMap::const_iterator it = atom_map_.begin();it!=atom_map_.end();++it) { + for (AtomImplMap::const_iterator it = atom_map_.begin(); + it!=atom_map_.end();++it) { center+=it->second->GetPos(); } center/=static_cast<Real>(atom_map_.size()); diff --git a/modules/mol/base/src/impl/entity_impl.hh b/modules/mol/base/src/impl/entity_impl.hh index ca83cf254b3b0c6c8315260a719261105c488a1f..ae1208f5e4bb70b8f603055fb7f0d98299e70d9c 100644 --- a/modules/mol/base/src/impl/entity_impl.hh +++ b/modules/mol/base/src/impl/entity_impl.hh @@ -93,10 +93,11 @@ public: Real GetMass() const; geom::Vec3 GetCenterOfMass() const; geom::Vec3 GetCenterOfAtoms() const; - geom::Vec3 GetGeometricCenter() const; - geom::Vec3 GetGeometricStart() const; - geom::Vec3 GetGeometricEnd() const; - geom::Vec3 GetBoundarySize() const; + + /// \brief returns the axis-aligned bounding box of the entity + geom::AlignedCuboid GetBounds() const; + + // default copy ctor and assignment op should work for now AtomImplPtr CreateAtom(const ResidueImplPtr& rp, const String& name, diff --git a/modules/mol/base/src/impl/residue_impl.cc b/modules/mol/base/src/impl/residue_impl.cc index bfee304770bcb5ec53443cda276127dc1458b074..225c5a974ba2768ddb6fadea26d7d2876a9f44a8 100644 --- a/modules/mol/base/src/impl/residue_impl.cc +++ b/modules/mol/base/src/impl/residue_impl.cc @@ -427,31 +427,23 @@ Real ResidueImpl::GetMass() const return mass; } -geom::Vec3 ResidueImpl::GetGeometricEnd() const { - geom::Vec3 maximum(-std::numeric_limits<Real>::infinity(), - -std::numeric_limits<Real>::infinity(), - -std::numeric_limits<Real>::infinity()); - for (AtomImplList::const_iterator i=atom_list_.begin(); - i!=atom_list_.end(); ++i) { - maximum=geom::Max(maximum,(*i)->GetPos()); - } - return maximum; -} - -geom::Vec3 ResidueImpl::GetGeometricStart() const { - geom::Vec3 minimum(std::numeric_limits<Real>::infinity(), - std::numeric_limits<Real>::infinity(), - std::numeric_limits<Real>::infinity()); - for (AtomImplList::const_iterator i=atom_list_.begin(); - i!=atom_list_.end(); ++i) { - minimum=geom::Min(minimum,(*i)->GetPos()); - } - return minimum; -} - -geom::Vec3 ResidueImpl::GetGeometricCenter() const +geom::AlignedCuboid ResidueImpl::GetBounds() const { - return (this->GetGeometricStart() + this->GetGeometricEnd())/2; + + geom::Vec3 mmin( std::numeric_limits<Real>::infinity()); + geom::Vec3 mmax(-std::numeric_limits<Real>::infinity()); + + if (atom_list_.size()>0) { + AtomImplList::const_iterator i=atom_list_.begin(); + mmin=mmax=(*i)->GetPos(); + for (++i; i!=atom_list_.end(); ++i) { + mmax=geom::Max(mmax,(*i)->GetPos()); + mmin=geom::Min(mmin,(*i)->GetPos()); + } + return geom::AlignedCuboid(mmin, mmax); + } else { + return geom::AlignedCuboid(geom::Vec3(), geom::Vec3()); + } } geom::Vec3 ResidueImpl::GetCenterOfAtoms() const diff --git a/modules/mol/base/src/impl/residue_impl.hh b/modules/mol/base/src/impl/residue_impl.hh index 22e816b6e851d79f2c4f56dedaddf23ae7cd4fef..0e03937674307b4b3b625c417bb86fa2046320c9 100644 --- a/modules/mol/base/src/impl/residue_impl.hh +++ b/modules/mol/base/src/impl/residue_impl.hh @@ -131,9 +131,9 @@ public: Real GetMass() const; geom::Vec3 GetCenterOfMass() const; geom::Vec3 GetCenterOfAtoms() const; - geom::Vec3 GetGeometricCenter() const; - geom::Vec3 GetGeometricStart() const; - geom::Vec3 GetGeometricEnd() const; + + geom::AlignedCuboid GetBounds() const; + void DeleteAtom(const AtomImplPtr& atom); void DeleteAtoms(const String& atom_name); diff --git a/modules/mol/base/src/residue_handle.cc b/modules/mol/base/src/residue_handle.cc index 1719708c9a0e52b9a6892bfc9b8b3560150547d0..6c9e007d80a2d52ea1f69a981f81e5416adf283c 100644 --- a/modules/mol/base/src/residue_handle.cc +++ b/modules/mol/base/src/residue_handle.cc @@ -226,22 +226,10 @@ geom::Vec3 ResidueHandle::GetAltAtomPos(const AtomHandle& atom, return Impl()->GetAltAtomPos(atom.Impl(), group); } -geom::Vec3 ResidueHandle::GetGeometricStart() const +geom::AlignedCuboid ResidueHandle::GetBounds() const { this->CheckValidity(); - return Impl()->GetGeometricStart(); -} - -geom::Vec3 ResidueHandle::GetGeometricEnd() const -{ - this->CheckValidity(); - return Impl()->GetGeometricEnd(); -} - -geom::Vec3 ResidueHandle::GetGeometricCenter() const -{ - this->CheckValidity(); - return Impl()->GetGeometricCenter(); + return Impl()->GetBounds(); } geom::Vec3 ResidueHandle::GetCenterOfMass() const diff --git a/modules/mol/base/src/residue_handle.hh b/modules/mol/base/src/residue_handle.hh index 0d85e6e7fd460be23d463f1c7210da729e74edee..57b7c56192d3bdb9b0b9aa125e3eb4ec659d9b8b 100644 --- a/modules/mol/base/src/residue_handle.hh +++ b/modules/mol/base/src/residue_handle.hh @@ -19,9 +19,11 @@ #ifndef OST_RESIDUE_HANDLE_HU #define OST_RESIDUE_HANDLE_HU +#include <ost/geom/vec3.hh> +#include <ost/geom/aligned_cuboid.hh> + #include <ost/mol/query.hh> #include <ost/mol/module_config.hh> -#include <ost/geom/vec3.hh> #include <ost/mol/residue_base.hh> #include <ost/mol/atom_prop.hh> #include <ost/mol/entity_visitor_fw.hh> @@ -77,17 +79,8 @@ public: /// similar to GetCenterOfMass(), but the atoms are not mass weighted geom::Vec3 GetCenterOfAtoms() const; - /// \brief Get entity's geometric center - /// - /// Returns the geometric center of the entity's bounding box - /// by calculating (GetGeometricStart()+GetGeometricEnd())/2 - geom::Vec3 GetGeometricCenter() const; - - /// \brief Get entity's minimum cartesian coordinates - geom::Vec3 GetGeometricStart() const; - - /// \brief Get entity's maximum cartesian coordinates - geom::Vec3 GetGeometricEnd() const; + /// \brief get axis-aligned bounding box of residue + geom::AlignedCuboid GetBounds() const; /// \brief The chain this residue is attached to ChainHandle GetChain() const; diff --git a/modules/mol/base/src/residue_view.cc b/modules/mol/base/src/residue_view.cc index 72c5ff76fbd08034f744229f76c24e975ba4ee1d..53e0a3eaa79126ebbd6095a3c69719196a8d6c09 100644 --- a/modules/mol/base/src/residue_view.cc +++ b/modules/mol/base/src/residue_view.cc @@ -205,36 +205,17 @@ double ResidueView::GetMass() const return mass; } -geom::Vec3 ResidueView::GetGeometricStart() const +geom::AlignedCuboid ResidueView::GetBounds() const { this->CheckValidity(); - geom::Vec3 minimum(std::numeric_limits<Real>::max(), - std::numeric_limits<Real>::max(), - std::numeric_limits<Real>::max()); + geom::Vec3 mmin( std::numeric_limits<Real>::max()); + geom::Vec3 mmax(-std::numeric_limits<Real>::max()); AtomViewList::const_iterator i; for (i=data_->atoms.begin(); i!=data_->atoms.end(); ++i) { - minimum=geom::Min(minimum, (*i).GetPos()); + mmin=geom::Min(mmin, (*i).GetPos()); + mmax=geom::Max(mmax, (*i).GetPos()); } - return minimum; -} - -geom::Vec3 ResidueView::GetGeometricEnd() const -{ - this->CheckValidity(); - geom::Vec3 maximum(-std::numeric_limits<Real>::max(), - -std::numeric_limits<Real>::max(), - -std::numeric_limits<Real>::max()); - AtomViewList::const_iterator i; - for (i=data_->atoms.begin(); i!=data_->atoms.end(); ++i) { - maximum=geom::Max(maximum, (*i).GetPos()); - } - return maximum; -} - -geom::Vec3 ResidueView::GetGeometricCenter() const -{ - this->CheckValidity(); - return (this->GetGeometricStart() + this->GetGeometricEnd())/2; + return geom::AlignedCuboid(mmin, mmax); } geom::Vec3 ResidueView::GetCenterOfMass() const diff --git a/modules/mol/base/src/residue_view.hh b/modules/mol/base/src/residue_view.hh index 0cd381e86e08046fa59456b6e7cf48f44bfabd03..d771a95ce09a0ba448eaca0be2a391e53020ecdd 100644 --- a/modules/mol/base/src/residue_view.hh +++ b/modules/mol/base/src/residue_view.hh @@ -153,14 +153,9 @@ public: /// similar to GetCenterOfMass(), but the atoms are not mass weighted geom::Vec3 GetCenterOfAtoms() const; - /// \brief Get entity's geometric center - /// - /// Returns the geometric center of the entity's bounding box - /// by calculating (GetGeometricStart()+GetGeometricEnd())/2 - geom::Vec3 GetGeometricCenter() const; + /// \brief Get entity's axis-aligned bounding box + geom::AlignedCuboid GetBounds() const; - geom::Vec3 GetGeometricStart() const; - geom::Vec3 GetGeometricEnd() const; /// \brief return view based on a query object /// \sa Query