source: src/Shapes/Shape.cpp@ b8d15ba

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 Candidate_v1.7.0 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 b8d15ba was 23bade, checked in by Frederik Heber <heber@…>, 15 years ago

Actually, AndShape_impl::getHomogeneousPointsOnSurface() was not non-trivial at all ...

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