source: src/Shapes/Shape.cpp@ 9cd807

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
Last change on this file since 9cd807 was 13e3c3, checked in by Frederik Heber <heber@…>, 15 years ago

Merge branch 'SmallFixes' into stable

Conflicts:

src/Shapes/BaseShapes.cpp

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