source: src/Shapes/ShapeOps.cpp@ 400170

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 400170 was c6f395, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added methods to calculate the intersections of Shapes with arbitrary lines

  • Property mode set to 100644
File size: 5.6 KB
RevLine 
[e09b70]1/*
2 * ShapeOps.cpp
3 *
4 * Created on: Jun 18, 2010
5 * Author: crueger
6 */
7
8#include "Shapes/ShapeOps.hpp"
9#include "Shapes/ShapeOps_impl.hpp"
10
[394529]11#include "Helpers/Assert.hpp"
12
[5de9da]13/*************** Base case ***********************/
14
15ShapeOpsBase_impl::ShapeOpsBase_impl(const Shape::impl_ptr &_arg) :
16 arg(_arg){}
17
18ShapeOpsBase_impl::~ShapeOpsBase_impl(){}
19
20bool ShapeOpsBase_impl::isInside(const Vector &point){
21 return arg->isInside(translateIn(point));
22}
23
24bool ShapeOpsBase_impl::isOnSurface(const Vector &point){
25 return arg->isOnSurface(translateIn(point));
26}
27
28Vector ShapeOpsBase_impl::getNormal(const Vector &point) throw (NotOnSurfaceException){
29 Vector helper = translateIn(point);
30 if(!arg->isOnSurface(helper)){
31 throw NotOnSurfaceException(__FILE__,__LINE__);
32 }
33 return translateOutNormal(arg->getNormal(helper));
34}
35
[c6f395]36LineSegmentSet ShapeOpsBase_impl::getLineIntersections(const Line &line){
37 Line newLine(translateIn(line.getOrigin()),translateIn(line.getDirection()));
38 LineSegmentSet res(line);
39 LineSegmentSet helper = getArg()->getLineIntersections(newLine);
40 for(LineSegmentSet::iterator iter = helper.begin();iter!=helper.end();++iter){
41 LinePoint lpBegin = iter->getBegin();
42 LinePoint lpEnd = iter->getBegin();
43 // translate both linepoints
44 lpBegin = lpBegin.isNegInfinity()?
45 line.negEndpoint():
46 line.getLinePoint(translateOutPos(lpBegin.getPoint()));
47 lpEnd = lpEnd.isPosInfinity()?
48 line.posEndpoint():
49 line.getLinePoint(translateOutPos(lpEnd.getPoint()));
50 res.insert(LineSegment(lpBegin,lpEnd));
51 }
52 return res;
53}
54
[cfda65]55Shape::impl_ptr ShapeOpsBase_impl::getArg(){
56 return arg;
57}
58
[5e588b5]59/********************* Resize ********************/
60
[e09b70]61Resize_impl::Resize_impl(const Shape::impl_ptr &_arg,double _size) :
[5de9da]62 ShapeOpsBase_impl(_arg), size(_size)
[394529]63{
64 ASSERT(size>0,"Cannot resize a Shape to size zero or below");
65}
[e09b70]66
67Resize_impl::~Resize_impl(){}
68
[5de9da]69Vector Resize_impl::translateIn(const Vector& point){
70 return (1/size) * point;
71}
72
73Vector Resize_impl::translateOutPos(const Vector& point){
74 return size * point;
75}
76
77Vector Resize_impl::translateOutNormal(const Vector& point){
78 return point;
[e09b70]79}
80
[cfda65]81string Resize_impl::toString(){
82 stringstream sstr;
83 sstr << "resize(" << getArg()->toString() << "," << size << ")";
84 return sstr.str();
85}
86
[e09b70]87Shape resize(const Shape &arg,double size){
88 Shape::impl_ptr impl = Shape::impl_ptr(new Resize_impl(getShapeImpl(arg),size));
89 return Shape(impl);
90}
91
[5e588b5]92/*************************** translate *******************/
93
[e09b70]94Translate_impl::Translate_impl(const Shape::impl_ptr &_arg, const Vector &_offset) :
[5de9da]95 ShapeOpsBase_impl(_arg),offset(_offset)
[e09b70]96{}
97
98Translate_impl::~Translate_impl(){}
99
[5de9da]100Vector Translate_impl::translateIn(const Vector& point){
101 return point-offset;
102}
103
104Vector Translate_impl::translateOutPos(const Vector& point){
105 return point+offset;
106}
107
108Vector Translate_impl::translateOutNormal(const Vector& point){
109 return point;
[e09b70]110}
111
[cfda65]112string Translate_impl::toString(){
113 stringstream sstr;
114 sstr << "translate(" << getArg()->toString() << "," << offset << ")";
[79dd0e]115 return sstr.str();
[cfda65]116}
117
[e09b70]118Shape translate(const Shape &arg, const Vector &offset){
119 Shape::impl_ptr impl = Shape::impl_ptr(new Translate_impl(getShapeImpl(arg),offset));
120 return Shape(impl);
121}
[5e588b5]122
123/*********************** stretch ******************/
124
125Stretch_impl::Stretch_impl(const Shape::impl_ptr &_arg, const Vector &_factors) :
[5de9da]126 ShapeOpsBase_impl(_arg),factors(_factors)
[5e588b5]127{
128 ASSERT(factors[0]>0,"cannot stretch a shape by a negative amount");
129 ASSERT(factors[1]>0,"cannot stretch a shape by a negative amount");
130 ASSERT(factors[2]>0,"cannot stretch a shape by a negative amount");
131 for(int i = NDIM;i--;){
132 reciFactors[i] = 1/factors[i];
133 }
134}
135
136Stretch_impl::~Stretch_impl(){}
137
[5de9da]138Vector Stretch_impl::translateIn(const Vector& point){
[5e588b5]139 Vector helper=point;
140 helper.ScaleAll(reciFactors);
[5de9da]141 return helper;
142}
143
144Vector Stretch_impl::translateOutPos(const Vector& point){
145 Vector helper=point;
146 helper.ScaleAll(factors);
147 return helper;
148}
149
150Vector Stretch_impl::translateOutNormal(const Vector& point){
151 Vector helper=point;
152 // the normalFactors are derived from appearances of the factors
153 // with in the vectorproduct
154 Vector normalFactors;
155 normalFactors[0]=factors[1]*factors[2];
156 normalFactors[1]=factors[0]*factors[2];
157 normalFactors[2]=factors[0]*factors[1];
158 helper.ScaleAll(normalFactors);
159 return helper;
[5e588b5]160}
161
[cfda65]162string Stretch_impl::toString(){
163 stringstream sstr;
164 sstr << "stretch(" << getArg()->toString() << "," << factors << ")";
165 return sstr.str();
166}
167
[5e588b5]168Shape stretch(const Shape &arg, const Vector &factors){
169 Shape::impl_ptr impl = Shape::impl_ptr(new Stretch_impl(getShapeImpl(arg),factors));
170 return Shape(impl);
171}
172
173/************************* transform *****************/
174
175Transform_impl::Transform_impl(const Shape::impl_ptr &_arg, const Matrix &_transformation) :
[5de9da]176 ShapeOpsBase_impl(_arg),transformation(_transformation)
[5e588b5]177{
178 transformationInv = transformation.invert();
179}
180
181Transform_impl::~Transform_impl(){}
182
[5de9da]183Vector Transform_impl::translateIn(const Vector& point){
184 return transformationInv * point;
185}
186
187Vector Transform_impl::translateOutPos(const Vector& point){
188 return transformation * point;
189}
190
191Vector Transform_impl::translateOutNormal(const Vector& point){
192 Matrix mat = transformation.determinant() * transformation.invert().transpose();
193 return mat * point;
[5e588b5]194}
195
[cfda65]196string Transform_impl::toString(){
197 stringstream sstr;
198 sstr << "transform(" << getArg()->toString() << "," << transformation << ")";
199 return sstr.str();
200}
201
[5e588b5]202Shape transform(const Shape &arg, const Matrix &transformation){
203 Shape::impl_ptr impl = Shape::impl_ptr(new Transform_impl(getShapeImpl(arg),transformation));
204 return Shape(impl);
205}
Note: See TracBrowser for help on using the repository browser.