// Copyright 2021 The Manifold Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "./csg_tree.h" #include "./impl.h" #include "./parallel.h" #include "manifold/polygon.h" namespace manifold { /** * Constructs a smooth version of the input mesh by creating tangents; this * method will throw if you have supplied tangents with your mesh already. The * actual triangle resolution is unchanged; use the Refine() method to * interpolate to a higher-resolution curve. * * By default, every edge is calculated for maximum smoothness (very much * approximately), attempting to minimize the maximum mean Curvature magnitude. * No higher-order derivatives are considered, as the interpolation is * independent per triangle, only sharing constraints on their boundaries. * * @param meshGL input MeshGL. * @param sharpenedEdges If desired, you can supply a vector of sharpened * halfedges, which should in general be a small subset of all halfedges. Order * of entries doesn't matter, as each one specifies the desired smoothness * (between zero and one, with one the default for all unspecified halfedges) * and the halfedge index (3 * triangle index + [0,1,2] where 0 is the edge * between triVert 0 and 1, etc). * * At a smoothness value of zero, a sharp crease is made. The smoothness is * interpolated along each edge, so the specified value should be thought of as * an average. Where exactly two sharpened edges meet at a vertex, their * tangents are rotated to be colinear so that the sharpened edge can be * continuous. Vertices with only one sharpened edge are completely smooth, * allowing sharpened edges to smoothly vanish at termination. A single vertex * can be sharpened by sharping all edges that are incident on it, allowing * cones to be formed. */ Manifold Manifold::Smooth(const MeshGL& meshGL, const std::vector<Smoothness>& sharpenedEdges) { … } /** * Constructs a smooth version of the input mesh by creating tangents; this * method will throw if you have supplied tangents with your mesh already. The * actual triangle resolution is unchanged; use the Refine() method to * interpolate to a higher-resolution curve. * * By default, every edge is calculated for maximum smoothness (very much * approximately), attempting to minimize the maximum mean Curvature magnitude. * No higher-order derivatives are considered, as the interpolation is * independent per triangle, only sharing constraints on their boundaries. * * @param meshGL64 input MeshGL64. * @param sharpenedEdges If desired, you can supply a vector of sharpened * halfedges, which should in general be a small subset of all halfedges. Order * of entries doesn't matter, as each one specifies the desired smoothness * (between zero and one, with one the default for all unspecified halfedges) * and the halfedge index (3 * triangle index + [0,1,2] where 0 is the edge * between triVert 0 and 1, etc). * * At a smoothness value of zero, a sharp crease is made. The smoothness is * interpolated along each edge, so the specified value should be thought of as * an average. Where exactly two sharpened edges meet at a vertex, their * tangents are rotated to be colinear so that the sharpened edge can be * continuous. Vertices with only one sharpened edge are completely smooth, * allowing sharpened edges to smoothly vanish at termination. A single vertex * can be sharpened by sharping all edges that are incident on it, allowing * cones to be formed. */ Manifold Manifold::Smooth(const MeshGL64& meshGL64, const std::vector<Smoothness>& sharpenedEdges) { … } /** * Constructs a tetrahedron centered at the origin with one vertex at (1,1,1) * and the rest at similarly symmetric points. */ Manifold Manifold::Tetrahedron() { … } /** * Constructs a unit cube (edge lengths all one), by default in the first * octant, touching the origin. If any dimensions in size are negative, or if * all are zero, an empty Manifold will be returned. * * @param size The X, Y, and Z dimensions of the box. * @param center Set to true to shift the center to the origin. */ Manifold Manifold::Cube(vec3 size, bool center) { … } /** * A convenience constructor for the common case of extruding a circle. Can also * form cones if both radii are specified. * * @param height Z-extent * @param radiusLow Radius of bottom circle. Must be positive. * @param radiusHigh Radius of top circle. Can equal zero. Default is equal to * radiusLow. * @param circularSegments How many line segments to use around the circle. * Default is calculated by the static Defaults. * @param center Set to true to shift the center to the origin. Default is * origin at the bottom. */ Manifold Manifold::Cylinder(double height, double radiusLow, double radiusHigh, int circularSegments, bool center) { … } /** * Constructs a geodesic sphere of a given radius. * * @param radius Radius of the sphere. Must be positive. * @param circularSegments Number of segments along its * diameter. This number will always be rounded up to the nearest factor of * four, as this sphere is constructed by refining an octahedron. This means * there are a circle of vertices on all three of the axis planes. Default is * calculated by the static Defaults. */ Manifold Manifold::Sphere(double radius, int circularSegments) { … } /** * Constructs a manifold from a set of polygons by extruding them along the * Z-axis. * Note that high twistDegrees with small nDivisions may cause * self-intersection. This is not checked here and it is up to the user to * choose the correct parameters. * * @param crossSection A set of non-overlapping polygons to extrude. * @param height Z-extent of extrusion. * @param nDivisions Number of extra copies of the crossSection to insert into * the shape vertically; especially useful in combination with twistDegrees to * avoid interpolation artifacts. Default is none. * @param twistDegrees Amount to twist the top crossSection relative to the * bottom, interpolated linearly for the divisions in between. * @param scaleTop Amount to scale the top (independently in X and Y). If the * scale is {0, 0}, a pure cone is formed with only a single vertex at the top. * Note that scale is applied after twist. * Default {1, 1}. */ Manifold Manifold::Extrude(const Polygons& crossSection, double height, int nDivisions, double twistDegrees, vec2 scaleTop) { … } /** * Constructs a manifold from a set of polygons by revolving this cross-section * around its Y-axis and then setting this as the Z-axis of the resulting * manifold. If the polygons cross the Y-axis, only the part on the positive X * side is used. Geometrically valid input will result in geometrically valid * output. * * @param crossSection A set of non-overlapping polygons to revolve. * @param circularSegments Number of segments along its diameter. Default is * calculated by the static Defaults. * @param revolveDegrees Number of degrees to revolve. Default is 360 degrees. */ Manifold Manifold::Revolve(const Polygons& crossSection, int circularSegments, double revolveDegrees) { … } /** * Constructs a new manifold from a vector of other manifolds. This is a purely * topological operation, so care should be taken to avoid creating * overlapping results. It is the inverse operation of Decompose(). * * @param manifolds A vector of Manifolds to lazy-union together. */ Manifold Manifold::Compose(const std::vector<Manifold>& manifolds) { … } /** * This operation returns a vector of Manifolds that are topologically * disconnected. If everything is connected, the vector is length one, * containing a copy of the original. It is the inverse operation of Compose(). */ std::vector<Manifold> Manifold::Decompose() const { … } } // namespace manifold