source: src/Shapes/ShapeOps.cpp@ 8b58ac

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 8b58ac was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 9.0 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
40#include "Shapes/ShapeExceptions.hpp"
41#include "Shapes/ShapeOps.hpp"
42#include "Shapes/ShapeOps_impl.hpp"
43
44#include "LinearAlgebra/Vector.hpp"
45#include "CodePatterns/Assert.hpp"
46
47/*************** Base case ***********************/
48
49ShapeOpsBase_impl::ShapeOpsBase_impl(const Shape::impl_ptr &_arg) :
50 arg(_arg){}
51
52ShapeOpsBase_impl::~ShapeOpsBase_impl(){}
53
54bool ShapeOpsBase_impl::isInside(const Vector &point) const{
55 return arg->isInside(translateIn(point));
56}
57
58bool ShapeOpsBase_impl::isOnSurface(const Vector &point) const{
59 return arg->isOnSurface(translateIn(point));
60}
61
62Vector ShapeOpsBase_impl::getNormal(const Vector &point) const throw (NotOnSurfaceException){
63 Vector helper = translateIn(point);
64 if(!arg->isOnSurface(helper)){
65 throw NotOnSurfaceException() << ShapeVector(&helper);
66 }
67 Vector res = translateOutNormal(arg->getNormal(helper));
68 res.Normalize();
69 return res;
70}
71
72Vector ShapeOpsBase_impl::getCenter() const
73{
74 return arg->getCenter();
75}
76
77double ShapeOpsBase_impl::getRadius() const
78{
79 return translateOutPos(Vector(arg->getRadius(), 0., 0.)).Norm();
80}
81
82
83LineSegmentSet ShapeOpsBase_impl::getLineIntersections(const Line &line) const{
84 Line newLine(translateIn(line.getOrigin()),translateIn(line.getDirection()));
85 LineSegmentSet res(line);
86 LineSegmentSet helper = getArg()->getLineIntersections(newLine);
87 for(LineSegmentSet::iterator iter = helper.begin();iter!=helper.end();++iter){
88 LinePoint lpBegin = iter->getBegin();
89 LinePoint lpEnd = iter->getBegin();
90 // translate both linepoints
91 lpBegin = lpBegin.isNegInfinity()?
92 line.negEndpoint():
93 line.getLinePoint(translateOutPos(lpBegin.getPoint()));
94 lpEnd = lpEnd.isPosInfinity()?
95 line.posEndpoint():
96 line.getLinePoint(translateOutPos(lpEnd.getPoint()));
97 res.insert(LineSegment(lpBegin,lpEnd));
98 }
99 return res;
100}
101
102enum ShapeType ShapeOpsBase_impl::getType() const {
103 return getArg()->getType();
104}
105
106std::vector<Vector> ShapeOpsBase_impl::getHomogeneousPointsOnSurface(const size_t N) const {
107 std::vector<Vector> PointsOnSurface = getArg()->getHomogeneousPointsOnSurface(N);
108 std::transform(PointsOnSurface.begin(), PointsOnSurface.end(), PointsOnSurface.begin(),
109 boost::bind(&ShapeOpsBase_impl::translateOutPos, this, _1) );
110 return PointsOnSurface;
111}
112
113std::vector<Vector> ShapeOpsBase_impl::getHomogeneousPointsInVolume(const size_t N) const {
114 std::vector<Vector> PointsOnSurface = getArg()->getHomogeneousPointsInVolume(N);
115 std::transform(PointsOnSurface.begin(), PointsOnSurface.end(), PointsOnSurface.begin(),
116 boost::bind(&ShapeOpsBase_impl::translateOutPos, this, _1) );
117 return PointsOnSurface;
118}
119
120Shape::impl_ptr ShapeOpsBase_impl::getArg() const{
121 return arg;
122}
123
124/********************* Resize ********************/
125
126Resize_impl::Resize_impl(const Shape::impl_ptr &_arg,double _size) :
127 ShapeOpsBase_impl(_arg), size(_size)
128{
129 ASSERT(size>0,"Cannot resize a Shape to size zero or below");
130}
131
132Resize_impl::~Resize_impl(){}
133
134double Resize_impl::getVolume() const
135{
136 return getArg()->getVolume() * size * size * size;
137}
138
139double Resize_impl::getSurfaceArea() const
140{
141 return getArg()->getSurfaceArea() * size * size;
142}
143
144
145bool Resize_impl::isInside(const Vector& point) const{
146 return getArg()->isInside((1./size) * point);
147}
148
149Vector Resize_impl::translateIn(const Vector& point) const{
150 return (1./size) * point;
151}
152
153Vector Resize_impl::translateOutPos(const Vector& point) const{
154 return size * point;
155}
156
157Vector Resize_impl::translateOutNormal(const Vector& point) const{
158 return point;
159}
160
161std::string Resize_impl::toString() const{
162 std::stringstream sstr;
163 sstr << "resize(" << getArg()->toString() << "," << size << ")";
164 return sstr.str();
165}
166
167Shape resize(const Shape &arg,double size){
168 Shape::impl_ptr impl = Shape::impl_ptr(new Resize_impl(getShapeImpl(arg),size));
169 return Shape(impl);
170}
171
172/*************************** translate *******************/
173
174Translate_impl::Translate_impl(const Shape::impl_ptr &_arg, const Vector &_offset) :
175 ShapeOpsBase_impl(_arg),offset(_offset)
176{}
177
178Translate_impl::~Translate_impl(){}
179
180bool Translate_impl::isInside(const Vector& point) const{
181 return getArg()->isInside(point-offset);
182}
183
184Vector Translate_impl::getCenter() const
185{
186 return getArg()->getCenter()+offset;
187}
188
189double Translate_impl::getRadius() const
190{
191 return getArg()->getRadius();
192}
193
194double Translate_impl::getVolume() const
195{
196 return getArg()->getVolume();
197}
198
199double Translate_impl::getSurfaceArea() const
200{
201 return getArg()->getSurfaceArea();
202}
203
204Vector Translate_impl::translateIn(const Vector& point) const{
205 return point-offset;
206}
207
208Vector Translate_impl::translateOutPos(const Vector& point) const{
209 return point+offset;
210}
211
212Vector Translate_impl::translateOutNormal(const Vector& point) const{
213 return point;
214}
215
216std::string Translate_impl::toString() const{
217 std::stringstream sstr;
218 sstr << "translate(" << getArg()->toString() << "," << offset << ")";
219 return sstr.str();
220}
221
222Shape translate(const Shape &arg, const Vector &offset){
223 Shape::impl_ptr impl = Shape::impl_ptr(new Translate_impl(getShapeImpl(arg),offset));
224 return Shape(impl);
225}
226
227/*********************** stretch ******************/
228
229Stretch_impl::Stretch_impl(const Shape::impl_ptr &_arg, const Vector &_factors) :
230 ShapeOpsBase_impl(_arg),factors(_factors)
231{
232 for(int i = NDIM;i--;){
233 ASSERT(factors[i]>0.,"cannot stretch a shape by a negative amount");
234 reciFactors[i] = 1./factors[i];
235 }
236}
237
238Stretch_impl::~Stretch_impl(){}
239
240double Stretch_impl::getVolume() const
241{
242 // TODO
243 return -1.;
244}
245
246double Stretch_impl::getSurfaceArea() const
247{
248 // TODO
249 return -1.;
250}
251
252bool Stretch_impl::isInside(const Vector& point) const{
253 Vector helper=point;
254 helper.ScaleAll(reciFactors);
255 return getArg()->isInside(helper);
256}
257
258Vector Stretch_impl::translateIn(const Vector& point) const{
259 Vector helper=point;
260 helper.ScaleAll(reciFactors);
261 return helper;
262}
263
264Vector Stretch_impl::translateOutPos(const Vector& point) const{
265 Vector helper=point;
266 helper.ScaleAll(factors);
267 return helper;
268}
269
270Vector Stretch_impl::translateOutNormal(const Vector& point) const{
271 Vector helper=point;
272 // the normalFactors are derived from appearances of the factors
273 // with in the vectorproduct
274 Vector normalFactors;
275 normalFactors[0]=factors[1]*factors[2];
276 normalFactors[1]=factors[0]*factors[2];
277 normalFactors[2]=factors[0]*factors[1];
278 helper.ScaleAll(normalFactors);
279 return helper;
280}
281
282std::string Stretch_impl::toString() const{
283 std::stringstream sstr;
284 sstr << "stretch(" << getArg()->toString() << "," << factors << ")";
285 return sstr.str();
286}
287
288Shape stretch(const Shape &arg, const Vector &factors){
289 Shape::impl_ptr impl = Shape::impl_ptr(new Stretch_impl(getShapeImpl(arg),factors));
290 return Shape(impl);
291}
292
293/************************* transform *****************/
294
295Transform_impl::Transform_impl(const Shape::impl_ptr &_arg, const RealSpaceMatrix &_transformation) :
296 ShapeOpsBase_impl(_arg),transformation(_transformation)
297{
298 transformationInv = transformation.invert();
299}
300
301Transform_impl::~Transform_impl(){}
302
303double Transform_impl::getVolume() const
304{
305 return getArg()->getVolume();
306}
307
308double Transform_impl::getSurfaceArea() const
309{
310 return getArg()->getSurfaceArea();
311}
312
313bool Transform_impl::isInside(const Vector& point) const{
314 return getArg()->isInside(transformationInv * point);
315}
316
317Vector Transform_impl::translateIn(const Vector& point) const{
318 return transformationInv * point;
319}
320
321Vector Transform_impl::translateOutPos(const Vector& point) const{
322 return transformation * point;
323}
324
325Vector Transform_impl::translateOutNormal(const Vector& point) const
326{
327 RealSpaceMatrix mat = transformation.invert().transpose();
328 return mat * point;
329}
330
331std::string Transform_impl::toString() const{
332 std::stringstream sstr;
333 sstr << "transform(" << getArg()->toString() << "," << transformation << ")";
334 return sstr.str();
335}
336
337Shape transform(const Shape &arg, const RealSpaceMatrix &transformation){
338 Shape::impl_ptr impl = Shape::impl_ptr(new Transform_impl(getShapeImpl(arg),transformation));
339 return Shape(impl);
340}
Note: See TracBrowser for help on using the repository browser.