1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 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 | * ApproximateShapeVolume.cpp
|
---|
10 | *
|
---|
11 | * Created on: Jan 30, 2012
|
---|
12 | * Author: heber
|
---|
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 "ApproximateShapeVolume.hpp"
|
---|
23 |
|
---|
24 | #include <boost/bind.hpp>
|
---|
25 | #include <vector>
|
---|
26 |
|
---|
27 | #include "Box.hpp"
|
---|
28 | #include "Filling/Mesh/CubeMesh.hpp"
|
---|
29 | #include "Filling/NodeTypes.hpp"
|
---|
30 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
|
---|
31 | #include "LinearAlgebra/Vector.hpp"
|
---|
32 | #include "World.hpp"
|
---|
33 |
|
---|
34 | /** Constructor of class ApproximateShapeVolume.
|
---|
35 | *
|
---|
36 | * @param _shape shape to calculate the volume approximately
|
---|
37 | */
|
---|
38 | ApproximateShapeVolume::ApproximateShapeVolume(const Shape &_shape) :
|
---|
39 | shape(_shape)
|
---|
40 | {}
|
---|
41 |
|
---|
42 | /** Destructor of class ApproximateShapeVolume.
|
---|
43 | *
|
---|
44 | */
|
---|
45 | ApproximateShapeVolume::~ApproximateShapeVolume()
|
---|
46 | {}
|
---|
47 |
|
---|
48 | /** Calculate the approximate volume of the given \a shape.
|
---|
49 | *
|
---|
50 | * @return surface volume approximated
|
---|
51 | */
|
---|
52 | double ApproximateShapeVolume::operator()() const
|
---|
53 | {
|
---|
54 | // TODO
|
---|
55 | // generate mesh of points to "integrate"
|
---|
56 | const double min_distance = 10.;
|
---|
57 | Vector distance(min_distance,min_distance,min_distance);
|
---|
58 | const RealSpaceMatrix &M = World::getInstance().getDomain().getM();
|
---|
59 | Mesh *mesh = new CubeMesh(distance, Vector(0.5,0.5,0.5), M );
|
---|
60 | NodeSet nodes = mesh->getNodes();
|
---|
61 |
|
---|
62 | // fill with grid points and count whether isInside
|
---|
63 | const size_t total = nodes.size();
|
---|
64 | size_t inside = 0;
|
---|
65 | for (NodeSet::const_iterator iter = nodes.begin();
|
---|
66 | iter != nodes.end(); ++iter) {
|
---|
67 | if (shape.isInside(*iter))
|
---|
68 | ++inside;
|
---|
69 | }
|
---|
70 |
|
---|
71 | // calculate volume of box
|
---|
72 | const double volume = M.determinant();
|
---|
73 |
|
---|
74 | // return fraction that is inside
|
---|
75 | return volume*((double)inside/(double)total);
|
---|
76 | }
|
---|