source: src/Shapes/Shape.cpp@ c5186e

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 c5186e was c5186e, checked in by Frederik Heber <heber@…>, 15 years ago

Added getHomogenousPointsOnSurface() function to Shapes.

  • missing is so far: AndShape_impl which is not trivial, as surface is inside of both probably (ASSERT(false,...) present).
  • missing also (although trivial): Cuboid_impl (ASSERT(false,...) present).
  • Property mode set to 100644
File size: 3.6 KB
Line 
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
11
12#include "Helpers/Assert.hpp"
13#include "LinearAlgebra/Vector.hpp"
14
15Shape::Shape(const Shape& src) :
16 impl(src.getImpl())
17{}
18
19Shape::~Shape(){}
20
21bool Shape::isInside(const Vector &point) const{
22 return impl->isInside(point);
23}
24
25std::vector<Vector> Shape::getHomogeneousPointsOnSurface(const int N) const {
26 return impl->getHomogeneousPointsOnSurface(N);
27}
28
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
44// allows arbitrary friendship, but only if implementation is known
45Shape::impl_ptr getShapeImpl(const Shape &shape){
46 return shape.getImpl();
47}
48
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
75std::vector<Vector> AndShape_impl::getHomogeneousPointsOnSurface(const int N) const {
76 std::vector<Vector> PointsOnSurface;
77 ASSERT(false, "AndShape_impl::getHomogeneousPointsOnSurface() not implemented yet");
78 return PointsOnSurface;
79}
80
81
82Shape operator&&(const Shape &lhs,const Shape &rhs){
83 Shape::impl_ptr newImpl = Shape::impl_ptr(new AndShape_impl(getShapeImpl(lhs),getShapeImpl(rhs)));
84 return Shape(newImpl);
85}
86
87// OR
88
89OrShape_impl::OrShape_impl(const Shape::impl_ptr &_lhs, const Shape::impl_ptr &_rhs) :
90 lhs(_lhs),rhs(_rhs)
91{}
92
93OrShape_impl::~OrShape_impl(){}
94
95bool OrShape_impl::isInside(const Vector &point){
96 return rhs->isInside(point) || lhs->isInside(point);
97}
98
99std::vector<Vector> OrShape_impl::getHomogeneousPointsOnSurface(const int N) const {
100 std::vector<Vector> PointsOnSurface_lhs = lhs->getHomogeneousPointsOnSurface(N);
101 std::vector<Vector> PointsOnSurface_rhs = rhs->getHomogeneousPointsOnSurface(N);
102 std::vector<Vector> PointsOnSurface;
103
104 for (std::vector<Vector>::const_iterator iter = PointsOnSurface_lhs.begin(); iter != PointsOnSurface_lhs.end(); ++iter) {
105 if (!rhs->isInside(*iter))
106 PointsOnSurface.push_back(*iter);
107 }
108 for (std::vector<Vector>::const_iterator iter = PointsOnSurface_rhs.begin(); iter != PointsOnSurface_rhs.end(); ++iter) {
109 if (!lhs->isInside(*iter))
110 PointsOnSurface.push_back(*iter);
111 }
112
113 return PointsOnSurface;
114}
115
116Shape operator||(const Shape &lhs,const Shape &rhs){
117 Shape::impl_ptr newImpl = Shape::impl_ptr(new OrShape_impl(getShapeImpl(lhs),getShapeImpl(rhs)));
118 return Shape(newImpl);
119}
120
121// NOT
122
123NotShape_impl::NotShape_impl(const Shape::impl_ptr &_arg) :
124 arg(_arg)
125{}
126
127NotShape_impl::~NotShape_impl(){}
128
129bool NotShape_impl::isInside(const Vector &point){
130 return !arg->isInside(point);
131}
132
133std::vector<Vector> NotShape_impl::getHomogeneousPointsOnSurface(const int N) const {
134 // surfaces are the same, only normal direction is different
135 return arg->getHomogeneousPointsOnSurface(N);
136}
137
138Shape operator!(const Shape &arg){
139 Shape::impl_ptr newImpl = Shape::impl_ptr(new NotShape_impl(getShapeImpl(arg)));
140 return Shape(newImpl);
141}
Note: See TracBrowser for help on using the repository browser.