| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
|---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | /*
|
|---|
| 9 | * Shape.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 "CodePatterns/Assert.hpp"
|
|---|
| 23 | #include "LinearAlgebra/Vector.hpp"
|
|---|
| 24 |
|
|---|
| 25 | #include "Shapes/Shape.hpp"
|
|---|
| 26 | #include "Shapes/Shape_impl.hpp"
|
|---|
| 27 | #include "Shapes/ShapeExceptions.hpp"
|
|---|
| 28 | #include "Shapes/ShapeType.hpp"
|
|---|
| 29 |
|
|---|
| 30 | #include "Tesselation/ApproximateShapeArea.hpp"
|
|---|
| 31 | #include "Tesselation/ApproximateShapeVolume.hpp"
|
|---|
| 32 |
|
|---|
| 33 | #include <algorithm>
|
|---|
| 34 | #include <limits>
|
|---|
| 35 | #include <string>
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | Shape::Shape(const Shape& src) :
|
|---|
| 39 | impl(src.getImpl())
|
|---|
| 40 | {}
|
|---|
| 41 |
|
|---|
| 42 | Shape::~Shape(){}
|
|---|
| 43 |
|
|---|
| 44 | bool Shape::isInside(const Vector &point) const{
|
|---|
| 45 | return impl->isInside(point);
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | bool Shape::isOnSurface(const Vector &point) const{
|
|---|
| 49 | return impl->isOnSurface(point);
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | Vector Shape::getNormal(const Vector &point) const throw (NotOnSurfaceException){
|
|---|
| 53 | return impl->getNormal(point);
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | Vector Shape::getCenter() const{
|
|---|
| 57 | return impl->getCenter();
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | double Shape::getRadius() const{
|
|---|
| 61 | return impl->getRadius();
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | /** Returns the volume of the Shape.
|
|---|
| 65 | *
|
|---|
| 66 | * If the underlying implementation does not have a working implementation,
|
|---|
| 67 | * i.e. returns -1., then we use an approximate method to calculate the
|
|---|
| 68 | * volume via a mesh of grid points and checking for isInside (basically
|
|---|
| 69 | * a Monte-Carlo integration of the volume).
|
|---|
| 70 | *
|
|---|
| 71 | * \return volume of the shape
|
|---|
| 72 | */
|
|---|
| 73 | double Shape::getVolume() const
|
|---|
| 74 | {
|
|---|
| 75 | const double volume = impl->getVolume();
|
|---|
| 76 | if (volume != -1.) {
|
|---|
| 77 | return volume;
|
|---|
| 78 | } else {
|
|---|
| 79 | ApproximateShapeVolume Approximator(*this);
|
|---|
| 80 | return Approximator();
|
|---|
| 81 | }
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | /** Returns the surface area of the Shape.
|
|---|
| 85 | *
|
|---|
| 86 | * If the underlying implementation does not have a working implementation,
|
|---|
| 87 | * i.e. returns -1., then we use the working filling of the shapes surface
|
|---|
| 88 | * with points and subsequent tesselation and obtaining the approximate
|
|---|
| 89 | * surface area therefrom.
|
|---|
| 90 | *
|
|---|
| 91 | * @return surface area of the Shape
|
|---|
| 92 | */
|
|---|
| 93 | double Shape::getSurfaceArea() const
|
|---|
| 94 | {
|
|---|
| 95 | const double surfacearea = impl->getSurfaceArea();
|
|---|
| 96 | if (surfacearea != -1.) {
|
|---|
| 97 | return surfacearea;
|
|---|
| 98 | } else {
|
|---|
| 99 | ApproximateShapeArea Approximator(*this);
|
|---|
| 100 | return Approximator();
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | LineSegmentSet Shape::getLineIntersections(const Line &line) const{
|
|---|
| 105 | return impl->getLineIntersections(line);
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | std::vector<Vector> Shape::getHomogeneousPointsOnSurface(const size_t N) const {
|
|---|
| 109 | return impl->getHomogeneousPointsOnSurface(N);
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | std::vector<Vector> Shape::getHomogeneousPointsInVolume(const size_t N) const {
|
|---|
| 113 | return impl->getHomogeneousPointsInVolume(N);
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | Shape::Shape(Shape::impl_ptr _impl) :
|
|---|
| 117 | impl(_impl)
|
|---|
| 118 | {}
|
|---|
| 119 |
|
|---|
| 120 | Shape &Shape::operator=(const Shape& rhs){
|
|---|
| 121 | if(&rhs!=this){
|
|---|
| 122 | impl=rhs.getImpl();
|
|---|
| 123 | }
|
|---|
| 124 | return *this;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | bool Shape::operator==(const Shape &rhs) const{
|
|---|
| 128 | return (this->getType() == rhs.getType());
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | std::string Shape::toString() const{
|
|---|
| 132 | return impl->toString();
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | enum ShapeType Shape::getType() const{
|
|---|
| 136 | return impl->getType();
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | Shape::impl_ptr Shape::getImpl() const{
|
|---|
| 140 | return impl;
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | // allows arbitrary friendship, but only if implementation is known
|
|---|
| 144 | Shape::impl_ptr getShapeImpl(const Shape &shape){
|
|---|
| 145 | return shape.getImpl();
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | /***************************** Some simple Shapes ***************************/
|
|---|
| 149 |
|
|---|
| 150 | Shape Everywhere(){
|
|---|
| 151 | static Shape::impl_ptr impl = Shape::impl_ptr(new Everywhere_impl());
|
|---|
| 152 | return Shape(impl);
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | Shape Nowhere(){
|
|---|
| 156 | static Shape::impl_ptr impl = Shape::impl_ptr(new Nowhere_impl());
|
|---|
| 157 | return Shape(impl);
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | /****************************** Operators ***********************************/
|
|---|
| 161 |
|
|---|
| 162 | // AND
|
|---|
| 163 |
|
|---|
| 164 | AndShape_impl::AndShape_impl(const Shape::impl_ptr &_lhs, const Shape::impl_ptr &_rhs) :
|
|---|
| 165 | lhs(_lhs),rhs(_rhs)
|
|---|
| 166 | {}
|
|---|
| 167 |
|
|---|
| 168 | AndShape_impl::~AndShape_impl(){}
|
|---|
| 169 |
|
|---|
| 170 | bool AndShape_impl::isInside(const Vector &point) const{
|
|---|
| 171 | return lhs->isInside(point) && rhs->isInside(point);
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | bool AndShape_impl::isOnSurface(const Vector &point) const{
|
|---|
| 175 | // check the number of surfaces that this point is on
|
|---|
| 176 | int surfaces =0;
|
|---|
| 177 | surfaces += lhs->isOnSurface(point);
|
|---|
| 178 | surfaces += rhs->isOnSurface(point);
|
|---|
| 179 |
|
|---|
| 180 | switch(surfaces){
|
|---|
| 181 | case 0:
|
|---|
| 182 | return false;
|
|---|
| 183 | // no break necessary
|
|---|
| 184 | case 1:
|
|---|
| 185 | // if it is inside for the object where it does not lie on
|
|---|
| 186 | // the surface the whole point lies inside
|
|---|
| 187 | return (lhs->isOnSurface(point) && rhs->isInside(point)) ||
|
|---|
| 188 | (rhs->isOnSurface(point) && lhs->isInside(point));
|
|---|
| 189 | // no break necessary
|
|---|
| 190 | case 2:
|
|---|
| 191 | {
|
|---|
| 192 | // it lies on both Shapes... could be an edge or an inner point
|
|---|
| 193 | // test the direction of the normals
|
|---|
| 194 | Vector direction=lhs->getNormal(point)+rhs->getNormal(point);
|
|---|
| 195 | // if the directions are opposite we lie on the inside
|
|---|
| 196 | return !direction.IsZero();
|
|---|
| 197 | }
|
|---|
| 198 | // no break necessary
|
|---|
| 199 | default:
|
|---|
| 200 | // if this happens there is something wrong
|
|---|
| 201 | ASSERT(0,"Default case should have never been used");
|
|---|
| 202 | }
|
|---|
| 203 | return false; // never reached
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | Vector AndShape_impl::getNormal(const Vector &point) const throw (NotOnSurfaceException){
|
|---|
| 207 | Vector res;
|
|---|
| 208 | if(!isOnSurface(point)){
|
|---|
| 209 | throw NotOnSurfaceException() << ShapeVector(&point);
|
|---|
| 210 | }
|
|---|
| 211 | res += lhs->isOnSurface(point)?lhs->getNormal(point):zeroVec;
|
|---|
| 212 | res += rhs->isOnSurface(point)?rhs->getNormal(point):zeroVec;
|
|---|
| 213 | res.Normalize();
|
|---|
| 214 | return res;
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | Vector AndShape_impl::getCenter() const
|
|---|
| 218 | {
|
|---|
| 219 | // calculate closest position on sphere surface to other center ..
|
|---|
| 220 | const Vector rhsDistance = rhs->getCenter() + rhs->getRadius()*((lhs->getCenter() - rhs->getCenter()).getNormalized());
|
|---|
| 221 | const Vector lhsDistance = lhs->getCenter() + lhs->getRadius()*((rhs->getCenter() - lhs->getCenter()).getNormalized());
|
|---|
| 222 | // .. and then it's right in between those two
|
|---|
| 223 | return 0.5*(rhsDistance + lhsDistance);
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | double AndShape_impl::getRadius() const
|
|---|
| 227 | {
|
|---|
| 228 | const double distance = (lhs->getCenter() - rhs->getCenter()).Norm();
|
|---|
| 229 | const double minradii = std::min(lhs->getRadius(), rhs->getRadius());
|
|---|
| 230 | // if no intersection
|
|---|
| 231 | if (distance > (lhs->getRadius() + rhs->getRadius()))
|
|---|
| 232 | return 0.;
|
|---|
| 233 | else // if intersection it can only be the smaller one
|
|---|
| 234 | return minradii;
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | double AndShape_impl::getVolume() const
|
|---|
| 238 | {
|
|---|
| 239 | // TODO
|
|---|
| 240 | return -1.;
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | double AndShape_impl::getSurfaceArea() const
|
|---|
| 244 | {
|
|---|
| 245 | // TODO
|
|---|
| 246 | return -1.;
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|
| 249 | LineSegmentSet AndShape_impl::getLineIntersections(const Line &line) const{
|
|---|
| 250 | return intersect(lhs->getLineIntersections(line),rhs->getLineIntersections(line));
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | std::string AndShape_impl::toString() const{
|
|---|
| 254 | return std::string("(") + lhs->toString() + std::string("&&") + rhs->toString() + std::string(")");
|
|---|
| 255 | }
|
|---|
| 256 |
|
|---|
| 257 | enum ShapeType AndShape_impl::getType() const{
|
|---|
| 258 | return CombinedType;
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | std::vector<Vector> AndShape_impl::getHomogeneousPointsOnSurface(const size_t N) const {
|
|---|
| 262 | std::vector<Vector> PointsOnSurface_lhs = lhs->getHomogeneousPointsOnSurface(N);
|
|---|
| 263 | std::vector<Vector> PointsOnSurface_rhs = rhs->getHomogeneousPointsOnSurface(N);
|
|---|
| 264 | std::vector<Vector> PointsOnSurface;
|
|---|
| 265 |
|
|---|
| 266 | for (std::vector<Vector>::const_iterator iter = PointsOnSurface_lhs.begin(); iter != PointsOnSurface_lhs.end(); ++iter) {
|
|---|
| 267 | if (rhs->isInside(*iter))
|
|---|
| 268 | PointsOnSurface.push_back(*iter);
|
|---|
| 269 | }
|
|---|
| 270 | for (std::vector<Vector>::const_iterator iter = PointsOnSurface_rhs.begin(); iter != PointsOnSurface_rhs.end(); ++iter) {
|
|---|
| 271 | if (lhs->isInside(*iter))
|
|---|
| 272 | PointsOnSurface.push_back(*iter);
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | return PointsOnSurface;
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | std::vector<Vector> AndShape_impl::getHomogeneousPointsInVolume(const size_t N) const {
|
|---|
| 279 | ASSERT(0,
|
|---|
| 280 | "AndShape_impl::getHomogeneousPointsInVolume() - not implemented.");
|
|---|
| 281 | return std::vector<Vector>();
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 | Shape operator&&(const Shape &lhs,const Shape &rhs){
|
|---|
| 286 | Shape::impl_ptr newImpl = Shape::impl_ptr(new AndShape_impl(getShapeImpl(lhs),getShapeImpl(rhs)));
|
|---|
| 287 | return Shape(newImpl);
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | // OR
|
|---|
| 291 |
|
|---|
| 292 | OrShape_impl::OrShape_impl(const Shape::impl_ptr &_lhs, const Shape::impl_ptr &_rhs) :
|
|---|
| 293 | lhs(_lhs),rhs(_rhs)
|
|---|
| 294 | {}
|
|---|
| 295 |
|
|---|
| 296 | OrShape_impl::~OrShape_impl(){}
|
|---|
| 297 |
|
|---|
| 298 | bool OrShape_impl::isInside(const Vector &point) const{
|
|---|
| 299 | return rhs->isInside(point) || lhs->isInside(point);
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 | bool OrShape_impl::isOnSurface(const Vector &point) const{
|
|---|
| 303 | // check the number of surfaces that this point is on
|
|---|
| 304 | int surfaces =0;
|
|---|
| 305 | surfaces += lhs->isOnSurface(point);
|
|---|
| 306 | surfaces += rhs->isOnSurface(point);
|
|---|
| 307 |
|
|---|
| 308 | switch(surfaces){
|
|---|
| 309 | case 0:
|
|---|
| 310 | return false;
|
|---|
| 311 | // no break necessary
|
|---|
| 312 | case 1:
|
|---|
| 313 | // if it is inside for the object where it does not lie on
|
|---|
| 314 | // the surface the whole point lies inside
|
|---|
| 315 | return (lhs->isOnSurface(point) && !rhs->isInside(point)) ||
|
|---|
| 316 | (rhs->isOnSurface(point) && !lhs->isInside(point));
|
|---|
| 317 | // no break necessary
|
|---|
| 318 | case 2:
|
|---|
| 319 | {
|
|---|
| 320 | // it lies on both Shapes... could be an edge or an inner point
|
|---|
| 321 | // test the direction of the normals
|
|---|
| 322 | Vector direction=lhs->getNormal(point)+rhs->getNormal(point);
|
|---|
| 323 | // if the directions are opposite we lie on the inside
|
|---|
| 324 | return !direction.IsZero();
|
|---|
| 325 | }
|
|---|
| 326 | // no break necessary
|
|---|
| 327 | default:
|
|---|
| 328 | // if this happens there is something wrong
|
|---|
| 329 | ASSERT(0,"Default case should have never been used");
|
|---|
| 330 | }
|
|---|
| 331 | return false; // never reached
|
|---|
| 332 | }
|
|---|
| 333 |
|
|---|
| 334 | Vector OrShape_impl::getNormal(const Vector &point) const throw (NotOnSurfaceException){
|
|---|
| 335 | Vector res;
|
|---|
| 336 | if(!isOnSurface(point)){
|
|---|
| 337 | throw NotOnSurfaceException() << ShapeVector(&point);
|
|---|
| 338 | }
|
|---|
| 339 | res += lhs->isOnSurface(point)?lhs->getNormal(point):zeroVec;
|
|---|
| 340 | res += rhs->isOnSurface(point)?rhs->getNormal(point):zeroVec;
|
|---|
| 341 | res.Normalize();
|
|---|
| 342 | return res;
|
|---|
| 343 | }
|
|---|
| 344 |
|
|---|
| 345 | Vector OrShape_impl::getCenter() const
|
|---|
| 346 | {
|
|---|
| 347 | // calculate furthest position on sphere surface to other center ..
|
|---|
| 348 | const Vector rhsDistance = rhs->getCenter() + rhs->getRadius()*((rhs->getCenter() - lhs->getCenter()).getNormalized());
|
|---|
| 349 | const Vector lhsDistance = lhs->getCenter() + lhs->getRadius()*((lhs->getCenter() - rhs->getCenter()).getNormalized());
|
|---|
| 350 | // .. and then it's right in between those two
|
|---|
| 351 | return .5*(rhsDistance + lhsDistance);
|
|---|
| 352 | }
|
|---|
| 353 |
|
|---|
| 354 | double OrShape_impl::getRadius() const
|
|---|
| 355 | {
|
|---|
| 356 | const Vector rhsDistance = rhs->getCenter() + rhs->getRadius()*((rhs->getCenter() - lhs->getCenter()).getNormalized());
|
|---|
| 357 | const Vector lhsDistance = lhs->getCenter() + lhs->getRadius()*((lhs->getCenter() - rhs->getCenter()).getNormalized());
|
|---|
| 358 | return .5*(rhsDistance - lhsDistance).Norm();
|
|---|
| 359 | }
|
|---|
| 360 |
|
|---|
| 361 | double OrShape_impl::getVolume() const
|
|---|
| 362 | {
|
|---|
| 363 | // TODO
|
|---|
| 364 | return -1.;
|
|---|
| 365 | }
|
|---|
| 366 |
|
|---|
| 367 | double OrShape_impl::getSurfaceArea() const
|
|---|
| 368 | {
|
|---|
| 369 | // TODO
|
|---|
| 370 | return -1.;
|
|---|
| 371 | }
|
|---|
| 372 |
|
|---|
| 373 | LineSegmentSet OrShape_impl::getLineIntersections(const Line &line) const{
|
|---|
| 374 | return merge(lhs->getLineIntersections(line),rhs->getLineIntersections(line));
|
|---|
| 375 | }
|
|---|
| 376 |
|
|---|
| 377 | std::string OrShape_impl::toString() const{
|
|---|
| 378 | return std::string("(") + lhs->toString() + std::string("||") + rhs->toString() + std::string(")");
|
|---|
| 379 | }
|
|---|
| 380 |
|
|---|
| 381 | enum ShapeType OrShape_impl::getType() const{
|
|---|
| 382 | return CombinedType;
|
|---|
| 383 | }
|
|---|
| 384 |
|
|---|
| 385 | std::vector<Vector> OrShape_impl::getHomogeneousPointsOnSurface(const size_t N) const {
|
|---|
| 386 | std::vector<Vector> PointsOnSurface_lhs = lhs->getHomogeneousPointsOnSurface(N);
|
|---|
| 387 | std::vector<Vector> PointsOnSurface_rhs = rhs->getHomogeneousPointsOnSurface(N);
|
|---|
| 388 | std::vector<Vector> PointsOnSurface;
|
|---|
| 389 |
|
|---|
| 390 | for (std::vector<Vector>::const_iterator iter = PointsOnSurface_lhs.begin(); iter != PointsOnSurface_lhs.end(); ++iter) {
|
|---|
| 391 | if (!rhs->isInside(*iter))
|
|---|
| 392 | PointsOnSurface.push_back(*iter);
|
|---|
| 393 | }
|
|---|
| 394 | for (std::vector<Vector>::const_iterator iter = PointsOnSurface_rhs.begin(); iter != PointsOnSurface_rhs.end(); ++iter) {
|
|---|
| 395 | if (!lhs->isInside(*iter))
|
|---|
| 396 | PointsOnSurface.push_back(*iter);
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| 399 | return PointsOnSurface;
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | std::vector<Vector> OrShape_impl::getHomogeneousPointsInVolume(const size_t N) const {
|
|---|
| 403 | ASSERT(0,
|
|---|
| 404 | "OrShape_impl::getHomogeneousPointsInVolume() - not implemented.");
|
|---|
| 405 | return std::vector<Vector>();
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | Shape operator||(const Shape &lhs,const Shape &rhs){
|
|---|
| 409 | Shape::impl_ptr newImpl = Shape::impl_ptr(new OrShape_impl(getShapeImpl(lhs),getShapeImpl(rhs)));
|
|---|
| 410 | return Shape(newImpl);
|
|---|
| 411 | }
|
|---|
| 412 |
|
|---|
| 413 | // NOT
|
|---|
| 414 |
|
|---|
| 415 | NotShape_impl::NotShape_impl(const Shape::impl_ptr &_arg) :
|
|---|
| 416 | arg(_arg)
|
|---|
| 417 | {}
|
|---|
| 418 |
|
|---|
| 419 | NotShape_impl::~NotShape_impl(){}
|
|---|
| 420 |
|
|---|
| 421 | bool NotShape_impl::isInside(const Vector &point) const{
|
|---|
| 422 | return !arg->isInside(point);
|
|---|
| 423 | }
|
|---|
| 424 |
|
|---|
| 425 | bool NotShape_impl::isOnSurface(const Vector &point) const{
|
|---|
| 426 | return arg->isOnSurface(point);
|
|---|
| 427 | }
|
|---|
| 428 |
|
|---|
| 429 | Vector NotShape_impl::getNormal(const Vector &point) const throw(NotOnSurfaceException){
|
|---|
| 430 | return -1.*arg->getNormal(point);
|
|---|
| 431 | }
|
|---|
| 432 |
|
|---|
| 433 | Vector NotShape_impl::getCenter() const
|
|---|
| 434 | {
|
|---|
| 435 | return arg->getCenter();
|
|---|
| 436 | }
|
|---|
| 437 |
|
|---|
| 438 | double NotShape_impl::getRadius() const
|
|---|
| 439 | {
|
|---|
| 440 | return std::numeric_limits<double>::infinity();
|
|---|
| 441 | }
|
|---|
| 442 |
|
|---|
| 443 | double NotShape_impl::getVolume() const
|
|---|
| 444 | {
|
|---|
| 445 | // TODO
|
|---|
| 446 | return -1.; //-arg->getVolume();
|
|---|
| 447 | }
|
|---|
| 448 |
|
|---|
| 449 | double NotShape_impl::getSurfaceArea() const
|
|---|
| 450 | {
|
|---|
| 451 | // TODO
|
|---|
| 452 | return -1.; // -arg->getSurfaceArea();
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | LineSegmentSet NotShape_impl::getLineIntersections(const Line &line) const{
|
|---|
| 456 | return invert(arg->getLineIntersections(line));
|
|---|
| 457 | }
|
|---|
| 458 |
|
|---|
| 459 | std::string NotShape_impl::toString() const{
|
|---|
| 460 | return std::string("!") + arg->toString();
|
|---|
| 461 | }
|
|---|
| 462 |
|
|---|
| 463 | enum ShapeType NotShape_impl::getType() const{
|
|---|
| 464 | return CombinedType;
|
|---|
| 465 | }
|
|---|
| 466 |
|
|---|
| 467 | std::vector<Vector> NotShape_impl::getHomogeneousPointsOnSurface(const size_t N) const {
|
|---|
| 468 | // surfaces are the same, only normal direction is different
|
|---|
| 469 | return arg->getHomogeneousPointsOnSurface(N);
|
|---|
| 470 | }
|
|---|
| 471 |
|
|---|
| 472 | std::vector<Vector> NotShape_impl::getHomogeneousPointsInVolume(const size_t N) const {
|
|---|
| 473 | ASSERT(0,
|
|---|
| 474 | "NotShape_impl::getHomogeneousPointsInVolume() - not implemented.");
|
|---|
| 475 | return std::vector<Vector>();
|
|---|
| 476 | }
|
|---|
| 477 |
|
|---|
| 478 | Shape operator!(const Shape &arg){
|
|---|
| 479 | Shape::impl_ptr newImpl = Shape::impl_ptr(new NotShape_impl(getShapeImpl(arg)));
|
|---|
| 480 | return Shape(newImpl);
|
|---|
| 481 | }
|
|---|
| 482 |
|
|---|
| 483 | /**************** global operations *********************************/
|
|---|
| 484 | std::ostream &operator<<(std::ostream &ost,const Shape &shape){
|
|---|
| 485 | ost << shape.toString();
|
|---|
| 486 | return ost;
|
|---|
| 487 | }
|
|---|