1
// Copyright (C) 2012 Anders Logg
3
// This file is part of DOLFIN.
5
// DOLFIN is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU Lesser General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
10
// DOLFIN is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU Lesser General Public License for more details.
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
18
// Modified by Benjamin Kehlet, 2012
19
// Modified by Johannes Ring, 2012
21
// First added: 2012-04-11
22
// Last changed: 2012-11-12
24
#ifndef __CSG_PRIMITIVES_3D_H
25
#define __CSG_PRIMITIVES_3D_H
27
#include "CSGPrimitive.h"
28
#include <dolfin/mesh/Point.h>
33
/// Base class for 3D primitives
34
class CSGPrimitive3D : public CSGPrimitive
38
/// Return dimension of geometry
39
std::size_t dim() const { return 3; }
43
/// This class describes a 3D sphere which can be used to build
44
/// geometries using Constructive Solid Geometry (CSG).
45
class Sphere : public CSGPrimitive3D
49
/// Create sphere at x = (x0, x1, x2) with radius r.
53
/// x0-coordinate of center.
55
/// x1-coordinate of center.
57
/// x2-coordinate of center.
60
Sphere(Point c, double r, std::size_t slices=16);
62
/// Informal string representation
63
std::string str(bool verbose) const;
66
{ return CSGGeometry::Sphere; }
70
const std::size_t slices;
74
/// This class describes a 3D box which can be used to build
75
/// geometries using Constructive Solid Geometry (CSG).
76
class Box : public CSGPrimitive3D
80
/// Create box defined by two opposite corners
81
/// x = (x0, x1, x2) and y = (y0, y1, y2).
85
/// x0-coordinate of first corner.
87
/// x1-coordinate of first corner.
89
/// x2-coordinate of first corner.
91
/// y0-coordinate of second corner.
93
/// y1-coordinate of second corner.
95
/// y2-coordinate of second corner.
96
Box(double x0, double x1, double x2,
97
double y0, double y1, double y2);
99
/// Informal string representation
100
std::string str(bool verbose) const;
103
{ return CSGGeometry::Box; }
105
double _x0, _x1, _x2, _y0, _y1, _y2;
108
/// This class describes a 3D cone which can be used to build
109
/// geometries using Constructive Solid Geometry (CSG).
110
class Cone : public CSGPrimitive3D
114
/// Create cone defined by upper and lower center
115
/// and radius respectively.
119
/// Center at top of cone.
120
/// top_radius(double)
121
/// Radius bottom of cone.
123
/// Center at top of cone.
124
/// bottom_radius (double)
125
/// radius at top of cone.
126
/// slices (std::size_t)
127
/// number of faces on the side when generating a
128
/// polyhedral approximation.
129
Cone(Point top, Point bottom, double top_radius, double bottom_radius, std::size_t slices=32);
131
/// Informal string representation
132
std::string str(bool verbose) const;
135
{ return CSGGeometry::Cone; }
137
const Point top, bottom;
138
const double top_radius, bottom_radius;
139
const std::size_t slices;
142
/// This class describes a 3D cylinder which can be used to build
143
/// geometries using Constructive Solid Geometry (CSG). A cylinder
144
/// is here just a special case of a cone.
145
class Cylinder : public Cone
148
Cylinder(Point top, Point bottom, double r, std::size_t slices=32) : Cone(top, bottom, r, r, slices){}
151
/// This class describes a Tetrahedron which can be used to build
152
/// geometries using Constructive Solid Geometry (CSG).
153
class Tetrahedron : public CSGPrimitive3D
156
Tetrahedron(Point x0, Point x1, Point x2, Point x3);
158
/// Informal string representation
159
std::string str(bool verbose) const;
162
{ return CSGGeometry::Tetrahedron; }
165
Point x0, x1, x2, x3;
168
/// This class describes a 3D surface loaded from file.
169
/// The supported file types
170
class Surface3D : public CSGPrimitive3D
173
Surface3D(std::string filename);
175
/// Informal string representation
176
std::string str(bool verbose) const;
179
{ return CSGGeometry::Surface3D; }
181
std::string filename;