source: src/Shapes/ShapeOps.cpp@ f3526d

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

Added methods to output shapes on the screen

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