source: src/Shapes/ShapeOps.cpp@ b88fe4

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 b88fe4 was ad011c, checked in by Frederik Heber <heber@…>, 14 years ago

CodePatterns places all includes now in subfolder CodePatterns/.

  • change all includes accordingly.
  • this was necessary as Helpers and Patterns are not very distinctive names for include folders. Already now, we had a conflict between Helpers from CodePatterns and Helpers from this project.
  • changed compilation test in ax_codepatterns.m4 when changing CodePatterns includes.
  • Property mode set to 100644
File size: 8.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * ShapeOps.cpp
10 *
11 * Created on: Jun 18, 2010
12 * Author: crueger
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "Shapes/ShapeOps.hpp"
23#include "Shapes/ShapeOps_impl.hpp"
24
25#include "LinearAlgebra/Vector.hpp"
26#include "CodePatterns/Assert.hpp"
27
28/*************** Base case ***********************/
29
30ShapeOpsBase_impl::ShapeOpsBase_impl(const Shape::impl_ptr &_arg) :
31 arg(_arg){}
32
33ShapeOpsBase_impl::~ShapeOpsBase_impl(){}
34
35bool ShapeOpsBase_impl::isInside(const Vector &point){
36 return arg->isInside(translateIn(point));
37}
38
39bool ShapeOpsBase_impl::isOnSurface(const Vector &point){
40 return arg->isOnSurface(translateIn(point));
41}
42
43Vector ShapeOpsBase_impl::getNormal(const Vector &point) throw (NotOnSurfaceException){
44 Vector helper = translateIn(point);
45 if(!arg->isOnSurface(helper)){
46 throw NotOnSurfaceException(__FILE__,__LINE__);
47 }
48 Vector res = translateOutNormal(arg->getNormal(helper));
49 res.Normalize();
50 return res;
51}
52
53LineSegmentSet ShapeOpsBase_impl::getLineIntersections(const Line &line){
54 Line newLine(translateIn(line.getOrigin()),translateIn(line.getDirection()));
55 LineSegmentSet res(line);
56 LineSegmentSet helper = getArg()->getLineIntersections(newLine);
57 for(LineSegmentSet::iterator iter = helper.begin();iter!=helper.end();++iter){
58 LinePoint lpBegin = iter->getBegin();
59 LinePoint lpEnd = iter->getBegin();
60 // translate both linepoints
61 lpBegin = lpBegin.isNegInfinity()?
62 line.negEndpoint():
63 line.getLinePoint(translateOutPos(lpBegin.getPoint()));
64 lpEnd = lpEnd.isPosInfinity()?
65 line.posEndpoint():
66 line.getLinePoint(translateOutPos(lpEnd.getPoint()));
67 res.insert(LineSegment(lpBegin,lpEnd));
68 }
69 return res;
70}
71
72std::vector<Vector> ShapeOpsBase_impl::getHomogeneousPointsOnSurface(const size_t N) const {
73 return getArg()->getHomogeneousPointsOnSurface(N);;
74}
75
76Shape::impl_ptr ShapeOpsBase_impl::getArg() const{
77 return arg;
78}
79
80/********************* Resize ********************/
81
82Resize_impl::Resize_impl(const Shape::impl_ptr &_arg,double _size) :
83 ShapeOpsBase_impl(_arg), size(_size)
84{
85 ASSERT(size>0,"Cannot resize a Shape to size zero or below");
86}
87
88Resize_impl::~Resize_impl(){}
89
90bool Resize_impl::isInside(const Vector& point){
91 return getArg()->isInside((1/size) * point);
92}
93
94Vector Resize_impl::translateIn(const Vector& point){
95 return (1/size) * point;
96}
97
98Vector Resize_impl::translateOutPos(const Vector& point){
99 return size * point;
100}
101
102Vector Resize_impl::translateOutNormal(const Vector& point){
103 return point;
104}
105
106string Resize_impl::toString(){
107 stringstream sstr;
108 sstr << "resize(" << getArg()->toString() << "," << size << ")";
109 return sstr.str();
110}
111
112std::vector<Vector> Resize_impl::getHomogeneousPointsOnSurface(const size_t N) const {
113 std::vector<Vector> PointsOnSurface = getArg()->getHomogeneousPointsOnSurface(N);
114 for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) {
115 *iter *= size;
116 }
117 return PointsOnSurface;
118}
119
120
121Shape resize(const Shape &arg,double size){
122 Shape::impl_ptr impl = Shape::impl_ptr(new Resize_impl(getShapeImpl(arg),size));
123 return Shape(impl);
124}
125
126/*************************** translate *******************/
127
128Translate_impl::Translate_impl(const Shape::impl_ptr &_arg, const Vector &_offset) :
129 ShapeOpsBase_impl(_arg),offset(_offset)
130{}
131
132Translate_impl::~Translate_impl(){}
133
134bool Translate_impl::isInside(const Vector& point){
135 return getArg()->isInside(point-offset);
136}
137
138Vector Translate_impl::translateIn(const Vector& point){
139 return point-offset;
140}
141
142Vector Translate_impl::translateOutPos(const Vector& point){
143 return point+offset;
144}
145
146Vector Translate_impl::translateOutNormal(const Vector& point){
147 return point;
148}
149
150string Translate_impl::toString(){
151 stringstream sstr;
152 sstr << "translate(" << getArg()->toString() << "," << offset << ")";
153 return sstr.str();
154}
155
156std::vector<Vector> Translate_impl::getHomogeneousPointsOnSurface(const size_t N) const {
157 std::vector<Vector> PointsOnSurface = getArg()->getHomogeneousPointsOnSurface(N);
158 for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) {
159 *iter += offset;
160 }
161 return PointsOnSurface;
162}
163
164Shape translate(const Shape &arg, const Vector &offset){
165 Shape::impl_ptr impl = Shape::impl_ptr(new Translate_impl(getShapeImpl(arg),offset));
166 return Shape(impl);
167}
168
169/*********************** stretch ******************/
170
171Stretch_impl::Stretch_impl(const Shape::impl_ptr &_arg, const Vector &_factors) :
172 ShapeOpsBase_impl(_arg),factors(_factors)
173{
174 ASSERT(factors[0]>0,"cannot stretch a shape by a negative amount");
175 ASSERT(factors[1]>0,"cannot stretch a shape by a negative amount");
176 ASSERT(factors[2]>0,"cannot stretch a shape by a negative amount");
177 for(int i = NDIM;i--;){
178 reciFactors[i] = 1/factors[i];
179 }
180}
181
182Stretch_impl::~Stretch_impl(){}
183
184bool Stretch_impl::isInside(const Vector& point){
185 Vector helper=point;
186 helper.ScaleAll(reciFactors);
187 return getArg()->isInside(helper);
188}
189
190Vector Stretch_impl::translateIn(const Vector& point){
191 Vector helper=point;
192 helper.ScaleAll(reciFactors);
193 return helper;
194}
195
196Vector Stretch_impl::translateOutPos(const Vector& point){
197 Vector helper=point;
198 helper.ScaleAll(factors);
199 return helper;
200}
201
202Vector Stretch_impl::translateOutNormal(const Vector& point){
203 Vector helper=point;
204 // the normalFactors are derived from appearances of the factors
205 // with in the vectorproduct
206 Vector normalFactors;
207 normalFactors[0]=factors[1]*factors[2];
208 normalFactors[1]=factors[0]*factors[2];
209 normalFactors[2]=factors[0]*factors[1];
210 helper.ScaleAll(normalFactors);
211 return helper;
212}
213
214string Stretch_impl::toString(){
215 stringstream sstr;
216 sstr << "stretch(" << getArg()->toString() << "," << factors << ")";
217 return sstr.str();
218}
219
220std::vector<Vector> Stretch_impl::getHomogeneousPointsOnSurface(const size_t N) const {
221 std::vector<Vector> PointsOnSurface = getArg()->getHomogeneousPointsOnSurface(N);
222 for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) {
223 (*iter).ScaleAll(reciFactors);
224 }
225 return PointsOnSurface;
226}
227
228Shape stretch(const Shape &arg, const Vector &factors){
229 Shape::impl_ptr impl = Shape::impl_ptr(new Stretch_impl(getShapeImpl(arg),factors));
230 return Shape(impl);
231}
232
233/************************* transform *****************/
234
235Transform_impl::Transform_impl(const Shape::impl_ptr &_arg, const RealSpaceMatrix &_transformation) :
236 ShapeOpsBase_impl(_arg),transformation(_transformation)
237{
238 transformationInv = transformation.invert();
239}
240
241Transform_impl::~Transform_impl(){}
242
243bool Transform_impl::isInside(const Vector& point){
244 return getArg()->isInside(transformationInv * point);
245}
246
247Vector Transform_impl::translateIn(const Vector& point){
248 return transformationInv * point;
249}
250
251Vector Transform_impl::translateOutPos(const Vector& point){
252 return transformation * point;
253}
254
255Vector Transform_impl::translateOutNormal(const Vector& point){
256 RealSpaceMatrix mat = transformation.invert().transpose();
257 return mat * point;
258}
259
260string Transform_impl::toString(){
261 stringstream sstr;
262 sstr << "transform(" << getArg()->toString() << "," << transformation << ")";
263 return sstr.str();
264}
265
266std::vector<Vector> Transform_impl::getHomogeneousPointsOnSurface(const size_t N) const {
267 std::vector<Vector> PointsOnSurface = getArg()->getHomogeneousPointsOnSurface(N);
268 for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) {
269 *iter = transformation * (*iter);
270 }
271 return PointsOnSurface;
272}
273
274Shape transform(const Shape &arg, const RealSpaceMatrix &transformation){
275 Shape::impl_ptr impl = Shape::impl_ptr(new Transform_impl(getShapeImpl(arg),transformation));
276 return Shape(impl);
277}
Note: See TracBrowser for help on using the repository browser.