diff --git a/LICENSE.AGPLv3 b/LICENSE.AGPLv3 deleted file mode 100644 index be3f7b28e5..0000000000 --- a/LICENSE.AGPLv3 +++ /dev/null @@ -1,661 +0,0 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - Version 3, 19 November 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU Affero General Public License is a free, copyleft license for -software and other kinds of works, specifically designed to ensure -cooperation with the community in the case of network server software. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -our General Public Licenses are intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - Developers that use our General Public Licenses protect your rights -with two steps: (1) assert copyright on the software, and (2) offer -you this License which gives you legal permission to copy, distribute -and/or modify the software. - - A secondary benefit of defending all users' freedom is that -improvements made in alternate versions of the program, if they -receive widespread use, become available for other developers to -incorporate. Many developers of free software are heartened and -encouraged by the resulting cooperation. However, in the case of -software used on network servers, this result may fail to come about. -The GNU General Public License permits making a modified version and -letting the public access it on a server without ever releasing its -source code to the public. - - The GNU Affero General Public License is designed specifically to -ensure that, in such cases, the modified source code becomes available -to the community. It requires the operator of a network server to -provide the source code of the modified version running there to the -users of that server. Therefore, public use of a modified version, on -a publicly accessible server, gives the public access to the source -code of the modified version. - - An older license, called the Affero General Public License and -published by Affero, was designed to accomplish similar goals. This is -a different license, not a version of the Affero GPL, but Affero has -released a new version of the Affero GPL which permits relicensing under -this license. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU Affero General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Remote Network Interaction; Use with the GNU General Public License. - - Notwithstanding any other provision of this License, if you modify the -Program, your modified version must prominently offer all users -interacting with it remotely through a computer network (if your version -supports such interaction) an opportunity to receive the Corresponding -Source of your version by providing access to the Corresponding Source -from a network server at no charge, through some standard or customary -means of facilitating copying of software. This Corresponding Source -shall include the Corresponding Source for any work covered by version 3 -of the GNU General Public License that is incorporated pursuant to the -following paragraph. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the work with which it is combined will remain governed by version -3 of the GNU General Public License. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU Affero General Public License from time to time. Such new versions -will be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU Affero General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU Affero General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU Affero General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If your software can interact with users remotely through a computer -network, you should also make sure that it provides a way for users to -get its source. For example, if your program is a web application, its -interface could display a "Source" link that leads users to an archive -of the code. There are many ways you could offer source, and different -solutions will be better for different programs; see section 13 for the -specific requirements. - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU AGPL, see -. diff --git a/LICENSE.README b/LICENSE.README index fefa0fcd17..c19d2bdf03 100644 --- a/LICENSE.README +++ b/LICENSE.README @@ -1,22 +1,20 @@ The majority of KiCad's source code is developed and distributed under the terms of the GPLv3 or later. However, It does include some third-party code licensed -under AGPLv3 or later as well as sections licensed under the BOOST license v1.0, -the ISC license and the MIT license. +under licensed under the BOOST license v1.0, the ISC license and the MIT license. These licenses are compatible, but a combined works as is will be governed under -the terms of the AGPLv3 (or later). This includes any binary distribution of the +the terms of the GPLv3 (or later). This includes any binary distribution of the KiCad EDA suite by the KiCad project or any third party, e.g. Linux distributor. You are free to use the *sources* under the terms of their respective licenses. -Licensed under AGPLv3 (or later): -- TTL [https://www.sintef.no/projectweb/geometry-toolkits/ttl/], sources in include/ttl/* Licensed under BOOSTv1: - libcontext [https://github.com/boostorg/context] in thirdparty/libcontext - clipper in thirdparty/clipper Licensed under ISC: - portions of code in include/geometry/polygon_triangulation.h Licensed under MIT: +- delaunator in thirdparty/delaunator - tinyspline_lib in thirdparty/tinyspline_lib - nlohmann/json in thirdparty/nlohmann_json - nlohmann/fifo_map in thirdparty/nlohmann_json diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index ae3fb62184..08e50f575b 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -67,7 +67,6 @@ set( GAL_SRCS add_library( gal STATIC ${GAL_SRCS} ) target_link_libraries( gal - ttl kimath bitmaps ${GLEW_LIBRARIES} @@ -511,14 +510,17 @@ set_source_files_properties( ${PCB_COMMON_SRCS} PROPERTIES add_library( pcbcommon STATIC ${PCB_COMMON_SRCS} ) target_include_directories( pcbcommon PUBLIC + $ ) target_link_libraries( pcbcommon PUBLIC common + delaunator kimath kiplatform ) +add_dependencies( pcbcommon delaunator ) # auto-generate netlist_lexer.h and netlist_keywords.cpp make_lexer( diff --git a/common/dialog_about/AboutDialog_main.cpp b/common/dialog_about/AboutDialog_main.cpp index c3daa594c3..a61d02cb31 100644 --- a/common/dialog_about/AboutDialog_main.cpp +++ b/common/dialog_about/AboutDialog_main.cpp @@ -179,7 +179,7 @@ static void buildKicadAboutBanner( EDA_BASE_FRAME* aParent, ABOUT_APP_INFO& aInf << HtmlNewline( 4 ) << _( "The complete KiCad EDA Suite is released under the" ) << HtmlNewline( 2 ) << HtmlHyperlink( "http://www.gnu.org/licenses", - _( "GNU Affero General Public License (AGPL) version 3 or any later version" ) ) + _( "GNU General Public License (GPL) version 3 or any later version" ) ) << ""; aInfo.SetLicense( license ); diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index bba3b69980..5ca87c5fc8 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -623,7 +623,6 @@ target_include_directories( pcbnew_kiface_objects PRIVATE $ $ $ - $ $ $ ) @@ -633,7 +632,6 @@ target_include_directories( pcbnew_kiface_objects PRIVATE add_dependencies( pcbnew_kiface_objects common ) add_dependencies( pcbnew_kiface_objects dxflib_qcad ) add_dependencies( pcbnew_kiface_objects tinyspline_lib ) -add_dependencies( pcbnew_kiface_objects ttl ) add_dependencies( pcbnew_kiface_objects nanosvg ) add_library( pcbnew_kiface MODULE $ ) @@ -670,7 +668,6 @@ set( PCBNEW_KIFACE_LIBRARIES gal dxflib_qcad tinyspline_lib - ttl idf3 nanosvg ${wxWidgets_LIBRARIES} diff --git a/pcbnew/connectivity/connectivity_algo.h b/pcbnew/connectivity/connectivity_algo.h index 9bdd0daffb..ae3dc4d90e 100644 --- a/pcbnew/connectivity/connectivity_algo.h +++ b/pcbnew/connectivity/connectivity_algo.h @@ -68,14 +68,13 @@ public: {} /** - * This sort operator implements the reverse sort such that the smallest weight will be placed first - * in a priority queue + * This sort operator provides a sort-by-weight for the ratsnest operation * @param aOther Other edge to compare - * @return true if our weight is larger than the other weight + * @return true if our weight is smaller than the other weight */ bool operator<( CN_EDGE aOther ) const { - return m_weight > aOther.m_weight; + return m_weight < aOther.m_weight; } CN_ANCHOR_PTR GetSourceNode() const { return m_source; } diff --git a/pcbnew/ratsnest/delauney.h b/pcbnew/ratsnest/delauney.h new file mode 100644 index 0000000000..eb10212cc8 --- /dev/null +++ b/pcbnew/ratsnest/delauney.h @@ -0,0 +1,789 @@ +/* + * delauney.h + * + * Created on: Jun 19, 2020 + * Author: seth + */ + +#ifndef PCBNEW_RATSNEST_DELAUNEY_H_ +#define PCBNEW_RATSNEST_DELAUNEY_H_ + +#include +#include +#include +#include +#include +#include +#include +#include + +constexpr std::size_t INVALID_INDEX = + (std::numeric_limits::max)(); + +class Point +{ +public: + Point(double x, double y) : m_x(x), m_y(y) + {} + Point() : m_x(0), m_y(0) + {} + + double x() const + { return m_x; } + + double y() const + { return m_y; } + + double magnitude2() const + { return m_x * m_x + m_y * m_y; } + + static double determinant(const Point& p1, const Point& p2) + { + return p1.m_x * p2.m_y - p1.m_y * p2.m_x; + } + + static Point vector(const Point& p1, const Point& p2) + { + return Point(p2.m_x - p1.m_x, p2.m_y - p1.m_y); + } + + static double dist2(const Point& p1, const Point& p2) + { + Point vec = vector(p1, p2); + return vec.m_x * vec.m_x + vec.m_y * vec.m_y; + } + + static bool equal(const Point& p1, const Point& p2, double span) + { + double dist = dist2(p1, p2) / span; + + // ABELL - This number should be examined to figure how how + // it correlates with the breakdown of calculating determinants. + return dist < 1e-20; + } + +private: + double m_x; + double m_y; +}; + +inline std::ostream& operator<<(std::ostream& out, const Point& p) +{ + out << p.x() << "/" << p.y(); + return out; +} + + +class Points +{ +public: + using const_iterator = Point const *; + + Points(const std::vector& coords) : m_coords(coords) + {} + + const Point& operator[](size_t offset) + { + return reinterpret_cast( + *(m_coords.data() + (offset * 2))); + }; + + Points::const_iterator begin() const + { return reinterpret_cast(m_coords.data()); } + Points::const_iterator end() const + { return reinterpret_cast( + m_coords.data() + m_coords.size()); } + size_t size() const + { return m_coords.size() / 2; } + +private: + const std::vector& m_coords; +}; + +class Delaunator +{ + +public: + std::vector const &coords; + Points m_points; + + // 'triangles' stores the indices to the 'X's of the input + // 'coords'. + std::vector triangles; + + // 'halfedges' store indices into 'triangles'. If halfedges[X] = Y, + // It says that there's an edge from X to Y where a) X and Y are + // both indices into triangles and b) X and Y are indices into different + // triangles in the array. This allows you to get from a triangle to + // its adjacent triangle. If the a triangle edge has no adjacent triangle, + // its half edge will be INVALID_INDEX. + std::vector halfedges; + + std::vector hull_prev; + std::vector hull_next; + + // This contains indexes into the triangles array. + std::vector hull_tri; + std::size_t hull_start; + + inline Delaunator( std::vector const &in_coords ); + inline double get_hull_area(); + inline double get_triangle_area(); + +private: + std::vector m_hash; + Point m_center; + std::size_t m_hash_size; + std::vector m_edge_stack; + + inline std::size_t legalize( std::size_t a ); + inline std::size_t hash_key( double x, double y ) const; + inline std::size_t add_triangle( std::size_t i0, std::size_t i1, std::size_t i2, std::size_t a, + std::size_t b, std::size_t c ); + inline void link( std::size_t a, std::size_t b ); +}; + +//@see https://stackoverflow.com/questions/33333363/built-in-mod-vs-custom-mod-function-improve-the-performance-of-modulus-op/33333636#33333636 +inline size_t fast_mod( const size_t i, const size_t c ) +{ + return i >= c ? i % c : i; +} + +// Kahan and Babuska summation, Neumaier variant; accumulates less FP error +inline double sum( const std::vector &x ) +{ + double sum = x[0]; + double err = 0.0; + + for( size_t i = 1; i < x.size(); i++ ) + { + const double k = x[i]; + const double m = sum + k; + err += std::fabs( sum ) >= std::fabs( k ) ? sum - m + k : k - m + sum; + sum = m; + } + return sum + err; +} + +inline double dist( const double ax, const double ay, const double bx, const double by ) +{ + const double dx = ax - bx; + const double dy = ay - by; + return dx * dx + dy * dy; +} + +inline double circumradius( const Point &p1, const Point &p2, const Point &p3 ) +{ + Point d = Point::vector( p1, p2 ); + Point e = Point::vector( p1, p3 ); + + const double bl = d.magnitude2(); + const double cl = e.magnitude2(); + const double det = Point::determinant( d, e ); + + Point radius( ( e.y() * bl - d.y() * cl ) * 0.5 / det, + ( d.x() * cl - e.x() * bl ) * 0.5 / det ); + + if( ( bl > 0.0 || bl < 0.0 ) && ( cl > 0.0 || cl < 0.0 ) && ( det > 0.0 || det < 0.0 ) ) + return radius.magnitude2(); + return ( std::numeric_limits::max )(); +} + +inline double circumradius( const double ax, const double ay, const double bx, const double by, + const double cx, const double cy ) +{ + const double dx = bx - ax; + const double dy = by - ay; + const double ex = cx - ax; + const double ey = cy - ay; + + const double bl = dx * dx + dy * dy; + const double cl = ex * ex + ey * ey; + const double d = dx * ey - dy * ex; + + const double x = ( ey * bl - dy * cl ) * 0.5 / d; + const double y = ( dx * cl - ex * bl ) * 0.5 / d; + + if( ( bl > 0.0 || bl < 0.0 ) && ( cl > 0.0 || cl < 0.0 ) && ( d > 0.0 || d < 0.0 ) ) + { + return x * x + y * y; + } + else + { + return ( std::numeric_limits::max )(); + } +} + +inline bool clockwise( const Point &p0, const Point &p1, const Point &p2 ) +{ + Point v0 = Point::vector( p0, p1 ); + Point v1 = Point::vector( p0, p2 ); + double det = Point::determinant( v0, v1 ); + double dist = v0.magnitude2() + v1.magnitude2(); + double dist2 = Point::dist2( v0, v1 ); + if( det == 0 ) + { + return false; + } + double reldet = std::abs( dist / det ); + if( reldet > 1e14 ) + return false; + return det < 0; +} + +inline bool clockwise( double px, double py, double qx, double qy, double rx, double ry ) +{ + Point p0( px, py ); + Point p1( qx, qy ); + Point p2( rx, ry ); + return clockwise( p0, p1, p2 ); +} + +inline bool counterclockwise( const Point &p0, const Point &p1, const Point &p2 ) +{ + Point v0 = Point::vector( p0, p1 ); + Point v1 = Point::vector( p0, p2 ); + double det = Point::determinant( v0, v1 ); + double dist = v0.magnitude2() + v1.magnitude2(); + double dist2 = Point::dist2( v0, v1 ); + if( det == 0 ) + return false; + double reldet = std::abs( dist / det ); + if( reldet > 1e14 ) + return false; + return det > 0; +} + +inline bool counterclockwise( double px, double py, double qx, double qy, double rx, double ry ) +{ + Point p0( px, py ); + Point p1( qx, qy ); + Point p2( rx, ry ); + return counterclockwise( p0, p1, p2 ); +} + +inline Point circumcenter( const double ax, const double ay, const double bx, const double by, + const double cx, const double cy ) +{ + const double dx = bx - ax; + const double dy = by - ay; + const double ex = cx - ax; + const double ey = cy - ay; + + const double bl = dx * dx + dy * dy; + const double cl = ex * ex + ey * ey; + //ABELL - This is suspect for div-by-0. + const double d = dx * ey - dy * ex; + + const double x = ax + ( ey * bl - dy * cl ) * 0.5 / d; + const double y = ay + ( dx * cl - ex * bl ) * 0.5 / d; + + return Point( x, y ); +} + +inline bool in_circle( const double ax, const double ay, const double bx, const double by, + const double cx, const double cy, const double px, const double py ) +{ + const double dx = ax - px; + const double dy = ay - py; + const double ex = bx - px; + const double ey = by - py; + const double fx = cx - px; + const double fy = cy - py; + + const double ap = dx * dx + dy * dy; + const double bp = ex * ex + ey * ey; + const double cp = fx * fx + fy * fy; + + return ( dx * ( ey * cp - bp * fy ) - dy * ( ex * cp - bp * fx ) + ap * ( ex * fy - ey * fx ) ) + < 0.0; +} + +constexpr double EPSILON = std::numeric_limits::epsilon(); + +inline bool check_pts_equal( double x1, double y1, double x2, double y2 ) +{ + return std::fabs( x1 - x2 ) <= EPSILON && std::fabs( y1 - y2 ) <= EPSILON; +} + +// monotonically increases with real angle, but doesn't need expensive trigonometry +inline double pseudo_angle( const double dx, const double dy ) +{ + const double p = dx / ( std::abs( dx ) + std::abs( dy ) ); + return ( dy > 0.0 ? 3.0 - p : 1.0 + p ) / 4.0; // [0..1) +} + +Delaunator::Delaunator( std::vector const &in_coords ) : + coords( in_coords ), m_points( in_coords ) +{ + std::size_t n = coords.size() >> 1; + + std::vector ids( n ); + std::iota( ids.begin(), ids.end(), 0 ); + + double max_x = std::numeric_limits::lowest(); + double max_y = std::numeric_limits::lowest(); + double min_x = ( std::numeric_limits::max )(); + double min_y = ( std::numeric_limits::max )(); + for( const Point &p : m_points ) + { + min_x = std::min( p.x(), min_x ); + min_y = std::min( p.y(), min_y ); + max_x = std::max( p.x(), max_x ); + max_y = std::max( p.y(), max_y ); + } + double width = max_x - min_x; + double height = max_y - min_y; + double span = width * width + height * height; // Everything is square dist. + + Point center( ( min_x + max_x ) / 2, ( min_y + max_y ) / 2 ); + + std::size_t i0 = INVALID_INDEX; + std::size_t i1 = INVALID_INDEX; + std::size_t i2 = INVALID_INDEX; + + // pick a seed point close to the centroid + double min_dist = ( std::numeric_limits::max )(); + for( size_t i = 0; i < m_points.size(); ++i ) + { + const Point &p = m_points[i]; + const double d = Point::dist2( center, p ); + if( d < min_dist ) + { + i0 = i; + min_dist = d; + } + } + + const Point &p0 = m_points[i0]; + + min_dist = ( std::numeric_limits::max )(); + + // find the point closest to the seed + for( std::size_t i = 0; i < n; i++ ) + { + if( i == i0 ) + continue; + const double d = Point::dist2( p0, m_points[i] ); + if( d < min_dist && d > 0.0 ) + { + i1 = i; + min_dist = d; + } + } + + const Point &p1 = m_points[i1]; + + double min_radius = ( std::numeric_limits::max )(); + + // find the third point which forms the smallest circumcircle + // with the first two + for( std::size_t i = 0; i < n; i++ ) + { + if( i == i0 || i == i1 ) + continue; + + const double r = circumradius( p0, p1, m_points[i] ); + if( r < min_radius ) + { + i2 = i; + min_radius = r; + } + } + + if( !( min_radius < ( std::numeric_limits::max )() ) ) + { + throw std::runtime_error( "not triangulation" ); + } + + const Point &p2 = m_points[i2]; + + if( counterclockwise( p0, p1, p2 ) ) + std::swap( i1, i2 ); + + double i0x = p0.x(); + double i0y = p0.y(); + double i1x = m_points[i1].x(); + double i1y = m_points[i1].y(); + double i2x = m_points[i2].x(); + double i2y = m_points[i2].y(); + + m_center = circumcenter( i0x, i0y, i1x, i1y, i2x, i2y ); + + // Calculate the distances from the center once to avoid having to + // calculate for each compare. This used to be done in the comparator, + // but GCC 7.5+ would copy the comparator to iterators used in the + // sort, and this was excruciatingly slow when there were many points + // because you had to copy the vector of distances. + std::vector dists; + dists.reserve( m_points.size() ); + for( const Point &p : m_points ) + dists.push_back( dist( p.x(), p.y(), m_center.x(), m_center.y() ) ); + + // sort the points by distance from the seed triangle circumcenter + std::sort( ids.begin(), ids.end(), [ &dists ]( std::size_t i, std::size_t j ) + { return dists[i] < dists[j];} ); + + // initialize a hash table for storing edges of the advancing convex hull + m_hash_size = static_cast( std::ceil( std::sqrt( n ) ) ); + m_hash.resize( m_hash_size ); + std::fill( m_hash.begin(), m_hash.end(), INVALID_INDEX ); + + // initialize arrays for tracking the edges of the advancing convex hull + hull_prev.resize( n ); + hull_next.resize( n ); + hull_tri.resize( n ); + + hull_start = i0; + + size_t hull_size = 3; + + hull_next[i0] = hull_prev[i2] = i1; + hull_next[i1] = hull_prev[i0] = i2; + hull_next[i2] = hull_prev[i1] = i0; + + hull_tri[i0] = 0; + hull_tri[i1] = 1; + hull_tri[i2] = 2; + + m_hash[hash_key( i0x, i0y )] = i0; + m_hash[hash_key( i1x, i1y )] = i1; + m_hash[hash_key( i2x, i2y )] = i2; + + // ABELL - Why are we doing this is n < 3? There is no triangulation if + // there is no triangle. + + std::size_t max_triangles = n < 3 ? 1 : 2 * n - 5; + triangles.reserve( max_triangles * 3 ); + halfedges.reserve( max_triangles * 3 ); + add_triangle( i0, i1, i2, INVALID_INDEX, INVALID_INDEX, INVALID_INDEX ); + double xp = std::numeric_limits::quiet_NaN(); + double yp = std::numeric_limits::quiet_NaN(); + + // Go through points based on distance from the center. + for( std::size_t k = 0; k < n; k++ ) + { + const std::size_t i = ids[k]; + const double x = coords[2 * i]; + const double y = coords[2 * i + 1]; + + // skip near-duplicate points + if( k > 0 && check_pts_equal( x, y, xp, yp ) ) + continue; + xp = x; + yp = y; + + //ABELL - This is dumb. We have the indices. Use them. + // skip seed triangle points + if( check_pts_equal( x, y, i0x, i0y ) || check_pts_equal( x, y, i1x, i1y ) + || check_pts_equal( x, y, i2x, i2y ) ) + continue; + + // find a visible edge on the convex hull using edge hash + std::size_t start = 0; + + size_t key = hash_key( x, y ); + for( size_t j = 0; j < m_hash_size; j++ ) + { + start = m_hash[fast_mod( key + j, m_hash_size )]; + + // ABELL - Not sure how hull_next[start] could ever equal start + // I *think* hull_next is just a representation of the hull in one + // direction. + if( start != INVALID_INDEX && start != hull_next[start] ) + break; + } + + //ABELL + // Make sure what we found is on the hull. + assert( hull_prev[start] != start ); + assert( hull_prev[start] != INVALID_INDEX ); + + start = hull_prev[start]; + size_t e = start; + size_t q; + + // Advance until we find a place in the hull where our current point + // can be added. + while( true ) + { + q = hull_next[e]; + if( Point::equal( m_points[i], m_points[e], span ) + || Point::equal( m_points[i], m_points[q], span ) ) + { + e = INVALID_INDEX; + break; + } + if( counterclockwise( x, y, coords[2 * e], coords[2 * e + 1], coords[2 * q], + coords[2 * q + 1] ) ) + break; + e = q; + if( e == start ) + { + e = INVALID_INDEX; + break; + } + } + + // ABELL + // This seems wrong. Perhaps we should check what's going on? + if( e == INVALID_INDEX ) // likely a near-duplicate point; skip it + continue; + + // add the first triangle from the point + std::size_t t = add_triangle( e, i, hull_next[e], INVALID_INDEX, INVALID_INDEX, + hull_tri[e] ); + + hull_tri[i] = legalize( t + 2 ); // Legalize the triangle we just added. + hull_tri[e] = t; + hull_size++; + + // walk forward through the hull, adding more triangles and + // flipping recursively + std::size_t next = hull_next[e]; + while( true ) + { + q = hull_next[next]; + if( !counterclockwise( x, y, coords[2 * next], coords[2 * next + 1], coords[2 * q], + coords[2 * q + 1] ) ) + break; + t = add_triangle( next, i, q, hull_tri[i], INVALID_INDEX, hull_tri[next] ); + hull_tri[i] = legalize( t + 2 ); + hull_next[next] = next; // mark as removed + hull_size--; + next = q; + } + + // walk backward from the other side, adding more triangles and flipping + if( e == start ) + { + while( true ) + { + q = hull_prev[e]; + if( !counterclockwise( x, y, coords[2 * q], coords[2 * q + 1], coords[2 * e], + coords[2 * e + 1] ) ) + break; + t = add_triangle( q, i, e, INVALID_INDEX, hull_tri[e], hull_tri[q] ); + legalize( t + 2 ); + hull_tri[q] = t; + hull_next[e] = e; // mark as removed + hull_size--; + e = q; + } + } + + // update the hull indices + hull_prev[i] = e; + hull_start = e; + hull_prev[next] = i; + hull_next[e] = i; + hull_next[i] = next; + + m_hash[hash_key( x, y )] = i; + m_hash[hash_key( coords[2 * e], coords[2 * e + 1] )] = e; + } +} + +double Delaunator::get_hull_area() +{ + std::vector hull_area; + size_t e = hull_start; + size_t cnt = 1; + do + { + hull_area.push_back( + ( coords[2 * e] - coords[2 * hull_prev[e]] ) + * ( coords[2 * e + 1] + coords[2 * hull_prev[e] + 1] ) ); + cnt++; + e = hull_next[e]; + } while( e != hull_start ); + return sum( hull_area ); +} + +double Delaunator::get_triangle_area() +{ + std::vector vals; + for( size_t i = 0; i < triangles.size(); i += 3 ) + { + const double ax = coords[2 * triangles[i]]; + const double ay = coords[2 * triangles[i] + 1]; + const double bx = coords[2 * triangles[i + 1]]; + const double by = coords[2 * triangles[i + 1] + 1]; + const double cx = coords[2 * triangles[i + 2]]; + const double cy = coords[2 * triangles[i + 2] + 1]; + double val = std::fabs( ( by - ay ) * ( cx - bx ) - ( bx - ax ) * ( cy - by ) ); + vals.push_back( val ); + } + return sum( vals ); +} + +std::size_t Delaunator::legalize( std::size_t a ) +{ + std::size_t i = 0; + std::size_t ar = 0; + m_edge_stack.clear(); + + // recursion eliminated with a fixed-size stack + while( true ) + { + const size_t b = halfedges[a]; + + /* if the pair of triangles doesn't satisfy the Delaunay condition + * (p1 is inside the circumcircle of [p0, pl, pr]), flip them, + * then do the same check/flip recursively for the new pair of triangles + * + * pl pl + * /||\ / \ + * al/ || \bl al/ \a + * / || \ / \ + * / a||b \ flip /___ar___\ + * p0\ || /p1 => p0\---bl---/p1 + * \ || / \ / + * ar\ || /br b\ /br + * \||/ \ / + * pr pr + */ + const size_t a0 = 3 * ( a / 3 ); + ar = a0 + ( a + 2 ) % 3; + + if( b == INVALID_INDEX ) + { + if( i > 0 ) + { + i--; + a = m_edge_stack[i]; + continue; + } + else + { + //i = INVALID_INDEX; + break; + } + } + + const size_t b0 = 3 * ( b / 3 ); + const size_t al = a0 + ( a + 1 ) % 3; + const size_t bl = b0 + ( b + 2 ) % 3; + + const std::size_t p0 = triangles[ar]; + const std::size_t pr = triangles[a]; + const std::size_t pl = triangles[al]; + const std::size_t p1 = triangles[bl]; + + const bool illegal = in_circle( coords[2 * p0], coords[2 * p0 + 1], coords[2 * pr], + coords[2 * pr + 1], coords[2 * pl], coords[2 * pl + 1], coords[2 * p1], + coords[2 * p1 + 1] ); + + if( illegal ) + { + triangles[a] = p1; + triangles[b] = p0; + + auto hbl = halfedges[bl]; + + // Edge swapped on the other side of the hull (rare). + // Fix the halfedge reference + if( hbl == INVALID_INDEX ) + { + std::size_t e = hull_start; + do + { + if( hull_tri[e] == bl ) + { + hull_tri[e] = a; + break; + } + e = hull_prev[e]; + } while( e != hull_start ); + } + link( a, hbl ); + link( b, halfedges[ar] ); + link( ar, bl ); + std::size_t br = b0 + ( b + 1 ) % 3; + + if( i < m_edge_stack.size() ) + { + m_edge_stack[i] = br; + } + else + { + m_edge_stack.push_back( br ); + } + i++; + + } + else + { + if( i > 0 ) + { + i--; + a = m_edge_stack[i]; + continue; + } + else + { + break; + } + } + } + return ar; +} + +std::size_t Delaunator::hash_key( const double x, const double y ) const +{ + const double dx = x - m_center.x(); + const double dy = y - m_center.y(); + return fast_mod( + static_cast( std::llround( + std::floor( pseudo_angle( dx, dy ) * static_cast( m_hash_size ) ) ) ), + m_hash_size ); +} + +std::size_t Delaunator::add_triangle( std::size_t i0, std::size_t i1, std::size_t i2, + std::size_t a, std::size_t b, std::size_t c ) +{ + std::size_t t = triangles.size(); + triangles.push_back( i0 ); + triangles.push_back( i1 ); + triangles.push_back( i2 ); + link( t, a ); + link( t + 1, b ); + link( t + 2, c ); + return t; +} + +void Delaunator::link( const std::size_t a, const std::size_t b ) +{ + std::size_t s = halfedges.size(); + if( a == s ) + { + halfedges.push_back( b ); + } + else if( a < s ) + { + halfedges[a] = b; + } + else + { + throw std::runtime_error( "Cannot link edge" ); + } + if( b != INVALID_INDEX ) + { + std::size_t s2 = halfedges.size(); + if( b == s2 ) + { + halfedges.push_back( a ); + } + else if( b < s2 ) + { + halfedges[b] = a; + } + else + { + throw std::runtime_error( "Cannot link edge" ); + } + } +} + + +#endif /* PCBNEW_RATSNEST_DELAUNEY_H_ */ diff --git a/pcbnew/ratsnest/ratsnest_data.cpp b/pcbnew/ratsnest/ratsnest_data.cpp index cfd2701c77..2571bf53a6 100644 --- a/pcbnew/ratsnest/ratsnest_data.cpp +++ b/pcbnew/ratsnest/ratsnest_data.cpp @@ -41,7 +41,8 @@ using namespace std::placeholders; #include #include #include -#include + +#include class disjoint_set { @@ -105,7 +106,7 @@ private: std::vector m_depth; }; -void RN_NET::kruskalMST( std::priority_queue &aEdges ) +void RN_NET::kruskalMST( const std::vector &aEdges ) { disjoint_set dset( m_nodes.size() ); @@ -116,10 +117,8 @@ void RN_NET::kruskalMST( std::priority_queue &aEdges ) for( auto& node : m_nodes ) node->SetTag( i++ ); - while( !aEdges.empty() ) + for( auto& tmp : aEdges ) { - auto& tmp = aEdges.top(); - int u = tmp.GetSourceNode()->GetTag(); int v = tmp.GetTargetNode()->GetTag(); @@ -128,8 +127,6 @@ void RN_NET::kruskalMST( std::priority_queue &aEdges ) if( tmp.GetWeight() > 0 ) m_rnEdges.push_back( tmp ); } - - aEdges.pop(); } } @@ -137,37 +134,25 @@ void RN_NET::kruskalMST( std::priority_queue &aEdges ) class RN_NET::TRIANGULATOR_STATE { private: - std::vector m_allNodes; - - std::list hedTriangulation( std::vector& aNodes ) - { - hed::TRIANGULATION triangulator; - triangulator.CreateDelaunay( aNodes.begin(), aNodes.end() ); - std::list edges; - triangulator.GetEdges( edges ); - - return edges; - } + std::multiset m_allNodes; // Checks if all nodes in aNodes lie on a single line. Requires the nodes to // have unique coordinates! - bool areNodesColinear( const std::vector& aNodes ) const + bool areNodesColinear( const std::vector& aNodes ) const { if ( aNodes.size() <= 2 ) return true; - const auto p0 = aNodes[0]->Pos(); - const auto v0 = aNodes[1]->Pos() - p0; + const VECTOR2I p0( aNodes[0]->Pos() ); + const VECTOR2I v0( aNodes[1]->Pos() - p0 ); for( unsigned i = 2; i < aNodes.size(); i++ ) { - const auto v1 = aNodes[i]->Pos() - p0; + const VECTOR2I v1 = aNodes[i]->Pos() - p0; if( v0.Cross( v1 ) != 0 ) - { return false; - } } return true; @@ -182,97 +167,84 @@ public: void AddNode( CN_ANCHOR_PTR aNode ) { - m_allNodes.push_back( aNode ); + m_allNodes.insert( aNode ); } - const std::priority_queue Triangulate() + void Triangulate( std::vector& mstEdges) { - std::priority_queue mstEdges; - std::list triangEdges; - std::vector triNodes; + std::vector node_pts; using ANCHOR_LIST = std::vector; - std::vector anchorChains; - triNodes.reserve( m_allNodes.size() ); - anchorChains.resize( m_allNodes.size() ); + ANCHOR_LIST anchors; + std::vector anchorChains( m_allNodes.size() ); - std::sort( m_allNodes.begin(), m_allNodes.end(), - [] ( const CN_ANCHOR_PTR& aNode1, const CN_ANCHOR_PTR& aNode2 ) - { - if( aNode1->Pos().y < aNode2->Pos().y ) - return true; - else if( aNode1->Pos().y == aNode2->Pos().y ) - { - return aNode1->Pos().x < aNode2->Pos().x; - } + node_pts.reserve( 2 * m_allNodes.size() ); + anchors.reserve( m_allNodes.size() ); - return false; - } - ); - - CN_ANCHOR_PTR prev, last; - int id = 0; + CN_ANCHOR_PTR prev = nullptr; for( const auto& n : m_allNodes ) { if( !prev || prev->Pos() != n->Pos() ) { - auto tn = std::make_shared ( n->Pos().x, n->Pos().y ); - - tn->SetId( id ); - triNodes.push_back( tn ); + node_pts.push_back( n->Pos().x ); + node_pts.push_back( n->Pos().y ); + anchors.push_back( n ); + prev = n; } - id++; - prev = n; + anchorChains[anchors.size() - 1].push_back( n ); } - int prevId = 0; - - for( const auto& n : triNodes ) + if( anchors.size() < 2 ) { - for( int i = prevId; i < n->Id(); i++ ) - anchorChains[prevId].push_back( m_allNodes[ i ] ); - - prevId = n->Id(); + return; } - - for( int i = prevId; i < id; i++ ) - anchorChains[prevId].push_back( m_allNodes[ i ] ); - - if( triNodes.size() == 1 ) - { - return mstEdges; - } - else if( areNodesColinear( triNodes ) ) + else if( areNodesColinear( anchors ) ) { // special case: all nodes are on the same line - there's no // triangulation for such set. In this case, we sort along any coordinate // and chain the nodes together. - for(int i = 0; i < (int)triNodes.size() - 1; i++ ) + for( size_t i = 0; i < anchors.size() - 1; i++ ) { - auto src = m_allNodes[ triNodes[i]->Id() ]; - auto dst = m_allNodes[ triNodes[i + 1]->Id() ]; - mstEdges.emplace( src, dst, src->Dist( *dst ) ); + auto src = anchors[i]; + auto dst = anchors[i + 1]; + mstEdges.emplace_back( src, dst, src->Dist( *dst ) ); } } else { - hed::TRIANGULATION triangulator; - triangulator.CreateDelaunay( triNodes.begin(), triNodes.end() ); - triangulator.GetEdges( triangEdges ); + delaunator::Delaunator delaunator( node_pts ); + auto& triangles = delaunator.triangles; - for( const auto& e : triangEdges ) + for( size_t i = 0; i < triangles.size(); i += 3 ) { - auto src = m_allNodes[ e->GetSourceNode()->Id() ]; - auto dst = m_allNodes[ e->GetTargetNode()->Id() ]; + auto src = anchors[triangles[i]]; + auto dst = anchors[triangles[i + 1]]; + mstEdges.emplace_back( src, dst, src->Dist( *dst ) ); - mstEdges.emplace( src, dst, src->Dist( *dst ) ); + src = anchors[triangles[i + 1]]; + dst = anchors[triangles[i + 2]]; + mstEdges.emplace_back( src, dst, src->Dist( *dst ) ); + + src = anchors[triangles[i + 2]]; + dst = anchors[triangles[i]]; + mstEdges.emplace_back( src, dst, src->Dist( *dst ) ); + } + + for( size_t i = 0; i < delaunator.halfedges.size(); i++ ) + { + if( delaunator.halfedges[i] == delaunator::INVALID_INDEX ) + continue; + + auto src = anchors[triangles[i]]; + auto dst = anchors[triangles[delaunator.halfedges[i]]]; + mstEdges.emplace_back( src, dst, src->Dist( *dst ) ); } } - for( unsigned int i = 0; i < anchorChains.size(); i++ ) + for( size_t i = 0; i < anchorChains.size(); i++ ) { auto& chain = anchorChains[i]; @@ -289,11 +261,9 @@ public: const auto& prevNode = chain[j - 1]; const auto& curNode = chain[j]; int weight = prevNode->GetCluster() != curNode->GetCluster() ? 1 : 0; - mstEdges.emplace( prevNode, curNode, weight ); + mstEdges.emplace_back( prevNode, curNode, weight ); } } - - return mstEdges; } }; @@ -342,16 +312,21 @@ void RN_NET::compute() m_triangulator->AddNode( n ); } + std::vector triangEdges; + triangEdges.reserve( m_nodes.size() + m_boardEdges.size() ); + #ifdef PROFILE PROF_COUNTER cnt("triangulate"); #endif - auto triangEdges = m_triangulator->Triangulate(); + m_triangulator->Triangulate( triangEdges ); #ifdef PROFILE cnt.Show(); #endif for( const auto& e : m_boardEdges ) - triangEdges.push( e ); + triangEdges.emplace_back( e ); + + std::sort( triangEdges.begin(), triangEdges.end() ); // Get the minimal spanning tree #ifdef PROFILE diff --git a/pcbnew/ratsnest/ratsnest_data.h b/pcbnew/ratsnest/ratsnest_data.h index dd8c0852f8..38eacfed2b 100644 --- a/pcbnew/ratsnest/ratsnest_data.h +++ b/pcbnew/ratsnest/ratsnest_data.h @@ -2,6 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 2013-2015 CERN + * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors. * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -33,24 +34,14 @@ #include #include -#include #include -#include -#include - -#include -#include +#include #include -class BOARD; class BOARD_ITEM; class BOARD_CONNECTED_ITEM; class CN_CLUSTER; -class CN_CONNECTIVITY_ALGO; - -struct RN_NODE_OR_FILTER; -struct RN_NODE_AND_FILTER; struct CN_PTR_CMP { @@ -160,7 +151,7 @@ protected: void compute(); ///> Compute the minimum spanning tree using Kruskal's algorithm - void kruskalMST( std::priority_queue &aEdges ); + void kruskalMST( const std::vector &aEdges ); ///> Vector of nodes std::multiset m_nodes; diff --git a/resources/linux/appdata/kicad.appdata.xml.in b/resources/linux/appdata/kicad.appdata.xml.in index 8fa827c1c4..180e836e9a 100644 --- a/resources/linux/appdata/kicad.appdata.xml.in +++ b/resources/linux/appdata/kicad.appdata.xml.in @@ -1,11 +1,11 @@ - + org.kicad_pcb.kicad KiCad - AGPL-3.0-or-later + GPL-3.0-or-later CC-BY-SA-4.0 EDA Suite diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index d1aa51bacb..11e3bce683 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -1,7 +1,7 @@ # # This program source code file is part of KICAD, a free EDA CAD application. # -# Copyright (C) 2007-2018 Kicad Developers, see AUTHORS.txt for contributors. +# Copyright (C) 2007-2020 Kicad Developers, see AUTHORS.txt for contributors. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -23,6 +23,7 @@ add_subdirectory( clipper ) add_subdirectory( compoundfilereader ) +add_subdirectory( delaunator ) add_subdirectory( dxflib_qcad ) add_subdirectory( libcontext ) add_subdirectory( markdown2html ) @@ -30,6 +31,5 @@ add_subdirectory( nanosvg ) add_subdirectory( other_math ) add_subdirectory( rtree ) add_subdirectory( tinyspline_lib ) -add_subdirectory( ttl ) add_subdirectory( potrace ) add_subdirectory( nlohmann_json ) diff --git a/thirdparty/delaunator/CMakeLists.txt b/thirdparty/delaunator/CMakeLists.txt new file mode 100644 index 0000000000..2a3557d41e --- /dev/null +++ b/thirdparty/delaunator/CMakeLists.txt @@ -0,0 +1,10 @@ +set(DELAUNATOR_SRCS + delaunator.cpp + ) + +add_library(delaunator STATIC ${DELAUNATOR_SRCS}) + +target_include_directories( delaunator + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ) diff --git a/thirdparty/delaunator/LICENSE.MIT b/thirdparty/delaunator/LICENSE.MIT new file mode 100644 index 0000000000..7215f6950b --- /dev/null +++ b/thirdparty/delaunator/LICENSE.MIT @@ -0,0 +1,17 @@ +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/thirdparty/delaunator/README.txt b/thirdparty/delaunator/README.txt new file mode 100644 index 0000000000..348e56dbc8 --- /dev/null +++ b/thirdparty/delaunator/README.txt @@ -0,0 +1,4 @@ +This directory contains the delaunator-cpp project from https://github.com/abellgithub/delaunator-cpp + +It is licensed under MIT, with the license text in this directory. + diff --git a/thirdparty/delaunator/delaunator.cpp b/thirdparty/delaunator/delaunator.cpp new file mode 100644 index 0000000000..7fb1691901 --- /dev/null +++ b/thirdparty/delaunator/delaunator.cpp @@ -0,0 +1,648 @@ + +#include "delaunator.hpp" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace delaunator { + +//@see https://stackoverflow.com/questions/33333363/built-in-mod-vs-custom-mod-function-improve-the-performance-of-modulus-op/33333636#33333636 +inline size_t fast_mod(const size_t i, const size_t c) { + return i >= c ? i % c : i; +} + +// Kahan and Babuska summation, Neumaier variant; accumulates less FP error +inline double sum(const std::vector& x) { + double sum = x[0]; + double err = 0.0; + + for (size_t i = 1; i < x.size(); i++) { + const double k = x[i]; + const double m = sum + k; + err += std::fabs(sum) >= std::fabs(k) ? sum - m + k : k - m + sum; + sum = m; + } + return sum + err; +} + +inline double dist( + const double ax, + const double ay, + const double bx, + const double by) { + const double dx = ax - bx; + const double dy = ay - by; + return dx * dx + dy * dy; +} + +inline double circumradius(const Point& p1, const Point& p2, const Point& p3) +{ + Point d = Point::vector(p1, p2); + Point e = Point::vector(p1, p3); + + const double bl = d.magnitude2(); + const double cl = e.magnitude2(); + const double det = Point::determinant(d, e); + + Point radius((e.y() * bl - d.y() * cl) * 0.5 / det, + (d.x() * cl - e.x() * bl) * 0.5 / det); + + if ((bl > 0.0 || bl < 0.0) && + (cl > 0.0 || cl < 0.0) && + (det > 0.0 || det < 0.0)) + return radius.magnitude2(); + return (std::numeric_limits::max)(); +} + +inline double circumradius( + const double ax, + const double ay, + const double bx, + const double by, + const double cx, + const double cy) { + const double dx = bx - ax; + const double dy = by - ay; + const double ex = cx - ax; + const double ey = cy - ay; + + const double bl = dx * dx + dy * dy; + const double cl = ex * ex + ey * ey; + const double d = dx * ey - dy * ex; + + const double x = (ey * bl - dy * cl) * 0.5 / d; + const double y = (dx * cl - ex * bl) * 0.5 / d; + + if ((bl > 0.0 || bl < 0.0) && (cl > 0.0 || cl < 0.0) && (d > 0.0 || d < 0.0)) { + return x * x + y * y; + } else { + return (std::numeric_limits::max)(); + } +} + +inline bool clockwise(const Point& p0, const Point& p1, const Point& p2) +{ + Point v0 = Point::vector(p0, p1); + Point v1 = Point::vector(p0, p2); + double det = Point::determinant(v0, v1); + double dist = v0.magnitude2() + v1.magnitude2(); + double dist2 = Point::dist2(v0, v1); + if (det == 0) + { + return false; + } + double reldet = std::abs(dist / det); + if (reldet > 1e14) + return false; + return det < 0; +} + +inline bool clockwise(double px, double py, double qx, double qy, + double rx, double ry) +{ + Point p0(px, py); + Point p1(qx, qy); + Point p2(rx, ry); + return clockwise(p0, p1, p2); +} + +inline bool counterclockwise(const Point& p0, const Point& p1, const Point& p2) +{ + Point v0 = Point::vector(p0, p1); + Point v1 = Point::vector(p0, p2); + double det = Point::determinant(v0, v1); + double dist = v0.magnitude2() + v1.magnitude2(); + double dist2 = Point::dist2(v0, v1); + if (det == 0) + return false; + double reldet = std::abs(dist / det); + if (reldet > 1e14) + return false; + return det > 0; +} + +inline bool counterclockwise(double px, double py, double qx, double qy, + double rx, double ry) +{ + Point p0(px, py); + Point p1(qx, qy); + Point p2(rx, ry); + return counterclockwise(p0, p1, p2); +} + + +inline Point circumcenter( + const double ax, + const double ay, + const double bx, + const double by, + const double cx, + const double cy) { + const double dx = bx - ax; + const double dy = by - ay; + const double ex = cx - ax; + const double ey = cy - ay; + + const double bl = dx * dx + dy * dy; + const double cl = ex * ex + ey * ey; + //ABELL - This is suspect for div-by-0. + const double d = dx * ey - dy * ex; + + const double x = ax + (ey * bl - dy * cl) * 0.5 / d; + const double y = ay + (dx * cl - ex * bl) * 0.5 / d; + + return Point(x, y); +} + +inline bool in_circle( + const double ax, + const double ay, + const double bx, + const double by, + const double cx, + const double cy, + const double px, + const double py) { + const double dx = ax - px; + const double dy = ay - py; + const double ex = bx - px; + const double ey = by - py; + const double fx = cx - px; + const double fy = cy - py; + + const double ap = dx * dx + dy * dy; + const double bp = ex * ex + ey * ey; + const double cp = fx * fx + fy * fy; + + return (dx * (ey * cp - bp * fy) - + dy * (ex * cp - bp * fx) + + ap * (ex * fy - ey * fx)) < 0.0; +} + +constexpr double EPSILON = std::numeric_limits::epsilon(); + +inline bool check_pts_equal(double x1, double y1, double x2, double y2) { + return std::fabs(x1 - x2) <= EPSILON && + std::fabs(y1 - y2) <= EPSILON; +} + +// monotonically increases with real angle, but doesn't need expensive trigonometry +inline double pseudo_angle(const double dx, const double dy) { + const double p = dx / (std::abs(dx) + std::abs(dy)); + return (dy > 0.0 ? 3.0 - p : 1.0 + p) / 4.0; // [0..1) +} + + +Delaunator::Delaunator(std::vector const& in_coords) + : coords(in_coords), m_points(in_coords) +{ + std::size_t n = coords.size() >> 1; + + std::vector ids(n); + std::iota(ids.begin(), ids.end(), 0); + + double max_x = std::numeric_limits::lowest(); + double max_y = std::numeric_limits::lowest(); + double min_x = (std::numeric_limits::max)(); + double min_y = (std::numeric_limits::max)(); + for (const Point& p : m_points) + { + min_x = std::min(p.x(), min_x); + min_y = std::min(p.y(), min_y); + max_x = std::max(p.x(), max_x); + max_y = std::max(p.y(), max_y); + } + double width = max_x - min_x; + double height = max_y - min_y; + double span = width * width + height * height; // Everything is square dist. + + Point center((min_x + max_x) / 2, (min_y + max_y) / 2); + + std::size_t i0 = INVALID_INDEX; + std::size_t i1 = INVALID_INDEX; + std::size_t i2 = INVALID_INDEX; + + // pick a seed point close to the centroid + double min_dist = (std::numeric_limits::max)(); + for (size_t i = 0; i < m_points.size(); ++i) + { + const Point& p = m_points[i]; + const double d = Point::dist2(center, p); + if (d < min_dist) { + i0 = i; + min_dist = d; + } + } + + const Point& p0 = m_points[i0]; + + min_dist = (std::numeric_limits::max)(); + + // find the point closest to the seed + for (std::size_t i = 0; i < n; i++) { + if (i == i0) continue; + const double d = Point::dist2(p0, m_points[i]); + if (d < min_dist && d > 0.0) { + i1 = i; + min_dist = d; + } + } + + const Point& p1 = m_points[i1]; + + double min_radius = (std::numeric_limits::max)(); + + // find the third point which forms the smallest circumcircle + // with the first two + for (std::size_t i = 0; i < n; i++) { + if (i == i0 || i == i1) continue; + + const double r = circumradius(p0, p1, m_points[i]); + if (r < min_radius) { + i2 = i; + min_radius = r; + } + } + + if (!(min_radius < (std::numeric_limits::max)())) { + throw std::runtime_error("not triangulation"); + } + + const Point& p2 = m_points[i2]; + + if (counterclockwise(p0, p1, p2)) + std::swap(i1, i2); + + double i0x = p0.x(); + double i0y = p0.y(); + double i1x = m_points[i1].x(); + double i1y = m_points[i1].y(); + double i2x = m_points[i2].x(); + double i2y = m_points[i2].y(); + + m_center = circumcenter(i0x, i0y, i1x, i1y, i2x, i2y); + + // Calculate the distances from the center once to avoid having to + // calculate for each compare. This used to be done in the comparator, + // but GCC 7.5+ would copy the comparator to iterators used in the + // sort, and this was excruciatingly slow when there were many points + // because you had to copy the vector of distances. + std::vector dists; + dists.reserve(m_points.size()); + for (const Point& p : m_points) + dists.push_back(dist(p.x(), p.y(), m_center.x(), m_center.y())); + + // sort the points by distance from the seed triangle circumcenter + std::sort(ids.begin(), ids.end(), + [&dists](std::size_t i, std::size_t j) + { return dists[i] < dists[j]; }); + + // initialize a hash table for storing edges of the advancing convex hull + m_hash_size = static_cast(std::ceil(std::sqrt(n))); + m_hash.resize(m_hash_size); + std::fill(m_hash.begin(), m_hash.end(), INVALID_INDEX); + + // initialize arrays for tracking the edges of the advancing convex hull + hull_prev.resize(n); + hull_next.resize(n); + hull_tri.resize(n); + + hull_start = i0; + + size_t hull_size = 3; + + hull_next[i0] = hull_prev[i2] = i1; + hull_next[i1] = hull_prev[i0] = i2; + hull_next[i2] = hull_prev[i1] = i0; + + hull_tri[i0] = 0; + hull_tri[i1] = 1; + hull_tri[i2] = 2; + + m_hash[hash_key(i0x, i0y)] = i0; + m_hash[hash_key(i1x, i1y)] = i1; + m_hash[hash_key(i2x, i2y)] = i2; + + // ABELL - Why are we doing this is n < 3? There is no triangulation if + // there is no triangle. + + std::size_t max_triangles = n < 3 ? 1 : 2 * n - 5; + triangles.reserve(max_triangles * 3); + halfedges.reserve(max_triangles * 3); + add_triangle(i0, i1, i2, INVALID_INDEX, INVALID_INDEX, INVALID_INDEX); + double xp = std::numeric_limits::quiet_NaN(); + double yp = std::numeric_limits::quiet_NaN(); + + // Go through points based on distance from the center. + for (std::size_t k = 0; k < n; k++) { + const std::size_t i = ids[k]; + const double x = coords[2 * i]; + const double y = coords[2 * i + 1]; + + // skip near-duplicate points + if (k > 0 && check_pts_equal(x, y, xp, yp)) + continue; + xp = x; + yp = y; + + //ABELL - This is dumb. We have the indices. Use them. + // skip seed triangle points + if (check_pts_equal(x, y, i0x, i0y) || + check_pts_equal(x, y, i1x, i1y) || + check_pts_equal(x, y, i2x, i2y)) continue; + + // find a visible edge on the convex hull using edge hash + std::size_t start = 0; + + size_t key = hash_key(x, y); + for (size_t j = 0; j < m_hash_size; j++) { + start = m_hash[fast_mod(key + j, m_hash_size)]; + + // ABELL - Not sure how hull_next[start] could ever equal start + // I *think* hull_next is just a representation of the hull in one + // direction. + if (start != INVALID_INDEX && start != hull_next[start]) + break; + } + + //ABELL + // Make sure what we found is on the hull. + assert(hull_prev[start] != start); + assert(hull_prev[start] != INVALID_INDEX); + + start = hull_prev[start]; + size_t e = start; + size_t q; + + // Advance until we find a place in the hull where our current point + // can be added. + while (true) + { + q = hull_next[e]; + if (Point::equal(m_points[i], m_points[e], span) || + Point::equal(m_points[i], m_points[q], span)) + { + e = INVALID_INDEX; + break; + } + if (counterclockwise(x, y, coords[2 * e], coords[2 * e + 1], + coords[2 * q], coords[2 * q + 1])) + break; + e = q; + if (e == start) { + e = INVALID_INDEX; + break; + } + } + + // ABELL + // This seems wrong. Perhaps we should check what's going on? + if (e == INVALID_INDEX) // likely a near-duplicate point; skip it + continue; + + // add the first triangle from the point + std::size_t t = add_triangle( + e, + i, + hull_next[e], + INVALID_INDEX, + INVALID_INDEX, + hull_tri[e]); + + hull_tri[i] = legalize(t + 2); // Legalize the triangle we just added. + hull_tri[e] = t; + hull_size++; + + // walk forward through the hull, adding more triangles and + // flipping recursively + std::size_t next = hull_next[e]; + while (true) + { + q = hull_next[next]; + if (!counterclockwise(x, y, coords[2 * next], coords[2 * next + 1], + coords[2 * q], coords[2 * q + 1])) + break; + t = add_triangle(next, i, q, + hull_tri[i], INVALID_INDEX, hull_tri[next]); + hull_tri[i] = legalize(t + 2); + hull_next[next] = next; // mark as removed + hull_size--; + next = q; + } + + // walk backward from the other side, adding more triangles and flipping + if (e == start) { + while (true) + { + q = hull_prev[e]; + if (!counterclockwise(x, y, coords[2 * q], coords[2 * q + 1], + coords[2 * e], coords[2 * e + 1])) + break; + t = add_triangle(q, i, e, + INVALID_INDEX, hull_tri[e], hull_tri[q]); + legalize(t + 2); + hull_tri[q] = t; + hull_next[e] = e; // mark as removed + hull_size--; + e = q; + } + } + + // update the hull indices + hull_prev[i] = e; + hull_start = e; + hull_prev[next] = i; + hull_next[e] = i; + hull_next[i] = next; + + m_hash[hash_key(x, y)] = i; + m_hash[hash_key(coords[2 * e], coords[2 * e + 1])] = e; + } +} + +double Delaunator::get_hull_area() +{ + std::vector hull_area; + size_t e = hull_start; + size_t cnt = 1; + do { + hull_area.push_back((coords[2 * e] - coords[2 * hull_prev[e]]) * + (coords[2 * e + 1] + coords[2 * hull_prev[e] + 1])); + cnt++; + e = hull_next[e]; + } while (e != hull_start); + return sum(hull_area); +} + +double Delaunator::get_triangle_area() +{ + std::vector vals; + for (size_t i = 0; i < triangles.size(); i += 3) + { + const double ax = coords[2 * triangles[i]]; + const double ay = coords[2 * triangles[i] + 1]; + const double bx = coords[2 * triangles[i + 1]]; + const double by = coords[2 * triangles[i + 1] + 1]; + const double cx = coords[2 * triangles[i + 2]]; + const double cy = coords[2 * triangles[i + 2] + 1]; + double val = std::fabs((by - ay) * (cx - bx) - (bx - ax) * (cy - by)); + vals.push_back(val); + } + return sum(vals); +} + +std::size_t Delaunator::legalize(std::size_t a) { + std::size_t i = 0; + std::size_t ar = 0; + m_edge_stack.clear(); + + // recursion eliminated with a fixed-size stack + while (true) { + const size_t b = halfedges[a]; + + /* if the pair of triangles doesn't satisfy the Delaunay condition + * (p1 is inside the circumcircle of [p0, pl, pr]), flip them, + * then do the same check/flip recursively for the new pair of triangles + * + * pl pl + * /||\ / \ + * al/ || \bl al/ \a + * / || \ / \ + * / a||b \ flip /___ar___\ + * p0\ || /p1 => p0\---bl---/p1 + * \ || / \ / + * ar\ || /br b\ /br + * \||/ \ / + * pr pr + */ + const size_t a0 = 3 * (a / 3); + ar = a0 + (a + 2) % 3; + + if (b == INVALID_INDEX) { + if (i > 0) { + i--; + a = m_edge_stack[i]; + continue; + } else { + //i = INVALID_INDEX; + break; + } + } + + const size_t b0 = 3 * (b / 3); + const size_t al = a0 + (a + 1) % 3; + const size_t bl = b0 + (b + 2) % 3; + + const std::size_t p0 = triangles[ar]; + const std::size_t pr = triangles[a]; + const std::size_t pl = triangles[al]; + const std::size_t p1 = triangles[bl]; + + const bool illegal = in_circle( + coords[2 * p0], + coords[2 * p0 + 1], + coords[2 * pr], + coords[2 * pr + 1], + coords[2 * pl], + coords[2 * pl + 1], + coords[2 * p1], + coords[2 * p1 + 1]); + + if (illegal) { + triangles[a] = p1; + triangles[b] = p0; + + auto hbl = halfedges[bl]; + + // Edge swapped on the other side of the hull (rare). + // Fix the halfedge reference + if (hbl == INVALID_INDEX) { + std::size_t e = hull_start; + do { + if (hull_tri[e] == bl) { + hull_tri[e] = a; + break; + } + e = hull_prev[e]; + } while (e != hull_start); + } + link(a, hbl); + link(b, halfedges[ar]); + link(ar, bl); + std::size_t br = b0 + (b + 1) % 3; + + if (i < m_edge_stack.size()) { + m_edge_stack[i] = br; + } else { + m_edge_stack.push_back(br); + } + i++; + + } else { + if (i > 0) { + i--; + a = m_edge_stack[i]; + continue; + } else { + break; + } + } + } + return ar; +} + +std::size_t Delaunator::hash_key(const double x, const double y) const { + const double dx = x - m_center.x(); + const double dy = y - m_center.y(); + return fast_mod( + static_cast(std::llround(std::floor(pseudo_angle(dx, dy) * static_cast(m_hash_size)))), + m_hash_size); +} + +std::size_t Delaunator::add_triangle( + std::size_t i0, + std::size_t i1, + std::size_t i2, + std::size_t a, + std::size_t b, + std::size_t c) { + std::size_t t = triangles.size(); + triangles.push_back(i0); + triangles.push_back(i1); + triangles.push_back(i2); + link(t, a); + link(t + 1, b); + link(t + 2, c); + return t; +} + +void Delaunator::link(const std::size_t a, const std::size_t b) { + std::size_t s = halfedges.size(); + if (a == s) { + halfedges.push_back(b); + } else if (a < s) { + halfedges[a] = b; + } else { + throw std::runtime_error("Cannot link edge"); + } + if (b != INVALID_INDEX) { + std::size_t s2 = halfedges.size(); + if (b == s2) { + halfedges.push_back(a); + } else if (b < s2) { + halfedges[b] = a; + } else { + throw std::runtime_error("Cannot link edge"); + } + } +} + +} //namespace delaunator diff --git a/thirdparty/delaunator/delaunator.hpp b/thirdparty/delaunator/delaunator.hpp new file mode 100644 index 0000000000..854263f8c2 --- /dev/null +++ b/thirdparty/delaunator/delaunator.hpp @@ -0,0 +1,147 @@ +#pragma once + +#ifdef DELAUNATOR_HEADER_ONLY +#define INLINE inline +#else +#define INLINE +#endif + +#include +#include +#include + +namespace delaunator { + +constexpr std::size_t INVALID_INDEX = + (std::numeric_limits::max)(); + +class Point +{ +public: + Point(double x, double y) : m_x(x), m_y(y) + {} + Point() : m_x(0), m_y(0) + {} + + double x() const + { return m_x; } + + double y() const + { return m_y; } + + double magnitude2() const + { return m_x * m_x + m_y * m_y; } + + static double determinant(const Point& p1, const Point& p2) + { + return p1.m_x * p2.m_y - p1.m_y * p2.m_x; + } + + static Point vector(const Point& p1, const Point& p2) + { + return Point(p2.m_x - p1.m_x, p2.m_y - p1.m_y); + } + + static double dist2(const Point& p1, const Point& p2) + { + Point vec = vector(p1, p2); + return vec.m_x * vec.m_x + vec.m_y * vec.m_y; + } + + static bool equal(const Point& p1, const Point& p2, double span) + { + double dist = dist2(p1, p2) / span; + + // ABELL - This number should be examined to figure how how + // it correlates with the breakdown of calculating determinants. + return dist < 1e-20; + } + +private: + double m_x; + double m_y; +}; + +inline std::ostream& operator<<(std::ostream& out, const Point& p) +{ + out << p.x() << "/" << p.y(); + return out; +} + + +class Points +{ +public: + using const_iterator = Point const *; + + Points(const std::vector& coords) : m_coords(coords) + {} + + const Point& operator[](size_t offset) + { + return reinterpret_cast( + *(m_coords.data() + (offset * 2))); + }; + + Points::const_iterator begin() const + { return reinterpret_cast(m_coords.data()); } + Points::const_iterator end() const + { return reinterpret_cast( + m_coords.data() + m_coords.size()); } + size_t size() const + { return m_coords.size() / 2; } + +private: + const std::vector& m_coords; +}; + +class Delaunator { + +public: + std::vector const& coords; + Points m_points; + + // 'triangles' stores the indices to the 'X's of the input + // 'coords'. + std::vector triangles; + + // 'halfedges' store indices into 'triangles'. If halfedges[X] = Y, + // It says that there's an edge from X to Y where a) X and Y are + // both indices into triangles and b) X and Y are indices into different + // triangles in the array. This allows you to get from a triangle to + // its adjacent triangle. If the a triangle edge has no adjacent triangle, + // its half edge will be INVALID_INDEX. + std::vector halfedges; + + std::vector hull_prev; + std::vector hull_next; + + // This contains indexes into the triangles array. + std::vector hull_tri; + std::size_t hull_start; + + INLINE Delaunator(std::vector const& in_coords); + INLINE double get_hull_area(); + INLINE double get_triangle_area(); + +private: + std::vector m_hash; + Point m_center; + std::size_t m_hash_size; + std::vector m_edge_stack; + + INLINE std::size_t legalize(std::size_t a); + INLINE std::size_t hash_key(double x, double y) const; + INLINE std::size_t add_triangle( + std::size_t i0, + std::size_t i1, + std::size_t i2, + std::size_t a, + std::size_t b, + std::size_t c); + INLINE void link(std::size_t a, std::size_t b); +}; + +} //namespace delaunator + +#undef INLINE diff --git a/thirdparty/ttl/CMakeLists.txt b/thirdparty/ttl/CMakeLists.txt deleted file mode 100644 index 095b99b41e..0000000000 --- a/thirdparty/ttl/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ - -set( TTL_SRCS - src/halfedge/hetriang.cpp -) - -add_library( ttl STATIC - ${TTL_SRCS} -) - -target_include_directories( ttl - PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/include -) - -# It needs VECTOR2D from the math library -# Luckily that is header-only -target_include_directories( ttl - PRIVATE - ${PROJECT_SOURCE_DIR}/libs/kimath/include -) diff --git a/thirdparty/ttl/LICENSE.AGPLv3 b/thirdparty/ttl/LICENSE.AGPLv3 deleted file mode 100644 index be3f7b28e5..0000000000 --- a/thirdparty/ttl/LICENSE.AGPLv3 +++ /dev/null @@ -1,661 +0,0 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - Version 3, 19 November 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU Affero General Public License is a free, copyleft license for -software and other kinds of works, specifically designed to ensure -cooperation with the community in the case of network server software. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -our General Public Licenses are intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - Developers that use our General Public Licenses protect your rights -with two steps: (1) assert copyright on the software, and (2) offer -you this License which gives you legal permission to copy, distribute -and/or modify the software. - - A secondary benefit of defending all users' freedom is that -improvements made in alternate versions of the program, if they -receive widespread use, become available for other developers to -incorporate. Many developers of free software are heartened and -encouraged by the resulting cooperation. However, in the case of -software used on network servers, this result may fail to come about. -The GNU General Public License permits making a modified version and -letting the public access it on a server without ever releasing its -source code to the public. - - The GNU Affero General Public License is designed specifically to -ensure that, in such cases, the modified source code becomes available -to the community. It requires the operator of a network server to -provide the source code of the modified version running there to the -users of that server. Therefore, public use of a modified version, on -a publicly accessible server, gives the public access to the source -code of the modified version. - - An older license, called the Affero General Public License and -published by Affero, was designed to accomplish similar goals. This is -a different license, not a version of the Affero GPL, but Affero has -released a new version of the Affero GPL which permits relicensing under -this license. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU Affero General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Remote Network Interaction; Use with the GNU General Public License. - - Notwithstanding any other provision of this License, if you modify the -Program, your modified version must prominently offer all users -interacting with it remotely through a computer network (if your version -supports such interaction) an opportunity to receive the Corresponding -Source of your version by providing access to the Corresponding Source -from a network server at no charge, through some standard or customary -means of facilitating copying of software. This Corresponding Source -shall include the Corresponding Source for any work covered by version 3 -of the GNU General Public License that is incorporated pursuant to the -following paragraph. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the work with which it is combined will remain governed by version -3 of the GNU General Public License. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU Affero General Public License from time to time. Such new versions -will be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU Affero General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU Affero General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU Affero General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If your software can interact with users remotely through a computer -network, you should also make sure that it provides a way for users to -get its source. For example, if your program is a web application, its -interface could display a "Source" link that leads users to an archive -of the code. There are many ways you could offer source, and different -solutions will be better for different programs; see section 13 for the -specific requirements. - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU AGPL, see -. diff --git a/thirdparty/ttl/README.txt b/thirdparty/ttl/README.txt deleted file mode 100644 index f4578324e4..0000000000 --- a/thirdparty/ttl/README.txt +++ /dev/null @@ -1,3 +0,0 @@ -This directory contains the Triangulation Template Library (TTL) from https://github.com/SINTEF-Geometry/TTL. - -It is licensed under the AGPLv3, with the license text in this directory. diff --git a/thirdparty/ttl/include/ttl/halfedge/hedart.h b/thirdparty/ttl/include/ttl/halfedge/hedart.h deleted file mode 100644 index 7fbb849bf7..0000000000 --- a/thirdparty/ttl/include/ttl/halfedge/hedart.h +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT, - * Applied Mathematics, Norway. - * - * Contact information: E-mail: tor.dokken@sintef.no - * SINTEF ICT, Department of Applied Mathematics, - * P.O. Box 124 Blindern, - * 0314 Oslo, Norway. - * - * This file is part of TTL. - * - * TTL is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * TTL is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with TTL. If not, see - * . - * - * In accordance with Section 7(b) of the GNU Affero General Public - * License, a covered work must retain the producer line in every data - * file that is created or manipulated using TTL. - * - * Other Usage - * You can be released from the requirements of the license by purchasing - * a commercial license. Buying such a license is mandatory as soon as you - * develop commercial activities involving the TTL library without - * disclosing the source code of your own applications. - * - * This file may be used in accordance with the terms contained in a - * written agreement between you and SINTEF ICT. - */ - -#ifndef _HALF_EDGE_DART_ -#define _HALF_EDGE_DART_ - -#include - -namespace hed -{ -/** - * \class Dart - * \brief \b %Dart class for the half-edge data structure. - * - * See \ref api for a detailed description of how the member functions - * should be implemented. - */ -class DART -{ - EDGE_PTR m_edge; - - /// Dart direction: true if dart is counterclockwise in face - bool m_dir; - -public: - /// Default constructor - DART() - { - m_dir = true; - } - - /// Constructor - DART( const EDGE_PTR& aEdge, bool aDir = true ) - { - m_edge = aEdge; - assert ( m_edge ); - m_dir = aDir; - } - - /// Copy constructor - DART( const DART& aDart ) - { - m_edge = aDart.m_edge; - assert ( m_edge ); - m_dir = aDart.m_dir; - } - - /// Destructor - ~DART() - { - } - - /// Assignment operator - DART& operator=( const DART& aDart ) - { - if( this == &aDart ) - return *this; - - m_edge = aDart.m_edge; - assert ( m_edge ); - m_dir = aDart.m_dir; - - return *this; - } - - /// Comparing dart objects - bool operator==( const DART& aDart ) const - { - return ( aDart.m_edge == m_edge && aDart.m_dir == m_dir ); - } - - /// Comparing dart objects - bool operator!=( const DART& aDart ) const - { - return !( aDart == *this ); - } - - /// Maps the dart to a different node - DART& Alpha0() - { - m_dir = !m_dir; - return *this; - } - - /// Maps the dart to a different edge - DART& Alpha1() - { - if( m_dir ) - { - m_edge = m_edge->GetNextEdgeInFace()->GetNextEdgeInFace(); - assert ( m_edge ); - m_dir = false; - } - else - { - m_edge = m_edge->GetNextEdgeInFace(); - assert ( m_edge ); - m_dir = true; - } - - return *this; - } - - /// Maps the dart to a different triangle. \b Note: the dart is not changed if it is at the boundary! - DART& Alpha2() - { - if( m_edge->GetTwinEdge() ) - { - m_edge = m_edge->GetTwinEdge(); - assert ( m_edge ); - m_dir = !m_dir; - } - - // else, the dart is at the boundary and should not be changed - return *this; - } - - /** @name Utilities not required by TTL */ - //@{ - void Init( const EDGE_PTR& aEdge, bool aDir = true ) - { - m_edge = aEdge; - assert(m_edge); - m_dir = aDir; - } - - double X() const - { - return GetNode()->GetX(); - } - - double Y() const - { - return GetNode()->GetY(); - } - - bool IsCCW() const - { - return m_dir; - } - - const NODE_PTR& GetNode() const - { - return m_dir ? m_edge->GetSourceNode() : m_edge->GetTargetNode(); - } - - const NODE_PTR& GetOppositeNode() const - { - return m_dir ? m_edge->GetTargetNode() : m_edge->GetSourceNode(); - } - - EDGE_PTR& GetEdge() - { - return m_edge; - } - - //@} // End of Utilities not required by TTL -}; - -} // End of hed namespace - -#endif diff --git a/thirdparty/ttl/include/ttl/halfedge/hetraits.h b/thirdparty/ttl/include/ttl/halfedge/hetraits.h deleted file mode 100644 index a186c405ea..0000000000 --- a/thirdparty/ttl/include/ttl/halfedge/hetraits.h +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT, - * Applied Mathematics, Norway. - * - * Contact information: E-mail: tor.dokken@sintef.no - * SINTEF ICT, Department of Applied Mathematics, - * P.O. Box 124 Blindern, - * 0314 Oslo, Norway. - * - * This file is part of TTL. - * - * TTL is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * TTL is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with TTL. If not, see - * . - * - * In accordance with Section 7(b) of the GNU Affero General Public - * License, a covered work must retain the producer line in every data - * file that is created or manipulated using TTL. - * - * Other Usage - * You can be released from the requirements of the license by purchasing - * a commercial license. Buying such a license is mandatory as soon as you - * develop commercial activities involving the TTL library without - * disclosing the source code of your own applications. - * - * This file may be used in accordance with the terms contained in a - * written agreement between you and SINTEF ICT. - */ - -#ifndef _HALF_EDGE_TRAITS_ -#define _HALF_EDGE_TRAITS_ - -#include -#include - -namespace hed -{ -/** - * \struct TTLtraits - * \brief \b Traits class (static struct) for the half-edge data structure. - * - * The member functions are those required by different function templates - * in the TTL. Documentation is given here to explain what actions - * should be carried out on the actual data structure as required by the functions - * in the \ref ttl namespace. - * - * The source code of \c %HeTraits.h shows how the traits class is implemented for the - * half-edge data structure. - * - * \see \ref api - */ -struct TTLtraits -{ - /** - * The floating point type used in calculations involving scalar products and cross products. - */ - typedef double REAL_TYPE; - - /** @name Geometric Predicates */ - //@{ - /** - * Scalar product between two 2D vectors represented as darts.\n - * - * ttl_util::scalarProduct2d can be used. - */ - static REAL_TYPE ScalarProduct2D( const DART& aV1, const DART& aV2 ) - { - DART v10 = aV1; - v10.Alpha0(); - - DART v20 = aV2; - v20.Alpha0(); - - return ttl_util::ScalarProduct2D( v10.X() - aV1.X(), v10.Y() - aV1.Y(), - v20.X() - aV2.X(), v20.Y() - aV2.Y() ); - } - - /** - * Scalar product between two 2D vectors. - * The first vector is represented by a dart \e v, and the second - * vector has direction from the source node of \e v to the point \e p.\n - * - * ttl_util::ScalarProduct2D can be used. - */ - static REAL_TYPE ScalarProduct2D( const DART& aV, const NODE_PTR& aP ) - { - DART d0 = aV; - d0.Alpha0(); - - return ttl_util::ScalarProduct2D( d0.X() - aV.X(), d0.Y() - aV.Y(), - aP->GetX() - aV.X(), aP->GetY() - aV.Y() ); - } - - /** - * Cross product between two vectors in the plane represented as darts. - * The z-component of the cross product is returned.\n - * - * ttl_util::CrossProduct2D can be used. - */ - static REAL_TYPE CrossProduct2D( const DART& aV1, const DART& aV2 ) - { - DART v10 = aV1; - v10.Alpha0(); - - DART v20 = aV2; - v20.Alpha0(); - - return ttl_util::CrossProduct2D( v10.X() - aV1.X(), v10.Y() - aV1.Y(), - v20.X() - aV2.X(), v20.Y() - aV2.Y() ); - } - - /** - * Cross product between two vectors in the plane. - * The first vector is represented by a dart \e v, and the second - * vector has direction from the source node of \e v to the point \e p. - * The z-component of the cross product is returned.\n - * - * ttl_util::CrossProduct2d can be used. - */ - static REAL_TYPE CrossProduct2D( const DART& aV, const NODE_PTR& aP ) - { - DART d0 = aV; - d0.Alpha0(); - - return ttl_util::CrossProduct2D( d0.X() - aV.X(), d0.Y() - aV.Y(), - aP->GetX() - aV.X(), aP->GetY() - aV.Y() ); - } - - /** - * Let \e n1 and \e n2 be the nodes associated with two darts, and let \e p - * be a point in the plane. Return a positive value if \e n1, \e n2, - * and \e p occur in counterclockwise order; a negative value if they occur - * in clockwise order; and zero if they are collinear. - */ - static REAL_TYPE Orient2D( const DART& aN1, const DART& aN2, const NODE_PTR& aP ) - { - REAL_TYPE pa[2]; - REAL_TYPE pb[2]; - REAL_TYPE pc[2]; - - pa[0] = aN1.X(); - pa[1] = aN1.Y(); - pb[0] = aN2.X(); - pb[1] = aN2.Y(); - pc[0] = aP->GetX(); - pc[1] = aP->GetY(); - - return ttl_util::Orient2DFast( pa, pb, pc ); - } - - /** - * This is the same predicate as represented with the function above, - * but with a slighty different interface: - * The last parameter is given as a dart where the source node of the dart - * represents a point in the plane. - * This function is required for constrained triangulation. - */ - static REAL_TYPE Orient2D( const DART& aN1, const DART& aN2, const DART& aP ) - { - REAL_TYPE pa[2]; - REAL_TYPE pb[2]; - REAL_TYPE pc[2]; - - pa[0] = aN1.X(); - pa[1] = aN1.Y(); - pb[0] = aN2.X(); - pb[1] = aN2.Y(); - pc[0] = aP.X(); - pc[1] = aP.Y(); - - return ttl_util::Orient2DFast( pa, pb, pc ); - } - - //@} // End of Geometric Predicates Group -}; - -} // End of hed namespace - -#endif diff --git a/thirdparty/ttl/include/ttl/halfedge/hetriang.h b/thirdparty/ttl/include/ttl/halfedge/hetriang.h deleted file mode 100644 index 84ec2cdce6..0000000000 --- a/thirdparty/ttl/include/ttl/halfedge/hetriang.h +++ /dev/null @@ -1,430 +0,0 @@ -/* - * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT, - * Applied Mathematics, Norway. - * Copyright (C) 2013 CERN - * @author Maciej Suminski - * - * Contact information: E-mail: tor.dokken@sintef.no - * SINTEF ICT, Department of Applied Mathematics, - * P.O. Box 124 Blindern, - * 0314 Oslo, Norway. - * - * This file is part of TTL. - * - * TTL is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * TTL is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with TTL. If not, see - * . - * - * In accordance with Section 7(b) of the GNU Affero General Public - * License, a covered work must retain the producer line in every data - * file that is created or manipulated using TTL. - * - * Other Usage - * You can be released from the requirements of the license by purchasing - * a commercial license. Buying such a license is mandatory as soon as you - * develop commercial activities involving the TTL library without - * disclosing the source code of your own applications. - * - * This file may be used in accordance with the terms contained in a - * written agreement between you and SINTEF ICT. - */ - -#ifndef _HE_TRIANG_H_ -#define _HE_TRIANG_H_ - -#define TTL_USE_NODE_ID // Each node gets it's own unique id -#define TTL_USE_NODE_FLAG // Each node gets a flag (can be set to true or false) - -#include -#include -#include -#include -#include -#include -#include -#include - -class BOARD_CONNECTED_ITEM; -class CN_CLUSTER; - -namespace ttl -{ - class TRIANGULATION_HELPER; -} - -/** - * The half-edge data structure - */ -namespace hed -{ -// Helper typedefs -class NODE; -class EDGE; -typedef std::shared_ptr NODE_PTR; -typedef std::shared_ptr EDGE_PTR; -typedef std::weak_ptr EDGE_WEAK_PTR; -typedef std::vector NODES_CONTAINER; - -/** - * \class NODE - * \brief \b Node class for data structures (Inherits from HandleId) - * - * \note - * - To enable node IDs, TTL_USE_NODE_ID must be defined. - * - To enable node flags, TTL_USE_NODE_FLAG must be defined. - * - TTL_USE_NODE_ID and TTL_USE_NODE_FLAG should only be enabled if this functionality is - * required by the application, because they increase the memory usage for each Node object. - */ -class NODE -{ -protected: -#ifdef TTL_USE_NODE_FLAG - /// TTL_USE_NODE_FLAG must be defined - bool m_flag; -#endif - -#ifdef TTL_USE_NODE_ID - /// TTL_USE_NODE_ID must be defined - static int id_count; - - /// A unique id for each node (TTL_USE_NODE_ID must be defined) - int m_id; -#endif - - /// Node coordinates - const int m_x, m_y; - -public: - /// Constructor - NODE( int aX = 0, int aY = 0, std::shared_ptr aCluster = nullptr ) : -#ifdef TTL_USE_NODE_FLAG - m_flag( false ), -#endif -#ifdef TTL_USE_NODE_ID - m_id( id_count++ ), -#endif - m_x( aX ), m_y( aY ) - { - } - - /// Destructor - ~NODE() { - - } - - const VECTOR2D Pos() const { return VECTOR2D( m_x, m_y ); } - - /// Returns the x-coordinate - inline int GetX() const - { - return m_x; - } - - /// Returns the y-coordinate - inline int GetY() const - { - return m_y; - } - - inline VECTOR2I GetPos() const - { - return VECTOR2I( m_x, m_y ); - } - -#ifdef TTL_USE_NODE_ID - /// Returns the id (TTL_USE_NODE_ID must be defined) - - inline void SetId( int aId ) - { - m_id = aId; - } - - inline int Id() const - { - return m_id; - } -#endif - -#ifdef TTL_USE_NODE_FLAG - /// Sets the flag (TTL_USE_NODE_FLAG must be defined) - inline void SetFlag( bool aFlag ) - { - m_flag = aFlag; - } - - /// Returns the flag (TTL_USE_NODE_FLAG must be defined) - inline const bool& GetFlag() const - { - return m_flag; - } -#endif -}; - - -/** - * \class EDGE - * \brief \b %Edge class in the in the half-edge data structure. - */ -class EDGE -{ -public: - /// Constructor - EDGE() : m_isLeadingEdge( false ) - { - } - - /// Destructor - virtual ~EDGE() - { - - } - - /// Sets the source node - inline void SetSourceNode( const NODE_PTR& aNode ) - { - m_sourceNode = aNode; - } - - /// Sets the next edge in face - inline void SetNextEdgeInFace( const EDGE_PTR& aEdge ) - { - m_nextEdgeInFace = aEdge; - } - - /// Sets the twin edge - inline void SetTwinEdge( const EDGE_PTR& aEdge ) - { - m_twinEdge = aEdge; - } - - /// Sets the edge as a leading edge - inline void SetAsLeadingEdge( bool aLeading = true ) - { - m_isLeadingEdge = aLeading; - } - - /// Checks if an edge is a leading edge - inline bool IsLeadingEdge() const - { - return m_isLeadingEdge; - } - - /// Returns the twin edge - inline EDGE_PTR GetTwinEdge() const - { - if( m_twinEdge.expired() ) - return nullptr; - - return m_twinEdge.lock(); - } - - inline void ClearTwinEdge() - { - m_twinEdge.reset(); - } - - /// Returns the next edge in face - inline const EDGE_PTR& GetNextEdgeInFace() const - { - assert ( m_nextEdgeInFace ); - return m_nextEdgeInFace; - } - - /// Retuns the source node - inline const NODE_PTR& GetSourceNode() const - { - return m_sourceNode; - } - - /// Returns the target node - virtual const NODE_PTR& GetTargetNode() const - { - return m_nextEdgeInFace->GetSourceNode(); - } - - void Clear() - { - m_sourceNode.reset(); - m_nextEdgeInFace.reset(); - - if( !m_twinEdge.expired() ) - { - m_twinEdge.lock()->ClearTwinEdge(); - m_twinEdge.reset(); - } - } - -protected: - NODE_PTR m_sourceNode; - EDGE_WEAK_PTR m_twinEdge; - EDGE_PTR m_nextEdgeInFace; - bool m_isLeadingEdge; -}; - -class DART; // Forward declaration (class in this namespace) - -/** - * \class TRIANGULATION - * \brief \b %Triangulation class for the half-edge data structure with adaption to TTL. - */ -class TRIANGULATION -{ -protected: - /// One half-edge for each arc - std::list m_leadingEdges; - - ttl::TRIANGULATION_HELPER* m_helper; - - void addLeadingEdge( EDGE_PTR& aEdge ) - { - aEdge->SetAsLeadingEdge(); - m_leadingEdges.push_front( aEdge ); - } - - bool removeLeadingEdgeFromList( EDGE_PTR& aLeadingEdge ); - - void cleanAll(); - - /** Swaps the edge associated with \e dart in the actual data structure. - * - *
- * \image html swapEdge.gif - *
- * - * \param aDart - * Some of the functions require a dart as output. - * If this is required by the actual function, the dart should be delivered - * back in a position as seen if it was glued to the edge when swapping (rotating) - * the edge CCW; see the figure. - * - * \note - * - If the edge is \e constrained, or if it should not be swapped for - * some other reason, this function need not do the actual swap of the edge. - * - Some functions in TTL require that \c swapEdge is implemented such that - * darts outside the quadrilateral are not affected by the swap. - */ - void swapEdge( DART& aDart ); - - /** - * Splits the triangle associated with \e dart in the actual data structure into - * three new triangles joining at \e point. - * - *
- * \image html splitTriangle.gif - *
- * - * \param aDart - * Output: A CCW dart incident with the new node; see the figure. - */ - void splitTriangle( DART& aDart, const NODE_PTR& aPoint ); - - /** - * The reverse operation of TTLtraits::splitTriangle. - * This function is only required for functions that involve - * removal of interior nodes; see for example TrinagulationHelper::RemoveInteriorNode. - * - *
- * \image html reverse_splitTriangle.gif - *
- */ - void reverseSplitTriangle( DART& aDart ); - - /** - * Removes a triangle with an edge at the boundary of the triangulation - * in the actual data structure - */ - void removeBoundaryTriangle( DART& aDart ); - -public: - /// Default constructor - TRIANGULATION(); - - /// Copy constructor - TRIANGULATION( const TRIANGULATION& aTriangulation ); - - /// Destructor - ~TRIANGULATION(); - - /// Creates a Delaunay triangulation from a set of points - void CreateDelaunay( NODES_CONTAINER::iterator aFirst, NODES_CONTAINER::iterator aLast ); - - /// Creates an initial Delaunay triangulation from two enclosing triangles - // When using rectangular boundary - loop through all points and expand. - // (Called from createDelaunay(...) when starting) - EDGE_PTR InitTwoEnclosingTriangles( NODES_CONTAINER::iterator aFirst, - NODES_CONTAINER::iterator aLast ); - - // These two functions are required by TTL for Delaunay triangulation - - /// Swaps the edge associated with diagonal - void SwapEdge( EDGE_PTR& aDiagonal ); - - /// Splits the triangle associated with edge into three new triangles joining at point - EDGE_PTR SplitTriangle( EDGE_PTR& aEdge, const NODE_PTR& aPoint ); - - // Functions required by TTL for removing nodes in a Delaunay triangulation - - /// Removes the boundary triangle associated with edge - void RemoveTriangle( EDGE_PTR& aEdge ); // boundary triangle required - - /// The reverse operation of removeTriangle - void ReverseSplitTriangle( EDGE_PTR& aEdge ); - - /// Creates an arbitrary CCW dart - DART CreateDart(); - - /// Returns a list of "triangles" (one leading half-edge for each triangle) - const std::list& GetLeadingEdges() const - { - return m_leadingEdges; - } - - /// Returns the number of triangles - int NoTriangles() const - { - return (int) m_leadingEdges.size(); - } - - /// Returns a list of half-edges (one half-edge for each arc) - void GetEdges( std::list& aEdges, bool aSkipBoundaryEdges = false ) const; - -#ifdef TTL_USE_NODE_FLAG - /// Sets flag in all the nodes - void FlagNodes( bool aFlag ) const; - - /// Returns a list of nodes. This function requires TTL_USE_NODE_FLAG to be defined. \see Node. - std::list* GetNodes() const; -#endif - - /// Swaps edges until the triangulation is Delaunay (constrained edges are not swapped) - void OptimizeDelaunay(); - - /// Checks if the triangulation is Delaunay - bool CheckDelaunay() const; - - /// Returns an arbitrary interior node (as the source node of the returned edge) - EDGE_PTR GetInteriorNode() const; - - EDGE_PTR GetBoundaryEdgeInTriangle( const EDGE_PTR& aEdge ) const; - - /// Returns an arbitrary boundary edge - EDGE_PTR GetBoundaryEdge() const; - - /// Print edges for plotting with, e.g., gnuplot - void PrintEdges( std::ofstream& aOutput ) const; - - friend class ttl::TRIANGULATION_HELPER; -}; -} // End of hed namespace - -#endif diff --git a/thirdparty/ttl/include/ttl/ttl.h b/thirdparty/ttl/include/ttl/ttl.h deleted file mode 100644 index 391104ff24..0000000000 --- a/thirdparty/ttl/include/ttl/ttl.h +++ /dev/null @@ -1,1904 +0,0 @@ -/* - * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT, - * Applied Mathematics, Norway. - * - * Contact information: E-mail: tor.dokken@sintef.no - * SINTEF ICT, Department of Applied Mathematics, - * P.O. Box 124 Blindern, - * 0314 Oslo, Norway. - * - * This file is part of TTL. - * - * see https://www.sintef.no/projectweb/geometry-toolkits/ttl/ - * and https://github.com/SINTEF-Geometry/TTL - * - * TTL is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * TTL is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with TTL. If not, see - * . - * - * In accordance with Section 7(b) of the GNU Affero General Public - * License, a covered work must retain the producer line in every data - * file that is created or manipulated using TTL. - * - * Other Usage - * You can be released from the requirements of the license by purchasing - * a commercial license. Buying such a license is mandatory as soon as you - * develop commercial activities involving the TTL library without - * disclosing the source code of your own applications. - * - * This file may be used in accordance with the terms contained in a - * written agreement between you and SINTEF ICT. - */ - -#ifndef _TTL_H_ -#define _TTL_H_ - -#include -#include - -// Debugging -#ifdef DEBUG_TTL -static void errorAndExit( char* aMessage ) -{ - cout << "\n!!! ERROR: " << aMessage << " !!!\n" << endl; - exit(-1); -} -#endif - -// Next on TOPOLOGY: -// - get triangle strips -// - weighted graph, algorithms using a weight (real) for each edge, -// e.g. an "abstract length". Use for minimum spanning tree -// or some arithmetics on weights? -// - Circulators as defined in CGAL with more STL compliant code - -// - analyze in detail locateFace: e.g. detect 0-orbit in case of infinite loop -// around a node etc. - -/** - * \brief Main interface to TTL -* -* This namespace contains the basic generic algorithms for the TTL, -* the Triangulation Template Library.\n -* -* Examples of functionality are: -* - Incremental Delaunay triangulation -* - Constrained triangulation -* - Insert/remove nodes and constrained edges -* - Traversal operations -* - Misc. queries for extracting information for visualisation systems etc. -* -* \par General requirements and assumptions: -* - \e DART_TYPE and \e TRAITS_TYPE should be implemented in accordance with the description -* in \ref api. -* - A \b "Requires:" section in the documentation of a function template -* shows which functionality is required in \e TRAITS_TYPE to -* support that specific function.\n -* Functionalty required in \e DART_TYPE is the same (almost) for all -* function templates; see \ref api and the example referred to. -* - When a reference to a \e dart object is passed to a function in TTL, -* it is assumed that it is oriented \e counterclockwise (CCW) in a triangle -* unless it is explicitly mentioned that it can also be \e clockwise (CW). -* The same applies for a dart that is passed from a function in TTL to -* the users TRAITS_TYPE class (or struct). -* - When an edge (represented with a dart) is swapped, it is assumed that darts -* outside the quadrilateral where the edge is a diagonal are not affected by -* the swap. Thus, \ref hed::TTLtraits::swapEdge "TRAITS_TYPE::swapEdge" -* must be implemented in accordance with this rule. -* -* \par Glossary: -* - General terms are explained in \ref api. -* - \e CCW - counterclockwise -* - \e CW - clockwise -* - \e 0_orbit, \e 1_orbit and \e 2_orbit: A sequence of darts around -* a node, around an edge and in a triangle respectively; -* see get_0_orbit_interior and get_0_orbit_boundary -* - \e arc - In a triangulation an arc is equivalent with an edge -* -* \see -* \ref ttl_util and \ref api -* -* \author -* �yvind Hjelle, oyvindhj@ifi.uio.no -*/ - - -namespace ttl -{ -class TRIANGULATION_HELPER -{ -#ifndef DOXYGEN_SHOULD_SKIP_THIS - -public: - TRIANGULATION_HELPER( hed::TRIANGULATION& aTriang ) : - m_triangulation( aTriang ) - { - } - - // Delaunay Triangulation - template - bool InsertNode( DART_TYPE& aDart, POINT_TYPE& aPoint ); - - template - void RemoveRectangularBoundary( DART_TYPE& aDart ); - - template - void RemoveNode( DART_TYPE& aDart ); - - template - void RemoveBoundaryNode( DART_TYPE& aDart ); - - template - void RemoveInteriorNode( DART_TYPE& aDart ); - - // Topological and Geometric Queries - // --------------------------------- - template - static bool LocateFaceSimplest( const POINT_TYPE& aPoint, DART_TYPE& aDart ); - - template - static bool LocateTriangle( const POINT_TYPE& aPoint, DART_TYPE& aDart ); - - template - static bool InTriangle( const POINT_TYPE& aPoint, const DART_TYPE& aDart ); - - template - static void GetBoundary( const DART_TYPE& aDart, DART_LIST_TYPE& aBoundary ); - - template - static bool IsBoundaryEdge( const DART_TYPE& aDart ); - - template - static bool IsBoundaryFace( const DART_TYPE& aDart ); - - template - static bool IsBoundaryNode( const DART_TYPE& aDart ); - - template - static int GetDegreeOfNode( const DART_TYPE& aDart ); - - template - static void Get0OrbitInterior( const DART_TYPE& aDart, DART_LIST_TYPE& aOrbit ); - - template - static void Get0OrbitBoundary( const DART_TYPE& aDart, DART_LIST_TYPE& aOrbit ); - - template - static bool Same0Orbit( const DART_TYPE& aD1, const DART_TYPE& aD2 ); - - template - static bool Same1Orbit( const DART_TYPE& aD1, const DART_TYPE& aD2 ); - - template - static bool Same2Orbit( const DART_TYPE& aD1, const DART_TYPE& aD2 ); - - template - static bool SwappableEdge( const DART_TYPE& aDart, bool aAllowDegeneracy = false ); - - template - static void PositionAtNextBoundaryEdge( DART_TYPE& aDart ); - - template - static bool ConvexBoundary( const DART_TYPE& aDart ); - - // Utilities for Delaunay Triangulation - // ------------------------------------ - template - void OptimizeDelaunay( DART_LIST_TYPE& aElist ); - - template - void OptimizeDelaunay( DART_LIST_TYPE& aElist, const typename DART_LIST_TYPE::iterator aEnd ); - - template - bool SwapTestDelaunay( const DART_TYPE& aDart, bool aCyclingCheck = false ) const; - - template - void RecSwapDelaunay( DART_TYPE& aDiagonal ); - - template - void SwapEdgesAwayFromInteriorNode( DART_TYPE& aDart, LIST_TYPE& aSwappedEdges ); - - template - void SwapEdgesAwayFromBoundaryNode( DART_TYPE& aDart, LIST_TYPE& aSwappedEdges ); - - template - void SwapEdgeInList( const typename DART_LIST_TYPE::iterator& aIt, DART_LIST_TYPE& aElist ); - - // Constrained Triangulation - // ------------------------- - template - static DART_TYPE InsertConstraint( DART_TYPE& aDStart, DART_TYPE& aDEnd, bool aOptimizeDelaunay ); - -private: - hed::TRIANGULATION& m_triangulation; - - template - void insertNodes( FORWARD_ITERATOR aFirst, FORWARD_ITERATOR aLast, DART_TYPE& aDart ); - - template - static bool isMemberOfFace( const TOPOLOGY_ELEMENT_TYPE& aTopologyElement, const DART_TYPE& aDart ); - - template - static bool locateFaceWithNode( const NODE_TYPE& aNode, DART_TYPE& aDartIter ); - - template - static void getAdjacentTriangles( const DART_TYPE& aDart, DART_TYPE& aT1, DART_TYPE& aT2, - DART_TYPE& aT3 ); - - template - static void getNeighborNodes( const DART_TYPE& aDart, std::list& aNodeList, - bool& aBoundary ); - - template - static bool degenerateTriangle( const DART_TYPE& aDart ); -}; - -#endif // DOXYGEN_SHOULD_SKIP_THIS - - - /** @name Delaunay Triangulation */ -//@{ -/** - * Inserts a new node in an existing Delaunay triangulation and - * swaps edges to obtain a new Delaunay triangulation. - * This is the basic function for incremental Delaunay triangulation. - * When starting from a set of points, an initial Delaunay triangulation - * can be created as two triangles forming a rectangle that contains - * all the points. - * After \c insertNode has been called repeatedly with all the points, - * removeRectangularBoundary can be called to remove triangles - * at the boundary of the triangulation so that the boundary - * form the convex hull of the points. - * - * Note that this incremetal scheme will run much faster if the points - * have been sorted lexicographically on \e x and \e y. - * - * \param aDart - * An arbitrary CCW dart in the tringulation.\n - * Output: A CCW dart incident to the new node. - * - * \param aPoint - * A point (node) to be inserted in the triangulation. - * - * \retval bool - * \c true if \e point was inserted; \c false if not.\n - * If \e point is outside the triangulation, or the input dart is not valid, - * \c false is returned. - * - * \b require - * - \ref hed::TTLtraits::splitTriangle "TRAITS_TYPE::splitTriangle" (DART_TYPE&, const POINT_TYPE&) - * - * \a using - * - locateTriangle - * - RecSwapDelaunay - * - * \note - * - For efficiency reasons \e dart should be close to the insertion \e point. - * - * \see - * removeRectangularBoundary - */ -template -bool TRIANGULATION_HELPER::InsertNode( DART_TYPE& aDart, POINT_TYPE& aPoint ) -{ - bool found = LocateTriangle( aPoint, aDart ); - - if( !found ) - { -#ifdef DEBUG_TTL - cout << "ERROR: Triangulation::insertNode: NO triangle found. /n"; -#endif - return false; - } - - // ??? can we hide the dart? this is not possible if one triangle only - m_triangulation.splitTriangle( aDart, aPoint ); - - DART_TYPE d1 = aDart; - d1.Alpha2().Alpha1().Alpha2().Alpha0().Alpha1(); - - DART_TYPE d2 = aDart; - d2.Alpha1().Alpha0().Alpha1(); - - // Preserve a dart as output incident to the node and CCW - DART_TYPE d3 = aDart; - d3.Alpha2(); - aDart = d3; // and see below - //DART_TYPE dsav = d3; - d3.Alpha0().Alpha1(); - - //if (!TRAITS_TYPE::fixedEdge(d1) && !IsBoundaryEdge(d1)) { - if( !IsBoundaryEdge( d1 ) ) - { - d1.Alpha2(); - RecSwapDelaunay( d1 ); - } - - //if (!TRAITS_TYPE::fixedEdge(d2) && !IsBoundaryEdge(d2)) { - if( !IsBoundaryEdge( d2 ) ) - { - d2.Alpha2(); - RecSwapDelaunay( d2 ); - } - - // Preserve the incoming dart as output incident to the node and CCW - //d = dsav.Alpha2(); - aDart.Alpha2(); - //if (!TRAITS_TYPE::fixedEdge(d3) && !IsBoundaryEdge(d3)) { - if( !IsBoundaryEdge( d3 ) ) - { - d3.Alpha2(); - RecSwapDelaunay( d3 ); - } - - return true; -} - -//------------------------------------------------------------------------------------------------ -// Private/Hidden function (might change later) -template -void TRIANGULATION_HELPER::insertNodes( FORWARD_ITERATOR aFirst, FORWARD_ITERATOR aLast, - DART_TYPE& aDart ) -{ - - // Assumes that the dereferenced point objects are pointers. - // References to the point objects are then passed to TTL. - - FORWARD_ITERATOR it; - for( it = aFirst; it != aLast; ++it ) - { - InsertNode( aDart, **it ); - } -} - - -/** Removes the rectangular boundary of a triangulation as a final step of an - * incremental Delaunay triangulation. - * The four nodes at the corners will be removed and the resulting triangulation - * will have a convex boundary and be Delaunay. - * - * \param aDart - * A CCW dart at the boundary of the triangulation\n - * Output: A CCW dart at the new boundary - * - * \a using - * - RemoveBoundaryNode - * - * \note - * - This function requires that the boundary of the m_triangulation is - * a rectangle with four nodes (one in each corner). - */ -template -void TRIANGULATION_HELPER::RemoveRectangularBoundary( DART_TYPE& aDart ) -{ - DART_TYPE d_next = aDart; - DART_TYPE d_iter; - - for( int i = 0; i < 4; i++ ) - { - d_iter = d_next; - d_next.Alpha0(); - PositionAtNextBoundaryEdge( d_next ); - RemoveBoundaryNode( d_iter ); - } - - aDart = d_next; // Return a dart at the new boundary -} - -/** Removes the node associated with \e dart and - * updates the triangulation to be Delaunay. - * - * \a using - * - RemoveBoundaryNode if \e dart represents a node at the boundary - * - RemoveInteriorNode if \e dart represents an interior node - * - * \note - * - The node cannot belong to a fixed (constrained) edge that is not - * swappable. (An endless loop is likely to occur in this case). - */ -template -void TRIANGULATION_HELPER::RemoveNode( DART_TYPE& aDart ) -{ - - if( isBoundaryNode( aDart ) ) - RemoveBoundaryNode( aDart ); - else - RemoveInteriorNode( aDart ); -} - -/** Removes the boundary node associated with \e dart and - * updates the triangulation to be Delaunay. - * - * \a using - * - SwapEdgesAwayFromBoundaryNode - * - OptimizeDelaunay - * - * \b require - * - \ref hed::TTLtraits::removeBoundaryTriangle "TRAITS_TYPE::removeBoundaryTriangle" (Dart&) - */ -template -void TRIANGULATION_HELPER::RemoveBoundaryNode( DART_TYPE& aDart ) -{ - - // ... and update Delaunay - // - CCW dart must be given (for remove) - // - No dart is delivered back now (but this is possible if - // we assume that there is not only one triangle left in the m_triangulation. - - // Position at boundary edge and CCW - if( !IsBoundaryEdge( aDart ) ) - { - aDart.Alpha1(); // ensures that next function delivers back a CCW dart (if the given dart is CCW) - PositionAtNextBoundaryEdge( aDart ); - } - - std::list swapped_edges; - SwapEdgesAwayFromBoundaryNode( aDart, swapped_edges ); - - // Remove boundary triangles and remove the new boundary from the list - // of swapped edges, see below. - DART_TYPE d_iter = aDart; - DART_TYPE dnext = aDart; - bool bend = false; - while( bend == false ) - { - dnext.Alpha1().Alpha2(); - if( IsBoundaryEdge( dnext ) ) - bend = true; // Stop when boundary - - // Generic: Also remove the new boundary from the list of swapped edges - DART_TYPE n_bedge = d_iter; - n_bedge.Alpha1().Alpha0().Alpha1().Alpha2(); // new boundary edge - - // ??? can we avoid find if we do this in swap away? - typename std::list::iterator it; - it = find( swapped_edges.begin(), swapped_edges.end(), n_bedge ); - - if( it != swapped_edges.end() ) - swapped_edges.erase( it ); - - // Remove the boundary triangle - m_triangulation.removeBoundaryTriangle( d_iter ); - d_iter = dnext; - } - - // Optimize Delaunay - typedef std::list DART_LIST_TYPE; - OptimizeDelaunay( swapped_edges ); -} - - -/** Removes the interior node associated with \e dart and - * updates the triangulation to be Delaunay. - * - * \a using - * - SwapEdgesAwayFromInteriorNode - * - OptimizeDelaunay - * - * \b require - * - \ref hed::TTLtraits::reverse_splitTriangle "TRAITS_TYPE::reverse_splitTriangle" (Dart&) - * - * \note - * - The node cannot belong to a fixed (constrained) edge that is not - * swappable. (An endless loop is likely to occur in this case). - */ -template -void TRIANGULATION_HELPER::RemoveInteriorNode( DART_TYPE& aDart ) -{ - // ... and update to Delaunay. - // Must allow degeneracy temporarily, see comments in swap edges away - // Assumes: - // - revese_splitTriangle does not affect darts - // outside the resulting triangle. - - // 1) Swaps edges away from the node until degree=3 (generic) - // 2) Removes the remaining 3 triangles and creates a new to fill the hole - // unsplitTriangle which is required - // 3) Runs LOP on the platelet to obtain a Delaunay m_triangulation - // (No dart is delivered as output) - - // Assumes dart is counterclockwise - - std::list swapped_edges; - SwapEdgesAwayFromInteriorNode( aDart, swapped_edges ); - - // The reverse operation of split triangle: - // Make one triangle of the three triangles at the node associated with dart - // TRAITS_TYPE:: - m_triangulation.reverseSplitTriangle( aDart ); - - // ???? Not generic yet if we are very strict: - // When calling unsplit triangle, darts at the three opposite sides may - // change! - // Should we hide them longer away??? This is possible since they cannot - // be boundary edges. - // ----> Or should we just require that they are not changed??? - - // Make the swapped-away edges Delaunay. - // Note the theoretical result: if there are no edges in the list, - // the triangulation is Delaunay already - - OptimizeDelaunay( swapped_edges ); -} - -//@} // End of Delaunay Triangulation Group - -/** @name Topological and Geometric Queries */ -//@{ -//------------------------------------------------------------------------------------------------ -// Private/Hidden function (might change later) -template -bool TRIANGULATION_HELPER::isMemberOfFace( const TOPOLOGY_ELEMENT_TYPE& aTopologyElement, - const DART_TYPE& aDart ) -{ - // Check if the given topology element (node, edge or face) is a member of the face - // Assumes: - // - DART_TYPE::isMember(TOPOLOGY_ELEMENT_TYPE) - - DART_TYPE dart_iter = aDart; - - do - { - if( dart_iter.isMember( aTopologyElement ) ) - return true; - dart_iter.Alpha0().Alpha1(); - } - while( dart_iter != aDart ); - - return false; -} - -//------------------------------------------------------------------------------------------------ -// Private/Hidden function (might change later) -template -bool TRIANGULATION_HELPER::locateFaceWithNode( const NODE_TYPE& aNode, DART_TYPE& aDartIter ) -{ - // Locate a face in the topology structure with the given node as a member - // Assumes: - // - TRAITS_TYPE::Orient2D(DART_TYPE, DART_TYPE, NODE_TYPE) - // - DART_TYPE::isMember(NODE_TYPE) - // - Note that if false is returned, the node might still be in the - // topology structure. Application programmer - // should check all if by hypothesis the node is in the topology structure; - // see doc. on LocateTriangle. - - bool status = LocateFaceSimplest( aNode, aDartIter ); - - if( status == false ) - return status; - - // True was returned from LocateFaceSimplest, but if the located triangle is - // degenerate and the node is on the extension of the edges, - // the node might still be inside. Check if node is a member and return false - // if not. (Still the node might be in the topology structure, see doc. above - // and in locateTriangle(const POINT_TYPE& point, DART_TYPE& dart_iter) - - return isMemberOfFace( aNode, aDartIter ); -} - -/** Locates the face containing a given point. - * It is assumed that the tessellation (e.g. a triangulation) is \e regular in the sense that - * there are no holes, the boundary is convex and there are no degenerate faces. - * - * \param aPoint - * A point to be located - * - * \param aDart - * An arbitrary CCW dart in the triangulation\n - * Output: A CCW dart in the located face - * - * \retval bool - * \c true if a face is found; \c false if not. - * - * \b require - * - \ref hed::TTLtraits::Orient2D "TRAITS_TYPE::Orient2D" (DART_TYPE&, DART_TYPE&, POINT_TYPE&) - * - * \note - * - If \c false is returned, \e point may still be inside a face if the tessellation is not - * \e regular as explained above. - * - * \see - * LocateTriangle - */ -template -bool TRIANGULATION_HELPER::LocateFaceSimplest( const POINT_TYPE& aPoint, DART_TYPE& aDart ) -{ - // Not degenerate triangles if point is on the extension of the edges - // But inTriangle may be called in case of true (may update to inFace2) - // Convex boundary - // no holes - // convex faces (works for general convex faces) - // Not specialized for triangles, but ok? - // - // TRAITS_TYPE::orint2d(POINT_TYPE) is the half open half-plane defined - // by the dart: - // n1 = dart.node() - // n2 = dart.Alpha0().node - // Only the following gives true: - // ((n2->x()-n1->x())*(point.y()-n1->y()) >= (point.x()-n1->x())*(n2->y()-n1->y())) - - DART_TYPE dart_start; - dart_start = aDart; - DART_TYPE dart_prev; - - DART_TYPE d0; - for( ;; ) - { - d0 = aDart; - d0.Alpha0(); - - if( TRAITS_TYPE::Orient2D( aDart, d0, aPoint ) >= 0 ) - { - aDart.Alpha0().Alpha1(); - if( aDart == dart_start ) - return true; // left to all edges in face - } - else - { - dart_prev = aDart; - aDart.Alpha2(); - - if( aDart == dart_prev ) - return false; // iteration to outside boundary - - dart_start = aDart; - dart_start.Alpha0(); - - aDart.Alpha1(); // avoid twice on same edge and ccw in next - } - } -} - - -/** Locates the triangle containing a given point. - * It is assumed that the triangulation is \e regular in the sense that there - * are no holes and the boundary is convex. - * This function deals with degeneracy to some extent, but round-off errors may still - * lead to a wrong result if triangles are degenerate. - * - * \param aPoint - * A point to be located - * - * \param aDart - * An arbitrary CCW dart in the triangulation\n - * Output: A CCW dart in the located triangle - * - * \retval bool - * \c true if a triangle is found; \c false if not.\n - * If \e point is outside the m_triangulation, in which case \c false is returned, - * then the edge associated with \e dart will be at the boundary of the m_triangulation. - * - * \a using - * - LocateFaceSimplest - * - InTriangle - */ -template -bool TRIANGULATION_HELPER::LocateTriangle( const POINT_TYPE& aPoint, DART_TYPE& aDart ) -{ - // The purpose is to have a fast and stable procedure that - // i) avoids concluding that a point is inside a triangle if it is not inside - // ii) avoids infinite loops - - // Thus, if false is returned, the point might still be inside a triangle in - // the triangulation. But this will probably only occur in the following cases: - // i) There are holes in the triangulation which causes the procedure to stop. - // ii) The boundary of the m_triangulation is not convex. - // ii) There might be degenerate triangles interior to the triangulation, or on the - // the boundary, which in some cases might cause the procedure to stop there due - // to the logic of the algorithm. - - // It is the application programmer's responsibility to check further if false is - // returned. For example, if by hypothesis the point is inside a triangle - // in the triangulation and and false is returned, then all triangles in the - // triangulation should be checked by the application. This can be done using - // the function: - // bool inTriangle(const POINT_TYPE& point, const DART_TYPE& dart). - - // Assumes: - // - CrossProduct2D, ScalarProduct2D etc., see functions called - - bool status = LocateFaceSimplest( aPoint, aDart ); - - if( status == false ) - return status; - - // There may be degeneracy, i.e., the point might be outside the triangle - // on the extension of the edges of a degenerate triangle. - - // The next call returns true if inside a non-degenerate or a degenerate triangle, - // but false if the point coincides with the "supernode" in the case where all - // edges are degenerate. - return InTriangle( aPoint, aDart ); -} - -/** Checks if \e point is inside the triangle associated with \e dart. - * This function deals with degeneracy to some extent, but round-off errors may still - * lead to wrong result if the triangle is degenerate. - * - * \param aDart - * A CCW dart in the triangle - * - * \b require - * - \ref hed::TTLtraits::CrossProduct2D "TRAITS_TYPE::CrossProduct2D" (DART_TYPE&, POINT_TYPE&) - * - \ref hed::TTLtraits::ScalarProduct2D "TRAITS_TYPE::ScalarProduct2D" (DART_TYPE&, POINT_TYPE&) - * - * \see - * InTriangleSimplest - */ -template -bool TRIANGULATION_HELPER::InTriangle( const POINT_TYPE& aPoint, const DART_TYPE& aDart ) -{ - - // SHOULD WE INCLUDE A STRATEGY WITH EDGE X e_1 ETC? TO GUARANTEE THAT - // ONLY ON ONE EDGE? BUT THIS DOES NOT SOLVE PROBLEMS WITH - // notInE1 && notInE1.neghbour ? - - // Returns true if inside (but not necessarily strictly inside) - // Works for degenerate triangles, but not when all edges are degenerate, - // and the aPoint coincides with all nodes; - // then false is always returned. - - typedef typename TRAITS_TYPE::REAL_TYPE REAL_TYPE; - - DART_TYPE dart_iter = aDart; - - REAL_TYPE cr1 = TRAITS_TYPE::CrossProduct2D( dart_iter, aPoint ); - if( cr1 < 0 ) - return false; - - dart_iter.Alpha0().Alpha1(); - REAL_TYPE cr2 = TRAITS_TYPE::CrossProduct2D( dart_iter, aPoint ); - - if( cr2 < 0 ) - return false; - - dart_iter.Alpha0().Alpha1(); - REAL_TYPE cr3 = TRAITS_TYPE::CrossProduct2D( dart_iter, aPoint ); - if( cr3 < 0 ) - return false; - - // All cross products are >= 0 - // Check for degeneracy - if( cr1 != 0 || cr2 != 0 || cr3 != 0 ) - return true; // inside non-degenerate face - - // All cross-products are zero, i.e. degenerate triangle, check if inside - // Strategy: d.ScalarProduct2D >= 0 && alpha0(d).d.ScalarProduct2D >= 0 for one of - // the edges. But if all edges are degenerate and the aPoint is on (all) the nodes, - // then "false is returned". - - DART_TYPE dart_tmp = dart_iter; - REAL_TYPE sc1 = TRAITS_TYPE::ScalarProduct2D( dart_tmp, aPoint ); - REAL_TYPE sc2 = TRAITS_TYPE::ScalarProduct2D( dart_tmp.Alpha0(), aPoint ); - - if( sc1 >= 0 && sc2 >= 0 ) - { - // test for degenerate edge - if( sc1 != 0 || sc2 != 0 ) - return true; // interior to this edge or on a node (but see comment above) - } - - dart_tmp = dart_iter.Alpha0().Alpha1(); - sc1 = TRAITS_TYPE::ScalarProduct2D( dart_tmp, aPoint ); - sc2 = TRAITS_TYPE::ScalarProduct2D( dart_tmp.Alpha0(), aPoint ); - - if( sc1 >= 0 && sc2 >= 0 ) - { - // test for degenerate edge - if( sc1 != 0 || sc2 != 0 ) - return true; // interior to this edge or on a node (but see comment above) - } - - dart_tmp = dart_iter.Alpha1(); - sc1 = TRAITS_TYPE::ScalarProduct2D( dart_tmp, aPoint ); - sc2 = TRAITS_TYPE::ScalarProduct2D( dart_tmp.Alpha0(), aPoint ); - - if( sc1 >= 0 && sc2 >= 0 ) - { - // test for degenerate edge - if( sc1 != 0 || sc2 != 0 ) - return true; // interior to this edge or on a node (but see comment above) - } - - // Not on any of the edges of the degenerate triangle. - // The only possibility for the aPoint to be "inside" is that all edges are degenerate - // and the point coincide with all nodes. So false is returned in this case. - - return false; -} - - - //------------------------------------------------------------------------------------------------ -// Private/Hidden function (might change later) -template -void TRIANGULATION_HELPER::getAdjacentTriangles( const DART_TYPE& aDart, DART_TYPE& aT1, - DART_TYPE& aT2, DART_TYPE& aT3 ) -{ - - DART_TYPE dart_iter = aDart; - - // add first - if( dart_iter.Alpha2() != aDart ) - { - aT1 = dart_iter; - dart_iter = aDart; - } - - // add second - dart_iter.Alpha0(); - dart_iter.Alpha1(); - DART_TYPE dart_prev = dart_iter; - - if( ( dart_iter.Alpha2() ) != dart_prev ) - { - aT2 = dart_iter; - dart_iter = dart_prev; - } - - // add third - dart_iter.Alpha0(); - dart_iter.Alpha1(); - dart_prev = dart_iter; - - if( ( dart_iter.Alpha2() ) != dart_prev ) - aT3 = dart_iter; -} - -//------------------------------------------------------------------------------------------------ -/** Gets the boundary as sequence of darts, where the edges associated with the darts are boundary - * edges, given a dart with an associating edge at the boundary of a topology structure. - * The first dart in the sequence will be the given one, and the others will have the same - * orientation (CCW or CW) as the first. - * Assumes that the given dart is at the boundary. - * - * \param aDart - * A dart at the boundary (CCW or CW) - * - * \param aBoundary - * A sequence of darts, where the associated edges are the boundary edges - * - * \b require - * - DART_LIST_TYPE::push_back (DART_TYPE&) - */ -template -void TRIANGULATION_HELPER::GetBoundary( const DART_TYPE& aDart, DART_LIST_TYPE& aBoundary ) -{ - // assumes the given dart is at the boundary (by edge) - - DART_TYPE dart_iter( aDart ); - aBoundary.push_back( dart_iter ); // Given dart as first element - dart_iter.Alpha0(); - PositionAtNextBoundaryEdge( dart_iter ); - - while( dart_iter != aDart ) - { - aBoundary.push_back( dart_iter ); - dart_iter.Alpha0(); - PositionAtNextBoundaryEdge( dart_iter ); - } -} - -/** Checks if the edge associated with \e dart is at - * the boundary of the m_triangulation. - * - * \par Implements: - * \code - * DART_TYPE dart_iter = dart; - * if (dart_iter.Alpha2() == dart) - * return true; - * else - * return false; - * \endcode - */ -template -bool TRIANGULATION_HELPER::IsBoundaryEdge( const DART_TYPE& aDart ) -{ - DART_TYPE dart_iter = aDart; - - if( dart_iter.Alpha2() == aDart ) - return true; - else - return false; -} - -/** Checks if the face associated with \e dart is at - * the boundary of the m_triangulation. - */ -template -bool TRIANGULATION_HELPER::IsBoundaryFace( const DART_TYPE& aDart ) -{ - // Strategy: boundary if alpha2(d)=d - - DART_TYPE dart_iter( aDart ); - DART_TYPE dart_prev; - - do - { - dart_prev = dart_iter; - - if( dart_iter.Alpha2() == dart_prev ) - return true; - else - dart_iter = dart_prev; // back again - - dart_iter.Alpha0(); - dart_iter.Alpha1(); - - } while( dart_iter != aDart ); - - return false; -} - -/** Checks if the node associated with \e dart is at - * the boundary of the m_triangulation. - */ -template -bool TRIANGULATION_HELPER::IsBoundaryNode( const DART_TYPE& aDart ) -{ - // Strategy: boundary if alpha2(d)=d - - DART_TYPE dart_iter( aDart ); - DART_TYPE dart_prev; - - // If input dart is reached again, then internal node - // If alpha2(d)=d, then boundary - - do - { - dart_iter.Alpha1(); - dart_prev = dart_iter; - dart_iter.Alpha2(); - - if( dart_iter == dart_prev ) - return true; - - } while( dart_iter != aDart ); - - return false; -} - -/** Returns the degree of the node associated with \e dart. - * - * \par Definition: - * The \e degree (or valency) of a node \e V in a m_triangulation, - * is defined as the number of edges incident with \e V, i.e., - * the number of edges joining \e V with another node in the triangulation. - */ -template -int TRIANGULATION_HELPER::GetDegreeOfNode( const DART_TYPE& aDart ) -{ - DART_TYPE dart_iter( aDart ); - DART_TYPE dart_prev; - - // If input dart is reached again, then interior node - // If alpha2(d)=d, then boundary - - int degree = 0; - bool boundaryVisited = false; - do - { - dart_iter.Alpha1(); - degree++; - dart_prev = dart_iter; - - dart_iter.Alpha2(); - - if( dart_iter == dart_prev ) - { - if( !boundaryVisited ) - { - boundaryVisited = true; - // boundary is reached first time, count in the reversed direction - degree++; // count the start since it is not done above - dart_iter = aDart; - dart_iter.Alpha2(); - } else - return degree; - } - - } while( dart_iter != aDart ); - - return degree; -} - -// Modification of GetDegreeOfNode: -// Strategy, reverse the list and start in the other direction if the boundary -// is reached. NB. copying of darts but ok., or we could have collected pointers, -// but the memory management. - -// NOTE: not symmetry if we choose to collect opposite edges -// now we collect darts with radiating edges - -// Remember that we must also copy the node, but ok with push_back -// The size of the list will be the degree of the node - -// No CW/CCW since topology only - -// Each dart consists of an incident edge and an adjacent node. -// But note that this is only how we interpret the dart in this implementation. -// Given this list, how can we find the opposite edges: -// We can perform alpha1 on each, but for boundary nodes we will get one edge twice. -// But this is will always be the last dart! -// The darts in the list are in sequence and starts with the alpha0(dart) -// alpha0, alpha1 and alpha2 - -// Private/Hidden function -template -void TRIANGULATION_HELPER::getNeighborNodes( const DART_TYPE& aDart, - std::list& aNodeList, bool& aBoundary ) -{ - DART_TYPE dart_iter( aDart ); - dart_iter.Alpha0(); // position the dart at an opposite node - - DART_TYPE dart_prev = dart_iter; - bool start_at_boundary = false; - dart_iter.Alpha2(); - - if( dart_iter == dart_prev ) - start_at_boundary = true; - else - dart_iter = dart_prev; // back again - - DART_TYPE dart_start = dart_iter; - - do - { - aNodeList.push_back( dart_iter ); - dart_iter.Alpha1(); - dart_iter.Alpha0(); - dart_iter.Alpha1(); - dart_prev = dart_iter; - dart_iter.Alpha2(); - - if( dart_iter == dart_prev ) - { - // boundary reached - aBoundary = true; - - if( start_at_boundary == true ) - { - // add the dart which now is positioned at the opposite boundary - aNodeList.push_back( dart_iter ); - return; - } - else - { - // call the function again such that we start at the boundary - // first clear the list and reposition to the initial node - dart_iter.Alpha0(); - aNodeList.clear(); - getNeighborNodes( dart_iter, aNodeList, aBoundary ); - - return; // after one recursive step - } - } - } - while( dart_iter != dart_start ); - - aBoundary = false; -} - -/** Gets the 0-orbit around an interior node. - * - * \param aDart - * A dart (CCW or CW) positioned at an \e interior node. - * - * \retval aOrbit - * Sequence of darts with one orbit for each arc. All the darts have the same - * orientation (CCW or CW) as \e dart, and \e dart is the first element - * in the sequence. - * - * \b require - * - DART_LIST_TYPE::push_back (DART_TYPE&) - * - * \see - * Get0OrbitBoundary - */ -template -void TRIANGULATION_HELPER::Get0OrbitInterior( const DART_TYPE& aDart, DART_LIST_TYPE& aOrbit ) -{ - DART_TYPE d_iter = aDart; - aOrbit.push_back( d_iter ); - d_iter.Alpha1().Alpha2(); - - while( d_iter != aDart ) - { - aOrbit.push_back( d_iter ); - d_iter.Alpha1().Alpha2(); - } -} - -/** Gets the 0-orbit around a node at the boundary - * - * \param aDart - * A dart (CCW or CW) positioned at a \e boundary \e node and at a \e boundary \e edge. - * - * \retval orbit - * Sequence of darts with one orbit for each arc. All the darts, \e exept \e the \e last one, - * have the same orientation (CCW or CW) as \e dart, and \e dart is the first element - * in the sequence. - * - * \b require - * - DART_LIST_TYPE::push_back (DART_TYPE&) - * - * \note - * - The last dart in the sequence have opposite orientation compared to the others! - * - * \see - * Get0OrbitInterior - */ -template -void TRIANGULATION_HELPER::Get0OrbitBoundary( const DART_TYPE& aDart, DART_LIST_TYPE& aOrbit ) -{ - DART_TYPE dart_prev; - DART_TYPE d_iter = aDart; - - do - { - aOrbit.push_back( d_iter ); - d_iter.Alpha1(); - dart_prev = d_iter; - d_iter.Alpha2(); - } - while( d_iter != dart_prev ); - - aOrbit.push_back( d_iter ); // the last one with opposite orientation -} - -/** Checks if the two darts belong to the same 0-orbit, i.e., - * if they share a node. - * \e d1 and/or \e d2 can be CCW or CW. - * - * (This function also examines if the the node associated with - * \e d1 is at the boundary, which slows down the function (slightly). - * If it is known that the node associated with \e d1 is an interior - * node and a faster version is needed, the user should implement his/her - * own version.) - */ -template -bool TRIANGULATION_HELPER::Same0Orbit( const DART_TYPE& aD1, const DART_TYPE& aD2 ) -{ - // Two copies of the same dart - DART_TYPE d_iter = aD2; - DART_TYPE d_end = aD2; - - if( isBoundaryNode( d_iter ) ) - { - // position at both boundary edges - PositionAtNextBoundaryEdge( d_iter ); - d_end.Alpha1(); - PositionAtNextBoundaryEdge( d_end ); - } - - for( ;; ) - { - if( d_iter == aD1 ) - return true; - - d_iter.Alpha1(); - - if( d_iter == aD1 ) - return true; - - d_iter.Alpha2(); - - if( d_iter == d_end ) - break; - } - - return false; -} - -/** Checks if the two darts belong to the same 1-orbit, i.e., - * if they share an edge. - * \e d1 and/or \e d2 can be CCW or CW. - */ -template -bool TRIANGULATION_HELPER::Same1Orbit( const DART_TYPE& aD1, const DART_TYPE& aD2 ) -{ - DART_TYPE d_iter = aD2; - - // (Also works at the boundary) - return ( d_iter == aD1 || d_iter.Alpha0() == aD1 || - d_iter.Alpha2() == aD1 || d_iter.Alpha0() == aD1 ); -} - -//------------------------------------------------------------------------------------------------ -/** Checks if the two darts belong to the same 2-orbit, i.e., - * if they lie in the same triangle. - * \e d1 and/or \e d2 can be CCW or CW - */ -template -bool TRIANGULATION_HELPER::Same2Orbit( const DART_TYPE& aD1, const DART_TYPE& aD2 ) -{ - DART_TYPE d_iter = aD2; - - return ( d_iter == aD1 || d_iter.Alpha0() == aD1 || d_iter.Alpha1() == aD1 || - d_iter.Alpha0() == aD1 || d_iter.Alpha1() == aD1 || d_iter.Alpha0() == aD1 ); -} - -// Private/Hidden function -template -bool TRIANGULATION_HELPER::degenerateTriangle( const DART_TYPE& aDart ) -{ - // Check if triangle is degenerate - // Assumes CCW dart - - DART_TYPE d1 = aDart; - DART_TYPE d2 = d1; - d2.Alpha1(); - - return ( TRAITS_TYPE::CrossProduct2D( d1, d2 ) == 0 ); -} - -/** Checks if the edge associated with \e dart is swappable, i.e., if the edge - * is a diagonal in a \e strictly convex (or convex) quadrilateral. - * - * \param aAllowDegeneracy - * If set to true, the function will also return true if the numerical calculations - * indicate that the quadrilateral is convex only, and not necessarily strictly - * convex. - * - * \b require - * - \ref hed::TTLtraits::CrossProduct2D "TRAITS_TYPE::CrossProduct2D" (Dart&, Dart&) - */ -template -bool TRIANGULATION_HELPER::SwappableEdge( const DART_TYPE& aDart, bool aAllowDegeneracy ) -{ - // How "safe" is it? - - if( IsBoundaryEdge( aDart ) ) - return false; - - // "angles" are at the diagonal - DART_TYPE d1 = aDart; - d1.Alpha2().Alpha1(); - DART_TYPE d2 = aDart; - d2.Alpha1(); - - if( aAllowDegeneracy ) - { - if( TRAITS_TYPE::CrossProduct2D( d1, d2 ) < 0.0 ) - return false; - } - else - { - if( TRAITS_TYPE::CrossProduct2D( d1, d2 ) <= 0.0 ) - return false; - } - - // Opposite side (still angle at the diagonal) - d1 = aDart; - d1.Alpha0(); - d2 = d1; - d1.Alpha1(); - d2.Alpha2().Alpha1(); - - if( aAllowDegeneracy ) - { - if( TRAITS_TYPE::CrossProduct2D( d1, d2 ) < 0.0 ) - return false; - } - else - { - if( TRAITS_TYPE::CrossProduct2D( d1, d2 ) <= 0.0 ) - return false; - } - - return true; -} - -/** Given a \e dart, CCW or CW, positioned in a 0-orbit at the boundary of a tessellation. - * Position \e dart at a boundary edge in the same 0-orbit.\n - * If the given \e dart is CCW, \e dart is positioned at the left boundary edge - * and will be CW.\n - * If the given \e dart is CW, \e dart is positioned at the right boundary edge - * and will be CCW. - * - * \note - * - The given \e dart must have a source node at the boundary, otherwise an - * infinit loop occurs. - */ -template -void TRIANGULATION_HELPER::PositionAtNextBoundaryEdge( DART_TYPE& aDart ) -{ - DART_TYPE dart_prev; - - // If alpha2(d)=d, then boundary - - //old convention: dart.Alpha0(); - do - { - aDart.Alpha1(); - dart_prev = aDart; - aDart.Alpha2(); - } - while( aDart != dart_prev ); -} - -/** Checks if the boundary of a triangulation is convex. - * - * \param aDart - * A CCW dart at the boundary of the m_triangulation - * - * \b require - * - \ref hed::TTLtraits::CrossProduct2D "TRAITS_TYPE::CrossProduct2D" (const Dart&, const Dart&) - */ -template -bool TRIANGULATION_HELPER::ConvexBoundary( const DART_TYPE& aDart ) -{ - std::list blist; - getBoundary( aDart, blist ); - - int no; - no = (int) blist.size(); - typename std::list::const_iterator bit = blist.begin(); - DART_TYPE d1 = *bit; - ++bit; - DART_TYPE d2; - bool convex = true; - - for( ; bit != blist.end(); ++bit ) - { - d2 = *bit; - double crossProd = TRAITS_TYPE::CrossProduct2D( d1, d2 ); - - if( crossProd < 0.0 ) - { - //cout << "!!! Boundary is NOT convex: crossProd = " << crossProd << endl; - convex = false; - return convex; - } - - d1 = d2; - } - - // Check the last angle - d2 = *blist.begin(); - double crossProd = TRAITS_TYPE::CrossProduct2D( d1, d2 ); - - if( crossProd < 0.0 ) - { - //cout << "!!! Boundary is NOT convex: crossProd = " << crossProd << endl; - convex = false; - } - - //if (convex) - // cout << "\n---> Boundary is convex\n" << endl; - //cout << endl; - return convex; -} - -//@} // End of Topological and Geometric Queries Group - -/** @name Utilities for Delaunay Triangulation */ -//@{ -//------------------------------------------------------------------------------------------------ -/** Optimizes the edges in the given sequence according to the - * \e Delaunay criterion, i.e., such that the edge will fullfill the - * \e circumcircle criterion (or equivalently the \e MaxMin - * angle criterion) with respect to the quadrilaterals where - * they are diagonals. - * - * \param aElist - * The sequence of edges - * - * \b require - * - \ref hed::TTLtraits::swapEdge "TRAITS_TYPE::swapEdge" (DART_TYPE& \e dart)\n - * \b Note: Must be implemented such that \e dart is delivered back in a position as - * seen if it was glued to the edge when swapping (rotating) the edge CCW - * - * \a using - * - swapTestDelaunay - */ -template -void TRIANGULATION_HELPER::OptimizeDelaunay( DART_LIST_TYPE& aElist ) -{ - OptimizeDelaunay( aElist, aElist.end() ); -} - -//------------------------------------------------------------------------------------------------ -template -void TRIANGULATION_HELPER::OptimizeDelaunay( DART_LIST_TYPE& aElist, - const typename DART_LIST_TYPE::iterator aEnd ) -{ - // CCW darts - // Optimize here means Delaunay, but could be any criterion by - // requiring a "should swap" in the traits class, or give - // a function object? - // Assumes that elist has only one dart for each arc. - // Darts outside the quadrilateral are preserved - - // For some data structures it is possible to preserve - // all darts when swapping. Thus a preserve_darts_when swapping - // ccould be given to indicate this and we would gain performance by avoiding - // find in list. - - // Requires that swap retuns a dart in the "same position when rotated CCW" - // (A vector instead of a list may be better.) - - // First check that elist is not empty - if( aElist.empty() ) - return; - - // Avoid cycling by more extensive circumcircle test - bool cycling_check = true; - bool optimal = false; - typename DART_LIST_TYPE::iterator it; - - typename DART_LIST_TYPE::iterator end_opt = aEnd; - - // Hmm... The following code is trying to derefence an iterator that may - // be invalid. This may lead to debug error on Windows, so we comment out - // this code. Checking elist.empty() above will prevent some - // problems... - // - // last_opt is passed the end of the "active list" - //typename DART_LIST_TYPE::iterator end_opt; - //if (*end != NULL) - // end_opt = end; - //else - // end_opt = elist.end(); - - while( !optimal ) - { - optimal = true; - for( it = aElist.begin(); it != end_opt; ++it ) - { - if( SwapTestDelaunay( *it, cycling_check ) ) - { - // Preserve darts. Potential darts in the list are: - // - The current dart - // - the four CCW darts on the boundary of the quadrilateral - // (the current arc has only one dart) - - SwapEdgeInList( it, aElist ); - - optimal = false; - } // end if should swap - } // end for - } // end pass -} - -/** Checks if the edge associated with \e dart should be swapped according - * to the \e Delaunay criterion, i.e., the \e circumcircle criterion (or - * equivalently the \e MaxMin angle criterion). - * - * \param aCyclingCheck - * Must be set to \c true when used in connection with optimization algorithms, - * e.g., OptimizeDelaunay. This will avoid cycling and infinite loops in nearly - * neutral cases. - * - * \b require - * - \ref hed::TTLtraits::ScalarProduct2D "TRAITS_TYPE::ScalarProduct2D" (DART_TYPE&, DART_TYPE&) - * - \ref hed::TTLtraits::CrossProduct2D "TRAITS_TYPE::CrossProduct2D" (DART_TYPE&, DART_TYPE&) - */ -template -#if ((_MSC_VER > 0) && (_MSC_VER < 1300))//#ifdef _MSC_VER -bool TRIANGULATION_HELPER::SwapTestDelaunay(const DART_TYPE& aDart, bool aCyclingCheck = false) const -{ -#else -bool TRIANGULATION_HELPER::SwapTestDelaunay( const DART_TYPE& aDart, bool aCyclingCheck ) const -{ -#endif - // The general strategy is taken from Cline & Renka. They claim that - // their algorithm insure numerical stability, but experiments show - // that this is not correct for neutral, or almost neutral cases. - // I have extended this strategy (without using tolerances) to avoid - // cycling and infinit loops when used in connection with LOP algorithms; - // see the comments below. - - typedef typename TRAITS_TYPE::REAL_TYPE REAL_TYPE; - - if( IsBoundaryEdge( aDart ) ) - return false; - - DART_TYPE v11 = aDart; - v11.Alpha1().Alpha0(); - DART_TYPE v12 = v11; - v12.Alpha1(); - - DART_TYPE v22 = aDart; - v22.Alpha2().Alpha1().Alpha0(); - DART_TYPE v21 = v22; - v21.Alpha1(); - - REAL_TYPE cos1 = TRAITS_TYPE::ScalarProduct2D( v11, v12 ); - REAL_TYPE cos2 = TRAITS_TYPE::ScalarProduct2D( v21, v22 ); - - // "Angles" are opposite to the diagonal. - // The diagonals should be swapped iff (t1+t2) .gt. 180 - // degrees. The following two tests insure numerical - // stability according to Cline & Renka. But experiments show - // that cycling may still happen; see the aditional test below. - if( cos1 >= 0 && cos2 >= 0 ) // both angles are grater or equual 90 - return false; - - if( cos1 < 0 && cos2 < 0 ) // both angles are less than 90 - return true; - - REAL_TYPE sin1 = TRAITS_TYPE::CrossProduct2D( v11, v12 ); - REAL_TYPE sin2 = TRAITS_TYPE::CrossProduct2D( v21, v22 ); - REAL_TYPE sin12 = sin1 * cos2 + cos1 * sin2; - - if( sin12 >= 0 ) // equality represents a neutral case - return false; - - if( aCyclingCheck ) - { - // situation so far is sin12 < 0. Test if this also - // happens for the swapped edge. - - // The numerical calculations so far indicate that the edge is - // not Delaunay and should not be swapped. But experiments show that - // in neutral cases, or almost neutral cases, it may happen that - // the swapped edge may again be found to be not Delaunay and thus - // be swapped if we return true here. This may lead to cycling and - // an infinte loop when used, e.g., in connection with OptimizeDelaunay. - // - // In an attempt to avoid this we test if the swapped edge will - // also be found to be not Delaunay by repeating the last test above - // for the swapped edge. - // We now rely on the general requirement for TRAITS_TYPE::swapEdge which - // should deliver CCW dart back in "the same position"; see the general - // description. This will insure numerical stability as the next calculation - // is the same as if this function was called again with the swapped edge. - // Cycling is thus impossible provided that the initial tests above does - // not result in ambiguity (and they should probably not do so). - - v11.Alpha0(); - v12.Alpha0(); - v21.Alpha0(); - v22.Alpha0(); - // as if the edge was swapped/rotated CCW - cos1 = TRAITS_TYPE::ScalarProduct2D( v22, v11 ); - cos2 = TRAITS_TYPE::ScalarProduct2D( v12, v21 ); - sin1 = TRAITS_TYPE::CrossProduct2D( v22, v11 ); - sin2 = TRAITS_TYPE::CrossProduct2D( v12, v21 ); - sin12 = sin1 * cos2 + cos1 * sin2; - - if( sin12 < 0 ) - { - // A neutral case, but the tests above lead to swapping - return false; - } - } - - return true; -} - -//----------------------------------------------------------------------- -// -// x -//" / \ " -// / | \ Darts: -//oe2 / | \ oe2 = oppEdge2 -// x....|....x -// \ d| d/ d = diagonal (input and output) -// \ | / -// oe1 \ / oe1 = oppEdge1 -// x -// -//----------------------------------------------------------------------- -/** Recursively swaps edges in the triangulation according to the \e Delaunay criterion. - * - * \param aDiagonal - * A CCW dart representing the edge where the recursion starts from. - * - * \b require - * - \ref hed::TTLtraits::swapEdge "TRAITS_TYPE::swapEdge" (DART_TYPE&)\n - * \b Note: Must be implemented such that the darts outside the quadrilateral - * are not affected by the swap. - * - * \a using - * - Calls itself recursively - */ -template -void TRIANGULATION_HELPER::RecSwapDelaunay( DART_TYPE& aDiagonal ) -{ - if( !SwapTestDelaunay( aDiagonal ) ) - // ??? swapTestDelaunay also checks if boundary, so this can be optimized - return; - - // Get the other "edges" of the current triangle; see illustration above. - DART_TYPE oppEdge1 = aDiagonal; - oppEdge1.Alpha1(); - bool b1; - - if( IsBoundaryEdge( oppEdge1 ) ) - b1 = true; - else - { - b1 = false; - oppEdge1.Alpha2(); - } - - DART_TYPE oppEdge2 = aDiagonal; - oppEdge2.Alpha0().Alpha1().Alpha0(); - bool b2; - - if( IsBoundaryEdge( oppEdge2 ) ) - b2 = true; - else - { - b2 = false; - oppEdge2.Alpha2(); - } - - // Swap the given diagonal - m_triangulation.swapEdge( aDiagonal ); - - if( !b1 ) - RecSwapDelaunay( oppEdge1 ); - - if( !b2 ) - RecSwapDelaunay( oppEdge2 ); -} - -/** Swaps edges away from the (interior) node associated with - * \e dart such that that exactly three edges remain incident - * with the node. - * This function is used as a first step in RemoveInteriorNode - * - * \retval dart - * A CCW dart incident with the node - * - * \par Assumes: - * - The node associated with \e dart is interior to the - * triangulation. - * - * \b require - * - \ref hed::TTLtraits::swapEdge "TRAITS_TYPE::swapEdge" (DART_TYPE& \e dart)\n - * \b Note: Must be implemented such that \e dart is delivered back in a position as - * seen if it was glued to the edge when swapping (rotating) the edge CCW - * - * \note - * - A degenerate triangle may be left at the node. - * - The function is not unique as it depends on which dart - * at the node that is given as input. - * - * \see - * SwapEdgesAwayFromBoundaryNode - */ -template -void TRIANGULATION_HELPER::SwapEdgesAwayFromInteriorNode( DART_TYPE& aDart, - LIST_TYPE& aSwappedEdges ) -{ - - // Same iteration as in fixEdgesAtCorner, but not boundary - DART_TYPE dnext = aDart; - - // Allow degeneracy, otherwise we might end up with degree=4. - // For example, the reverse operation of inserting a point on an - // existing edge gives a situation where all edges are non-swappable. - // Ideally, degeneracy in this case should be along the actual node, - // but there is no strategy for this now. - // ??? An alternative here is to wait with degeneracy till we get an - // infinite loop with degree > 3. - bool allowDegeneracy = true; - - int degree = getDegreeOfNode( aDart ); - DART_TYPE d_iter; - - while( degree > 3 ) - { - d_iter = dnext; - dnext.Alpha1().Alpha2(); - - if( SwappableEdge( d_iter, allowDegeneracy ) ) - { - m_triangulation.swapEdge( d_iter ); // swap the edge away - // Collect swapped edges in the list - // "Hide" the dart on the other side of the edge to avoid it being changed for - // other swaps - DART_TYPE swapped_edge = d_iter; // it was delivered back - swapped_edge.Alpha2().Alpha0(); // CCW (if not at boundary) - aSwappedEdges.push_back( swapped_edge ); - - degree--; - } - } - - // Output, incident to the node - aDart = dnext; -} - -/** Swaps edges away from the (boundary) node associated with - * \e dart in such a way that when removing the edges that remain incident - * with the node, the boundary of the triangulation will be convex. - * This function is used as a first step in RemoveBoundaryNode - * - * \retval dart - * A CCW dart incident with the node - * - * \b require - * - \ref hed::TTLtraits::swapEdge "TRAITS_TYPE::swapEdge" (DART_TYPE& \e dart)\n - * \b Note: Must be implemented such that \e dart is delivered back in a position as - * seen if it was glued to the edge when swapping (rotating) the edge CCW - * - * \par Assumes: - * - The node associated with \e dart is at the boundary of the m_triangulation. - * - * \see - * SwapEdgesAwayFromInteriorNode - */ -template -void TRIANGULATION_HELPER::SwapEdgesAwayFromBoundaryNode( DART_TYPE& aDart, - LIST_TYPE& aSwappedEdges ) -{ - // All darts that are swappable. - // To treat collinear nodes at an existing boundary, we must allow degeneracy - // when swapping to the boundary. - // dart is CCW and at the boundary. - // The 0-orbit runs CCW - // Deliver the dart back in the "same position". - // Assume for the swap in the traits class: - // - A dart on the swapped edge is delivered back in a position as - // seen if it was glued to the edge when swapping (rotating) the edge CCW - - //int degree = getDegreeOfNode(dart); - - passes: - // Swap swappable edges that radiate from the node away - DART_TYPE d_iter = aDart; // ???? can simply use dart - d_iter.Alpha1().Alpha2(); // first not at boundary - DART_TYPE d_next = d_iter; - bool bend = false; - bool swapped_next_to_boundary = false; - bool swapped_in_pass = false; - - bool allowDegeneracy; // = true; - DART_TYPE tmp1, tmp2; - - while( !bend ) - { - d_next.Alpha1().Alpha2(); - - if( IsBoundaryEdge( d_next ) ) - bend = true; // then it is CW since alpha2 - - // To allow removing among collinear nodes at the boundary, - // degenerate triangles must be allowed - // (they will be removed when used in connection with RemoveBoundaryNode) - tmp1 = d_iter; - tmp1.Alpha1(); - tmp2 = d_iter; - tmp2.Alpha2().Alpha1(); // don't bother with boundary (checked later) - - if( IsBoundaryEdge( tmp1 ) && IsBoundaryEdge( tmp2 ) ) - allowDegeneracy = true; - else - allowDegeneracy = false; - - if( SwappableEdge( d_iter, allowDegeneracy ) ) - { - m_triangulation.swapEdge( d_iter ); - - // Collect swapped edges in the list - // "Hide" the dart on the other side of the edge to avoid it being changed for - // other swapps - DART_TYPE swapped_edge = d_iter; // it was delivered back - swapped_edge.Alpha2().Alpha0(); // CCW - aSwappedEdges.push_back( swapped_edge ); - - //degree--; // if degree is 2, or bend=true, we are done - swapped_in_pass = true; - if( bend ) - swapped_next_to_boundary = true; - } - - if( !bend ) - d_iter = d_next; - } - - // Deliver a dart as output in the same position as the incoming dart - if( swapped_next_to_boundary ) - { - // Assume that "swapping is CCW and dart is preserved in the same position - d_iter.Alpha1().Alpha0().Alpha1(); // CW and see below - } - else - { - d_iter.Alpha1(); // CW and see below - } - PositionAtNextBoundaryEdge( d_iter ); // CCW - - aDart = d_iter; // for next pass or output - - // If a dart was swapped in this iteration we must run it more - if( swapped_in_pass ) - goto passes; -} - -/** Swap the the edge associated with iterator \e it and update affected darts - * in \e elist accordingly. - * The darts affected by the swap are those in the same quadrilateral. - * Thus, if one want to preserve one or more of these darts on should - * keep them in \e elist. - */ -template -void TRIANGULATION_HELPER::SwapEdgeInList( const typename DART_LIST_TYPE::iterator& aIt, - DART_LIST_TYPE& aElist ) -{ - - typename DART_LIST_TYPE::iterator it1, it2, it3, it4; - DART_TYPE dart( *aIt ); - - //typename TRAITS_TYPE::DART_TYPE d1 = dart; d1.Alpha2().Alpha1(); - //typename TRAITS_TYPE::DART_TYPE d2 = d1; d2.Alpha0().Alpha1(); - //typename TRAITS_TYPE::DART_TYPE d3 = dart; d3.Alpha0().Alpha1(); - //typename TRAITS_TYPE::DART_TYPE d4 = d3; d4.Alpha0().Alpha1(); - DART_TYPE d1 = dart; - d1.Alpha2().Alpha1(); - DART_TYPE d2 = d1; - d2.Alpha0().Alpha1(); - DART_TYPE d3 = dart; - d3.Alpha0().Alpha1(); - DART_TYPE d4 = d3; - d4.Alpha0().Alpha1(); - - // Find pinters to the darts that may change. - // ??? Note, this is not very efficient since we must use find, which is O(N), - // four times. - // - Solution?: replace elist with a vector of pair (dart,number) - // and avoid find? - // - make a function for swapping generically? - // - sould we use another container type or, - // - erase them and reinsert? - // - or use two lists? - it1 = find( aElist.begin(), aElist.end(), d1 ); - it2 = find( aElist.begin(), aElist.end(), d2 ); - it3 = find( aElist.begin(), aElist.end(), d3 ); - it4 = find( aElist.begin(), aElist.end(), d4 ); - - m_triangulation.swapEdge( dart ); - // Update the current dart which may have changed - *aIt = dart; - - // Update darts that may have changed again (if they were present) - // Note that dart is delivered back after swapping - if( it1 != aElist.end() ) - { - d1 = dart; - d1.Alpha1().Alpha0(); - *it1 = d1; - } - - if( it2 != aElist.end() ) - { - d2 = dart; - d2.Alpha2().Alpha1(); - *it2 = d2; - } - - if( it3 != aElist.end() ) - { - d3 = dart; - d3.Alpha2().Alpha1().Alpha0().Alpha1(); - *it3 = d3; - } - - if( it4 != aElist.end() ) - { - d4 = dart; - d4.Alpha0().Alpha1(); - *it4 = d4; - } -} - -//@} // End of Utilities for Delaunay Triangulation Group - -} -// End of ttl namespace scope (but other files may also contain functions for ttl) - -#endif // _TTL_H_ diff --git a/thirdparty/ttl/include/ttl/ttl_util.h b/thirdparty/ttl/include/ttl/ttl_util.h deleted file mode 100644 index a7540ed7eb..0000000000 --- a/thirdparty/ttl/include/ttl/ttl_util.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT, - * Applied Mathematics, Norway. - * - * Contact information: E-mail: tor.dokken@sintef.no - * SINTEF ICT, DeaPArtment of Applied Mathematics, - * P.O. Box 124 Blindern, - * 0314 Oslo, Norway. - * - * This file is aPArt of TTL. - * - * TTL is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * TTL is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A aPARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with TTL. If not, see - * . - * - * In accordance with Section 7(b) of the GNU Affero General Public - * License, a covered work must retain the producer line in every data - * file that is created or manipulated using TTL. - * - * Other Usage - * You can be released from the requirements of the license by purchasing - * a commercial license. Buying such a license is mandatory as soon as you - * develop commercial activities involving the TTL library without - * disclosing the source code of your own applications. - * - * This file may be used in accordance with the terms contained in a - * written agreement between you and SINTEF ICT. - */ - -#ifndef _TTL_UTIL_H_ -#define _TTL_UTIL_H_ - -#include -#include - -#ifdef _MSC_VER -# if _MSC_VER < 1300 -# include -# endif -#endif - -/** \brief Utilities -* -* This name saPAce contains utility functions for TTL.\n -* -* Point and vector algebra such as scalar product and cross product -* between vectors are implemented here. -* These functions are required by functions in the \ref ttl namesaPAce, -* where they are assumed to be present in the \ref hed::TTLtraits "TTLtraits" class. -* Thus, the user can call these functions from the traits class. -* For efficiency reasons, the user may consider implementing these -* functions in the the API directly on the actual data structure; -* see \ref api. -* -* \note -* - Cross product between vectors in the xy-plane delivers a scalar, -* which is the z-component of the actual cross product -* (the x and y components are both zero). -* -* \see -* ttl and \ref api -* -* \author -* �yvind Hjelle, oyvindhj@ifi.uio.no -*/ - -namespace ttl_util -{ -/** @name Computational geometry */ -//@{ -/** Scalar product between two 2D vectors. - * - * \a Returns: - * \code - * aDX1*aDX2 + aDY1*aDY2 - * \endcode - */ -template -REAL_TYPE ScalarProduct2D( REAL_TYPE aDX1, REAL_TYPE aDY1, REAL_TYPE aDX2, REAL_TYPE aDY2 ) -{ - return aDX1 * aDX2 + aDY1 * aDY2; -} - -/** Cross product between two 2D vectors. (The z-component of the actual cross product.) - * - * \a Returns: - * \code - * aDX1*aDY2 - aDY1*aDX2 - * \endcode - */ -template -REAL_TYPE CrossProduct2D( REAL_TYPE aDX1, REAL_TYPE aDY1, REAL_TYPE aDX2, REAL_TYPE aDY2 ) -{ - return aDX1 * aDY2 - aDY1 * aDX2; -} - -/** Returns a positive value if the 2D nodes/points \e aPA, \e aPB, and - * \e aPC occur in counterclockwise order; a negative value if they occur - * in clockwise order; and zero if they are collinear. - * - * \note - * - This is a finite arithmetic fast version. It can be made more robust using - * exact arithmetic schemes by Jonathan Richard Shewchuk. See - * http://www-2.cs.cmu.edu/~quake/robust.html - */ -template -REAL_TYPE Orient2DFast( REAL_TYPE aPA[2], REAL_TYPE aPB[2], REAL_TYPE aPC[2] ) -{ - REAL_TYPE acx = aPA[0] - aPC[0]; - REAL_TYPE bcx = aPB[0] - aPC[0]; - REAL_TYPE acy = aPA[1] - aPC[1]; - REAL_TYPE bcy = aPB[1] - aPC[1]; - - return acx * bcy - acy * bcx; -} - -} // namespace ttl_util - -#endif // _TTL_UTIL_H_ diff --git a/thirdparty/ttl/src/halfedge/hetriang.cpp b/thirdparty/ttl/src/halfedge/hetriang.cpp deleted file mode 100644 index 9047a40ec3..0000000000 --- a/thirdparty/ttl/src/halfedge/hetriang.cpp +++ /dev/null @@ -1,727 +0,0 @@ -/* - * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT, - * Applied Mathematics, Norway. - * Copyright (C) 2013 CERN - * @author Maciej Suminski - * - * Contact information: E-mail: tor.dokken@sintef.no - * SINTEF ICT, Department of Applied Mathematics, - * P.O. Box 124 Blindern, - * 0314 Oslo, Norway. - * - * This file is part of TTL. - * - * TTL is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * TTL is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with TTL. If not, see - * . - * - * In accordance with Section 7(b) of the GNU Affero General Public - * License, a covered work must retain the producer line in every data - * file that is created or manipulated using TTL. - * - * Other Usage - * You can be released from the requirements of the license by purchasing - * a commercial license. Buying such a license is mandatory as soon as you - * develop commercial activities involving the TTL library without - * disclosing the source code of your own applications. - * - * This file may be used in accordance with the terms contained in a - * written agreement between you and SINTEF ICT. - */ - -#include -#include -#include -#include -#include -#include -#include - -using namespace hed; - -#ifdef TTL_USE_NODE_ID - int NODE::id_count = 0; -#endif - - - -//#define DEBUG_HE -#ifdef DEBUG_HE -#include -static void errorAndExit( char* aMessage ) -{ - cout << "\n!!! ERROR: "<< aMessage << " !!!\n" << endl; - exit( -1 ); -} -#endif - - -static EDGE_PTR getLeadingEdgeInTriangle( const EDGE_PTR& aEdge ) -{ - EDGE_PTR edge = aEdge; - - // Code: 3EF (assumes triangle) - if( !edge->IsLeadingEdge() ) - { - edge = edge->GetNextEdgeInFace(); - - if( !edge->IsLeadingEdge() ) - edge = edge->GetNextEdgeInFace(); - } - - if( !edge->IsLeadingEdge() ) - { - return EDGE_PTR(); - } - - return edge; -} - - -static void getLimits( NODES_CONTAINER::iterator aFirst, NODES_CONTAINER::iterator aLast, - int& aXmin, int& aYmin, int& aXmax, int& aYmax) -{ - aXmin = aYmin = std::numeric_limits::min(); - aXmax = aYmax = std::numeric_limits::max(); - - NODES_CONTAINER::iterator it; - - for( it = aFirst; it != aLast; ++it ) - { - aXmin = std::min( aXmin, ( *it )->GetX() ); - aYmin = std::min( aYmin, ( *it )->GetY() ); - aXmax = std::max( aXmax, ( *it )->GetX() ); - aYmax = std::max( aYmax, ( *it )->GetY() ); - } -} - - -EDGE_PTR TRIANGULATION::InitTwoEnclosingTriangles( NODES_CONTAINER::iterator aFirst, - NODES_CONTAINER::iterator aLast) -{ - int xmin, ymin, xmax, ymax; - getLimits( aFirst, aLast, xmin, ymin, xmax, ymax ); - - // Add 10% of range: - double fac = 10.0; - double dx = ( xmax - xmin ) / fac; - double dy = ( ymax - ymin ) / fac; - - NODE_PTR n1 = std::make_shared( xmin - dx, ymin - dy ); - NODE_PTR n2 = std::make_shared( xmax + dx, ymin - dy ); - NODE_PTR n3 = std::make_shared( xmax + dx, ymax + dy ); - NODE_PTR n4 = std::make_shared( xmin - dx, ymax + dy ); - - // diagonal - EDGE_PTR e1d = std::make_shared(); - EDGE_PTR e2d = std::make_shared(); - - // lower triangle - EDGE_PTR e11 = std::make_shared(); - EDGE_PTR e12 = std::make_shared(); - - // upper triangle - EDGE_PTR e21 = std::make_shared(); - EDGE_PTR e22 = std::make_shared(); - - // lower triangle - e1d->SetSourceNode( n3 ); - e1d->SetNextEdgeInFace( e11 ); - e1d->SetTwinEdge( e2d ); - addLeadingEdge( e1d ); - - e11->SetSourceNode( n1 ); - e11->SetNextEdgeInFace( e12 ); - - e12->SetSourceNode( n2 ); - e12->SetNextEdgeInFace( e1d ); - - // upper triangle - e2d->SetSourceNode( n1 ); - e2d->SetNextEdgeInFace( e21 ); - e2d->SetTwinEdge( e1d ); - addLeadingEdge( e2d ); - - e21->SetSourceNode( n3 ); - e21->SetNextEdgeInFace( e22 ); - - e22->SetSourceNode( n4 ); - e22->SetNextEdgeInFace( e2d ); - - return e11; -} - - -TRIANGULATION::TRIANGULATION() -{ - m_helper = new ttl::TRIANGULATION_HELPER( *this ); -} - - -TRIANGULATION::TRIANGULATION( const TRIANGULATION& aTriangulation ) -{ - m_helper = 0; // make coverity and static analysers quiet. - // Triangulation: Copy constructor not present - assert( false ); -} - - -TRIANGULATION::~TRIANGULATION() -{ - cleanAll(); - delete m_helper; -} - - -void TRIANGULATION::CreateDelaunay( NODES_CONTAINER::iterator aFirst, - NODES_CONTAINER::iterator aLast ) -{ - cleanAll(); - - EDGE_PTR bedge = InitTwoEnclosingTriangles( aFirst, aLast ); - DART dc( bedge ); - - DART d_iter = dc; - - NODES_CONTAINER::iterator it; - for( it = aFirst; it != aLast; ++it ) - { - m_helper->InsertNode( d_iter, *it ); - } - - // In general (e.g. for the triangle based data structure), the initial dart - // may have been changed. - // It is the users responsibility to get a valid boundary dart here. - // The half-edge data structure preserves the initial dart. - // (A dart at the boundary can also be found by trying to locate a - // triangle "outside" the triangulation.) - - // Assumes rectangular domain - m_helper->RemoveRectangularBoundary( dc ); -} - - -void TRIANGULATION::RemoveTriangle( EDGE_PTR& aEdge ) -{ - EDGE_PTR e1 = getLeadingEdgeInTriangle( aEdge ); - -#ifdef DEBUG_HE - if( !e1 ) - errorAndExit( "Triangulation::removeTriangle: could not find leading aEdge" ); -#endif - - removeLeadingEdgeFromList( e1 ); - // cout << "No leading edges = " << leadingEdges_.size() << endl; - // Remove the triangle - EDGE_PTR e2( e1->GetNextEdgeInFace() ); - EDGE_PTR e3( e2->GetNextEdgeInFace() ); - - e1->Clear(); - e2->Clear(); - e3->Clear(); -} - - -void TRIANGULATION::ReverseSplitTriangle( EDGE_PTR& aEdge ) -{ - // Reverse operation of splitTriangle - EDGE_PTR e1( aEdge->GetNextEdgeInFace() ); - EDGE_PTR le( getLeadingEdgeInTriangle( e1 ) ); -#ifdef DEBUG_HE - if (!le) - errorAndExit("Triangulation::removeTriangle: could not find leading edge"); -#endif - removeLeadingEdgeFromList( le ); - - EDGE_PTR e2( e1->GetNextEdgeInFace()->GetTwinEdge()->GetNextEdgeInFace() ); - le = getLeadingEdgeInTriangle( e2 ); -#ifdef DEBUG_HE - if (!le) - errorAndExit("Triangulation::removeTriangle: could not find leading edge"); -#endif - removeLeadingEdgeFromList( le ); - - EDGE_PTR e3( aEdge->GetTwinEdge()->GetNextEdgeInFace()->GetNextEdgeInFace() ); - le = getLeadingEdgeInTriangle( e3 ); -#ifdef DEBUG_HE - if (!le) - errorAndExit("Triangulation::removeTriangle: could not find leading edge"); -#endif - removeLeadingEdgeFromList( le ); - - // The three triangles at the node have now been removed - // from the triangulation, but the arcs have not been deleted. - // Next delete the 6 half edges radiating from the node - // The node is maintained by handle and need not be deleted explicitly - EDGE_PTR estar = aEdge; - EDGE_PTR enext = estar->GetTwinEdge()->GetNextEdgeInFace(); - estar->GetTwinEdge()->Clear(); - estar->Clear(); - - estar = enext; - enext = estar->GetTwinEdge()->GetNextEdgeInFace(); - estar->GetTwinEdge()->Clear(); - estar->Clear(); - - enext->GetTwinEdge()->Clear(); - enext->Clear(); - - // Create the new triangle - e1->SetNextEdgeInFace( e2 ); - e2->SetNextEdgeInFace( e3 ); - e3->SetNextEdgeInFace( e1 ); - addLeadingEdge( e1 ); -} - - -DART TRIANGULATION::CreateDart() -{ - // Return an arbitrary CCW dart - return DART( *m_leadingEdges.begin() ); -} - - -bool TRIANGULATION::removeLeadingEdgeFromList( EDGE_PTR& aLeadingEdge ) -{ - // Remove the edge from the list of leading edges, - // but don't delete it. - // Also set flag for leading edge to false. - // Must search from start of list. Since edges are added to the - // start of the list during triangulation, this operation will - // normally be fast (when used in the triangulation algorithm) - std::list::iterator it; - for( it = m_leadingEdges.begin(); it != m_leadingEdges.end(); ++it ) - { - EDGE_PTR edge = *it; - - if( edge == aLeadingEdge ) - { - edge->SetAsLeadingEdge( false ); - it = m_leadingEdges.erase( it ); - - return true; - } - } - - return false; -} - - -void TRIANGULATION::cleanAll() -{ - for( EDGE_PTR& edge : m_leadingEdges ) - edge->SetNextEdgeInFace( EDGE_PTR() ); -} - - -void TRIANGULATION::swapEdge( DART& aDart ) -{ - SwapEdge( aDart.GetEdge() ); -} - - -void TRIANGULATION::splitTriangle( DART& aDart, const NODE_PTR& aPoint ) -{ - EDGE_PTR edge = SplitTriangle( aDart.GetEdge(), aPoint ); - aDart.Init( edge ); -} - - -void TRIANGULATION::reverseSplitTriangle( DART& aDart ) -{ - ReverseSplitTriangle( aDart.GetEdge() ); -} - - -void TRIANGULATION::removeBoundaryTriangle( DART& aDart ) -{ - RemoveTriangle( aDart.GetEdge() ); -} - - -#ifdef TTL_USE_NODE_FLAG -void TRIANGULATION::FlagNodes( bool aFlag ) const -{ - std::list::const_iterator it; - for( it = m_leadingEdges.begin(); it != m_leadingEdges.end(); ++it ) - { - EDGE_PTR edge = *it; - - for( int i = 0; i < 3; ++i ) - { - edge->GetSourceNode()->SetFlag( aFlag ); - edge = edge->GetNextEdgeInFace(); - } - } -} - - -std::list* TRIANGULATION::GetNodes() const -{ - FlagNodes( false ); - std::list* nodeList = new std::list; - std::list::const_iterator it; - - for( it = m_leadingEdges.begin(); it != m_leadingEdges.end(); ++it ) - { - EDGE_PTR edge = *it; - - for( int i = 0; i < 3; ++i ) - { - const NODE_PTR& node = edge->GetSourceNode(); - - if( node->GetFlag() == false ) - { - nodeList->push_back( node ); - node->SetFlag( true ); - } - edge = edge->GetNextEdgeInFace(); - } - } - return nodeList; -} -#endif - - -void TRIANGULATION::GetEdges( std::list& aEdges, bool aSkipBoundaryEdges ) const -{ - // collect all arcs (one half edge for each arc) - // (boundary edges are also collected). - std::list::const_iterator it; - - for( it = m_leadingEdges.begin(); it != m_leadingEdges.end(); ++it ) - { - EDGE_PTR edge = *it; - for( int i = 0; i < 3; ++i ) - { - EDGE_PTR twinedge = edge->GetTwinEdge(); - // only one of the half-edges - - if( ( !twinedge && !aSkipBoundaryEdges ) - || ( twinedge && ( (size_t) edge.get() > (size_t) twinedge.get() ) ) ) - { - aEdges.push_front( edge ); - } - - edge = edge->GetNextEdgeInFace(); - } - } -} - - -EDGE_PTR TRIANGULATION::SplitTriangle( EDGE_PTR& aEdge, const NODE_PTR& aPoint ) -{ - // Add a node by just splitting a triangle into three triangles - // Assumes the half aEdge is located in the triangle - // Returns a half aEdge with source node as the new node - - // e#_n are new edges - // e# are existing edges - // e#_n and e##_n are new twin edges - // e##_n are edges incident to the new node - - // Add the node to the structure - //NODE_PTR new_node(new Node(x,y,z)); - - NODE_PTR n1( aEdge->GetSourceNode() ); - EDGE_PTR e1( aEdge ); - - EDGE_PTR e2( aEdge->GetNextEdgeInFace() ); - NODE_PTR n2( e2->GetSourceNode() ); - - EDGE_PTR e3( e2->GetNextEdgeInFace() ); - NODE_PTR n3( e3->GetSourceNode() ); - - EDGE_PTR e1_n = std::make_shared(); - EDGE_PTR e11_n = std::make_shared(); - EDGE_PTR e2_n = std::make_shared(); - EDGE_PTR e22_n = std::make_shared(); - EDGE_PTR e3_n = std::make_shared(); - EDGE_PTR e33_n = std::make_shared(); - - e1_n->SetSourceNode( n1 ); - e11_n->SetSourceNode( aPoint ); - e2_n->SetSourceNode( n2 ); - e22_n->SetSourceNode( aPoint ); - e3_n->SetSourceNode( n3 ); - e33_n->SetSourceNode( aPoint ); - - e1_n->SetTwinEdge( e11_n ); - e11_n->SetTwinEdge( e1_n ); - e2_n->SetTwinEdge( e22_n ); - e22_n->SetTwinEdge( e2_n ); - e3_n->SetTwinEdge( e33_n ); - e33_n->SetTwinEdge( e3_n ); - - e1_n->SetNextEdgeInFace( e33_n ); - e2_n->SetNextEdgeInFace( e11_n ); - e3_n->SetNextEdgeInFace( e22_n ); - - e11_n->SetNextEdgeInFace( e1 ); - e22_n->SetNextEdgeInFace( e2 ); - e33_n->SetNextEdgeInFace( e3 ); - - // and update old's next aEdge - e1->SetNextEdgeInFace( e2_n ); - e2->SetNextEdgeInFace( e3_n ); - e3->SetNextEdgeInFace( e1_n ); - - // add the three new leading edges, - // Must remove the old leading aEdge from the list. - // Use the field telling if an aEdge is a leading aEdge - // NOTE: Must search in the list!!! - - if( e1->IsLeadingEdge() ) - removeLeadingEdgeFromList( e1 ); - else if( e2->IsLeadingEdge() ) - removeLeadingEdgeFromList( e2 ); - else if( e3->IsLeadingEdge() ) - removeLeadingEdgeFromList( e3 ); - else - assert( false ); // one of the edges should be leading - - addLeadingEdge( e1_n ); - addLeadingEdge( e2_n ); - addLeadingEdge( e3_n ); - - // Return a half aEdge incident to the new node (with the new node as source node) - - return e11_n; -} - - -void TRIANGULATION::SwapEdge( EDGE_PTR& aDiagonal ) -{ - // Note that diagonal is both input and output and it is always - // kept in counterclockwise direction (this is not required by all - // functions in TriangulationHelper now) - - // Swap by rotating counterclockwise - // Use the same objects - no deletion or new objects - EDGE_PTR eL( aDiagonal ); - EDGE_PTR eR( eL->GetTwinEdge() ); - EDGE_PTR eL_1( eL->GetNextEdgeInFace() ); - EDGE_PTR eL_2( eL_1->GetNextEdgeInFace() ); - EDGE_PTR eR_1( eR->GetNextEdgeInFace() ); - EDGE_PTR eR_2( eR_1->GetNextEdgeInFace() ); - - // avoid node to be dereferenced to zero and deleted - NODE_PTR nR( eR_2->GetSourceNode() ); - NODE_PTR nL( eL_2->GetSourceNode() ); - - eL->SetSourceNode( nR ); - eR->SetSourceNode( nL ); - - // and now 6 1-sewings - eL->SetNextEdgeInFace( eL_2 ); - eL_2->SetNextEdgeInFace( eR_1 ); - eR_1->SetNextEdgeInFace( eL ); - - eR->SetNextEdgeInFace( eR_2 ); - eR_2->SetNextEdgeInFace( eL_1 ); - eL_1->SetNextEdgeInFace( eR ); - - if( eL->IsLeadingEdge() ) - removeLeadingEdgeFromList( eL ); - else if( eL_1->IsLeadingEdge() ) - removeLeadingEdgeFromList( eL_1 ); - else if( eL_2->IsLeadingEdge() ) - removeLeadingEdgeFromList( eL_2 ); - - if( eR->IsLeadingEdge() ) - removeLeadingEdgeFromList( eR ); - else if( eR_1->IsLeadingEdge() ) - removeLeadingEdgeFromList( eR_1 ); - else if( eR_2->IsLeadingEdge() ) - removeLeadingEdgeFromList( eR_2 ); - - addLeadingEdge( eL ); - addLeadingEdge( eR ); -} - - -bool TRIANGULATION::CheckDelaunay() const -{ - // ???? outputs !!!! - // ofstream os("qweND.dat"); - const std::list& leadingEdges = GetLeadingEdges(); - - std::list::const_iterator it; - bool ok = true; - int noNotDelaunay = 0; - - for( it = leadingEdges.begin(); it != leadingEdges.end(); ++it ) - { - EDGE_PTR edge = *it; - - for( int i = 0; i < 3; ++i ) - { - EDGE_PTR twinedge = edge->GetTwinEdge(); - - // only one of the half-edges - if( !twinedge || (size_t) edge.get() > (size_t) twinedge.get() ) - { - DART dart( edge ); - if( m_helper->SwapTestDelaunay( dart ) ) - { - noNotDelaunay++; - - //printEdge(dart,os); os << "\n"; - ok = false; - //cout << "............. not Delaunay .... " << endl; - } - } - - edge = edge->GetNextEdgeInFace(); - } - } - -#ifdef DEBUG_HE - cout << "!!! Triangulation is NOT Delaunay: " << noNotDelaunay << " edges\n" << endl; -#endif - - return ok; -} - - -void TRIANGULATION::OptimizeDelaunay() -{ - // This function is also present in ttl where it is implemented - // generically. - // The implementation below is tailored for the half-edge data structure, - // and is thus more efficient - - // Collect all interior edges (one half edge for each arc) - bool skip_boundary_edges = true; - std::list elist; - GetEdges( elist, skip_boundary_edges ); - - // Assumes that elist has only one half-edge for each arc. - bool cycling_check = true; - bool optimal = false; - std::list::const_iterator it; - - while( !optimal ) - { - optimal = true; - - for( it = elist.begin(); it != elist.end(); ++it ) - { - EDGE_PTR edge = *it; - - DART dart( edge ); - // Constrained edges should not be swapped - if( m_helper->SwapTestDelaunay( dart, cycling_check ) ) - { - optimal = false; - SwapEdge( edge ); - } - } - } -} - - -EDGE_PTR TRIANGULATION::GetInteriorNode() const -{ - const std::list& leadingEdges = GetLeadingEdges(); - std::list::const_iterator it; - - for( it = leadingEdges.begin(); it != leadingEdges.end(); ++it ) - { - EDGE_PTR edge = *it; - - // multiple checks, but only until found - for( int i = 0; i < 3; ++i ) - { - if( edge->GetTwinEdge() ) - { - if( !m_helper->IsBoundaryNode( DART( edge ) ) ) - return edge; - } - - edge = edge->GetNextEdgeInFace(); - } - } - - return EDGE_PTR(); // no boundary nodes -} - - -EDGE_PTR TRIANGULATION::GetBoundaryEdgeInTriangle( const EDGE_PTR& aEdge ) const -{ - EDGE_PTR edge = aEdge; - - if( m_helper->IsBoundaryEdge( DART( edge ) ) ) - return edge; - - edge = edge->GetNextEdgeInFace(); - if( m_helper->IsBoundaryEdge( DART( edge ) ) ) - return edge; - - edge = edge->GetNextEdgeInFace(); - if( m_helper->IsBoundaryEdge( DART( edge ) ) ) - return edge; - - return EDGE_PTR(); -} - - -EDGE_PTR TRIANGULATION::GetBoundaryEdge() const -{ - // Get an arbitrary (CCW) boundary edge - // If the triangulation is closed, NULL is returned - const std::list& leadingEdges = GetLeadingEdges(); - std::list::const_iterator it; - EDGE_PTR edge; - - for( it = leadingEdges.begin(); it != leadingEdges.end(); ++it ) - { - edge = GetBoundaryEdgeInTriangle( *it ); - - if( edge ) - return edge; - } - return EDGE_PTR(); -} - - -void TRIANGULATION::PrintEdges( std::ofstream& aOutput ) const -{ - // Print source node and target node for each edge face by face, - // but only one of the half-edges. - const std::list& leadingEdges = GetLeadingEdges(); - std::list::const_iterator it; - - for( it = leadingEdges.begin(); it != leadingEdges.end(); ++it ) - { - EDGE_PTR edge = *it; - - for( int i = 0; i < 3; ++i ) - { - EDGE_PTR twinedge = edge->GetTwinEdge(); - - // Print only one edge (the highest value of the pointer) - if( !twinedge || (size_t) edge.get() > (size_t) twinedge.get() ) - { - // Print source node and target node - NODE_PTR node = edge->GetSourceNode(); - aOutput << node->GetX() << " " << node->GetY() << std::endl; - node = edge->GetTargetNode(); - aOutput << node->GetX() << " " << node->GetY() << std::endl; - aOutput << '\n'; // blank line - } - - edge = edge->GetNextEdgeInFace(); - } - } -}