source: src/Shapes/ShapeOps.cpp@ 2ad482

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

BUGFIX: Normals were not normalized in shape operations

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