diff --git a/.github/workflows/cmake-single-platform.yml b/.github/workflows/cmake-single-platform.yml new file mode 100644 index 0000000..c2fb718 --- /dev/null +++ b/.github/workflows/cmake-single-platform.yml @@ -0,0 +1,43 @@ +# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage. +# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml +name: CMake on a single platform + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + build: + # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. + # You can convert this to a matrix build if you need cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Install deps + run: sudo apt install -y libopengl-dev libgl1-mesa-dev libxrandr-dev libxi-dev libxinerama-dev libgl-dev libxcursor-dev libmpfr-dev libmpfrc++-dev libblas-dev liblapack-dev + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_VISUALIZATION=OFF + + - name: Build + # Build your program with the given configuration + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + + - name: Build tests + run: cmake --build ${{github.workspace}}/build --target penner_tests --config ${{env.BUILD_TYPE}} + + - name: Test + working-directory: ${{github.workspace}}/build + run: ctest --output-on-failure --build-config ${{env.BUILD_TYPE}} + diff --git a/CMakeLists.txt b/CMakeLists.txt index 8959ef6..3eb56a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,11 @@ project(PennerOptimization) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_compile_options(-fPIC) +add_compile_options(-Wno-register) set(DIR_EXT "${CMAKE_CURRENT_SOURCE_DIR}/ext") +list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + # Set options if top level if (PROJECT_IS_TOP_LEVEL) # Options to generate python bindings @@ -26,17 +29,34 @@ if (PROJECT_IS_TOP_LEVEL) option(BUILD_CURVATURE_METRIC_TESTS "Build tests" ON) option(CHECK_VALIDITY "Check validity pre and post conditions" ON) + # Set default libigl and suitesparse options option(LIBIGL_PREDICATES "Use Predicates" ON) - set ( SUITESPARSE_ENABLE_PROJECTS "suitesparse_config;cholmod;spqr" ) + #set ( SUITESPARSE_ENABLE_PROJECTS "suitesparse_config;cholmod;spqr" ) option ( SUITESPARSE_USE_CUDA OFF ) endif() +set ( SUITESPARSE_ENABLE_PROJECTS "${SUITESPARSE_ENABLE_PROJECTS};suitesparse_config;cholmod" CACHE STRING "" FORCE) list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -include(boost) include(eigen) +include(boost) +# create a fake BoostConfig.cmake before libigl runs and force Boost_DIR +# to it so ignore_package (which uses no FORCE) cannot override it. +set(_fake_boost_dir "${CMAKE_BINARY_DIR}/cmake/FakeBoost") +file(MAKE_DIRECTORY "${_fake_boost_dir}") +file(WRITE "${_fake_boost_dir}/BoostConfig.cmake" + "set(Boost_FOUND TRUE)\nset(Boost_system_FOUND TRUE)\nset(Boost_thread_FOUND TRUE)\n") +file(WRITE "${_fake_boost_dir}/BoostConfigVersion.cmake" + "set(PACKAGE_VERSION 1.83.0)\nset(PACKAGE_VERSION_COMPATIBLE TRUE)\nset(PACKAGE_VERSION_EXACT FALSE)\n") +set(Boost_DIR "${_fake_boost_dir}" CACHE PATH "" FORCE) + +if(BUILD_CURVATURE_METRIC_TESTS) + include(Catch2) + include(CTest) +endif() + # Optionally get multiprecision libraries if(USE_MULTIPRECISION OR USE_MULTIPRECISION_OVERLAY) # Turning this on activates mpfr in the conformal code @@ -55,7 +75,7 @@ endif() if (USE_COMISO) add_compile_definitions(USE_COMISO) set(LIBIGL_COPYLEFT_CORE ON CACHE BOOL "" FORCE) - #se. (LIBIGL_COPYLEFT_COMISO ON CACHE BOOL "" FORCE) + #set(LIBIGL_COPYLEFT_COMISO ON CACHE BOOL "" FORCE) #option(LIBIGL_COPYLEFT_COMISO "Use COSIMO" ON) #set(COMISO_ENABLE_SUITESPARSE_DEFAULT OFF) set(COMISO_NO_INSTALL ON) @@ -90,15 +110,14 @@ endif() # conformal ideal delaunay library if(USE_SUITESPARSE) add_compile_definitions(USE_SUITESPARSE) - set(SUITESPARSE_LIBS + list(APPEND SUITESPARSE_LIBS SuiteSparse::SuiteSparseConfig - SuiteSparse::SPQR + #SuiteSparse::SPQR SuiteSparse::CHOLMOD ) endif() # Get external libraries -include(boost) include(conformal_ideal_delaunay) include(libigl) include(spectra) @@ -110,7 +129,7 @@ find_package(HDF5 REQUIRED COMPONENTS CXX) # get optimization library if (USE_UV_OPTIMIZATION) add_compile_definitions(USE_UV_OPTIMIZATION) - include(symmetric-dirichlet) + include(seamless-optimization) else() include(json) endif() diff --git a/LICENSE.GPL b/LICENSE.GPL new file mode 100644 index 0000000..53d1f3d --- /dev/null +++ b/LICENSE.GPL @@ -0,0 +1,675 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 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 General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is 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. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + 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. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + 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 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. Use with the GNU Affero General Public License. + + 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 Affero 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 special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU 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 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 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 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 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + 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 GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. + diff --git a/LICENSE.MPL2 b/LICENSE.MPL2 new file mode 100644 index 0000000..14e2f77 --- /dev/null +++ b/LICENSE.MPL2 @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/README.md b/README.md index 4429531..e7afa80 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,87 @@ To engender future work in this exciting direction, we provide a library `Penner 2. Various energy functionals and constrained optimization methods for meshes with Penner coordinates 3. Layout and refinement methods to generate a parameterization for a mesh from arbitrary Penner coordinates, i.e., the parameterization is an embedding in the uv plane of the metric defined by the Penner coordinate. +### Library Structure + +- Field + - Cross Field: Methods for generating cross fields as represented by four rotationally symmetric tangent vectors. + - Facet Field: Methods for generating cross fields using legacy facet field file representations. + - Field: Methods to generate field directions and cones from an nrosy field. (TODO: Move rosy and combing field functions here) + - Forms: Methods for creating and manipulating one forms on a surface, represented as anti-symmetric halfedge values. + - Frame Field: TODO: move assorted functions here to appropriate locations + - Intrinsic Field: TODO: Needs cleanup +- Optimization + - Core: Underlying methods for differentiable intrinsic metrics, including (a) area and angle values, and (b) length, Penner, shear, and conformal coordinates. + - Area: Methods to compute the area of triangles from intrinsic lengths + - Common: TODO + - Cone Metric: Core representation of a differentiable intrinsic metric on an underlying halfedge mesh + - Constraint: Methods to compute triangle inequality and differentiable cone angle constraints. + - Flip Matrix Generator: Data structure to iteratively compute the change of coordinate matrix for intrinsic flips + - Globals: (TODO: Put structs in relevant files) + - Projection: Methods to project a metric conformally to cone constraints, and to project metric coordinate vectors to the tangent space of the constraint submanifold. + - Reparametrization: Methods for changing edge and interior barycentric coordinates as determined by hyperbolic edge translations. (TODO: This name is pretty confusing in a parameterization library. Change to something better like `barycentric`, and move to parameterization) + - Shear: Methods to compute the shear coordinates of a metric from Penner coordinates and shear coordinate bases, linearly independent from the conformal scaling space. + - Metric Optimization: Methods for optimizing distortion energies for an intrinsic metric with constraints + - Convergence: (TODO: a single function; move somewhere else) + - Energies: Differentiable per-face energy functions with gradients for metric optimization + - Energy Functor: Class for differentiable distortion measures supporting evaluation, gradients, and Hessians + - Energy Weights: Methods to scale per-element values by element weights + - Explicit Optimization: Methods to optimize a metric with angle constraints using an explicit basis complimentary to the conformal scaling space. + - Implicit Optimization: Method to optimize distortion with constraints using a walk-on-manifold approach in a full space of metric coordinates using projection + - Nonlinear Optimization: Methods to perform advanced nonlinear optimization, including conjugate gradient and L-BFGS-B + - Parameterization: (TODO: move to top level. This is fundamental and common code.) + - Interpolation: Data structures to compute pointwise maps between two intrinsic metrics. + - Layout: Methods to layout a uv parameterization determined by intrinsic lengths (TODO: cleanup and documentation) + - Refinement: Methods to refine a triangulation with an accompanying overlay layout sufficiently to ensure the parametrization does not have inverted elements. (TODO: replace `refinement` with `simplification` or something of this sort; check what is in the paper) + - Translation: Method to compute hyperbolic translations determining a continuous map between two intrinsic metrics + - Triangulation: Methods for triangulating self overlapping polygons in the plane + - Util: TODO: Mostly utility for unit tests and validation. Redistribute this code. +- Holonomy: Library for parametrizing surfaces with full seamless constraints with arbitrary holonomy signatures + - Core: Basic utilities for tracking dual loops on a surface + - Boundary Basis: Basis loops for boundary alignment constraints + - Common: Assorted utilities + - Dual Lengths: Compute lengths of dual edges on a surface (TODO: move) + - Dual Loop: Data structures for representing dual loops on a surface with efficient queries of edge and path intersections + - Dual Segment: Minimal representation of dual paths on a surface as list of atomic face crossings + - Homology Basis: Construct homology basis loops for a surface. + - Quality: Compute triangle quality measures on a mesh (TODO: move) + - Viewer: Assorted viewers + - Holonomy: + - Cones: Compute cones, as well as related queries and modification heuristics (TODO: move to field, and consolidate cone code here) + - Constraints: Holonomy angle constraints, including cone and dual loop constraints. + - Holonomy: Compute holonomy of dual loops on a surface with metric + - Marked Penner Cone Metric: Differentiable cone metric with full holonomy signature constraints + - Newton: Modified least squares Newton method for holonomy angle constraints + - Rotation Form: Method to compute the rotation of a field across edges from a cross field (TODO: integrate with field code) + - Similarity: TODO. It makes sense to keep this here, since it can satisfy full holonomy signature constraints, but is not integral to the codebase +- Feature: Library for parametrizing surfaces with both seamless and feature alignment constraints + - Core + - Boundary Path: Data structure for tracking the line of symmetry between two boundary vertices + - Common: TODO + - Component Mesh: Methods and data structures for splitting a disconnected mesh into separate components, as well as corresponding reindexing maps. + - IO: Methods to write/read edges to/from file. + - Quads: Methods to compute relevant quad mesh statistics (TODO: Only contains valence computation; Unify with other quad related code) + - Union Meshes: Methods to combine collections of meshes into a single mesh with multiple components. + - VF Corners: Methods for representing mesh edges using opposite corners. + - Viewer: Assorted viewers + - Dirichlet: Methods for enforcing hard and optimizing soft feature alignment constraints (TODO: consider renaming) + - Angle Constraint Relaxer: Method to compute a relaxed angle constraint system that maintains total vertex angles while relaxing feature edge alignment. + - Cone Perturber: Data structure to modify sector angle constraints for feature alignment + - Constraints: Methods to compute feature aligned seamless constraints and associated Jacobians + - Dirichlet Penner Cone Metric: Extension of the differentiable cone metric using Penner coordinates to include full feature aligned seamless constraints (TODO: finish documenting) + - Optimization: Two-phase optimization method for alignment of relaxed angle constraint + - Experimental: (TODO: Remove) + - Feature: Methods to find + - Error: Methods to compute feature alignment error + - Features: Method to find feature edges on a surface and hard feature constraint subsets + - Gluing: Methods to get cut mesh edge and vertex correspondences + - Surgery: Methods to cut, refine, and stitch meshes and their parametrizations + - Cut Mesh Layout: Methods to parameterize the uv components of a cut mesh + - Cut Metric Generator: Data structure to generate fields and differentiable metrics for a mesh cut along feature lines. + - Refinement: Data structure with limited support to refine the faces and edges of a mesh for feature alignment + - Stitching: Method to stitch a mesh cut along feature lines and parametrized, possibly with edge refinement, into a single parametrized mesh. + - Util: Union Find: (TODO: Move to global utility) + ## Citation ``` diff --git a/cmake/Catch2.cmake b/cmake/Catch2.cmake index 44577de..589941b 100644 --- a/cmake/Catch2.cmake +++ b/cmake/Catch2.cmake @@ -6,6 +6,6 @@ Include(FetchContent) FetchContent_Declare( Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.0.1 + GIT_TAG v3.15.0 ) -FetchContent_MakeAvailable(Catch2) \ No newline at end of file +FetchContent_MakeAvailable(Catch2) diff --git a/cmake/conformal_ideal_delaunay.cmake b/cmake/conformal_ideal_delaunay.cmake index 461c7ad..27d218f 100644 --- a/cmake/conformal_ideal_delaunay.cmake +++ b/cmake/conformal_ideal_delaunay.cmake @@ -6,5 +6,9 @@ FetchContent_Declare( GIT_TAG penner_optimization ) FetchContent_MakeAvailable(conformal_ideal_delaunay) + +if(TARGET conformal_ideal_delaunay AND APPLE) + target_compile_options(conformal_ideal_delaunay PRIVATE -Wno-extra-tokens) +endif() target_compile_features(conformal_cpp PRIVATE cxx_std_20) diff --git a/cmake/highfive.cmake b/cmake/deprecated/highfive.cmake similarity index 100% rename from cmake/highfive.cmake rename to cmake/deprecated/highfive.cmake diff --git a/cmake/seamless-optimization.cmake b/cmake/seamless-optimization.cmake new file mode 100644 index 0000000..9e5651c --- /dev/null +++ b/cmake/seamless-optimization.cmake @@ -0,0 +1,14 @@ +if(TARGET SymmetricDirichletLib) + return() +endif() + + +include(FetchContent) +FetchContent_Declare( + seamless-optimization + SYSTEM + GIT_REPOSITORY https://github.com/rjc8237/seamless-optimization.git + GIT_TAG main +) +FetchContent_MakeAvailable(seamless-optimization) + diff --git a/cmake/symmetric-dirichlet.cmake b/cmake/symmetric-dirichlet.cmake deleted file mode 100644 index f2d143f..0000000 --- a/cmake/symmetric-dirichlet.cmake +++ /dev/null @@ -1,14 +0,0 @@ -if(TARGET SymmetricDirichletLib) - return() -endif() - - -include(FetchContent) -FetchContent_Declare( - symmetric-dirichlet - SYSTEM - GIT_REPOSITORY https://github.com/rjc8237/symmetric-dirichlet.git - GIT_TAG merge -) -FetchContent_MakeAvailable(symmetric-dirichlet) - diff --git a/include/feature/feature/core/boundary_path.h b/include/feature/feature/core/boundary_path.h index 9415f7e..fd7daeb 100644 --- a/include/feature/feature/core/boundary_path.h +++ b/include/feature/feature/core/boundary_path.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" @@ -5,6 +13,12 @@ namespace Penner { namespace Feature { +/** + * @brief Data structure for tracking the line of symmetry between two boundary vertices. Also + * supports computation of the length of the line and the gradient with repect to Penner coordinates. + * + */ + /** * @brief Representation of a boundary edge path. If the boundary edge is unflipped and lies along * the symmetry line, then this is just a single halfedge in the primal mesh. If the edge is @@ -149,4 +163,4 @@ class BoundaryPath std::tuple, MatrixX> build_boundary_paths(const Mesh& m); } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/feature/feature/core/common.h b/include/feature/feature/core/common.h index 91ffc4c..899873a 100644 --- a/include/feature/feature/core/common.h +++ b/include/feature/feature/core/common.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/interface.h" @@ -6,6 +14,11 @@ #include "holonomy/holonomy/marked_penner_cone_metric.h" #include "holonomy/holonomy/newton.h" +/** + * @brief Assorted utility functions. + * + */ + namespace Penner { namespace Feature { @@ -13,7 +26,6 @@ using Holonomy::DualLoop; using Holonomy::MarkedPennerConeMetric; using Holonomy::NewtonParameters; using Holonomy::MarkedMetricParameters; -typedef std::array VertexEdge; /** * @brief Compute the square of a scalar. @@ -69,4 +81,4 @@ std::vector> reindex_endpoints( } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/feature/feature/core/component_mesh.h b/include/feature/feature/core/component_mesh.h index adf693a..e5b489a 100644 --- a/include/feature/feature/core/component_mesh.h +++ b/include/feature/feature/core/component_mesh.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once @@ -7,6 +15,14 @@ #include "feature/util/union_find.h" #include "holonomy/holonomy/marked_penner_cone_metric.h" +/** + * @brief Methods and data structures for splitting a disconnected mesh into separate components, + * as well as corresponding reindexing maps. + * + * Separate methods for both halfedge and VF representations. + * + */ + namespace Penner { namespace Feature { @@ -27,6 +43,13 @@ class ComponentMesh */ ComponentMesh(const Mesh& m); + /** + * @brief Construct a collection of components for the global (possibly disconnected) mesh using + * precomputed component information + * + * @param m: (possibly disconnected) manifold mesh + * @param components: component index for each face of the mesh + */ ComponentMesh(const Mesh& m, const Eigen::VectorXi& components); /** diff --git a/include/feature/feature/core/io.h b/include/feature/feature/core/io.h index 3c3cfd9..1195628 100644 --- a/include/feature/feature/core/io.h +++ b/include/feature/feature/core/io.h @@ -1,10 +1,24 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" +#include "feature/core/vf_corners.h" namespace Penner { namespace Feature { +/** + * @brief Methods to write/read edges to/from file, including feature, boundary, and seam edges. + * + */ + /** * @brief Write feature edges to a 0-indexed list in the following format: * @@ -91,10 +105,22 @@ void write_boundary( const Eigen::MatrixXi& F, const Eigen::MatrixXi& F_uv); +/** + * @brief Write mesh edges to file in the format: + * v x0 y0 z0 + * v x1 y1 z1 + * ... + * l v0 v1 + * ... + * + * @param filename: output edge geometry file + * @param V: mesh vertices + * @param F: mesh edges + */ void write_edges( const std::string& filename, const Eigen::MatrixXd& V, const Eigen::MatrixXi& E); } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/feature/feature/core/quads.h b/include/feature/feature/core/quads.h index 04b05e1..13b0c6d 100644 --- a/include/feature/feature/core/quads.h +++ b/include/feature/feature/core/quads.h @@ -1,8 +1,21 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" +/** + * @brief Methods to compute relevant quad mesh statistics, including degree valences. + * + */ + namespace Penner { namespace Feature { diff --git a/include/feature/feature/core/union_meshes.h b/include/feature/feature/core/union_meshes.h index 5f4ec3b..f0791bc 100644 --- a/include/feature/feature/core/union_meshes.h +++ b/include/feature/feature/core/union_meshes.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once @@ -6,10 +14,14 @@ #include "holonomy/holonomy/marked_penner_cone_metric.h" #include "feature/util/union_find.h" +/** + * @brief Methods to combine collections of meshes into a single mesh with multiple components. + * + */ + namespace Penner { namespace Feature { - /** * @brief Count the total number of vertices in set of mesh components. * diff --git a/include/feature/feature/core/vf_corners.h b/include/feature/feature/core/vf_corners.h index 58d9e97..647699e 100644 --- a/include/feature/feature/core/vf_corners.h +++ b/include/feature/feature/core/vf_corners.h @@ -1,10 +1,37 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" +/** + * @brief Methods for representing mesh edges using opposite corners. + * + * The representations are: + * Mask: a Fx3 boolean mask for marking corners + * Corner: a simple face and local corner index pair (f, i), with i in {0, 1, 2} + * Face Edge: pair of both VF corners opposite the edge + * + * Supports conversion between different representations, as well as conversion to and from + * vertex pairs and halfedge indices. + * + * Also includes various edge utilities, such pruning redundant corners, taking mask differences, + * and finding parametrization seams. + * + */ + namespace Penner { namespace Feature { + +typedef std::array VertexEdge; + /** * @brief Representation of an edge as the two opposite face corners * @@ -253,19 +280,6 @@ Eigen::MatrixXd transfer_halfedge_function_to_corner( const Eigen::MatrixXi& F, const VectorX& halfedge_func); -/** - * @brief Find the seams of the parameterization of a closed mesh. - * - * TODO: Extend to open meshes - * - * @param F: mesh faces - * @param FT: mesh layout faces - * @return |F|x3 mask of corners opposite seam edges - */ -Eigen::MatrixXi find_seams( - const Eigen::MatrixXi& F, - const Eigen::MatrixXi& FT); - /** * @brief Given a mask of corners opposite edges, generate the corresponding edge geometry. * diff --git a/include/feature/feature/core/viewer.h b/include/feature/feature/core/viewer.h index 12aba87..585d5e1 100644 --- a/include/feature/feature/core/viewer.h +++ b/include/feature/feature/core/viewer.h @@ -1,9 +1,22 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" // TODO: Cleaning pass +/** + * @brief Assorted viewers. + * + */ + namespace Penner { namespace Feature { diff --git a/include/feature/feature/dirichlet/angle_constraint_relaxer.h b/include/feature/feature/dirichlet/angle_constraint_relaxer.h index 0e20075..5d081fc 100644 --- a/include/feature/feature/dirichlet/angle_constraint_relaxer.h +++ b/include/feature/feature/dirichlet/angle_constraint_relaxer.h @@ -1,9 +1,23 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" #include "feature/dirichlet/dirichlet_penner_cone_metric.h" +/** + * @brief Method to compute a relaxed angle constraint system that maintains total vertex angles + * while relaxing feature edge alignment. + * + */ + namespace Penner { namespace Feature { diff --git a/include/feature/feature/dirichlet/cone_perturber.h b/include/feature/feature/dirichlet/cone_perturber.h index c9e9f97..6e554b5 100644 --- a/include/feature/feature/dirichlet/cone_perturber.h +++ b/include/feature/feature/dirichlet/cone_perturber.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" @@ -6,6 +14,10 @@ #include "feature/feature/gluing.h" #include +/** + * @brief Data structure to modify sector angle constraints for feature alignment + * + */ namespace Penner { namespace Feature { @@ -77,4 +89,4 @@ class ConePerturber }; } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/feature/feature/dirichlet/constraint.h b/include/feature/feature/dirichlet/constraint.h index e3a0da0..cd0f465 100644 --- a/include/feature/feature/dirichlet/constraint.h +++ b/include/feature/feature/dirichlet/constraint.h @@ -1,9 +1,23 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" #include "feature/dirichlet/dirichlet_penner_cone_metric.h" +/** + * @brief Methods to compute feature aligned seamless constraints, which includes boundary length + * consistency constraints, and associated Jacobians + * + */ + namespace Penner { namespace Feature { diff --git a/include/feature/feature/dirichlet/dirichlet_penner_cone_metric.h b/include/feature/feature/dirichlet/dirichlet_penner_cone_metric.h index 6920262..6c0c789 100644 --- a/include/feature/feature/dirichlet/dirichlet_penner_cone_metric.h +++ b/include/feature/feature/dirichlet/dirichlet_penner_cone_metric.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/boundary_path.h" @@ -7,6 +15,13 @@ #include "holonomy/holonomy/marked_penner_cone_metric.h" #include "holonomy/holonomy/constraint.h" +/** + * @brief Extension of the differentiable cone metric using Penner coordinates + * to include both dual loop holonomy constraints and boundary length consistency + * constraints, which allow for feature aligned seamless metric constraints. + * + */ + namespace Penner { namespace Feature { @@ -121,7 +136,7 @@ class DirichletPennerConeMetric : public Holonomy::MarkedPennerConeMetric virtual std::unique_ptr project_to_constraint( SolveStats& solve_stats, - std::shared_ptr proj_params) const override; + std::shared_ptr proj_params) const override; virtual void write_status_log(std::ostream& stream, bool write_header = false) override; diff --git a/include/feature/feature/dirichlet/optimization.h b/include/feature/feature/dirichlet/optimization.h index 2c0a7c2..c0715d3 100644 --- a/include/feature/feature/dirichlet/optimization.h +++ b/include/feature/feature/dirichlet/optimization.h @@ -1,9 +1,22 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" #include "feature/dirichlet/dirichlet_penner_cone_metric.h" #include "holonomy/holonomy/newton.h" +/** + * @brief Two-phase optimization method for alignment of relaxed angle constraint. + * + */ + namespace Penner { namespace Feature { diff --git a/include/feature/feature/experimental/boundary_constraint_generator.h b/include/feature/feature/experimental/boundary_constraint_generator.h index cd9d5c1..6a15cfe 100644 --- a/include/feature/feature/experimental/boundary_constraint_generator.h +++ b/include/feature/feature/experimental/boundary_constraint_generator.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once diff --git a/include/feature/feature/experimental/boundary_constraint_validator.h b/include/feature/feature/experimental/boundary_constraint_validator.h index 92e28ed..1c6d3d5 100644 --- a/include/feature/feature/experimental/boundary_constraint_validator.h +++ b/include/feature/feature/experimental/boundary_constraint_validator.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once diff --git a/include/feature/feature/experimental/energy.h b/include/feature/feature/experimental/energy.h index 849b920..5bf4863 100644 --- a/include/feature/feature/experimental/energy.h +++ b/include/feature/feature/experimental/energy.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once @@ -15,10 +23,10 @@ class ConeEnergy : public Optimization::EnergyFunctor /// Sum of square cone error energy. /// /// @param[in] cone_metric: mesh topology - ConeEnergy(const Optimization::PennerConeMetric& cone_metric); + ConeEnergy(const PennerConeMetric& cone_metric); private: - Optimization::PennerConeMetric m_cone_metric; + PennerConeMetric m_cone_metric; virtual Scalar energy(const VectorX& metric_coords) const override; virtual VectorX gradient(const VectorX& metric_coords) const override; diff --git a/include/feature/feature/experimental/junctions.h b/include/feature/feature/experimental/junctions.h index f63d043..12d1a3c 100644 --- a/include/feature/feature/experimental/junctions.h +++ b/include/feature/feature/experimental/junctions.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once diff --git a/include/feature/feature/experimental/layout_optimizer.h b/include/feature/feature/experimental/layout_optimizer.h index ff238a0..6f4f28d 100644 --- a/include/feature/feature/experimental/layout_optimizer.h +++ b/include/feature/feature/experimental/layout_optimizer.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" diff --git a/include/feature/feature/experimental/marked_refinement.h b/include/feature/feature/experimental/marked_refinement.h index fc48cc4..553b18b 100644 --- a/include/feature/feature/experimental/marked_refinement.h +++ b/include/feature/feature/experimental/marked_refinement.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" diff --git a/include/feature/feature/experimental/misc.h b/include/feature/feature/experimental/misc.h index 942093a..23f306b 100644 --- a/include/feature/feature/experimental/misc.h +++ b/include/feature/feature/experimental/misc.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + struct ParametrizedMesh { @@ -47,4 +55,4 @@ struct ParametrizedOverlayMesh Eigen::MatrixXi F_uv; std::vector Fn_to_F; std::vector> endpoints; -}; +}; \ No newline at end of file diff --git a/include/feature/feature/experimental/newton.h b/include/feature/feature/experimental/newton.h index 62695ec..ac4d18f 100644 --- a/include/feature/feature/experimental/newton.h +++ b/include/feature/feature/experimental/newton.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" diff --git a/include/feature/feature/experimental/patches.h b/include/feature/feature/experimental/patches.h index 329237e..846ef96 100644 --- a/include/feature/feature/experimental/patches.h +++ b/include/feature/feature/experimental/patches.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" diff --git a/include/feature/feature/experimental/polygon_cones.h b/include/feature/feature/experimental/polygon_cones.h index 6c7240b..046d059 100644 --- a/include/feature/feature/experimental/polygon_cones.h +++ b/include/feature/feature/experimental/polygon_cones.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" diff --git a/include/feature/feature/experimental/transfer.h b/include/feature/feature/experimental/transfer.h index 2345a6e..19b0559 100644 --- a/include/feature/feature/experimental/transfer.h +++ b/include/feature/feature/experimental/transfer.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once diff --git a/include/feature/feature/feature/error.h b/include/feature/feature/feature/error.h index 6e6b7c1..7c1876d 100644 --- a/include/feature/feature/feature/error.h +++ b/include/feature/feature/feature/error.h @@ -1,9 +1,23 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" #include "feature/core/vf_corners.h" +/** + * @brief Methods to compute feature alignment error. Also includes methods to determine + * misaligned edges and numerically degenerate triangles. + * + */ + namespace Penner { namespace Feature { @@ -160,4 +174,4 @@ int check_flip(const Eigen::MatrixXd& uv, const Eigen::MatrixXi& FT); Eigen::MatrixXd compute_height(const Eigen::MatrixXd& uv, const Eigen::MatrixXi& FT); } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/feature/feature/feature/features.h b/include/feature/feature/feature/features.h index 3dce9cc..77ef349 100644 --- a/include/feature/feature/feature/features.h +++ b/include/feature/feature/feature/features.h @@ -1,11 +1,31 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" #include "feature/util/union_find.h" +#include "feature/core/vf_corners.h" #include "holonomy/holonomy/marked_penner_cone_metric.h" +/** + * @brief Method to find feature edges on a surface and hard feature constraint subsets. + * + * Uses dihedral angle to determine feature edges. Also includes options to set features manually, + * and methods to prune features based on component size. + * + * Also includes methods to remove feature graph cycles to use as hard feature constraints, and + * to greedily remove additional features. + * + */ + namespace Penner { namespace Feature { diff --git a/include/feature/feature/feature/gluing.h b/include/feature/feature/feature/gluing.h index 2a176b9..deee777 100644 --- a/include/feature/feature/feature/gluing.h +++ b/include/feature/feature/feature/gluing.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once @@ -6,6 +14,11 @@ namespace Penner { namespace Feature { +/** + * @brief Methods to get cut mesh edge and vertex correspondences, as well as total vertex cone angles. + * + */ + /** * @brief Given a mesh with vertex pairings arising from cuts, generate pairings of cut edges. * diff --git a/include/feature/feature/interface.h b/include/feature/feature/interface.h index b8cefda..0b5b5c3 100644 --- a/include/feature/feature/interface.h +++ b/include/feature/feature/interface.h @@ -1,9 +1,17 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" #include "feature/dirichlet/dirichlet_penner_cone_metric.h" #include "feature/feature/features.h" -#include "holonomy/field/intrinsic_field.h" +#include "field/intrinsic_field.h" #include "feature/core/vf_corners.h" #include "holonomy/interface.h" @@ -234,4 +242,4 @@ class AlignedMetricGenerator } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/feature/feature/pybind.h b/include/feature/feature/pybind.h index d875e8a..12d53e8 100644 --- a/include/feature/feature/pybind.h +++ b/include/feature/feature/pybind.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #ifdef PYBIND #ifndef MULTIPRECISION diff --git a/include/feature/feature/surgery/cut_mesh_layout.h b/include/feature/feature/surgery/cut_mesh_layout.h index 1ba06f8..432e5c3 100644 --- a/include/feature/feature/surgery/cut_mesh_layout.h +++ b/include/feature/feature/surgery/cut_mesh_layout.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" @@ -6,6 +14,11 @@ namespace Penner { namespace Feature { +/** + * @brief Methods to parameterize the uv components of a cut mesh, aligning each component with uv isolines. + * + */ + /** * @brief Parametrize a cut mesh with optimized metric. * diff --git a/include/feature/feature/surgery/cut_metric_generator.h b/include/feature/feature/surgery/cut_metric_generator.h index 7bc3251..5ab97d6 100644 --- a/include/feature/feature/surgery/cut_metric_generator.h +++ b/include/feature/feature/surgery/cut_metric_generator.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" @@ -7,6 +15,12 @@ namespace Penner { namespace Feature { +/** + * @brief Data structure to generate fields and differentiable metrics for a mesh cut + * along feature lines. + * + */ + class CutMetricGenerator { public: @@ -174,4 +188,4 @@ class CutMetricGenerator }; } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/feature/feature/surgery/refinement.h b/include/feature/feature/surgery/refinement.h index fb8fba6..54e2b30 100644 --- a/include/feature/feature/surgery/refinement.h +++ b/include/feature/feature/surgery/refinement.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/boundary_path.h" @@ -6,6 +14,16 @@ #include "feature/feature/features.h" #include "holonomy/holonomy/marked_penner_cone_metric.h" +/** + * @brief Data structure with limited support to refine the faces and edges of a mesh for feature alignment. + * + * Only intended for use with the limited mesh refinement needed for ensuring the validity + * of the feature alignment problem, including refining faces with more than one feature edge, + * and refining edges to ensure every facet component of the feature cut mesh has at least one adjacent + * hard feature constraint + * + */ + namespace Penner { namespace Feature { diff --git a/include/feature/feature/surgery/stitching.h b/include/feature/feature/surgery/stitching.h index 64f2731..6a17198 100644 --- a/include/feature/feature/surgery/stitching.h +++ b/include/feature/feature/surgery/stitching.h @@ -1,8 +1,22 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" +/** + * @brief Method to stitch a mesh cut along feature lines and parametrized, possibly with edge refinement, + * into a single parametrized mesh. + * + */ + namespace Penner { namespace Feature { diff --git a/include/feature/feature/util/union_find.h b/include/feature/feature/util/union_find.h index 45046b3..f8bbf79 100644 --- a/include/feature/feature/util/union_find.h +++ b/include/feature/feature/util/union_find.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "feature/core/common.h" @@ -101,6 +109,8 @@ class UnionFind } /** +<<<<<<< HEAD +======= * @brief Get a representative element for each set. * * @return vector of one element per set @@ -123,6 +133,7 @@ class UnionFind } /** +>>>>>>> resolution * @brief Build labels for the set elements. * * @return map from elements to set index diff --git a/include/field/field/comiso.h b/include/field/field/comiso.h new file mode 100644 index 0000000..b533924 --- /dev/null +++ b/include/field/field/comiso.h @@ -0,0 +1,197 @@ +// Copyright (C) 2026 Ryan Capouellez +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU 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 General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#pragma once + +// WARNING: CoMISo uses a more restrictive copyleft license +#if USE_COMISO +#include +#include +#include + +#include "field/rounder.h" + +namespace Penner { +namespace Field { + + + +// TODO Make option and make cone rounder code public +class ConeMISolver : public COMISO::MISolver +{ +public: + ConeMISolver() {}; + void solve_cone_rounding( + CSCMatrix& _A, + Vecd& _x, + Vecd& _rhs, + Veci& _to_round, + Rounder& rounder) { + // StopWatch + COMISO::StopWatch sw; + double time_search_next_integer = 0; + + // some statistics + n_local_ = 0; + n_cg_ = 0; + n_full_ = 0; + + // reset cholmod step flag + cholmod_step_done_ = false; + + Veci to_round(_to_round); + // copy to round vector and make it unique + std::sort(to_round.begin(), to_round.end()); + Veci::iterator last_unique; + last_unique = std::unique(to_round.begin(), to_round.end()); + int r = last_unique - to_round.begin(); + to_round.resize( r); + + // initalize old indices + Veci old_idx(_rhs.size()); + for(unsigned int i=0; i 2) std::cerr << "initial full solution" << std::endl; + direct_solver_.calc_system_gmm(_A); + direct_solver_.solve(_x, _rhs); + + cholmod_step_done_ = true; + + ++n_full_; + } + + // neighbors for local optimization + Vecui neigh_i; + + // Vector for reduced solution + Vecd xr(_x); + + // loop until solution computed + for(unsigned int i=0; i 0) + { + std::cerr << "Integer DOF's left: " << to_round.size()-(i+1) << " "; + if( noisy_ > 1) + std::cerr << "residuum_norm: " << COMISO_GMM::residuum_norm( _A, xr, _rhs) << std::endl; + } + + // position in round vector + std::vector tr_best; + + sw.start(); + + RoundingSet rset; + rset.set_threshold(multiple_rounding_threshold_); + + // find index yielding smallest rounding error + for(unsigned int j=0; j 5) + std::cerr << "round " << tr_best.size() << " variables simultaneously\n"; + + // clear neigh for local update + neigh_i.clear(); + + for(unsigned int j = 0; j 2) std::cerr << "final full solution" << std::endl; + + if( gmm::mat_ncols( _A) > 0) + { + if(cholmod_step_done_) + direct_solver_.update_system_gmm(_A); + else + direct_solver_.calc_system_gmm(_A); + + direct_solver_.solve( xr, _rhs); + ++n_full_; + } + } + + // store solution values to result vector + for(unsigned int i=0; i +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "holonomy/core/common.h" +#include "metric/common.h" + +/** + * @brief Methods for generating cross fields as represented by four rotationally symmetric + * tangent vectors. + * + */ namespace Penner { -namespace Holonomy { +namespace Field { /** * @brief Load rawfield data format used by Directional. @@ -65,4 +79,4 @@ std::array reduce_curl( const std::vector& fixed_faces); } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/holonomy/holonomy/field/facet_field.h b/include/field/field/facet_field.h similarity index 75% rename from include/holonomy/holonomy/field/facet_field.h rename to include/field/field/facet_field.h index b5db9c9..a484a3a 100644 --- a/include/holonomy/holonomy/field/facet_field.h +++ b/include/field/field/facet_field.h @@ -1,10 +1,23 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "holonomy/core/common.h" +#include "metric/common.h" namespace Penner { -namespace Holonomy { +namespace Field { + +/** + * @brief Methods for generating cross fields using legacy facet field file representations. + * + */ /** * @brief Load a per-facet frame field with edge matchings from file @@ -48,4 +61,4 @@ std::tuple generate_halfedge_from_face_matchin int version=0); } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/field/field/field.h b/include/field/field/field.h new file mode 100644 index 0000000..874cd5e --- /dev/null +++ b/include/field/field/field.h @@ -0,0 +1,35 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + + +#pragma once +#include "metric/common.h" + +/** + * @brief Methods to generate field directions and cones from an nrosy field. + * + */ + +namespace Penner { +namespace Field { + +/** + * @brief Generate a cross field for a mesh + * + * @param V: mesh vertices + * @param F: mesh faces + * @return |F|x3 frame field of per-face field direction vectors + * @return per-vertex cone angles corresponding to the frame field + */ +std::tuple> generate_cross_field( + const Eigen::MatrixXd& V, + const Eigen::MatrixXi& F); + + +} // namespace Field +} // namespace Penner \ No newline at end of file diff --git a/include/holonomy/holonomy/field/forms.h b/include/field/field/forms.h similarity index 74% rename from include/holonomy/holonomy/field/forms.h rename to include/field/field/forms.h index 1c56594..6f49558 100644 --- a/include/holonomy/holonomy/field/forms.h +++ b/include/field/field/forms.h @@ -1,10 +1,30 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "holonomy/core/common.h" -#include "holonomy/core/dual_loop.h" +#include "metric/common.h" +#include "metric/cone_metric.h" + +/** + * @brief Methods for creating and manipulating one forms on a surface, represented as + * anti-symmetric halfedge values. + * + * These halfedge values are interpretable as the integrated values of the form along the + * oriented halfedges. + * + * Includes methods to check whether forms are valid and closed, to integrate closed one + * forms over a disk, and to scale vertices by integrated one forms. + * + */ namespace Penner { -namespace Holonomy { +namespace Field { /** * @brief Determine if a one form is valid. @@ -16,7 +36,7 @@ namespace Holonomy { bool is_valid_one_form(const Mesh& m, const VectorX& one_form); /** - * @brief Determine if a one form is closed + * @brief Determine if a one form is closed, meaning the sum of halfedge values in a face is zero * * @param m: mesh * @param one_form: per-halfedge one-form @@ -24,33 +44,6 @@ bool is_valid_one_form(const Mesh& m, const VectorX& one_form); */ bool is_closed_one_form(const Mesh& m, const VectorX& one_form); -/** - * @brief Given a list of dual loops, compute a matrix with columns given by the corresponding - * closed one forms for the dual loops. - * - * @param m: mesh - * @param dual_loops: loops defining the one forms - * @return matrix of dual loop one forms - */ -MatrixX build_dual_loop_basis_one_form_matrix( - const Mesh& m, - const std::vector>& dual_loops); - -/** - * @brief Given a mesh and a homology basis, compute a matrix for the space of closed one forms - * with the first |V| (or |V| - 1) columns corresponding to vertex hat function derivatives and the - * last 2g corresponding to the homology basis loops. - * - * @param m: mesh - * @param homology_basis_loops: homology basis loops for the mesh - * @param eliminate_vertex: remove the last vertex of the mesh so that the matrix is full rank - * @return matrix with basis forms as columns - */ -MatrixX build_closed_one_form_matrix( - const Mesh& m, - const std::vector>& homology_basis_loops, - bool eliminate_vertex = false); - /** * @brief Compute the matrix that integrates a closed one-form over a cut of the mesh to a disk. * @@ -129,5 +122,5 @@ VectorX scale_edges_by_zero_form( const VectorX& metric_coords, const VectorX& zero_form); -} // namespace Holonomy +} // namespace Field } // namespace Penner \ No newline at end of file diff --git a/include/holonomy/holonomy/field/frame_field.h b/include/field/field/frame_field.h similarity index 85% rename from include/holonomy/holonomy/field/frame_field.h rename to include/field/field/frame_field.h index 63f7a18..6ac750f 100644 --- a/include/holonomy/holonomy/field/frame_field.h +++ b/include/field/field/frame_field.h @@ -1,11 +1,23 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "holonomy/core/common.h" -#include "holonomy/field/intrinsic_field.h" +#include "field/intrinsic_field.h" + +/** + * @brief TODO: Redistribute this code + * + */ namespace Penner { -namespace Holonomy { +namespace Field { /** * @brief Generate the reference tangent direction of a face along the oriented edge opposite @@ -59,7 +71,7 @@ Eigen::MatrixXd generate_reference_field( * @param theta: offset angles of a representative cross field direction relative to the reference * @return per-face representative direction matrix */ -Eigen::MatrixXd generate_field( +Eigen::MatrixXd generate_frame_field( const Eigen::MatrixXd& V, const Eigen::MatrixXi& F, const Eigen::MatrixXd& reference_field, @@ -129,6 +141,48 @@ void write_frame_field( const Eigen::MatrixXd& kappa, const Eigen::MatrixXi& period_jump); +/** + * @brief Write a rosy field to file. + * + * The format is + * ``` + * + * 4 + * + * ... + * ``` + * where d is a representative direction on the face. + * + * @param output_filename: file location to serialize the frame field + * @param V: mesh vertices + * @param F: mesh faces + * @param reference_field: per-face reference tangent direction matrix + * @param theta: offset angles of a representative cross field direction relative to the reference + */ +void write_rosy_field( + const std::string& output_filename, + const Eigen::MatrixXd& V, + const Eigen::MatrixXi& F, + const Eigen::MatrixXd& reference_field, + const Eigen::VectorXd& theta); + +/** + * @brief Write a combed frame field to file. + * + * + * ... + * ``` + * where d1 and d2 are the two combed field direction + * + * @param output_filename: file location to serialize the frame field + * @param PD1: per-face u direction matrix + * @param PD2: per-face b direction matrix + */ +void write_combed_field( + const std::string& output_filename, + const Eigen::MatrixXd& PD1, + const Eigen::MatrixXd& PD2); + std::tuple maximize_combed_frame_alignment( const Eigen::MatrixXd& V, @@ -152,24 +206,21 @@ std::tuple load_combed_field(const std::string& ffield_file); /** - * @brief Write a combed frame field to file. + * @brief Load a rosy field from file. * * The format is * ``` * - * + * 4 + * * ... * ``` - * where d1 and d2 are the two combed field direction + * where d is a representative direction on the face. * - * @param output_filename: file location to serialize the frame field - * @param PD1: per-face u direction matrix - * @param PD2: per-face b direction matrix + * @param input_filename: file location of the rosy field + * @return per-face representative field direction */ -void write_combed_field( - const std::string& output_filename, - const Eigen::MatrixXd& PD1, - const Eigen::MatrixXd& PD2); +Eigen::MatrixXd load_rosy_field(const std::string& input_filename); /** * @brief Load a frame field from file. @@ -254,4 +305,4 @@ Eigen::VectorXi transfer_period_jumps_to_halfedge( const Eigen::MatrixXi& corner_period_jump); } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/holonomy/holonomy/field/intrinsic_field.h b/include/field/field/intrinsic_field.h similarity index 86% rename from include/holonomy/holonomy/field/intrinsic_field.h rename to include/field/field/intrinsic_field.h index a080b00..92ae87c 100644 --- a/include/holonomy/holonomy/field/intrinsic_field.h +++ b/include/field/field/intrinsic_field.h @@ -1,6 +1,15 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "holonomy/core/common.h" +#include "metric/common.h" +#include "metric/cone_metric.h" // TODO: This needs a lot of cleanup. To make it clean: // - The rounder should be moved to another file, and the CoMISo changes made in a fork @@ -8,7 +17,7 @@ // - The double code should be much cleaner, e.g., by making a derived class namespace Penner { -namespace Holonomy { +namespace Field { /** * @brief Parameters for cross field generation @@ -63,6 +72,14 @@ class IntrinsicNRosyField Eigen::VectorXd& face_angle, Eigen::MatrixXd& corner_kappa, Eigen::MatrixXi& corner_period_jump) const; + void get_field( + const Mesh& m, + const std::vector& vtx_reindex, + const Eigen::MatrixXi& F, + Eigen::VectorXi& reference_corner, + Eigen::VectorXd& face_angle, + Eigen::MatrixXd& corner_kappa, + Eigen::MatrixXi& corner_period_jump) const; void get_halfedge_field( const Mesh& m, @@ -88,6 +105,18 @@ class IntrinsicNRosyField const Eigen::VectorXd& face_theta, const Eigen::MatrixXd& corner_kappa, const Eigen::MatrixXi& corner_period_jump); + void set_field( + const Mesh& m, + const std::vector& vtx_reindex, + const Eigen::MatrixXi& F, + const Eigen::VectorXd& face_theta, + const Eigen::MatrixXd& corner_kappa, + const Eigen::MatrixXi& corner_period_jump); + void set_theta( + const Mesh& m, + const Eigen::VectorXd& face_theta); + + Scalar min_angle = 0.; void set_halfedge_field( const Mesh& m, @@ -213,5 +242,5 @@ void initialize_double_priority_kappa(const Mesh& m, const std::vector generate_min_cones(const Mesh& m, int min_cone=1); std::vector build_double_dual_bfs_forest(const Mesh& m, const std::vector roots); -} // namespace Holonomy -} // namespace Penner +} // namespace Field +} // namespace Penner \ No newline at end of file diff --git a/include/field/field/rounder.h b/include/field/field/rounder.h new file mode 100644 index 0000000..aef2056 --- /dev/null +++ b/include/field/field/rounder.h @@ -0,0 +1,150 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once + +#include "metric/common.h" +#include "metric/cone_metric.h" +#include "util/vector.h" +#include "util/map.h" + +// TODO: This needs a lot of cleanup. To make it clean: +// - The rounder should be moved to another file, and the CoMISo changes made in a fork +// - The facet principal curvature should be in another file +// - The double code should be much cleaner, e.g., by making a derived class + +namespace Penner { +namespace Field { + +class Rounder { +public: + Rounder( + const Mesh& m, + const std::vector& _var2he, + const std::vector& _halfedge_var_id, + const std::vector& _base_cones, + const std::vector& _min_cones) + : var2he(_var2he) + , halfedge_var_id(_halfedge_var_id) + , base_cones(_base_cones) + , min_cones(_min_cones) + , is_rounded(m.n_halfedges(), false) + , values(m.n_halfedges(), 0) + , to(vector_compose(m.v_rep, m.to)) + , opp(m.opp) + , is_double(m.type[0] > 0) + { + int num_halfedges = m.n_halfedges(); + int num_vertices = m.n_ind_vertices(); + cone_period_jumps = std::vector>(num_vertices, std::vector()); + for (int hij = 0; hij < num_halfedges; ++hij) + { + // only add variable period jumps + if (halfedge_var_id[hij] == -1) continue; + + // add halfedge to tip + int vj = m.v_rep[m.to[hij]]; + cone_period_jumps[vj].push_back(hij); + + // add opposite halfedge to base + int hji = m.opp[hij]; + int vi = m.v_rep[m.to[hji]]; + cone_period_jumps[vi].push_back(hji); + } + } + + int compute_cone_correction(int hij) + { + int vj = to[hij]; + int cone = base_cones[vj]; + for (int h : cone_period_jumps[vj]) + { + cone += (is_double) ? (2 * values[h]) : values[h]; + } + + return (min_cones[vj] - cone); + } + + bool is_zero_cone(int hij) + { + int vj = to[hij]; + int cone = base_cones[vj]; + for (int h : cone_period_jumps[vj]) + { + if ((h != hij) && (!is_rounded[h])) return false; + cone += (is_double) ? (2 * values[h]) : values[h]; + } + + return (cone < min_cones[vj]); + } + + int test_round(int id, Scalar x) + { + int hij = var2he[id]; + //int rounded_value = ((x)<0?int((x)-0.5):int((x)+0.5)); + int rounded_value = lround(x); + int hji = opp[hij]; + values[hij] = rounded_value; + values[hji] = -rounded_value; + bool is_tip_cone = is_zero_cone(hij); + bool is_base_cone = is_zero_cone(hji); + + if ((is_tip_cone) && (is_base_cone)) + { + spdlog::warn("Cone at both tip and base of period jump halfedge"); + return rounded_value; + } + if (is_tip_cone) + { + spdlog::trace("Cone at tip of period jump halfedge"); + int n = compute_cone_correction(hij); + if (n > 1) spdlog::trace("correction at tip is {}", n); + if (n < 0) spdlog::error("correction at tip is {}", n); + return rounded_value + n; + } + if (is_base_cone) + { + spdlog::trace("Cone at base of period jump halfedge"); + int n = compute_cone_correction(hji); + if (n > 1) spdlog::trace("correction at base is {}", n); + if (n < 0) spdlog::error("correction at tip is {}", n); + return rounded_value - n; + } + + return rounded_value; + + } + + int commit_round(int id, Scalar x) + { + int rounded_value = test_round(id, x); + int hij = var2he[id]; + int hji = opp[hij]; + values[hij] = rounded_value; + values[hji] = -rounded_value; + is_rounded[hij] = true; + is_rounded[hji] = true; + return rounded_value; + } + +private: + std::vector var2he; + std::vector halfedge_var_id; + std::vector base_cones; + std::vector min_cones; + std::vector is_rounded; + std::vector values; + std::vector> cone_period_jumps; + std::vector to; + std::vector opp; + bool is_double; + +}; + +} +} \ No newline at end of file diff --git a/include/holonomy/holonomy/core/boundary_basis.h b/include/holonomy/holonomy/core/boundary_basis.h index b56c70e..b12fb7c 100644 --- a/include/holonomy/holonomy/core/boundary_basis.h +++ b/include/holonomy/holonomy/core/boundary_basis.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/core/common.h" @@ -6,6 +14,21 @@ namespace Penner { namespace Holonomy { +/** + * @brief Methods to generate basis dual loops for the double of meshes with boundary. + * + * These loops correspond to alignment constraints between different boundary components + * of a mesh with boundary. For a mesh with b boundary components, b - 1 constraints are needed. + * The constraint measures the holonomy between a base boundary component and another component. + * + * In the doubled mesh for a mesh with boundary, the paths between components become dual loops. + * + * Note that the double mesh has b - 1 handles corresponding to the boundary loops, which results + * in an increase in genus of 2b - 2. However, the holonomy of b - 1 loops are determined by cone + * angle constraints and symmetry. + * + */ + /** * @brief Class to generate boundary loops and boundary path basis loops */ @@ -66,4 +89,4 @@ class BoundaryBasisGenerator }; } // namespace Holonomy -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/holonomy/holonomy/core/common.h b/include/holonomy/holonomy/core/common.h index 1882ada..4b48aea 100644 --- a/include/holonomy/holonomy/core/common.h +++ b/include/holonomy/holonomy/core/common.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include @@ -9,15 +17,19 @@ #include #include "optimization/interface.h" -#include "optimization/core/common.h" -#include "optimization/core/cone_metric.h" +#include "metric/common.h" +#include "metric/cone_metric.h" #include "util/vector.h" +/** + * @brief Assorted utility functions. + * + */ + namespace Penner { namespace Holonomy { // Typedefs -using Optimization::DifferentiableConeMetric; typedef Eigen::Matrix RowVectors2i; @@ -34,64 +46,6 @@ Type square(const Type& a) return a * a; } -/** - * @brief Compute the dot product of two 3D vectors. - * - * @tparam vector representation of R3 supporting indexing - * @param v1: first vector - * @param v2: second vector - * @return dot product of the two vectors - */ -template -double dot_prod(const VectorType& v1, const VectorType& v2) -{ - return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; -} - -/** - * @brief Compute the cross product of two 3D vectors. - * - * @tparam vector representation of R3 supporting indexing - * @param v1: first vector - * @param v2: second vector - * @return cross product of the two vectors - */ -template -VectorType cross_prod(const VectorType& v1, const VectorType& v2) -{ - return VectorType( - v1[1] * v2[2] - v1[2] * v2[1], - v1[2] * v2[0] - v1[0] * v2[2], - v1[0] * v2[1] - v1[1] * v2[0]); -} - -/** - * @brief Compute the signed angle between two 3D vectors around a normal axis. - * - * @tparam vector representation of R3 supporting indexing - * @param v1: first vector - * @param v2: second vector - * @param normal: normal vector representing the axis of rotation - * @return signed angle between the two vectors around the axis of rotation - */ -template -double signed_angle(const VectorType& v1, const VectorType& v2, const VectorType& normal) -{ - double s = dot_prod(normal, cross_prod(v1, v2)); - double c = dot_prod(v1, v2); - const double angle = (s == 0 && c == 0) ? 0.0 : atan2(s, c); - return angle; -} - -/** - * @brief Compute the real modulus of x mod y - * - * @param x: positive number to mod - * @param y: positive modulus - * @return x (mod y) - */ -inline -Scalar pos_fmod(Scalar x, Scalar y) { return (0 == y) ? x : x - y * floor(x / y); } /** * @brief Compute the Euler characteristic of the mesh diff --git a/include/holonomy/holonomy/core/dual_lengths.h b/include/holonomy/holonomy/core/dual_lengths.h index 6944aa5..453db05 100644 --- a/include/holonomy/holonomy/core/dual_lengths.h +++ b/include/holonomy/holonomy/core/dual_lengths.h @@ -1,9 +1,23 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/core/common.h" #include "util/spanning_tree.h" +/** + * @brief Method to compute the dual edge lengths. Also includes a related method to compute + * the length of loops formed by adding an edge to a dual spanning tree. + * + */ + namespace Penner { namespace Holonomy { @@ -30,4 +44,4 @@ std::vector compute_dual_loop_length_weights( const DualTree& dual_tree); } // namespace Holonomy -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/holonomy/holonomy/core/dual_loop.h b/include/holonomy/holonomy/core/dual_loop.h index 75f5405..59c98b9 100644 --- a/include/holonomy/holonomy/core/dual_loop.h +++ b/include/holonomy/holonomy/core/dual_loop.h @@ -1,19 +1,74 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/core/common.h" #include "holonomy/core/dual_segment.h" +/** + * @brief Methods to manage dual loops on a surface. Includes classes to represent dual loops on a surface + * and data structures to quickly query intersections of the loops with edges of the underlying mesh. + * + */ + namespace Penner { namespace Holonomy { +/** + * @brief Representation of a dual segment as two halfedges in a face at the start + * and end of the dual segment. + * + */ typedef std::array DualSegment; +/** + * @brief Utility class to map from halfedges to dual loop segments that intersect it, + * using a dense vector representation, + * + * WARNING: Memory usage is O(|E|), so it scales poorly for large meshes with many edges + * + */ class DenseHalfedgeMap { public: + /** + * @brief Construct a halfedge map with a fixed capacity. + * + * @param num_halfedges: total number of halfedges in the mesh + */ DenseHalfedgeMap(int num_halfedges); + + /** + * @brief Remove all segment entries from all halfedges. + */ void clear(); + + /** + * @brief Add entry for a segment in a halfedge. + * + * @param halfedge_index: halfedge containing segment + * @param segment_index: segment intersecting halfedge + */ void add_segment(int halfedge_index, int segment_index); + + /** + * @brief Remove all segments from a given halfedge + * + * @param halfedge_index: halfedge in mesh + */ void erase_entry(int halfedge_index); + + /** + * @brief Get all segments in the given halfedge + * + * @param halfedge_index: index of a halfedge in the mesh + * @return segments in the halfedge. + */ const std::vector& get_halfedge_segments(int halfedge_index); private: std::vector m_h_num_segments; @@ -26,18 +81,51 @@ class DenseHalfedgeMap { std::vector m_temp_list; }; +/** + * @brief Utility class to map from halfedges to dual loop segments that intersect it, + * using a sparse map representation, + * + */ class SparseHalfedgeMap { public: + /** + * @brief Construct an empty halfedge map. + */ SparseHalfedgeMap(); + + /** + * @brief Remove all segment entries from all halfedges. + */ void clear(); + + /** + * @brief Add entry for a segment in a halfedge. + * + * @param halfedge_index: halfedge containing segment + * @param segment_index: segment intersecting halfedge + */ void add_segment(int halfedge_index, int segment_index); + + /** + * @brief Remove all segments from a given halfedge. + * + * @param halfedge_index: halfedge in mesh + */ void erase_entry(int halfedge_index); + + /** + * @brief Get all segments in the given halfedge. + * + * @param halfedge_index: index of a halfedge in the mesh + * @return segments in the halfedge, or an empty list if none exist + */ const std::vector& get_halfedge_segments(int halfedge_index); private: std::unordered_map> m_h2segments; std::vector m_empty_list; }; +// By default, use sparse representation typedef SparseHalfedgeMap HalfedgeMap; /** @@ -47,8 +135,27 @@ typedef SparseHalfedgeMap HalfedgeMap; class DualLoop { public: + /** + * @brief Update the dual loop after a counter-clockwise flip in the underlying mesh. + * + * @param m: underlying mesh before the flip + * @param halfedge_index: halfedge to be flipped + */ virtual void update_under_ccw_flip(const Mesh& m, int halfedge_index) = 0; + + /** + * @brief Generate the ordered sequence of face indices the dual loop traverses. + * + * @param m: underlying mesh + * @return sequence of face indices in traversal order + */ virtual std::vector generate_face_sequence(const Mesh& m) const = 0; + + /** + * @brief Create a heap-allocated copy of this dual loop. + * + * @return owning pointer to a cloned dual loop of the same concrete type + */ virtual std::unique_ptr clone() const = 0; virtual ~DualLoop() = default; @@ -59,6 +166,12 @@ class DualLoop class DualSegmentIterator { public: + /** + * @brief Construct an iterator positioned at the start or end of the loop. + * + * @param parent: dual loop being iterated + * @param is_start: true to position at the first segment, false for the end sentinel + */ DualSegmentIterator(const DualLoop& parent, bool is_start = true) : m_parent(parent) , m_is_start(is_start) @@ -67,6 +180,11 @@ class DualLoop m_current_segment_index = m_start_segment_index; } + /** + * @brief Advance the iterator to the next segment (pre-increment). + * + * @return reference to this iterator after advancing + */ DualSegmentIterator& operator++() { m_is_start = false; @@ -74,6 +192,11 @@ class DualLoop return *this; } + /** + * @brief Advance the iterator to the next segment (post-increment). + * + * @return copy of this iterator before advancing + */ DualSegmentIterator operator++(int) { DualSegmentIterator temp = *this; @@ -81,6 +204,16 @@ class DualLoop return temp; } + /** + * @brief Check equality with another iterator. + * + * Two iterators are equal when they point to the same segment index and + * both share the same start/non-start state (to distinguish begin from end + * on a closed loop). + * + * @param rhs: iterator to compare against + * @return true if iterators are equal + */ bool is_equal(const DualSegmentIterator& rhs) const { return ( @@ -98,11 +231,21 @@ class DualLoop return (!(lhs == rhs)); } + /** + * @brief Check whether the iterator has traversed the entire loop. + * + * @return true if the iterator has wrapped back to the start segment + */ bool is_end() { return ((!m_is_start) && (m_current_segment_index == m_start_segment_index)); } + /** + * @brief Dereference the iterator to obtain the current dual segment. + * + * @return dual segment at the current position + */ DualSegment operator*() { return m_parent.get_dual_segment(m_current_segment_index); } private: @@ -127,8 +270,27 @@ class DualLoop DualSegmentIterator end() const { return DualSegmentIterator(*this, false); } protected: + /** + * @brief Return the index of the segment following the given one in the loop. + * + * @param segment_index: index of the current segment + * @return index of the next segment + */ virtual int get_next(int segment_index) const = 0; + + /** + * @brief Return the index of the canonical first segment used to initialize iteration. + * + * @return starting segment index + */ virtual int get_start_segment_index() const = 0; + + /** + * @brief Return the dual segment stored at the given index. + * + * @param segment_index: index of the segment to retrieve + * @return dual segment (pair of halfedge indices bounding a face crossing) + */ virtual DualSegment get_dual_segment(int segment_index) const = 0; }; @@ -195,42 +357,97 @@ class DualLoopConnectivity : public DualLoop void enable_validity_checks() { m_check_validity = true; } protected: - // Connectivity getters + /** + * @brief Return the total number of allocated segment slots (including deleted ones). + * + * @return number of segment slots + */ int count_segment_indices() const { return m_next.size(); } + /** + * @brief Return the index of the segment following the given one in the loop. + * + * @param segment_index: index of the current segment + * @return index of the next segment + */ int get_next(int segment_index) const override { assert(is_valid_segment_index(segment_index)); return m_next[segment_index]; } + /** + * @brief Return the index of the segment preceding the given one in the loop. + * + * @param segment_index: index of the current segment + * @return index of the previous segment + */ int get_prev(int segment_index) const { assert(is_valid_segment_index(segment_index)); return m_prev[segment_index]; } + /** + * @brief Return the start halfedge of the given segment. + * + * @param segment_index: index of the segment + * @return halfedge index at which the segment enters its face + */ int get_start(int segment_index) const { assert(is_valid_segment_index(segment_index)); return m_start[segment_index]; } + /** + * @brief Return the end halfedge of the given segment. + * + * @param segment_index: index of the segment + * @return halfedge index at which the segment exits its face + */ int get_end(int segment_index) const { assert(is_valid_segment_index(segment_index)); return m_end[segment_index]; } + /** + * @brief Check whether a segment slot has been freed. + * + * @param segment_index: index of the segment slot + * @return true if the slot is deleted and available for reuse + */ bool is_deleted(int segment_index) const { return m_is_deleted[segment_index]; } // Index based segment management int get_start_segment_index() const override; DualSegment get_dual_segment(int segment_index) const override; - // Validity tests + /** + * @brief Check whether a segment index is within bounds and not deleted. + * + * @param segment_index: index to validate + * @return true if the index refers to a live segment + */ bool is_valid_segment_index(int segment_index) const; + + /** + * @brief Verify that the next/prev linkage is internally consistent. + * + * @return true if all segments form a well-linked circular list + */ bool is_valid_connectivity() const; + + /** + * @brief Verify that the dual loop correctly overlays the given mesh. + * + * Checks that every segment's halfedges belong to a common face and that + * consecutive segments share an edge crossing. + * + * @param m: underlying mesh + * @return true if the dual loop is geometrically valid on the mesh + */ bool is_valid_dual_loop(const Mesh& m) const; private: @@ -251,17 +468,51 @@ class DualLoopConnectivity : public DualLoop bool m_check_validity = false; - // Atomic loop change operations + /** + * @brief Split a segment at an interior halfedge, inserting a new segment. + * + * Used when a flip introduces an edge that bisects an existing segment. + * + * @param segment_index: segment to split + * @param halfedge_index: new halfedge crossing the segment + * @param opposite_halfedge: opposite halfedge of the crossing edge + */ void split_segment(int segment_index, int halfedge_index, int opposite_halfedge); + + /** + * @brief Swap the endpoints of two adjacent segments across a flipped edge. + * + * @param first_segment_index: first segment involved in the flip + * @param second_segment_index: second segment involved in the flip + * @param halfedge_index: halfedge that was flipped + * @param opposite_halfedge: opposite halfedge of the flipped edge + */ void flip_segments( int first_segment_index, int second_segment_index, int halfedge_index, int opposite_halfedge); + + /** + * @brief Merge two consecutive segments into one, removing the shared crossing. + * + * @param first_segment_index: segment whose end will be extended + * @param second_segment_index: segment to be absorbed and deleted + */ void combine_segments(int first_segment_index, int second_segment_index); - // Index memory management + /** + * @brief Allocate a new segment slot, reusing a freed index if available. + * + * @return index of the newly created segment slot + */ int create_segment_index(); + + /** + * @brief Mark a segment slot as deleted and return it to the free list. + * + * @param segment_index: index of the segment to free + */ void delete_segment_index(int segment_index); // TODO Add garbage collector for resizing @@ -328,13 +579,59 @@ class DualLoopList : public DualLoop int count_segment_indices() const { return m_dual_path.size(); } }; +/** + * @brief Manager that maps mesh edges to the dual loops crossing them. + * + * Provides O(1) lookup of which dual loops intersect a given edge, and supports + * bulk registration of all edges crossed by a loop. + */ class DualLoopManager{ public: + /** + * @brief Construct a manager sized for the given number of edges. + * + * @param num_edges: total number of edges in the mesh + */ DualLoopManager(int num_edges); + + /** + * @brief Remove all edge-to-loop associations. + */ void clear(); + + /** + * @brief Record that a dual loop crosses a given edge. + * + * @param edge_index: edge intersected by the loop + * @param loop_index: index of the dual loop + */ void add_loop(int edge_index, int loop_index); + + /** + * @brief Register all edges crossed by a dual loop. + * + * Iterates over every segment of @p dual_loop, determines which mesh edge each + * segment crosses, and calls add_loop() for each edge-loop pair. + * + * @param loop_index: index of the dual loop being registered + * @param m: underlying mesh + * @param dual_loop: dual loop whose edge crossings will be recorded + */ void register_loop_edges(int loop_index, const Mesh& m, const DualLoop& dual_loop); + + /** + * @brief Remove all loop associations for a given edge. + * + * @param edge_index: edge whose loop entries will be cleared + */ void erase_entry(int edge_index); + + /** + * @brief Get all dual loops crossing a given edge. + * + * @param edge_index: index of the edge to query + * @return loop indices crossing the edge + */ const std::vector& get_edge_loops(int edge_index); private: std::vector m_e_num_loops; diff --git a/include/holonomy/holonomy/core/dual_segment.h b/include/holonomy/holonomy/core/dual_segment.h index 29e6621..c542af4 100644 --- a/include/holonomy/holonomy/core/dual_segment.h +++ b/include/holonomy/holonomy/core/dual_segment.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/core/common.h" @@ -5,6 +13,20 @@ namespace Penner { namespace Holonomy { +/** + * @brief Methods to manage sequences of dual segments (pairs of halfedges bounding a face crossing path) on a mesh, + * including methods to convert to or from dual loop sequences and to update under counter clockwise edge flips. + * + * These methods are largely superseded by the Dual Loop representations, which support more efficient + * queries, but are useful as a minimal representation for quick implementations and comparison. + * + */ + +/** + * @brief Representation of a dual segment as two halfedges in a face at the start + * and end of the dual segment. + * + */ typedef std::array DualSegment; /** diff --git a/include/holonomy/holonomy/core/homology_basis.h b/include/holonomy/holonomy/core/homology_basis.h index bac00c1..4bff11c 100644 --- a/include/holonomy/holonomy/core/homology_basis.h +++ b/include/holonomy/holonomy/core/homology_basis.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once @@ -5,6 +13,16 @@ #include "holonomy/core/dual_loop.h" #include "util/spanning_tree.h" +/** + * @brief Methods to generate basis dual loops for a mesh. A closed genus g surface has + * 2g basis loops. + * + * For meshes with boundary, this generates the basis loops that do not bound holes. + * Basis loops corresponding holes are generally irrelevant in the seamless context, + * but can be generated by the Boundary Basis methods. + * + */ + namespace Penner { namespace Holonomy { diff --git a/include/holonomy/holonomy/core/quality.h b/include/holonomy/holonomy/core/quality.h index aac459b..b9a35b6 100644 --- a/include/holonomy/holonomy/core/quality.h +++ b/include/holonomy/holonomy/core/quality.h @@ -1,5 +1,18 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/core/common.h" +/** + * @brief Methods to compute the quality of triangles in a mesh. + * + */ + namespace Penner { namespace Holonomy { diff --git a/include/holonomy/holonomy/core/viewer.h b/include/holonomy/holonomy/core/viewer.h index 0a7b425..90e4493 100644 --- a/include/holonomy/holonomy/core/viewer.h +++ b/include/holonomy/holonomy/core/viewer.h @@ -1,20 +1,40 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/core/common.h" #include "holonomy/holonomy/marked_penner_cone_metric.h" -#include "optimization/core/viewer.h" +#include "metric/viewer.h" #ifdef ENABLE_VISUALIZATION #include "polyscope/surface_mesh.h" #endif +/** + * @brief Collection of viewers. + * + */ + namespace Penner { namespace Holonomy { -using Optimization::generate_doubled_mesh; -using Optimization::generate_FV_halfedge_data; - +/** + * @brief View a frame field on a mesh. + * + * @param V: mesh vertices + * @param F: mesh faces + * @param frame_field: per-face frame directions + * @param Th_hat: target cone angles at vertices + * @param mesh_handle: (optional) name for the surface mesh in the viewer + * @param scale: (optional) glyph scale for displayed frame vectors + */ void view_frame_field( const Eigen::MatrixXd& V, const Eigen::MatrixXi& F, @@ -23,6 +43,7 @@ void view_frame_field( std::string mesh_handle="", Scalar scale=0.005); + /** * @brief View a cross field on a mesh. * @@ -43,12 +64,31 @@ void view_cross_field( const Eigen::MatrixXi& period_jump, std::string mesh_handle = "intrinsic_field_mesh"); +/** + * @brief View a vector field on a mesh. + * + * @param V: mesh vertices + * @param F: mesh faces + * @param vector_field: per-face tangent vectors to display + * @param mesh_handle: (optional) name for the surface mesh in the viewer + */ void view_vector_field( const Eigen::MatrixXd& V, const Eigen::MatrixXi& F, const Eigen::MatrixXd& vector_field, std::string mesh_handle=""); +/** + * @brief View a rotation form on a mesh as a per-edge colormap. + * + * @param m: underlying mesh + * @param vtx_reindex: map from mesh vertex indices to original vertex indices + * @param V: mesh vertices + * @param rotation_form: per-halfedge rotation angles + * @param Th_hat: target cone angles at vertices + * @param mesh_handle: (optional) name for the surface mesh in the viewer + * @param show: (optional) if true, open the viewer + */ void view_rotation_form( const Mesh& m, const std::vector& vtx_reindex, @@ -58,6 +98,15 @@ void view_rotation_form( std::string mesh_handle="", bool show=true); +/** + * @brief View the holonomy constraint error of a cone metric as a per-vertex colormap. + * + * @param marked_metric: marked Penner cone metric with holonomy constraints + * @param vtx_reindex: map from mesh vertex indices to original vertex indices + * @param V: mesh vertices + * @param mesh_handle: (optional) name for the surface mesh in the viewer + * @param show: (optional) if true, open the viewer + */ void view_constraint_error( const MarkedPennerConeMetric& marked_metric, const std::vector& vtx_reindex, @@ -84,6 +133,16 @@ void view_seamless_parameterization( bool show=true); +/** + * @brief View the homology basis loops of a marked cone metric on a mesh. + * + * @param marked_metric: marked Penner cone metric containing the homology basis + * @param vtx_reindex: map from mesh vertex indices to original vertex indices + * @param V: mesh vertices + * @param num_homology_basis_loops: (optional) number of basis loops to display; -1 shows all + * @param mesh_handle: (optional) name for the surface mesh in the viewer + * @param show: (optional) if true, open the viewer + */ void view_homology_basis( const MarkedPennerConeMetric& marked_metric, const std::vector& vtx_reindex, @@ -92,11 +151,35 @@ void view_homology_basis( std::string mesh_handle="", bool show=true); +/** + * @brief Compute per-edge seamless error metrics for a UV parameterization. + * + * Returns four per-edge vectors measuring how far the parameterization deviates + * from seamlessness across each interior edge. + * + * @param F: mesh faces (vertex indices) + * @param uv: UV vertex positions + * @param F_uv: UV faces (uv vertex indices, parallel to F) + * @return tuple of (translation error, rotation error, period jump error, total error) + */ std::tuple compute_seamless_error( const Eigen::MatrixXi& F, const Eigen::MatrixXd& uv, const Eigen::MatrixXi& F_uv); +/** + * @brief View parameterization quality metrics as per-face colormaps. + * + * Displays distortion measures (e.g., conformal and isometric distortion) to + * assess the quality of a UV parameterization. + * + * @param V: mesh vertices + * @param F: mesh faces + * @param uv: uv vertex positions + * @param FT: uv faces + * @param mesh_handle: (optional) name for the surface mesh in the viewer + * @param show: (optional) if true, open the viewer + */ void view_parameterization_quality( const Eigen::MatrixXd& V, const Eigen::MatrixXi& F, @@ -105,16 +188,48 @@ void view_parameterization_quality( std::string mesh_handle="", bool show=true); +/** + * @brief Compute the per-corner angle error of a UV parameterization. + * + * Measures how much the UV angles deviate from being quantized to multiples + * of Pi/2. + * + * @param F: mesh faces (vertex indices) + * @param uv: UV vertex positions + * @param F_uv: UV faces (uv vertex indices, parallel to F) + * @return per-corner angle errors + */ VectorX compute_angle_error( const Eigen::MatrixXi& F, const Eigen::MatrixXd& uv, const Eigen::MatrixXi& F_uv); +/** + * @brief Compute the Euclidean length of a UV edge. + * + * @param uv_0: first UV coordinate + * @param uv_1: second UV coordinate + * @return length of the segment from uv_0 to uv_1 + */ Scalar compute_uv_length(const Eigen::Vector2d& uv_0, const Eigen::Vector2d& uv_1); +/** + * @brief Compute the cosine of the angle at uv_0 in the triangle (uv_0, uv_1, origin). + * + * @param uv_0: vertex at which the angle is measured + * @param uv_1: opposite vertex + * @return cosine of the angle at uv_0 + */ Scalar uv_cos_angle(const Eigen::Vector2d& uv_0, const Eigen::Vector2d& uv_1); +/** + * @brief Compute the angle at uv_0 in the triangle (uv_0, uv_1, origin). + * + * @param uv_0: vertex at which the angle is measured + * @param uv_1: opposite vertex + * @return angle in radians at uv_0 + */ Scalar uv_angle(const Eigen::Vector2d& uv_0, const Eigen::Vector2d& uv_1); } // namespace Holonomy -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/holonomy/holonomy/field/field.h b/include/holonomy/holonomy/field/field.h deleted file mode 100644 index e61eb71..0000000 --- a/include/holonomy/holonomy/field/field.h +++ /dev/null @@ -1,23 +0,0 @@ - -#pragma once - -#include "holonomy/core/common.h" - -namespace Penner { -namespace Holonomy { - -/** - * @brief Generate a cross field for a mesh - * - * @param V: mesh vertices - * @param F: mesh faces - * @return |F|x3 frame field of per-face field direction vectors - * @return per-vertex cone angles corresponding to the frame field - */ -std::tuple> generate_cross_field( - const Eigen::MatrixXd& V, - const Eigen::MatrixXi& F); - - -} // namespace Holonomy -} // namespace Penner \ No newline at end of file diff --git a/include/holonomy/holonomy/holonomy/cones.h b/include/holonomy/holonomy/holonomy/cones.h index a07bd18..1f650ff 100644 --- a/include/holonomy/holonomy/holonomy/cones.h +++ b/include/holonomy/holonomy/holonomy/cones.h @@ -1,8 +1,22 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/core/common.h" #include "holonomy/holonomy/marked_penner_cone_metric.h" +/** + * @brief Methods to compute cones on a surface from field data, as well as various + * queries and methods to modify invalid or challenging cone configurations. + * + */ + namespace Penner { namespace Holonomy { @@ -80,4 +94,4 @@ std::pair count_cones(const Mesh& m); bool is_interior(const Mesh& m, int vi); } // namespace Holonomy -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/holonomy/holonomy/holonomy/constraint.h b/include/holonomy/holonomy/holonomy/constraint.h index 8ad11fe..6224012 100644 --- a/include/holonomy/holonomy/holonomy/constraint.h +++ b/include/holonomy/holonomy/holonomy/constraint.h @@ -1,24 +1,64 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/core/common.h" #include "holonomy/holonomy/marked_penner_cone_metric.h" +/** + * @brief Holonomy signature constraints, including vertex cone angles and dual loop angle constraints. + * Also includes methods to compute the constraint Jacobians, which are needed for first-order methods. + * + */ + namespace Penner { namespace Holonomy { /** - * @brief Compute dual loop holonomy angles for a mesh with given angles + * @brief * * @param[in] m: mesh topology * @param[in] homology_basis_loops: dual loops for holonomy angle computation * @param[in] alpha: per-halfedge angles for the mesh * @return vector of dual loop holonomy angles */ -VectorX -Kappa(const Mesh& m, const std::vector>& homology_basis_loops, const VectorX& alpha); +VectorX Kappa(const Mesh& m, const std::vector>& homology_basis_loops, const VectorX& alpha); VectorX Kappa(const MarkedPennerConeMetric& marked_metric, const VectorX& alpha); +/** + * @brief Given a list of dual loops, compute a matrix with columns given by the corresponding + * closed one forms for the dual loops. + * + * @param m: mesh + * @param dual_loops: loops defining the one forms + * @return matrix of dual loop one forms + */ +MatrixX build_dual_loop_basis_one_form_matrix( + const Mesh& m, + const std::vector>& dual_loops); + +/** + * @brief Given a mesh and a homology basis, compute a matrix for the space of closed one forms + * with the first |V| (or |V| - 1) columns corresponding to vertex hat function derivatives and the + * last 2g corresponding to the homology basis loops. + * + * @param m: mesh + * @param homology_basis_loops: homology basis loops for the mesh + * @param eliminate_vertex: remove the last vertex of the mesh so that the matrix is full rank + * @return matrix with basis forms as columns + */ +MatrixX build_closed_one_form_matrix( + const Mesh& m, + const std::vector>& homology_basis_loops, + bool eliminate_vertex = false); + /** * @brief Compute vertex cone holonomy constraints * diff --git a/include/holonomy/holonomy/holonomy/holonomy.h b/include/holonomy/holonomy/holonomy/holonomy.h index d7ce7e5..5163a38 100644 --- a/include/holonomy/holonomy/holonomy/holonomy.h +++ b/include/holonomy/holonomy/holonomy/holonomy.h @@ -1,8 +1,22 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/core/common.h" #include "holonomy/holonomy/marked_penner_cone_metric.h" +/** + * @brief Methods to compute the holonomy of dual loops on a surface with metric data, + * as well as the rotation of a field under the dual loop. + * + */ + namespace Penner { namespace Holonomy { diff --git a/include/holonomy/holonomy/holonomy/marked_penner_cone_metric.h b/include/holonomy/holonomy/holonomy/marked_penner_cone_metric.h index 8cafc58..08518ee 100644 --- a/include/holonomy/holonomy/holonomy/marked_penner_cone_metric.h +++ b/include/holonomy/holonomy/holonomy/marked_penner_cone_metric.h @@ -1,10 +1,25 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/core/common.h" #include "holonomy/core/dual_loop.h" #include "holonomy/core/homology_basis.h" -#include "optimization/core/cone_metric.h" +#include "metric/cone_metric.h" + +/** + * @brief Extension of the differentiable cone metric using Penner coordinates + * to include dual loop holonomy constraints, which allow for full seamless metric + * constraints. + * + */ namespace Penner { namespace Holonomy { @@ -23,7 +38,7 @@ bool is_valid_mesh(const Mesh& m); /** * @brief Class to represent a mesh with a Penner metric and homology basis markings */ -class MarkedPennerConeMetric : public Optimization::PennerConeMetric +class MarkedPennerConeMetric : public PennerConeMetric { public: // Additional constraints for homology loops @@ -132,7 +147,7 @@ class MarkedPennerConeMetric : public Optimization::PennerConeMetric // TODO Use Newton virtual std::unique_ptr project_to_constraint( SolveStats& solve_stats, - std::shared_ptr proj_params = + std::shared_ptr proj_params = nullptr) const override; // Flip method diff --git a/include/holonomy/holonomy/holonomy/newton.h b/include/holonomy/holonomy/holonomy/newton.h index 6e1074a..54bb61e 100644 --- a/include/holonomy/holonomy/holonomy/newton.h +++ b/include/holonomy/holonomy/holonomy/newton.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/core/common.h" @@ -7,6 +15,12 @@ #include +/** + * @brief Modified Newton method to find a Marked Penner Cone Metric satisfying holonomy + * signature constraints. + * + */ + namespace Penner { namespace Holonomy { diff --git a/include/holonomy/holonomy/holonomy/rotation_form.h b/include/holonomy/holonomy/holonomy/rotation_form.h index a026190..621cb13 100644 --- a/include/holonomy/holonomy/holonomy/rotation_form.h +++ b/include/holonomy/holonomy/holonomy/rotation_form.h @@ -1,7 +1,24 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/core/common.h" -#include "holonomy/field/intrinsic_field.h" +#include "field/intrinsic_field.h" + +/** + * @brief Methods to compute a rotation form, either from an existing field or generated + * using a cross-field optimization method. + * + * The rotation form is a minimal representation of a cross field (up to global phase), + * encoding the rotation of the field across edges. + * + */ namespace Penner { namespace Holonomy { @@ -23,13 +40,13 @@ VectorX generate_rotation_form_from_cross_field( const Eigen::MatrixXi& F, const Eigen::MatrixXd& frame_field); -VectorX generate_intrinsic_rotation_form(const Mesh& m, const FieldParameters& field_params); +VectorX generate_intrinsic_rotation_form(const Mesh& m, const Field::FieldParameters& field_params); VectorX generate_intrinsic_rotation_form( const Mesh& m, const std::vector& vtx_reindex, const Eigen::MatrixXd& V, - const FieldParameters& field_params); + const Field::FieldParameters& field_params); } // namespace Holonomy } // namespace Penner \ No newline at end of file diff --git a/include/holonomy/holonomy/interface.h b/include/holonomy/holonomy/interface.h index 9005170..5eeed38 100644 --- a/include/holonomy/holonomy/interface.h +++ b/include/holonomy/holonomy/interface.h @@ -1,7 +1,15 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/core/common.h" -#include "holonomy/field/field.h" +#include "field/field.h" #include "holonomy/holonomy/rotation_form.h" #include "holonomy/holonomy/marked_penner_cone_metric.h" #include "holonomy/similarity/similarity_penner_cone_metric.h" @@ -225,14 +233,14 @@ std::vector extend_vtx_reindex( std::tuple> generate_intrinsic_rotation_form( const Eigen::MatrixXd& V, const Eigen::MatrixXi& F, - const FieldParameters& field_params); + const Field::FieldParameters& field_params); std::vector compute_kappa( const Mesh& discrete_metric, const VectorX& rotation_form, const std::vector>& basis_loops); -Optimization::DiscreteMetric generate_discrete_metric(const Mesh& m); +DiscreteMetric generate_discrete_metric(const Mesh& m); } // namespace Holonomy } // namespace Penner \ No newline at end of file diff --git a/include/holonomy/holonomy/pybind.h b/include/holonomy/holonomy/pybind.h index 8b4c71d..19b7eee 100644 --- a/include/holonomy/holonomy/pybind.h +++ b/include/holonomy/holonomy/pybind.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #ifdef PYBIND #ifndef MULTIPRECISION diff --git a/include/holonomy/holonomy/similarity/conformal.h b/include/holonomy/holonomy/similarity/conformal.h index 2227a63..6e9eca7 100644 --- a/include/holonomy/holonomy/similarity/conformal.h +++ b/include/holonomy/holonomy/similarity/conformal.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/core/common.h" diff --git a/include/holonomy/holonomy/similarity/constraint.h b/include/holonomy/holonomy/similarity/constraint.h index a7e4173..3be7a55 100644 --- a/include/holonomy/holonomy/similarity/constraint.h +++ b/include/holonomy/holonomy/similarity/constraint.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once diff --git a/include/holonomy/holonomy/similarity/energy.h b/include/holonomy/holonomy/similarity/energy.h index c1c29f7..126728a 100644 --- a/include/holonomy/holonomy/similarity/energy.h +++ b/include/holonomy/holonomy/similarity/energy.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/core/common.h" diff --git a/include/holonomy/holonomy/similarity/layout.h b/include/holonomy/holonomy/similarity/layout.h index db8e5f6..a29af77 100644 --- a/include/holonomy/holonomy/similarity/layout.h +++ b/include/holonomy/holonomy/similarity/layout.h @@ -1,9 +1,17 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/core/common.h" #include "holonomy/similarity/similarity_penner_cone_metric.h" -#include "optimization/parameterization/interpolation.h" +#include "parametrization/interpolation.h" #include "conformal_ideal_delaunay/OverlayMesh.hh" diff --git a/include/holonomy/holonomy/similarity/similarity_penner_cone_metric.h b/include/holonomy/holonomy/similarity/similarity_penner_cone_metric.h index f729d43..b1bbee9 100644 --- a/include/holonomy/holonomy/similarity/similarity_penner_cone_metric.h +++ b/include/holonomy/holonomy/similarity/similarity_penner_cone_metric.h @@ -1,7 +1,15 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "holonomy/core/common.h" -#include "holonomy/field/forms.h" +#include "field/forms.h" #include "holonomy/holonomy/marked_penner_cone_metric.h" namespace Penner { @@ -52,7 +60,7 @@ class SimilarityPennerConeMetric : public MarkedPennerConeMetric bool only_free_vertices) const override; std::unique_ptr project_to_constraint( SolveStats& solve_stats, - std::shared_ptr proj_params = + std::shared_ptr proj_params = nullptr) const override; // Discrete metric methods @@ -61,12 +69,12 @@ class SimilarityPennerConeMetric : public MarkedPennerConeMetric // One form getters and setters void set_one_form(const VectorX& one_form) { - assert(is_closed_one_form(*this, one_form)); + assert(Field::is_closed_one_form(*this, one_form)); m_one_form = one_form; } void set_one_form_direction(const VectorX& one_form_direction) { - assert(is_closed_one_form(*this, one_form_direction)); + assert(Field::is_closed_one_form(*this, one_form_direction)); m_one_form_direction = one_form_direction; } const VectorX& get_one_form() const { return m_one_form; } @@ -104,4 +112,4 @@ void MakeSimilarityDelaunay( bool Ptolemy = true); } // namespace Holonomy -} // namespace Penner \ No newline at end of file +} // namespace Penner diff --git a/include/optimization/optimization/core/area.h b/include/metric/metric/area.h similarity index 50% rename from include/optimization/optimization/core/area.h rename to include/metric/metric/area.h index 73dd657..03a4e4b 100644 --- a/include/optimization/optimization/core/area.h +++ b/include/metric/metric/area.h @@ -1,40 +1,23 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "optimization/core/common.h" -#include "optimization/core/cone_metric.h" +/** + * @brief Methods to compute the area of triangles from intrinsic lengths, along + * with the derivatives with respect to lengths and log lengths. + * + */ + +#include "metric/common.h" +#include "metric/cone_metric.h" namespace Penner { -namespace Optimization { /// Compute the squared area of the triangle with edge lengths li, lj, lk using /// the numerically stable version of Heron's formula. @@ -91,5 +74,4 @@ VectorX squared_area_length_derivatives(const Mesh& m); /// @return map from halfedges to the derivative of the square of the area of the face containing it VectorX squared_area_log_length_derivatives(const Mesh& m); -} // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/include/metric/metric/common.h b/include/metric/metric/common.h new file mode 100644 index 0000000..4c7814a --- /dev/null +++ b/include/metric/metric/common.h @@ -0,0 +1,54 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once + +/** + * @brief Assorted utility functions. + * + */ + +#include "util/common.h" +#include "metric/globals.h" + +#include +#include + +#include +#include + +namespace Penner { + +// Check if two vectors are component-wise equal, up to a tolerance. +// +/// @param[in] v: first vector to compare +/// @param[in] w: second vector to compare +/// @param[in] eps: tolerance for equality +/// @return true iff ||v - i||_inf < eps +bool vector_equal(VectorX v, VectorX w, Scalar eps = 1e-10); + +/// Check if a matrix contains a nan +/// +/// @param[in] mat: matrix to check +/// @return true iff mat contains a nan +bool matrix_contains_nan(const Eigen::MatrixXd& mat); + +// Compute the sup norm of a vector. +// +/// @param[in] v: vector +/// @return sup norm of v +Scalar sup_norm(const VectorX& v); + +// Compute the sup norm of a matrix. +// +/// @param[in] matrix: matrix +/// @return sup norm of the matrix +Scalar matrix_sup_norm(const MatrixX& matrix); + + +} // namespace Penner \ No newline at end of file diff --git a/include/optimization/optimization/core/cone_metric.h b/include/metric/metric/cone_metric.h similarity index 85% rename from include/optimization/optimization/core/cone_metric.h rename to include/metric/metric/cone_metric.h index e0e50cd..ae1d1d5 100644 --- a/include/optimization/optimization/core/cone_metric.h +++ b/include/metric/metric/cone_metric.h @@ -1,43 +1,28 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include #include "util/embedding.h" -#include "optimization/core/common.h" -#include "optimization/core/flip_matrix_generator.h" +#include "metric/common.h" +#include "metric/flip_matrix_generator.h" + +/** + * @brief Core representation of a differentiable intrinsic metric on an underlying halfedge mesh, with + * support for edge flips and projection to intrinsic metric constraints. + * + * Also includes the basic differentiable metric coordinates: log length coordinates and Penner coordinates. + * + */ namespace Penner { -namespace Optimization { /// Representation of a differentiable intrinsic metric on a mesh with angle constraints at cones. /// @@ -60,6 +45,7 @@ namespace Optimization { /// - Computation of the cone angle constraint error with reduced coordinate Jacobian /// - Compute a new metric satisfying the constraints /// - Compute the change of coordinates flip Jacobian +/// TODO: Check if interface still up to date /// class DifferentiableConeMetric : public Mesh { @@ -358,5 +344,4 @@ class DiscreteMetric : public DifferentiableConeMetric void expand_metric_coordinates(const VectorX& metric_coords); }; -} // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/include/optimization/optimization/core/constraint.h b/include/metric/metric/constraint.h similarity index 63% rename from include/optimization/optimization/core/constraint.h rename to include/metric/metric/constraint.h index dc710ec..6d02a53 100644 --- a/include/optimization/optimization/core/constraint.h +++ b/include/metric/metric/constraint.h @@ -1,40 +1,25 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "optimization/core/common.h" -#include "optimization/core/cone_metric.h" +#include "metric/common.h" +#include "metric/cone_metric.h" + +/** + * @brief Methods to compute triangle inequality and differentiable cone angle constraints. + * + * Also includes cone enumeration, and elimination of redundant or other fixed degrees of + * freedom in the vertex cone angle constraints. + * + */ namespace Penner { -namespace Optimization { /** @@ -136,9 +121,16 @@ Scalar compute_max_constraint(const DifferentiableConeMetric& cone_metric); */ VectorX compute_cone_angles(const DifferentiableConeMetric& cone_metric); +/** + * @brief Method to compute the angles of a triangle with given lengths + * + * @param l12: first edge length + * @param l23: second edge length + * @param l31: third edge length + * @return corner angles at v1, v2, v3 + */ std::array compute_triangle_angles(Scalar l12, Scalar l23, Scalar l31); /// TODO Optionally add halfedge coordinate Jacobians -} // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/include/metric/metric/flip_matrix_generator.h b/include/metric/metric/flip_matrix_generator.h new file mode 100644 index 0000000..d8e4ab7 --- /dev/null +++ b/include/metric/metric/flip_matrix_generator.h @@ -0,0 +1,93 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once + +#include "metric/common.h" + +/** + * @brief Data structure to iteratively compute the change of coordinate matrix for intrinsic flips, e.g., in Penner coordinates. + * + */ + +namespace Penner { + +/// Class for iteratively building the flip change of coordinate matrix +class FlipMatrixGenerator +{ +public: + /// Initialize an identity matrix + /// + /// @param[in] size: dimension of the flip matrix + FlipMatrixGenerator(int size); + + /// Reset the matrix to the identity + void reset(); + + /// Multiply the current matrix by a flip matrix Di for a given edge on the left. + /// + /// The flip matrix is the identity except the row ed, which has the values indicated + /// by the (ed, j, v) specified by matrix indices and scalars + /// + /// @param[in] column_indices: column indices j for row ed of the matrix Di + /// @param[in] values: values v for row ed of the matrix Di + /// @param[in] ed: edge index for the nontrivial row of the matrix Di + void multiply_by_matrix( + const std::array& column_indices, + const std::array& values, + int ed); + + /// Generate a standard sparse representation of the current matrix + /// + /// @return flip matrix + MatrixX build_matrix() const; + +private: + int m_size; + std::vector>> m_list_of_lists; +}; + +/// Class for incrementally building the flip change of coordinate matrix using a standard template +/// library map representation +/// +/// NOTE: Potential alternative representation of the flip matrix generator. +class FlipMapMatrixGenerator +{ +public: + /// Initialize an identity matrix + /// + /// @param[in] size: dimension of the flip matrix + FlipMapMatrixGenerator(int size); + + /// Reset the matrix to the identity + void reset(); + + /// Multiply the current matrix by a flip matrix Di for a given edge on the left. + /// + /// The flip matrix is the identity except the row ed, which has the values indicated + /// by the (ed, j, v) specified by matrix indices and scalars + /// + /// @param[in] column_indices: column indices j for row ed of the matrix Di + /// @param[in] values: values v for row ed of the matrix Di + /// @param[in] ed: edge index for the nontrivial row of the matrix Di + void multiply_by_matrix( + const std::array& column_indices, + const std::array& values, + int ed); + + /// Generate a standard sparse representation of the current matrix + /// + /// @return flip matrix + MatrixX build_matrix() const; + +private: + int m_size; + std::vector> m_list_of_lists; +}; + +} // namespace Penner \ No newline at end of file diff --git a/include/metric/metric/globals.h b/include/metric/metric/globals.h new file mode 100644 index 0000000..71454a8 --- /dev/null +++ b/include/metric/metric/globals.h @@ -0,0 +1,34 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once + +#include "util/common.h" + +namespace Penner { + +// Parameters to pass to the conformal method for projecting to the constraint. +// More detail on these parameters can be found in the documentation for that +// method. +struct ProjectionParameters +{ + int max_itr = 100; // maximum number of iterations + Scalar bound_norm_thres = 1e-10; // line search threshold for dropping the gradient norm bound +#ifdef MULTIPRECISION + Scalar error_eps = 1e-24; // minimum error termination condition +#else + Scalar error_eps = 1e-8; // minimum error termination condition +#endif + bool do_reduction = + true; // reduce the initial line step if the range of coordinate values is large + bool initial_ptolemy = true; // initial_ptolemy: use ptolemy flips for the initial make_delaunay + bool use_edge_flips = true; // use intrinsic edge flips + std::string output_dir = ""; +}; + +} // namespace Penner \ No newline at end of file diff --git a/include/optimization/optimization/core/projection.h b/include/metric/metric/projection.h similarity index 59% rename from include/optimization/optimization/core/projection.h rename to include/metric/metric/projection.h index 8c85353..da5415a 100644 --- a/include/optimization/optimization/core/projection.h +++ b/include/metric/metric/projection.h @@ -1,40 +1,23 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "optimization/core/common.h" -#include "optimization/core/cone_metric.h" +/** + * @brief Methods to project a metric conformally to cone constraints, and to project + * metric coordinate vectors to the tangent space of the constraint submanifold. + * + */ + +#include "metric/common.h" +#include "metric/cone_metric.h" namespace Penner { -namespace Optimization { /// Create matrix mapping vertex scale factors to their corresponding edges. /// @@ -118,5 +101,4 @@ VectorX project_descent_direction( const DifferentiableConeMetric& cone_metric, const VectorX& descent_direction); -} // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/include/metric/metric/reparametrization.h b/include/metric/metric/reparametrization.h new file mode 100644 index 0000000..31778c5 --- /dev/null +++ b/include/metric/metric/reparametrization.h @@ -0,0 +1,51 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once + +#include "metric/common.h" + +/** + * @brief Methods for changing edge and interior barycentric coordinates as determined + * by hyperbolic edge translations. + * + * Translations for mapping between surfaces can be computed using methods in translation.h. + */ + +namespace Penner { + +/// Reparametrize the barycentric coordinates for the equilateral triangle by +/// translating a constant hyperbolic distance along each halfedge. If the sum +/// of translations per triangle is 0, then this corresponds to a projective map +/// over the triangle. +/// +/// @param[in, out] m_o: mesh to reparametrize +/// @param[in] tau: per halfeedge hyperbolic translation distances +template +void bc_reparametrize_eq(OverlayMesh& m_o, const VectorX& tau); + +/// Reparametrize points contained in equilateral reference triangles by +/// translating a constant hyperbolic distance along each halfedge. If the sum +/// of translations per triangle is 0, then this corresponds to a projective map +/// over the triangle. +/// +/// @param[in, out] pts: points to reparameterize +/// @param[in] n: next halfedge array for mesh +/// @param[in] h: face to halfedge array for mesh +/// @param[in] tau: per halfeedge hyperbolic translation distances +template +void reparametrize_equilateral( + std::vector>& pts, + const std::vector& n, + const std::vector& h, + const VectorX& tau); + +#ifdef PYBIND +#endif + +} // namespace Penner \ No newline at end of file diff --git a/include/optimization/optimization/core/shear.h b/include/metric/metric/shear.h similarity index 53% rename from include/optimization/optimization/core/shear.h rename to include/metric/metric/shear.h index eb9248d..dfe7882 100644 --- a/include/optimization/optimization/core/shear.h +++ b/include/metric/metric/shear.h @@ -1,40 +1,26 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "optimization/core/common.h" -#include "optimization/core/cone_metric.h" +#include "metric/common.h" +#include "metric/cone_metric.h" + +/** + * @brief Methods to compute the shear coordinates of a metric from Penner coordinates + * and shear coordinate bases, linearly independent from the conformal scaling space. + * + * Also can compute the change in shear coordinates between two non-conformal metrics, + * which is necessary for computing continuous mappings between arbitrary surfaces. + * + */ namespace Penner { -namespace Optimization { /// Compute the per halfedge logarithmic shear values for the mesh m with /// logarithmic lengths lambdas_he @@ -107,5 +93,4 @@ void compute_shear_basis_coordinates( VectorX& shear_coords, VectorX& scale_factors); -} // namespace Optimization -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/optimization/optimization/core/viewer.h b/include/metric/metric/viewer.h similarity index 72% rename from include/optimization/optimization/core/viewer.h rename to include/metric/metric/viewer.h index 06bc229..f54b7ce 100644 --- a/include/optimization/optimization/core/viewer.h +++ b/include/metric/metric/viewer.h @@ -1,15 +1,37 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "optimization/core/common.h" +#include "metric/common.h" #ifdef ENABLE_VISUALIZATION #include "polyscope/surface_mesh.h" #endif +/** + * @brief Assorted viewers. + * + */ + namespace Penner { -namespace Optimization { +#ifdef ENABLE_VISUALIZATION +extern glm::vec3 BEIGE; +extern glm::vec3 BLACK_BROWN; +extern glm::vec3 TAN; +extern glm::vec3 MUSTARD; +extern glm::vec3 FOREST_GREEN; +extern glm::vec3 TEAL; +extern glm::vec3 DARK_TEAL; +#endif + // TODO Refactor and add some more convenient viewers @@ -145,5 +167,35 @@ VectorX compute_corner_angles( const Eigen::MatrixXi& F ); -} // namespace Holonomy +/// View the triangles in the mesh with inverted elements. +/// +/// @param[in] V: mesh vertices +/// @param[in] F: mesh faces +/// @param[in] uv: mesh uv vertices +/// @param[in] F_uv: mesh uv faces +void +view_flipped_triangles( + const Eigen::MatrixXd& V, + const Eigen::MatrixXi& F, + const Eigen::MatrixXd& uv, + const Eigen::MatrixXi& F_uv +); + +/// View a layout for a mesh with uv coordinates assigned per halfedge. +/// +/// @param[in] m: mesh +/// @param[in] u_vec: per-halfedge u coordinates +/// @param[in] v_vec: per-halfedge v coordinates +void +view_halfedge_mesh_layout( + const Mesh& m, + const std::vector& u_vec, + const std::vector& v_vec +); +void view_halfedge_mesh_layout( + const std::vector& next, + const std::vector& f2h, + const std::vector& u_vec, + const std::vector& v_vec); + } // namespace Penner \ No newline at end of file diff --git a/include/optimization/optimization/core/common.h b/include/optimization/optimization/core/common.h deleted file mode 100644 index 095502e..0000000 --- a/include/optimization/optimization/core/common.h +++ /dev/null @@ -1,73 +0,0 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#pragma once - -#include "util/common.h" -#include "optimization/core/globals.h" - -#include -#include - -#include -#include - -namespace Penner { -namespace Optimization { - -// Check if two vectors are component-wise equal, up to a tolerance. -// -/// @param[in] v: first vector to compare -/// @param[in] w: second vector to compare -/// @param[in] eps: tolerance for equality -/// @return true iff ||v - i||_inf < eps -bool vector_equal(VectorX v, VectorX w, Scalar eps = 1e-10); - -/// Check if a matrix contains a nan -/// -/// @param[in] mat: matrix to check -/// @return true iff mat contains a nan -bool matrix_contains_nan(const Eigen::MatrixXd& mat); - -// Compute the sup norm of a vector. -// -/// @param[in] v: vector -/// @return sup norm of v -Scalar sup_norm(const VectorX& v); - -// Compute the sup norm of a matrix. -// -/// @param[in] matrix: matrix -/// @return sup norm of the matrix -Scalar matrix_sup_norm(const MatrixX& matrix); - - -} // namespace Optimization -} // namespace Penner \ No newline at end of file diff --git a/include/optimization/optimization/core/flip_matrix_generator.h b/include/optimization/optimization/core/flip_matrix_generator.h deleted file mode 100644 index 458686c..0000000 --- a/include/optimization/optimization/core/flip_matrix_generator.h +++ /dev/null @@ -1,112 +0,0 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#pragma once - -#include "optimization/core/common.h" - -namespace Penner { -namespace Optimization { - -/// Class for incrementally building the flip change of coordinate matrix -class FlipMatrixGenerator -{ -public: - /// Initialize an identity matrix - /// - /// @param[in] size: dimension of the flip matrix - FlipMatrixGenerator(int size); - - /// Reset the matrix to the identity - void reset(); - - /// Multiply the current matrix by a flip matrix Di for a given edge on the left. - /// - /// The flip matrix is the identity except the row ed, which has the values indicated - /// by the (ed, j, v) specified by matrix indices and scalars - /// - /// @param[in] column_indices: column indices j for row ed of the matrix Di - /// @param[in] values: values v for row ed of the matrix Di - /// @param[in] ed: edge index for the nontrivial row of the matrix Di - void multiply_by_matrix( - const std::array& column_indices, - const std::array& values, - int ed); - - /// Generate a standard sparse representation of the current matrix - /// - /// @return flip matrix - MatrixX build_matrix() const; - -private: - int m_size; - std::vector>> m_list_of_lists; -}; - -/// Class for incrementally building the flip change of coordinate matrix using a standard template -/// library map representation -/// -/// NOTE: Potential alternative representation of the flip matrix generator. -class FlipMapMatrixGenerator -{ -public: - /// Initialize an identity matrix - /// - /// @param[in] size: dimension of the flip matrix - FlipMapMatrixGenerator(int size); - - /// Reset the matrix to the identity - void reset(); - - /// Multiply the current matrix by a flip matrix Di for a given edge on the left. - /// - /// The flip matrix is the identity except the row ed, which has the values indicated - /// by the (ed, j, v) specified by matrix indices and scalars - /// - /// @param[in] column_indices: column indices j for row ed of the matrix Di - /// @param[in] values: values v for row ed of the matrix Di - /// @param[in] ed: edge index for the nontrivial row of the matrix Di - void multiply_by_matrix( - const std::array& column_indices, - const std::array& values, - int ed); - - /// Generate a standard sparse representation of the current matrix - /// - /// @return flip matrix - MatrixX build_matrix() const; - -private: - int m_size; - std::vector> m_list_of_lists; -}; - -} // namespace Optimization -} // namespace Penner \ No newline at end of file diff --git a/include/optimization/optimization/core/globals.h b/include/optimization/optimization/core/globals.h deleted file mode 100644 index bf9020e..0000000 --- a/include/optimization/optimization/core/globals.h +++ /dev/null @@ -1,96 +0,0 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#pragma once - -#include "util/common.h" - -namespace Penner { -namespace Optimization { - -/// Energies available for optimization -enum class EnergyChoice { - log_length, // 2-norm of the metric coordinates - log_scale, // scaling energy of best fit scale factors - quadratic_sym_dirichlet, // quadratic approximation to symmetric Dirichlet - sym_dirichlet, // symmetric Dirichlet - p_norm // 4-norm of the metric coordinates -}; - -// Parameters to pass to the conformal method for projecting to the constraint. -// More detail on these parameters can be found in the documentation for that -// method. -struct ProjectionParameters -{ - int max_itr = 100; // maximum number of iterations - Scalar bound_norm_thres = 1e-10; // line search threshold for dropping the gradient norm bound -#ifdef MULTIPRECISION - Scalar error_eps = 1e-24; // minimum error termination condition -#else - Scalar error_eps = 1e-8; // minimum error termination condition -#endif - bool do_reduction = - true; // reduce the initial line step if the range of coordinate values is large - bool initial_ptolemy = true; // initial_ptolemy: use ptolemy flips for the initial make_delaunay - bool use_edge_flips = true; // use intrinsic edge flips - std::string output_dir = ""; -}; - -// Parameters for the optimization method -struct OptimizationParameters -{ - // Logging - std::string output_dir = ""; // output directory for file logs - bool use_checkpoints = false; // if true, checkpoint state to output directory - - // Convergence parameters - Scalar min_ratio = - 0.0; // minimum ratio of projected to ambient descent direction for convergence - int num_iter = 200; // maximum number of iterations - - // Line step choice parameters - bool require_energy_decr = true; // if true, require energy to decrease in each iteration - bool require_gradient_proj_negative = true; // if true, require projection of the gradient onto - // the descent direction to remain negative - Scalar max_angle_incr = INF; // maximum allowed angle error increase in line step - Scalar max_energy_incr = 1e-8; // maximum allowed energy increase in iteration - - // Optimization method choices - std::string direction_choice = "projected_gradient"; // choice of direction - - // Numerical stability parameters - Scalar beta_0 = 1.0; // initial line step size to try - Scalar max_beta = 1e16; // maximum allowed line step size - Scalar max_grad_range = 10; // maximum allowed gradient range (reduce if larger) - Scalar max_angle = INF; // maximum allowed cone angle error (reduce if larger) -}; - -} // namespace Optimization -} // namespace Penner \ No newline at end of file diff --git a/include/optimization/optimization/core/reparametrization.h b/include/optimization/optimization/core/reparametrization.h deleted file mode 100644 index 949c91a..0000000 --- a/include/optimization/optimization/core/reparametrization.h +++ /dev/null @@ -1,68 +0,0 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#pragma once - -#include "optimization/core/common.h" - -namespace Penner { -namespace Optimization { - -/// Reparametrize the barycentric coordinates for the equilateral triangle by -/// translating a constant hyperbolic distance along each halfedge. If the sum -/// of translations per triangle is 0, then this corresponds to a projective map -/// over the triangle. -/// -/// @param[in, out] m_o: mesh to reparametrize -/// @param[in] tau: per halfeedge hyperbolic translation distances -template -void bc_reparametrize_eq(OverlayMesh& m_o, const VectorX& tau); - -/// Reparametrize points contained in equilateral reference triangles by -/// translating a constant hyperbolic distance along each halfedge. If the sum -/// of translations per triangle is 0, then this corresponds to a projective map -/// over the triangle. -/// -/// @param[in, out] pts: points to reparameterize -/// @param[in] n: next halfedge array for mesh -/// @param[in] h: face to halfedge array for mesh -/// @param[in] tau: per halfeedge hyperbolic translation distances -template -void reparametrize_equilateral( - std::vector>& pts, - const std::vector& n, - const std::vector& h, - const VectorX& tau); - -#ifdef PYBIND -#endif - -} // namespace Optimization -} // namespace Penner diff --git a/include/optimization/optimization/interface.h b/include/optimization/optimization/interface.h index 6971fe7..11edacc 100644 --- a/include/optimization/optimization/interface.h +++ b/include/optimization/optimization/interface.h @@ -1,36 +1,14 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "optimization/core/common.h" -#include "optimization/core/cone_metric.h" +#include "metric/common.h" +#include "metric/cone_metric.h" #include "optimization/metric_optimization/energy_functor.h" namespace Penner { @@ -80,91 +58,5 @@ std::unique_ptr generate_energy( /// @return: corrected angles std::vector correct_cone_angles(const std::vector& initial_cone_angles); -/// Write an obj file with uv coordinates. -/// -/// @param[in] filename: obj output file location -/// @param[in] V: mesh vertices -/// @param[in] F: mesh faces -/// @param[in] uv: mesh uv corner coordinates -/// @param[in] F_uv: mesh uv faces -void write_obj_with_uv( - const std::string& filename, - const Eigen::MatrixXd& V, - const Eigen::MatrixXi& F, - const Eigen::MatrixXd& uv, - const Eigen::MatrixXi& F_uv); - -/// Given a mesh with initial target and final optimized metric coordinates, generate a corresponding -/// overlay VF mesh with parametrization. -/// -/// @param[in] V: initial mesh vertices -/// @param[in] F: initial mesh faces -/// @param[in] Th_hat: initial target angles -/// @param[in] m: mesh -/// @param[in] vtx_reindex: map from old to new vertices -/// @param[in] reduced_metric_target: initial mesh Penner coordinates -/// @param[in] reduced_metric_coords: optimized mesh metric -/// @param[in] do_best_fit_scaling: if true, extract best fit scale factors from the metric -/// @return parametrized VF mesh with cut and topology mapping information -std:: - tuple< - OverlayMesh, // m_o - Eigen::MatrixXd, // V_o - Eigen::MatrixXi, // F_o - Eigen::MatrixXd, // uv_o - Eigen::MatrixXi, // FT_o - std::vector, // is_cut_h - std::vector, // is_cut_o - std::vector, // Fn_to_F - std::vector> // endpoints_o - > - generate_VF_mesh_from_metric( - const Eigen::MatrixXd& V, - const Eigen::MatrixXi& F, - const std::vector& Th_hat, - const DifferentiableConeMetric& initial_cone_metric, - const VectorX& reduced_metric_coords, - std::vector is_cut = {}, - bool do_best_fit_scaling = false); - -template -std:: - tuple< - OverlayMesh, // m_o - Eigen::MatrixXd, // V_o - Eigen::MatrixXi, // F_o - Eigen::MatrixXd, // uv_o - Eigen::MatrixXi, // FT_o - std::vector, // is_cut_h - std::vector, // is_cut_o - std::vector, // Fn_to_F - std::vector> // endpoints_o - > - generate_VF_mesh_from_halfedge_metric( - const Eigen::MatrixXd& V, - const Mesh& m, - const std::vector& vtx_reindex, - const DifferentiableConeMetric& initial_cone_metric, - const VectorX& reduced_metric_coords, - std::vector cut_h, - bool do_best_fit_scaling, - bool use_uniform_bc=false, - std::string layout_output_path=""); - -std:: - tuple< - Eigen::MatrixXd, // V_o - Eigen::MatrixXi, // F_o - Eigen::MatrixXd, // uv_o - Eigen::MatrixXi, // FT_o - std::vector // is_cut_h - > - generate_VF_mesh_from_discrete_metric( - const Eigen::MatrixXd& V, - const Eigen::MatrixXi& F, - const std::vector& Th_hat, - const VectorX& reduced_log_edge_lengths, - std::vector cut_h = {}); - } // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/include/optimization/optimization/metric_optimization/convergence.h b/include/optimization/optimization/metric_optimization/convergence.h index 55112df..35a2b79 100644 --- a/include/optimization/optimization/metric_optimization/convergence.h +++ b/include/optimization/optimization/metric_optimization/convergence.h @@ -1,42 +1,23 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "optimization/core/common.h" -#include "optimization/core/cone_metric.h" +#include "metric/common.h" +#include "metric/cone_metric.h" #include "util/embedding.h" #include "optimization/metric_optimization/energy_functor.h" +#include "optimization/metric_optimization/implicit_optimization.h" /// @file Methods to analyze the convergence of a metric to a global minimum on the /// constraint surface. +/// +/// TODO: Move elsewhre namespace Penner { namespace Optimization { diff --git a/include/optimization/optimization/metric_optimization/energies.h b/include/optimization/optimization/metric_optimization/energies.h index c4166a8..a3d9392 100644 --- a/include/optimization/optimization/metric_optimization/energies.h +++ b/include/optimization/optimization/metric_optimization/energies.h @@ -1,44 +1,30 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "optimization/core/common.h" -#include "optimization/core/cone_metric.h" +#include "metric/common.h" +#include "metric/cone_metric.h" #include "conformal_ideal_delaunay/OverlayMesh.hh" #include "util/embedding.h" -/// \file energies.h -/// -/// Differentiable per face energy functions with gradients for the metric -/// optimization for both halfedge and VF representations +/** \file energies.h + * + * Differentiable per-face energy functions with gradients for metric + * optimization for both halfedge and VF representations + * + * Energies include: + * - Metric distortion: (sigma_1 - 1)^2 + (sigma_2 - 1)^2, + * - Area distortion: (sigma_1 * sigma_2 - 1)^2 + * - Symmetric Dirichlet: sigma_1^2 + sigma_2^2 + sigma_1^(-2) + sigma_2^(-2), + * - Surface Hencky Strain: a quadratic approximation of symmetric Dirichlet + */ + namespace Penner { namespace Optimization { diff --git a/include/optimization/optimization/metric_optimization/energy_functor.h b/include/optimization/optimization/metric_optimization/energy_functor.h index 084c939..a052c8b 100644 --- a/include/optimization/optimization/metric_optimization/energy_functor.h +++ b/include/optimization/optimization/metric_optimization/energy_functor.h @@ -1,44 +1,44 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "util/embedding.h" #include "util/linear_algebra.h" -#include "optimization/core/common.h" -#include "optimization/core/cone_metric.h" +#include "metric/common.h" +#include "metric/cone_metric.h" #include "conformal_ideal_delaunay/OverlayMesh.hh" + +/** + * @brief Class for differentiable distortion measures supporting evaluation, gradients, and Hessians + * + * Energies include: + * - Log length: ||l - l0||_2^2 + * - Log Scale: ||u||_2^2, with u the best fit conformal scale factors + * - Symmetric Dirichlet + * - Quadratic Symmetric Dirichlet Approximation + * - Regularized Quadratic Sym. Dir. Approx. + * + */ + namespace Penner { namespace Optimization { +/// Energies available for optimization +enum class EnergyChoice { + log_length, // 2-norm of the metric coordinates + log_scale, // scaling energy of best fit scale factors + quadratic_sym_dirichlet, // quadratic approximation to symmetric Dirichlet + sym_dirichlet, // symmetric Dirichlet + p_norm // 4-norm of the metric coordinates +}; + /// Functor to compute a differentiable energy over a mesh with an intrinsic /// metric in terms of log edge or Penner coordinates. /// diff --git a/include/optimization/optimization/metric_optimization/energy_weights.h b/include/optimization/optimization/metric_optimization/energy_weights.h index 0a87af4..a290164 100644 --- a/include/optimization/optimization/metric_optimization/energy_weights.h +++ b/include/optimization/optimization/metric_optimization/energy_weights.h @@ -1,43 +1,21 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "optimization/core/common.h" -#include "optimization/core/cone_metric.h" +#include "metric/common.h" +#include "metric/cone_metric.h" #include "conformal_ideal_delaunay/OverlayMesh.hh" #include "util/embedding.h" /// \file energy_functor.h /// -/// Methods to weight energies, e.g., per element energies by element area weights +/// Methods to scale per-element values by element weights namespace Penner { namespace Optimization { diff --git a/include/optimization/optimization/metric_optimization/explicit_optimization.h b/include/optimization/optimization/metric_optimization/explicit_optimization.h index 8cdfdbc..6ab23eb 100644 --- a/include/optimization/optimization/metric_optimization/explicit_optimization.h +++ b/include/optimization/optimization/metric_optimization/explicit_optimization.h @@ -1,42 +1,23 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include -#include "optimization/core/common.h" +#include "metric/common.h" #include "util/embedding.h" #include "optimization/metric_optimization/energy_functor.h" +#include "optimization/metric_optimization/implicit_optimization.h" -/// @file Methods to optimize a metric satisfying angle constraints using an explicit -/// representation of the constraint manifold as a graph over a linear subspace of the +/// @file Methods to optimize a metric with angle constraints using an explicit basis complimentary +/// to the conformal scaling space. +/// +/// Represents the constraint manifold as a graph over a linear subspace of the /// space of Penner coordinates. The domain of this space has |E| - |V| + d degrees of /// freedom, where d > 0 is the number of vertices with free angles in the mesh. diff --git a/include/optimization/optimization/metric_optimization/implicit_optimization.h b/include/optimization/optimization/metric_optimization/implicit_optimization.h index f688f25..628e703 100644 --- a/include/optimization/optimization/metric_optimization/implicit_optimization.h +++ b/include/optimization/optimization/metric_optimization/implicit_optimization.h @@ -1,44 +1,62 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include -#include "optimization/core/common.h" -#include "optimization/core/cone_metric.h" +#include "metric/common.h" +#include "metric/cone_metric.h" #include "conformal_ideal_delaunay/OverlayMesh.hh" #include "util/embedding.h" #include "optimization/metric_optimization/energy_functor.h" +/** + * @brief Method to optimize distortion with constraints using a walk-on-manifold approach in the + * full space of metric coordinates using projection. + * + * The constraints are determined by the Differentiable Cone Metric, as well as the method of projecting + * to its constraint submanifold and projecting distortion descent directions. This is more general than + * the explicit optimization methods, which assume the existence of a conformal basis for solving angle + * constraints. + * + */ + namespace Penner { namespace Optimization { + +// Parameters for the optimization method +struct OptimizationParameters +{ + // Logging + std::string output_dir = ""; // output directory for file logs + bool use_checkpoints = false; // if true, checkpoint state to output directory + + // Convergence parameters + Scalar min_ratio = + 0.0; // minimum ratio of projected to ambient descent direction for convergence + int num_iter = 200; // maximum number of iterations + + // Line step choice parameters + bool require_energy_decr = true; // if true, require energy to decrease in each iteration + bool require_gradient_proj_negative = true; // if true, require projection of the gradient onto + // the descent direction to remain negative + Scalar max_angle_incr = INF; // maximum allowed angle error increase in line step + Scalar max_energy_incr = 1e-8; // maximum allowed energy increase in iteration + + // Optimization method choices + std::string direction_choice = "projected_gradient"; // choice of direction + + // Numerical stability parameters + Scalar beta_0 = 1.0; // initial line step size to try + Scalar max_beta = 1e16; // maximum allowed line step size + Scalar max_grad_range = 10; // maximum allowed gradient range (reduce if larger) + Scalar max_angle = INF; // maximum allowed cone angle error (reduce if larger) +}; // Log for implicit optimization iteration values struct OptimizationLog diff --git a/include/optimization/optimization/metric_optimization/nonlinear_optimization.h b/include/optimization/optimization/metric_optimization/nonlinear_optimization.h index efc240f..a721867 100644 --- a/include/optimization/optimization/metric_optimization/nonlinear_optimization.h +++ b/include/optimization/optimization/metric_optimization/nonlinear_optimization.h @@ -1,40 +1,19 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include -#include "optimization/core/common.h" +#include "metric/common.h" /// @file Methods to perform advanced nonlinear optimization, including conjugate gradient /// and L-BFGS-B, using the current gradient, previous gradient, and previous descent direction. +/// /// These methods are intended to be general enough to apply to both implicit projected gradient /// descent and unconstrained gradient descent. diff --git a/include/optimization/optimization/parameterization/translation.h b/include/optimization/optimization/parameterization/translation.h deleted file mode 100644 index 2ede8af..0000000 --- a/include/optimization/optimization/parameterization/translation.h +++ /dev/null @@ -1,58 +0,0 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#pragma once - -#include "optimization/core/common.h" - -namespace Penner { -namespace Optimization { - -/// Generate the least squares solution to the halfedge translations in the -/// hyperbolic metric needed to satisfy the per halfedge shear change and face -/// zero sum condition. -/// -/// The zero sum face condition is necessary to extend the edge translations -/// to a projective transformation on the entire face. -/// -/// @param[in] m: mesh -/// @param[in] he_metric_coords: metric coordinates for m -/// @param[in] he_metric_target: target metric coordinates for m -/// @param[out] he_translations: per halfedge translations -template -bool compute_as_symmetric_as_possible_translations( - const Mesh& m, - const VectorX& he_metric_coords, - const VectorX& he_metric_target, - VectorX& he_translations); -// TODO: Add option to bypass and use zero translations or to solve in double precision - -} // namespace Optimization -} // namespace Penner diff --git a/include/optimization/optimization/pybind.h b/include/optimization/optimization/pybind.h index 6554074..3db28f1 100644 --- a/include/optimization/optimization/pybind.h +++ b/include/optimization/optimization/pybind.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #ifdef PYBIND #ifndef MULTIPRECISION @@ -16,4 +24,4 @@ void init_optimization_pybind(pybind11::module& m); } // namespace Penner #endif -#endif +#endif \ No newline at end of file diff --git a/include/optimization/optimization/util/shapes.h b/include/optimization/optimization/util/shapes.h index c1796d5..8f1f69f 100644 --- a/include/optimization/optimization/util/shapes.h +++ b/include/optimization/optimization/util/shapes.h @@ -1,36 +1,14 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "optimization/core/common.h" +#include "metric/common.h" // Some good simple tests are simplex embeddings that are natural (one vertex // at the origin and others at unit vectors) with metrics that are uniform diff --git a/include/optimization/optimization/util/validation.h b/include/optimization/optimization/util/validation.h index 66e9189..71794d2 100644 --- a/include/optimization/optimization/util/validation.h +++ b/include/optimization/optimization/util/validation.h @@ -1,41 +1,19 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include #include -#include "optimization/core/common.h" +#include "metric/common.h" #include "optimization/metric_optimization/energy_functor.h" -#include "optimization/core/constraint.h" -#include "optimization/core/cone_metric.h" +#include "metric/constraint.h" +#include "metric/cone_metric.h" namespace Penner { namespace Optimization { @@ -185,4 +163,4 @@ validate_constraint( } } } // namespace Optimization -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/optimization/optimization/util/viewers.h b/include/optimization/optimization/util/viewers.h deleted file mode 100644 index 5554dfa..0000000 --- a/include/optimization/optimization/util/viewers.h +++ /dev/null @@ -1,85 +0,0 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#pragma once -#include "optimization/core/common.h" - -/// @file viewers.hh -/// -/// Some simple viewers to be used to analyze and debug the optimization pipeline. - -namespace Penner { -namespace Optimization { - -/// View the triangles in the mesh with inverted elements. -/// -/// @param[in] V: mesh vertices -/// @param[in] F: mesh faces -/// @param[in] uv: mesh uv vertices -/// @param[in] F_uv: mesh uv faces -void -view_flipped_triangles( - const Eigen::MatrixXd& V, - const Eigen::MatrixXi& F, - const Eigen::MatrixXd& uv, - const Eigen::MatrixXi& F_uv -); - -/// View a layout for a mesh with uv coordinates assigned per halfedge. -/// -/// @param[in] m: mesh -/// @param[in] u_vec: per-halfedge u coordinates -/// @param[in] v_vec: per-halfedge v coordinates -void -view_halfedge_mesh_layout( - const Mesh& m, - const std::vector& u_vec, - const std::vector& v_vec -); -void view_halfedge_mesh_layout( - const std::vector& next, - const std::vector& f2h, - const std::vector& u_vec, - const std::vector& v_vec); - -/// View a mesh with parameterization grid -/// -/// @param[in] V: mesh vertices -/// @param[in] F: mesh faces -/// @param[in] uv: mesh uv vertices -/// @param[in] F_uv: mesh uv faces -void view_parameterization( - const Eigen::MatrixXd& V, - const Eigen::MatrixXi& F, - const Eigen::MatrixXd& uv, - const Eigen::MatrixXi& FT); - -} // namespace Optimization -} // namespace Penner \ No newline at end of file diff --git a/include/optimization/optimization/util/visualization.h b/include/optimization/optimization/util/visualization.h index 34d989b..80870a4 100644 --- a/include/optimization/optimization/util/visualization.h +++ b/include/optimization/optimization/util/visualization.h @@ -1,33 +1,11 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include @@ -65,4 +43,4 @@ void save_mesh_screen_capture(Viewer &viewer, } // namespace Optimization -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/optimization/optimization/parameterization/interpolation.h b/include/parametrization/parametrization/interpolation.h similarity index 82% rename from include/optimization/optimization/parameterization/interpolation.h rename to include/parametrization/parametrization/interpolation.h index fa20b1a..2eba946 100644 --- a/include/optimization/optimization/parameterization/interpolation.h +++ b/include/parametrization/parametrization/interpolation.h @@ -1,40 +1,26 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "optimization/core/common.h" +#include "metric/common.h" #include "conformal_ideal_delaunay/OverlayMesh.hh" +/** + * @brief Data structures to compute pointwise maps between two intrinsic metrics. + * + * Includes both forward and backwards mappings between the two surfaces. These data + * structures are primarily used as helpers for computing a traditional uv parameterization, + * but can be used directly for pointwise maps. + * + */ + namespace Penner { -namespace Optimization { /// A mesh structure to perform interpolation of points in a surface. /// @@ -309,5 +295,4 @@ void interpolate_vertex_positions( template bool overlay_has_all_original_halfedges(OverlayMesh& mo); -} // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/include/optimization/optimization/parameterization/layout.h b/include/parametrization/parametrization/layout.h similarity index 68% rename from include/optimization/optimization/parameterization/layout.h rename to include/parametrization/parametrization/layout.h index c0010a3..cd85912 100644 --- a/include/optimization/optimization/parameterization/layout.h +++ b/include/parametrization/parametrization/layout.h @@ -1,40 +1,22 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once -#include "optimization/core/common.h" +#include "metric/common.h" #include "conformal_ideal_delaunay/OverlayMesh.hh" +/** + * @brief Methods to layout a uv parameterization determined by intrinsic lengths. + * + */ + namespace Penner { -namespace Optimization { /// Generate an overlay mesh for the mesh m with given metric coordinates integrated /// as the mesh metric. @@ -187,5 +169,4 @@ std::tuple, std::vector, std::vector> compute_ #endif -} // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/include/parametrization/parametrization/parametrize.h b/include/parametrization/parametrization/parametrize.h new file mode 100644 index 0000000..158a1b1 --- /dev/null +++ b/include/parametrization/parametrization/parametrize.h @@ -0,0 +1,87 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once +#include "metric/common.h" +#include "metric/cone_metric.h" + +namespace Penner { + +/// Given a mesh with initial target and final optimized metric coordinates, generate a corresponding +/// overlay VF mesh with parametrization. +/// +/// @param[in] V: initial mesh vertices +/// @param[in] F: initial mesh faces +/// @param[in] Th_hat: initial target angles +/// @param[in] m: mesh +/// @param[in] vtx_reindex: map from old to new vertices +/// @param[in] reduced_metric_target: initial mesh Penner coordinates +/// @param[in] reduced_metric_coords: optimized mesh metric +/// @param[in] do_best_fit_scaling: if true, extract best fit scale factors from the metric +/// @return parametrized VF mesh with cut and topology mapping information +std:: + tuple< + OverlayMesh, // m_o + Eigen::MatrixXd, // V_o + Eigen::MatrixXi, // F_o + Eigen::MatrixXd, // uv_o + Eigen::MatrixXi, // FT_o + std::vector, // is_cut_h + std::vector, // is_cut_o + std::vector, // Fn_to_F + std::vector> // endpoints_o + > + generate_VF_mesh_from_metric( + const Eigen::MatrixXd& V, + const Eigen::MatrixXi& F, + const std::vector& Th_hat, + const DifferentiableConeMetric& initial_cone_metric, + const VectorX& reduced_metric_coords, + std::vector is_cut = {}, + bool do_best_fit_scaling = false); + +template +std:: + tuple< + OverlayMesh, // m_o + Eigen::MatrixXd, // V_o + Eigen::MatrixXi, // F_o + Eigen::MatrixXd, // uv_o + Eigen::MatrixXi, // FT_o + std::vector, // is_cut_h + std::vector, // is_cut_o + std::vector, // Fn_to_F + std::vector> // endpoints_o + > + generate_VF_mesh_from_halfedge_metric( + const Eigen::MatrixXd& V, + const Mesh& m, + const std::vector& vtx_reindex, + const DifferentiableConeMetric& initial_cone_metric, + const VectorX& reduced_metric_coords, + std::vector cut_h, + bool do_best_fit_scaling, + bool use_uniform_bc=false, + std::string layout_output_path=""); + +std:: + tuple< + Eigen::MatrixXd, // V_o + Eigen::MatrixXi, // F_o + Eigen::MatrixXd, // uv_o + Eigen::MatrixXi, // FT_o + std::vector // is_cut_h + > + generate_VF_mesh_from_discrete_metric( + const Eigen::MatrixXd& V, + const Eigen::MatrixXi& F, + const std::vector& Th_hat, + const VectorX& reduced_log_edge_lengths, + std::vector cut_h = {}); + +} // namespace Penner \ No newline at end of file diff --git a/include/optimization/optimization/parameterization/refinement.h b/include/parametrization/parametrization/refinement.h similarity index 79% rename from include/optimization/optimization/parameterization/refinement.h rename to include/parametrization/parametrization/refinement.h index 831b109..9cf78fc 100644 --- a/include/optimization/optimization/parameterization/refinement.h +++ b/include/parametrization/parametrization/refinement.h @@ -1,35 +1,13 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include -#include "optimization/core/common.h" +#include "metric/common.h" /// @file refinement.h /// @@ -37,7 +15,6 @@ /// to ensure the parametrization does not have inverted elements. namespace Penner { -namespace Optimization { /// A class to represent a mesh that supports an overlay refinement scheme. class RefinementMesh @@ -324,5 +301,4 @@ void build_faces( */ std::vector> build_F_to_Fn(const std::vector& Fn_to_F); -} // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/include/parametrization/parametrization/translation.h b/include/parametrization/parametrization/translation.h new file mode 100644 index 0000000..fb77734 --- /dev/null +++ b/include/parametrization/parametrization/translation.h @@ -0,0 +1,40 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once + +#include "metric/common.h" + +/** + * @brief Method to compute hyperbolic translations determining a continuous map between + * two intrinsic metrics. + * + */ + +namespace Penner { + +/// Generate the least squares solution to the halfedge translations in the +/// hyperbolic metric needed to satisfy the per halfedge shear change and face +/// zero sum condition. +/// +/// The zero sum face condition is necessary to extend the edge translations +/// to a projective transformation on the entire face. +/// +/// @param[in] m: mesh +/// @param[in] he_metric_coords: metric coordinates for m +/// @param[in] he_metric_target: target metric coordinates for m +/// @param[out] he_translations: per halfedge translations +template +bool compute_as_symmetric_as_possible_translations( + const Mesh& m, + const VectorX& he_metric_coords, + const VectorX& he_metric_target, + VectorX& he_translations); +// TODO: Add option to bypass and use zero translations or to solve in double precision + +} // namespace Penner \ No newline at end of file diff --git a/include/optimization/optimization/parameterization/triangulation.h b/include/parametrization/parametrization/triangulation.h similarity index 57% rename from include/optimization/optimization/parameterization/triangulation.h rename to include/parametrization/parametrization/triangulation.h index 4c3d00d..0bb7017 100644 --- a/include/optimization/optimization/parameterization/triangulation.h +++ b/include/parametrization/parametrization/triangulation.h @@ -1,41 +1,26 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#include "optimization/core/common.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "metric/common.h" + +/** + * @brief Methods for triangulating self overlapping polygons in the plane. + * + * Also supports optimization over triangle area for both the planar and spatial + * coordinates of the vertices of the polygon. + * + */ /// @file refinement.hh /// /// Methods to determine if polygons are self-overlapping and triangulate them namespace Penner { -namespace Optimization { /// Given three vertices in the plane, compute the triangle area /// @@ -103,5 +88,4 @@ void triangulate_self_overlapping_polygon( std::vector>& faces); -} // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/include/util/util/boundary.h b/include/util/util/boundary.h index 0c32339..ad07e19 100644 --- a/include/util/util/boundary.h +++ b/include/util/util/boundary.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "util/common.h" @@ -68,4 +76,4 @@ std::vector find_boundary_components(const Mesh& m); */ std::vector build_boundary_component(const Mesh& m, int halfedge_index); -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/util/util/common.h b/include/util/util/common.h index 811642c..d7f4af7 100644 --- a/include/util/util/common.h +++ b/include/util/util/common.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include @@ -104,6 +112,16 @@ inline std::vector arange(size_t n) return vec; } +/** + * @brief Compute the real modulus of x mod y + * + * @param x: positive number to mod + * @param y: positive modulus + * @return x (mod y) + */ +inline +Scalar pos_fmod(Scalar x, Scalar y) { return (0 == y) ? x : x - y * floor(x / y); } + template Mesh change_mesh_type(const Mesh& m) { diff --git a/include/util/util/embedding.h b/include/util/util/embedding.h index df52897..6eec189 100644 --- a/include/util/util/embedding.h +++ b/include/util/util/embedding.h @@ -1,33 +1,11 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "util/common.h" @@ -274,4 +252,4 @@ bool is_valid_symmetry(const Mesh& m); */ std::vector generate_face_map(const Mesh& m); -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/util/util/io.h b/include/util/util/io.h index bf6fb7e..325f55b 100644 --- a/include/util/util/io.h +++ b/include/util/util/io.h @@ -1,33 +1,11 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "util/common.h" @@ -180,6 +158,20 @@ void write_integer_matrix(const Eigen::MatrixXi& matrix, const std::string& file Eigen::MatrixXd read_matrix(const std::string& filename); +/// Write an obj file with uv coordinates. +/// +/// @param[in] filename: obj output file location +/// @param[in] V: mesh vertices +/// @param[in] F: mesh faces +/// @param[in] uv: mesh uv corner coordinates +/// @param[in] F_uv: mesh uv faces +void write_obj_with_uv( + const std::string& filename, + const Eigen::MatrixXd& V, + const Eigen::MatrixXi& F, + const Eigen::MatrixXd& uv, + const Eigen::MatrixXi& F_uv); + void write_hdf5_mesh(const std::string& path, const Eigen::MatrixXd& V, const Eigen::MatrixXi& F); @@ -223,4 +215,4 @@ void write_sparse_matrix( const std::string& filename, std::string format = "csv"); -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/util/util/linear_algebra.h b/include/util/util/linear_algebra.h index 2aee405..97a8abd 100644 --- a/include/util/util/linear_algebra.h +++ b/include/util/util/linear_algebra.h @@ -1,33 +1,11 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "util/common.h" @@ -35,6 +13,56 @@ namespace Penner { +/** + * @brief Compute the dot product of two 3D vectors. + * + * @tparam vector representation of R3 supporting indexing + * @param v1: first vector + * @param v2: second vector + * @return dot product of the two vectors + */ +template +double dot_prod(const VectorType& v1, const VectorType& v2) +{ + return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; +} + +/** + * @brief Compute the cross product of two 3D vectors. + * + * @tparam vector representation of R3 supporting indexing + * @param v1: first vector + * @param v2: second vector + * @return cross product of the two vectors + */ +template +VectorType cross_prod(const VectorType& v1, const VectorType& v2) +{ + return VectorType( + v1[1] * v2[2] - v1[2] * v2[1], + v1[2] * v2[0] - v1[0] * v2[2], + v1[0] * v2[1] - v1[1] * v2[0]); +} + +/** + * @brief Compute the signed angle between two 3D vectors around a normal axis. + * + * @tparam vector representation of R3 supporting indexing + * @param v1: first vector + * @param v2: second vector + * @param normal: normal vector representing the axis of rotation + * @return signed angle between the two vectors around the axis of rotation + */ +template +double signed_angle(const VectorType& v1, const VectorType& v2, const VectorType& normal) +{ + double s = dot_prod(normal, cross_prod(v1, v2)); + double c = dot_prod(v1, v2); + const double angle = (s == 0 && c == 0) ? 0.0 : atan2(s, c); + return angle; +} + + /// Compute the Kronecker product of two vectors. /// /// @param[in] vec_1: first vector to product @@ -143,4 +171,4 @@ Matrix2x2 compute_rotation(Scalar theta); std::vector generate_linspace(Scalar a, Scalar b, int num_steps); -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/util/util/map.h b/include/util/util/map.h index 37f93dc..0a5b099 100644 --- a/include/util/util/map.h +++ b/include/util/util/map.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "util/common.h" @@ -300,4 +308,4 @@ bool are_polygon_mesh_faces_valid( const std::vector& he2f, const std::vector& f2he); -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/util/util/spanning_tree.h b/include/util/util/spanning_tree.h index 4887c89..fb159a0 100644 --- a/include/util/util/spanning_tree.h +++ b/include/util/util/spanning_tree.h @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "util/common.h" diff --git a/include/util/util/vector.h b/include/util/util/vector.h index 2bdf4b7..314d784 100644 --- a/include/util/util/vector.h +++ b/include/util/util/vector.h @@ -1,33 +1,11 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "util/common.h" @@ -519,4 +497,4 @@ std::vector enumerate_boolean_array(const std::vector& boolean_array) std::vector remove_unreferenced_indices(const std::vector& index_vector); -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/include/util/util/vf_mesh.h b/include/util/util/vf_mesh.h index 4acb669..78ac1c4 100644 --- a/include/util/util/vf_mesh.h +++ b/include/util/util/vf_mesh.h @@ -1,33 +1,11 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #pragma once #include "util/common.h" @@ -150,4 +128,19 @@ std::tuple reindex_mesh( const Eigen::MatrixXi& F, const std::vector& vtx_reindex); -} // namespace Penner +/** + * @brief Find the seams of the parameterization of a closed mesh. + * + * TODO: Extend to open meshes + * + * @param F: mesh faces + * @param FT: mesh layout faces + * @return |F|x3 mask of corners opposite seam edges + */ +Eigen::MatrixXi find_seams( + const Eigen::MatrixXi& F, + const Eigen::MatrixXi& FT); + + + +} // namespace Penner \ No newline at end of file diff --git a/py/optimize_impl/energies.py b/py/optimize_impl/energies.py index c5f0673..0313dae 100644 --- a/py/optimize_impl/energies.py +++ b/py/optimize_impl/energies.py @@ -250,6 +250,8 @@ def get_vertex_energy( uv_embed[:,:2] = uv[:,:2] # Get energy + if (colormap == 'none'): + energy = 0.25 * np.ones(len(v)) if (colormap == 'scale_factors'): energy = best_fit_conformal_vf(v, f, uv_embed, fuv) if (colormap == 'sym_dirichlet'): @@ -293,6 +295,8 @@ def get_face_energy( energy = arap_vf(v, f, uv_embed, fuv) if (colormap == 'quadratic_sym_dirichlet'): energy = quadratic_sym_dirichlet_vf(v, f, uv_embed, fuv) + if (colormap == 'none'): + energy = 0.25 * np.ones(len(f)) # Optionally use face weighting if (use_face_weight): diff --git a/scripts/holonomy_overlay.py b/scripts/holonomy_overlay.py index 83d760c..91bae2c 100644 --- a/scripts/holonomy_overlay.py +++ b/scripts/holonomy_overlay.py @@ -1,4 +1,4 @@ -# Script to generate an overlay from a similarity mesh +# Script to generate an overlay from a marked mesh import os, sys script_dir = os.path.dirname(__file__) @@ -27,10 +27,11 @@ def similarity_overlay_one(args, fname): # Skip meshes that are already processed try: uv_mesh_path = os.path.join(output_dir, name + '_refined_with_uv.obj') - V, F = igl.read_triangle_mesh(uv_mesh_path) - if (len(V) > 0): - print("Skipping processed mesh") - return + if os.path.isfile(uv_mesh_path): + V, F = igl.read_triangle_mesh(uv_mesh_path) + if (len(V) > 0): + print("Skipping processed mesh") + return except: pass diff --git a/scripts/holonomy_render.py b/scripts/holonomy_render.py index 1f29566..bb3b916 100644 --- a/scripts/holonomy_render.py +++ b/scripts/holonomy_render.py @@ -42,7 +42,7 @@ def render_uv_one(args, fname): os.makedirs(output_dir, exist_ok=True) # Get logger - log_path = os.path.join(output_dir, name+'_similarity_render.log') + log_path = os.path.join(output_dir, name+'_holonomy_render.log') logger = script_util.get_logger(log_path) logger.info("Rendering {}".format(name)) @@ -64,11 +64,6 @@ def render_uv_one(args, fname): logger.error("Could not load uv coordinates") return - # Cut mesh along along uv lines - #v_cut = script_util.cut_mesh(v3d, f, uv, fuv) - #v3d = v_cut - #f = fuv - # Need to build double mesh when it has boundary is_bd = igl.is_border_vertex(v3d_orig, f_orig) build_double = (np.sum(is_bd) != 0) @@ -99,28 +94,12 @@ def render_uv_one(args, fname): blue_size = 0 # Get cut to singularity edges (or build for double meshes) - use_boundary_edges = True if (args["no_cut"]): v_cut_to_sin = [] f_cut_to_sin = [] logger.info("Skipping cut to singularity") - elif (use_boundary_edges): - v_cut_to_sin, f_cut_to_sin = script_util.get_boundary_edges(v3d, uv, f, fuv, bd_thick) else: - try: - cut_to_sin_list_path = os.path.join(uv_dir, m + "_output", name+"_cut_to_sin_list.pickle") - logger.info("Loading cut_to_sin_list at {}".format(cut_to_sin_list_path)) - with open(cut_to_sin_list_path, 'rb') as fp: - cut_to_sin_list = pickle.load(fp) - except: - logger.error("Could not load cut_to_sin_list") - # FIXME Make independent function - bd_loops = igl.all_boundary_loop(f) - cut_to_sin_list = [] - #for loop in bd_loops: - # for i in np.arange(len(loop) - 1): - # cut_to_sin_list.append([loop[i], loop[i+1]]) - v_cut_to_sin, f_cut_to_sin = penner.get_edges(v3d_orig, f_orig, cut_to_sin_list, bd_thick) + v_cut_to_sin, f_cut_to_sin = script_util.get_boundary_edges(v3d, uv, f, fuv, bd_thick) # Get point matrices logger.info("Getting point matrices") @@ -156,19 +135,11 @@ def render_uv_one(args, fname): # Get colormap for the mesh logger.info('Getting {} colormap'.format(args['colormap'])) - #r = np.full(len(v3d), 0.25) - r = np.full(len(v3d), 0.5) - #colormap = cm.get_cmap('YlOrBr') - #colormap = cm.get_cmap('OrRd') - #colormap = cm.get_cmap('PuRd') + if args['render_color'] == 'blue': + r = 0.25 + 0.0 * np.abs(r) + elif args['render_color'] == 'purple': + r = 0.5 + 0.0 * np.abs(r) colormap = cm.get_cmap('cool') - colormap_scale = args['colormap_scale'] - logger.info('Using colormap scale {}'.format(colormap_scale)) - if (colormap_scale > 0): - norm = colors.CenteredNorm(colormap_scale*0.5, colormap_scale*0.6) - else: - norm = colors.CenteredNorm(0, 1) - r = r * 0 norm = colors.NoNorm() # Render image @@ -218,7 +189,6 @@ def render_uv_one(args, fname): def render_uv_many(args): script_util.run_many(render_uv_one, args) - def add_render_uv_arguments(parser): parser.add_argument( "-o", "--output_dir", @@ -240,20 +210,9 @@ def add_render_uv_arguments(parser): default=1 ) parser.add_argument( - "--colormap", - help="energy for colormap", - default="scale_factors" - ) - parser.add_argument( - "--interpolate_from_original", - help="use interpolated colormap from original values", - action="store_true" - ) - parser.add_argument( - "--colormap_scale", - help="ratio to scale colormap by", - type=float, - default=1 + "--render_color", + help="color for the mesh render", + default="blue" ) parser.add_argument( "--suffix", diff --git a/scripts/optimization_scripts/pipeline.py b/scripts/optimization_scripts/pipeline.py index e25f9f8..bdb38ef 100644 --- a/scripts/optimization_scripts/pipeline.py +++ b/scripts/optimization_scripts/pipeline.py @@ -1,6 +1,6 @@ import os, sys script_dir = os.path.dirname(__file__) -module_dir = os.path.join(script_dir, '..', 'py') +module_dir = os.path.join(script_dir, '..', '..', 'py') sys.path.append(module_dir) import numpy as np @@ -100,4 +100,4 @@ args = script_util.overwrite_args(args_default, args_spec) # Run method - method_func(args) \ No newline at end of file + method_func(args) diff --git a/scripts/optimize_angles.py b/scripts/optimize_angles.py index b23a26b..485f89e 100644 --- a/scripts/optimize_angles.py +++ b/scripts/optimize_angles.py @@ -48,7 +48,7 @@ def constrain_similarity_one(args, fname): if args['fit_field']: logger.info("Fitting cross field") field_params = penner.FieldParameters() - field_params.min_cone = 2 + field_params.min_angle = np.pi rotation_form, Th_hat = penner.generate_intrinsic_rotation_form(V, F, field_params) Th_hat = np.array(Th_hat) else: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a975307..149d634 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,76 @@ -add_subdirectory(util) +set(UtilSrc + util/boundary.cpp + util/common.cpp + util/embedding.cpp + util/io.cpp + util/linear_algebra.cpp + util/map.cpp + util/spanning_tree.cpp + util/vector.cpp + util/vf_mesh.cpp +) + +set(MetricSrc + metric/area.cpp + metric/common.cpp + metric/cone_metric.cpp + metric/constraint.cpp + metric/flip_matrix_generator.cpp + metric/projection.cpp + metric/reparametrization.cpp + metric/shear.cpp + metric/viewer.cpp +) + +set(ParametrizationSrc + parametrization/interpolation.cpp + parametrization/layout.cpp + parametrization/parametrize.cpp + parametrization/refinement.cpp + parametrization/translation.cpp + parametrization/triangulation.cpp +) + +add_library(PennerCoreLib + ${UtilSrc} + ${MetricSrc} + ${ParametrizationSrc} +) +target_include_directories(PennerCoreLib PUBLIC ../include/util) +target_include_directories(PennerCoreLib PUBLIC ../include/metric) +target_include_directories(PennerCoreLib PUBLIC ../include/parametrization) +target_link_libraries(PennerCoreLib PUBLIC + Eigen3::Eigen + igl::core + igl::predicates + spdlog::spdlog + conformal_cpp + HDF5::HDF5 + #CoMISo + ${MPFR_LIBRARIES} + ${SUITESPARSE_LIBS} + ${POLYSCOPE_LIBRARIES} +) +target_compile_features(PennerCoreLib PUBLIC cxx_std_17) + +target_compile_definitions(PennerCoreLib PUBLIC + SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG +) +# TODO Fix for multiprecision +if ((NOT USE_MULTIPRECISION) AND (DEBUG_WARNINGS)) + target_compile_options(PennerCoreLib PRIVATE + -Wall -Wpedantic -Wextra -Werror + ) +endif() + +add_subdirectory(field) add_subdirectory(optimization) add_subdirectory(holonomy) add_subdirectory(feature) add_library(PennerLib INTERFACE) target_link_libraries(PennerLib INTERFACE + PennerFieldLib PennerOptimizationLib PennerHolonomyLib PennerFeatureLib diff --git a/src/feature/core/boundary_path.cpp b/src/feature/core/boundary_path.cpp index 2456c0b..8daefc0 100644 --- a/src/feature/core/boundary_path.cpp +++ b/src/feature/core/boundary_path.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/core/boundary_path.h" #include "util/boundary.h" diff --git a/src/feature/core/common.cpp b/src/feature/core/common.cpp index 660e739..a176847 100644 --- a/src/feature/core/common.cpp +++ b/src/feature/core/common.cpp @@ -1,6 +1,14 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/core/common.h" -#include "holonomy/field/intrinsic_field.h" +#include "field/intrinsic_field.h" #include #include @@ -99,4 +107,4 @@ std::vector> reindex_endpoints( } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/feature/core/component_mesh.cpp b/src/feature/core/component_mesh.cpp index 1c80c6a..822ad5d 100644 --- a/src/feature/core/component_mesh.cpp +++ b/src/feature/core/component_mesh.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/core/component_mesh.h" diff --git a/src/feature/core/io.cpp b/src/feature/core/io.cpp index 14b512a..7ff182f 100644 --- a/src/feature/core/io.cpp +++ b/src/feature/core/io.cpp @@ -1,6 +1,15 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/core/io.h" #include "feature/core/vf_corners.h" +#include "util/vf_mesh.h" #include @@ -149,4 +158,4 @@ void write_boundary( } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/feature/core/quads.cpp b/src/feature/core/quads.cpp index 39dbd82..408ef52 100644 --- a/src/feature/core/quads.cpp +++ b/src/feature/core/quads.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/core/quads.h" #include diff --git a/src/feature/core/union_meshes.cpp b/src/feature/core/union_meshes.cpp index 5215083..d0b6cfe 100644 --- a/src/feature/core/union_meshes.cpp +++ b/src/feature/core/union_meshes.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/core/union_meshes.h" diff --git a/src/feature/core/vf_corners.cpp b/src/feature/core/vf_corners.cpp index f4004e3..43b5992 100644 --- a/src/feature/core/vf_corners.cpp +++ b/src/feature/core/vf_corners.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/core/vf_corners.h" #include @@ -508,39 +516,6 @@ Eigen::MatrixXd transfer_halfedge_function_to_corner( return corner_func; } -Eigen::MatrixXi find_seams( - const Eigen::MatrixXi& F, - const Eigen::MatrixXi& FT) -{ - Eigen::MatrixXi TT; - Eigen::MatrixXi TTi; - igl::triangle_triangle_adjacency(F, TT, TTi); - - int num_faces = F.rows(); - Eigen::MatrixXi F_mask = Eigen::MatrixXi::Zero(num_faces, 3); - for (int f = 0; f < num_faces; ++f) { - // Check if an edge is a cut - for (int k = 0; k < 3; ++k) { - int i = (k + 1) % 3; - int j = (i + 1) % 3; - int f_opp = TT(f, i); - if (F(f, j) != F(f_opp, TTi(f, i))) - spdlog::error("Incorrect 1"); - if (F(f, i) != F(f_opp, (TTi(f, i) + 1) % 3)) - spdlog::error("Incorrect 2"); - int uvi = FT(f, i); - int uvj = FT(f, j); - int uvi_opp = FT(f_opp, (TTi(f, i) + 1) % 3); - int uvj_opp = FT(f_opp, TTi(f, i)); - if ((uvi != uvi_opp) || (uvj != uvj_opp)) { - F_mask(f, k) = 1; - } - } - } - - return F_mask; -} - std::tuple generate_edges( const Eigen::MatrixXd& V, diff --git a/src/feature/core/viewer.cpp b/src/feature/core/viewer.cpp index 8128689..bf612e9 100644 --- a/src/feature/core/viewer.cpp +++ b/src/feature/core/viewer.cpp @@ -1,16 +1,24 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/core/viewer.h" #include "feature/core/vf_corners.h" #include "feature/feature/error.h" #include "feature/feature/features.h" #include "feature/feature/gluing.h" -#include "holonomy/field/facet_field.h" -#include "holonomy/field/frame_field.h" -#include "holonomy/field/cross_field.h" +#include "field/facet_field.h" +#include "field/frame_field.h" +#include "field/cross_field.h" #include "feature/core/quads.h" -#include "optimization/core/projection.h" -#include "holonomy/field/intrinsic_field.h" -#include "optimization/core/viewer.h" +#include "metric/projection.h" +#include "field/intrinsic_field.h" +#include "metric/viewer.h" #include "holonomy/core/viewer.h" #include "util/vf_mesh.h" @@ -82,7 +90,7 @@ void view_glued_mesh_cones( } // get doubled mesh to view from halfedge - auto [V_double, F_mesh, F_halfedge] = Optimization::generate_doubled_mesh(V, m, vtx_gluing); + auto [V_double, F_mesh, F_halfedge] = generate_doubled_mesh(V, m, vtx_gluing); // Generate cone geometry spdlog::info("Generating cone info"); @@ -186,7 +194,7 @@ void view_cross_field( } // generate frame field geometry from cross field - Eigen::MatrixXd frame_field = Holonomy::generate_field(V, F, reference_field, theta); + Eigen::MatrixXd frame_field = Field::generate_frame_field(V, F, reference_field, theta); int num_faces = F.rows(); // transfer kappa and period jump to viewer halfedge indexing @@ -420,7 +428,7 @@ void view_principal_curvature( Eigen::VectorXd PV1,PV2; std::vector bad_vertices; igl::principal_curvature(V,F,PD1,PD2,PV1,PV2, bad_vertices, radius); - auto[face_max_direction, face_min_direction, face_max_curvature, face_min_curvature] = Holonomy::compute_facet_principal_curvature(V, F, radius); + auto[face_max_direction, face_min_direction, face_max_curvature, face_min_curvature] = Field::compute_facet_principal_curvature(V, F, radius); #ifdef ENABLE_VISUALIZATION polyscope::init(); @@ -484,7 +492,7 @@ VectorX best_fit_conformal_vf( auto C_v = Optimization::generate_initial_mesh(V, F, V, F, Th_hat, vtx_reindex); auto C_uv = Optimization::generate_initial_mesh(V, F, uv, F_uv, Th_hat, vtx_reindex); VectorX metric_coords = C_uv->get_metric_coordinates(); - VectorX r_perm = Optimization::best_fit_conformal(*C_v, metric_coords); + VectorX r_perm = best_fit_conformal(*C_v, metric_coords); VectorX r = vector_inverse_reindex(r_perm, vtx_reindex); return r; @@ -550,7 +558,7 @@ void view_feature_cross_field( } // generate frame field geometry from cross field - Eigen::MatrixXd frame_field = Holonomy::generate_field(V, F, reference_field, theta); + Eigen::MatrixXd frame_field = Field::generate_frame_field(V, F, reference_field, theta); int num_faces = F.rows(); // transfer kappa and period jump to viewer halfedge indexing @@ -570,8 +578,8 @@ void view_feature_cross_field( Eigen::MatrixXd V_disp = displace_cut_faces(V, F, displacement); // get cone angles - std::vector Th_hat = Holonomy::compute_cone_angle(V, F, kappa, period_jump); - auto [cone_positions, cone_values] = Optimization::generate_cone_vertices(V_disp, Th_hat); + std::vector Th_hat = Field::compute_cone_angle(V, F, kappa, period_jump); + auto [cone_positions, cone_values] = generate_cone_vertices(V_disp, Th_hat); #ifdef ENABLE_VISUALIZATION @@ -614,4 +622,4 @@ void view_feature_cross_field( } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/feature/dirichlet/angle_constraint_relaxer.cpp b/src/feature/dirichlet/angle_constraint_relaxer.cpp index 3ab0197..be07b91 100644 --- a/src/feature/dirichlet/angle_constraint_relaxer.cpp +++ b/src/feature/dirichlet/angle_constraint_relaxer.cpp @@ -1,9 +1,17 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/dirichlet/angle_constraint_relaxer.h" #include "feature/core/component_mesh.h" #include "holonomy/holonomy/constraint.h" #include "holonomy/holonomy/holonomy.h" -#include "optimization/core/constraint.h" -#include "optimization/core/viewer.h" +#include "metric/constraint.h" +#include "metric/viewer.h" #include "util/io.h" #include "util/vector.h" @@ -49,7 +57,7 @@ void AngleConstraintMatrixRelaxer::view(const Mesh& m, const std::vector& vtx_reindex, const Eigen::MatrixXd& V) const { - auto [V_double, F_mesh, F_halfedge] = Optimization::generate_doubled_mesh(V, m, vtx_reindex); + auto [V_double, F_mesh, F_halfedge] = generate_doubled_mesh(V, m, vtx_reindex); // propagate joined corner labels to vertices and edges int num_ind_vertices = m.n_ind_vertices(); @@ -72,7 +80,7 @@ void AngleConstraintMatrixRelaxer::view(const Mesh& m, edge_label[hij] = ci; } } - VectorX edge_label_VF = Optimization::generate_FV_halfedge_data(F_halfedge, edge_label); + VectorX edge_label_VF = generate_FV_halfedge_data(F_halfedge, edge_label); VectorX corner_label_VF = vector_compose(corner_label, m.v_rep); #ifdef ENABLE_VISUALIZATION diff --git a/src/feature/dirichlet/cone_perturber.cpp b/src/feature/dirichlet/cone_perturber.cpp index 176e48f..6468264 100644 --- a/src/feature/dirichlet/cone_perturber.cpp +++ b/src/feature/dirichlet/cone_perturber.cpp @@ -1,6 +1,14 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/dirichlet/cone_perturber.h" -#include "optimization/core/constraint.h" +#include "metric/constraint.h" #include "feature/core/vf_corners.h" namespace Penner { @@ -42,7 +50,7 @@ void ConePerturber::perturb_boundary_cones( Scalar min_angle) { // get initial metric actual angles - VectorX Theta = Optimization::compute_cone_angles(m); + VectorX Theta = compute_cone_angles(m); // get map from halfedge endpoints to halfedges Eigen::SparseMatrix vv2he = generate_VV_to_halfedge_map(m, vtx_reindex, V_map); @@ -255,4 +263,4 @@ int ConePerturber::find_max_adjacent_cone(Mesh& m, int vi) } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/feature/dirichlet/constraint.cpp b/src/feature/dirichlet/constraint.cpp index 05ccf1f..d52759d 100644 --- a/src/feature/dirichlet/constraint.cpp +++ b/src/feature/dirichlet/constraint.cpp @@ -1,9 +1,17 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/dirichlet/constraint.h" #include "feature/core/component_mesh.h" #include "holonomy/holonomy/constraint.h" #include "holonomy/holonomy/holonomy.h" -#include "optimization/core/constraint.h" -#include "optimization/core/viewer.h" +#include "metric/constraint.h" +#include "metric/viewer.h" #include "util/io.h" #include "util/vector.h" diff --git a/src/feature/dirichlet/dirichlet_penner_cone_metric.cpp b/src/feature/dirichlet/dirichlet_penner_cone_metric.cpp index 15af83c..7f78b64 100644 --- a/src/feature/dirichlet/dirichlet_penner_cone_metric.cpp +++ b/src/feature/dirichlet/dirichlet_penner_cone_metric.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/dirichlet/dirichlet_penner_cone_metric.h" #include "util/boundary.h" @@ -131,7 +139,7 @@ MatrixX DirichletPennerConeMetric::constraint_jacobian(const VectorX& cotangents return compute_dirichlet_constraint_jacobian(*this, cotangents); } -std::unique_ptr +std::unique_ptr DirichletPennerConeMetric::set_metric_coordinates(const VectorX& metric_coords) const { return std::make_unique(DirichletPennerConeMetric( @@ -145,10 +153,12 @@ DirichletPennerConeMetric::set_metric_coordinates(const VectorX& metric_coords) m_relaxed_angle_constraint_system)); } -std::unique_ptr DirichletPennerConeMetric::project_to_constraint( +std::unique_ptr DirichletPennerConeMetric::project_to_constraint( SolveStats& solve_stats, - std::shared_ptr proj_params) const + std::shared_ptr proj_params) const { + // TODO: Replace with full feature alignment constraints + // Copy projection parameters to newton method parameters Holonomy::NewtonParameters alg_params; alg_params.max_itr = proj_params->max_itr; diff --git a/src/feature/dirichlet/optimization.cpp b/src/feature/dirichlet/optimization.cpp index 1948a26..ffec26a 100644 --- a/src/feature/dirichlet/optimization.cpp +++ b/src/feature/dirichlet/optimization.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/dirichlet/optimization.h" #ifdef USE_SUITESPARSE @@ -7,7 +15,7 @@ #include "feature/dirichlet/angle_constraint_relaxer.h" #include "feature/dirichlet/constraint.h" #include "holonomy/holonomy/constraint.h" -#include "optimization/core/constraint.h" +#include "metric/constraint.h" #include #include @@ -49,7 +57,7 @@ class OptimizeDirichletRelaxation // build projection parameters for the subroutines SolveStats solve_stats; - proj_params = std::make_shared(); + proj_params = std::make_shared(); proj_params->do_reduction = true; proj_params->output_dir = alg_params.output_dir; proj_params->error_eps = 1e-12; @@ -71,7 +79,7 @@ class OptimizeDirichletRelaxation // perform initial projection dirichlet_metric.change_metric(initial_dirichlet_metric, reduced_metric_init); - std::unique_ptr projected_cone_metric = + std::unique_ptr projected_cone_metric = dirichlet_metric.project_to_constraint(solve_stats, proj_params); reduced_metric_coords = projected_cone_metric->get_reduced_metric_coordinates(); update_metric(initial_dirichlet_metric, reduced_metric_coords); @@ -137,7 +145,7 @@ class OptimizeDirichletRelaxation int num_solves; Scalar max_triangle_quality; Scalar max_hard_error; - std::shared_ptr proj_params; + std::shared_ptr proj_params; VectorX triangle_quality, he2angle, he2cot; // Open a per iteration data log and write a header @@ -293,7 +301,7 @@ class OptimizeDirichletRelaxation SolveStats solve_stats; reduced_metric_coords = reduced_metric_start + lambda * descent_direction; dirichlet_metric.change_metric(initial_dirichlet_metric, reduced_metric_coords); - std::unique_ptr line_step_cone_metric = + std::unique_ptr line_step_cone_metric = dirichlet_metric.project_to_constraint(solve_stats, proj_params); reduced_metric_coords = line_step_cone_metric->get_reduced_metric_coordinates(); update_metric(initial_dirichlet_metric, reduced_metric_coords); @@ -470,4 +478,4 @@ std::vector> reduce_relaxed_edges( } } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/feature/experimental/boundary_constraint_generator.cpp b/src/feature/experimental/boundary_constraint_generator.cpp index 8fc5ba9..cf6d7f1 100644 --- a/src/feature/experimental/boundary_constraint_generator.cpp +++ b/src/feature/experimental/boundary_constraint_generator.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/experimental/boundary_constraint_generator.h" #include "util/boundary.h" @@ -303,7 +311,7 @@ void BoundaryConstraintGenerator::view( const std::vector& vtx_reindex) { const Mesh& m = get_mesh(); - auto [V_double, F, F_halfedge] = Optimization::generate_doubled_mesh(V, m, vtx_reindex); + auto [V_double, F, F_halfedge] = generate_doubled_mesh(V, m, vtx_reindex); // build feature coloring int num_halfedges = m.n_halfedges(); @@ -315,9 +323,9 @@ void BoundaryConstraintGenerator::view( is_feature_halfedge(h) = i + 1; } } - VectorX FV_feature_halfedges = Optimization::generate_FV_halfedge_data(F_halfedge, is_feature_halfedge); + VectorX FV_feature_halfedges = generate_FV_halfedge_data(F_halfedge, is_feature_halfedge); - auto [cone_positions, cone_values] = Optimization::generate_cone_vertices(V, vtx_reindex, m); + auto [cone_positions, cone_values] = generate_cone_vertices(V, vtx_reindex, m); #ifdef ENABLE_VISUALIZATION polyscope::init(); diff --git a/src/feature/experimental/boundary_constraint_validator.cpp b/src/feature/experimental/boundary_constraint_validator.cpp index ad3933e..f2cc1da 100644 --- a/src/feature/experimental/boundary_constraint_validator.cpp +++ b/src/feature/experimental/boundary_constraint_validator.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/experimental/boundary_constraint_validator.h" #include "util/boundary.h" diff --git a/src/feature/experimental/depracated.cpp b/src/feature/experimental/depracated.cpp index ec8ea18..7ba1dff 100644 --- a/src/feature/experimental/depracated.cpp +++ b/src/feature/experimental/depracated.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + std::tuple parameterize_components( @@ -30,8 +38,8 @@ parameterize_components( metric_init[i] = 2. * log(init_component.l[i]); metric_coords[i] = 2. * log(mesh_component.l[i]); } - Optimization::PennerConeMetric component_init(mesh_component, metric_init); - Optimization::PennerConeMetric component_metric(mesh_component, metric_coords); + PennerConeMetric component_init(mesh_component, metric_init); + PennerConeMetric component_metric(mesh_component, metric_coords); // Get component vertices int n_v_component = component_metric.n_vertices(); @@ -81,7 +89,7 @@ parameterize_components( std::vector> endpoints_o = std::get<8>(vf_res); // Refine mesh - Optimization::RefinementMesh refinement_mesh(V_o, F_o, uv_o, FT_o, fn_to_f_o, endpoints_o); + RefinementMesh refinement_mesh(V_o, F_o, uv_o, FT_o, fn_to_f_o, endpoints_o); auto [V_r, F_r, uv_r, FT_r, fn_to_f_r, endpoints_r] = refinement_mesh.get_VF_mesh(); // Add components to lists @@ -339,7 +347,7 @@ layout_cut_mesh( for (int i = 0; i < mesh_component.n_halfedges(); ++i) { metric_coords[i] = 2. * log(mesh_component.l[i]); } - Optimization::PennerConeMetric component_metric(mesh_component, metric_coords); + PennerConeMetric component_metric(mesh_component, metric_coords); int n_v_component = component_metric.n_vertices(); int n_ind_v_component = component_metric.n_ind_vertices(); @@ -362,7 +370,7 @@ layout_cut_mesh( scale_factors.setZero(n_ind_v_component); // Compute interpolation overlay mesh - Optimization::InterpolationMesh interpolation_mesh, reverse_interpolation_mesh; + InterpolationMesh interpolation_mesh, reverse_interpolation_mesh; interpolate_penner_coordinates( embedding_component, component_metric.get_metric_coordinates(), @@ -370,7 +378,7 @@ layout_cut_mesh( interpolation_mesh, reverse_interpolation_mesh); OverlayMesh m_o = interpolation_mesh.get_overlay_mesh(); - auto [F_o, uv_o, FT_o] = Optimization::compute_layout_VF(m_o); + auto [F_o, uv_o, FT_o] = compute_layout_VF(m_o); //Optimization::view_mesh_topology(V_component, F_o); // Add components to lists @@ -708,4 +716,4 @@ generate_union_metric( CutMetricGenerator cut_metric_generator(V_cut, F_cut, marked_metric_params, marked_corners); cut_metric_generator.generate_fields(V_cut, F_cut, V_map, direction, is_fixed_direction); return cut_metric_generator.get_union_metric(marked_metric_params); -} +} \ No newline at end of file diff --git a/src/feature/experimental/energy.cpp b/src/feature/experimental/energy.cpp index 7b5922a..0c207a1 100644 --- a/src/feature/experimental/energy.cpp +++ b/src/feature/experimental/energy.cpp @@ -1,10 +1,18 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/experimental/energy.h" -#include "optimization/core/constraint.h" +#include "metric/constraint.h" namespace Penner { namespace Feature { -ConeEnergy::ConeEnergy(const Optimization::PennerConeMetric& cone_metric) +ConeEnergy::ConeEnergy(const PennerConeMetric& cone_metric) : m_cone_metric(cone_metric) {} @@ -18,7 +26,7 @@ Scalar ConeEnergy::energy(const VectorX& metric_coords) const MatrixX J_constraint; bool need_jacobian = false; bool only_free_vertices = true; - Optimization::constraint_with_jacobian( + constraint_with_jacobian( *cone_metric, constraint, J_constraint, @@ -38,7 +46,7 @@ VectorX ConeEnergy::gradient(const VectorX& metric_coords) const MatrixX J_constraint; bool need_jacobian = true; bool only_free_vertices = true; - Optimization::constraint_with_jacobian( + constraint_with_jacobian( *cone_metric, constraint, J_constraint, diff --git a/src/feature/experimental/junctions.cpp b/src/feature/experimental/junctions.cpp index 74034d8..1ef13e4 100644 --- a/src/feature/experimental/junctions.cpp +++ b/src/feature/experimental/junctions.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/experimental/junctions.h" #include "feature/core/common.h" @@ -31,7 +39,7 @@ void JunctionFeatureFinder::view_junctions(bool show) // get junction vertices std::vector junction_vertices = vector_reindex(vtx_reindex, compute_junctions()); Eigen::MatrixXd junctions = - Optimization::generate_subset_vertices(vertex_positions, junction_vertices); + generate_subset_vertices(vertex_positions, junction_vertices); #ifdef ENABLE_VISUALIZATION polyscope::init(); @@ -238,7 +246,7 @@ void JunctionFeatureFinder::prune_closest_junction(int vertex_index) // compute distance to input vertex with features cut const std::vector& is_feature_halfedge = get_feature_halfedges(); std::vector vertex_weights = find_vertex_weights(m, is_feature_halfedge, root); - Optimization::view_vertex_function(m, vtx_reindex, vertex_positions, vertex_weights); + view_vertex_function(m, vtx_reindex, vertex_positions, vertex_weights); // get the junction closest to the root vertex std::vector junctions = compute_junctions(); @@ -363,4 +371,4 @@ std::tuple, std::vector> JunctionFeatureFinder::compute_f } } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/feature/experimental/marked_refinement.cpp b/src/feature/experimental/marked_refinement.cpp index 384936d..26e5739 100644 --- a/src/feature/experimental/marked_refinement.cpp +++ b/src/feature/experimental/marked_refinement.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/experimental/marked_refinement.h" #include "util/boundary.h" diff --git a/src/feature/experimental/newton.cpp b/src/feature/experimental/newton.cpp index 81a2951..89c6218 100644 --- a/src/feature/experimental/newton.cpp +++ b/src/feature/experimental/newton.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/experimental/newton.h" #include "holonomy/holonomy/holonomy.h" @@ -9,13 +17,13 @@ #include #include "optimization/metric_optimization/energies.h" #include "optimization/metric_optimization/energy_functor.h" -#include "optimization/core/projection.h" -#include "optimization/core/shear.h" +#include "metric/projection.h" +#include "metric/shear.h" #include "util/io.h" #ifdef USE_SUITESPARSE #include -#include +//#include #endif namespace Penner { diff --git a/src/feature/experimental/patches.cpp b/src/feature/experimental/patches.cpp index 8f9d6b3..9443530 100644 --- a/src/feature/experimental/patches.cpp +++ b/src/feature/experimental/patches.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/experimental/patches.h" namespace Penner { diff --git a/src/feature/experimental/penner_optimization.cpp b/src/feature/experimental/penner_optimization.cpp index e95971d..42d3f1e 100644 --- a/src/feature/experimental/penner_optimization.cpp +++ b/src/feature/experimental/penner_optimization.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + /// Build a VF mesh for the embedded mesh in the doubled mesh and also extract /// the mapping from VF mesh corners to opposite halfedge index diff --git a/src/feature/experimental/polygon_cones.cpp b/src/feature/experimental/polygon_cones.cpp index a31462c..c191f5c 100644 --- a/src/feature/experimental/polygon_cones.cpp +++ b/src/feature/experimental/polygon_cones.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/experimental/polygon_cones.h" #include "util/boundary.h" diff --git a/src/feature/experimental/transfer.cpp b/src/feature/experimental/transfer.cpp index 08bfeb5..1af5307 100644 --- a/src/feature/experimental/transfer.cpp +++ b/src/feature/experimental/transfer.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/experimental/transfer.h" diff --git a/src/feature/feature/error.cpp b/src/feature/feature/error.cpp index 047621c..6cdcd9a 100644 --- a/src/feature/feature/error.cpp +++ b/src/feature/feature/error.cpp @@ -1,10 +1,18 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/feature/error.h" #include #include "feature/core/common.h" #include "feature/core/component_mesh.h" #include "feature/dirichlet/constraint.h" #include "holonomy/holonomy/constraint.h" -#include "optimization/core/constraint.h" +#include "metric/constraint.h" #include "util/vf_mesh.h" @@ -20,7 +28,7 @@ double compute_edge_alignment(const Eigen::Vector2d& d) // compute signed angle between the nearest axis double signed_axis_angle = - (double)(Holonomy::pos_fmod(diagonal_angle, M_PI / 2.) - (M_PI / 4.)); + (double)(pos_fmod(diagonal_angle, M_PI / 2.) - (M_PI / 4.)); // compute normalized absolute value return abs(signed_axis_angle) / (M_PI / 4.); @@ -318,4 +326,4 @@ Eigen::MatrixXd compute_height(const Eigen::MatrixXd& uv, const Eigen::MatrixXi& } } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/feature/feature/features.cpp b/src/feature/feature/features.cpp index 95bf229..5877604 100644 --- a/src/feature/feature/features.cpp +++ b/src/feature/feature/features.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/feature/features.h" #include "feature/core/common.h" @@ -496,7 +504,7 @@ FeatureFinder::generate_feature_cut_mesh() const void FeatureFinder::view_features(bool show) { // view the feature edges as a graph - Optimization::view_primal_graph( + view_primal_graph( m_vertex_positions, m_mesh, m_vtx_reindex, @@ -506,7 +514,7 @@ void FeatureFinder::view_features(bool show) // view the feature forest that would be produced by pruning cycles as a graph std::vector is_in_feature_forest = compute_feature_forest_halfedges(); - Optimization::view_primal_graph( + view_primal_graph( m_vertex_positions, m_mesh, m_vtx_reindex, @@ -521,7 +529,7 @@ void FeatureFinder::view_parametric_features( const std::vector& vtx_reindex) const { // add features - Optimization::view_primal_graph(uv, m_mesh, vtx_reindex, m_is_feature_halfedge); + view_primal_graph(uv, m_mesh, vtx_reindex, m_is_feature_halfedge); } void FeatureFinder::set_feature_edge(int halfedge_index, bool is_feature) @@ -731,4 +739,4 @@ std::vector FeatureFinder::compute_feature_forest() const } } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/feature/feature/gluing.cpp b/src/feature/feature/gluing.cpp index 79145d9..9388bd9 100644 --- a/src/feature/feature/gluing.cpp +++ b/src/feature/feature/gluing.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/feature/gluing.h" @@ -124,4 +132,4 @@ std::pair count_glued_cones( } } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/feature/interface.cpp b/src/feature/interface.cpp index 352b407..08ddc8a 100644 --- a/src/feature/interface.cpp +++ b/src/feature/interface.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/interface.h" #ifdef WITH_MPFR @@ -7,11 +15,11 @@ #include "util/vf_mesh.h" #include "util/boundary.h" -#include "optimization/parameterization/refinement.h" -#include "optimization/core/common.h" +#include "parametrization/refinement.h" +#include "metric/common.h" #include "holonomy/interface.h" -#include "holonomy/field/frame_field.h" +#include "field/frame_field.h" #include "holonomy/core/viewer.h" #include "feature/feature/gluing.h" @@ -329,7 +337,7 @@ void AlignedMetricGenerator::view_constraints() const { if (dirichlet_metric.fixed_dof[i]) independent[i] = 1.; } - Optimization::view_independent_vertex_function( + view_independent_vertex_function( dirichlet_metric, vtx_reindex, V_cut, @@ -337,7 +345,7 @@ void AlignedMetricGenerator::view_constraints() const "Th_hat", false ); - Optimization::view_independent_vertex_function( + view_independent_vertex_function( dirichlet_metric, vtx_reindex, V_cut, @@ -386,7 +394,7 @@ void AlignedMetricGenerator::parameterize(bool use_high_precision, bool use_unif if ((is_axis_aligned) && (!use_high_precision)) { auto [uv_length_error, uv_angle_error, uv_length, uv_angle] = Holonomy::compute_seamless_error(F_o, uv_o, FT_o); - if ((uv_length_error.maxCoeff() > 1e-10) || (uv_angle_error.maxCoeff() > 1e-10) || Optimization::matrix_contains_nan(uv_o) || Optimization::matrix_contains_nan(V_o)) + if ((uv_length_error.maxCoeff() > 1e-10) || (uv_angle_error.maxCoeff() > 1e-10) || matrix_contains_nan(uv_o) || matrix_contains_nan(V_o)) { spdlog::warn("Falling back to high precision"); return parameterize(true, use_uniform_bc); @@ -413,7 +421,7 @@ void AlignedMetricGenerator::parameterize(bool use_high_precision, bool use_unif if (simplify) { //Optimization::view_triangulation(V_s, F_s, fn_to_f_s, endpoints_s, "stitched mesh"); - Optimization::RefinementMesh refinement_mesh(V_s, F_s, uv_s, FT_s, fn_to_f_s, endpoints_s); + RefinementMesh refinement_mesh(V_s, F_s, uv_s, FT_s, fn_to_f_s, endpoints_s); refinement_mesh.refine_mesh(); refinement_mesh.simplify_mesh(); refinement_mesh.get_VF_mesh(V_r, F_r, uv_r, FT_r, fn_to_f_r, endpoints_r); @@ -427,7 +435,7 @@ void AlignedMetricGenerator::parameterize(bool use_high_precision, bool use_unif if ((is_axis_aligned) && (!use_high_precision)) { auto [uv_length_error, uv_angle_error, uv_length, uv_angle] = Holonomy::compute_seamless_error(F_r, uv_r, FT_r); - if ((uv_length_error.maxCoeff() > 1e-10) || (uv_angle_error.maxCoeff() > 1e-10) || Optimization::matrix_contains_nan(uv_r) || Optimization::matrix_contains_nan(V_r)) + if ((uv_length_error.maxCoeff() > 1e-10) || (uv_angle_error.maxCoeff() > 1e-10) || matrix_contains_nan(uv_r) || matrix_contains_nan(V_r)) { spdlog::warn("Falling back to high precision"); return parameterize(true); @@ -449,7 +457,7 @@ void AlignedMetricGenerator::parameterize(bool use_high_precision, bool use_unif } // refine frame field - std::tie(reference_field_r, theta_r, kappa_r, period_jump_r) = Holonomy::refine_frame_field( + std::tie(reference_field_r, theta_r, kappa_r, period_jump_r) = Field::refine_frame_field( F_r, FT_r, fn_to_f_r, @@ -567,4 +575,4 @@ generate_feature_aligned_parameterization( } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/feature/pybind.cpp b/src/feature/pybind.cpp index 2789e93..c059f43 100644 --- a/src/feature/pybind.cpp +++ b/src/feature/pybind.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/pybind.h" #ifdef PYBIND @@ -175,6 +183,7 @@ void init_feature_pybind(pybind11::module& m) m.def("prune_redundant_edge_corners", &prune_redundant_edge_corners, default_call_guard); m.def("compute_seamless_error", &Holonomy::compute_seamless_error, default_call_guard); m.def("compute_angle_error", &Holonomy::compute_angle_error, default_call_guard); + //m.def("compute_field_direction", &compute_field_direction, default_call_guard); m.def("reduce_relaxed_edges", &reduce_relaxed_edges, default_call_guard); m.def("transfer_corner_function_to_halfedge", &transfer_corner_function_to_halfedge, default_call_guard); m.def("transfer_halfedge_function_to_corner", &transfer_halfedge_function_to_corner, default_call_guard); @@ -182,7 +191,7 @@ void init_feature_pybind(pybind11::module& m) m.def("check_flip", &check_flip, default_call_guard); m.def("compute_height", &compute_height, default_call_guard); - m.def("find_seams", &find_seams, default_call_guard); + //m.def("find_seams", &find_seams, default_call_guard); m.def("write_seams", &write_seams, default_call_guard); m.def("write_boundary", &write_boundary, default_call_guard); m.def("write_features", &write_features, default_call_guard); @@ -200,4 +209,4 @@ void init_feature_pybind(pybind11::module& m) } #endif -#endif +#endif \ No newline at end of file diff --git a/src/feature/surgery/cut_mesh_layout.cpp b/src/feature/surgery/cut_mesh_layout.cpp index 2b08b2e..6f88dd8 100644 --- a/src/feature/surgery/cut_mesh_layout.cpp +++ b/src/feature/surgery/cut_mesh_layout.cpp @@ -1,9 +1,18 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/surgery/cut_mesh_layout.h" #include "util/vf_mesh.h" -#include "optimization/parameterization/interpolation.h" -#include "optimization/parameterization/layout.h" +#include "parametrization/interpolation.h" +#include "parametrization/layout.h" +#include "parametrization/parametrize.h" #include "feature/feature/error.h" #include "feature/core/component_mesh.h" @@ -70,8 +79,8 @@ parameterize_cut_mesh( // metric_init[i] = 2. * log(init_component.l[i]); metric_coords[i] = 2. * log(mesh_component.l[i]); } - Optimization::PennerConeMetric component_init(mesh_component, metric_init); - Optimization::PennerConeMetric component_metric(mesh_component, metric_coords); + PennerConeMetric component_init(mesh_component, metric_init); + PennerConeMetric component_metric(mesh_component, metric_coords); // Get component vertices int n_v_component = component_metric.n_vertices(); @@ -97,7 +106,7 @@ parameterize_cut_mesh( // Generate overlay std::vector is_cut = {}; std::string component_layout_path = join_path(output_dir, "component_" + std::to_string(i) + ".obj"); - auto vf_res = Optimization::generate_VF_mesh_from_halfedge_metric( + auto vf_res = generate_VF_mesh_from_halfedge_metric( V_component, embedding_component, vtx_reindex_component, @@ -382,7 +391,7 @@ generate_connected_parameterization( Mesh m = FV_to_double(V, F, uv, F_uv, convert_vector_type(Th_hat), vtx_reindex, indep_vtx, dep_vtx, v_rep, bnd_loops); //average_length(m); OverlayMesh m_o(m); - Optimization::make_tufted_overlay(m_o); + make_tufted_overlay(m_o); spdlog::info("generated overlay mesh with {} vertices", m_o.n_vertices()); spdlog::info("length error is {}", compute_length_error(m)); @@ -426,7 +435,7 @@ generate_connected_parameterization( // Now directly do layout on triangulated overlay mesh std::vector phi(m.n_vertices(), 0.0); std::vector is_cut; - auto overlay_layout_res = Optimization::compute_layout_components(m_o.cmesh(), phi, is_cut, h_start); + auto overlay_layout_res = compute_layout_components(m_o.cmesh(), phi, is_cut, h_start); std::vector u_o = std::get<0>(overlay_layout_res); std::vector v_o = std::get<1>(overlay_layout_res); std::vector is_cut_o = std::get<2>(overlay_layout_res); @@ -511,4 +520,4 @@ generate_connected_parameterization( #endif } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/feature/surgery/cut_metric_generator.cpp b/src/feature/surgery/cut_metric_generator.cpp index 0d0429b..a997139 100644 --- a/src/feature/surgery/cut_metric_generator.cpp +++ b/src/feature/surgery/cut_metric_generator.cpp @@ -1,9 +1,16 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/surgery/cut_metric_generator.h" -#include "optimization/core/constraint.h" -#include "holonomy/field/cross_field.h" -#include "holonomy/field/frame_field.h" -#include "holonomy/field/intrinsic_field.h" +#include "field/cross_field.h" +#include "field/frame_field.h" +#include "field/intrinsic_field.h" #include "holonomy/holonomy/cones.h" #include "feature/core/component_mesh.h" @@ -210,11 +217,11 @@ void CutMetricGenerator::generate_fields( auto& face_map = face_maps[i]; // TODO: make parameter - Holonomy::FieldParameters field_params; + Field::FieldParameters field_params; field_params.min_cone = 1; // initialize field data for component (needed to generate reference corners) - Holonomy::IntrinsicNRosyField field_generator; + Field::IntrinsicNRosyField field_generator; field_generator.min_cone = field_params.min_cone; if (V_map.size() > 0) { @@ -233,8 +240,8 @@ void CutMetricGenerator::generate_fields( is_fixed[i] = is_fixed_direction[fijk]; // convert extrinsic direction to intrinsic angle - Eigen::Vector3d reference_direction = Holonomy::generate_reference_direction(V_cut, F_cut, fijk, reference_corner[fijk]); - target_theta[i] = -Holonomy::signed_angle(direction.row(fijk), reference_direction, N.row(fijk)); + Eigen::Vector3d reference_direction = Field::generate_reference_direction(V_cut, F_cut, fijk, reference_corner[fijk]); + target_theta[i] = -signed_angle(direction.row(fijk), reference_direction, N.row(fijk)); } field_generator.set_fixed_directions(m, target_theta, is_fixed); @@ -252,7 +259,7 @@ void CutMetricGenerator::generate_fields( } // generate reference field from reference corners - reference_field = Holonomy::generate_reference_field(V_cut, F_cut, reference_corner); + reference_field = Field::generate_reference_field(V_cut, F_cut, reference_corner); } @@ -278,7 +285,7 @@ void CutMetricGenerator::set_fields( auto& face_map = face_maps[i]; // initialize feild generator with the given field - Holonomy::IntrinsicNRosyField field_generator; + Field::IntrinsicNRosyField field_generator; field_generator.min_cone = 1; field_generator.use_trivial_boundary = true; field_generator.initialize(m); @@ -465,12 +472,12 @@ void CutMetricGenerator::generate_marked_metrics(MarkedMetricParameters marked_m void CutMetricGenerator::optimize_fields(const Eigen::MatrixXd& V, const Eigen::MatrixXi& F, const Eigen::MatrixXi& F_cut) { // generate cross field from current field - std::array cross_field = Holonomy::generate_cross_field(V, F, reference_field, theta); + std::array cross_field = Field::generate_cross_field(V, F, reference_field, theta); // optimize cross field std::vector fixed_faces; convert_boolean_array_to_index_vector(is_fixed_face, fixed_faces); - cross_field = Holonomy::reduce_curl(V, F, cross_field, fixed_faces); + cross_field = Field::reduce_curl(V, F, cross_field, fixed_faces); // build glued mesh spdlog::info("Generating uncut mesh"); @@ -482,11 +489,11 @@ void CutMetricGenerator::optimize_fields(const Eigen::MatrixXd& V, const Eigen:: // set field with optimized cross field spdlog::info("Setting field"); Eigen::VectorXi reference_corner(F.rows()); - Holonomy::IntrinsicNRosyField field_generator; + Field::IntrinsicNRosyField field_generator; field_generator.initialize(m); field_generator.get_field(m, vtx_reindex_uncut, F, face_reindex_uncut, reference_corner, theta, kappa, period_jump); - theta = Holonomy::infer_theta(V, F, reference_corner, cross_field[0]); - reference_field = Holonomy::generate_reference_field(V, F, reference_corner); + theta = Field::infer_theta(V, F, reference_corner, cross_field[0]); + reference_field = Field::generate_reference_field(V, F, reference_corner); field_generator.set_field(m, vtx_reindex_uncut, F, face_reindex_uncut, theta, kappa, period_jump); // set principal matchings @@ -498,4 +505,4 @@ void CutMetricGenerator::optimize_fields(const Eigen::MatrixXd& V, const Eigen:: } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/feature/surgery/refinement.cpp b/src/feature/surgery/refinement.cpp index f95accc..d87244c 100644 --- a/src/feature/surgery/refinement.cpp +++ b/src/feature/surgery/refinement.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/surgery/refinement.h" #include "util/boundary.h" @@ -471,7 +479,23 @@ std::tuple> refine_cor int num_halfedges = m.n_halfedges(); IntrinsicRefinementMesh refinement_mesh(m); - // refine feature faces + // get list of components with no interior vertices + std::vector feature_degrees = feature_finder.compute_feature_degrees(); + UnionFind cut_features = feature_finder.compute_cut_feature_components(); + std::vector feature_labels = cut_features.index_sets(); + int num_components = cut_features.count_sets(); + std::vector is_component_seen(num_components, false); + for (int hij = 0; hij < num_halfedges; ++hij) + { + // check if tip is interior vertex + int vj = m.v_rep[m.to[hij]]; + if (feature_degrees[vj] > 0) continue; + + // label component as seen if interior vertex found + is_component_seen[feature_labels[hij]] = true; + } + + // refine faces with two feature edges or in components with no interior vertices for (int fijk = 0; fijk < num_faces; ++fijk) { // count number of feature vertices in face @@ -486,9 +510,10 @@ std::tuple> refine_cor } // refine if multiple edges are features - if (num_feature_edges > 1) + if ((num_feature_edges > 1) || (!is_component_seen[feature_labels[hij]])) { refinement_mesh.refine_face(fijk); + is_component_seen[feature_labels[hij]] = true; } } diff --git a/src/feature/surgery/stitching.cpp b/src/feature/surgery/stitching.cpp index 1516fe7..98176ba 100644 --- a/src/feature/surgery/stitching.cpp +++ b/src/feature/surgery/stitching.cpp @@ -1,8 +1,16 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "feature/surgery/stitching.h" #include "holonomy/core/viewer.h" -#include "optimization/parameterization/refinement.h" -#include "optimization/parameterization/layout.h" +#include "parametrization/refinement.h" +#include "parametrization/layout.h" #include "util/io.h" #include "util/vector.h" #include "util/vf_mesh.h" @@ -429,7 +437,7 @@ class EdgeSplicer Eigen::Vector2d pj(refined_uv[vj][0], refined_uv[vj][1]); Eigen::Vector2d pk(refined_uv[vk][0], refined_uv[vk][1]); - return Optimization::signed_area(pi, pj, pk); + return signed_area(pi, pj, pk); } // split the current segment, returning the current stitched vertex and corresponding uv points @@ -744,12 +752,12 @@ EdgeSplicer::EdgeSplicer( , m_endpoints(endpoints) { // build list of split faces per original face - std::vector> F_to_Fn = Optimization::build_F_to_Fn(Fn_to_F); + std::vector> F_to_Fn = build_F_to_Fn(Fn_to_F); // For each original face, get the overlay vertices corresponding to the face int num_faces = F_to_Fn.size(); Eigen::MatrixXi halfedge_map; - Optimization::build_faces( + build_faces( F, F_uv, F_to_Fn, @@ -912,4 +920,4 @@ stitch_cut_overlay( } // namespace Feature -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/feature/util/union_find.cpp b/src/feature/util/union_find.cpp index e69de29..e686939 100644 --- a/src/feature/util/union_find.cpp +++ b/src/feature/util/union_find.cpp @@ -0,0 +1,8 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + diff --git a/src/field/CMakeLists.txt b/src/field/CMakeLists.txt new file mode 100644 index 0000000..da75bfa --- /dev/null +++ b/src/field/CMakeLists.txt @@ -0,0 +1,31 @@ +set(FieldSrc + field.cpp + frame_field.cpp + cross_field.cpp + facet_field.cpp + forms.cpp + intrinsic_field.cpp +) + +add_library(PennerFieldLib + ${FieldSrc} +) +target_include_directories(PennerFieldLib PUBLIC ../../include/field) +target_link_libraries(PennerFieldLib PUBLIC + PennerCoreLib + ${VISUALIZATION_LIBS} +) +target_link_libraries(PennerFieldLib PRIVATE + geometry-central + nlohmann_json::nlohmann_json + DirectionalLib + ${COMISO_LIBS} +) +target_compile_definitions(PennerFieldLib PUBLIC + SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG +) +if ((NOT USE_MULTIPRECISION) AND (USE_WARNINGS)) + target_compile_options(PennerFieldLib PRIVATE + -Wall -Wpedantic -Wextra -Werror + ) +endif() diff --git a/src/field/comiso.h b/src/field/comiso.h new file mode 100644 index 0000000..aa35cca --- /dev/null +++ b/src/field/comiso.h @@ -0,0 +1,180 @@ +#include "field/rounder.h" + +#include "field/rounder.h" + +namespace Penner { +namespace Field { + +// WARNING: CoMISo uses a more restrictive copyleft license +#if USE_COMISO +#include +#include +#include + + +// TODO Make option and make cone rounder code public +class ConeMISolver : public COMISO::MISolver +{ +public: + ConeMISolver() {}; + void solve_cone_rounding( + CSCMatrix& _A, + Vecd& _x, + Vecd& _rhs, + Veci& _to_round, + Rounder& rounder) { + // StopWatch + COMISO::StopWatch sw; + double time_search_next_integer = 0; + + // some statistics + n_local_ = 0; + n_cg_ = 0; + n_full_ = 0; + + // reset cholmod step flag + cholmod_step_done_ = false; + + Veci to_round(_to_round); + // copy to round vector and make it unique + std::sort(to_round.begin(), to_round.end()); + Veci::iterator last_unique; + last_unique = std::unique(to_round.begin(), to_round.end()); + int r = last_unique - to_round.begin(); + to_round.resize( r); + + // initalize old indices + Veci old_idx(_rhs.size()); + for(unsigned int i=0; i 2) std::cerr << "initial full solution" << std::endl; + direct_solver_.calc_system_gmm(_A); + direct_solver_.solve(_x, _rhs); + + cholmod_step_done_ = true; + + ++n_full_; + } + + // neighbors for local optimization + Vecui neigh_i; + + // Vector for reduced solution + Vecd xr(_x); + + // loop until solution computed + for(unsigned int i=0; i 0) + { + std::cerr << "Integer DOF's left: " << to_round.size()-(i+1) << " "; + if( noisy_ > 1) + std::cerr << "residuum_norm: " << COMISO_GMM::residuum_norm( _A, xr, _rhs) << std::endl; + } + + // position in round vector + std::vector tr_best; + + sw.start(); + + RoundingSet rset; + rset.set_threshold(multiple_rounding_threshold_); + + // find index yielding smallest rounding error + for(unsigned int j=0; j 5) + std::cerr << "round " << tr_best.size() << " variables simultaneously\n"; + + // clear neigh for local update + neigh_i.clear(); + + for(unsigned int j = 0; j 2) std::cerr << "final full solution" << std::endl; + + if( gmm::mat_ncols( _A) > 0) + { + if(cholmod_step_done_) + direct_solver_.update_system_gmm(_A); + else + direct_solver_.calc_system_gmm(_A); + + direct_solver_.solve( xr, _rhs); + ++n_full_; + } + } + + // store solution values to result vector + for(unsigned int i=0; i +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "field/cross_field.h" #include #include @@ -7,14 +15,10 @@ #include #include -#if ENABLE_VISUALIZATION -#include -#endif - #include namespace Penner { -namespace Holonomy { +namespace Field { std::array load_rawfield(const std::string& filename) { @@ -174,23 +178,6 @@ std::array reduce_curl( directional::polycurl_reduction_precompute(mesh, b, bc, blevel, rawField , pcrdata); Eigen::VectorXi constFaces = b; -#if ENABLE_VISUALIZATION - directional::DirectionalViewer viewer; - bool view = false; - if (view) - { - viewer.set_mesh(mesh,0); - viewer.set_mesh(mesh, 1); - viewer.set_field(rawField,Eigen::MatrixXd(), 1,0.9, 0, 10.0); - - viewer.toggle_mesh(false,0); - viewer.toggle_field(true,0); - viewer.toggle_field(true,1); - viewer.set_selected_faces(constFaces,1); - viewer.launch(); - } -#endif - spdlog::debug("Optimizing curl"); int iter = 0; params.numIter = 5; @@ -247,5 +234,5 @@ std::array reduce_curl( return opt_cross_field; } -} // namespace Holonomy -} // namespace Penner +} +} // namespace Penner \ No newline at end of file diff --git a/src/holonomy/field/facet_field.cpp b/src/field/facet_field.cpp similarity index 98% rename from src/holonomy/field/facet_field.cpp rename to src/field/facet_field.cpp index e97c79b..3871b74 100644 --- a/src/holonomy/field/facet_field.cpp +++ b/src/field/facet_field.cpp @@ -1,9 +1,18 @@ -#include "holonomy/field/facet_field.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "field/facet_field.h" +#include "util/linear_algebra.h" #include #include namespace Penner { -namespace Holonomy { +namespace Field { const char WHITESPACE[] = " \t\r\n"; @@ -706,4 +715,4 @@ std::tuple generate_halfedge_from_face_matchin } // namespace Holonomy -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/holonomy/field/field.cpp b/src/field/field.cpp similarity index 76% rename from src/holonomy/field/field.cpp rename to src/field/field.cpp index d3c17e5..9877298 100644 --- a/src/holonomy/field/field.cpp +++ b/src/field/field.cpp @@ -1,10 +1,17 @@ -#include "holonomy/field/field.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "field/field.h" #include "util/vf_mesh.h" -#include "holonomy/core/dual_loop.h" -#include "holonomy/field/forms.h" +#include "field/forms.h" -#include "optimization/core/constraint.h" +#include "metric/constraint.h" #include "util/vector.h" #if USE_COMISO @@ -13,7 +20,7 @@ #endif namespace Penner { -namespace Holonomy { +namespace Field { std::tuple> generate_cross_field( const Eigen::MatrixXd& V, diff --git a/src/holonomy/field/forms.cpp b/src/field/forms.cpp similarity index 75% rename from src/holonomy/field/forms.cpp rename to src/field/forms.cpp index 57442fa..750e00c 100644 --- a/src/holonomy/field/forms.cpp +++ b/src/field/forms.cpp @@ -1,10 +1,18 @@ -#include "holonomy/field/forms.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. -#include "optimization/core/constraint.h" +#include "field/forms.h" + +#include "metric/constraint.h" #include namespace Penner { -namespace Holonomy { +namespace Field { bool is_valid_one_form(const Mesh& m, const VectorX& one_form) { @@ -69,82 +77,6 @@ bool is_closed_one_form(const Mesh& m, const VectorX& one_form) return true; } -MatrixX build_dual_loop_basis_one_form_matrix( - const Mesh& m, - const std::vector>& dual_loops) -{ - int num_loops = dual_loops.size(); - int num_halfedges = m.n_halfedges(); - - // Columns of matrix are signed segment halfedge indicators - typedef Eigen::Triplet T; - std::vector tripletList; - tripletList.reserve(num_halfedges); - for (int i = 0; i < num_loops; ++i) { - for (const auto& dual_segment : *dual_loops[i]) { - tripletList.push_back(T(dual_segment[0], i, -1.0)); - tripletList.push_back(T(dual_segment[1], i, 1.0)); - } - } - - // Create the matrix from the triplets - MatrixX one_form_matrix; - one_form_matrix.resize(num_halfedges, num_loops); - one_form_matrix.reserve(tripletList.size()); - one_form_matrix.setFromTriplets(tripletList.begin(), tripletList.end()); - return one_form_matrix; -} - -MatrixX build_closed_one_form_matrix( - const Mesh& m, - const std::vector>& homology_basis_loops, - bool eliminate_vertex) -{ - // Initialize matrix triplet list - int num_halfedges = m.n_halfedges(); - typedef Eigen::Triplet T; - std::vector tripletList; - tripletList.reserve(2 * num_halfedges); - - // Build v_rep - std::vector v_rep; - int num_vertex_forms; - if (eliminate_vertex) { - Optimization::build_free_vertex_map(m, v_rep, num_vertex_forms); - } else { - v_rep = m.v_rep; - num_vertex_forms = m.n_ind_vertices(); - } - - // Add vertex basis forms - for (int h = 0; h < num_halfedges; ++h) { - int v0 = v_rep[m.to[h]]; - if (v0 >= 0) { - tripletList.push_back(T(h, v0, 1.0)); - } - - int v1 = v_rep[m.to[m.opp[h]]]; - if (v1 >= 0) { - tripletList.push_back(T(h, v1, -1.0)); - } - } - - // Add homology basis forms - int num_loops = homology_basis_loops.size(); - for (int i = 0; i < num_loops; ++i) { - for (const auto& dual_segment : *homology_basis_loops[i]) { - tripletList.push_back(T(dual_segment[0], num_vertex_forms + i, -1.0)); - tripletList.push_back(T(dual_segment[1], num_vertex_forms + i, 1.0)); - } - } - - // Create the matrix from the triplets - MatrixX one_form_matrix(num_halfedges, num_vertex_forms + num_loops); - one_form_matrix.reserve(tripletList.size()); - one_form_matrix.setFromTriplets(tripletList.begin(), tripletList.end()); - return one_form_matrix; -} - MatrixX build_one_form_integral_matrix( const Mesh& m, const std::vector& cut_h, diff --git a/src/holonomy/field/frame_field.cpp b/src/field/frame_field.cpp similarity index 89% rename from src/holonomy/field/frame_field.cpp rename to src/field/frame_field.cpp index d4eb1e7..457fc49 100644 --- a/src/holonomy/field/frame_field.cpp +++ b/src/field/frame_field.cpp @@ -1,10 +1,17 @@ -#include "holonomy/field/frame_field.h" -#include "holonomy/holonomy/constraint.h" -#include "holonomy/core/dual_loop.h" -#include "holonomy/holonomy/holonomy.h" -#include "optimization/parameterization/refinement.h" -#include "holonomy/core/viewer.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "field/frame_field.h" +#include "parametrization/refinement.h" #include "util/vf_mesh.h" +#include "util/vector.h" +#include "util/linear_algebra.h" +#include "util/map.h" #include #include @@ -18,7 +25,7 @@ // TODO: Cleaning pass namespace Penner { -namespace Holonomy { +namespace Field { Eigen::Vector3d generate_reference_direction( const Eigen::MatrixXd& V, @@ -64,7 +71,7 @@ Eigen::MatrixXd generate_reference_field( return reference_field; } -Eigen::MatrixXd generate_field( +Eigen::MatrixXd generate_frame_field( const Eigen::MatrixXd& V, const Eigen::MatrixXi& F, const Eigen::MatrixXd& reference_field, @@ -75,6 +82,31 @@ Eigen::MatrixXd generate_field( return igl::rotate_vectors(reference_field, theta, B1, B2); } +void write_rosy_field( + const std::string& output_filename, + const Eigen::MatrixXd& V, + const Eigen::MatrixXi& F, + const Eigen::MatrixXd& reference_field, + const Eigen::VectorXd& theta) +{ + Eigen::MatrixXd rosy_field = generate_frame_field(V, F, reference_field, theta); + + std::ofstream field_file(output_filename, std::ios::out | std::ios::trunc); + field_file << F.rows() << std::endl; + field_file << "4" << std::endl; + for (int f = 0; f < F.rows(); ++f) + { + for (int j : {0 , 1, 2}) + { + field_file << std::fixed << std::setprecision(17) << rosy_field(f, j) << " "; + } + + field_file << std::endl; + } + + field_file.close(); +} + // difference of principal curvatures relative to their total magnitude Scalar compute_relative_anisotropy(Scalar max_val, Scalar min_val) { @@ -110,9 +142,9 @@ std::tuple> compute_field_direction( Scalar rel_threshold, Scalar sample_rate) { - //auto[max_direction, min_direction, _max_curvature, _min_curvature] = Holonomy::compute_facet_principal_curvature(V, F, radius); - //auto[_max_direction, _min_direction, max_curvature, min_curvature] = Holonomy::compute_facet_principal_curvature(V, F, 3); - auto[max_direction, min_direction, max_curvature, min_curvature] = Holonomy::compute_facet_principal_curvature(V, F, radius); + //auto[max_direction, min_direction, _max_curvature, _min_curvature] = compute_facet_principal_curvature(V, F, radius); + //auto[_max_direction, _min_direction, max_curvature, min_curvature] = compute_facet_principal_curvature(V, F, 3); + auto[max_direction, min_direction, max_curvature, min_curvature] = compute_facet_principal_curvature(V, F, radius); int num_faces = F.rows(); std::vector is_fixed_direction(num_faces, false); for (int fijk = 0; fijk < num_faces; ++fijk) @@ -174,7 +206,7 @@ generate_frame_field( std::vector face_map = generate_face_map(m); // initalize field generator - Holonomy::IntrinsicNRosyField field_generator; + IntrinsicNRosyField field_generator; field_generator.min_cone = field_params.min_cone; field_generator.use_roundings= field_params.use_roundings; field_generator.initialize(m); @@ -215,8 +247,8 @@ generate_frame_field( is_fixed[i] = is_fixed_direction[fijk]; // convert extrinsic direction to intrinsic angle - Eigen::Vector3d reference_direction = Holonomy::generate_reference_direction(V, F, fijk, reference_corner[fijk]); - target_theta[i] = -Holonomy::signed_angle(direction.row(fijk), reference_direction, N.row(fijk)); + Eigen::Vector3d reference_direction = generate_reference_direction(V, F, fijk, reference_corner[fijk]); + target_theta[i] = -signed_angle(direction.row(fijk), reference_direction, N.row(fijk)); } // set fixed directions @@ -241,7 +273,7 @@ generate_frame_field( field_generator.get_field(m, vtx_reindex, F, face_map, reference_corner, theta, kappa, period_jump); // convert face corner to tangent direction - Eigen::MatrixXd reference_field = Holonomy::generate_reference_field(V, F, reference_corner); + Eigen::MatrixXd reference_field = generate_reference_field(V, F, reference_corner); return std::make_tuple(reference_field, theta, kappa, period_jump); } @@ -288,6 +320,47 @@ void write_frame_field( field_file.close(); } +Eigen::MatrixXd load_rosy_field(const std::string& input_filename) +{ + // Open file + spdlog::debug("opening field at {}", input_filename); + std::ifstream input_file(input_filename); + if (!input_file) return {}; + + // get number of faces + std::string line; + std::getline(input_file, line); + std::istringstream iss(line); + int num_faces; + iss >> num_faces; + spdlog::debug("{} faces", num_faces); + std::getline(input_file, line); // skip start line + + // initialize vectors + Eigen::MatrixXd frame_field(num_faces, 3); + + // Read file one face at a time + int f = 0; + while ((f < num_faces) && (std::getline(input_file, line))) { + std::istringstream iss(line); + for (int i : {0 , 1, 2}) + { + iss >> frame_field(f, i); + } + + ++f; + } + + if (num_faces != f) + { + spdlog::error("Number of faces inconsistent with number of lines"); + } + + // Close file + input_file.close(); + return frame_field; +} + Eigen::VectorXd rotate_vector( const Eigen::VectorXd& vec, double angle, @@ -691,8 +764,8 @@ std::tuple r // TODO: make version that does not require uv map Eigen::MatrixXi F_orig, F_uv_orig, halfedge_map; std::vector, 3>> corner_v_points, corner_uv_points; - std::vector> F_to_Fn = Optimization::build_F_to_Fn(Fn_to_F); - Optimization::build_faces( + std::vector> F_to_Fn = build_F_to_Fn(Fn_to_F); + build_faces( F, F_uv, F_to_Fn, @@ -796,4 +869,4 @@ Eigen::VectorXi transfer_period_jumps_to_halfedge( } // namespace Holonomy -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/holonomy/field/intrinsic_field.cpp b/src/field/intrinsic_field.cpp similarity index 89% rename from src/holonomy/field/intrinsic_field.cpp rename to src/field/intrinsic_field.cpp index d4349e8..3eabc2a 100644 --- a/src/holonomy/field/intrinsic_field.cpp +++ b/src/field/intrinsic_field.cpp @@ -1,23 +1,36 @@ -#include "holonomy/field/intrinsic_field.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. +#include "field/intrinsic_field.h" + +#if USE_COMISO #include +#include "field/comiso.h" #include #include #include #include +#endif #include #include #include -#include "holonomy/field/field.h" +#include "field/field.h" #include "util/spanning_tree.h" #include "util/boundary.h" -#include "holonomy/core/viewer.h" -#include "holonomy/field/forms.h" +#include "field/forms.h" +#include "field/rounder.h" -#include "optimization/core/constraint.h" +#include "metric/constraint.h" +#include "metric/viewer.h" #include "util/vector.h" +#include "util/linear_algebra.h" #include @@ -27,132 +40,8 @@ #endif namespace Penner { -namespace Holonomy { - -class Rounder { -public: - Rounder( - const Mesh& m, - const std::vector& _var2he, - const std::vector& _halfedge_var_id, - const std::vector& _base_cones, - const std::vector& _min_cones) - : var2he(_var2he) - , halfedge_var_id(_halfedge_var_id) - , base_cones(_base_cones) - , min_cones(_min_cones) - , is_rounded(m.n_halfedges(), false) - , values(m.n_halfedges(), 0) - , to(vector_compose(m.v_rep, m.to)) - , opp(m.opp) - , is_double(m.type[0] > 0) - { - int num_halfedges = m.n_halfedges(); - int num_vertices = m.n_ind_vertices(); - cone_period_jumps = std::vector>(num_vertices, std::vector()); - for (int hij = 0; hij < num_halfedges; ++hij) - { - // only add variable period jumps - if (halfedge_var_id[hij] == -1) continue; - - // add halfedge to tip - int vj = m.v_rep[m.to[hij]]; - cone_period_jumps[vj].push_back(hij); - - // add opposite halfedge to base - int hji = m.opp[hij]; - int vi = m.v_rep[m.to[hji]]; - cone_period_jumps[vi].push_back(hji); - } - } - - int compute_cone_correction(int hij) - { - int vj = to[hij]; - int cone = base_cones[vj]; - for (int h : cone_period_jumps[vj]) - { - cone += (is_double) ? (2 * values[h]) : values[h]; - } - - return (min_cones[vj] - cone); - } - - bool is_zero_cone(int hij) - { - int vj = to[hij]; - int cone = base_cones[vj]; - for (int h : cone_period_jumps[vj]) - { - if ((h != hij) && (!is_rounded[h])) return false; - cone += (is_double) ? (2 * values[h]) : values[h]; - } - - return (cone < min_cones[vj]); - } - - int test_round(int id, Scalar x) - { - int hij = var2he[id]; - //int rounded_value = ((x)<0?int((x)-0.5):int((x)+0.5)); - int rounded_value = lround(x); - int hji = opp[hij]; - values[hij] = rounded_value; - values[hji] = -rounded_value; - bool is_tip_cone = is_zero_cone(hij); - bool is_base_cone = is_zero_cone(hji); - - if ((is_tip_cone) && (is_base_cone)) - { - spdlog::warn("Cone at both tip and base of period jump halfedge"); - return rounded_value; - } - if (is_tip_cone) - { - spdlog::trace("Cone at tip of period jump halfedge"); - int n = compute_cone_correction(hij); - if (n > 1) spdlog::trace("correction at tip is {}", n); - if (n < 0) spdlog::error("correction at tip is {}", n); - return rounded_value + n; - } - if (is_base_cone) - { - spdlog::trace("Cone at base of period jump halfedge"); - int n = compute_cone_correction(hji); - if (n > 1) spdlog::trace("correction at base is {}", n); - if (n < 0) spdlog::error("correction at tip is {}", n); - return rounded_value - n; - } - - return rounded_value; - - } +namespace Field { - int commit_round(int id, Scalar x) - { - int rounded_value = test_round(id, x); - int hij = var2he[id]; - int hji = opp[hij]; - values[hij] = rounded_value; - values[hji] = -rounded_value; - is_rounded[hij] = true; - is_rounded[hji] = true; - return rounded_value; - } - -private: - std::vector var2he; - std::vector halfedge_var_id; - std::vector base_cones; - std::vector min_cones; - std::vector is_rounded; - std::vector values; - std::vector> cone_period_jumps; - std::vector to; - std::vector opp; - bool is_double; - -}; Eigen::MatrixXd transfer_vertex_direction_to_corner( const Eigen::MatrixXi& F, @@ -448,7 +337,7 @@ void IntrinsicNRosyField::initialize_local_frames(const Mesh& m) void IntrinsicNRosyField::initialize_kappa(const Mesh& m) { // Compute corner angles - Optimization::corner_angles(m, he2angle, he2cot); + corner_angles(m, he2angle, he2cot); // Compute the angle between reference halfedges across faces int num_halfedges = m.n_halfedges(); @@ -469,7 +358,7 @@ void IntrinsicNRosyField::initialize_priority_kappa( const std::vector& vtx_reindex) { // Compute corner angles - Optimization::corner_angles(m, he2angle, he2cot); + corner_angles(m, he2angle, he2cot); // Compute the angle between reference halfedges across faces int num_halfedges = m.n_halfedges(); @@ -640,7 +529,7 @@ Eigen::MatrixXd IntrinsicNRosyField::generate_reference_field( void IntrinsicNRosyField::initialize_double_kappa(const Mesh& m) { // Compute corner angles - Optimization::corner_angles(m, he2angle, he2cot); + corner_angles(m, he2angle, he2cot); // Compute the angle between reference halfedges across faces int num_halfedges = m.n_halfedges(); @@ -662,7 +551,7 @@ void IntrinsicNRosyField::initialize_double_kappa(const Mesh& m) void IntrinsicNRosyField::initialize_double_priority_kappa(const Mesh& m, const std::vector& vtx_reindex) { // Compute corner angles - Optimization::corner_angles(m, he2angle, he2cot); + corner_angles(m, he2angle, he2cot); // Compute the angle between reference halfedges across faces int num_halfedges = m.n_halfedges(); @@ -1432,168 +1321,6 @@ void IntrinsicNRosyField::initialize_double_mixed_integer_system(const Mesh 2) std::cerr << "initial full solution" << std::endl; - direct_solver_.calc_system_gmm(_A); - direct_solver_.solve(_x, _rhs); - - cholmod_step_done_ = true; - - ++n_full_; - } - - // neighbors for local optimization - Vecui neigh_i; - - // Vector for reduced solution - Vecd xr(_x); - - // loop until solution computed - for(unsigned int i=0; i 0) - { - std::cerr << "Integer DOF's left: " << to_round.size()-(i+1) << " "; - if( noisy_ > 1) - std::cerr << "residuum_norm: " << COMISO_GMM::residuum_norm( _A, xr, _rhs) << std::endl; - } - - // position in round vector - std::vector tr_best; - - sw.start(); - - RoundingSet rset; - rset.set_threshold(multiple_rounding_threshold_); - - // find index yielding smallest rounding error - for(unsigned int j=0; j 5) - std::cerr << "round " << tr_best.size() << " variables simultaneously\n"; - - // clear neigh for local update - neigh_i.clear(); - - for(unsigned int j = 0; j 2) std::cerr << "final full solution" << std::endl; - - if( gmm::mat_ncols( _A) > 0) - { - if(cholmod_step_done_) - direct_solver_.update_system_gmm(_A); - else - direct_solver_.calc_system_gmm(_A); - - direct_solver_.solve( xr, _rhs); - ++n_full_; - } - } - - // store solution values to result vector - for(unsigned int i=0; i generate_min_cones(const Mesh& m, int min_cone) { int num_vertices = m.n_ind_vertices(); @@ -1666,6 +1393,9 @@ void IntrinsicNRosyField::solve(const Mesh& m) { min_cones = generate_min_cones(m, min_cone); } + + +#if USE_COMISO if (use_roundings) { Rounder rounder(m, var2he, halfedge_var_id, base_cones, min_cones); @@ -1677,6 +1407,10 @@ void IntrinsicNRosyField::solve(const Mesh& m) COMISO::MISolver cs; cs.solve(Acsc, x, gmm_b, var_edges); } +#else + spdlog::error("cannot optimize field without CoMISo"); + return; +#endif // Copy the face angles int num_faces = m.n_faces(); @@ -1706,7 +1440,7 @@ std::vector generate_cones_from_rotation_form_FIXME( { // Compute the corner angles VectorX he2angle, he2cot; - Optimization::corner_angles(m, he2angle, he2cot); + corner_angles(m, he2angle, he2cot); // Compute cones from the rotation form as holonomy - rotation around each vertex // Per-halfedge iteration is used for faster computation @@ -1728,7 +1462,6 @@ std::vector generate_cones_from_rotation_form_FIXME( void IntrinsicNRosyField::compute_principal_matchings(const Mesh& m) { int num_halfedges = m.n_halfedges(); - VectorX rotation_form(num_halfedges); for (int hij = 0; hij < num_halfedges; ++hij) { if (hij < m.opp[hij]) continue; int hji = m.opp[hij]; @@ -2126,7 +1859,7 @@ std::vector IntrinsicNRosyField::generate_base_cones(const Mesh& m) { // Compute the corner angles VectorX he2angle, he2cot; - Optimization::corner_angles(m, he2angle, he2cot); + corner_angles(m, he2angle, he2cot); std::vector is_variable(m.n_halfedges(), false); for (int hij = 0; hij < m.n_halfedges(); hij++) { @@ -2163,7 +1896,7 @@ std::vector IntrinsicNRosyField::generate_kappa_cones(const Mesh& m { // Compute the corner angles VectorX he2angle, he2cot; - Optimization::corner_angles(m, he2angle, he2cot); + corner_angles(m, he2angle, he2cot); int num_vertices = m.n_ind_vertices(); std::vector Th_hat(num_vertices, 0); @@ -2185,7 +1918,7 @@ std::vector IntrinsicNRosyField::generate_cones(const Mesh& m) cons { // Compute the corner angles VectorX he2angle, he2cot; - Optimization::corner_angles(m, he2angle, he2cot); + corner_angles(m, he2angle, he2cot); int num_vertices = m.n_ind_vertices(); std::vector Th_hat(num_vertices, 0); @@ -2522,11 +2255,11 @@ void IntrinsicNRosyField::update_viewer( { // Compute the corner angles VectorX he2angle, he2cot; - Optimization::corner_angles(m, he2angle, he2cot); + corner_angles(m, he2angle, he2cot); // Initialize viewer auto [V_double, F_mesh, F_halfedge] = generate_doubled_mesh(V, m, vtx_reindex); - Optimization::view_dual_graph(V, m, vtx_reindex, is_period_jump_fixed); + view_dual_graph(V, m, vtx_reindex, is_period_jump_fixed); VectorX kappa_mesh = generate_FV_halfedge_data(F_halfedge, kappa); VectorX period_jump_scaled(period_jump.size()); int num_halfedges = m.n_halfedges(); @@ -2809,6 +2542,59 @@ void IntrinsicNRosyField::set_field( } } +void IntrinsicNRosyField::set_theta( + const Mesh& m, + const Eigen::VectorXd& face_theta) +{ + int num_faces = m.n_faces(); + for (int fijk = 0; fijk < num_faces; ++fijk) + { + // get reference halfedge + int hij = m.h[fijk]; + + // only process original faces + if (m.type[hij] == 2) continue; + + // record face angles + theta[fijk] = Scalar(face_theta[fijk]); + + // skip doubling on closed mesh + if (m.type[hij] == 0) continue; + + // invert theta on reflected face + int fjik = m.f[m.R[hij]]; + theta[fjik] = M_PI - theta[fijk]; + } +} + + +void IntrinsicNRosyField::set_field( + const Mesh& m, + const std::vector& vtx_reindex, + const Eigen::MatrixXi& F, + const Eigen::VectorXd& face_theta, + const Eigen::MatrixXd& corner_kappa, + const Eigen::MatrixXi& corner_period_jump) +{ + std::vector face_reindex; + arange(F.rows(), face_reindex); + set_field(m, vtx_reindex, F, face_reindex, face_theta, corner_kappa, corner_period_jump); +} + +void IntrinsicNRosyField::get_field( + const Mesh& m, + const std::vector& vtx_reindex, + const Eigen::MatrixXi& F, + Eigen::VectorXi& reference_corner, + Eigen::VectorXd& face_theta, + Eigen::MatrixXd& corner_kappa, + Eigen::MatrixXi& corner_period_jump) const +{ + std::vector face_reindex; + arange(F.rows(), face_reindex); + get_field(m, vtx_reindex, F, face_reindex, reference_corner, face_theta, corner_kappa, corner_period_jump); +} + void IntrinsicNRosyField::set_halfedge_field( const Mesh& m, const Eigen::VectorXd& face_theta, @@ -2820,4 +2606,4 @@ void IntrinsicNRosyField::set_halfedge_field( period_jump = halfedge_period_jump; } } // namespace Holonomy -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/field/rounder.cpp b/src/field/rounder.cpp new file mode 100644 index 0000000..4c129d9 --- /dev/null +++ b/src/field/rounder.cpp @@ -0,0 +1,303 @@ +#include "field/rounder.h" + +namespace Penner { +namespace Field { + +class Rounder { +public: + Rounder( + const Mesh& m, + const std::vector& _var2he, + const std::vector& _halfedge_var_id, + const std::vector& _base_cones, + const std::vector& _min_cones) + : var2he(_var2he) + , halfedge_var_id(_halfedge_var_id) + , base_cones(_base_cones) + , min_cones(_min_cones) + , is_rounded(m.n_halfedges(), false) + , values(m.n_halfedges(), 0) + , to(vector_compose(m.v_rep, m.to)) + , opp(m.opp) + , is_double(m.type[0] > 0) + { + int num_halfedges = m.n_halfedges(); + int num_vertices = m.n_ind_vertices(); + cone_period_jumps = std::vector>(num_vertices, std::vector()); + for (int hij = 0; hij < num_halfedges; ++hij) + { + // only add variable period jumps + if (halfedge_var_id[hij] == -1) continue; + + // add halfedge to tip + int vj = m.v_rep[m.to[hij]]; + cone_period_jumps[vj].push_back(hij); + + // add opposite halfedge to base + int hji = m.opp[hij]; + int vi = m.v_rep[m.to[hji]]; + cone_period_jumps[vi].push_back(hji); + } + } + + int compute_cone_correction(int hij) + { + int vj = to[hij]; + int cone = base_cones[vj]; + for (int h : cone_period_jumps[vj]) + { + cone += (is_double) ? (2 * values[h]) : values[h]; + } + + return (min_cones[vj] - cone); + } + + bool is_zero_cone(int hij) + { + int vj = to[hij]; + int cone = base_cones[vj]; + for (int h : cone_period_jumps[vj]) + { + if ((h != hij) && (!is_rounded[h])) return false; + cone += (is_double) ? (2 * values[h]) : values[h]; + } + + return (cone < min_cones[vj]); + } + + int test_round(int id, Scalar x) + { + int hij = var2he[id]; + //int rounded_value = ((x)<0?int((x)-0.5):int((x)+0.5)); + int rounded_value = lround(x); + int hji = opp[hij]; + values[hij] = rounded_value; + values[hji] = -rounded_value; + bool is_tip_cone = is_zero_cone(hij); + bool is_base_cone = is_zero_cone(hji); + + if ((is_tip_cone) && (is_base_cone)) + { + spdlog::warn("Cone at both tip and base of period jump halfedge"); + return rounded_value; + } + if (is_tip_cone) + { + spdlog::trace("Cone at tip of period jump halfedge"); + int n = compute_cone_correction(hij); + if (n > 1) spdlog::trace("correction at tip is {}", n); + if (n < 0) spdlog::error("correction at tip is {}", n); + return rounded_value + n; + } + if (is_base_cone) + { + spdlog::trace("Cone at base of period jump halfedge"); + int n = compute_cone_correction(hji); + if (n > 1) spdlog::trace("correction at base is {}", n); + if (n < 0) spdlog::error("correction at tip is {}", n); + return rounded_value - n; + } + + return rounded_value; + + } + + int commit_round(int id, Scalar x) + { + int rounded_value = test_round(id, x); + int hij = var2he[id]; + int hji = opp[hij]; + values[hij] = rounded_value; + values[hji] = -rounded_value; + is_rounded[hij] = true; + is_rounded[hji] = true; + return rounded_value; + } + +private: + std::vector var2he; + std::vector halfedge_var_id; + std::vector base_cones; + std::vector min_cones; + std::vector is_rounded; + std::vector values; + std::vector> cone_period_jumps; + std::vector to; + std::vector opp; + bool is_double; + +}; + +// WARNING: CoMISo uses a more restrictive copyleft license +#if USE_COMISO +#include +#include +#include + + +// TODO Make option and make cone rounder code public +class ConeMISolver : public COMISO::MISolver +{ +public: + ConeMISolver() {}; + void solve_cone_rounding( + CSCMatrix& _A, + Vecd& _x, + Vecd& _rhs, + Veci& _to_round, + Rounder& rounder) { + // StopWatch + COMISO::StopWatch sw; + double time_search_next_integer = 0; + + // some statistics + n_local_ = 0; + n_cg_ = 0; + n_full_ = 0; + + // reset cholmod step flag + cholmod_step_done_ = false; + + Veci to_round(_to_round); + // copy to round vector and make it unique + std::sort(to_round.begin(), to_round.end()); + Veci::iterator last_unique; + last_unique = std::unique(to_round.begin(), to_round.end()); + int r = last_unique - to_round.begin(); + to_round.resize( r); + + // initalize old indices + Veci old_idx(_rhs.size()); + for(unsigned int i=0; i 2) std::cerr << "initial full solution" << std::endl; + direct_solver_.calc_system_gmm(_A); + direct_solver_.solve(_x, _rhs); + + cholmod_step_done_ = true; + + ++n_full_; + } + + // neighbors for local optimization + Vecui neigh_i; + + // Vector for reduced solution + Vecd xr(_x); + + // loop until solution computed + for(unsigned int i=0; i 0) + { + std::cerr << "Integer DOF's left: " << to_round.size()-(i+1) << " "; + if( noisy_ > 1) + std::cerr << "residuum_norm: " << COMISO_GMM::residuum_norm( _A, xr, _rhs) << std::endl; + } + + // position in round vector + std::vector tr_best; + + sw.start(); + + RoundingSet rset; + rset.set_threshold(multiple_rounding_threshold_); + + // find index yielding smallest rounding error + for(unsigned int j=0; j 5) + std::cerr << "round " << tr_best.size() << " variables simultaneously\n"; + + // clear neigh for local update + neigh_i.clear(); + + for(unsigned int j = 0; j 2) std::cerr << "final full solution" << std::endl; + + if( gmm::mat_ncols( _A) > 0) + { + if(cholmod_step_done_) + direct_solver_.update_system_gmm(_A); + else + direct_solver_.calc_system_gmm(_A); + + direct_solver_.solve( xr, _rhs); + ++n_full_; + } + } + + // store solution values to result vector + for(unsigned int i=0; i +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/core/boundary_basis.h" #include "holonomy/core/dual_lengths.h" diff --git a/src/holonomy/core/common.cpp b/src/holonomy/core/common.cpp index ce3279e..ad4d109 100644 --- a/src/holonomy/core/common.cpp +++ b/src/holonomy/core/common.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/core/common.h" namespace Penner { diff --git a/src/holonomy/core/dual_lengths.cpp b/src/holonomy/core/dual_lengths.cpp index f4ad34a..e370e87 100644 --- a/src/holonomy/core/dual_lengths.cpp +++ b/src/holonomy/core/dual_lengths.cpp @@ -1,6 +1,14 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/core/dual_lengths.h" -#include "optimization/core/constraint.h" +#include "metric/constraint.h" #include @@ -14,7 +22,7 @@ std::vector compute_dual_edge_lengths(const Mesh& m) // Compute cotangent angles VectorX he2angle, he2cot; - Optimization::corner_angles(m, he2angle, he2cot); + corner_angles(m, he2angle, he2cot); for (int hij = 0; hij < num_halfedges; ++hij) { // Only process halfedge with lower index @@ -177,4 +185,4 @@ std::vector compute_dual_loop_length_weights( } } // namespace Holonomy -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/holonomy/core/dual_loop.cpp b/src/holonomy/core/dual_loop.cpp index 01d14f7..0a07094 100644 --- a/src/holonomy/core/dual_loop.cpp +++ b/src/holonomy/core/dual_loop.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/core/dual_loop.h" #include #include diff --git a/src/holonomy/core/dual_segment.cpp b/src/holonomy/core/dual_segment.cpp index e339446..fa7e027 100644 --- a/src/holonomy/core/dual_segment.cpp +++ b/src/holonomy/core/dual_segment.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/core/dual_segment.h" #include #include diff --git a/src/holonomy/core/homology_basis.cpp b/src/holonomy/core/homology_basis.cpp index 26d84c3..6a69ce4 100644 --- a/src/holonomy/core/homology_basis.cpp +++ b/src/holonomy/core/homology_basis.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/core/homology_basis.h" #include "util/vector.h" diff --git a/src/holonomy/core/quality.cpp b/src/holonomy/core/quality.cpp index 86edb1b..73a2b37 100644 --- a/src/holonomy/core/quality.cpp +++ b/src/holonomy/core/quality.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/core/quality.h" namespace Penner { diff --git a/src/holonomy/core/viewer.cpp b/src/holonomy/core/viewer.cpp index daf7e02..95e29e1 100644 --- a/src/holonomy/core/viewer.cpp +++ b/src/holonomy/core/viewer.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/core/viewer.h" @@ -16,8 +24,8 @@ #include "util/vector.h" #include "util/vf_mesh.h" #include "holonomy/holonomy/constraint.h" -#include "holonomy/field/frame_field.h" -#include "optimization/core/viewer.h" +#include "field/frame_field.h" +#include "metric/viewer.h" #ifdef ENABLE_VISUALIZATION #include "polyscope/curve_network.h" @@ -57,7 +65,7 @@ void view_frame_field( if (num_cones != num_vertices) return; // Generate cones - auto [cone_positions, cone_values] = Optimization::generate_cone_vertices(V, Th_hat); + auto [cone_positions, cone_values] = generate_cone_vertices(V, Th_hat); // Generate rotated cross field vectors from reference std::array cross_field; @@ -138,7 +146,7 @@ void view_cross_field( } // generate frame field geometry from cross field - Eigen::MatrixXd frame_field = Holonomy::generate_field(V, F, reference_field, theta); + Eigen::MatrixXd frame_field = Field::generate_frame_field(V, F, reference_field, theta); int num_faces = F.rows(); // transfer kappa and period jump to viewer halfedge indexing @@ -155,8 +163,8 @@ void view_cross_field( } // get cone angles - std::vector Th_hat = compute_cone_angle(V, F, kappa, period_jump); - auto [cone_positions, cone_values] = Optimization::generate_cone_vertices(V, Th_hat); + std::vector Th_hat = Field::compute_cone_angle(V, F, kappa, period_jump); + auto [cone_positions, cone_values] = generate_cone_vertices(V, Th_hat); #ifdef ENABLE_VISUALIZATION polyscope::init(); @@ -214,7 +222,7 @@ void view_rotation_form( // Generate cones spdlog::info("{} vertices", Th_hat.size()); //auto [cone_positions, cone_values] = Optimization::generate_cone_vertices(V, vtx_reindex, m); - auto [cone_positions, cone_values] = Optimization::generate_cone_vertices(V, Th_hat); + auto [cone_positions, cone_values] = generate_cone_vertices(V, Th_hat); #ifdef ENABLE_VISUALIZATION polyscope::init(); @@ -389,7 +397,7 @@ void view_constraint_error( if (show) { spdlog::info("Viewing {} mesh with {} vertices", mesh_handle, num_vertices); } - auto [V_double, F_mesh, F_halfedge] = Optimization::generate_doubled_mesh(V, marked_metric, vtx_reindex); + auto [V_double, F_mesh, F_halfedge] = generate_doubled_mesh(V, marked_metric, vtx_reindex); // Make mesh into discrete metric spdlog::debug("Making metric discrete"); @@ -405,7 +413,7 @@ void view_constraint_error( // Generate cones and cone errors spdlog::debug("Computing cones and errors"); VectorX vertex_constraint = compute_vertex_constraint(marked_metric_copy, he2angle); - auto [cone_positions, cone_values] = Optimization::generate_cone_vertices(V, vtx_reindex, marked_metric); + auto [cone_positions, cone_values] = generate_cone_vertices(V, vtx_reindex, marked_metric); VectorX cone_error = vector_compose(vertex_constraint, marked_metric.v_rep); #ifdef ENABLE_VISUALIZATION @@ -498,8 +506,8 @@ void view_seamless_parameterization( VectorX area, uv_area; igl::doublearea(V_cut, FT, area); igl::doublearea(uv, FT, uv_area); - VectorX corner_angles = Optimization::compute_corner_angles(V_cut, FT); - VectorX uv_corner_angles = Optimization::compute_corner_angles(uv, FT); + VectorX corner_angles = compute_corner_angles(V_cut, FT); + VectorX uv_corner_angles = compute_corner_angles(uv, FT); spdlog::info("Max uv length error: {}", uv_length_error.maxCoeff()); spdlog::info("Max uv angle error: {}", uv_angle_error.maxCoeff()); spdlog::info("Min embedding area: {}", area.minCoeff()); @@ -510,7 +518,7 @@ void view_seamless_parameterization( VectorX cone_angles = compute_cone_angles(V, F, uv, FT); std::vector cone_angles_vec; convert_eigen_to_std_vector(cone_angles, cone_angles_vec); - auto [cone_positions, cone_values] = Optimization::generate_cone_vertices(V, cone_angles_vec); + auto [cone_positions, cone_values] = generate_cone_vertices(V, cone_angles_vec); VectorX cone_error(cone_values.size()); for (int i = 0; i < cone_values.size(); ++i) { @@ -646,4 +654,4 @@ void view_homology_basis( } // namespace Holonomy -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/holonomy/holonomy/cones.cpp b/src/holonomy/holonomy/cones.cpp index 44cf983..64ba7be 100644 --- a/src/holonomy/holonomy/cones.cpp +++ b/src/holonomy/holonomy/cones.cpp @@ -1,10 +1,18 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/holonomy/cones.h" #include "util/boundary.h" -#include "holonomy/field/forms.h" +#include "field/forms.h" #include "holonomy/holonomy/holonomy.h" -#include "optimization/core/constraint.h" +#include "metric/constraint.h" #include @@ -19,7 +27,7 @@ bool validate_cones_from_rotation_form( { // Compute the corner angles VectorX he2angle, he2cot; - Optimization::corner_angles(m, he2angle, he2cot); + corner_angles(m, he2angle, he2cot); // Get boundary vertices if symmetric mesh with boundary int num_vertices = m.n_vertices(); @@ -68,10 +76,10 @@ std::vector generate_cones_from_rotation_form( const Mesh& m, const VectorX& rotation_form) { - assert(is_valid_one_form(m, rotation_form)); + assert(Field::is_valid_one_form(m, rotation_form)); // Compute the corner angles VectorX he2angle, he2cot; - Optimization::corner_angles(m, he2angle, he2cot); + corner_angles(m, he2angle, he2cot); // Compute cones from the rotation form as holonomy - rotation around each vertex // Per-halfedge iteration is used for faster computation @@ -472,4 +480,4 @@ void make_interior_free(Mesh& m) } } // namespace Holonomy -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/holonomy/holonomy/constraint.cpp b/src/holonomy/holonomy/constraint.cpp index 7f4db09..cd9fe9f 100644 --- a/src/holonomy/holonomy/constraint.cpp +++ b/src/holonomy/holonomy/constraint.cpp @@ -1,8 +1,16 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/holonomy/constraint.h" #include "holonomy/holonomy/holonomy.h" -#include "optimization/core/constraint.h" +#include "metric/constraint.h" namespace Penner { namespace Holonomy { @@ -28,12 +36,89 @@ VectorX Kappa(const MarkedPennerConeMetric& marked_metric, const VectorX& alpha) return Kappa(marked_metric, homology_basis_loops, alpha); } +MatrixX build_dual_loop_basis_one_form_matrix( + const Mesh& m, + const std::vector>& dual_loops) +{ + int num_loops = dual_loops.size(); + int num_halfedges = m.n_halfedges(); + + // Columns of matrix are signed segment halfedge indicators + typedef Eigen::Triplet T; + std::vector tripletList; + tripletList.reserve(num_halfedges); + for (int i = 0; i < num_loops; ++i) { + for (const auto& dual_segment : *dual_loops[i]) { + tripletList.push_back(T(dual_segment[0], i, -1.0)); + tripletList.push_back(T(dual_segment[1], i, 1.0)); + } + } + + // Create the matrix from the triplets + MatrixX one_form_matrix; + one_form_matrix.resize(num_halfedges, num_loops); + one_form_matrix.reserve(tripletList.size()); + one_form_matrix.setFromTriplets(tripletList.begin(), tripletList.end()); + return one_form_matrix; +} + +MatrixX build_closed_one_form_matrix( + const Mesh& m, + const std::vector>& homology_basis_loops, + bool eliminate_vertex) +{ + // Initialize matrix triplet list + int num_halfedges = m.n_halfedges(); + typedef Eigen::Triplet T; + std::vector tripletList; + tripletList.reserve(2 * num_halfedges); + + // Build v_rep + std::vector v_rep; + int num_vertex_forms; + if (eliminate_vertex) { + build_free_vertex_map(m, v_rep, num_vertex_forms); + } else { + v_rep = m.v_rep; + num_vertex_forms = m.n_ind_vertices(); + } + + // Add vertex basis forms + for (int h = 0; h < num_halfedges; ++h) { + int v0 = v_rep[m.to[h]]; + if (v0 >= 0) { + tripletList.push_back(T(h, v0, 1.0)); + } + + int v1 = v_rep[m.to[m.opp[h]]]; + if (v1 >= 0) { + tripletList.push_back(T(h, v1, -1.0)); + } + } + + // Add homology basis forms + int num_loops = homology_basis_loops.size(); + for (int i = 0; i < num_loops; ++i) { + for (const auto& dual_segment : *homology_basis_loops[i]) { + tripletList.push_back(T(dual_segment[0], num_vertex_forms + i, -1.0)); + tripletList.push_back(T(dual_segment[1], num_vertex_forms + i, 1.0)); + } + } + + // Create the matrix from the triplets + MatrixX one_form_matrix(num_halfedges, num_vertex_forms + num_loops); + one_form_matrix.reserve(tripletList.size()); + one_form_matrix.setFromTriplets(tripletList.begin(), tripletList.end()); + return one_form_matrix; +} + + MatrixX build_free_vertex_system(const Mesh& m) { // build map to free vertices std::vector v_map; int num_free_vertices; - Optimization::build_free_vertex_map(m, v_map, num_free_vertices); + build_free_vertex_map(m, v_map, num_free_vertices); // make map into a matrix int num_vertices = v_map.size(); @@ -564,4 +649,4 @@ std::tuple compute_metric_constraint_with_jacobian_pybind( } } // namespace Holonomy -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/holonomy/holonomy/holonomy.cpp b/src/holonomy/holonomy/holonomy.cpp index df8f5d8..c5adf75 100644 --- a/src/holonomy/holonomy/holonomy.cpp +++ b/src/holonomy/holonomy/holonomy.cpp @@ -1,8 +1,16 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/holonomy/holonomy.h" #include "holonomy/core/dual_loop.h" -#include "optimization/core/area.h" +#include "metric/area.h" #include diff --git a/src/holonomy/holonomy/marked_penner_cone_metric.cpp b/src/holonomy/holonomy/marked_penner_cone_metric.cpp index 8381cd3..6073af3 100644 --- a/src/holonomy/holonomy/marked_penner_cone_metric.cpp +++ b/src/holonomy/holonomy/marked_penner_cone_metric.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/holonomy/marked_penner_cone_metric.h" #include "util/vector.h" @@ -6,8 +14,8 @@ #include "holonomy/holonomy/holonomy.h" #include "holonomy/holonomy/newton.h" -#include "optimization/core/constraint.h" -#include "optimization/core/projection.h" +#include "metric/constraint.h" +#include "metric/projection.h" #include "conformal_ideal_delaunay/ConformalInterface.hh" @@ -119,7 +127,7 @@ MarkedPennerConeMetric::MarkedPennerConeMetric( const VectorX& metric_coords, const std::vector>& homology_basis_loops, const std::vector& kappa) - : Optimization::PennerConeMetric(m, metric_coords) + : PennerConeMetric(m, metric_coords) , kappa_hat(kappa) , m_dual_loop_manager(m.n_edges()) { @@ -341,7 +349,7 @@ MatrixX MarkedPennerConeMetric::constraint_jacobian(const VectorX& cotangents) std::unique_ptr MarkedPennerConeMetric::project_to_constraint( SolveStats& solve_stats, - std::shared_ptr proj_params) const + std::shared_ptr proj_params) const { // Copy parameters NewtonParameters alg_params; @@ -404,4 +412,4 @@ void MarkedPennerConeMetric::write_status_log(std::ostream& stream, bool write_h } // namespace Holonomy -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/holonomy/holonomy/newton.cpp b/src/holonomy/holonomy/newton.cpp index d7657b1..859f0b5 100644 --- a/src/holonomy/holonomy/newton.cpp +++ b/src/holonomy/holonomy/newton.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/holonomy/newton.h" #include "holonomy/holonomy/constraint.h" @@ -8,13 +16,13 @@ #include #include "optimization/metric_optimization/energies.h" #include "optimization/metric_optimization/energy_functor.h" -#include "optimization/core/projection.h" -#include "optimization/core/shear.h" +#include "metric/projection.h" +#include "metric/shear.h" #include "util/io.h" #ifdef USE_SUITESPARSE #include -#include +//#include #endif #ifdef ENABLE_VISUALIZATION @@ -188,7 +196,7 @@ void OptimizeNewton::checkpoint_metric(const MarkedPennerConeMetric& marked_metr // Write best fit scale factors int num_halfedges = marked_metric.n_halfedges(); - VectorX scale_factors = Optimization::best_fit_conformal(marked_metric, VectorX::Zero(num_halfedges)); + VectorX scale_factors = best_fit_conformal(marked_metric, VectorX::Zero(num_halfedges)); checkpoint_path = join_path(checkpoint_dir, "scale_factors_" + suffix); write_vector(scale_factors, checkpoint_path); @@ -197,7 +205,7 @@ void OptimizeNewton::checkpoint_metric(const MarkedPennerConeMetric& marked_metr MatrixX shear_dual_matrix; std::vector edges; arange(num_edges, edges); - Optimization::compute_shear_dual_matrix(marked_metric, edges, shear_dual_matrix); + compute_shear_dual_matrix(marked_metric, edges, shear_dual_matrix); VectorX metric_coords = marked_metric.get_metric_coordinates(); VectorX shears = shear_dual_matrix.transpose() * metric_coords; checkpoint_path = join_path(checkpoint_dir, "shears_" + suffix); @@ -261,7 +269,7 @@ void OptimizeNewton::solve_linear_system() } // QR based minimum norm computation: more numerically stable than direct pseudo-inverse else if (alg_params.solver == "qr") { -#ifdef USE_SUITESPARSE +#ifdef USE_QR typedef int32_t Int; typedef Eigen::SparseMatrix PinvMatrix; @@ -802,4 +810,4 @@ void view_optimization_state( } } // namespace Holonomy -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/holonomy/holonomy/rotation_form.cpp b/src/holonomy/holonomy/rotation_form.cpp index e419c51..15edfdf 100644 --- a/src/holonomy/holonomy/rotation_form.cpp +++ b/src/holonomy/holonomy/rotation_form.cpp @@ -1,8 +1,16 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/holonomy/rotation_form.h" -#include "holonomy/field/field.h" -#include "holonomy/field/intrinsic_field.h" -#include "holonomy/field/forms.h" +#include "field/field.h" +#include "field/intrinsic_field.h" +#include "field/forms.h" #include #include @@ -102,13 +110,13 @@ VectorX generate_rotation_form_from_cross_field( rotation_form[h] = compute_cross_field_edge_angle(m, vtx_reindex, V, frame_field, N, h); } - assert(is_valid_one_form(m, rotation_form)); + assert(Field::is_valid_one_form(m, rotation_form)); return rotation_form; } -VectorX generate_intrinsic_rotation_form(const Mesh& m, const FieldParameters& field_params) +VectorX generate_intrinsic_rotation_form(const Mesh& m, const Field::FieldParameters& field_params) { - IntrinsicNRosyField field_generator; + Field::IntrinsicNRosyField field_generator; field_generator.min_cone = field_params.min_cone; field_generator.use_roundings = field_params.use_roundings; @@ -119,9 +127,9 @@ VectorX generate_intrinsic_rotation_form( const Mesh& m, const std::vector& vtx_reindex, const Eigen::MatrixXd& V, - const FieldParameters& field_params) + const Field::FieldParameters& field_params) { - IntrinsicNRosyField field_generator; + Field::IntrinsicNRosyField field_generator; field_generator.use_roundings = field_params.use_roundings; field_generator.min_cone = field_params.min_cone; @@ -129,4 +137,4 @@ VectorX generate_intrinsic_rotation_form( } } // namespace Holonomy -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/holonomy/interface.cpp b/src/holonomy/interface.cpp index cb0f55d..272e2b7 100644 --- a/src/holonomy/interface.cpp +++ b/src/holonomy/interface.cpp @@ -1,8 +1,16 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/interface.h" #include "holonomy/core/boundary_basis.h" #include "holonomy/core/homology_basis.h" -#include "holonomy/field/intrinsic_field.h" +#include "field/intrinsic_field.h" #include "holonomy/core/quality.h" #include "holonomy/holonomy/cones.h" #include "holonomy/holonomy/holonomy.h" @@ -10,10 +18,10 @@ #include "holonomy/similarity/energy.h" #include "util/boundary.h" -#include "optimization/core/cone_metric.h" -#include "optimization/core/constraint.h" -#include "optimization/parameterization/interpolation.h" -#include "optimization/parameterization/refinement.h" +#include "metric/cone_metric.h" +#include "metric/constraint.h" +#include "parametrization/interpolation.h" +#include "parametrization/refinement.h" #include "util/io.h" #include "util/vector.h" @@ -110,7 +118,7 @@ generate_metric_from_field( // build field // TODO: make field setting check for validity of field - Holonomy::IntrinsicNRosyField field_generator; + Field::IntrinsicNRosyField field_generator; field_generator.initialize(m); field_generator.set_field(m, vtx_reindex, F, face_map, theta, kappa, period_jump); VectorX rotation_form = field_generator.compute_rotation_form(m); @@ -256,16 +264,16 @@ void generate_basis_loops( } } -Optimization::DiscreteMetric generate_discrete_metric(const Mesh& m) { +DiscreteMetric generate_discrete_metric(const Mesh& m) { // Build initial metric and target metric from edge lengths VectorX scale_factors; scale_factors.setZero(m.n_ind_vertices()); bool is_hyperbolic = false; - Optimization::InterpolationMesh interpolation_mesh(m, scale_factors, is_hyperbolic); + InterpolationMesh interpolation_mesh(m, scale_factors, is_hyperbolic); // Get initial log length coordinates VectorX log_length_coords = interpolation_mesh.get_halfedge_metric_coordinates(); - return Optimization::DiscreteMetric(m, log_length_coords); + return DiscreteMetric(m, log_length_coords); } @@ -276,7 +284,7 @@ std::vector compute_kappa( { // Compute the corner angles VectorX he2angle, he2cot; - Optimization::corner_angles(discrete_metric, he2angle, he2cot); + corner_angles(discrete_metric, he2angle, he2cot); // Compute rotation angles along dual loops if loop constraints are needed int num_basis_loops = basis_loops.size(); @@ -344,7 +352,7 @@ MarkedPennerConeMetric generate_marked_metric_from_mesh( Mesh m = _m; // Get initial log length coordinates - Optimization::DiscreteMetric discrete_metric = generate_discrete_metric(m); + DiscreteMetric discrete_metric = generate_discrete_metric(m); VectorX log_length_coords = discrete_metric.get_metric_coordinates(); // compute basis loops @@ -359,7 +367,7 @@ MarkedPennerConeMetric generate_marked_metric_from_mesh( // if set to free cones, instead mark all free cones if (marked_metric_params.use_free_cones) { - std::vector cones = Optimization::enumerate_cone_vertices(m); + std::vector cones = enumerate_cone_vertices(m); if (!cones.empty()) { convert_index_vector_to_boolean_array(cones, m.n_ind_vertices(), m.fixed_dof); @@ -388,6 +396,14 @@ std::tuple, std::vector> generate_mesh( const std::vector& Th_hat, std::vector free_cones) { + // set all flat cones if no cones given + std::vector Th_hat_temp = Th_hat; + if (Th_hat.empty()) + { + Th_hat_temp = std::vector(V.rows(), 2 * PI); + } + + // Convert VF mesh to halfedge bool fix_boundary = false; std::vector vtx_reindex, indep_vtx, dep_vtx, v_rep, bnd_loops; @@ -396,7 +412,7 @@ std::tuple, std::vector> generate_mesh( F, uv, F_uv, - Th_hat, + Th_hat_temp, vtx_reindex, indep_vtx, dep_vtx, @@ -414,7 +430,7 @@ infer_marked_metric( bool use_intrinsic, MarkedMetricParameters marked_metric_params) { - auto [frame_field, field_Th_hat] = generate_cross_field(V, F); + auto [frame_field, field_Th_hat] = Field::generate_cross_field(V, F); // Convert VF mesh to halfedge std::vector vtx_reindex_mesh, indep_vtx, dep_vtx, v_rep, bnd_loops; @@ -437,7 +453,7 @@ infer_marked_metric( // Generate rotation form and cones VectorX rotation_form; if (use_intrinsic) { - FieldParameters field_params; + Field::FieldParameters field_params; rotation_form = generate_intrinsic_rotation_form(m, field_params); } else { rotation_form = @@ -460,7 +476,7 @@ infer_marked_metric( std::tuple> generate_intrinsic_rotation_form( const Eigen::MatrixXd& V, const Eigen::MatrixXi& F, - const FieldParameters& field_params) + const Field::FieldParameters& field_params) { // generate halfedge mesh std::vector vtx_reindex; @@ -555,7 +571,7 @@ std::tuple> generate_refine m.fixed_dof[0] = true; // Get rotation form and corresponding cones - FieldParameters field_params; + Field::FieldParameters field_params; VectorX rotation_form = generate_intrinsic_rotation_form(m, field_params); std::vector Th_hat = generate_cones_from_rotation_form(m, rotation_form); m.Th_hat = Th_hat; diff --git a/src/holonomy/pybind.cpp b/src/holonomy/pybind.cpp index d732815..50554f7 100644 --- a/src/holonomy/pybind.cpp +++ b/src/holonomy/pybind.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/pybind.h" #include "holonomy/interface.h" @@ -8,8 +16,8 @@ #include "holonomy/holonomy/newton.h" #include "holonomy/holonomy/constraint.h" #include "holonomy/holonomy/rotation_form.h" -#include "holonomy/field/intrinsic_field.h" -#include "holonomy/field/frame_field.h" +#include "field/intrinsic_field.h" +#include "field/frame_field.h" #include "holonomy/similarity/conformal.h" #include "holonomy/similarity/energy.h" #include "holonomy/similarity/layout.h" @@ -50,13 +58,28 @@ void init_holonomy_pybind(pybind11::module& m) .value("primal_min_dual_max", HomotopyBasisGenerator::Weighting::primal_min_dual_max) .export_values(); - pybind11::class_(m, "IntrinsicNRosyField") + pybind11::class_(m, "IntrinsicNRosyField") .def(pybind11::init<>()) - .def("initialize", &IntrinsicNRosyField::initialize) - .def("set_field", &IntrinsicNRosyField::set_field) - .def("compute_principal_matchings", &IntrinsicNRosyField::compute_principal_matchings) - .def("fix_inconsistent_matchings", &IntrinsicNRosyField::fix_inconsistent_matchings) - .def("compute_rotation_form", &IntrinsicNRosyField::compute_rotation_form); + .def("initialize", &Field::IntrinsicNRosyField::initialize) + .def("set_field", pybind11::overload_cast< + const Mesh&, + const std::vector&, + const Eigen::MatrixXi&, + const std::vector&, + const Eigen::VectorXd&, + const Eigen::MatrixXd&, + const Eigen::MatrixXi&>(&Field::IntrinsicNRosyField::set_field)) + .def("set_field", pybind11::overload_cast< + const Mesh&, + const std::vector&, + const Eigen::MatrixXi&, + const Eigen::VectorXd&, + const Eigen::MatrixXd&, + const Eigen::MatrixXi&>(&Field::IntrinsicNRosyField::set_field)) + //.def("set_field", &Field::IntrinsicNRosyField::set_field) + .def("compute_principal_matchings", &Field::IntrinsicNRosyField::compute_principal_matchings) + .def("fix_inconsistent_matchings", &Field::IntrinsicNRosyField::fix_inconsistent_matchings) + .def("compute_rotation_form", &Field::IntrinsicNRosyField::compute_rotation_form); pybind11::class_>(m, "NewtonParameters") .def(pybind11::init<>()) @@ -84,9 +107,9 @@ void init_holonomy_pybind(pybind11::module& m) .def_readwrite("free_interior", &MarkedMetricParameters::free_interior) .def_readwrite("weighting", &MarkedMetricParameters::weighting); - pybind11::class_>(m, "FieldParameters") + pybind11::class_>(m, "FieldParameters") .def(pybind11::init<>()) - .def_readwrite("min_cone", &FieldParameters::min_cone); + .def_readwrite("min_cone", &Field::FieldParameters::min_cone); pybind11::class_(m, "MarkedPennerConeMetric") .def(pybind11::init< @@ -154,7 +177,7 @@ void init_holonomy_pybind(pybind11::module& m) m.def( "generate_intrinsic_rotation_form", pybind11:: - overload_cast( + overload_cast( &generate_intrinsic_rotation_form), default_call_guard); @@ -176,11 +199,11 @@ void init_holonomy_pybind(pybind11::module& m) &generate_penner_coordinates, default_call_guard); - m.def("load_frame_field", &load_frame_field, default_call_guard); - m.def("write_frame_field", &write_frame_field, default_call_guard); - m.def("refine_frame_field", &refine_frame_field, default_call_guard); + m.def("load_frame_field", &Field::load_frame_field, default_call_guard); + m.def("write_frame_field", &Field::write_frame_field, default_call_guard); + m.def("refine_frame_field", &Field::refine_frame_field, default_call_guard); m.def("compute_loop_holonomy_matrix", &compute_loop_holonomy_matrix, default_call_guard); - m.def("compute_field_direction", &compute_field_direction, default_call_guard); + m.def("compute_field_direction", &Field::compute_field_direction, default_call_guard); m.def("write_obj", writeOBJ, default_call_guard); } @@ -189,4 +212,4 @@ void init_holonomy_pybind(pybind11::module& m) #endif } // namespace Holonomy -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/holonomy/similarity/conformal.cpp b/src/holonomy/similarity/conformal.cpp index 83f79c5..befbe5c 100644 --- a/src/holonomy/similarity/conformal.cpp +++ b/src/holonomy/similarity/conformal.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/similarity/conformal.h" #include @@ -76,7 +84,7 @@ Scalar compute_newton_decrement( for (int h = 0; h < similarity_metric.n_halfedges(); h++) { d[h] = similarity_metric.sign(h) * descent_direction[similarity_metric.he2e[h]]; } - assert(is_closed_one_form(similarity_metric, d)); + assert(Field::is_closed_one_form(similarity_metric, d)); // Get reduced descent direction coefficients VectorX y = similarity_metric.reduce_one_form(d); diff --git a/src/holonomy/similarity/constraint.cpp b/src/holonomy/similarity/constraint.cpp index f6c9b07..50a3a9b 100644 --- a/src/holonomy/similarity/constraint.cpp +++ b/src/holonomy/similarity/constraint.cpp @@ -1,6 +1,14 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/similarity/constraint.h" -#include "optimization/core/constraint.h" +#include "metric/constraint.h" #include "holonomy/holonomy/holonomy.h" #include "holonomy/holonomy/constraint.h" @@ -17,7 +25,7 @@ VectorX compute_similarity_constraint( std::vector v_map; int num_vertex_forms; - Optimization::build_free_vertex_map(similarity_metric, v_map, num_vertex_forms); + build_free_vertex_map(similarity_metric, v_map, num_vertex_forms); // Initialize the constraint constraint.setZero(num_vertex_forms + n_s + n_f - 1); @@ -43,7 +51,7 @@ MatrixX compute_one_form_constraint_jacobian( // Get free vertex map std::vector v_rep; int num_vertex_forms; - Optimization::build_free_vertex_rep(similarity_metric, v_rep, num_vertex_forms); + build_free_vertex_rep(similarity_metric, v_rep, num_vertex_forms); // Add entries for vertex angles constraints for (int h = 0; h < n_h; h++) { diff --git a/src/holonomy/similarity/energy.cpp b/src/holonomy/similarity/energy.cpp index b328903..ba6f3b3 100644 --- a/src/holonomy/similarity/energy.cpp +++ b/src/holonomy/similarity/energy.cpp @@ -1,6 +1,15 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/similarity/energy.h" -#include "holonomy/field/forms.h" +#include "field/forms.h" +#include "holonomy/holonomy/constraint.h" namespace Penner { namespace Holonomy { @@ -99,9 +108,9 @@ IntegratedEnergy::IntegratedEnergy(const SimilarityPennerConeMetric& target_simi target_similarity_metric, target_similarity_metric.get_homology_basis_loops()); MatrixX integral_matrix = - build_one_form_integral_matrix(target_similarity_metric, cut_h, is_cut_h); + Field::build_one_form_integral_matrix(target_similarity_metric, cut_h, is_cut_h); MatrixX integrated_scaling_matrix = - build_integrated_one_form_scaling_matrix(target_similarity_metric); + Field::build_integrated_one_form_scaling_matrix(target_similarity_metric); // Get metric expansion matrix MatrixX identification, projection; diff --git a/src/holonomy/similarity/layout.cpp b/src/holonomy/similarity/layout.cpp index a6388e6..d56edbd 100644 --- a/src/holonomy/similarity/layout.cpp +++ b/src/holonomy/similarity/layout.cpp @@ -1,7 +1,15 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/similarity/layout.h" -#include "optimization/parameterization/layout.h" -#include "optimization/parameterization/translation.h" +#include "parametrization/layout.h" +#include "parametrization/translation.h" #include "conformal_ideal_delaunay/ConformalInterface.hh" namespace Penner { @@ -13,8 +21,8 @@ void interpolate_penner_coordinates( const Mesh& mesh, const SimilarityPennerConeMetric& initial_marked_metric, SimilarityPennerConeMetric& marked_metric, - Optimization::InterpolationMesh& interpolation_mesh, - Optimization::InterpolationMesh& reverse_interpolation_mesh) + InterpolationMesh& interpolation_mesh, + InterpolationMesh& reverse_interpolation_mesh) { marked_metric = initial_marked_metric; @@ -23,7 +31,7 @@ void interpolate_penner_coordinates( trivial_scale_factors.setZero(mesh.n_ind_vertices()); bool is_hyperbolic = false; interpolation_mesh = - Optimization::InterpolationMesh(mesh, trivial_scale_factors, is_hyperbolic); + InterpolationMesh(mesh, trivial_scale_factors, is_hyperbolic); // Get initial reflection structure Mesh& mc = interpolation_mesh.get_mesh(); @@ -48,7 +56,7 @@ void interpolate_penner_coordinates( // Compute translations for reparametrization VectorX translations; - Optimization::compute_as_symmetric_as_possible_translations( + compute_as_symmetric_as_possible_translations( mc, flipped_metric_coords, initial_metric_coords, @@ -73,7 +81,7 @@ void interpolate_penner_coordinates( Mesh m_layout = interpolation_mesh.get_mesh(); is_hyperbolic = true; reverse_interpolation_mesh = - Optimization::InterpolationMesh(m_layout, trivial_scale_factors, is_hyperbolic); + InterpolationMesh(m_layout, trivial_scale_factors, is_hyperbolic); // Undo the flips to make the hyperbolic surface with new metric Delaunay reverse_interpolation_mesh.reverse_flip_sequence(flip_sequence); @@ -130,7 +138,7 @@ std:: // Compute interpolation overlay mesh // TODO: Use consistent interpolation code from the Penner codebase Eigen::MatrixXd V_overlay; - Optimization::InterpolationMesh interpolation_mesh, reverse_interpolation_mesh; + InterpolationMesh interpolation_mesh, reverse_interpolation_mesh; SimilarityPennerConeMetric similarity_metric = initial_similarity_metric; spdlog::trace("Interpolating penner coordinates"); interpolate_penner_coordinates( @@ -155,7 +163,7 @@ std:: for (int h = 0; h < metric_coords.size(); ++h) { mc.l[h] = exp(metric_coords[h] / 2.0); } - Optimization::make_tufted_overlay(m_o); + make_tufted_overlay(m_o); // Get endpoints std::vector> endpoints; @@ -171,12 +179,12 @@ std:: } // Get layout topology from original mesh - std::vector is_cut = Optimization::compute_layout_topology(m, cut_h); + std::vector is_cut = compute_layout_topology(m, cut_h); // Convert overlay mesh to VL format spdlog::trace("Getting layout"); std::vector u(m.n_ind_vertices(), 0.0); - return Optimization::consistent_overlay_mesh_to_VL( + return consistent_overlay_mesh_to_VL( m, m_o, vtx_reindex, diff --git a/src/holonomy/similarity/similarity_penner_cone_metric.cpp b/src/holonomy/similarity/similarity_penner_cone_metric.cpp index 55ff2e8..6cf0c43 100644 --- a/src/holonomy/similarity/similarity_penner_cone_metric.cpp +++ b/src/holonomy/similarity/similarity_penner_cone_metric.cpp @@ -1,13 +1,22 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "holonomy/similarity/similarity_penner_cone_metric.h" #include "holonomy/similarity/conformal.h" #include "holonomy/similarity/constraint.h" +#include "holonomy/holonomy/constraint.h" #include "holonomy/holonomy/holonomy.h" #include -#include "optimization/core/area.h" -#include "optimization/core/constraint.h" +#include "metric/area.h" +#include "metric/constraint.h" namespace Penner { namespace Holonomy { @@ -40,7 +49,7 @@ void similarity_corner_angles( Scalar lk = exp(metric_coords[hk] / 2.0); // Compute the cotangent of the angles - Scalar Aijk4 = 4 * sqrt(std::max(Optimization::squared_area(li, lj, lk), 0.0)); + Scalar Aijk4 = 4 * sqrt(std::max(squared_area(li, lj, lk), 0.0)); Scalar Ijk = (-li * li + lj * lj + lk * lk); Scalar iJk = (li * li - lj * lj + lk * lk); Scalar ijK = (li * li + lj * lj - lk * lk); @@ -303,7 +312,7 @@ bool SimilarityPennerConeMetric::constraint( std::unique_ptr SimilarityPennerConeMetric::project_to_constraint( SolveStats& solve_stats, - std::shared_ptr proj_params) const + std::shared_ptr proj_params) const { solve_stats.n_solves++; // TODO Make accurate AlgorithmParameters alg_params; @@ -354,9 +363,9 @@ std::tuple> SimilarityPennerConeMetric::get_integrated_metric_coordinates(std::vector cut_h) const { std::vector is_cut_h; - VectorX u = integrate_one_form(*this, m_one_form, cut_h, is_cut_h); + VectorX u = Field::integrate_one_form(*this, m_one_form, cut_h, is_cut_h); VectorX metric_coords = get_metric_coordinates(); - metric_coords = scale_halfedges_by_integrated_one_form(*this, metric_coords, u); + metric_coords = Field::scale_halfedges_by_integrated_one_form(*this, metric_coords, u); return std::make_tuple(metric_coords, u, is_cut_h); } @@ -390,7 +399,7 @@ SimilarityPennerConeMetric SimilarityPennerConeMetric::scale_by_one_form() const u.setZero(num_vertices); std::vector v_map; int num_angles; - Optimization::build_free_vertex_map(*this, v_map, num_angles); + build_free_vertex_map(*this, v_map, num_angles); for (int vi = 0; vi < num_vertices; ++vi) { if (v_map[vi] >= 0) { u[vi] = coefficients[v_map[vi]]; diff --git a/src/optimization/core/area.cpp b/src/metric/area.cpp similarity index 62% rename from src/optimization/core/area.cpp rename to src/metric/area.cpp index 1b76cb0..13de093 100644 --- a/src/optimization/core/area.cpp +++ b/src/metric/area.cpp @@ -1,39 +1,16 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#include "optimization/core/area.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "metric/area.h" #include "util/embedding.h" namespace Penner { -namespace Optimization { Scalar squared_area(Scalar li, Scalar lj, Scalar lk) { @@ -190,5 +167,4 @@ VectorX squared_area_log_length_derivatives(const Mesh& m) return he2areasq_log_deriv; } -} // namespace Optimization } // namespace Penner diff --git a/src/metric/common.cpp b/src/metric/common.cpp new file mode 100644 index 0000000..35f1651 --- /dev/null +++ b/src/metric/common.cpp @@ -0,0 +1,64 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "metric/common.h" + +namespace Penner { + +bool vector_equal(VectorX v, VectorX w, Scalar eps) +{ + // Check if the sizes are the same + if (v.size() != w.size()) return false; + + // Check per element equality + for (Eigen::Index i = 0; i < v.size(); ++i) { + if (!float_equal(v[i], w[i], eps)) return false; + } + + // Equal otherwise + return true; +} + +bool matrix_contains_nan(const Eigen::MatrixXd& mat) +{ + for (Eigen::Index i = 0; i < mat.rows(); ++i) { + for (Eigen::Index j = 0; j < mat.cols(); ++j) { + if (std::isnan(mat(i, j))) return true; + } + } + + return false; +} + +Scalar sup_norm(const VectorX& v) +{ + Scalar norm_value = 0.0; + for (Eigen::Index i = 0; i < v.size(); ++i) { + norm_value = max(norm_value, abs(v[i])); + } + + return norm_value; +} + +Scalar matrix_sup_norm(const MatrixX& matrix) +{ + // Check for trivial matrices + if (matrix.size() == 0) return 0; + + // Iterate to determine maximum abs value + Scalar max_value = 0.0; + for (Eigen::Index k = 0; k < matrix.outerSize(); ++k) { + for (MatrixX::InnerIterator it(matrix, k); it; ++it) { + max_value = std::max(max_value, abs(it.value())); + } + } + + return max_value; +} + +} // namespace Penner \ No newline at end of file diff --git a/src/optimization/core/cone_metric.cpp b/src/metric/cone_metric.cpp similarity index 82% rename from src/optimization/core/cone_metric.cpp rename to src/metric/cone_metric.cpp index 44335ef..e83fc9e 100644 --- a/src/optimization/core/cone_metric.cpp +++ b/src/metric/cone_metric.cpp @@ -1,43 +1,20 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#include "optimization/core/cone_metric.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "metric/cone_metric.h" #include "conformal_ideal_delaunay/ConformalInterface.hh" -#include "optimization/core/constraint.h" -#include "optimization/core/projection.h" +#include "metric/constraint.h" +#include "metric/projection.h" // TODO: Clean code namespace Penner { -namespace Optimization { DifferentiableConeMetric::DifferentiableConeMetric(const Mesh& m) : Mesh(m) @@ -428,5 +405,4 @@ void DiscreteMetric::expand_metric_coordinates(const VectorX& metric_coords) // TODO error } -} // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/src/optimization/core/constraint.cpp b/src/metric/constraint.cpp similarity index 81% rename from src/optimization/core/constraint.cpp rename to src/metric/constraint.cpp index 6d020f1..4f2817b 100644 --- a/src/optimization/core/constraint.cpp +++ b/src/metric/constraint.cpp @@ -1,42 +1,19 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#include "optimization/core/constraint.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "metric/constraint.h" #include "util/embedding.h" #include "util/linear_algebra.h" #include "util/boundary.h" -#include "optimization/core/area.h" +#include "metric/area.h" namespace Penner { -namespace Optimization { std::vector enumerate_cone_vertices(const Mesh& m) { @@ -378,5 +355,4 @@ VectorX compute_cone_angles(const DifferentiableConeMetric& cone_metric) return Theta(*cone_metric_copy, he2angle); } -} // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/src/optimization/core/flip_matrix_generator.cpp b/src/metric/flip_matrix_generator.cpp similarity index 59% rename from src/optimization/core/flip_matrix_generator.cpp rename to src/metric/flip_matrix_generator.cpp index f3e99be..c212dfc 100644 --- a/src/optimization/core/flip_matrix_generator.cpp +++ b/src/metric/flip_matrix_generator.cpp @@ -1,37 +1,14 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#include "optimization/core/flip_matrix_generator.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "metric/flip_matrix_generator.h" namespace Penner { -namespace Optimization { FlipMatrixGenerator::FlipMatrixGenerator(int size) : m_size(size) @@ -167,5 +144,4 @@ MatrixX FlipMapMatrixGenerator::build_matrix() const return matrix; } -} // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/src/optimization/core/projection.cpp b/src/metric/projection.cpp similarity index 69% rename from src/optimization/core/projection.cpp rename to src/metric/projection.cpp index 45aa4a5..5b193c7 100644 --- a/src/optimization/core/projection.cpp +++ b/src/metric/projection.cpp @@ -1,34 +1,12 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#include "optimization/core/projection.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "metric/projection.h" #include #include @@ -37,13 +15,12 @@ #include "util/embedding.h" #include "util/linear_algebra.h" #include "util/vector.h" -#include "optimization/core/constraint.h" -#include "optimization/core/globals.h" +#include "metric/constraint.h" +#include "metric/globals.h" /// FIXME Do cleaning pass namespace Penner { -namespace Optimization { MatrixX conformal_scaling_matrix(const Mesh& m) { @@ -206,5 +183,4 @@ VectorX project_descent_direction( } -} // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/src/optimization/core/reparametrization.cpp b/src/metric/reparametrization.cpp similarity index 53% rename from src/optimization/core/reparametrization.cpp rename to src/metric/reparametrization.cpp index 4e7628d..f79dbe3 100644 --- a/src/optimization/core/reparametrization.cpp +++ b/src/metric/reparametrization.cpp @@ -1,34 +1,12 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#include "optimization/core/reparametrization.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "metric/reparametrization.h" #include "conformal_ideal_delaunay/ConformalIdealDelaunayMapping.hh" #include "util/embedding.h" @@ -36,7 +14,6 @@ /// FIXME Do cleaning pass namespace Penner { -namespace Optimization { template void bc_reparametrize_eq(OverlayMesh& m_o, const VectorX& tau) @@ -130,5 +107,4 @@ template void reparametrize_equilateral( #endif #endif -} // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/src/optimization/core/shear.cpp b/src/metric/shear.cpp similarity index 84% rename from src/optimization/core/shear.cpp rename to src/metric/shear.cpp index 55b19bc..be59033 100644 --- a/src/optimization/core/shear.cpp +++ b/src/metric/shear.cpp @@ -1,45 +1,22 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#include "optimization/core/shear.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "metric/shear.h" #include "conformal_ideal_delaunay/ConformalIdealDelaunayMapping.hh" #include "util/embedding.h" -#include "optimization/core/projection.h" -#include "optimization/core/reparametrization.h" +#include "metric/projection.h" +#include "metric/reparametrization.h" #include "util/vector.h" /// FIXME Do cleaning pass namespace Penner { -namespace Optimization { VectorX compute_shear(const Mesh& m, const VectorX& he_metric_coords) { @@ -426,5 +403,4 @@ void compute_shear_basis_coordinates( scale_factors)); } -} // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/src/optimization/core/viewer.cpp b/src/metric/viewer.cpp similarity index 89% rename from src/optimization/core/viewer.cpp rename to src/metric/viewer.cpp index 5f95b40..2f30330 100644 --- a/src/optimization/core/viewer.cpp +++ b/src/metric/viewer.cpp @@ -1,5 +1,13 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. -#include "optimization/core/viewer.h" + +#include "metric/viewer.h" #include "util/vf_mesh.h" @@ -10,6 +18,7 @@ #include #include #include +#include #include @@ -25,7 +34,6 @@ namespace Penner { -namespace Optimization { std::tuple generate_halfedge_faces( const std::vector& next, @@ -388,7 +396,7 @@ void view_cones( auto [V_double, F_mesh, F_halfedge] = generate_doubled_mesh(V, m, vtx_reindex); // Generate cones - auto [cone_positions, cone_values] = Optimization::generate_cone_vertices(V, vtx_reindex, m); + auto [cone_positions, cone_values] = generate_cone_vertices(V, vtx_reindex, m); #ifdef ENABLE_VISUALIZATION polyscope::init(); @@ -781,5 +789,79 @@ void view_halfedge_function( #endif } -} // namespace Optimization -} // namespace Penner +void view_flipped_triangles( + const Eigen::MatrixXd& V, + const Eigen::MatrixXi& F, + const Eigen::MatrixXd& uv, + const Eigen::MatrixXi& F_uv) +{ + // Cut the mesh along the parametrization seams + Eigen::MatrixXd V_cut; + cut_mesh_along_parametrization_seams(V, F, uv, F_uv, V_cut); + + // Get the flipped elements + Eigen::VectorXi flipped_f; + igl::flipped_triangles(uv, F_uv, flipped_f); + spdlog::info("{} flipped elements", flipped_f.size()); + + // Convert flipped element list to a scalar function + int num_faces = F_uv.rows(); + Eigen::VectorXd is_flipped; + is_flipped.setZero(num_faces); + for (int i = 0; i < flipped_f.size(); ++i) { + int fi = flipped_f[i]; + is_flipped[fi] = 1.0; + spdlog::info("Face {}: {} is flipped", fi, F_uv.row(fi)); + } + +#if ENABLE_VISUALIZATION + // Add the mesh and uv mesh with flipped element maps + polyscope::init(); + polyscope::registerSurfaceMesh("mesh", V_cut, F_uv) + ->addFaceScalarQuantity("is_flipped", is_flipped); + polyscope::getSurfaceMesh("mesh")->addVertexParameterizationQuantity("uv", uv); + polyscope::registerSurfaceMesh2D("uv mesh", uv, F_uv) + ->addFaceScalarQuantity("is_flipped", is_flipped); + polyscope::show(); +#endif // ENABLE_VISUALIZATION +} + +void view_halfedge_mesh_layout( + const std::vector& next, + const std::vector& f2h, + const std::vector& u_vec, + const std::vector& v_vec) +{ + Eigen::VectorXd u, v; + convert_std_to_eigen_vector(u_vec, u); + convert_std_to_eigen_vector(v_vec, v); + Eigen::MatrixXd uv(u.size(), 3); + uv.col(0) = u; + uv.col(1) = v; + int num_faces = f2h.size(); + Eigen::MatrixXi F(num_faces, 3); + for (int f = 0; f < num_faces; ++f) { + int hij = f2h[f]; + int hjk = next[hij]; + int hki = next[hjk]; + F(f, 0) = hij; + F(f, 1) = hjk; + F(f, 2) = hki; + } +#if ENABLE_VISUALIZATION + spdlog::info("Viewing layout"); + polyscope::init(); + polyscope::registerSurfaceMesh2D("layout", uv, F); + polyscope::show(); +#endif +} + +void view_halfedge_mesh_layout( + const Mesh& m, + const std::vector& u_vec, + const std::vector& v_vec) +{ + view_halfedge_mesh_layout(m.n, m.h, u_vec, v_vec); +} + +} // namespace Penner \ No newline at end of file diff --git a/src/optimization/CMakeLists.txt b/src/optimization/CMakeLists.txt index e6ff6f2..455c975 100644 --- a/src/optimization/CMakeLists.txt +++ b/src/optimization/CMakeLists.txt @@ -1,14 +1,3 @@ -set(OptimizationCoreSrc - core/area.cpp - core/common.cpp - core/cone_metric.cpp - core/constraint.cpp - core/flip_matrix_generator.cpp - core/projection.cpp - core/reparametrization.cpp - core/shear.cpp - core/viewer.cpp -) set(MetricOptimizationSrc metric_optimization/convergence.cpp @@ -20,30 +9,19 @@ set(MetricOptimizationSrc metric_optimization/nonlinear_optimization.cpp ) -set(ParameterizationSrc - parameterization/interpolation.cpp - parameterization/layout.cpp - parameterization/refinement.cpp - parameterization/translation.cpp - parameterization/triangulation.cpp -) - set(OptimizationUtilSrc util/shapes.cpp - util/viewers.cpp ) add_library(PennerOptimizationLib interface.cpp pybind.cpp - ${OptimizationCoreSrc} ${MetricOptimizationSrc} - ${ParameterizationSrc} ${OptimizationUtilSrc} ) target_include_directories(PennerOptimizationLib PUBLIC ../../include/optimization) target_link_libraries(PennerOptimizationLib PUBLIC - PennerUtilLib + PennerCoreLib ${RENDER_LIBRARIES} ${PYBIND_LIBRARIES} ) @@ -55,3 +33,13 @@ if ((NOT USE_MULTIPRECISION) AND (DEBUG_WARNINGS)) -Wall -Wpedantic -Wextra -Werror ) endif() + +if(BUILD_CURVATURE_METRIC_TESTS) + add_executable(penner_tests tests/tests.cpp) + target_link_libraries(penner_tests PRIVATE PennerOptimizationLib Catch2::Catch2WithMain) + target_include_directories(penner_tests PRIVATE tests) + target_compile_definitions(penner_tests PRIVATE + TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/tests/regression" + ) + add_test(NAME penner_tests COMMAND penner_tests) +endif() diff --git a/src/optimization/core/common.cpp b/src/optimization/core/common.cpp deleted file mode 100644 index 5f81e6f..0000000 --- a/src/optimization/core/common.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#include "optimization/core/common.h" - -namespace Penner { -namespace Optimization { - -bool vector_equal(VectorX v, VectorX w, Scalar eps) -{ - // Check if the sizes are the same - if (v.size() != w.size()) return false; - - // Check per element equality - for (Eigen::Index i = 0; i < v.size(); ++i) { - if (!float_equal(v[i], w[i], eps)) return false; - } - - // Equal otherwise - return true; -} - -bool matrix_contains_nan(const Eigen::MatrixXd& mat) -{ - for (Eigen::Index i = 0; i < mat.rows(); ++i) { - for (Eigen::Index j = 0; j < mat.cols(); ++j) { - if (std::isnan(mat(i, j))) return true; - } - } - - return false; -} - -Scalar sup_norm(const VectorX& v) -{ - Scalar norm_value = 0.0; - for (Eigen::Index i = 0; i < v.size(); ++i) { - norm_value = max(norm_value, abs(v[i])); - } - - return norm_value; -} - -Scalar matrix_sup_norm(const MatrixX& matrix) -{ - // Check for trivial matrices - if (matrix.size() == 0) return 0; - - // Iterate to determine maximum abs value - Scalar max_value = 0.0; - for (Eigen::Index k = 0; k < matrix.outerSize(); ++k) { - for (MatrixX::InnerIterator it(matrix, k); it; ++it) { - max_value = std::max(max_value, abs(it.value())); - } - } - - return max_value; -} - -} // namespace Optimization -} // namespace Penner \ No newline at end of file diff --git a/src/optimization/interface.cpp b/src/optimization/interface.cpp index 2bb5c6f..31b2b91 100644 --- a/src/optimization/interface.cpp +++ b/src/optimization/interface.cpp @@ -1,42 +1,19 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "optimization/interface.h" #include "conformal_ideal_delaunay/ConformalInterface.hh" #include "util/embedding.h" #include "util/vector.h" -#include "optimization/parameterization/interpolation.h" -#include "optimization/parameterization/layout.h" -#include "optimization/core/projection.h" -#include "optimization/parameterization/translation.h" -#include "optimization/util/viewers.h" +#include "parametrization/interpolation.h" +#include "parametrization/layout.h" +#include "metric/projection.h" +#include "parametrization/translation.h" /// FIXME Do cleaning pass @@ -157,293 +134,6 @@ std::vector correct_cone_angles(const std::vector& initial_cone_ return corrected_cone_angles; } -void write_obj_with_uv( - const std::string& filename, - const Eigen::MatrixXd& V, - const Eigen::MatrixXi& F, - const Eigen::MatrixXd& uv, - const Eigen::MatrixXi& F_uv) -{ - Eigen::MatrixXd N; - Eigen::MatrixXi FN; - igl::writeOBJ(filename, V, F, N, FN, uv, F_uv); -} - -std::vector find_boundary_vertices(const Mesh& m) -{ - std::vector is_bd(m.n_ind_vertices(), false); - for (int i = 0; i < m.n_halfedges(); i++) { - if ((m.type[i] == 1) && (m.type[m.opp[i]] == 2)) - { - is_bd[m.v_rep[m.to[i]]] = true; - } - } - - return is_bd; -} - -template -std:: - tuple< - OverlayMesh, // m_o - Eigen::MatrixXd, // V_o - Eigen::MatrixXi, // F_o - Eigen::MatrixXd, // uv_o - Eigen::MatrixXi, // FT_o - std::vector, // is_cut_h - std::vector, // is_cut_o - std::vector, // Fn_to_F - std::vector> // endpoints_o - > - generate_VF_mesh_from_halfedge_metric( - const Eigen::MatrixXd& V, - const Mesh& m, - const std::vector& vtx_reindex, - const DifferentiableConeMetric& initial_cone_metric, - const VectorX& reduced_metric_coords, - std::vector cut_h, - bool do_best_fit_scaling, - bool use_uniform_bc, - std::string layout_output_path) -{ - // Get metric target coordinates - auto cone_metric = initial_cone_metric.set_metric_coordinates(reduced_metric_coords); - VectorX metric_target = initial_cone_metric.get_metric_coordinates(); - VectorX metric_coords = cone_metric->get_metric_coordinates(); - - // Get boundary vertices - std::vector is_bd = find_boundary_vertices(m); - - // Fit conformal scale factors - VectorX metric_coords_scaled = metric_coords; - VectorX scale_factors; - scale_factors.setZero(initial_cone_metric.n_ind_vertices()); - if (do_best_fit_scaling) { - scale_factors = best_fit_conformal(initial_cone_metric, metric_coords); - MatrixX B = conformal_scaling_matrix(initial_cone_metric); - metric_coords_scaled = metric_coords - B * scale_factors; - } - VectorX metric_diff = metric_coords_scaled - metric_target; - SPDLOG_DEBUG( - "Scale factors in range [{}, {}]", - scale_factors.minCoeff(), - scale_factors.maxCoeff()); - SPDLOG_DEBUG( - "Scaled metric coordinates in range [{}, {}]", - metric_coords_scaled.minCoeff(), - metric_coords_scaled.maxCoeff()); - SPDLOG_DEBUG( - "Differences from target to optimized metric in range [{}, {}]", - metric_diff.minCoeff(), - metric_diff.maxCoeff()); - - // Compute interpolation overlay mesh - Eigen::MatrixXd V_overlay; - InterpolationMesh interpolation_mesh, reverse_interpolation_mesh; - spdlog::trace("Interpolating penner coordinates for mesh with {} halfedges", m.n_halfedges()); - interpolate_penner_coordinates( - m, - metric_coords_scaled, - scale_factors, - interpolation_mesh, - reverse_interpolation_mesh); - spdlog::trace("Interpolating vertex positions"); - interpolate_vertex_positions( - V, - vtx_reindex, - interpolation_mesh, - reverse_interpolation_mesh, - V_overlay); - OverlayMesh m_o = interpolation_mesh.get_overlay_mesh(); - make_tufted_overlay(m_o); - - // Get endpoints - std::vector> endpoints; - find_origin_endpoints(m_o, endpoints); - - // Convert overlay mesh to transposed vector format - std::vector> V_overlay_vec(3); - for (int i = 0; i < 3; ++i) { - V_overlay_vec[i].resize(V_overlay.rows()); - for (int j = 0; j < V_overlay.rows(); ++j) { - V_overlay_vec[i][j] = OverlayScalar(V_overlay(j, i)); - } - } - - // Get layout topology from original mesh - std::vector is_cut = compute_layout_topology(m, cut_h); - - // Convert overlay mesh to VL format - spdlog::trace("Getting layout"); - std::vector vtx_reindex_mutable = vtx_reindex; - std::vector u; // (m_o._m.Th_hat.size(), 0.0); - convert_eigen_to_std_vector(scale_factors, u); - // auto parametrize_res = overlay_mesh_to_VL(V, F, Th_hat, m_o, u, V_overlay_vec, - // vtx_reindex_mutable, endpoints, -1); FIXME - return consistent_overlay_mesh_to_VL( - m, - m_o, - vtx_reindex, - is_bd, - u, - V_overlay_vec, - endpoints, - is_cut, - {}, - use_uniform_bc, - layout_output_path); -} - -std:: - tuple< - OverlayMesh, // m_o - Eigen::MatrixXd, // V_o - Eigen::MatrixXi, // F_o - Eigen::MatrixXd, // uv_o - Eigen::MatrixXi, // FT_o - std::vector, // is_cut_h - std::vector, // is_cut_o - std::vector, // Fn_to_F - std::vector> // endpoints_o - > - generate_VF_mesh_from_metric( - const Eigen::MatrixXd& V, - const Eigen::MatrixXi& F, - const std::vector& Th_hat, - const DifferentiableConeMetric& initial_cone_metric, - const VectorX& reduced_metric_coords, - std::vector cut_h, - bool do_best_fit_scaling) -{ - // Get mesh with vertex reindexing - std::vector vtx_reindex, indep_vtx, dep_vtx, v_rep, bnd_loops; - Mesh m = - FV_to_double(V, F, V, F, Th_hat, vtx_reindex, indep_vtx, dep_vtx, v_rep, bnd_loops); - - return generate_VF_mesh_from_halfedge_metric(V, m, vtx_reindex, initial_cone_metric, reduced_metric_coords, cut_h, do_best_fit_scaling); -} - -std:: - tuple< - Eigen::MatrixXd, // V_o - Eigen::MatrixXi, // F_o - Eigen::MatrixXd, // uv_o - Eigen::MatrixXi, // FT_o - std::vector // is_cut_h - > - generate_VF_mesh_from_discrete_metric( - const Eigen::MatrixXd& V, - const Eigen::MatrixXi& F, - const std::vector& Th_hat, - const VectorX& reduced_log_edge_lengths, - std::vector cut_h) -{ - // Get mesh with vertex reindexing - std::vector vtx_reindex, indep_vtx, dep_vtx, v_rep, bnd_loops; - Mesh m = - FV_to_double(V, F, V, F, Th_hat, vtx_reindex, indep_vtx, dep_vtx, v_rep, bnd_loops); - - // Get boundary vertices - std::vector is_bd = find_boundary_vertices(m); - - // Get layout topology from mesh - std::vector is_cut = compute_layout_topology(m, cut_h); - - // Set metric for layout - DiscreteMetric discrete_metric(m, reduced_log_edge_lengths); - - // Create trivial overlay mesh - OverlayMesh m_o(discrete_metric); - make_tufted_overlay(m_o); - - // Convert vertices to transposed vector format - std::vector> V_overlay_vec(3); - for (int i = 0; i < 3; ++i) { - V_overlay_vec[i].resize(V.rows()); - for (int j = 0; j < V.rows(); ++j) { - V_overlay_vec[i][j] = V(vtx_reindex[j], i); - } - } - - // Get endpoints - std::vector> endpoints; - find_origin_endpoints(m_o, endpoints); - - // Compute layout - std::vector u_vec(m.n_ind_vertices(), 0.0); - //std::vector vtx_reindex_mutable = vtx_reindex; - auto layout_res = consistent_overlay_mesh_to_VL( - m, - m_o, - vtx_reindex, - is_bd, - u_vec, - V_overlay_vec, - endpoints, - is_cut, - {}); - - Eigen::MatrixXd V_l = std::get<1>(layout_res); - Eigen::MatrixXi F_l = std::get<2>(layout_res); - Eigen::MatrixXd uv = std::get<3>(layout_res); - Eigen::MatrixXi FT = std::get<4>(layout_res); - - return std::make_tuple(V_l, F_l, uv, FT, cut_h); -} - -template -std:: - tuple< - OverlayMesh, // m_o - Eigen::MatrixXd, // V_o - Eigen::MatrixXi, // F_o - Eigen::MatrixXd, // uv_o - Eigen::MatrixXi, // FT_o - std::vector, // is_cut_h - std::vector, // is_cut_o - std::vector, // Fn_to_F - std::vector> // endpoints_o - > - generate_VF_mesh_from_halfedge_metric( - const Eigen::MatrixXd& V, - const Mesh& m, - const std::vector& vtx_reindex, - const DifferentiableConeMetric& initial_cone_metric, - const VectorX& reduced_metric_coords, - std::vector cut_h, - bool do_best_fit_scaling, - bool use_uniform_bc, - std::string layout_output_path); - -#ifdef WITH_MPFR -#ifndef MULTIPRECISION - -template -std:: - tuple< - OverlayMesh, // m_o - Eigen::MatrixXd, // V_o - Eigen::MatrixXi, // F_o - Eigen::MatrixXd, // uv_o - Eigen::MatrixXi, // FT_o - std::vector, // is_cut_h - std::vector, // is_cut_o - std::vector, // Fn_to_F - std::vector> // endpoints_o - > - generate_VF_mesh_from_halfedge_metric( - const Eigen::MatrixXd& V, - const Mesh& m, - const std::vector& vtx_reindex, - const DifferentiableConeMetric& initial_cone_metric, - const VectorX& reduced_metric_coords, - std::vector cut_h, - bool do_best_fit_scaling, - bool use_uniform_bc, - std::string layout_output_path); -#endif -#endif - } // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/src/optimization/metric_optimization/convergence.cpp b/src/optimization/metric_optimization/convergence.cpp index e8029ce..b397ee4 100644 --- a/src/optimization/metric_optimization/convergence.cpp +++ b/src/optimization/metric_optimization/convergence.cpp @@ -1,39 +1,17 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "optimization/metric_optimization/convergence.h" -#include "optimization/core/constraint.h" +#include "metric/constraint.h" #include "optimization/metric_optimization/explicit_optimization.h" #include "optimization/metric_optimization/implicit_optimization.h" -#include "optimization/core/projection.h" +#include "metric/projection.h" namespace Penner { @@ -237,4 +215,4 @@ step_projected_descent_direction); gradient_signs[i] = */ } // namespace Optimization -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/optimization/metric_optimization/energies.cpp b/src/optimization/metric_optimization/energies.cpp index dbbfb4b..fc519ad 100644 --- a/src/optimization/metric_optimization/energies.cpp +++ b/src/optimization/metric_optimization/energies.cpp @@ -1,42 +1,20 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "optimization/metric_optimization/energies.h" #include #include #include -#include "optimization/core/area.h" -#include "optimization/core/cone_metric.h" -#include "optimization/core/constraint.h" -#include "optimization/core/projection.h" +#include "metric/area.h" +#include "metric/cone_metric.h" +#include "metric/constraint.h" +#include "metric/projection.h" /// FIXME Do cleaning pass diff --git a/src/optimization/metric_optimization/energy_functor.cpp b/src/optimization/metric_optimization/energy_functor.cpp index b904f58..22b7891 100644 --- a/src/optimization/metric_optimization/energy_functor.cpp +++ b/src/optimization/metric_optimization/energy_functor.cpp @@ -1,43 +1,21 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "optimization/metric_optimization/energy_functor.h" #include #include #include -#include "optimization/core/area.h" -#include "optimization/core/constraint.h" +#include "metric/area.h" +#include "metric/constraint.h" #include "optimization/metric_optimization/energies.h" #include "optimization/metric_optimization/energy_weights.h" -#include "optimization/core/projection.h" +#include "metric/projection.h" /// FIXME Do cleaning pass diff --git a/src/optimization/metric_optimization/energy_weights.cpp b/src/optimization/metric_optimization/energy_weights.cpp index 9e39040..855782c 100644 --- a/src/optimization/metric_optimization/energy_weights.cpp +++ b/src/optimization/metric_optimization/energy_weights.cpp @@ -1,39 +1,17 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "optimization/metric_optimization/energy_functor.h" -#include "optimization/core/area.h" -#include "optimization/core/constraint.h" +#include "metric/area.h" +#include "metric/constraint.h" #include "optimization/metric_optimization/energies.h" -#include "optimization/core/projection.h" +#include "metric/projection.h" #include "util/vector.h" #include @@ -284,4 +262,4 @@ void compute_boundary_face_weights( } // namespace Optimization -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/optimization/metric_optimization/explicit_optimization.cpp b/src/optimization/metric_optimization/explicit_optimization.cpp index 0c3cb29..bc71739 100644 --- a/src/optimization/metric_optimization/explicit_optimization.cpp +++ b/src/optimization/metric_optimization/explicit_optimization.cpp @@ -1,45 +1,23 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "optimization/metric_optimization/explicit_optimization.h" #include #include -#include "optimization/core/constraint.h" +#include "metric/constraint.h" #include "util/embedding.h" #include "optimization/metric_optimization/energies.h" -#include "optimization/core/globals.h" +#include "metric/globals.h" #include "util/io.h" #include "optimization/metric_optimization/nonlinear_optimization.h" -#include "optimization/core/projection.h" -#include "optimization/core/shear.h" +#include "metric/projection.h" +#include "metric/shear.h" #include "util/vector.h" /// FIXME Do cleaning pass diff --git a/src/optimization/metric_optimization/implicit_optimization.cpp b/src/optimization/metric_optimization/implicit_optimization.cpp index 56d3578..888a2e5 100644 --- a/src/optimization/metric_optimization/implicit_optimization.cpp +++ b/src/optimization/metric_optimization/implicit_optimization.cpp @@ -1,45 +1,23 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "optimization/metric_optimization/implicit_optimization.h" #include #include -#include "optimization/core/area.h" -#include "optimization/core/constraint.h" +#include "metric/area.h" +#include "metric/constraint.h" #include "util/embedding.h" #include "optimization/metric_optimization/energies.h" -#include "optimization/core/globals.h" +#include "metric/globals.h" #include "util/io.h" #include "optimization/metric_optimization/nonlinear_optimization.h" -#include "optimization/core/projection.h" +#include "metric/projection.h" /// FIXME Do cleaning pass diff --git a/src/optimization/metric_optimization/nonlinear_optimization.cpp b/src/optimization/metric_optimization/nonlinear_optimization.cpp index f43a993..309c3e4 100644 --- a/src/optimization/metric_optimization/nonlinear_optimization.cpp +++ b/src/optimization/metric_optimization/nonlinear_optimization.cpp @@ -1,33 +1,11 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "optimization/metric_optimization/nonlinear_optimization.h" #include "util/vector.h" diff --git a/src/optimization/pybind.cpp b/src/optimization/pybind.cpp index dfce184..f3886f0 100644 --- a/src/optimization/pybind.cpp +++ b/src/optimization/pybind.cpp @@ -1,54 +1,34 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "optimization/pybind.h" -#include "optimization/core/common.h" +#include "metric/common.h" -#include "optimization/core/area.h" -#include "optimization/core/constraint.h" +#include "metric/area.h" +#include "metric/constraint.h" #include "optimization/metric_optimization/convergence.h" #include "util/embedding.h" +#include "util/io.h" #include "optimization/metric_optimization/energies.h" #include "optimization/metric_optimization/energy_functor.h" #include "optimization/metric_optimization/explicit_optimization.h" #include "optimization/metric_optimization/implicit_optimization.h" -#include "optimization/parameterization/interpolation.h" -#include "optimization/parameterization/layout.h" +#include "parametrization/interpolation.h" +#include "parametrization/layout.h" #include "optimization/interface.h" -#include "optimization/core/projection.h" -#include "optimization/parameterization/refinement.h" -#include "optimization/core/reparametrization.h" +#include "metric/projection.h" +#include "parametrization/refinement.h" +#include "parametrization/parametrize.h" +#include "metric/reparametrization.h" #include "optimization/util/shapes.h" -#include "optimization/core/shear.h" -#include "optimization/parameterization/translation.h" +#include "metric/shear.h" +#include "parametrization/translation.h" #ifdef USE_HIGHFIVE #include @@ -317,12 +297,6 @@ void init_conformal_pybind(pybind11::module& m) "add shading to mesh", pybind11:: call_guard()); - m.def( - "save_mesh_screen_capture", - &save_mesh_screen_capture, - "save viewer image to png", - pybind11:: - call_guard()); #endif } @@ -559,4 +533,4 @@ void init_optimization_pybind(pybind11::module& m) #endif } // namespace Optimization -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/optimization/tests/test_area.cpp b/src/optimization/tests/test_area.cpp index 402ee99..0895762 100644 --- a/src/optimization/tests/test_area.cpp +++ b/src/optimization/tests/test_area.cpp @@ -1,41 +1,20 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include -#include "area.hh" -#include "shapes.hh" -#include "common.hh" -#include "cone_metric.hh" +#include "metric/area.h" +#include "optimization/util/shapes.h" +#include "metric/common.h" +#include "metric/cone_metric.h" -using namespace CurvatureMetric; +using namespace Penner; +using namespace Penner::Optimization; TEST_CASE( "The squared area of a triangle can be computed", "[area]" ) { diff --git a/src/optimization/tests/test_energies.cpp b/src/optimization/tests/test_energies.cpp index 3fea108..909cc9f 100644 --- a/src/optimization/tests/test_energies.cpp +++ b/src/optimization/tests/test_energies.cpp @@ -1,41 +1,20 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include -#include "energies.hh" -#include "shapes.hh" -#include "common.hh" -#include "cone_metric.hh" +#include "optimization/metric_optimization/energies.h" +#include "optimization/util/shapes.h" +#include "metric/common.h" +#include "metric/cone_metric.h" -using namespace CurvatureMetric; +using namespace Penner; +using namespace Penner::Optimization; TEST_CASE( "The energies of a triangle can be computed", "[energies]" ) { @@ -122,4 +101,4 @@ TEST_CASE( "The errors of a triangle can be computed", "[energies]" ) { CHECK( float_equal(relative_root_mean_square_error(x, x0), std::sqrt(1.25 / (3.0 * 9.0))) ); CHECK( float_equal(root_mean_square_relative_error(x, x0), std::sqrt(0.5 / 3.0)) ); } -} +} \ No newline at end of file diff --git a/src/optimization/tests/test_optimize.cpp b/src/optimization/tests/test_optimize.cpp index caa86c5..e5d74fd 100644 --- a/src/optimization/tests/test_optimize.cpp +++ b/src/optimization/tests/test_optimize.cpp @@ -1,42 +1,21 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include -#include "implicit_optimization.hh" -#include "shapes.hh" -#include "common.hh" -#include "cone_metric.hh" -#include "energy_functor.hh" +#include "optimization/metric_optimization/implicit_optimization.h" +#include "optimization/util/shapes.h" +#include "metric/common.h" +#include "metric/cone_metric.h" +#include "optimization/metric_optimization/energy_functor.h" -using namespace CurvatureMetric; +using namespace Penner; +using namespace Penner::Optimization; TEST_CASE("The optimium edge length for a triangle can be computed", "[optimize]") { @@ -129,4 +108,4 @@ TEST_CASE("The optimium edge length for a square can be computed", "[optimize]") REQUIRE(optimized_reduced_metric_coords.size() == 5); } -} +} \ No newline at end of file diff --git a/src/optimization/tests/test_refinement.cpp b/src/optimization/tests/test_refinement.cpp index 0d0d8b5..7dc34f8 100644 --- a/src/optimization/tests/test_refinement.cpp +++ b/src/optimization/tests/test_refinement.cpp @@ -1,47 +1,27 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include -#include "common.hh" -#include "refinement.hh" -#include "triangulation.hh" +#include "metric/common.h" +#include "parametrization/refinement.h" +#include "parametrization/triangulation.h" -using namespace CurvatureMetric; +using namespace Penner; +using namespace Penner::Optimization; TEST_CASE( "A self overlapping polygon can be identified", "[refinement]" ) { std::vector> is_self_overlapping_subpolygon; std::vector> splitting_vertices; std::vector> min_face_areas; - std::vector uv_vertices, vertices; + std::vector uv_vertices; + std::vector vertices; SECTION ( "Vertex" ) { @@ -253,4 +233,4 @@ TEST_CASE( "A self overlapping polygon can be identified", "[refinement]" ) TEST_CASE( "A valid refinement mesh can be built", "[refinement]" ) { -} +} \ No newline at end of file diff --git a/src/optimization/tests/test_regression.cpp b/src/optimization/tests/test_regression.cpp index 279fe66..ae1cf3c 100644 --- a/src/optimization/tests/test_regression.cpp +++ b/src/optimization/tests/test_regression.cpp @@ -1,43 +1,22 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include #include -#include "common.hh" -#include "penner_optimization_interface.hh" -#include "io.hh" -#include "vector.hh" +#include "metric/common.h" +#include "optimization/interface.h" +#include "util/io.h" +#include "util/vector.h" -using namespace CurvatureMetric; +using namespace Penner; +using namespace Penner::Optimization; namespace { @@ -102,4 +81,4 @@ TEST_CASE("Optimization produces consistent results", "[regression]") // Run regression test CHECK(is_optimized_metric_reproduced(V, F, Th_hat, ground_truth_metric_coords)); } -} +} \ No newline at end of file diff --git a/src/optimization/tests/test_shear.cpp b/src/optimization/tests/test_shear.cpp index 23d2503..a27abd2 100644 --- a/src/optimization/tests/test_shear.cpp +++ b/src/optimization/tests/test_shear.cpp @@ -1,44 +1,23 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include -#include "shear.hh" -#include "shapes.hh" -#include "embedding.hh" -#include "common.hh" -#include "cone_metric.hh" -#include "penner_optimization_interface.hh" -#include "projection.hh" +#include "metric/shear.h" +#include "optimization/util/shapes.h" +#include "util/embedding.h" +#include "metric/common.h" +#include "metric/cone_metric.h" +#include "optimization/interface.h" +#include "metric/projection.h" -using namespace CurvatureMetric; +using namespace Penner; +using namespace Penner::Optimization; TEST_CASE( "A dual shear coordinate basis can be computed", "[shear]" ) { @@ -368,4 +347,4 @@ TEST_CASE( "Shear dual basis coordinates for a pyramid can be computed", "[shear REQUIRE( vector_equal(shear_coords, exact_shear_coords) ); REQUIRE( vector_equal(scale_factors, exact_scale_factors) ); } -} +} \ No newline at end of file diff --git a/src/optimization/tests/tests.cpp b/src/optimization/tests/tests.cpp index 4321e42..6832bb1 100644 --- a/src/optimization/tests/tests.cpp +++ b/src/optimization/tests/tests.cpp @@ -1,33 +1,11 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include #define CATCH_CONFIG_MAIN @@ -37,4 +15,4 @@ #include "test_optimize.cpp" #include "test_shear.cpp" #include "test_refinement.cpp" -#include "test_regression.cpp" +#include "test_regression.cpp" \ No newline at end of file diff --git a/src/optimization/util/shapes.cpp b/src/optimization/util/shapes.cpp index 42ef311..5f59c1a 100644 --- a/src/optimization/util/shapes.cpp +++ b/src/optimization/util/shapes.cpp @@ -1,33 +1,11 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "optimization/util/shapes.h" #include "util/vector.h" #include "conformal_ideal_delaunay/ConformalInterface.hh" diff --git a/src/optimization/util/viewers.cpp b/src/optimization/util/viewers.cpp deleted file mode 100644 index e47642b..0000000 --- a/src/optimization/util/viewers.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#include "optimization/util/viewers.h" - -#include "util/vector.h" -#include "util/vf_mesh.h" - -#include -#if ENABLE_VISUALIZATION -#include "polyscope/surface_mesh.h" -#endif // ENABLE_VISUALIZATION - -namespace Penner { -namespace Optimization { - -void view_flipped_triangles( - const Eigen::MatrixXd& V, - const Eigen::MatrixXi& F, - const Eigen::MatrixXd& uv, - const Eigen::MatrixXi& F_uv) -{ - // Cut the mesh along the parametrization seams - Eigen::MatrixXd V_cut; - cut_mesh_along_parametrization_seams(V, F, uv, F_uv, V_cut); - - // Get the flipped elements - Eigen::VectorXi flipped_f; - igl::flipped_triangles(uv, F_uv, flipped_f); - spdlog::info("{} flipped elements", flipped_f.size()); - - // Convert flipped element list to a scalar function - int num_faces = F_uv.rows(); - Eigen::VectorXd is_flipped; - is_flipped.setZero(num_faces); - for (int i = 0; i < flipped_f.size(); ++i) { - int fi = flipped_f[i]; - is_flipped[fi] = 1.0; - spdlog::info("Face {}: {} is flipped", fi, F_uv.row(fi)); - } - -#if ENABLE_VISUALIZATION - // Add the mesh and uv mesh with flipped element maps - polyscope::init(); - polyscope::registerSurfaceMesh("mesh", V_cut, F_uv) - ->addFaceScalarQuantity("is_flipped", is_flipped); - polyscope::getSurfaceMesh("mesh")->addVertexParameterizationQuantity("uv", uv); - polyscope::registerSurfaceMesh2D("uv mesh", uv, F_uv) - ->addFaceScalarQuantity("is_flipped", is_flipped); - polyscope::show(); -#endif // ENABLE_VISUALIZATION -} - -void view_halfedge_mesh_layout( - const std::vector& next, - const std::vector& f2h, - const std::vector& u_vec, - const std::vector& v_vec) -{ - Eigen::VectorXd u, v; - convert_std_to_eigen_vector(u_vec, u); - convert_std_to_eigen_vector(v_vec, v); - Eigen::MatrixXd uv(u.size(), 3); - uv.col(0) = u; - uv.col(1) = v; - int num_faces = f2h.size(); - Eigen::MatrixXi F(num_faces, 3); - for (int f = 0; f < num_faces; ++f) { - int hij = f2h[f]; - int hjk = next[hij]; - int hki = next[hjk]; - F(f, 0) = hij; - F(f, 1) = hjk; - F(f, 2) = hki; - } -#if ENABLE_VISUALIZATION - spdlog::info("Viewing layout"); - polyscope::init(); - polyscope::registerSurfaceMesh2D("layout", uv, F); - polyscope::show(); -#endif -} - -void view_halfedge_mesh_layout( - const Mesh& m, - const std::vector& u_vec, - const std::vector& v_vec) -{ - view_halfedge_mesh_layout(m.n, m.h, u_vec, v_vec); -} - -void view_parameterization( - const Eigen::MatrixXd& V, - const Eigen::MatrixXi& F, - const Eigen::MatrixXd& uv, - const Eigen::MatrixXi& FT) -{ - // Cut mesh along seams - Eigen::MatrixXd V_cut; - cut_mesh_along_parametrization_seams(V, F, uv, FT, V_cut); - -#ifdef ENABLE_VISUALIZATION - polyscope::init(); - std::string mesh_handle = "cut_mesh"; - - // Add cut mesh with - polyscope::registerSurfaceMesh(mesh_handle, V_cut, FT); - polyscope::getSurfaceMesh(mesh_handle) - ->addVertexParameterizationQuantity("uv", uv) - ->setEnabled(true); - - polyscope::show(); -#else - spdlog::info("Visualization disabled"); -#endif -} - -} // namespace Optimization -} // namespace Penner \ No newline at end of file diff --git a/src/optimization/util/visualization.cc b/src/optimization/util/visualization.cc index 541d844..fb52df3 100644 --- a/src/optimization/util/visualization.cc +++ b/src/optimization/util/visualization.cc @@ -1,33 +1,11 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "visualization.h" namespace Penner { diff --git a/src/optimization/parameterization/interpolation.cpp b/src/parametrization/interpolation.cpp similarity index 93% rename from src/optimization/parameterization/interpolation.cpp rename to src/parametrization/interpolation.cpp index 621c86f..d46d453 100644 --- a/src/optimization/parameterization/interpolation.cpp +++ b/src/parametrization/interpolation.cpp @@ -1,47 +1,24 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#include "optimization/parameterization/interpolation.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "parametrization/interpolation.h" #include "conformal_ideal_delaunay/ConformalIdealDelaunayMapping.hh" #include "conformal_ideal_delaunay/ConformalInterface.hh" #include "util/embedding.h" #include "util/vector.h" -#include "optimization/core/projection.h" -#include "optimization/core/reparametrization.h" -#include "optimization/parameterization/translation.h" +#include "metric/projection.h" +#include "metric/reparametrization.h" +#include "parametrization/translation.h" /// FIXME Do cleaning pass namespace Penner { -namespace Optimization { bool is_vector_equal(const std::vector& v, const std::vector& w) { @@ -1087,5 +1064,4 @@ template void interpolate_vertex_positions( #endif #endif -} // namespace Optimization -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/optimization/parameterization/layout.cpp b/src/parametrization/layout.cpp similarity index 94% rename from src/optimization/parameterization/layout.cpp rename to src/parametrization/layout.cpp index c469aca..b20ff08 100644 --- a/src/optimization/parameterization/layout.cpp +++ b/src/parametrization/layout.cpp @@ -1,34 +1,12 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#include "optimization/parameterization/layout.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "parametrization/layout.h" #include #include @@ -37,21 +15,19 @@ #include "conformal_ideal_delaunay/ConformalInterface.hh" #include "conformal_ideal_delaunay/Layout.hh" #include "util/embedding.h" -#include "optimization/parameterization/interpolation.h" -#include "optimization/core/viewer.h" -#include "optimization/core/projection.h" -#include "optimization/core/constraint.h" -#include "optimization/parameterization/refinement.h" -#include "optimization/parameterization/translation.h" +#include "parametrization/interpolation.h" +#include "metric/viewer.h" +#include "metric/projection.h" +#include "metric/constraint.h" +#include "parametrization/refinement.h" +#include "parametrization/translation.h" #include "util/vector.h" #include "util/vf_mesh.h" #include "util/io.h" -#include "optimization/util/viewers.h" // TODO: cleaning pass namespace Penner { -namespace Optimization { template OverlayMesh add_overlay(const Mesh& m, const VectorX& reduced_metric_coords) @@ -226,6 +202,20 @@ int prev_halfedge( return hli; } +template +int prev_halfedge( + const OverlayMesh& m, + int hij) +{ + int hli = hij; + while (m.n[hli] != hij) + { + hli = m.n[hli]; + } + + return hli; +} + // compute the area of the triangle with vertices ijk template Scalar triangle_area( @@ -1565,5 +1555,4 @@ std::tuple, std::vector, std::vector +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "parametrization/parametrize.h" + +#include "conformal_ideal_delaunay/ConformalInterface.hh" +#include "util/boundary.h" +#include "util/embedding.h" +#include "util/vector.h" +#include "parametrization/interpolation.h" +#include "parametrization/layout.h" +#include "metric/projection.h" +#include "parametrization/translation.h" + +/// FIXME Do cleaning pass + + +namespace Penner { + + +/* +std::vector find_boundary_vertices(const Mesh& m) +{ + std::vector is_bd(m.n_ind_vertices(), false); + for (int i = 0; i < m.n_halfedges(); i++) { + if ((m.type[i] == 1) && (m.type[m.opp[i]] == 2)) + { + is_bd[m.v_rep[m.to[i]]] = true; + } + } + + return is_bd; +} +*/ + +template +std:: + tuple< + OverlayMesh, // m_o + Eigen::MatrixXd, // V_o + Eigen::MatrixXi, // F_o + Eigen::MatrixXd, // uv_o + Eigen::MatrixXi, // FT_o + std::vector, // is_cut_h + std::vector, // is_cut_o + std::vector, // Fn_to_F + std::vector> // endpoints_o + > + generate_VF_mesh_from_halfedge_metric( + const Eigen::MatrixXd& V, + const Mesh& m, + const std::vector& vtx_reindex, + const DifferentiableConeMetric& initial_cone_metric, + const VectorX& reduced_metric_coords, + std::vector cut_h, + bool do_best_fit_scaling, + bool use_uniform_bc, + std::string layout_output_path) +{ + // Get metric target coordinates + auto cone_metric = initial_cone_metric.set_metric_coordinates(reduced_metric_coords); + VectorX metric_target = initial_cone_metric.get_metric_coordinates(); + VectorX metric_coords = cone_metric->get_metric_coordinates(); + + // Get boundary vertices + std::vector is_bd = compute_boundary_vertices(m); + + // Fit conformal scale factors + VectorX metric_coords_scaled = metric_coords; + VectorX scale_factors; + scale_factors.setZero(initial_cone_metric.n_ind_vertices()); + if (do_best_fit_scaling) { + scale_factors = best_fit_conformal(initial_cone_metric, metric_coords); + MatrixX B = conformal_scaling_matrix(initial_cone_metric); + metric_coords_scaled = metric_coords - B * scale_factors; + } + VectorX metric_diff = metric_coords_scaled - metric_target; + SPDLOG_DEBUG( + "Scale factors in range [{}, {}]", + scale_factors.minCoeff(), + scale_factors.maxCoeff()); + SPDLOG_DEBUG( + "Scaled metric coordinates in range [{}, {}]", + metric_coords_scaled.minCoeff(), + metric_coords_scaled.maxCoeff()); + SPDLOG_DEBUG( + "Differences from target to optimized metric in range [{}, {}]", + metric_diff.minCoeff(), + metric_diff.maxCoeff()); + + // Compute interpolation overlay mesh + Eigen::MatrixXd V_overlay; + InterpolationMesh interpolation_mesh, reverse_interpolation_mesh; + spdlog::trace("Interpolating penner coordinates for mesh with {} halfedges", m.n_halfedges()); + interpolate_penner_coordinates( + m, + metric_coords_scaled, + scale_factors, + interpolation_mesh, + reverse_interpolation_mesh); + spdlog::trace("Interpolating vertex positions"); + interpolate_vertex_positions( + V, + vtx_reindex, + interpolation_mesh, + reverse_interpolation_mesh, + V_overlay); + OverlayMesh m_o = interpolation_mesh.get_overlay_mesh(); + make_tufted_overlay(m_o); + + // Get endpoints + std::vector> endpoints; + find_origin_endpoints(m_o, endpoints); + + // Convert overlay mesh to transposed vector format + std::vector> V_overlay_vec(3); + for (int i = 0; i < 3; ++i) { + V_overlay_vec[i].resize(V_overlay.rows()); + for (int j = 0; j < V_overlay.rows(); ++j) { + V_overlay_vec[i][j] = OverlayScalar(V_overlay(j, i)); + } + } + + // Get layout topology from original mesh + std::vector is_cut = compute_layout_topology(m, cut_h); + + // Convert overlay mesh to VL format + spdlog::trace("Getting layout"); + std::vector vtx_reindex_mutable = vtx_reindex; + std::vector u; // (m_o._m.Th_hat.size(), 0.0); + convert_eigen_to_std_vector(scale_factors, u); + // auto parametrize_res = overlay_mesh_to_VL(V, F, Th_hat, m_o, u, V_overlay_vec, + // vtx_reindex_mutable, endpoints, -1); FIXME + return consistent_overlay_mesh_to_VL( + m, + m_o, + vtx_reindex, + is_bd, + u, + V_overlay_vec, + endpoints, + is_cut, + {}, + use_uniform_bc, + layout_output_path); +} + +std:: + tuple< + OverlayMesh, // m_o + Eigen::MatrixXd, // V_o + Eigen::MatrixXi, // F_o + Eigen::MatrixXd, // uv_o + Eigen::MatrixXi, // FT_o + std::vector, // is_cut_h + std::vector, // is_cut_o + std::vector, // Fn_to_F + std::vector> // endpoints_o + > + generate_VF_mesh_from_metric( + const Eigen::MatrixXd& V, + const Eigen::MatrixXi& F, + const std::vector& Th_hat, + const DifferentiableConeMetric& initial_cone_metric, + const VectorX& reduced_metric_coords, + std::vector cut_h, + bool do_best_fit_scaling) +{ + // Get mesh with vertex reindexing + std::vector vtx_reindex, indep_vtx, dep_vtx, v_rep, bnd_loops; + Mesh m = + FV_to_double(V, F, V, F, Th_hat, vtx_reindex, indep_vtx, dep_vtx, v_rep, bnd_loops); + + return generate_VF_mesh_from_halfedge_metric(V, m, vtx_reindex, initial_cone_metric, reduced_metric_coords, cut_h, do_best_fit_scaling); +} + +std:: + tuple< + Eigen::MatrixXd, // V_o + Eigen::MatrixXi, // F_o + Eigen::MatrixXd, // uv_o + Eigen::MatrixXi, // FT_o + std::vector // is_cut_h + > + generate_VF_mesh_from_discrete_metric( + const Eigen::MatrixXd& V, + const Eigen::MatrixXi& F, + const std::vector& Th_hat, + const VectorX& reduced_log_edge_lengths, + std::vector cut_h) +{ + // Get mesh with vertex reindexing + std::vector vtx_reindex, indep_vtx, dep_vtx, v_rep, bnd_loops; + Mesh m = + FV_to_double(V, F, V, F, Th_hat, vtx_reindex, indep_vtx, dep_vtx, v_rep, bnd_loops); + + // Get boundary vertices + std::vector is_bd = compute_boundary_vertices(m); + + // Get layout topology from mesh + std::vector is_cut = compute_layout_topology(m, cut_h); + + // Set metric for layout + DiscreteMetric discrete_metric(m, reduced_log_edge_lengths); + + // Create trivial overlay mesh + OverlayMesh m_o(discrete_metric); + make_tufted_overlay(m_o); + + // Convert vertices to transposed vector format + std::vector> V_overlay_vec(3); + for (int i = 0; i < 3; ++i) { + V_overlay_vec[i].resize(V.rows()); + for (int j = 0; j < V.rows(); ++j) { + V_overlay_vec[i][j] = V(vtx_reindex[j], i); + } + } + + // Get endpoints + std::vector> endpoints; + find_origin_endpoints(m_o, endpoints); + + // Compute layout + std::vector u_vec(m.n_ind_vertices(), 0.0); + //std::vector vtx_reindex_mutable = vtx_reindex; + auto layout_res = consistent_overlay_mesh_to_VL( + m, + m_o, + vtx_reindex, + is_bd, + u_vec, + V_overlay_vec, + endpoints, + is_cut, + {}); + + Eigen::MatrixXd V_l = std::get<1>(layout_res); + Eigen::MatrixXi F_l = std::get<2>(layout_res); + Eigen::MatrixXd uv = std::get<3>(layout_res); + Eigen::MatrixXi FT = std::get<4>(layout_res); + + return std::make_tuple(V_l, F_l, uv, FT, cut_h); +} + +template +std:: + tuple< + OverlayMesh, // m_o + Eigen::MatrixXd, // V_o + Eigen::MatrixXi, // F_o + Eigen::MatrixXd, // uv_o + Eigen::MatrixXi, // FT_o + std::vector, // is_cut_h + std::vector, // is_cut_o + std::vector, // Fn_to_F + std::vector> // endpoints_o + > + generate_VF_mesh_from_halfedge_metric( + const Eigen::MatrixXd& V, + const Mesh& m, + const std::vector& vtx_reindex, + const DifferentiableConeMetric& initial_cone_metric, + const VectorX& reduced_metric_coords, + std::vector cut_h, + bool do_best_fit_scaling, + bool use_uniform_bc, + std::string layout_output_path); + +#ifdef WITH_MPFR +#ifndef MULTIPRECISION + +template +std:: + tuple< + OverlayMesh, // m_o + Eigen::MatrixXd, // V_o + Eigen::MatrixXi, // F_o + Eigen::MatrixXd, // uv_o + Eigen::MatrixXi, // FT_o + std::vector, // is_cut_h + std::vector, // is_cut_o + std::vector, // Fn_to_F + std::vector> // endpoints_o + > + generate_VF_mesh_from_halfedge_metric( + const Eigen::MatrixXd& V, + const Mesh& m, + const std::vector& vtx_reindex, + const DifferentiableConeMetric& initial_cone_metric, + const VectorX& reduced_metric_coords, + std::vector cut_h, + bool do_best_fit_scaling, + bool use_uniform_bc, + std::string layout_output_path); +#endif +#endif + + +} // namespace Penner \ No newline at end of file diff --git a/src/optimization/parameterization/refinement.cpp b/src/parametrization/refinement.cpp similarity index 93% rename from src/optimization/parameterization/refinement.cpp rename to src/parametrization/refinement.cpp index 9555556..a3b2ff9 100644 --- a/src/optimization/parameterization/refinement.cpp +++ b/src/parametrization/refinement.cpp @@ -1,34 +1,12 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#include "optimization/parameterization/refinement.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "parametrization/refinement.h" #include #include #include @@ -40,13 +18,12 @@ #include #include #include -#include "optimization/core/area.h" +#include "metric/area.h" #include "conformal_ideal_delaunay/Halfedge.hh" #include "util/io.h" -#include "optimization/parameterization/triangulation.h" +#include "parametrization/triangulation.h" #include "util/vector.h" #include "util/vf_mesh.h" -#include "optimization/util/viewers.h" #if ENABLE_VISUALIZATION #include "polyscope/point_cloud.h" @@ -56,7 +33,6 @@ /// FIXME Do cleaning pass (Done through viewers) namespace Penner { -namespace Optimization { RefinementMesh::RefinementMesh( const Eigen::MatrixXd& V, @@ -1207,11 +1183,12 @@ bool RefinementMesh::triangulate_face( } // FIXME - if (vertex_indices.size() > 3) { - spdlog::trace("Triangulating face {} of size {}", face_index, vertex_indices.size()); + if (face_triangles.size() > 1) { + spdlog::trace("Triangulating face {} with {} subfaces", face_index, face_triangles.size()); spdlog::trace("Face vertices are {}", formatted_vector(vertex_indices)); } + // Triangulate the face the same as the overlay if it is too large if (compute_face_size(face_index) >= 50) { face_triangles = m_overlay_face_triangles[face_index]; @@ -1234,6 +1211,7 @@ bool RefinementMesh::triangulate_face( // Return false if the face is not self overlapping if (!is_self_overlapping) { spdlog::warn("Face {} with {} vertices is not self overlapping", face_index, vertex_indices.size()); + assert(false); return false; } @@ -1317,5 +1295,4 @@ bool RefinementMesh::is_valid_refinement_mesh() const return true; } -} // namespace Optimization -} // namespace Penner \ No newline at end of file +} // namespace Penner diff --git a/src/optimization/parameterization/translation.cpp b/src/parametrization/translation.cpp similarity index 84% rename from src/optimization/parameterization/translation.cpp rename to src/parametrization/translation.cpp index 079ce79..120503f 100644 --- a/src/optimization/parameterization/translation.cpp +++ b/src/parametrization/translation.cpp @@ -1,34 +1,12 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#include "optimization/parameterization/translation.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "parametrization/translation.h" #include #include @@ -36,13 +14,12 @@ #include "util/embedding.h" #include "util/linear_algebra.h" #include "util/vector.h" -#include "optimization/core/reparametrization.h" -#include "optimization/core/shear.h" +#include "metric/reparametrization.h" +#include "metric/shear.h" /// FIXME Do cleaning pass namespace Penner { -namespace Optimization { /// Generate the Lagrangian system Lx = b for the least squares solution to the halfedge /// translations in the hyperbolic metric needed to satisfy the per halfedge shear @@ -432,5 +409,4 @@ template bool compute_as_symmetric_as_possible_translations( #endif #endif -} // namespace Optimization -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/optimization/parameterization/triangulation.cpp b/src/parametrization/triangulation.cpp similarity index 85% rename from src/optimization/parameterization/triangulation.cpp rename to src/parametrization/triangulation.cpp index 63ba14a..cbb3690 100644 --- a/src/optimization/parameterization/triangulation.cpp +++ b/src/parametrization/triangulation.cpp @@ -1,34 +1,12 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ -#include "optimization/parameterization/triangulation.h" +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + +#include "parametrization/triangulation.h" #include #include @@ -41,12 +19,11 @@ #include #include #include -#include "optimization/core/area.h" +#include "metric/area.h" #include "util/io.h" -#include "optimization/parameterization/refinement.h" -#include "optimization/core/constraint.h" +#include "parametrization/refinement.h" +#include "metric/constraint.h" #include "util/vector.h" -#include "optimization/util/viewers.h" #if ENABLE_VISUALIZATION #include "polyscope/point_cloud.h" @@ -56,8 +33,6 @@ /// FIXME Do cleaning pass namespace Penner { -namespace Optimization { - template Scalar compute_face_area(const std::array& vertices) @@ -475,5 +450,4 @@ void view_triangulation( } -} // namespace Optimization } // namespace Penner \ No newline at end of file diff --git a/src/pybind.cpp b/src/pybind.cpp index bb22aac..351cebe 100644 --- a/src/pybind.cpp +++ b/src/pybind.cpp @@ -1,33 +1,11 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "optimization/pybind.h" #include "holonomy/pybind.h" #include "feature/pybind.h" @@ -50,4 +28,4 @@ PYBIND11_MODULE(penner, m) } #endif -#endif +#endif \ No newline at end of file diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt deleted file mode 100644 index 926e9d1..0000000 --- a/src/util/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -set(UtilSrc - boundary.cpp - common.cpp - embedding.cpp - io.cpp - linear_algebra.cpp - map.cpp - spanning_tree.cpp - vector.cpp - vf_mesh.cpp -) - -add_library(PennerUtilLib - ${UtilSrc} -) -target_include_directories(PennerUtilLib PUBLIC ../../include/util) -target_link_libraries(PennerUtilLib PUBLIC - Eigen3::Eigen - igl::core - igl::predicates - spdlog::spdlog - conformal_cpp - HDF5::HDF5 - #CoMISo - ${MPFR_LIBRARIES} - ${SUITESPARSE_LIBS} - ${POLYSCOPE_LIBRARIES} -) -target_compile_features(PennerUtilLib PUBLIC cxx_std_17) - -target_compile_definitions(PennerUtilLib PUBLIC - SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG -) -# TODO Fix for multiprecision -if ((NOT USE_MULTIPRECISION) AND (DEBUG_WARNINGS)) - target_compile_options(PennerUtilLib PRIVATE - -Wall -Wpedantic -Wextra -Werror - ) -endif() diff --git a/src/util/boundary.cpp b/src/util/boundary.cpp index d2d9641..b23ab68 100644 --- a/src/util/boundary.cpp +++ b/src/util/boundary.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "util/boundary.h" #include "util/vector.h" @@ -138,4 +146,4 @@ std::vector find_boundary_components(const Mesh& m) return boundary_components; } -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/util/common.cpp b/src/util/common.cpp index e99a4b6..fad0473 100644 --- a/src/util/common.cpp +++ b/src/util/common.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "util/common.h" namespace Penner { @@ -14,4 +22,4 @@ glm::vec3 DARK_TEAL(0., 0.5*0.375, 0.5*0.5); #endif -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/util/embedding.cpp b/src/util/embedding.cpp index ad695d0..a4b76d5 100644 --- a/src/util/embedding.cpp +++ b/src/util/embedding.cpp @@ -1,33 +1,11 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "util/embedding.h" namespace Penner { @@ -369,4 +347,4 @@ std::vector generate_face_map(const Mesh& m) return face_map; } -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/util/io.cpp b/src/util/io.cpp index 9c6623d..87931dd 100644 --- a/src/util/io.cpp +++ b/src/util/io.cpp @@ -1,38 +1,17 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "util/io.h" #include "spdlog/sinks/basic_file_sink.h" #include "spdlog/sinks/ostream_sink.h" #include +#include #include "util/vector.h" @@ -166,6 +145,18 @@ void write_integer_matrix(const Eigen::MatrixXi& matrix, const std::string& file return convert_std_to_eigen_matrix(matrix_vec); } +void write_obj_with_uv( + const std::string& filename, + const Eigen::MatrixXd& V, + const Eigen::MatrixXi& F, + const Eigen::MatrixXd& uv, + const Eigen::MatrixXi& F_uv) +{ + Eigen::MatrixXd N; + Eigen::MatrixXi FN; + igl::writeOBJ(filename, V, F, N, FN, uv, F_uv); +} + void write_hdf5_mesh(const std::string& path, const Eigen::MatrixXd& V, // Nx3 const Eigen::MatrixXi& F) // Mx3 @@ -431,4 +422,4 @@ void write_sparse_matrix(const MatrixX& matrix, const std::string& filename, std output_file.close(); } -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/util/linear_algebra.cpp b/src/util/linear_algebra.cpp index 5770c47..8a2219a 100644 --- a/src/util/linear_algebra.cpp +++ b/src/util/linear_algebra.cpp @@ -1,33 +1,11 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "util/linear_algebra.h" #ifdef USE_SUITESPARSE @@ -205,4 +183,4 @@ std::vector generate_linspace(Scalar a, Scalar b, int num_steps) return linspace; } -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/util/map.cpp b/src/util/map.cpp index 71e903f..ebd47af 100644 --- a/src/util/map.cpp +++ b/src/util/map.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "util/map.h" #include "util/vector.h" @@ -7,7 +15,6 @@ namespace Penner { - std::vector index_subset(size_t set_size, const std::vector& subset_indices) { std::vector set_to_subset_mapping; @@ -244,4 +251,4 @@ bool are_polygon_mesh_faces_valid( } -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/util/spanning_tree.cpp b/src/util/spanning_tree.cpp index c21c801..bddd9f3 100644 --- a/src/util/spanning_tree.cpp +++ b/src/util/spanning_tree.cpp @@ -1,3 +1,11 @@ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "util/spanning_tree.h" diff --git a/src/util/vector.cpp b/src/util/vector.cpp index 1633492..eea17da 100644 --- a/src/util/vector.cpp +++ b/src/util/vector.cpp @@ -1,33 +1,11 @@ -/********************************************************************************* -* This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * -* `Metric Optimization in Penner Coordinates` * -* v1.0 * -* * -* The MIT License * -* * -* 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 NON INFRINGEMENT. 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. * -* * -* Author(s): * -* Ryan Capouellez, Denis Zorin, * -* Courant Institute of Mathematical Sciences, New York University, USA * -* * * -*********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "util/vector.h" namespace Penner { @@ -205,4 +183,4 @@ std::vector remove_unreferenced_indices(const std::vector& index_vecto return reduced_vector; } -} // namespace Penner +} // namespace Penner \ No newline at end of file diff --git a/src/util/vf_mesh.cpp b/src/util/vf_mesh.cpp index 290b8ce..a4cd7b7 100644 --- a/src/util/vf_mesh.cpp +++ b/src/util/vf_mesh.cpp @@ -1,33 +1,11 @@ -/********************************************************************************* - * This file is part of reference implementation of SIGGRAPH Asia 2023 Paper * - * `Metric Optimization in Penner Coordinates` * - * v1.0 * - * * - * The MIT License * - * * - * 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 NON INFRINGEMENT. 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. * - * * - * Author(s): * - * Ryan Capouellez, Denis Zorin, * - * Courant Institute of Mathematical Sciences, New York University, USA * - * * * - *********************************************************************************/ +// This file is part of penner-optimization, a constrained parametrization library. +// +// Copyright (C) 2026 Ryan Capouellez +// +// This Source Code Form is subject to the terms of the Mozilla Public License +// v. 2.0. If a copy of the MPL was not distributed with this file, You can +// obtain one at http://mozilla.org/MPL/2.0/. + #include "util/vf_mesh.h" #include "util/vector.h" @@ -318,6 +296,40 @@ std::tuple reindex_mesh( F_reindex(fijk, i) = vtx_reindex[F(fijk, i)]; } } + +} + +Eigen::MatrixXi find_seams( + const Eigen::MatrixXi& F, + const Eigen::MatrixXi& FT) +{ + Eigen::MatrixXi TT; + Eigen::MatrixXi TTi; + igl::triangle_triangle_adjacency(F, TT, TTi); + + int num_faces = F.rows(); + Eigen::MatrixXi F_mask = Eigen::MatrixXi::Zero(num_faces, 3); + for (int f = 0; f < num_faces; ++f) { + // Check if an edge is a cut + for (int k = 0; k < 3; ++k) { + int i = (k + 1) % 3; + int j = (i + 1) % 3; + int f_opp = TT(f, i); + if (F(f, j) != F(f_opp, TTi(f, i))) + spdlog::error("Incorrect 1"); + if (F(f, i) != F(f_opp, (TTi(f, i) + 1) % 3)) + spdlog::error("Incorrect 2"); + int uvi = FT(f, i); + int uvj = FT(f, j); + int uvi_opp = FT(f_opp, (TTi(f, i) + 1) % 3); + int uvj_opp = FT(f_opp, TTi(f, i)); + if ((uvi != uvi_opp) || (uvj != uvj_opp)) { + F_mask(f, k) = 1; + } + } + } + + return F_mask; } -} // namespace Penner +} // namespace Penner \ No newline at end of file