1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-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 | * FillRegularGridAction.cpp
|
---|
10 | *
|
---|
11 | * Created on: Jan 12, 2012
|
---|
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 "Atom/atom.hpp"
|
---|
23 | #include "Atom/CopyAtoms/CopyAtoms_withBonds.hpp"
|
---|
24 | #include "CodePatterns/Log.hpp"
|
---|
25 | #include "Descriptors/MoleculeOrderDescriptor.hpp"
|
---|
26 | #include "Filling/Cluster.hpp"
|
---|
27 | #include "Filling/Filler.hpp"
|
---|
28 | #include "Filling/Mesh/CubeMesh.hpp"
|
---|
29 | #include "Filling/Predicates/IsInsideSurface_FillPredicate.hpp"
|
---|
30 | #include "Filling/Predicates/IsVoidNode_FillPredicate.hpp"
|
---|
31 | #include "Filling/Predicates/Ops_FillPredicate.hpp"
|
---|
32 | #include "LinkedCell/linkedcell.hpp"
|
---|
33 | #include "LinkedCell/PointCloudAdaptor.hpp"
|
---|
34 | #include "molecule.hpp"
|
---|
35 | #include "MoleculeListClass.hpp"
|
---|
36 | #include "Parser/FormatParserInterface.hpp"
|
---|
37 | #include "Parser/FormatParserStorage.hpp"
|
---|
38 | #include "Shapes/BaseShapes.hpp"
|
---|
39 | #include "Tesselation/tesselation.hpp"
|
---|
40 | #include "Tesselation/BoundaryLineSet.hpp"
|
---|
41 | #include "Tesselation/BoundaryTriangleSet.hpp"
|
---|
42 | #include "Tesselation/CandidateForTesselation.hpp"
|
---|
43 | #include "World.hpp"
|
---|
44 |
|
---|
45 |
|
---|
46 | #include <algorithm>
|
---|
47 | #include <iostream>
|
---|
48 | #include <string>
|
---|
49 | #include <vector>
|
---|
50 |
|
---|
51 | #include "Actions/FillAction/FillRegularGridAction.hpp"
|
---|
52 |
|
---|
53 | using namespace MoleCuilder;
|
---|
54 |
|
---|
55 | // and construct the stuff
|
---|
56 | #include "FillRegularGridAction.def"
|
---|
57 | #include "Action_impl_pre.hpp"
|
---|
58 | /** =========== define the function ====================== */
|
---|
59 | Action::state_ptr FillRegularGridAction::performCall() {
|
---|
60 | typedef std::vector<atom*> AtomVector;
|
---|
61 |
|
---|
62 | // obtain information
|
---|
63 | getParametersfromValueStorage();
|
---|
64 |
|
---|
65 | // get all present atoms for UndoState
|
---|
66 | AtomVector presentatoms = World::getInstance().getAllAtoms();
|
---|
67 |
|
---|
68 | // get the filler molecule and move to origin
|
---|
69 | const std::vector< molecule *> molecules = World::getInstance().getSelectedMolecules();
|
---|
70 | if (molecules.size() != 1) {
|
---|
71 | ELOG(1, "No exactly one molecule selected, aborting,");
|
---|
72 | return Action::failure;
|
---|
73 | }
|
---|
74 | molecule *filler = *(molecules.begin());
|
---|
75 | LOG(1, "INFO: Chosen molecule has " << filler->size() << " atoms.");
|
---|
76 |
|
---|
77 | // check for selected molecules and create surfaces from them
|
---|
78 | std::vector<atom *> atoms(World::getInstance().getSelectedAtoms());
|
---|
79 | FillPredicate * surface_predicate = NULL;
|
---|
80 | LinkedCell_deprecated * LC = NULL;
|
---|
81 | Tesselation * TesselStruct = NULL;
|
---|
82 | if (params.SphereRadius != 0.) {
|
---|
83 | if ( molecules.size() == 0) {
|
---|
84 | ELOG(1, "You have given a sphere radius " << params.SphereRadius
|
---|
85 | << " != 0, but have not select any molecules.");
|
---|
86 | }
|
---|
87 | // create adaptor for the selected atoms
|
---|
88 | PointCloudAdaptor< std::vector<atom *> > cloud(&atoms, std::string("Selected atoms"));
|
---|
89 |
|
---|
90 | // create tesselation
|
---|
91 | LC = new LinkedCell_deprecated(cloud, 2.*params.SphereRadius);
|
---|
92 | TesselStruct = new Tesselation;
|
---|
93 | (*TesselStruct)(cloud, params.SphereRadius);
|
---|
94 |
|
---|
95 | // and create predicate
|
---|
96 | surface_predicate = new FillPredicate( IsInsideSurface_FillPredicate( *TesselStruct, *LC ) );
|
---|
97 | }
|
---|
98 |
|
---|
99 | // create predicate, mesh, and filler
|
---|
100 | {
|
---|
101 | FillPredicate *voidnode_predicate = new FillPredicate(
|
---|
102 | IsVoidNode_FillPredicate(
|
---|
103 | Sphere(zeroVec, params.mindistance)
|
---|
104 | )
|
---|
105 | );
|
---|
106 | FillPredicate Andpredicate = (*voidnode_predicate);
|
---|
107 | if (surface_predicate != NULL)
|
---|
108 | Andpredicate = (Andpredicate) && !(*surface_predicate);
|
---|
109 | Mesh *mesh = new CubeMesh(params.counts, params.offset, World::getInstance().getDomain().getM());
|
---|
110 |
|
---|
111 | // fill
|
---|
112 | {
|
---|
113 | Filler *fillerFunction = new Filler(*mesh, Andpredicate);
|
---|
114 | ClusterInterface::Cluster_impl cluster( new Cluster( filler->getAtomIds(), filler->getBoundingShape()) );
|
---|
115 | CopyAtoms_withBonds copyMethod;
|
---|
116 | (*fillerFunction)(copyMethod, cluster);
|
---|
117 | delete fillerFunction;
|
---|
118 | }
|
---|
119 |
|
---|
120 | // remove
|
---|
121 | delete mesh;
|
---|
122 | delete voidnode_predicate;
|
---|
123 | delete surface_predicate;
|
---|
124 | delete LC;
|
---|
125 | delete TesselStruct;
|
---|
126 | }
|
---|
127 |
|
---|
128 | // generate list of newly created atoms
|
---|
129 | // (we can in general remove more quickly from a list than a vector)
|
---|
130 | AtomVector filleratoms = World::getInstance().getAllAtoms();
|
---|
131 | // LOG(0, filleratoms.size() << " atoms are present.");
|
---|
132 | std::list<atom *> filleratoms_list;
|
---|
133 | std::copy( filleratoms.begin(), filleratoms.end(), std::back_inserter( filleratoms_list ));
|
---|
134 | // LOG(0, filleratoms_list.size() << " atoms have been copied.");
|
---|
135 | for (AtomVector::const_iterator iter = presentatoms.begin();
|
---|
136 | iter != presentatoms.end();
|
---|
137 | ++iter) {
|
---|
138 | filleratoms_list.remove(*iter);
|
---|
139 | }
|
---|
140 | // LOG(0, filleratoms_list.size() << " atoms left after removal.");
|
---|
141 | filleratoms.clear();
|
---|
142 | std::copy(filleratoms_list.begin(), filleratoms_list.end(), std::back_inserter( filleratoms ));
|
---|
143 |
|
---|
144 | // LOG(0, filleratoms.size() << " atoms have been inserted.");
|
---|
145 |
|
---|
146 | return Action::state_ptr(new FillRegularGridState(filleratoms,params));
|
---|
147 | }
|
---|
148 |
|
---|
149 | Action::state_ptr FillRegularGridAction::performUndo(Action::state_ptr _state) {
|
---|
150 | // FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get());
|
---|
151 | //
|
---|
152 | // BOOST_FOREACH(atom *_atom, state->filleratoms) {
|
---|
153 | // World::getInstance().destroyAtom(Walker);
|
---|
154 | // }
|
---|
155 | //
|
---|
156 | // // as atoms and atoms from state are removed, we have to create a new one
|
---|
157 | // std::vector<atom*> filleratoms;
|
---|
158 | // return Action::state_ptr(new FillRegularGridState(filleratoms,state->params));
|
---|
159 | return Action::failure;
|
---|
160 | }
|
---|
161 |
|
---|
162 | Action::state_ptr FillRegularGridAction::performRedo(Action::state_ptr _state){
|
---|
163 | //FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get());
|
---|
164 |
|
---|
165 | return Action::failure;
|
---|
166 | //return Action::state_ptr(_state);
|
---|
167 | }
|
---|
168 |
|
---|
169 | bool FillRegularGridAction::canUndo() {
|
---|
170 | return false;
|
---|
171 | }
|
---|
172 |
|
---|
173 | bool FillRegularGridAction::shouldUndo() {
|
---|
174 | return false;
|
---|
175 | }
|
---|
176 | /** =========== end of function ====================== */
|
---|