source: src/Shapes/Shape.cpp@ fd4905

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable v1.0.3
Last change on this file since fd4905 was 9c1c89, checked in by Frederik Heber <heber@…>, 14 years ago

FIX: all ...:getHomogeneousPointsOnSurface() now have size_t instead of int parameter.

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * Shape.cpp
10 *
11 * Created on: Jun 18, 2010
12 * Author: crueger
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "Helpers/MemDebug.hpp"
21
22#include "Shape.hpp"
23#include "Shape_impl.hpp"
24
25
26#include "Helpers/Assert.hpp"
27#include "LinearAlgebra/Vector.hpp"
28
29Shape::Shape(const Shape& src) :
30 impl(src.getImpl())
31{}
32
33Shape::~Shape(){}
34
35bool Shape::isInside(const Vector &point) const{
36 return impl->isInside(point);
37}
38
39std::vector<Vector> Shape::getHomogeneousPointsOnSurface(const size_t N) const {
40 return impl->getHomogeneousPointsOnSurface(N);
41}
42
43Shape::Shape(Shape::impl_ptr _impl) :
44 impl(_impl)
45{}
46
47Shape &Shape::operator=(const Shape& rhs){
48 if(&rhs!=this){
49 impl=rhs.getImpl();
50 }
51 return *this;
52}
53
54Shape::impl_ptr Shape::getImpl() const{
55 return impl;
56}
57
58// allows arbitrary friendship, but only if implementation is known
59Shape::impl_ptr getShapeImpl(const Shape &shape){
60 return shape.getImpl();
61}
62
63/***************************** Some simple Shapes ***************************/
64
65Shape Everywhere(){
66 static Shape::impl_ptr impl = Shape::impl_ptr(new Everywhere_impl());
67 return Shape(impl);
68}
69
70Shape Nowhere(){
71 static Shape::impl_ptr impl = Shape::impl_ptr(new Nowhere_impl());
72 return Shape(impl);
73}
74
75/****************************** Operators ***********************************/
76
77// AND
78
79AndShape_impl::AndShape_impl(const Shape::impl_ptr &_lhs, const Shape::impl_ptr &_rhs) :
80 lhs(_lhs),rhs(_rhs)
81{}
82
83AndShape_impl::~AndShape_impl(){}
84
85bool AndShape_impl::isInside(const Vector &point){
86 return lhs->isInside(point) && rhs->isInside(point);
87}
88
89std::vector<Vector> AndShape_impl::getHomogeneousPointsOnSurface(const size_t N) const {
90 std::vector<Vector> PointsOnSurface_lhs = lhs->getHomogeneousPointsOnSurface(N);
91 std::vector<Vector> PointsOnSurface_rhs = rhs->getHomogeneousPointsOnSurface(N);
92 std::vector<Vector> PointsOnSurface;
93
94 for (std::vector<Vector>::const_iterator iter = PointsOnSurface_lhs.begin(); iter != PointsOnSurface_lhs.end(); ++iter) {
95 if (rhs->isInside(*iter))
96 PointsOnSurface.push_back(*iter);
97 }
98 for (std::vector<Vector>::const_iterator iter = PointsOnSurface_rhs.begin(); iter != PointsOnSurface_rhs.end(); ++iter) {
99 if (lhs->isInside(*iter))
100 PointsOnSurface.push_back(*iter);
101 }
102
103 return PointsOnSurface;
104}
105
106
107Shape operator&&(const Shape &lhs,const Shape &rhs){
108 Shape::impl_ptr newImpl = Shape::impl_ptr(new AndShape_impl(getShapeImpl(lhs),getShapeImpl(rhs)));
109 return Shape(newImpl);
110}
111
112// OR
113
114OrShape_impl::OrShape_impl(const Shape::impl_ptr &_lhs, const Shape::impl_ptr &_rhs) :
115 lhs(_lhs),rhs(_rhs)
116{}
117
118OrShape_impl::~OrShape_impl(){}
119
120bool OrShape_impl::isInside(const Vector &point){
121 return rhs->isInside(point) || lhs->isInside(point);
122}
123
124std::vector<Vector> OrShape_impl::getHomogeneousPointsOnSurface(const size_t N) const {
125 std::vector<Vector> PointsOnSurface_lhs = lhs->getHomogeneousPointsOnSurface(N);
126 std::vector<Vector> PointsOnSurface_rhs = rhs->getHomogeneousPointsOnSurface(N);
127 std::vector<Vector> PointsOnSurface;
128
129 for (std::vector<Vector>::const_iterator iter = PointsOnSurface_lhs.begin(); iter != PointsOnSurface_lhs.end(); ++iter) {
130 if (!rhs->isInside(*iter))
131 PointsOnSurface.push_back(*iter);
132 }
133 for (std::vector<Vector>::const_iterator iter = PointsOnSurface_rhs.begin(); iter != PointsOnSurface_rhs.end(); ++iter) {
134 if (!lhs->isInside(*iter))
135 PointsOnSurface.push_back(*iter);
136 }
137
138 return PointsOnSurface;
139}
140
141Shape operator||(const Shape &lhs,const Shape &rhs){
142 Shape::impl_ptr newImpl = Shape::impl_ptr(new OrShape_impl(getShapeImpl(lhs),getShapeImpl(rhs)));
143 return Shape(newImpl);
144}
145
146// NOT
147
148NotShape_impl::NotShape_impl(const Shape::impl_ptr &_arg) :
149 arg(_arg)
150{}
151
152NotShape_impl::~NotShape_impl(){}
153
154bool NotShape_impl::isInside(const Vector &point){
155 return !arg->isInside(point);
156}
157
158std::vector<Vector> NotShape_impl::getHomogeneousPointsOnSurface(const size_t N) const {
159 // surfaces are the same, only normal direction is different
160 return arg->getHomogeneousPointsOnSurface(N);
161}
162
163Shape operator!(const Shape &arg){
164 Shape::impl_ptr newImpl = Shape::impl_ptr(new NotShape_impl(getShapeImpl(arg)));
165 return Shape(newImpl);
166}
Note: See TracBrowser for help on using the repository browser.