tools/physicalModeling/mesh2faust/vega/libraries/wildMagic/geometryQuery/verticesQuery.h
raw symbols SCIP| 1 | /* |
| 2 | This code is based on code from the Geometric Tools library, |
| 3 | which is licensed under a boost license. |
| 4 | Such usage is permitted by the boost license; for details, |
| 5 | please see the boost license below. |
| 6 | */ |
| 7 | |
| 8 | // Geometric Tools, LLC |
| 9 | // Copyright (c) 1998-2014 |
| 10 | // Distributed under the Boost Software License, Version 1.0. |
| 11 | // http://www.boost.org/LICENSE_1_0.txt |
| 12 | // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt |
| 13 | |
| 14 | /************************************************************************* |
| 15 | * * |
| 16 | * We release our improvements to the wildMagic code under our standard * |
| 17 | * Vega FEM license, as follows: * |
| 18 | * * |
| 19 | * Vega FEM Simulation Library Version 3.1 * |
| 20 | * * |
| 21 | * "improvements to the wildMagic library" , Copyright (C) 2016 USC * |
| 22 | * All rights reserved. * |
| 23 | * * |
| 24 | * Code author: Yijing Li * |
| 25 | * http://www.jernejbarbic.com/code * |
| 26 | * * |
| 27 | * Funding: National Science Foundation * |
| 28 | * * |
| 29 | * This library is free software; you can redistribute it and/or * |
| 30 | * modify it under the terms of the BSD-style license that is * |
| 31 | * included with this library in the file LICENSE.txt * |
| 32 | * * |
| 33 | * This library is distributed in the hope that it will be useful, * |
| 34 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 35 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file * |
| 36 | * LICENSE.TXT for more details. * |
| 37 | * * |
| 38 | *************************************************************************/ |
| 39 | |
| 40 | |
| 41 | #ifndef VERTICESQUERY_H |
| 42 | #define VERTICESQUERY_H |
| 43 | |
| 44 | // handles floating-point queries among vertices |
| 45 | #include <vector> |
| 46 | #include "minivector.h" |
| 47 | #include "query.h" |
| 48 | |
| 49 | class VerticesQuery : public Query |
| 50 | { |
| 51 | public: |
| 52 | |
| 53 | VerticesQuery (int numVertices, const Vec3d * vertices); |
| 54 | virtual ~VerticesQuery (); |
| 55 | |
| 56 | // Run-time type information. |
| 57 | virtual Type getType () const { return DOUBLE; } |
| 58 | |
| 59 | // Member access. |
| 60 | inline size_t getNumVertices () const { return vertices.size(); } |
| 61 | inline const Vec3d * getVertices () const { return vertices.data(); } |
| 62 | |
| 63 | virtual void addVertex(const Vec3d & v); |
| 64 | |
| 65 | // Queries about the relation of a point to various geometric objects. |
| 66 | |
| 67 | // Returns: |
| 68 | // +1, on positive side of plane |
| 69 | // -1, on negative side of plane |
| 70 | // 0, on the plane |
| 71 | // normal direction of plane: cross(v1-v0, v2-v0) |
| 72 | virtual int toPlane (int i, int v0, int v1, int v2) const; |
| 73 | virtual int toPlane (const Vec3d& test, int v0, int v1, int v2) const; |
| 74 | |
| 75 | // Returns: |
| 76 | // +1, outside tetrahedron |
| 77 | // -1, inside tetrahedron |
| 78 | // 0, on tetrahedron |
| 79 | virtual int toTetrahedron (int i, int v0, int v1, int v2, int v3) const; |
| 80 | virtual int toTetrahedron (const Vec3d & test, int v0, int v1, int v2, int v3) const; |
| 81 | |
| 82 | // Returns: |
| 83 | // +1, outside circumsphere of tetrahedron |
| 84 | // -1, inside circumsphere of tetrahedron |
| 85 | // 0, on circumsphere of tetrahedron |
| 86 | virtual int toCircumsphere (int i, int v0, int v1, int v2, int v3) const; |
| 87 | virtual int toCircumsphere (const Vec3d & test, int v0, int v1, int v2, int v3) const; |
| 88 | |
| 89 | // Returns: |
| 90 | // +1, outside circumsphere of triangle |
| 91 | // -1, inside circumsphere of triangle |
| 92 | // 0, on circumsphere of triangle |
| 93 | virtual int toCircumsphere (int i, int v0, int v1, int v2) const; |
| 94 | virtual int toCircumsphere (const Vec3d & test, int v0, int v1, int v2) const; |
| 95 | |
| 96 | struct Information |
| 97 | { |
| 98 | // The intrinsic dimension of the input set. The parameter 'epsilon' |
| 99 | // to the VerticesQuery::getInformation function is used to provide a tolerance when |
| 100 | // determining the dimension. |
| 101 | // if dimension == 0, all points are effectively the same (or very close based on epsilon) |
| 102 | // If dimension == 1, all points effectively lie on a line segment. |
| 103 | // If dimension == 2, all points effectively line on a plane. |
| 104 | // If dimension == 3, the points are not coplanar. |
| 105 | int dimension; |
| 106 | |
| 107 | // Axis-aligned bounding box of the input set. |
| 108 | double min[3], max[3]; |
| 109 | // mMaxRange = max(max[0]-min[0], max[1]-min[1], and max[2]-min[2].) |
| 110 | double maxRange; |
| 111 | |
| 112 | // The indices that define the maximum dimensional extents. The |
| 113 | // values mExtreme[0] and mExtreme[1] are the indices for the points |
| 114 | // that define the largest extent in one of the coordinate axis |
| 115 | // directions. |
| 116 | // If the dimension is 2, then mExtreme[2] is the index |
| 117 | // for the point that generates the largest extent in the direction |
| 118 | // perpendicular to the line through the points corresponding to |
| 119 | // mExtreme[0] and mExtreme[1]. |
| 120 | // Furthermore, if the dimension is 3, then mExtreme[3] is the index |
| 121 | // for the point that generates the largest extent in the direction |
| 122 | // perpendicular to the triangle defined by the other extreme points. |
| 123 | int extreme[4]; |
| 124 | // If dimenstion == 3, the tetrahedron formed by the |
| 125 | // points V[extreme0], V[extreme1], V[extreme2], V[extreme3]> is |
| 126 | // counterclockwise (positive) if extremeCCW == true. |
| 127 | // tet is positive if its vertices satisfy: ((v1 - v0) x (v2 - v0)) dot (v3 - v0) >= 0 |
| 128 | bool extremeCCW; |
| 129 | |
| 130 | // Coordinate system. |
| 131 | // The origin == vertices[exterme[0]. The |
| 132 | // unit-length direction vector is valid only for 0 <= i < d. |
| 133 | Vec3d origin; |
| 134 | Vec3d direction[3]; |
| 135 | }; |
| 136 | |
| 137 | // get dimensional information about the vertices |
| 138 | void getInformation(double epsilon, Information & info); |
| 139 | |
| 140 | // Helper functions. |
| 141 | static double dot (double x0, double y0, double z0, double x1, double y1, double z1); |
| 142 | |
| 143 | static double det3 (double x0, double y0, double z0, double x1, double y1, double z1, |
| 144 | double x2, double y2, double z2); |
| 145 | |
| 146 | static double det4 (double x0, double y0, double z0, double w0, double x1, double y1, |
| 147 | double z1, double w1, double x2, double y2, double z2, double w2, double x3, |
| 148 | double y3, double z3, double w3); |
| 149 | |
| 150 | // Support for ordering a set of unique indices into the vertex pool. On |
| 151 | // output it is guaranteed that: v0 < v1 < v2. This is used to guarantee |
| 152 | // consistent queries when the vertex ordering of a primitive is permuted, |
| 153 | // a necessity when using floating-point arithmetic that suffers from |
| 154 | // numerical round-off errors. The input indices are considered the |
| 155 | // positive ordering. The output indices are either positively ordered |
| 156 | // (an even number of transpositions occurs during sorting) or negatively |
| 157 | // ordered (an odd number of transpositions occurs during sorting). The |
| 158 | // functions return 'true' for a positive ordering and 'false' for a |
| 159 | // negative ordering. |
| 160 | static bool sort (int& v0, int& v1); |
| 161 | static bool sort (int& v0, int& v1, int& v2); |
| 162 | static bool sort (int& v0, int& v1, int& v2, int& v3); |
| 163 | |
| 164 | protected: |
| 165 | // Input points. |
| 166 | std::vector<Vec3d> vertices; |
| 167 | }; |
| 168 | |
| 169 | #endif |