| [bcf653] | 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 |  | 
|---|
| [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 |  | 
|---|
| [bbbad5] | 20 | #include "Helpers/MemDebug.hpp" | 
|---|
|  | 21 |  | 
|---|
| [e09b70] | 22 | #include "Shapes/ShapeOps.hpp" | 
|---|
|  | 23 | #include "Shapes/ShapeOps_impl.hpp" | 
|---|
|  | 24 |  | 
|---|
| [394529] | 25 | #include "Helpers/Assert.hpp" | 
|---|
|  | 26 |  | 
|---|
| [5e588b5] | 27 | /********************* Resize ********************/ | 
|---|
|  | 28 |  | 
|---|
| [e09b70] | 29 | Resize_impl::Resize_impl(const Shape::impl_ptr &_arg,double _size) : | 
|---|
|  | 30 | arg(_arg), size(_size) | 
|---|
| [394529] | 31 | { | 
|---|
|  | 32 | ASSERT(size>0,"Cannot resize a Shape to size zero or below"); | 
|---|
|  | 33 | } | 
|---|
| [e09b70] | 34 |  | 
|---|
|  | 35 | Resize_impl::~Resize_impl(){} | 
|---|
|  | 36 |  | 
|---|
|  | 37 | bool Resize_impl::isInside(const Vector& point){ | 
|---|
|  | 38 | return arg->isInside((1/size) * point); | 
|---|
|  | 39 | } | 
|---|
|  | 40 |  | 
|---|
| [c5186e] | 41 | std::vector<Vector> Resize_impl::getHomogeneousPointsOnSurface(const int N) const { | 
|---|
|  | 42 | std::vector<Vector> PointsOnSurface = arg->getHomogeneousPointsOnSurface(N); | 
|---|
|  | 43 | for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) { | 
|---|
|  | 44 | *iter *= size; | 
|---|
|  | 45 | } | 
|---|
|  | 46 | return PointsOnSurface; | 
|---|
|  | 47 | } | 
|---|
|  | 48 |  | 
|---|
|  | 49 |  | 
|---|
| [e09b70] | 50 | Shape resize(const Shape &arg,double size){ | 
|---|
|  | 51 | Shape::impl_ptr impl = Shape::impl_ptr(new Resize_impl(getShapeImpl(arg),size)); | 
|---|
|  | 52 | return Shape(impl); | 
|---|
|  | 53 | } | 
|---|
|  | 54 |  | 
|---|
| [5e588b5] | 55 | /*************************** translate *******************/ | 
|---|
|  | 56 |  | 
|---|
| [e09b70] | 57 | Translate_impl::Translate_impl(const Shape::impl_ptr &_arg, const Vector &_offset) : | 
|---|
|  | 58 | arg(_arg),offset(_offset) | 
|---|
|  | 59 | {} | 
|---|
|  | 60 |  | 
|---|
|  | 61 | Translate_impl::~Translate_impl(){} | 
|---|
|  | 62 |  | 
|---|
|  | 63 | bool Translate_impl::isInside(const Vector& point){ | 
|---|
|  | 64 | return arg->isInside(point-offset); | 
|---|
|  | 65 | } | 
|---|
|  | 66 |  | 
|---|
| [c5186e] | 67 | std::vector<Vector> Translate_impl::getHomogeneousPointsOnSurface(const int N) const { | 
|---|
|  | 68 | std::vector<Vector> PointsOnSurface = arg->getHomogeneousPointsOnSurface(N); | 
|---|
|  | 69 | for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) { | 
|---|
|  | 70 | *iter += offset; | 
|---|
|  | 71 | } | 
|---|
|  | 72 | return PointsOnSurface; | 
|---|
|  | 73 | } | 
|---|
|  | 74 |  | 
|---|
| [e09b70] | 75 | Shape translate(const Shape &arg, const Vector &offset){ | 
|---|
|  | 76 | Shape::impl_ptr impl = Shape::impl_ptr(new Translate_impl(getShapeImpl(arg),offset)); | 
|---|
|  | 77 | return Shape(impl); | 
|---|
|  | 78 | } | 
|---|
| [5e588b5] | 79 |  | 
|---|
|  | 80 | /*********************** stretch ******************/ | 
|---|
|  | 81 |  | 
|---|
|  | 82 | Stretch_impl::Stretch_impl(const Shape::impl_ptr &_arg, const Vector &_factors) : | 
|---|
|  | 83 | arg(_arg),factors(_factors) | 
|---|
|  | 84 | { | 
|---|
|  | 85 | ASSERT(factors[0]>0,"cannot stretch a shape by a negative amount"); | 
|---|
|  | 86 | ASSERT(factors[1]>0,"cannot stretch a shape by a negative amount"); | 
|---|
|  | 87 | ASSERT(factors[2]>0,"cannot stretch a shape by a negative amount"); | 
|---|
|  | 88 | for(int i = NDIM;i--;){ | 
|---|
|  | 89 | reciFactors[i] = 1/factors[i]; | 
|---|
|  | 90 | } | 
|---|
|  | 91 | } | 
|---|
|  | 92 |  | 
|---|
|  | 93 | Stretch_impl::~Stretch_impl(){} | 
|---|
|  | 94 |  | 
|---|
|  | 95 | bool Stretch_impl::isInside(const Vector& point){ | 
|---|
|  | 96 | Vector helper=point; | 
|---|
|  | 97 | helper.ScaleAll(reciFactors); | 
|---|
|  | 98 | return arg->isInside(helper); | 
|---|
|  | 99 | } | 
|---|
|  | 100 |  | 
|---|
| [c5186e] | 101 | std::vector<Vector> Stretch_impl::getHomogeneousPointsOnSurface(const int N) const { | 
|---|
|  | 102 | std::vector<Vector> PointsOnSurface = arg->getHomogeneousPointsOnSurface(N); | 
|---|
|  | 103 | for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) { | 
|---|
|  | 104 | (*iter).ScaleAll(reciFactors); | 
|---|
|  | 105 | } | 
|---|
|  | 106 | return PointsOnSurface; | 
|---|
|  | 107 | } | 
|---|
|  | 108 |  | 
|---|
| [5e588b5] | 109 | Shape stretch(const Shape &arg, const Vector &factors){ | 
|---|
|  | 110 | Shape::impl_ptr impl = Shape::impl_ptr(new Stretch_impl(getShapeImpl(arg),factors)); | 
|---|
|  | 111 | return Shape(impl); | 
|---|
|  | 112 | } | 
|---|
|  | 113 |  | 
|---|
|  | 114 | /************************* transform *****************/ | 
|---|
|  | 115 |  | 
|---|
|  | 116 | Transform_impl::Transform_impl(const Shape::impl_ptr &_arg, const Matrix &_transformation) : | 
|---|
|  | 117 | arg(_arg),transformation(_transformation) | 
|---|
|  | 118 | { | 
|---|
|  | 119 | transformationInv = transformation.invert(); | 
|---|
|  | 120 | } | 
|---|
|  | 121 |  | 
|---|
|  | 122 | Transform_impl::~Transform_impl(){} | 
|---|
|  | 123 |  | 
|---|
|  | 124 | bool Transform_impl::isInside(const Vector& point){ | 
|---|
|  | 125 | return arg->isInside(transformationInv * point); | 
|---|
|  | 126 | } | 
|---|
|  | 127 |  | 
|---|
| [c5186e] | 128 | std::vector<Vector> Transform_impl::getHomogeneousPointsOnSurface(const int N) const { | 
|---|
|  | 129 | std::vector<Vector> PointsOnSurface = arg->getHomogeneousPointsOnSurface(N); | 
|---|
|  | 130 | for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) { | 
|---|
|  | 131 | *iter = transformation * (*iter); | 
|---|
|  | 132 | } | 
|---|
|  | 133 | return PointsOnSurface; | 
|---|
|  | 134 | } | 
|---|
|  | 135 |  | 
|---|
| [5e588b5] | 136 | Shape transform(const Shape &arg, const Matrix &transformation){ | 
|---|
|  | 137 | Shape::impl_ptr impl = Shape::impl_ptr(new Transform_impl(getShapeImpl(arg),transformation)); | 
|---|
|  | 138 | return Shape(impl); | 
|---|
|  | 139 | } | 
|---|