1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Filler.cpp
|
---|
10 | *
|
---|
11 | * Created on: Jan 16, 2012
|
---|
12 | * Author: heber
|
---|
13 | */
|
---|
14 |
|
---|
15 |
|
---|
16 | // include config.h
|
---|
17 | #ifdef HAVE_CONFIG_H
|
---|
18 | #include <config.h>
|
---|
19 | #endif
|
---|
20 |
|
---|
21 | #include "CodePatterns/MemDebug.hpp"
|
---|
22 |
|
---|
23 | #include <algorithm>
|
---|
24 | #include <boost/bind.hpp>
|
---|
25 | #include <boost/lambda/lambda.hpp>
|
---|
26 | #include <sstream>
|
---|
27 | #include <vector>
|
---|
28 |
|
---|
29 | #include "Filler.hpp"
|
---|
30 |
|
---|
31 | #include "CodePatterns/Assert.hpp"
|
---|
32 | #include "CodePatterns/Log.hpp"
|
---|
33 |
|
---|
34 | #include "Atom/atom.hpp"
|
---|
35 | #include "ClusterInterface.hpp"
|
---|
36 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
37 | #include "Inserter/Inserter.hpp"
|
---|
38 | #include "LinearAlgebra/Vector.hpp"
|
---|
39 | #include "NodeTypes.hpp"
|
---|
40 | #include "Predicates/FillPredicate.hpp"
|
---|
41 | #include "Predicates/Ops_FillPredicate.hpp"
|
---|
42 | #include "World.hpp"
|
---|
43 |
|
---|
44 |
|
---|
45 | /** Constructor for class Filler.
|
---|
46 | *
|
---|
47 | * \note We store inverted \a _predicate because we need it only for
|
---|
48 | * remove_copy_if which works in this inverted way as desired.
|
---|
49 | *
|
---|
50 | * @param _mesh Mesh with a NodeSet that fills its Shape
|
---|
51 | * @param _predicate predicate construct to check at each Node
|
---|
52 | * @param _inserter inserter which places the cloned cluster
|
---|
53 | */
|
---|
54 | Filler::Filler(const Mesh &_mesh, const FillPredicate &_predicate, const Inserter &_inserter) :
|
---|
55 | mesh(_mesh),
|
---|
56 | predicate(!_predicate),
|
---|
57 | inserter(_inserter)
|
---|
58 | {}
|
---|
59 |
|
---|
60 | /** Destructor for class Filler.
|
---|
61 | *
|
---|
62 | */
|
---|
63 | Filler::~Filler()
|
---|
64 | {}
|
---|
65 |
|
---|
66 | /** Fill in the desired Cluster at each remaining node.
|
---|
67 | *
|
---|
68 | * \note The cluster is non-const because it is moved to the first vacant node.
|
---|
69 | *
|
---|
70 | * @param copyMethod functor that knows how to copy atoms.
|
---|
71 | * @param cluster set of atomic ids contained in a specific Shape to fill each Node with
|
---|
72 | */
|
---|
73 | void Filler::operator()(
|
---|
74 | CopyAtomsInterface ©Method,
|
---|
75 | ClusterInterface::Cluster_impl cluster) const
|
---|
76 | {
|
---|
77 | const NodeSet &nodes = mesh.getNodes();
|
---|
78 | std::stringstream output;
|
---|
79 | std::for_each( nodes.begin(), nodes.end(), output << boost::lambda::_1 << " ");
|
---|
80 | LOG(3, "DEBUG: Listing nodes to check: " << output.str());
|
---|
81 | if (nodes.size() == 0) {
|
---|
82 | ASSERT(false,
|
---|
83 | "Filler::operator() - Mesh contains no nodes.");
|
---|
84 | return;
|
---|
85 | }
|
---|
86 | NodeSet FillNodes(nodes.size(), zeroVec);
|
---|
87 |
|
---|
88 | // evaluate predicate and gather into new set
|
---|
89 | NodeSet::iterator transform_end =
|
---|
90 | std::remove_copy_if(nodes.begin(), nodes.end(), FillNodes.begin(), predicate );
|
---|
91 | FillNodes.erase(transform_end, FillNodes.end());
|
---|
92 |
|
---|
93 | if (FillNodes.size() == 0) {
|
---|
94 | ELOG(2, "For none of the nodes did the predicate return true.");
|
---|
95 | return;
|
---|
96 | } else {
|
---|
97 | LOG(1, "INFO: " << FillNodes.size() << " out of " << nodes.size() << " returned true from predicate.");
|
---|
98 | }
|
---|
99 |
|
---|
100 | // skip first node (as we must keep the original atoms)
|
---|
101 | NodeSet::iterator iter = ++FillNodes.begin();
|
---|
102 |
|
---|
103 | // fill all other true nodes
|
---|
104 | std::for_each(iter , FillNodes.end(),
|
---|
105 | boost::bind(&Inserter::operator(), boost::cref(inserter), boost::ref(copyMethod), boost::cref(cluster), _1) );
|
---|
106 |
|
---|
107 | // move cluster to first node
|
---|
108 | cluster->translate(*FillNodes.begin());
|
---|
109 | }
|
---|