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