source: src/Shapes/ShapeOps.cpp@ 87d6bd

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 87d6bd was 08a09ed, checked in by Frederik Heber <heber@…>, 12 years ago

Implemented getSurfaceArea() and getVolume() for Stretch_imp and Transform_impl.

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