source: src/Shapes/ShapeOps.cpp@ 5fa1f0

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 5fa1f0 was b98a32, checked in by Frederik Heber <heber@…>, 13 years ago

FIX: Some fixes to Resize_Impl functions.

  • replaced 1/ by 1./.
  • volume and surface area are size to the power of three and two, respectively.
  • Property mode set to 100644
File size: 8.4 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[bcf653]5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
[e09b70]8/*
9 * ShapeOps.cpp
10 *
11 * Created on: Jun 18, 2010
12 * Author: crueger
13 */
14
[bf3817]15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
[ad011c]20#include "CodePatterns/MemDebug.hpp"
[bbbad5]21
[5a8d61]22#include <algorithm>
23#include <boost/bind.hpp>
24
[b94634]25#include "Shapes/ShapeExceptions.hpp"
[e09b70]26#include "Shapes/ShapeOps.hpp"
27#include "Shapes/ShapeOps_impl.hpp"
28
[6c438f]29#include "LinearAlgebra/Vector.hpp"
[ad011c]30#include "CodePatterns/Assert.hpp"
[394529]31
[5de9da]32/*************** Base case ***********************/
33
34ShapeOpsBase_impl::ShapeOpsBase_impl(const Shape::impl_ptr &_arg) :
35 arg(_arg){}
36
37ShapeOpsBase_impl::~ShapeOpsBase_impl(){}
38
[735940]39bool ShapeOpsBase_impl::isInside(const Vector &point) const{
[5de9da]40 return arg->isInside(translateIn(point));
41}
42
[735940]43bool ShapeOpsBase_impl::isOnSurface(const Vector &point) const{
[5de9da]44 return arg->isOnSurface(translateIn(point));
45}
46
[735940]47Vector ShapeOpsBase_impl::getNormal(const Vector &point) const throw (NotOnSurfaceException){
[5de9da]48 Vector helper = translateIn(point);
49 if(!arg->isOnSurface(helper)){
[b94634]50 throw NotOnSurfaceException() << ShapeVector(&helper);
[5de9da]51 }
[f12805]52 Vector res = translateOutNormal(arg->getNormal(helper));
53 res.Normalize();
54 return res;
[5de9da]55}
56
[6acc2f3]57Vector ShapeOpsBase_impl::getCenter() const
58{
59 return arg->getCenter();
60}
61
62double ShapeOpsBase_impl::getRadius() const
63{
64 return translateOutPos(Vector(arg->getRadius(), 0., 0.)).Norm();
65}
66
67
[735940]68LineSegmentSet ShapeOpsBase_impl::getLineIntersections(const Line &line) const{
[c6f395]69 Line newLine(translateIn(line.getOrigin()),translateIn(line.getDirection()));
70 LineSegmentSet res(line);
71 LineSegmentSet helper = getArg()->getLineIntersections(newLine);
72 for(LineSegmentSet::iterator iter = helper.begin();iter!=helper.end();++iter){
73 LinePoint lpBegin = iter->getBegin();
74 LinePoint lpEnd = iter->getBegin();
75 // translate both linepoints
76 lpBegin = lpBegin.isNegInfinity()?
77 line.negEndpoint():
78 line.getLinePoint(translateOutPos(lpBegin.getPoint()));
79 lpEnd = lpEnd.isPosInfinity()?
80 line.posEndpoint():
81 line.getLinePoint(translateOutPos(lpEnd.getPoint()));
82 res.insert(LineSegment(lpBegin,lpEnd));
83 }
84 return res;
85}
86
[b92e4a]87enum ShapeType ShapeOpsBase_impl::getType() const {
88 return getArg()->getType();
89}
90
[6c438f]91std::vector<Vector> ShapeOpsBase_impl::getHomogeneousPointsOnSurface(const size_t N) const {
[c48641]92 std::vector<Vector> PointsOnSurface = getArg()->getHomogeneousPointsOnSurface(N);
93 std::transform(PointsOnSurface.begin(), PointsOnSurface.end(), PointsOnSurface.begin(),
94 boost::bind(&ShapeOpsBase_impl::translateOutPos, this, _1) );
95 return PointsOnSurface;
[5a8d61]96}
97
98std::vector<Vector> ShapeOpsBase_impl::getHomogeneousPointsInVolume(const size_t N) const {
[c48641]99 std::vector<Vector> PointsOnSurface = getArg()->getHomogeneousPointsInVolume(N);
100 std::transform(PointsOnSurface.begin(), PointsOnSurface.end(), PointsOnSurface.begin(),
101 boost::bind(&ShapeOpsBase_impl::translateOutPos, this, _1) );
102 return PointsOnSurface;
[6c438f]103}
104
105Shape::impl_ptr ShapeOpsBase_impl::getArg() const{
[cfda65]106 return arg;
107}
108
[5e588b5]109/********************* Resize ********************/
110
[e09b70]111Resize_impl::Resize_impl(const Shape::impl_ptr &_arg,double _size) :
[5de9da]112 ShapeOpsBase_impl(_arg), size(_size)
[394529]113{
114 ASSERT(size>0,"Cannot resize a Shape to size zero or below");
115}
[e09b70]116
117Resize_impl::~Resize_impl(){}
118
[c67c65]119double Resize_impl::getVolume() const
120{
[b98a32]121 return getArg()->getVolume() * size * size * size;
[c67c65]122}
123
124double Resize_impl::getSurfaceArea() const
125{
[b98a32]126 return getArg()->getSurfaceArea() * size * size;
[c67c65]127}
128
129
[735940]130bool Resize_impl::isInside(const Vector& point) const{
[b98a32]131 return getArg()->isInside((1./size) * point);
[6c438f]132}
133
[735940]134Vector Resize_impl::translateIn(const Vector& point) const{
[b98a32]135 return (1./size) * point;
[5de9da]136}
137
[735940]138Vector Resize_impl::translateOutPos(const Vector& point) const{
[5de9da]139 return size * point;
140}
141
[735940]142Vector Resize_impl::translateOutNormal(const Vector& point) const{
[5de9da]143 return point;
[e09b70]144}
145
[b92e4a]146std::string Resize_impl::toString() const{
[955b91]147 std::stringstream sstr;
[cfda65]148 sstr << "resize(" << getArg()->toString() << "," << size << ")";
149 return sstr.str();
150}
151
[e09b70]152Shape resize(const Shape &arg,double size){
153 Shape::impl_ptr impl = Shape::impl_ptr(new Resize_impl(getShapeImpl(arg),size));
154 return Shape(impl);
155}
156
[5e588b5]157/*************************** translate *******************/
158
[e09b70]159Translate_impl::Translate_impl(const Shape::impl_ptr &_arg, const Vector &_offset) :
[5de9da]160 ShapeOpsBase_impl(_arg),offset(_offset)
[e09b70]161{}
162
163Translate_impl::~Translate_impl(){}
164
[735940]165bool Translate_impl::isInside(const Vector& point) const{
[6c438f]166 return getArg()->isInside(point-offset);
167}
168
[6acc2f3]169Vector Translate_impl::getCenter() const
170{
171 return getArg()->getCenter()+offset;
172}
173
174double Translate_impl::getRadius() const
175{
176 return getArg()->getRadius();
177}
178
[c67c65]179double Translate_impl::getVolume() const
180{
181 return getArg()->getVolume();
182}
183
184double Translate_impl::getSurfaceArea() const
185{
186 return getArg()->getSurfaceArea();
187}
[6acc2f3]188
[735940]189Vector Translate_impl::translateIn(const Vector& point) const{
[5de9da]190 return point-offset;
191}
192
[735940]193Vector Translate_impl::translateOutPos(const Vector& point) const{
[5de9da]194 return point+offset;
195}
196
[735940]197Vector Translate_impl::translateOutNormal(const Vector& point) const{
[5de9da]198 return point;
[e09b70]199}
200
[b92e4a]201std::string Translate_impl::toString() const{
[955b91]202 std::stringstream sstr;
[cfda65]203 sstr << "translate(" << getArg()->toString() << "," << offset << ")";
[79dd0e]204 return sstr.str();
[cfda65]205}
206
[e09b70]207Shape translate(const Shape &arg, const Vector &offset){
208 Shape::impl_ptr impl = Shape::impl_ptr(new Translate_impl(getShapeImpl(arg),offset));
209 return Shape(impl);
210}
[5e588b5]211
212/*********************** stretch ******************/
213
214Stretch_impl::Stretch_impl(const Shape::impl_ptr &_arg, const Vector &_factors) :
[5de9da]215 ShapeOpsBase_impl(_arg),factors(_factors)
[5e588b5]216{
217 for(int i = NDIM;i--;){
[84721b]218 ASSERT(factors[i]>0.,"cannot stretch a shape by a negative amount");
219 reciFactors[i] = 1./factors[i];
[5e588b5]220 }
221}
222
223Stretch_impl::~Stretch_impl(){}
224
[c67c65]225double Stretch_impl::getVolume() const
226{
227 // TODO
228 return -1.;
229}
230
231double Stretch_impl::getSurfaceArea() const
232{
233 // TODO
234 return -1.;
235}
236
[735940]237bool Stretch_impl::isInside(const Vector& point) const{
[5e588b5]238 Vector helper=point;
239 helper.ScaleAll(reciFactors);
[6c438f]240 return getArg()->isInside(helper);
241}
242
[735940]243Vector Stretch_impl::translateIn(const Vector& point) const{
[5e588b5]244 Vector helper=point;
245 helper.ScaleAll(reciFactors);
[5de9da]246 return helper;
247}
248
[735940]249Vector Stretch_impl::translateOutPos(const Vector& point) const{
[5de9da]250 Vector helper=point;
251 helper.ScaleAll(factors);
252 return helper;
253}
254
[735940]255Vector Stretch_impl::translateOutNormal(const Vector& point) const{
[5de9da]256 Vector helper=point;
257 // the normalFactors are derived from appearances of the factors
258 // with in the vectorproduct
259 Vector normalFactors;
260 normalFactors[0]=factors[1]*factors[2];
261 normalFactors[1]=factors[0]*factors[2];
262 normalFactors[2]=factors[0]*factors[1];
263 helper.ScaleAll(normalFactors);
264 return helper;
[5e588b5]265}
266
[b92e4a]267std::string Stretch_impl::toString() const{
[955b91]268 std::stringstream sstr;
[cfda65]269 sstr << "stretch(" << getArg()->toString() << "," << factors << ")";
270 return sstr.str();
271}
272
[5e588b5]273Shape stretch(const Shape &arg, const Vector &factors){
274 Shape::impl_ptr impl = Shape::impl_ptr(new Stretch_impl(getShapeImpl(arg),factors));
275 return Shape(impl);
276}
277
278/************************* transform *****************/
279
[cca9ef]280Transform_impl::Transform_impl(const Shape::impl_ptr &_arg, const RealSpaceMatrix &_transformation) :
[5de9da]281 ShapeOpsBase_impl(_arg),transformation(_transformation)
[5e588b5]282{
283 transformationInv = transformation.invert();
284}
285
286Transform_impl::~Transform_impl(){}
287
[c67c65]288double Transform_impl::getVolume() const
289{
290 return getArg()->getVolume();
291}
292
293double Transform_impl::getSurfaceArea() const
294{
295 return getArg()->getSurfaceArea();
296}
297
[735940]298bool Transform_impl::isInside(const Vector& point) const{
[6c438f]299 return getArg()->isInside(transformationInv * point);
300}
301
[735940]302Vector Transform_impl::translateIn(const Vector& point) const{
[5de9da]303 return transformationInv * point;
304}
305
[735940]306Vector Transform_impl::translateOutPos(const Vector& point) const{
[5de9da]307 return transformation * point;
308}
309
[735940]310Vector Transform_impl::translateOutNormal(const Vector& point) const
311{
[cca9ef]312 RealSpaceMatrix mat = transformation.invert().transpose();
[5de9da]313 return mat * point;
[5e588b5]314}
315
[b92e4a]316std::string Transform_impl::toString() const{
[955b91]317 std::stringstream sstr;
[cfda65]318 sstr << "transform(" << getArg()->toString() << "," << transformation << ")";
319 return sstr.str();
320}
321
[cca9ef]322Shape transform(const Shape &arg, const RealSpaceMatrix &transformation){
[5e588b5]323 Shape::impl_ptr impl = Shape::impl_ptr(new Transform_impl(getShapeImpl(arg),transformation));
324 return Shape(impl);
325}
Note: See TracBrowser for help on using the repository browser.