| [7afb77] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
| [0aa122] | 4 | * Copyright (C)  2012 University of Bonn. All rights reserved. | 
|---|
| [7afb77] | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | /* | 
|---|
|  | 9 | * AtomsWithinDistanceOfDescriptor.cpp | 
|---|
|  | 10 | * | 
|---|
|  | 11 | *  Created on: Dec 19, 2011 | 
|---|
|  | 12 | *      Author: heber | 
|---|
|  | 13 | */ | 
|---|
|  | 14 |  | 
|---|
|  | 15 | // include config.h | 
|---|
|  | 16 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 17 | #include <config.h> | 
|---|
|  | 18 | #endif | 
|---|
|  | 19 |  | 
|---|
|  | 20 | #include "CodePatterns/MemDebug.hpp" | 
|---|
|  | 21 |  | 
|---|
|  | 22 | #include "AtomsWithinDistanceOfDescriptor.hpp" | 
|---|
|  | 23 | #include "AtomsWithinDistanceOfDescriptor_impl.hpp" | 
|---|
|  | 24 |  | 
|---|
|  | 25 | #include "Atom/atom.hpp" | 
|---|
|  | 26 | #include "LinkedCell/LinkedCell_View.hpp" | 
|---|
|  | 27 | #include "CodePatterns/Observer/ObservedContainer_impl.hpp" | 
|---|
|  | 28 |  | 
|---|
|  | 29 | using namespace std; | 
|---|
|  | 30 |  | 
|---|
|  | 31 |  | 
|---|
|  | 32 | AtomsWithinDistanceOfDescriptor_impl::AtomsWithinDistanceOfDescriptor_impl(const double _distance, const Vector &_position) : | 
|---|
|  | 33 | distance(_distance), | 
|---|
|  | 34 | distanceSquared(distance*distance), | 
|---|
|  | 35 | position(_position) | 
|---|
|  | 36 | {} | 
|---|
|  | 37 |  | 
|---|
|  | 38 | AtomsWithinDistanceOfDescriptor_impl::~AtomsWithinDistanceOfDescriptor_impl() | 
|---|
|  | 39 | {} | 
|---|
|  | 40 |  | 
|---|
|  | 41 | bool AtomsWithinDistanceOfDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom) | 
|---|
|  | 42 | { | 
|---|
|  | 43 | return ((atom.second->getPosition().DistanceSquared(position) - distanceSquared) <= 0); | 
|---|
|  | 44 | } | 
|---|
|  | 45 |  | 
|---|
|  | 46 | atom* AtomsWithinDistanceOfDescriptor_impl::find(){ | 
|---|
|  | 47 | LinkedCell::LinkedCell_View view = World::getInstance().getLinkedCell(distance); | 
|---|
|  | 48 | LinkedCell::LinkedList list = view.getPointsInsideSphere(distance, position); | 
|---|
|  | 49 | return (list.begin()!=list.end())? static_cast<atom *>(const_cast<TesselPoint *>(*list.begin())):0; | 
|---|
|  | 50 | } | 
|---|
|  | 51 |  | 
|---|
|  | 52 | std::vector<atom*> AtomsWithinDistanceOfDescriptor_impl::findAll(){ | 
|---|
|  | 53 | LinkedCell::LinkedCell_View view = World::getInstance().getLinkedCell(distance); | 
|---|
|  | 54 | LinkedCell::LinkedList list = view.getPointsInsideSphere(distance, position); | 
|---|
|  | 55 | std::vector<atom*> res; | 
|---|
|  | 56 | for (LinkedCell::LinkedList::iterator iter = list.begin(); iter != list.end(); ++iter) | 
|---|
|  | 57 | res.push_back(static_cast<atom *>(const_cast<TesselPoint *>(*iter))); | 
|---|
|  | 58 | return res; | 
|---|
|  | 59 | } | 
|---|
|  | 60 |  | 
|---|
|  | 61 | AtomDescriptor AtomsWithinDistanceOf(const double distance, const Vector &position) | 
|---|
|  | 62 | { | 
|---|
|  | 63 | return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomsWithinDistanceOfDescriptor_impl(distance, position))); | 
|---|
|  | 64 | } | 
|---|