Lattice Microbes 2.5
This is for whole cell modeling
Loading...
Searching...
No Matches
Shape.h
Go to the documentation of this file.
1/*
2 * University of Illinois Open Source License
3 * Copyright 2011-2018 Luthey-Schulten Group,
4 * All rights reserved.
5 *
6 * Developed by: Luthey-Schulten Group
7 * University of Illinois at Urbana-Champaign
8 * http://www.scs.uiuc.edu/~schulten
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy of
11 * this software and associated documentation files (the Software), to deal with
12 * the Software without restriction, including without limitation the rights to
13 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14 * of the Software, and to permit persons to whom the Software is furnished to
15 * do so, subject to the following conditions:
16 *
17 * - Redistributions of source code must retain the above copyright notice,
18 * this list of conditions and the following disclaimers.
19 *
20 * - Redistributions in binary form must reproduce the above copyright notice,
21 * this list of conditions and the following disclaimers in the documentation
22 * and/or other materials provided with the distribution.
23 *
24 * - Neither the names of the Luthey-Schulten Group, University of Illinois at
25 * Urbana-Champaign, nor the names of its contributors may be used to endorse or
26 * promote products derived from this Software without specific prior written
27 * permission.
28 *
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
32 * THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
33 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
34 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35 * OTHER DEALINGS WITH THE SOFTWARE.
36 *
37 * Author(s): Andrew Magis, Elijah Roberts
38 */
39
40#ifndef LM_BUILDER_SHAPE_H_
41#define LM_BUILDER_SHAPE_H_
42
43#include <cmath>
44#include <cstdlib>
45#include <ctime>
46#include "core/Math.h"
47#include "core/Types.h"
48#include "rdme/Lattice.h"
49
50namespace lm {
51
52namespace rdme {
53class Lattice;
54}
55
56namespace builder {
57
58// Forward declarations
59struct point;
60struct vector;
61struct matrix;
62
63
64
67typedef struct point {
72 point(si_dist_t x=0.0, si_dist_t y=0.0, si_dist_t z=0.0):x(x),y(y),z(z){}
76
79 point(const point &p2):x(p2.x),y(p2.y),z(p2.z) {}
80
85 {
86 si_dist_t dx = p2.x - x;
87 si_dist_t dy = p2.y - y;
88 si_dist_t dz = p2.z - z;
89 return (dx*dx + dy*dy + dz*dz);
90 }
91
95 point minus(const vector &r);
96
100 point plus(const vector &r);
101
105 si_dist_t distance(const point & p2) {return sqrt(distanceSquared(p2));}
107
110typedef struct bounding_box {
118 bounding_box(si_dist_t x1=0.0, si_dist_t y1=0.0, si_dist_t z1=0.0, si_dist_t x2=0.0, si_dist_t y2=0.0, si_dist_t z2=0.0):min(x1,y1,z1),max(x2,y2,z2){}
123
124 // Actual points of the bounding box
126
131 {
132 return bounding_box(::min(j.min.x,min.x),::min(j.min.y,min.y),::min(j.min.z,min.z),::max(j.max.x,max.x),::max(j.max.y,max.y),::max(j.max.z,max.z));
133 }
134
137 double volume() { return fabs((max.x - min.x)*(max.y - min.y)*(max.z - min.z)); }
138
142 double rx = (float)rand() / (float)RAND_MAX;
143 double ry = (float)rand() / (float)RAND_MAX;
144 double rz = (float)rand() / (float)RAND_MAX;
145 return point(rx * (max.x - min.x) + min.x,
146 ry * (max.y - min.y) + min.y,
147 rz * (max.z - min.z) + min.z);
148 }
150
153typedef struct vector {
155// Constructors //
161 vector(si_dist_t x=0.0, si_dist_t y=0.0, si_dist_t z=0.0):x(x),y(y),z(z){}
162
166 vector(const point &from, const point &to) {
167 x = to.x-from.x;
168 y = to.y-from.y;
169 z = to.z-from.z;
170 }
171
174 vector(const vector &v):x(v.x),y(v.y),z(v.z) {}
175
178 vector(const point &p):x(p.x),y(p.y),z(p.z) {}
179
182 return point(x,y,z);
183 }
184
186 if ( fabs(v.z) >= 1.0e-12 && fabs(-v.x - v.y) >= 1.0e-12)
187 return vector(v.z,v.z, -v.x-v.y);
188 else
189 return vector(-v.y-v.z,v.x,v.x);
190 }
191
192// Unary Operations //
196
198 vector unitize();
200// Binary Operations //
204 si_dist_t dot(const vector &r);
205
208 vector cross(const vector &r);
209
212 vector scale(const si_dist_t r);
213
216 matrix mult(const vector &r);
217
220 vector mult(const matrix &r);
221
223// Variables //
225 // coordinates
230
231
232
235typedef struct matrix {
237// Constructors //
241 si_dist_t m21 = 0.0, si_dist_t m22 = 0.0,si_dist_t m23 = 0.0,
242 si_dist_t m31 = 0.0, si_dist_t m32 = 0.0,si_dist_t m33 = 0.0)
243 : m11(m11), m12(m12), m13(m13),
244 m21(m21), m22(m22), m23(m23),
245 m31(m31), m32(m32), m33(m33)
246 {
247 }
248
254 matrix m( cos(theta)*cos(psi), cos(phi)*sin(psi) + sin(phi)*sin(theta)*cos(psi), sin(phi)*sin(psi) - cos(phi)*sin(theta)*cos(psi),
255 -cos(theta)*sin(psi), cos(phi)*cos(psi) - sin(phi)*sin(theta)*sin(psi), sin(phi)*cos(psi) + cos(phi)*sin(theta)*sin(psi),
256 sin(theta), -sin(phi)*cos(theta), cos(phi)*cos(theta));
257
258 return m;
259 }
260
262 static matrix Identity() {
263 return matrix(1.0, 0.0, 0.0,
264 0.0, 1.0, 0.0,
265 0.0, 0.0, 1.0);
266 }
267
269// Unary Operations //
272
274
276
278// Binary Operations //
281 vector mult(const vector &r);
282
284 matrix mult(const matrix &r);
285
287// Variables //
289 // Elements
300
301
304class Shape
305{
306public:
326
327public:
336 virtual ~Shape();
337
341 virtual bool boundingBoxesIntersect(Shape * query);
345 virtual bool intersects(Shape * query) = 0;
349 virtual bool contains(point query) = 0;
353 virtual bool contains(Shape * query) = 0;
354
358 virtual site_t getType() {return type;}
360 virtual ShapeType getShapeType() {return shapeType;}
362 virtual double getVolume() = 0;
363
366 virtual void discretizeTo(lm::rdme::Lattice * lattice);
367
368protected:
369 // Functions used for Monte-Carlo integration of volume
370 double integrateToPercentThreshold(double percent); // Integrate until the fluctuation in value is less than
371 double integrateToCount(int count); // Integrate a static number of steps
372
373 virtual point minBounds(point p1, point p2) const {return point(min(p1.x,p2.x),min(p1.y,p2.y),min(p1.z,p2.z));}
374 virtual point maxBounds(point p1, point p2) const {return point(max(p1.x,p2.x),max(p1.y,p2.y),max(p1.z,p2.z));}
375
379
380 // An orientation for the shape
381 vector at; // A vector pointing to where the object is heading
382 vector up; // A vector representing "up"
383 matrix rotation; // The rotation matrix based on Euler angles that converts a point to the same axes as (at, up)
384
385 friend class LatticeBuilder;
386};
387
388}
389}
390
391#endif
392
uint32_t site_t
Definition Lattice.h:74
double si_dist_t
Definition Types.h:63
Abstract base class for all the shapes in Lattice Microbes simulation builder.
Definition Shape.h:305
vector up
Definition Shape.h:382
friend class LatticeBuilder
Definition Shape.h:385
virtual bool contains(Shape *query)=0
Determine if the shape contains the specified shape.
virtual ~Shape()
Destroy the Shape.
Definition Shape.cpp:157
virtual bounding_box getBoundingBox()
Get the bounding box.
Definition Shape.h:356
double integrateToCount(int count)
Definition Shape.cpp:221
vector at
Definition Shape.h:381
virtual double getVolume()=0
Get the total internal volume of the shape.
virtual point maxBounds(point p1, point p2) const
Definition Shape.h:374
matrix rotation
Definition Shape.h:383
ShapeType
Possible shape types that can be used in Lattice Microbes.
Definition Shape.h:310
@ CAPSULE_SHELL
Definition Shape.h:316
@ CUBOID
Definition Shape.h:315
@ TORUS
Definition Shape.h:321
@ INTERSECTION
Definition Shape.h:319
@ CONE
Definition Shape.h:323
@ CAPSULE
Definition Shape.h:314
@ UNIONSET
Definition Shape.h:324
@ HEMISPHERE
Definition Shape.h:312
@ CYLINDER
Definition Shape.h:313
@ UNION
Definition Shape.h:317
@ DIFFERENCE
Definition Shape.h:318
@ MESH
Definition Shape.h:320
@ ELLIPSE
Definition Shape.h:322
@ SPHERE
Definition Shape.h:311
bounding_box boundingBox
Definition Shape.h:377
virtual bool intersects(Shape *query)=0
Check if two shapes intersect.
virtual bool contains(point query)=0
Determine if the shape contains the specified point.
virtual point minBounds(point p1, point p2) const
Definition Shape.h:373
virtual ShapeType getShapeType()
Get the shape type.
Definition Shape.h:360
double integrateToPercentThreshold(double percent)
Definition Shape.cpp:200
site_t type
Definition Shape.h:378
ShapeType shapeType
Definition Shape.h:376
virtual site_t getType()
Get the site type associated with the shape.
Definition Shape.h:358
Shape(ShapeType shapeType, bounding_box boundingBox, site_t type, vector at=vector(0.0, 0.0, 1.0), vector up=vector(0.0, 1.0, 0.0))
Create a Shape.
Definition Shape.cpp:129
virtual bool boundingBoxesIntersect(Shape *query)
Checks if another shape's bounding box interstects with this shape's bounding box.
Definition Shape.cpp:161
virtual void discretizeTo(lm::rdme::Lattice *lattice)
Discretize the object to the specified lattice.
Definition Shape.cpp:169
Base class for lattice type objects.
Definition Lattice.h:132
Definition Capsule.cpp:47
struct lm::builder::bounding_box bounding_box
struct lm::builder::vector vector
struct lm::builder::point point
struct lm::builder::matrix matrix
Definition LatticeBuilder.h:60
Definition Capsule.cpp:46
The bounds for a shape represented as a rectangular box.
Definition Shape.h:110
point max
Definition Shape.h:125
point randomPointInside()
Retun a random point inside the bounding box.
Definition Shape.h:141
point min
Definition Shape.h:125
double volume()
Returns the bounding box volume.
Definition Shape.h:137
bounding_box(si_dist_t x1=0.0, si_dist_t y1=0.0, si_dist_t z1=0.0, si_dist_t x2=0.0, si_dist_t y2=0.0, si_dist_t z2=0.0)
Create a bounding box for coordinates.
Definition Shape.h:118
bounding_box(point min, point max)
Create a bounding box from points.
Definition Shape.h:122
bounding_box joinWith(bounding_box j)
Return a bounding box spanning the two bounding boxes.
Definition Shape.h:130
A matrix used for rotations.
Definition Shape.h:235
matrix(si_dist_t m11=0.0, si_dist_t m12=0.0, si_dist_t m13=0.0, si_dist_t m21=0.0, si_dist_t m22=0.0, si_dist_t m23=0.0, si_dist_t m31=0.0, si_dist_t m32=0.0, si_dist_t m33=0.0)
Create a matrix with the speficied elements.
Definition Shape.h:240
vector mult(const vector &r)
Multiply by a vector.
Definition Shape.cpp:113
si_dist_t m32
Definition Shape.h:297
si_dist_t m12
Definition Shape.h:291
si_dist_t m21
Definition Shape.h:293
matrix transpose()
Definition Shape.cpp:98
static matrix Identity()
Get an identity matrix.
Definition Shape.h:262
si_dist_t m31
Definition Shape.h:296
static matrix eulerMatrixFromAngles(si_dist_t phi, si_dist_t theta, si_dist_t psi)
Get a forward rotation matrix from angles.
Definition Shape.h:253
si_dist_t determinant()
Definition Shape.cpp:104
si_dist_t m13
Definition Shape.h:292
si_dist_t m23
Definition Shape.h:295
si_dist_t m22
Definition Shape.h:294
si_dist_t m11
Definition Shape.h:290
si_dist_t trace()
Definition Shape.cpp:108
si_dist_t m33
Definition Shape.h:298
Type to store a position in space.
Definition Shape.h:67
si_dist_t x
Definition Shape.h:73
si_dist_t distanceSquared(const point &p2)
Determine the distance squared between two points.
Definition Shape.h:84
si_dist_t y
Definition Shape.h:74
point(si_dist_t x=0.0, si_dist_t y=0.0, si_dist_t z=0.0)
Create a point.
Definition Shape.h:72
point plus(const vector &r)
Add the vector from the point.
Definition Shape.cpp:54
si_dist_t z
Definition Shape.h:75
point minus(const vector &r)
Subtract the vector from the point.
Definition Shape.cpp:50
si_dist_t distance(const point &p2)
Determine the distance to another point.
Definition Shape.h:105
point(const point &p2)
Create a point from another point.
Definition Shape.h:79
A vector which points in a direction.
Definition Shape.h:153
static vector findPerpendicularVector(vector v)
Definition Shape.h:185
vector unitize()
Get a unit vector pointing in the same direction as this vector.
Definition Shape.cpp:63
si_dist_t length()
Get the vector length.
Definition Shape.cpp:59
matrix mult(const vector &r)
Multiply with another vector (taking this vector to be a row vector) to form a matrix.
Definition Shape.cpp:86
point toPoint()
convert the vector to a point
Definition Shape.h:181
si_dist_t y
Definition Shape.h:227
si_dist_t z
Definition Shape.h:228
si_dist_t x
Definition Shape.h:226
vector(const point &p)
Construct a vector from a point.
Definition Shape.h:178
vector(const point &from, const point &to)
Construct a vector pointing from one point to another.
Definition Shape.h:166
vector(const vector &v)
Construct a vector from another vector.
Definition Shape.h:174
vector scale(const si_dist_t r)
Scale the vector by a constant.
Definition Shape.cpp:82
vector(si_dist_t x=0.0, si_dist_t y=0.0, si_dist_t z=0.0)
Create a vector.
Definition Shape.h:161
si_dist_t dot(const vector &r)
Compute the dot product between vectors.
Definition Shape.cpp:72
vector cross(const vector &r)
Compute the cross product between vectors.
Definition Shape.cpp:76