├── .clang-tidy ├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── COPYING.GPL.md ├── COPYING.md ├── CPPLINT.cfg ├── README.md ├── StyleGuide.md ├── cmake ├── Config.cmake.in └── Modules │ └── FindGMock.cmake ├── example ├── CMakeLists.txt ├── ex1.cc ├── iga │ ├── CMakeLists.txt │ ├── cmake │ │ ├── Config.cmake.in │ │ └── Modules │ │ │ └── FindGMock.cmake │ ├── scripts │ │ └── spack-repo │ │ │ ├── packages │ │ │ └── csiga │ │ │ │ └── package.py │ │ │ └── repo.yaml │ ├── src │ │ ├── CMakeLists.txt │ │ ├── basis_function_handler.h │ │ ├── bdf_handler.h │ │ ├── connectivity_handler.h │ │ ├── element.h │ │ ├── element_generator.h │ │ ├── element_integral_calculator.h │ │ ├── element_integration_point.h │ │ ├── itg │ │ │ ├── CMakeLists.txt │ │ │ ├── five_point_gauss_legendre.h │ │ │ ├── four_point_gauss_legendre.h │ │ │ ├── integration_point.h │ │ │ ├── integration_rule.h │ │ │ ├── one_point_gauss_legendre.h │ │ │ ├── three_point_gauss_legendre.h │ │ │ └── two_point_gauss_legendre.h │ │ ├── linear_equation_assembler.h │ │ ├── mapping_handler.h │ │ ├── poisson_problem.h │ │ ├── solution_spline.h │ │ └── solution_vtk_writer.h │ └── test │ │ ├── CMakeLists.txt │ │ ├── basis_function_handler_test.cc │ │ ├── bdf_handler_test.cc │ │ ├── connectivity_handler_test.cc │ │ ├── element_generator_test.cc │ │ ├── element_integral_calculator_test.cc │ │ ├── element_integration_point_test.cc │ │ ├── element_test.cc │ │ ├── integration_point_test.cc │ │ ├── integration_rule_test.cc │ │ ├── linear_equation_assembler_test.cc │ │ ├── mapping_handler_test.cc │ │ ├── matlab_test_data.h │ │ ├── matlab_test_data_2.h │ │ ├── solution_vtk_writer_examples.cc │ │ ├── solution_vtk_writer_test.cc │ │ └── test_spline.h ├── log.txt └── testcase_optimizer.cc ├── external ├── CMakeLists.txt └── pugixml │ ├── CMakeLists.txt │ ├── pugiconfig.hpp │ ├── pugixml.cpp │ └── pugixml.hpp ├── scripts ├── build │ ├── before_install_osx.sh │ ├── create_build_folders.sh │ └── install_spack.sh ├── docker │ ├── Dockerfile.acceptancetests │ ├── Dockerfile.armadillo │ ├── Dockerfile.convert │ ├── Dockerfile.gtest │ ├── Dockerfile.iga │ ├── Dockerfile.install │ ├── Dockerfile.lint.clang-tidy │ ├── Dockerfile.lint.cpplint │ ├── Dockerfile.spack │ ├── Dockerfile.test.clang5.debug │ ├── Dockerfile.test.clang5.release │ ├── Dockerfile.test.clang6.debug │ ├── Dockerfile.test.clang6.release │ ├── Dockerfile.test.coverage │ ├── Dockerfile.test.gcc7.debug │ ├── Dockerfile.test.gcc7.release │ ├── Dockerfile.test.gcc8.debug │ ├── Dockerfile.test.gcc8.release │ ├── Dockerfile.test.gcc8.valgrind │ └── packages.yaml ├── run-clang-tidy.py └── spack-repo │ ├── packages │ └── splinelib │ │ └── package.py │ └── repo.yaml ├── src ├── CMakeLists.txt ├── baf │ ├── CMakeLists.txt │ ├── b_spline_basis_function.cc │ ├── b_spline_basis_function.h │ ├── basis_function.cc │ ├── basis_function.h │ ├── basis_function_factory.cc │ ├── basis_function_factory.h │ ├── control_point.cc │ ├── control_point.h │ ├── knot_vector.cc │ ├── knot_vector.h │ ├── zero_degree_b_spline_basis_function.cc │ └── zero_degree_b_spline_basis_function.h ├── io │ ├── CMakeLists.txt │ ├── executables │ │ ├── CMakeLists.txt │ │ ├── converter_log.cc │ │ ├── converter_log.h │ │ ├── iges_to_irit.cc │ │ ├── iges_to_vtk.cc │ │ ├── iges_to_xml.cc │ │ ├── irit_to_iges.cc │ │ ├── irit_to_vtk.cc │ │ ├── irit_to_xml.cc │ │ ├── xml_to_iges.cc │ │ ├── xml_to_irit.cc │ │ └── xml_to_vtk.cc │ ├── iges_reader.cc │ ├── iges_reader.h │ ├── iges_writer.cc │ ├── iges_writer.h │ ├── io_converter.cc │ ├── io_converter.h │ ├── irit_reader.cc │ ├── irit_reader.h │ ├── irit_reader_utils.h │ ├── irit_writer.cc │ ├── irit_writer.h │ ├── irit_writer_utils.h │ ├── reader.h │ ├── vtk_writer.cc │ ├── vtk_writer.h │ ├── vtk_writer_utils.h │ ├── writer.h │ ├── xml_reader.cc │ ├── xml_reader.h │ ├── xml_reader_utils.h │ ├── xml_writer.cc │ ├── xml_writer.h │ └── xml_writer_utils.h ├── spl │ ├── CMakeLists.txt │ ├── alias.h │ ├── b_spline.h │ ├── b_spline_generator.h │ ├── nurbs.h │ ├── nurbs_generator.h │ ├── parameter_space.h │ ├── physical_space.h │ ├── projection.h │ ├── random_b_spline_generator.h │ ├── random_nurbs_generator.h │ ├── random_spline_utils.h │ ├── spline.h │ ├── spline_generator.h │ ├── square_generator.cc │ ├── square_generator.h │ ├── surface_generator.cc │ ├── surface_generator.h │ └── weighted_physical_space.h └── util │ ├── CMakeLists.txt │ ├── any_casts.h │ ├── element.h │ ├── element_generator.h │ ├── multi_index_handler.h │ ├── named_type.h │ ├── numeric_operations.h │ ├── numeric_settings.h │ ├── random.h │ ├── string_operations.h │ ├── system_operations.h │ └── vector_utils.h └── test ├── CMakeLists.txt ├── acceptance_tests.cc ├── baf ├── CMakeLists.txt ├── b_spline_basis_function_test.cc ├── basis_function_factory.cc ├── control_point_test.cc ├── knot_vector_test.cc └── zero_degree_b_spline_basis_function_test.cc ├── io ├── CMakeLists.txt ├── config_iges.in.h ├── config_irit.in.h ├── config_xml.in.h ├── iges_reader_writer_test.cc ├── io_converter_executables_test.cc ├── io_converter_test.cc ├── irit_reader_writer_test.cc ├── test_files │ ├── read.iges │ ├── read2.iges │ ├── spline_tank.xml │ └── test.itd ├── vtk_writer_test.cc ├── xml_reader_test.cc └── xml_writer_test.cc ├── spl ├── CMakeLists.txt ├── b_spline_2d_mocking.h ├── b_spline_2d_test.cc ├── b_spline_test.cc ├── degree_elevation_test.cc ├── degree_reduction_test.cc ├── knot_insertion_and_removal_test.cc ├── knot_insertion_test.cc ├── knot_removal_test.cc ├── nurbs_2d_mocking.h ├── nurbs_2d_test.cc ├── nurbs_3d_mocking.h ├── nurbs_3d_test.cc ├── nurbs_test.cc ├── parameter_space_test.cc ├── physical_space_test.cc ├── projection_curve_test.cc ├── projection_surface_test.cc ├── random_b_spline_generator_test.cc ├── random_nurbs_generator_test.cc ├── spline_subdivision_test.cc ├── square_generator_test.cc ├── surface_generator_test.cc └── weighted_physical_space_test.cc └── util ├── CMakeLists.txt ├── any_casts_test.cc ├── multi_index_handler_test.cc ├── string_operations_test.cc └── vector_utils_test.cc /.clang-tidy: -------------------------------------------------------------------------------- 1 | Checks: '*,-hicpp-braces-around-statements,-readability-braces-around-statements,-android-*,-llvm-include-order,-fuchsia-overloaded-operator,-fuchsia-default-arguments,-cppcoreguidelines-pro-bounds-constant-array-index' 2 | FormatStyle: google 3 | WarningsAsErrors: '*' 4 | CheckOptions: 5 | - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor 6 | value: '1' 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | build/* 10 | *.pyc 11 | 12 | # Precompiled Headers 13 | *.gch 14 | *.pch 15 | 16 | # Compiled Dynamic libraries 17 | *.so 18 | *.dylib 19 | *.dll 20 | 21 | # Fortran module files 22 | *.mod 23 | *.smod 24 | 25 | # Compiled Static libraries 26 | *.lai 27 | *.la 28 | *.a 29 | *.lib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | 36 | # IDE files 37 | cmake-build-* 38 | .idea 39 | 40 | # mac related files 41 | .DS_Store 42 | ._.DS_Store 43 | 44 | # example build 45 | example/build/* 46 | -------------------------------------------------------------------------------- /CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | linelength=120 2 | filter=-build/include_subdir,-build/c++11 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **This repository is no longer maintained. The work is continued under https://github.com/SplineLib/SplineLib.** 2 | 3 | # SplineLib 4 | Library for spline manipulation. 5 | 6 | ## License 7 | Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 8 | 9 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation version 3 of the License. 11 | 12 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 13 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 14 | details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 17 | http://www.gnu.org/licenses/. 18 | 19 | ### Citation 20 | If you want to use SplineLib in your scientific project please cite [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1320259.svg)](https://doi.org/10.5281/zenodo.1320259). 21 | 22 | ## Status 23 | [![CodeFactor](https://www.codefactor.io/repository/github/mfcats/splinelib/badge)](https://www.codefactor.io/repository/github/mfcats/splinelib) 24 | [![codecov](https://codecov.io/gh/mfcats/SplineLib/branch/master/graph/badge.svg)](https://codecov.io/gh/mfcats/SplineLib) 25 | [![Build Status](https://travis-ci.org/mfcats/SplineLib.svg?branch=master)](https://travis-ci.org/mfcats/SplineLib) 26 | 27 | 28 | ## Installation 29 | 30 | A compiler with C++ 17 support is required to successfully build SplineLib. Compilers that fulfill this requirement are GCC 7, GCC 8, clang 5, and clang 6. The project is tested with these compilers. Therefore, the master branch should always run with them. 31 | 32 | To use SplineLib, you have to clone the github repository to your local machine. 33 | 34 | $ git clone https://github.com/mfcats/SplineLib.git 35 | 36 | For installation of all dependencies you can use spack. 37 | For more information on how to install spack see: https://spack.readthedocs.io/en/latest/ 38 | 39 | After installing spack you need to add the SplineLib repository. 40 | 41 | $ spack repo add path/to/SplineLib/scripts/spack-repo 42 | 43 | After that you can install the SplineLib. 44 | 45 | $ spack install splinelib 46 | 47 | This will install the Google testing framework as dependency and afterwards SplineLib. Then, you can use SplineLib by running 48 | 49 | $ spack load splinelib 50 | 51 | 52 | 53 | 54 | ## Installation for developers 55 | 56 | If you wish to install the SplineLib for development use the following command: 57 | 58 | $ spack setup splinelib@github 59 | 60 | Now go to the SplineLib directory and create a build directory in which you can 61 | build SplineLib with CMake and make. 62 | 63 | $ mkdir build 64 | $ cd build 65 | $ ./spconfig.py .. 66 | 67 | To verify that everything went right you can execute the built-in SplineLib tests. 68 | 69 | $ ./test/SplineLibTests 70 | -------------------------------------------------------------------------------- /StyleGuide.md: -------------------------------------------------------------------------------- 1 | # Style Guide for SplineLib 2 | In general the project sticks to the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html). This 3 | guide only describes these project differs from Google's guide. 4 | 5 | To check if the code is compliant with the Google C++ Style Guide [cpplint](https://github.com/cpplint/cpplint) can be 6 | used. cpplint is a linter written in python. To install the linter see the guidelines on github. 7 | 8 | ## Formatting 9 | ### Line lenght 10 | Google prescribes a [line length](https://google.github.io/styleguide/cppguide.html#Line_Length) of 80 characters. For 11 | modern displays this is a very narrow restriction. Since variable and method names shall be descriptive, this limit is 12 | reached very fast. Therefore, the line length is restricted to 120 characters. To account for this rule the change is 13 | defined in the CPPLINT.cfg of this project. 14 | -------------------------------------------------------------------------------- /cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") 4 | check_required_components("@PROJECT_NAME@") -------------------------------------------------------------------------------- /example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | cmake_minimum_required(VERSION 3.6) 17 | 18 | project(SplineLibExamples LANGUAGES CXX) 19 | set(CMAKE_CXX_STANDARD 17) 20 | 21 | set(SOURCES ex1.cc) 22 | set(OPTIMIZER testcase_optimizer.cc) 23 | 24 | find_package(SplineLib REQUIRED) 25 | 26 | add_executable(ex1 ${SOURCES}) 27 | add_executable(TestcaseOptimizer ${OPTIMIZER}) 28 | 29 | target_link_libraries(ex1 SplineLib::splinelibspl) 30 | target_link_libraries(TestcaseOptimizer SplineLib::splinelibspl SplineLib::splinelibutil SplineLib::splinelibio) 31 | 32 | -------------------------------------------------------------------------------- /example/ex1.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "b_spline.h" 20 | #include "control_point.h" 21 | #include "knot_vector.h" 22 | 23 | int main() { 24 | std::array degree = {Degree{2}}; 25 | std::vector control_points = { 26 | baf::ControlPoint(std::vector({4.0, 2.0})), 27 | baf::ControlPoint(std::vector({7.0, 1.5})), 28 | baf::ControlPoint(std::vector({11.0, 2.0})), 29 | baf::ControlPoint(std::vector({2.5, 4.5})), 30 | baf::ControlPoint(std::vector({3.0, 4.3})), 31 | baf::ControlPoint(std::vector({7.0, 3.0})), 32 | baf::ControlPoint(std::vector({8.0, 2.5})), 33 | baf::ControlPoint(std::vector({8.0, 1.0})) 34 | }; 35 | KnotVectors<1> knot_vector_ptr = 36 | {std::make_shared(baf::KnotVector({ParamCoord{0}, ParamCoord{0}, ParamCoord{0}, ParamCoord{1}, 37 | ParamCoord{2}, ParamCoord{3}, ParamCoord{4}, ParamCoord{4}, 38 | ParamCoord{5}, ParamCoord{5}, ParamCoord{5}}))}; 39 | spl::BSpline<1> b_spline(knot_vector_ptr, degree, control_points); 40 | 41 | b_spline.Evaluate({ParamCoord{1.0}}, {0}); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /example/iga/cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") 4 | check_required_components("@PROJECT_NAME@") -------------------------------------------------------------------------------- /example/iga/scripts/spack-repo/packages/csiga/package.py: -------------------------------------------------------------------------------- 1 | # Copyright 2013-2019 Lawrence Livermore National Security, LLC and other 2 | # Spack Project Developers. See the top-level COPYRIGHT file for details. 3 | # 4 | # SPDX-License-Identifier: (Apache-2.0 OR MIT) 5 | 6 | # ---------------------------------------------------------------------------- 7 | # If you submit this package back to Spack as a pull request, 8 | # please first remove this boilerplate and all FIXME comments. 9 | # 10 | # This is a template package file for Spack. We've put "FIXME" 11 | # next to all the things you'll want to change. Once you've handled 12 | # them, you can save this file and test your package like this: 13 | # 14 | # spack install csiga 15 | # 16 | # You can edit this file again by typing: 17 | # 18 | # spack edit csiga 19 | # 20 | # See the Spack documentation for more information on packaging. 21 | # ---------------------------------------------------------------------------- 22 | 23 | from spack import * 24 | 25 | 26 | class Csiga(CMakePackage): 27 | """Library for Isogeometric Analysis.""" 28 | 29 | homepage = "https://git.rwth-aachen.de/christophsusen/csiga" 30 | url = "" 31 | 32 | version('github', git='https://git.rwth-aachen.de/christophsusen/csiga.git', branch='master') 33 | 34 | depends_on("googletest+gmock~shared") 35 | depends_on("armadillo") 36 | depends_on("splinelib") 37 | 38 | def cmake_args(self): 39 | options = [] 40 | return options 41 | -------------------------------------------------------------------------------- /example/iga/scripts/spack-repo/repo.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Created by Christoph Susen on 24.01.19. 3 | # 4 | 5 | repo: 6 | namespace: csiga-software 7 | -------------------------------------------------------------------------------- /example/iga/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | add_subdirectory(itg) 17 | 18 | list(APPEND CMAKE_PREFIX_PATH /usr/local/opt/spack/linux-ubuntu18.04-x86_64/gcc-8/splinelib-github-t7by6dejarqmydvm2xo5zgcqtvkpz3dz) 19 | 20 | find_package(Armadillo REQUIRED) 21 | find_package(SplineLib REQUIRED) 22 | 23 | add_library(CSiga INTERFACE) 24 | target_include_directories(CSiga INTERFACE 25 | $ ${ARMADILLO_INCLUDE_DIRS}) 26 | target_link_libraries(CSiga INTERFACE CSigaitg SplineLib::splinelibspl SplineLib::splinelibio ${ARMADILLO_LIBRARIES}) 27 | 28 | install( 29 | TARGETS CSiga 30 | EXPORT "${targets_export_name}" 31 | LIBRARY DESTINATION "${library_install_dir}" 32 | ARCHIVE DESTINATION "${library_install_dir}" 33 | RUNTIME DESTINATION "${executable_install_dir}" 34 | INCLUDES DESTINATION "${include_install_dir}" 35 | ) 36 | 37 | install(FILES 38 | basis_function_handler.h 39 | bdf_handler.h 40 | connectivity_handler.h 41 | element.h 42 | element_generator.h 43 | element_integral_calculator.h 44 | element_integration_point.h 45 | linear_equation_assembler.h 46 | mapping_handler.h 47 | poisson_problem.h 48 | solution_spline.h 49 | solution_vtk_writer.h 50 | DESTINATION "${include_install_dir}") 51 | -------------------------------------------------------------------------------- /example/iga/src/connectivity_handler.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IGA_CONNECTIVITY_HANDLER_H_ 16 | #define SRC_IGA_CONNECTIVITY_HANDLER_H_ 17 | 18 | #include 19 | 20 | #include "element_generator.h" 21 | #include "multi_index_handler.h" 22 | #include "spline.h" 23 | 24 | namespace iga { 25 | template 26 | class ConnectivityHandler { 27 | public: 28 | explicit ConnectivityHandler(std::shared_ptr> spl) : spline_(std::move(spl)) { 29 | elm_gen_ = std::make_shared>(spline_); 30 | } 31 | 32 | int GetGlobalIndex(int element_number, int local_index) { 33 | return Get1DGlobalIndex(GetGlobalIndicesPerParametricDirection(element_number, local_index)); 34 | } 35 | 36 | private: 37 | std::array GetGlobalIndicesPerParametricDirection(int elm_num, int local_index) { 38 | util::MultiIndexHandler mult_ind_handl_elm(elm_gen_->GetNumElementsPerParamDir()); 39 | mult_ind_handl_elm = mult_ind_handl_elm + elm_num; 40 | std::array num_non_zero_baf{}; 41 | for (int i = 0; i < DIM; ++i) { 42 | num_non_zero_baf[i] = spline_->GetDegree(i).get() + 1; 43 | } 44 | util::MultiIndexHandler mult_ind_handl_baf(num_non_zero_baf); 45 | mult_ind_handl_baf = mult_ind_handl_baf + local_index; 46 | std::array knot_mult_index_shift = elm_gen_->GetKnotMultiplicityIndexShift(elm_num); 47 | std::array global_indices{}; 48 | for (int i = 0; i < DIM; ++i) { 49 | global_indices[i] = mult_ind_handl_baf[i] + mult_ind_handl_elm[i] + knot_mult_index_shift[i]; 50 | } 51 | return global_indices; 52 | } 53 | 54 | int Get1DGlobalIndex(std::array global_indices) { 55 | util::MultiIndexHandler mult_ind_handl_cp(spline_->GetPointsPerDirection()); 56 | mult_ind_handl_cp.SetIndices(global_indices); 57 | return mult_ind_handl_cp.Get1DIndex() + 1; 58 | } 59 | 60 | std::shared_ptr> spline_; 61 | std::shared_ptr> elm_gen_; 62 | }; 63 | } // namespace iga 64 | 65 | #endif // SRC_IGA_CONNECTIVITY_HANDLER_H_ 66 | -------------------------------------------------------------------------------- /example/iga/src/element.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IGA_ELM_ELEMENT_H_ 16 | #define SRC_IGA_ELM_ELEMENT_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "control_point.h" 22 | #include "knot_vector.h" 23 | 24 | namespace iga { 25 | namespace elm { 26 | class Element { 27 | public: 28 | explicit Element(const std::array &nodes) : nodes_(nodes) {} 29 | 30 | ParamCoord GetLowerBound() const { 31 | return nodes_[0]; 32 | } 33 | 34 | ParamCoord GetUpperBound() const { 35 | return nodes_[1]; 36 | } 37 | 38 | private: 39 | std::array nodes_; 40 | }; 41 | } // namespace elm 42 | } // namespace iga 43 | 44 | #endif // SRC_IGA_ELM_ELEMENT_H_ 45 | -------------------------------------------------------------------------------- /example/iga/src/element_integration_point.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IGA_ELM_ELEMENT_INTEGRATION_POINT_H_ 16 | #define SRC_IGA_ELM_ELEMENT_INTEGRATION_POINT_H_ 17 | 18 | #include 19 | #include 20 | 21 | namespace iga { 22 | namespace elm { 23 | template 24 | class ElementIntegrationPoint { 25 | public: 26 | ElementIntegrationPoint(std::vector basis_functions, double weight, 27 | double jac_det) : non_zero_basis_functions_(std::move(basis_functions)), weight_(weight), jac_det_(jac_det) {} 28 | 29 | ElementIntegrationPoint(std::array, DIM> basis_function_derivatives, double weight, 30 | double jac_det) : non_zero_basis_function_derivatives_(std::move(basis_function_derivatives)), 31 | weight_(weight), jac_det_(jac_det) {} 32 | 33 | std::vector GetNonZeroBasisFunctions() const { 34 | return non_zero_basis_functions_; 35 | } 36 | 37 | std::vector GetNonZeroBasisFunctionDerivatives(int dir) const { 38 | return non_zero_basis_function_derivatives_[dir]; 39 | } 40 | 41 | double GetWeight() const { 42 | return weight_; 43 | } 44 | 45 | double GetJacobianDeterminant() const { 46 | return jac_det_; 47 | } 48 | 49 | int GetNumberOfNonZeroBasisFunctions() const { 50 | return static_cast(non_zero_basis_functions_.size()); 51 | } 52 | 53 | int GetNumberOfNonZeroBasisFunctionDerivatives(int dir) const { 54 | return static_cast(non_zero_basis_function_derivatives_[dir].size()); 55 | } 56 | 57 | double GetBasisFunctionValue(int firstNonZeroOffset) const { 58 | return non_zero_basis_functions_[firstNonZeroOffset]; 59 | } 60 | 61 | double GetBasisFunctionDerivativeValue(int firstNonZeroOffset, int dir) const { 62 | return non_zero_basis_function_derivatives_[dir][firstNonZeroOffset]; 63 | } 64 | 65 | private: 66 | std::vector non_zero_basis_functions_; 67 | std::array, DIM> non_zero_basis_function_derivatives_; 68 | double weight_; 69 | double jac_det_; 70 | }; 71 | } // namespace elm 72 | } // namespace iga 73 | 74 | #endif // SRC_IGA_ELM_ELEMENT_INTEGRATION_POINT_H_ 75 | -------------------------------------------------------------------------------- /example/iga/src/itg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | add_library(CSigaitg INTERFACE) 17 | target_include_directories(CSigaitg INTERFACE $) 18 | 19 | install( 20 | TARGETS CSigaitg 21 | EXPORT "${targets_export_name}" 22 | LIBRARY DESTINATION "${library_install_dir}" 23 | ARCHIVE DESTINATION "${library_install_dir}" 24 | RUNTIME DESTINATION "${executable_install_dir}" 25 | INCLUDES DESTINATION "${include_install_dir}" 26 | ) 27 | 28 | install(FILES 29 | five_point_gauss_legendre.h 30 | four_point_gauss_legendre.h 31 | integration_point.h 32 | integration_rule.h 33 | one_point_gauss_legendre.h 34 | three_point_gauss_legendre.h 35 | two_point_gauss_legendre.h 36 | DESTINATION "${include_install_dir}") 37 | -------------------------------------------------------------------------------- /example/iga/src/itg/five_point_gauss_legendre.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IGA_ITG_FIVE_POINT_GAUSS_LEGENDRE_H_ 16 | #define SRC_IGA_ITG_FIVE_POINT_GAUSS_LEGENDRE_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "integration_rule.h" 22 | 23 | namespace iga { 24 | namespace itg { 25 | class FivePointGaussLegendre : public IntegrationRule { 26 | public: 27 | FivePointGaussLegendre() : IntegrationRule({ 28 | IntegrationPoint(-(1.0 / 3) * sqrt(5 + 2.0 * sqrt(10.0 / 7)), (322.0 - 13 * sqrt(70)) / 900), 29 | IntegrationPoint(-(1.0 / 3) * sqrt(5 - 2.0 * sqrt(10.0 / 7)), (322.0 + 13 * sqrt(70)) / 900), 30 | IntegrationPoint(0, 128.0 / 225), 31 | IntegrationPoint((1.0 / 3) * sqrt(5 - 2.0 * sqrt(10.0 / 7)), (322.0 + 13 * sqrt(70)) / 900), 32 | IntegrationPoint((1.0 / 3) * sqrt(5 + 2.0 * sqrt(10.0 / 7)), (322.0 - 13 * sqrt(70)) / 900)}) {} 33 | }; 34 | } // namespace itg 35 | } // namespace iga 36 | 37 | #endif // SRC_IGA_ITG_FIVE_POINT_GAUSS_LEGENDRE_H_ 38 | -------------------------------------------------------------------------------- /example/iga/src/itg/four_point_gauss_legendre.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IGA_ITG_FOUR_POINT_GAUSS_LEGENDRE_H_ 16 | #define SRC_IGA_ITG_FOUR_POINT_GAUSS_LEGENDRE_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "integration_rule.h" 22 | 23 | namespace iga { 24 | namespace itg { 25 | class FourPointGaussLegendre : public IntegrationRule { 26 | public: 27 | FourPointGaussLegendre() : IntegrationRule({ 28 | IntegrationPoint(-sqrt(3.0 / 7 + 2.0 / 7 * sqrt(6.0 / 5)), (18.0 - sqrt(30)) / 36), 29 | IntegrationPoint(-sqrt(3.0 / 7 - 2.0 / 7 * sqrt(6.0 / 5)), (18.0 + sqrt(30)) / 36), 30 | IntegrationPoint(sqrt(3.0 / 7 - 2.0 / 7 * sqrt(6.0 / 5)), (18.0 + sqrt(30)) / 36), 31 | IntegrationPoint(sqrt(3.0 / 7 + 2.0 / 7 * sqrt(6.0 / 5)), (18.0 - sqrt(30)) / 36)}) {} 32 | }; 33 | } // namespace itg 34 | } // namespace iga 35 | 36 | #endif // SRC_IGA_ITG_FOUR_POINT_GAUSS_LEGENDRE_H_ 37 | -------------------------------------------------------------------------------- /example/iga/src/itg/integration_point.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include 16 | 17 | #ifndef SRC_IGA_ITG_INTEGRATION_POINT_H_ 18 | #define SRC_IGA_ITG_INTEGRATION_POINT_H_ 19 | 20 | namespace iga { 21 | namespace itg { 22 | class IntegrationPoint { 23 | public: 24 | IntegrationPoint(double coordinate, double weight) 25 | : coordinate_(coordinate), weight_(weight) {} 26 | 27 | double GetCoordinate() const { 28 | return coordinate_; 29 | } 30 | 31 | double GetWeight() const { 32 | return weight_; 33 | } 34 | 35 | private: 36 | double coordinate_; 37 | double weight_; 38 | }; 39 | } // namespace itg 40 | } // namespace iga 41 | 42 | #endif // SRC_IGA_ITG_INTEGRATION_POINT_H_ 43 | -------------------------------------------------------------------------------- /example/iga/src/itg/integration_rule.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IGA_ITG_INTEGRATION_RULE_H_ 16 | #define SRC_IGA_ITG_INTEGRATION_RULE_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "integration_point.h" 22 | #include "multi_index_handler.h" 23 | 24 | namespace iga { 25 | namespace itg { 26 | class IntegrationRule { 27 | public: 28 | virtual ~IntegrationRule() = default; 29 | 30 | explicit IntegrationRule(std::vector points) : points_(std::move(points)) {} 31 | 32 | int GetNumberOfIntegrationPoints() const { 33 | return points_.size(); 34 | } 35 | 36 | double GetCoordinate(int point) const { 37 | #ifdef DEBUG 38 | return points_.at(point).GetCoordinate(); 39 | #else 40 | return points_[point].GetCoordinate(); 41 | #endif 42 | } 43 | 44 | std::vector GetIntegrationPoints() const { 45 | return points_; 46 | } 47 | 48 | private: 49 | std::vector points_; 50 | }; 51 | } // namespace itg 52 | } // namespace iga 53 | 54 | #endif // SRC_IGA_ITG_INTEGRATION_RULE_H_ 55 | -------------------------------------------------------------------------------- /example/iga/src/itg/one_point_gauss_legendre.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IGA_ITG_ONE_POINT_GAUSS_LEGENDRE_H_ 16 | #define SRC_IGA_ITG_ONE_POINT_GAUSS_LEGENDRE_H_ 17 | 18 | #include "integration_rule.h" 19 | 20 | namespace iga { 21 | namespace itg { 22 | class OnePointGaussLegendre : public IntegrationRule { 23 | public: 24 | OnePointGaussLegendre() : IntegrationRule({IntegrationPoint(0, 2)}) {} 25 | }; 26 | } // namespace itg 27 | } // namespace iga 28 | 29 | #endif // SRC_IGA_ITG_ONE_POINT_GAUSS_LEGENDRE_H_ 30 | -------------------------------------------------------------------------------- /example/iga/src/itg/three_point_gauss_legendre.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IGA_ITG_THREE_POINT_GAUSS_LEGENDRE_H_ 16 | #define SRC_IGA_ITG_THREE_POINT_GAUSS_LEGENDRE_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "integration_rule.h" 22 | 23 | namespace iga { 24 | namespace itg { 25 | class ThreePointGaussLegendre : public IntegrationRule { 26 | public: 27 | ThreePointGaussLegendre() : IntegrationRule( 28 | {IntegrationPoint(-sqrt(3.0 / 5), 5.0 / 9.0), 29 | IntegrationPoint(0, 8.0 / 9.0), 30 | IntegrationPoint(sqrt(3.0 / 5), 5.0 / 9.0)}) {} 31 | }; 32 | } // namespace itg 33 | } // namespace iga 34 | 35 | #endif // SRC_IGA_ITG_THREE_POINT_GAUSS_LEGENDRE_H_ 36 | -------------------------------------------------------------------------------- /example/iga/src/itg/two_point_gauss_legendre.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IGA_ITG_TWO_POINT_GAUSS_LEGENDRE_H_ 16 | #define SRC_IGA_ITG_TWO_POINT_GAUSS_LEGENDRE_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "integration_rule.h" 22 | 23 | namespace iga { 24 | namespace itg { 25 | class TwoPointGaussLegendre : public IntegrationRule { 26 | public: 27 | TwoPointGaussLegendre() : IntegrationRule({IntegrationPoint(-sqrt(1.0 / 3), 1), 28 | IntegrationPoint(sqrt(1.0 / 3), 1)}) {} 29 | }; 30 | } // namespace itg 31 | } // namespace iga 32 | 33 | #endif // SRC_IGA_ITG_TWO_POINT_GAUSS_LEGENDRE_H_ 34 | -------------------------------------------------------------------------------- /example/iga/src/solution_spline.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IGA_SOLUTION_SPLINE_H_ 16 | #define SRC_IGA_SOLUTION_SPLINE_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "nurbs.h" 22 | 23 | namespace iga { 24 | template 25 | class SolutionSpline { 26 | public: 27 | SolutionSpline(const std::shared_ptr> &spl, const arma::dvec &solution) { 28 | std::vector control_points; 29 | std::array points_per_direction = spl->GetPointsPerDirection(); 30 | util::MultiIndexHandler point_handler(points_per_direction); 31 | for (uint64_t i = 0, l = 0; i < static_cast(spl->GetNumberOfControlPoints()); ++i, ++point_handler, ++l) { 32 | std::vector temp; 33 | for (int j = 0; j < spl->GetPointDim(); ++j) { 34 | temp.emplace_back(spl->GetControlPoint(point_handler.GetIndices(), j)); 35 | } 36 | temp.emplace_back(solution(l)); 37 | control_points.emplace_back(baf::ControlPoint(temp)); 38 | } 39 | solution_spl_ = std::make_shared>(*spl.get(), control_points); 40 | } 41 | 42 | std::shared_ptr> GetSolutionSpline() { 43 | return solution_spl_; 44 | } 45 | 46 | private: 47 | std::shared_ptr> solution_spl_; 48 | }; 49 | } // namespace iga 50 | 51 | #endif // SRC_IGA_SOLUTION_SPLINE_H_ 52 | -------------------------------------------------------------------------------- /example/iga/src/solution_vtk_writer.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IGA_SOLUTION_VTK_WRITER_H_ 16 | #define SRC_IGA_SOLUTION_VTK_WRITER_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "multi_index_handler.h" 24 | #include "nurbs.h" 25 | #include "solution_spline.h" 26 | #include "vtk_writer.h" 27 | 28 | namespace iga { 29 | template 30 | class SolutionVTKWriter { 31 | public: 32 | SolutionVTKWriter() = default; 33 | 34 | void WriteSolutionToVTK(const std::shared_ptr> &spl, const arma::dvec &solution, 35 | const std::vector> &scattering, const std::string &filename) const { 36 | iga::SolutionSpline sol_spl(spl, solution); 37 | std::shared_ptr> solution_spl = sol_spl.GetSolutionSpline(); 38 | int cp_dim = spl->GetPointDim(); 39 | std::vector dxi; 40 | std::array num_pnts{}; 41 | for (int i = 0; i < DIM; ++i) { 42 | baf::KnotVector knots = *spl->GetKnotVector(i); 43 | dxi.emplace_back((knots.GetKnot(knots.GetNumberOfKnots() - 1) - knots.GetKnot(0)).get() / scattering[0][i]); 44 | num_pnts[i] = scattering[0][i] + 1; 45 | } 46 | std::vector point_data; 47 | util::MultiIndexHandler mih(num_pnts); 48 | while (true) { 49 | std::array param_coords{}; 50 | for (int i = 0; i < DIM; ++i) { 51 | param_coords[i] = spl->GetKnotVector(i)->GetKnot(0) + ParamCoord{mih[i] * dxi[i]}; 52 | } 53 | point_data.emplace_back(solution_spl->Evaluate(param_coords, {cp_dim})[0]); 54 | if (mih.Get1DIndex() == mih.Get1DLength() - 1) break; 55 | ++mih; 56 | } 57 | io::VTKWriter vtk_writer; 58 | std::vector splines = {std::make_any>>(spl)}; 59 | vtk_writer.WriteFile(splines, filename, scattering); 60 | std::ofstream newFile; 61 | newFile.open(filename, std::ofstream::out | std::ofstream::app); 62 | if (newFile.is_open()) { 63 | newFile << "\nPOINT_DATA " << point_data.size() << "\nSCALARS solution float 1\nLOOKUP_TABLE default\n"; 64 | for (auto &p : point_data) { 65 | newFile << p << "\n"; 66 | } 67 | newFile.close(); 68 | } 69 | } 70 | }; 71 | } // namespace iga 72 | 73 | #endif // SRC_IGA_SOLUTION_VTK_WRITER_H_ 74 | -------------------------------------------------------------------------------- /example/iga/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | set(TEST_SOURCES 17 | basis_function_handler_test.cc 18 | bdf_handler_test.cc 19 | connectivity_handler_test.cc 20 | element_generator_test.cc 21 | element_integral_calculator_test.cc 22 | element_integration_point_test.cc 23 | element_test.cc 24 | integration_point_test.cc 25 | integration_rule_test.cc 26 | linear_equation_assembler_test.cc 27 | mapping_handler_test.cc 28 | solution_vtk_writer_examples.cc 29 | solution_vtk_writer_test.cc) 30 | 31 | find_package(GMock REQUIRED) 32 | #include_directories(${GTEST_INCLUDE_DIRS}) 33 | 34 | add_executable(CSigaTests ${TEST_SOURCES}) 35 | target_link_libraries(CSigaTests CSiga GMock::Main) 36 | 37 | target_compile_definitions(CSigaTests PRIVATE GTEST_HAS_PTHREAD=0) 38 | -------------------------------------------------------------------------------- /example/iga/test/connectivity_handler_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "gmock/gmock.h" 16 | #include "connectivity_handler.h" 17 | #include "test_spline.h" 18 | 19 | using testing::Eq; 20 | 21 | TEST_F(AnIGATestSpline, TestConnectivityHandler) { // NOLINT 22 | iga::ConnectivityHandler<2> connectivity_handler = iga::ConnectivityHandler<2>(nurbs_); 23 | std::vector e1 = {1, 2, 3, 4, 8, 9, 10, 11, 15, 16, 17, 18, 22, 23, 24, 25}; 24 | std::vector e2 = {2, 3, 4, 5, 9, 10, 11, 12, 16, 17, 18, 19, 23, 24, 25, 26}; 25 | std::vector e3 = {3, 4, 5, 6, 10, 11, 12, 13, 17, 18, 19, 20, 24, 25, 26, 27}; 26 | std::vector e4 = {4, 5, 6, 7, 11, 12, 13, 14, 18, 19, 20, 21, 25, 26, 27, 28}; 27 | std::vector e5 = {22, 23, 24, 25, 29, 30, 31, 32, 36, 37, 38, 39, 43, 44, 45, 46}; 28 | std::vector e6 = {23, 24, 25, 26, 30, 31, 32, 33, 37, 38, 39, 40, 44, 45, 46, 47}; 29 | std::vector e7 = {24, 25, 26, 27, 31, 32, 33, 34, 38, 39, 40, 41, 45, 46, 47, 48}; 30 | std::vector e8 = {25, 26, 27, 28, 32, 33, 34, 35, 39, 40, 41, 42, 46, 47, 48, 49}; 31 | std::vector> connectivity_matlab = {e1, e2, e3, e4, e5, e6, e7, e8}; 32 | for (uint64_t i = 0; i < connectivity_matlab.size(); ++i) { 33 | for (uint64_t j = 0; j < connectivity_matlab[i].size(); ++j) { 34 | ASSERT_THAT(connectivity_handler.GetGlobalIndex(i, j), Eq(connectivity_matlab[i][j])); 35 | } 36 | } 37 | } 38 | 39 | TEST_F(AnIGATestSpline3, TestConnectivityHandler) { // NOLINT 40 | iga::ConnectivityHandler<3> connectivity_handler = iga::ConnectivityHandler<3>(nurbs_); 41 | ASSERT_THAT(connectivity_handler.GetGlobalIndex(15, 10), Eq(188)); 42 | } 43 | -------------------------------------------------------------------------------- /example/iga/test/element_generator_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include 16 | #include "gmock/gmock.h" 17 | 18 | #include "element_generator.h" 19 | 20 | using testing::Test; 21 | 22 | class A1DElementGenerator : public Test { 23 | public: 24 | std::array knot_vector = 25 | {baf::KnotVector({ParamCoord{0}, ParamCoord{0}, ParamCoord{0}, ParamCoord{1}, 26 | ParamCoord{2}, ParamCoord{3}, ParamCoord{4}, ParamCoord{4}, 27 | ParamCoord{5}, ParamCoord{5}, ParamCoord{5}})}; 28 | std::array degree = {Degree{2}}; 29 | std::vector control_points = { 30 | baf::ControlPoint(std::vector({0.0, 0.0, 0.0})), 31 | baf::ControlPoint(std::vector({1.0, 0.0, 0.0})), 32 | baf::ControlPoint(std::vector({2.0, 0.0, 0.0})), 33 | baf::ControlPoint(std::vector({3.0, 0.0, 0.0})), 34 | baf::ControlPoint(std::vector({4.0, 0.0, 0.0})), 35 | baf::ControlPoint(std::vector({5.0, 0.0, 0.0})), 36 | baf::ControlPoint(std::vector({6.0, 0.0, 0.0})), 37 | baf::ControlPoint(std::vector({7.0, 0.0, 0.0}))}; 38 | KnotVectors<1> kv_ptr = {std::make_shared(knot_vector[0])}; 39 | std::shared_ptr> b_spline = std::make_shared>(kv_ptr, degree, control_points); 40 | 41 | A1DElementGenerator() : element_generator(b_spline) {} 42 | 43 | protected: 44 | iga::elm::ElementGenerator<1> element_generator; 45 | }; 46 | 47 | TEST_F(A1DElementGenerator, ReturnsCorrectNumberOfElements) { // NOLINT 48 | ASSERT_THAT(element_generator.GetElementList(0).size(), 5); 49 | } 50 | 51 | TEST_F(A1DElementGenerator, ReturnsElementsWithCorrectNodes) { // NOLINT 52 | auto element_list = element_generator.GetElementList(0); 53 | for (auto element = 0u; element < element_list.size(); element++) { 54 | ASSERT_THAT(element_list[element].GetLowerBound().get(), element); 55 | ASSERT_THAT(element_list[element].GetUpperBound().get(), element + 1); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /example/iga/test/element_integral_calculator_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include "gmock/gmock.h" 19 | #include "matlab_test_data.h" 20 | #include "test_spline.h" 21 | 22 | using testing::DoubleNear; 23 | 24 | TEST_F(AnIGATestSpline, TestElementIntegralCalculator) { // NOLINT 25 | elm_itg_calc.GetLaplaceElementIntegral(0, rule, matA); 26 | for (uint64_t i = 0; i < matlab_element_one_integral.size(); ++i) { 27 | for (uint64_t j = 0; j < matlab_element_one_integral[0].size(); ++j) { 28 | ASSERT_THAT((*matA)(i, j), DoubleNear(matlab_element_one_integral[i][j], 0.00005)); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /example/iga/test/element_integration_point_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include 16 | 17 | #include "gmock/gmock.h" 18 | 19 | #include "element_integration_point.h" 20 | 21 | using testing::DoubleEq; 22 | using testing::Test; 23 | 24 | class AnElementIntegrationPoint : public Test{ 25 | public: 26 | AnElementIntegrationPoint() : element_integration_point({2.3, 4.5}, 0.75, 1.75) {} 27 | 28 | protected: 29 | iga::elm::ElementIntegrationPoint<1> element_integration_point; 30 | }; 31 | 32 | TEST_F(AnElementIntegrationPoint, GetNonZeroBasisFunctions) { //NOLINT 33 | ASSERT_THAT(element_integration_point.GetNonZeroBasisFunctions()[0] , DoubleEq(2.3)); 34 | ASSERT_THAT(element_integration_point.GetNonZeroBasisFunctions()[1] , DoubleEq(4.5)); 35 | } 36 | 37 | TEST_F(AnElementIntegrationPoint, SizeEqualsTwo) { //NOLINT 38 | ASSERT_THAT(element_integration_point.GetNumberOfNonZeroBasisFunctions(), 2); 39 | } 40 | 41 | TEST_F(AnElementIntegrationPoint, GetValueAtZero) { //NOLINT 42 | ASSERT_THAT(element_integration_point.GetBasisFunctionValue(1), DoubleEq(4.5)); 43 | } 44 | 45 | TEST_F(AnElementIntegrationPoint, GetWeight) { //NOLINT 46 | ASSERT_THAT(element_integration_point.GetWeight(), DoubleEq(0.75)); 47 | } 48 | 49 | TEST_F(AnElementIntegrationPoint, GetJacobianDeterminant) { //NOLINT 50 | ASSERT_THAT(element_integration_point.GetJacobianDeterminant(), DoubleEq(1.75)); 51 | } 52 | 53 | class AnElementIntegrationPointWithDerivatives : public Test{ 54 | public: 55 | std::array, 2> baf_ders = {std::vector({2.3, 4.5}), std::vector({3.2, 5.4})}; 56 | AnElementIntegrationPointWithDerivatives() : element_integration_point(baf_ders, 0.75, 1.75) {} 57 | 58 | protected: 59 | iga::elm::ElementIntegrationPoint<2> element_integration_point; 60 | }; 61 | 62 | TEST_F(AnElementIntegrationPointWithDerivatives, GetNonZeroBasisFunctionDerivatives) { //NOLINT 63 | ASSERT_THAT(element_integration_point.GetNonZeroBasisFunctionDerivatives(0)[0] , DoubleEq(2.3)); 64 | ASSERT_THAT(element_integration_point.GetNonZeroBasisFunctionDerivatives(0)[1] , DoubleEq(4.5)); 65 | ASSERT_THAT(element_integration_point.GetNonZeroBasisFunctionDerivatives(1)[0] , DoubleEq(3.2)); 66 | ASSERT_THAT(element_integration_point.GetNonZeroBasisFunctionDerivatives(1)[1] , DoubleEq(5.4)); 67 | } 68 | -------------------------------------------------------------------------------- /example/iga/test/element_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include 16 | #include "gmock/gmock.h" 17 | 18 | #include "element.h" 19 | 20 | using testing::Test; 21 | using testing::DoubleEq; 22 | 23 | class A1DElement : public Test { 24 | public: 25 | A1DElement() : element({ParamCoord(0.5), ParamCoord(1.0)}) {} 26 | 27 | protected: 28 | iga::elm::Element element; 29 | }; 30 | 31 | TEST_F(A1DElement, ReturnsCorrectNode) { // NOLINT 32 | ASSERT_THAT(element.GetLowerBound().get(), DoubleEq(0.5)); 33 | ASSERT_THAT(element.GetUpperBound().get(), DoubleEq(1.0)); 34 | } 35 | -------------------------------------------------------------------------------- /example/iga/test/integration_point_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "gmock/gmock.h" 16 | 17 | #include "integration_point.h" 18 | 19 | using testing::Test; 20 | using testing::DoubleEq; 21 | 22 | class AnIntegrationPoint : public Test { 23 | public: 24 | AnIntegrationPoint() : integration_point_(1.5, 0.5) {} 25 | 26 | protected: 27 | iga::itg::IntegrationPoint integration_point_; 28 | }; 29 | 30 | TEST_F(AnIntegrationPoint, ReturnsCorrectCoordinate) { // NOLINT 31 | ASSERT_THAT(integration_point_.GetCoordinate(), DoubleEq(1.5)); 32 | } 33 | 34 | TEST_F(AnIntegrationPoint, ReturnsCorrectWeight) { // NOLINT 35 | ASSERT_THAT(integration_point_.GetWeight(), DoubleEq(0.5)); 36 | } 37 | -------------------------------------------------------------------------------- /example/iga/test/integration_rule_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "gmock/gmock.h" 16 | 17 | #include "five_point_gauss_legendre.h" 18 | #include "four_point_gauss_legendre.h" 19 | #include "integration_rule.h" 20 | #include "numeric_settings.h" 21 | #include "one_point_gauss_legendre.h" 22 | #include "three_point_gauss_legendre.h" 23 | #include "two_point_gauss_legendre.h" 24 | 25 | using testing::Test; 26 | using testing::DoubleEq; 27 | using testing::DoubleNear; 28 | 29 | class AnIntegrationRule : public Test { 30 | public: 31 | AnIntegrationRule() { 32 | rules_.emplace_back(iga::itg::OnePointGaussLegendre()); 33 | rules_.emplace_back(iga::itg::TwoPointGaussLegendre()); 34 | rules_.emplace_back(iga::itg::ThreePointGaussLegendre()); 35 | rules_.emplace_back(iga::itg::FourPointGaussLegendre()); 36 | rules_.emplace_back(iga::itg::FivePointGaussLegendre()); 37 | } 38 | 39 | protected: 40 | std::vector rules_; 41 | }; 42 | 43 | TEST_F(AnIntegrationRule, ReturnsCorrectNumberOfPoints) { // NOLINT 44 | for (int points = 1; points <= 5; points++) { 45 | ASSERT_THAT(rules_[points - 1].GetNumberOfIntegrationPoints(), points); 46 | } 47 | } 48 | 49 | TEST_F(AnIntegrationRule, ReturnsCorrectWeightSum) { // NOLINT 50 | for (int points = 1; points <= 5; points++) { 51 | double weight_sum = 0; 52 | for (int weight = 0; weight < points; weight++) { 53 | weight_sum += rules_[points - 1].GetIntegrationPoints()[weight].GetWeight(); 54 | } 55 | ASSERT_THAT(weight_sum, DoubleEq(2)); 56 | } 57 | } 58 | 59 | TEST_F(AnIntegrationRule, ReturnsCorrectPointSum) { // NOLINT 60 | for (int points = 1; points <= 5; points++) { 61 | double point_sum = 0; 62 | for (int point = 0; point < points; point++) { 63 | point_sum += rules_[points - 1].GetIntegrationPoints()[point].GetCoordinate(); 64 | } 65 | ASSERT_THAT(point_sum, DoubleNear(0.0, util::NumericSettings::kEpsilon())); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /example/iga/test/linear_equation_assembler_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include 16 | 17 | #include "gmock/gmock.h" 18 | #include "matlab_test_data_2.h" 19 | #include "test_spline.h" 20 | 21 | using testing::DoubleNear; 22 | 23 | TEST_F(AnIGATestSpline, TestLeftSide) { // NOLINT 24 | linear_equation_assembler.GetLeftSide(rule, matA, elm_itg_calc); 25 | for (uint64_t i = 0; i < matlab_matrix_a.size(); ++i) { 26 | for (uint64_t j = 0; j < matlab_matrix_a[0].size(); ++j) { 27 | ASSERT_THAT((*matA)(i, j), DoubleNear(matlab_matrix_a[i][j], 0.00005)); 28 | } 29 | } 30 | } 31 | 32 | TEST_F(AnIGATestSpline, TestRightSide) { // NOLINT 33 | linear_equation_assembler.GetRightSide(rule, vecB, elm_itg_calc, srcCp); 34 | for (uint64_t i = 0; i < matlab_vector_b.size(); ++i) { 35 | ASSERT_THAT((*vecB)(i), DoubleNear(matlab_vector_b[i], 0.00005)); 36 | } 37 | } 38 | 39 | TEST_F(AnIGATestSpline, TestEquationSystemWithBC) { // NOLINT 40 | linear_equation_assembler.GetLeftSide(rule, matA, elm_itg_calc); 41 | linear_equation_assembler.GetRightSide(rule, vecB, elm_itg_calc, srcCp); 42 | linear_equation_assembler.SetZeroBC(matA, vecB); 43 | for (uint64_t i = 0; i < matlab_matrix_a_bc.size(); ++i) { 44 | for (uint64_t j = 0; j < matlab_matrix_a_bc[0].size(); ++j) { 45 | ASSERT_THAT((*matA)(i, j), DoubleNear(matlab_matrix_a_bc[i][j], 0.00005)); 46 | } 47 | } 48 | for (uint64_t i = 0; i < matlab_vector_b_bc.size(); ++i) { 49 | ASSERT_THAT((*vecB)(i), DoubleNear(matlab_vector_b_bc[i], 0.00005)); 50 | } 51 | } 52 | 53 | TEST_F(AnIGATestSpline, TestSolution) { // NOLINT 54 | iga::itg::IntegrationRule rule = iga::itg::TwoPointGaussLegendre(); 55 | linear_equation_assembler.GetLeftSide(rule, matA, elm_itg_calc); 56 | linear_equation_assembler.GetRightSide(rule, vecB, elm_itg_calc, srcCp); 57 | linear_equation_assembler.SetZeroBC(matA, vecB); 58 | arma::dvec solution = arma::solve(*matA, *vecB); 59 | for (uint64_t i = 0; i < matlab_solution.size(); ++i) { 60 | ASSERT_THAT(solution(i), DoubleNear(matlab_solution[i], 0.00005)); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /example/iga/test/mapping_handler_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "gmock/gmock.h" 16 | 17 | #include "mapping_handler.h" 18 | #include "test_spline.h" 19 | 20 | using testing::DoubleNear; 21 | 22 | TEST_F(AnIGATestSpline, TestMappingHandler) { // NOLINT 23 | iga::MappingHandler<2> mapping_handler(nurbs_); 24 | double j = mapping_handler.GetJacobianDeterminant(std::array({ParamCoord{0.367}, ParamCoord{0.893}})); 25 | ASSERT_THAT(j, DoubleNear(0.0905, 0.00005)); 26 | } 27 | -------------------------------------------------------------------------------- /example/log.txt: -------------------------------------------------------------------------------- 1 | input: 2 | ../../test/io/test_files/spline_tank.xml 3 | 4 | output: 5 | out.itd 6 | 7 | options: 8 | all -------------------------------------------------------------------------------- /example/testcase_optimizer.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "b_spline.h" 22 | #include "control_point.h" 23 | #include "knot_vector.h" 24 | #include "vtk_writer.h" 25 | 26 | void createVTKFromControlPoints(std::vector control_points, std::string fileName) { 27 | std::array degree = {Degree{2}}; 28 | std::array, 1> knot_vector_ptr = { 29 | std::make_shared(baf::KnotVector({ParamCoord{0}, ParamCoord{0}, ParamCoord{0}, 30 | ParamCoord{1}, ParamCoord{1}, ParamCoord{1}}))}; 31 | spl::BSpline<1> b_spline(knot_vector_ptr, degree, control_points); 32 | std::shared_ptr> b_spline_ptr = std::make_shared>(b_spline); 33 | 34 | std::any b_spline_any = std::make_any>>(b_spline_ptr); 35 | std::vector splines_ = {b_spline_any}; 36 | std::unique_ptr vtk_writer_; 37 | std::vector> scattering = {{100}}; 38 | vtk_writer_->WriteFile(splines_, fileName, scattering); 39 | } 40 | 41 | int main(int argc, char* argv[]) { 42 | if (argc != 3) { 43 | throw std::runtime_error("Exactly 10 coordinates of control points are required for the splinecreation"); 44 | } 45 | std::vector control_points; 46 | control_points.emplace_back(baf::ControlPoint({-1.0, 0.0})); 47 | double x, y; 48 | for (int i = 2; i < argc; i += 2) { 49 | x = atof(argv[i-1]); 50 | y = atof(argv[i]); 51 | std::cout << x << ", " << y << std::endl; 52 | control_points.emplace_back(baf::ControlPoint({x, y})); 53 | } 54 | control_points.emplace_back(baf::ControlPoint({1.0, 0.0})); 55 | std::string fileName = "optimized_Form.vtk"; 56 | createVTKFromControlPoints(control_points, fileName); 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /external/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | add_subdirectory(pugixml) 17 | -------------------------------------------------------------------------------- /external/pugixml/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | set(SOURCES 17 | pugixml.cpp) 18 | 19 | add_library(pugixmllib SHARED ${SOURCES}) 20 | target_include_directories(pugixmllib PUBLIC $) 21 | 22 | install( 23 | TARGETS pugixmllib 24 | EXPORT "${targets_export_name}" 25 | LIBRARY DESTINATION "${library_install_dir}" 26 | ARCHIVE DESTINATION "${library_install_dir}" 27 | RUNTIME DESTINATION "${executable_install_dir}" 28 | INCLUDES DESTINATION "${include_install_dir}" 29 | ) 30 | 31 | install(FILES 32 | pugiconfig.hpp 33 | pugixml.hpp 34 | DESTINATION "${include_install_dir}") 35 | -------------------------------------------------------------------------------- /external/pugixml/pugiconfig.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * pugixml parser - version 1.9 3 | * -------------------------------------------------------- 4 | * Copyright (C) 2006-2018, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) 5 | * Report bugs and download new versions at http://pugixml.org/ 6 | * 7 | * This library is distributed under the MIT License. See notice at the end 8 | * of this file. 9 | * 10 | * This work is based on the pugxml parser, which is: 11 | * Copyright (C) 2003, by Kristen Wegner (kristen@tima.net) 12 | */ 13 | 14 | #ifndef HEADER_PUGICONFIG_HPP 15 | #define HEADER_PUGICONFIG_HPP 16 | 17 | // Uncomment this to enable wchar_t mode 18 | // #define PUGIXML_WCHAR_MODE 19 | 20 | // Uncomment this to enable compact mode 21 | // #define PUGIXML_COMPACT 22 | 23 | // Uncomment this to disable XPath 24 | // #define PUGIXML_NO_XPATH 25 | 26 | // Uncomment this to disable STL 27 | // #define PUGIXML_NO_STL 28 | 29 | // Uncomment this to disable exceptions 30 | // #define PUGIXML_NO_EXCEPTIONS 31 | 32 | // Set this to control attributes for public classes/functions, i.e.: 33 | // #define PUGIXML_API __declspec(dllexport) // to export all public symbols from DLL 34 | // #define PUGIXML_CLASS __declspec(dllimport) // to import all classes from DLL 35 | // #define PUGIXML_FUNCTION __fastcall // to set calling conventions to all public functions to fastcall 36 | // In absence of PUGIXML_CLASS/PUGIXML_FUNCTION definitions PUGIXML_API is used instead 37 | 38 | // Tune these constants to adjust memory-related behavior 39 | // #define PUGIXML_MEMORY_PAGE_SIZE 32768 40 | // #define PUGIXML_MEMORY_OUTPUT_STACK 10240 41 | // #define PUGIXML_MEMORY_XPATH_PAGE_SIZE 4096 42 | 43 | // Uncomment this to switch to header-only version 44 | // #define PUGIXML_HEADER_ONLY 45 | 46 | // Uncomment this to enable long long support 47 | // #define PUGIXML_HAS_LONG_LONG 48 | 49 | #endif 50 | 51 | /** 52 | * Copyright (c) 2006-2018 Arseny Kapoulkine 53 | * 54 | * Permission is hereby granted, free of charge, to any person 55 | * obtaining a copy of this software and associated documentation 56 | * files (the "Software"), to deal in the Software without 57 | * restriction, including without limitation the rights to use, 58 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 59 | * copies of the Software, and to permit persons to whom the 60 | * Software is furnished to do so, subject to the following 61 | * conditions: 62 | * 63 | * The above copyright notice and this permission notice shall be 64 | * included in all copies or substantial portions of the Software. 65 | * 66 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 67 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 68 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 69 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 70 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 71 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 72 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 73 | * OTHER DEALINGS IN THE SOFTWARE. 74 | */ 75 | -------------------------------------------------------------------------------- /scripts/build/before_install_osx.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | brew cask uninstall oclint 4 | brew tap oclint/formulae 5 | brew install oclint gcc llvm 6 | echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile -------------------------------------------------------------------------------- /scripts/build/create_build_folders.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | 3 | # Check command line arguments 4 | if [ "$#" -ne 1 ]; then 5 | echo "Usage: $0 DIRECTORY" >&2 6 | exit 1 7 | fi 8 | if ! [ -e "$1" ]; then 9 | echo "$1 not found" >&2 10 | exit 1 11 | fi 12 | if ! [ -d "$1" ]; then 13 | echo "$1 not a directory" >&2 14 | exit 1 15 | fi 16 | 17 | # Get build prefix 18 | BUILD_PREFIX=$1 19 | 20 | # Create build folders 21 | mkdir $BUILD_PREFIX/cmake-build-debug-gcc 22 | mkdir $BUILD_PREFIX/cmake-build-release-gcc 23 | mkdir $BUILD_PREFIX/cmake-build-debug-clang 24 | mkdir $BUILD_PREFIX/cmake-build-release-clang 25 | -------------------------------------------------------------------------------- /scripts/build/install_spack.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if ! which spack >/dev/null; then 4 | mkdir -p $SPACK_ROOT 5 | git clone --depth 50 https://github.com/spack/spack.git $SPACK_ROOT 6 | echo -e "config:""\n build_jobs:"" 2" > $SPACK_ROOT/etc/spack/config.yaml; 7 | spack bootstrap 8 | CC=$CCOMPILER CXX=$CXXCOMPILER spack compiler find 9 | spack clean -a 10 | fi -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.acceptancetests: -------------------------------------------------------------------------------- 1 | FROM christophsusen/gtest 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | WORKDIR /code 6 | 7 | # Set-up shell 8 | SHELL ["bash", "-c"] 9 | ENV BASH_ENV /spack/bashrc 10 | 11 | RUN spack repo add /code/scripts/spack-repo 12 | RUN spack setup -v splinelib@github build_type=Release %gcc@8 13 | RUN mkdir /code/build-acceptance 14 | WORKDIR /code/build-acceptance 15 | RUN ./../spconfig.py .. 16 | 17 | # Install Splinelib 18 | CMD make && ./test/AcceptanceTests 19 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.armadillo: -------------------------------------------------------------------------------- 1 | FROM christophsusen/gtest 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | WORKDIR /code 6 | 7 | # Set-up shell 8 | SHELL ["bash", "-c"] 9 | ENV BASH_ENV /etc/profile.d/spack.sh 10 | 11 | RUN spack install -v openblas %gcc@7 12 | RUN spack install -v armadillo %gcc@7 13 | 14 | CMD /bin/bash -l 15 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.convert: -------------------------------------------------------------------------------- 1 | FROM christophsusen/gtest 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | WORKDIR /code 6 | 7 | # Set-up shell 8 | SHELL ["bash", "-c"] 9 | ENV BASH_ENV /etc/profile.d/spack.sh 10 | 11 | RUN spack repo add /code/scripts/spack-repo 12 | RUN spack setup -v splinelib@github build_type=Release %gcc@8 13 | RUN mkdir /code/build-convert 14 | WORKDIR /code/build-convert 15 | RUN ./../spconfig.py .. 16 | 17 | # Install Splinelib 18 | RUN make install 19 | 20 | RUN mkdir /code/example/build 21 | WORKDIR /code/example/build 22 | 23 | CMD spack load splinelib@github build_type=Release %gcc@8 && ./../../build-convert/src/io/executables/xml2irit --help && ./../../build-convert/src/io/executables/xml2irit ../log.txt 24 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.gtest: -------------------------------------------------------------------------------- 1 | # Build on top of spack 2 | FROM christophsusen/spack 3 | 4 | # Add code directory 5 | ADD . /spackrepo 6 | WORKDIR /spackrepo 7 | 8 | RUN apt-get update && apt-get install -y cmake 9 | RUN mv ./scripts/docker/packages.yaml /root/.spack/linux/packages.yaml 10 | 11 | # Install googletest versions 12 | RUN spack repo add /spackrepo/scripts/spack-repo 13 | RUN spack setup splinelib@github build_type=Debug %gcc@7 14 | RUN spack setup splinelib@github build_type=Release %gcc@7 15 | RUN spack setup splinelib@github build_type=Debug %clang@6 16 | RUN spack setup splinelib@github build_type=Release %clang@6 17 | RUN spack setup splinelib@github build_type=Debug %clang@5 18 | RUN spack setup splinelib@github build_type=Release %clang@5 19 | RUN spack setup splinelib@github build_type=Debug %gcc@8 20 | RUN spack setup splinelib@github build_type=Release %gcc@8 21 | RUN spack clean -a 22 | 23 | CMD /bin/bash 24 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.iga: -------------------------------------------------------------------------------- 1 | FROM christophsusen/armadillo 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | WORKDIR /code 6 | 7 | # Set-up shell 8 | SHELL ["bash", "-c"] 9 | ENV BASH_ENV /etc/profile.d/spack.sh 10 | 11 | # Install SplineLib 12 | RUN spack setup splinelib@github build_type=Release %gcc@8 arch=linux-ubuntu18.04-x86_64 13 | RUN mkdir /code/build 14 | WORKDIR /code/build 15 | RUN ./../spconfig.py .. 16 | RUN make install 17 | 18 | # Install CSiga 19 | RUN mkdir /code/example/iga/build 20 | WORKDIR /code/example/iga/build 21 | 22 | CMD spack load armadillo && spack load googletest@1.8.0 +gmock+pthreads~shared %gcc@8.2.0 && cmake .. && make && ./test/CSigaTests 23 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.install: -------------------------------------------------------------------------------- 1 | FROM christophsusen/gtest 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | WORKDIR /code 6 | 7 | # Set-up shell 8 | SHELL ["bash", "-c"] 9 | ENV BASH_ENV /etc/profile.d/spack.sh 10 | 11 | RUN spack repo add /code/scripts/spack-repo 12 | RUN spack setup -v splinelib@github build_type=Release %gcc@8 13 | RUN mkdir /code/build-install 14 | WORKDIR /code/build-install 15 | RUN ./../spconfig.py .. 16 | 17 | # Install Splinelib 18 | RUN make install 19 | 20 | RUN mkdir /code/example/build 21 | WORKDIR /code/example/build 22 | 23 | RUN spack load splinelib@github build_type=Release %gcc@8 && cmake ../ 24 | RUN make 25 | 26 | CMD spack load splinelib@github build_type=Release %gcc@8 && ./ex1 27 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.lint.clang-tidy: -------------------------------------------------------------------------------- 1 | FROM christophsusen/gtest 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | 6 | RUN mkdir -p /code/build-clang-tidy 7 | WORKDIR /code/build-clang-tidy 8 | 9 | # Set-up shell 10 | SHELL ["bash", "-c"] 11 | ENV BASH_ENV /etc/profile.d/spack.sh 12 | 13 | # Build and execute tests 14 | RUN spack load googletest+gmock~shared%gcc@7 && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ../ 15 | 16 | # execute clang-tidy 17 | CMD python ../scripts/run-clang-tidy.py /code/src/.* /code/test/.* | tee clang.log && grep -q -E "error:|warning:" clang.log && exit 1 || exit 0 18 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.lint.cpplint: -------------------------------------------------------------------------------- 1 | FROM christophsusen/spack 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | WORKDIR /code 6 | 7 | # execute cpplint 8 | CMD cpplint --extensions=cc,h --recursive /code/src/* /code/test/* 9 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.spack: -------------------------------------------------------------------------------- 1 | # Build on top of ubuntu 2 | FROM ubuntu:18.04 3 | 4 | ENV DEBIAN_FRONTEND=noninteractive \ 5 | SPACK_ROOT=/usr/local \ 6 | FORCE_UNSAFE_CONFIGURE=1 \ 7 | OCLINT_HOME=/spack/oclint-0.13.1 8 | 9 | RUN apt-get update \ 10 | && apt-get install -y --no-install-recommends \ 11 | autoconf \ 12 | ca-certificates \ 13 | curl \ 14 | environment-modules \ 15 | git \ 16 | build-essential \ 17 | python \ 18 | nano \ 19 | sudo \ 20 | unzip \ 21 | python-pip \ 22 | lcov \ 23 | gfortran-8 \ 24 | gcc-8 \ 25 | gfortran-7 \ 26 | gcc-7 \ 27 | llvm-5.0 \ 28 | llvm-6.0 \ 29 | clang-5.0 \ 30 | clang-6.0 \ 31 | libstdc++-6-dev \ 32 | libstdc++-7-dev \ 33 | libstdc++-8-dev \ 34 | clang-tidy \ 35 | cppcheck \ 36 | wget \ 37 | gfortran \ 38 | g++-8 \ 39 | valgrind \ 40 | && rm -rf /var/lib/apt/lists/* 41 | 42 | RUN curl -s -L https://api.github.com/repos/llnl/spack/tarball | tar xzC $SPACK_ROOT --strip 1 43 | RUN echo ". $SPACK_ROOT/share/spack/setup-env.sh" > /etc/profile.d/spack.sh 44 | RUN spack bootstrap 45 | RUN spack compiler find 46 | RUN sed -i -e 's/null/\/usr\/bin\/gfortran/g' ~/.spack/linux/compilers.yaml 47 | RUN spack compiler list 48 | RUN spack clean -a 49 | 50 | # startup 51 | CMD /bin/bash -l 52 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.test.clang5.debug: -------------------------------------------------------------------------------- 1 | FROM christophsusen/gtest 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | WORKDIR /code 6 | 7 | RUN spack repo add /code/scripts/spack-repo 8 | RUN spack setup -v splinelib@github build_type=Debug %clang@5 9 | RUN mkdir /code/build-clang5-debug 10 | WORKDIR /code/build-clang5-debug 11 | RUN ../spconfig.py .. 12 | 13 | # Build and execute tests 14 | CMD make && ./test/SplineLibTests 15 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.test.clang5.release: -------------------------------------------------------------------------------- 1 | FROM christophsusen/gtest 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | WORKDIR /code 6 | 7 | RUN spack repo add /code/scripts/spack-repo 8 | RUN spack setup -v splinelib@github build_type=Release %clang@5 9 | RUN mkdir /code/build-clang5-release 10 | WORKDIR /code/build-clang5-release 11 | RUN ../spconfig.py .. 12 | 13 | # Build and execute tests 14 | CMD make && ./test/SplineLibTests 15 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.test.clang6.debug: -------------------------------------------------------------------------------- 1 | FROM christophsusen/gtest 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | WORKDIR /code 6 | 7 | RUN spack repo add /code/scripts/spack-repo 8 | RUN spack setup -v splinelib@github build_type=Debug %clang@6 9 | RUN mkdir /code/build-clang6-debug 10 | WORKDIR /code/build-clang6-debug 11 | RUN ../spconfig.py .. 12 | 13 | # Build and execute tests 14 | CMD make && ./test/SplineLibTests 15 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.test.clang6.release: -------------------------------------------------------------------------------- 1 | FROM christophsusen/gtest 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | WORKDIR /code 6 | 7 | RUN spack repo add /code/scripts/spack-repo 8 | RUN spack setup -v splinelib@github build_type=Release %clang@6 9 | RUN mkdir /code/build-clang6-release 10 | WORKDIR /code/build-clang6-release 11 | RUN ../spconfig.py .. 12 | 13 | # Build and execute tests 14 | CMD make && ./test/SplineLibTests 15 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.test.coverage: -------------------------------------------------------------------------------- 1 | FROM christophsusen/gtest 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | WORKDIR /code 6 | 7 | ENV CXXFLAGS="-coverage" 8 | 9 | RUN spack repo add /code/scripts/spack-repo 10 | RUN spack setup -v splinelib@github build_type=Debug %gcc@7 11 | RUN mkdir /code/build-gcc7-coverage 12 | WORKDIR /code/build-gcc7-coverage 13 | RUN ../spconfig.py .. 14 | 15 | # Generate code coverage output 16 | RUN lcov --directory . --zerocounters && \ 17 | make SplineLibTests && \ 18 | ./test/SplineLibTests && \ 19 | lcov --directory . --capture --output-file coverage.info && \ 20 | lcov --remove coverage.info '/usr/*' --output-file coverage.info && \ 21 | lcov --remove coverage.info '*/.cache/*' --output-file coverage.info && \ 22 | lcov --remove coverage.info '*/CMakeFiles/*' --output-file coverage.info && \ 23 | lcov --remove coverage.info '*/external/*' --output-file coverage.info && \ 24 | lcov --remove coverage.info '*/io/executables/*' --output-file coverage.info && \ 25 | lcov --list coverage.info && \ 26 | find . -name "*.gcov" -type f -delete && \ 27 | find . -name "*.gcda" -type f -delete && \ 28 | find . -name "*.gcno" -type f -delete 29 | 30 | # Set-up shell 31 | SHELL ["bash", "-c"] 32 | 33 | CMD /bin/bash <(curl -s https://codecov.io/bash) 34 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.test.gcc7.debug: -------------------------------------------------------------------------------- 1 | FROM christophsusen/gtest 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | WORKDIR /code 6 | 7 | RUN spack repo add /code/scripts/spack-repo 8 | RUN spack setup -v splinelib@github build_type=Debug %gcc@7 9 | RUN mkdir /code/build-gcc7-debug 10 | WORKDIR /code/build-gcc7-debug 11 | RUN ../spconfig.py .. 12 | 13 | # Build and execute tests 14 | CMD make && ./test/SplineLibTests -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.test.gcc7.release: -------------------------------------------------------------------------------- 1 | FROM christophsusen/gtest 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | WORKDIR /code 6 | 7 | RUN spack repo add /code/scripts/spack-repo 8 | RUN spack setup -v splinelib@github build_type=Release %gcc@7 9 | RUN mkdir /code/build-gcc7-release 10 | WORKDIR /code/build-gcc7-release 11 | RUN ../spconfig.py .. 12 | 13 | # Build and execute tests 14 | CMD make && ./test/SplineLibTests 15 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.test.gcc8.debug: -------------------------------------------------------------------------------- 1 | FROM christophsusen/gtest 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | WORKDIR /code 6 | 7 | RUN spack repo add /code/scripts/spack-repo 8 | RUN spack setup -v splinelib@github build_type=Debug %gcc@8 9 | RUN mkdir /code/build-gcc8-debug 10 | WORKDIR /code/build-gcc8-debug 11 | RUN ../spconfig.py .. 12 | 13 | # Build and execute tests 14 | CMD make && ./test/SplineLibTests 15 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.test.gcc8.release: -------------------------------------------------------------------------------- 1 | FROM christophsusen/gtest 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | WORKDIR /code 6 | 7 | RUN spack repo add /code/scripts/spack-repo 8 | RUN spack setup -v splinelib@github build_type=Release %gcc@8 9 | RUN mkdir /code/build-gcc8-release 10 | WORKDIR /code/build-gcc8-release 11 | RUN ../spconfig.py .. 12 | 13 | # Build and execute tests 14 | CMD make && ./test/SplineLibTests 15 | -------------------------------------------------------------------------------- /scripts/docker/Dockerfile.test.gcc8.valgrind: -------------------------------------------------------------------------------- 1 | FROM christophsusen/gtest 2 | 3 | # Add current directory as working directory to docker 4 | ADD . /code 5 | WORKDIR /code 6 | 7 | RUN spack repo add /code/scripts/spack-repo 8 | RUN spack setup -v splinelib@github build_type=Debug %gcc@8 9 | RUN mkdir /code/build-gcc8-valgrind 10 | WORKDIR /code/build-gcc8-valgrind 11 | RUN ../spconfig.py .. 12 | 13 | # Build and execute tests 14 | CMD make && valgrind ./test/SplineLibTests 15 | -------------------------------------------------------------------------------- /scripts/docker/packages.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | cmake: 3 | paths: 4 | cmake@3.10.2 arch=linux-ubuntu18.04-x86_64: /usr/bin/cmake 5 | -------------------------------------------------------------------------------- /scripts/spack-repo/packages/splinelib/package.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright (c) 2013-2017, Lawrence Livermore National Security, LLC. 3 | # Produced at the Lawrence Livermore National Laboratory. 4 | # 5 | # This file is part of Spack. 6 | # Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. 7 | # LLNL-CODE-647188 8 | # 9 | # For details, see https://github.com/spack/spack 10 | # Please also see the NOTICE and LICENSE files for our notice and the LGPL. 11 | # 12 | # This program is free software; you can redistribute it and/or modify 13 | # it under the terms of the GNU Lesser General Public License (as 14 | # published by the Free Software Foundation) version 2.1, February 1999. 15 | # 16 | # This program is distributed in the hope that it will be useful, but 17 | # WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and 19 | # conditions of the GNU Lesser General Public License for more details. 20 | # 21 | # You should have received a copy of the GNU Lesser General Public 22 | # License along with this program; if not, write to the Free Software 23 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 | ############################################################################## 25 | 26 | from spack import * 27 | 28 | 29 | class Splinelib(CMakePackage): 30 | """Library for spline manipulation.""" 31 | 32 | homepage = "https://github.com/mfcats/SplineLib" 33 | url = "" 34 | 35 | version('github', git='https://github.com/mfcats/SplineLib.git', branch='master') 36 | 37 | depends_on("googletest+gmock~shared") 38 | 39 | def cmake_args(self): 40 | options = [] 41 | return options 42 | -------------------------------------------------------------------------------- /scripts/spack-repo/repo.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | repo: 17 | namespace: splinelib-software -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | add_subdirectory(util) 17 | add_subdirectory(baf) 18 | add_subdirectory(spl) 19 | add_subdirectory(io) 20 | -------------------------------------------------------------------------------- /src/baf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | set(SOURCES 17 | b_spline_basis_function.cc 18 | basis_function.cc 19 | basis_function_factory.cc 20 | control_point.cc 21 | knot_vector.cc 22 | zero_degree_b_spline_basis_function.cc) 23 | 24 | add_library(splinelibbaf SHARED ${SOURCES}) 25 | target_include_directories(splinelibbaf PUBLIC $) 26 | target_link_libraries(splinelibbaf splinelibutil) 27 | if (CMAKE_BUILD_TYPE STREQUAL "Debug") 28 | target_compile_options(splinelibbaf PUBLIC ${RUNTIME_CHECKS_DEBUG} ${WARNING_FLAGS}) 29 | elseif(CMAKE_BUILD_TYPE STREQUAL "Release") 30 | target_compile_options(splinelibbaf PUBLIC ${OPTIMIZATION_FLAGS} ${WARNING_FLAGS} ${PARALLELIZATION_FLAGS}) 31 | endif () 32 | 33 | install( 34 | TARGETS splinelibbaf 35 | EXPORT "${targets_export_name}" 36 | LIBRARY DESTINATION "${library_install_dir}" 37 | ARCHIVE DESTINATION "${library_install_dir}" 38 | RUNTIME DESTINATION "${executable_install_dir}" 39 | INCLUDES DESTINATION "${include_install_dir}" 40 | ) 41 | 42 | install(FILES 43 | b_spline_basis_function.h 44 | basis_function.h 45 | basis_function_factory.h 46 | control_point.h 47 | knot_vector.h 48 | zero_degree_b_spline_basis_function.h 49 | DESTINATION "${include_install_dir}") 50 | -------------------------------------------------------------------------------- /src/baf/b_spline_basis_function.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_BAF_B_SPLINE_BASIS_FUNCTION_H_ 16 | #define SRC_BAF_B_SPLINE_BASIS_FUNCTION_H_ 17 | 18 | #include 19 | 20 | #include "basis_function.h" 21 | 22 | namespace baf { 23 | class BSplineBasisFunction : public BasisFunction { 24 | public: 25 | BSplineBasisFunction(const KnotVector &knot_vector, const Degree °ree, const KnotSpan &start_of_support); 26 | 27 | protected: 28 | double EvaluateOnSupport(const ParamCoord ¶m_coord) const override; 29 | double EvaluateDerivativeOnSupport(const ParamCoord ¶m_coord, const Derivative &derivative) const override; 30 | 31 | private: 32 | void SetLowerDegreeBasisFunctions(const KnotVector &knot_vector, 33 | const Degree °ree, 34 | const KnotSpan &start_of_support); 35 | 36 | double ComputeLeftQuotient(const ParamCoord ¶m_coord) const; 37 | double ComputeRightQuotient(const ParamCoord ¶m_coord) const; 38 | 39 | double InverseWithPossiblyZeroDenominator(double denominator) const; 40 | 41 | double left_denom_inv_; 42 | double right_denom_inv_; 43 | std::unique_ptr left_lower_degree_; 44 | std::unique_ptr right_lower_degree_; 45 | }; 46 | } // namespace baf 47 | 48 | #endif // SRC_BAF_B_SPLINE_BASIS_FUNCTION_H_ 49 | -------------------------------------------------------------------------------- /src/baf/basis_function.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "basis_function.h" 16 | 17 | double baf::BasisFunction::Evaluate(const ParamCoord ¶mCoord) const { 18 | return IsCoordinateInSupport(paramCoord) ? this->EvaluateOnSupport(paramCoord) : 0.0; 19 | } 20 | 21 | double baf::BasisFunction::EvaluateDerivative(const ParamCoord ¶m_coord, const Derivative &derivative) const { 22 | return derivative.get() == 0 ? Evaluate(param_coord) : 23 | (IsCoordinateInSupport(param_coord) ? this->EvaluateDerivativeOnSupport(param_coord, derivative) : 0.0); 24 | } 25 | 26 | baf::BasisFunction::BasisFunction(const KnotVector &knot_vector, const Degree °ree, const KnotSpan &start_of_support) 27 | : degree_(degree) { 28 | auto start_index = static_cast(start_of_support.get()); 29 | auto degree_index = static_cast(degree.get()); 30 | start_knot_ = knot_vector.GetKnot(start_index); 31 | end_knot_ = knot_vector.GetKnot(start_index + degree_index + 1); 32 | end_knot_is_last_knot_ = knot_vector.IsLastKnot(end_knot_); 33 | } 34 | 35 | Degree baf::BasisFunction::GetDegree() const { 36 | return degree_; 37 | } 38 | 39 | ParamCoord baf::BasisFunction::GetStartKnot() const { 40 | return start_knot_; 41 | } 42 | 43 | ParamCoord baf::BasisFunction::GetEndKnot() const { 44 | return end_knot_; 45 | } 46 | 47 | bool baf::BasisFunction::IsCoordinateInSupport(const ParamCoord ¶m_coord) const { 48 | return (start_knot_ <= param_coord && param_coord < end_knot_) 49 | || (end_knot_is_last_knot_ && param_coord == end_knot_); 50 | } 51 | -------------------------------------------------------------------------------- /src/baf/basis_function.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_BAF_BASIS_FUNCTION_H_ 16 | #define SRC_BAF_BASIS_FUNCTION_H_ 17 | 18 | #include "knot_vector.h" 19 | #include "named_type.h" 20 | 21 | using Degree = util::NamedType; 22 | using Derivative = util::NamedType; 23 | 24 | namespace baf { 25 | class BasisFunction { 26 | public: 27 | virtual ~BasisFunction() = default; 28 | 29 | // The evaluation of the i-th basis function of degree p > 0 N_{i,p} is a linear combination of the basis functions 30 | // N_{i,p-1} and N_{i+1,p-1} (see NURBS book equation 2.5). Therefore, for each basis function of degree > 0 a pointer 31 | // to these two basis functions is set in constructor, so that a basis function can be evaluated recursively. 32 | double Evaluate(const ParamCoord ¶mCoord) const; 33 | 34 | double EvaluateDerivative(const ParamCoord ¶m_coord, const Derivative &derivative) const; 35 | 36 | protected: 37 | BasisFunction(const KnotVector &knot_vector, const Degree °ree, const KnotSpan &start_of_support); 38 | 39 | virtual double EvaluateOnSupport(const ParamCoord ¶m_coord) const = 0; 40 | virtual double EvaluateDerivativeOnSupport(const ParamCoord ¶m_coord, const Derivative &derivative) const = 0; 41 | 42 | Degree GetDegree() const; 43 | ParamCoord GetStartKnot() const; 44 | ParamCoord GetEndKnot() const; 45 | 46 | private: 47 | bool IsCoordinateInSupport(const ParamCoord ¶m_coord) const; 48 | 49 | Degree degree_; 50 | ParamCoord start_knot_{0}; 51 | ParamCoord end_knot_{1}; 52 | bool end_knot_is_last_knot_{false}; 53 | }; 54 | } // namespace baf 55 | 56 | #endif // SRC_BAF_BASIS_FUNCTION_H_ 57 | -------------------------------------------------------------------------------- /src/baf/basis_function_factory.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "basis_function_factory.h" 16 | 17 | #include 18 | 19 | #include "b_spline_basis_function.h" 20 | #include "zero_degree_b_spline_basis_function.h" 21 | 22 | baf::BasisFunction *baf::BasisFunctionFactory::CreateDynamic(const KnotVector &knot_vector, 23 | const KnotSpan &start_of_support, 24 | const Degree °ree) { 25 | if (degree < Degree{0}) { 26 | std::string msg; 27 | msg = "Basis function degree must be positive. Given degree is " + std::to_string(degree.get()); 28 | throw std::runtime_error(msg); 29 | } 30 | if (degree == Degree{0}) { 31 | return new baf::ZeroDegBSplBasFnc(knot_vector, start_of_support); 32 | } 33 | return new baf::BSplineBasisFunction(knot_vector, degree, start_of_support); 34 | } 35 | -------------------------------------------------------------------------------- /src/baf/basis_function_factory.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_BAF_BASIS_FUNCTION_FACTORY_H_ 16 | #define SRC_BAF_BASIS_FUNCTION_FACTORY_H_ 17 | 18 | #include "basis_function.h" 19 | 20 | namespace baf { 21 | class BasisFunctionFactory { 22 | public: 23 | static BasisFunction *CreateDynamic(const KnotVector &knot_vector, 24 | const KnotSpan &start_of_support, 25 | const Degree °ree); 26 | }; 27 | } // namespace baf 28 | 29 | #endif // SRC_BAF_BASIS_FUNCTION_FACTORY_H_ 30 | -------------------------------------------------------------------------------- /src/baf/control_point.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_BAF_CONTROL_POINT_H_ 16 | #define SRC_BAF_CONTROL_POINT_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace baf { 26 | class ControlPoint { 27 | public: 28 | explicit ControlPoint(std::initializer_list coordinates); 29 | explicit ControlPoint(std::vector coordinates); 30 | explicit ControlPoint(uint64_t dimension); 31 | 32 | int GetDimension() const; 33 | double GetValue(int dimension) const; 34 | 35 | void SetValue(int dimension, double value); 36 | 37 | ControlPoint operator+(const ControlPoint &control_point) const; 38 | ControlPoint operator-(const ControlPoint &control_point) const; 39 | ControlPoint operator*(const double &scalar) const; 40 | 41 | ControlPoint Transform(std::array, 4> TransMatrix, 42 | std::array scaling) const; 43 | double GetEuclideanNorm() const; 44 | 45 | protected: 46 | std::vector coordinates_; 47 | }; 48 | } // namespace baf 49 | 50 | #endif // SRC_BAF_CONTROL_POINT_H_ 51 | -------------------------------------------------------------------------------- /src/baf/knot_vector.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_BAF_KNOT_VECTOR_H_ 16 | #define SRC_BAF_KNOT_VECTOR_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "named_type.h" 23 | 24 | using ParamCoord = util::NamedType; 25 | using KnotSpan = util::NamedType; 26 | using Degree = util::NamedType; 27 | 28 | namespace baf { 29 | 30 | class KnotVector { 31 | public: 32 | using ConstKnotIterator = std::vector::const_iterator; 33 | using KnotIterator = std::vector::iterator; 34 | 35 | KnotVector() = default; 36 | KnotVector(const KnotVector &knotVector); 37 | KnotVector(KnotVector &&knotVector) noexcept; 38 | explicit KnotVector(std::vector knots); 39 | KnotVector(std::initializer_list knots) noexcept; 40 | KnotVector(ConstKnotIterator begin, ConstKnotIterator end); 41 | KnotVector(std::vector coords, Degree degree, int nbControlPoints); 42 | 43 | virtual ~KnotVector() = default; 44 | 45 | KnotVector operator-(const KnotVector &rhs) const; 46 | KnotVector &operator=(const KnotVector &other); 47 | KnotVector &operator=(KnotVector &&other) noexcept; 48 | // Check if absolute distance between all knots is smaller than the epsilon defined in 49 | // NumericSettings. 50 | bool operator==(const KnotVector &rhs) const; 51 | bool AreEqual(const KnotVector &rhs, double tolerance) const; 52 | ParamCoord &operator[](size_t index); 53 | 54 | virtual ParamCoord GetKnot(size_t index) const; 55 | ParamCoord GetLastKnot() const; 56 | virtual KnotSpan GetKnotSpan(ParamCoord param_coord) const; 57 | virtual size_t GetMultiplicity(ParamCoord param_coord) const; 58 | virtual size_t GetNumberOfKnots() const; 59 | int GetNumberOfDifferentKnots() const; 60 | 61 | ConstKnotIterator begin() const; 62 | ConstKnotIterator end() const; 63 | 64 | KnotIterator begin(); 65 | KnotIterator end(); 66 | 67 | virtual bool IsInKnotVectorRange(const ParamCoord ¶m_coord) const; 68 | virtual bool IsLastKnot(const ParamCoord ¶m_coord) const; 69 | 70 | void InsertKnot(const ParamCoord ¶m_coord); 71 | void RemoveKnot(const ParamCoord ¶m_coord); 72 | 73 | private: 74 | std::vector knots_; 75 | }; 76 | } // namespace baf 77 | 78 | #endif // SRC_BAF_KNOT_VECTOR_H_ 79 | -------------------------------------------------------------------------------- /src/baf/zero_degree_b_spline_basis_function.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "zero_degree_b_spline_basis_function.h" 16 | 17 | baf::ZeroDegBSplBasFnc::ZeroDegBSplBasFnc(const baf::KnotVector &knot_vector, const KnotSpan &start_of_support) : 18 | BasisFunction(knot_vector, Degree{0}, start_of_support) {} 19 | 20 | double baf::ZeroDegBSplBasFnc::EvaluateOnSupport(const ParamCoord /*param_coord*/&) const { 21 | return 1.0; 22 | } 23 | 24 | double baf::ZeroDegBSplBasFnc::EvaluateDerivativeOnSupport(const ParamCoord /*param_coord*/&, 25 | const Derivative /*degree*/&) const { 26 | return 0.0; 27 | } 28 | -------------------------------------------------------------------------------- /src/baf/zero_degree_b_spline_basis_function.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_BAF_ZERO_DEGREE_B_SPLINE_BASIS_FUNCTION_H_ 16 | #define SRC_BAF_ZERO_DEGREE_B_SPLINE_BASIS_FUNCTION_H_ 17 | 18 | #include "basis_function.h" 19 | #include "knot_vector.h" 20 | 21 | namespace baf { 22 | class ZeroDegBSplBasFnc : public baf::BasisFunction { 23 | public: 24 | ZeroDegBSplBasFnc(const baf::KnotVector &knot_vector, const KnotSpan &start_of_support); 25 | 26 | protected: 27 | double EvaluateOnSupport(const ParamCoord ¶m_coord) const override; 28 | double EvaluateDerivativeOnSupport(const ParamCoord ¶m_coord, const Derivative &derivative) const override; 29 | }; 30 | } // namespace baf 31 | 32 | #endif // SRC_BAF_ZERO_DEGREE_B_SPLINE_BASIS_FUNCTION_H_ 33 | -------------------------------------------------------------------------------- /src/io/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | add_subdirectory(executables) 17 | 18 | set(SOURCES 19 | iges_reader.cc 20 | iges_writer.cc 21 | io_converter.cc 22 | irit_reader.cc 23 | irit_writer.cc 24 | vtk_writer.cc 25 | xml_reader.cc 26 | xml_writer.cc) 27 | 28 | add_library(splinelibio SHARED ${SOURCES}) 29 | 30 | target_include_directories(splinelibio PUBLIC $) 31 | target_link_libraries(splinelibio splinelibspl pugixmllib) 32 | 33 | install( 34 | TARGETS splinelibio 35 | EXPORT "${targets_export_name}" 36 | LIBRARY DESTINATION "${library_install_dir}" 37 | ARCHIVE DESTINATION "${library_install_dir}" 38 | RUNTIME DESTINATION "${executable_install_dir}" 39 | INCLUDES DESTINATION "${include_install_dir}" 40 | ) 41 | 42 | install(FILES 43 | iges_reader.h 44 | iges_writer.h 45 | io_converter.h 46 | irit_reader.h 47 | irit_reader_utils.h 48 | irit_writer.h 49 | irit_writer_utils.h 50 | reader.h 51 | vtk_writer.h 52 | vtk_writer_utils.h 53 | writer.h 54 | xml_reader.h 55 | xml_reader_utils.h 56 | xml_writer.h 57 | xml_writer_utils.h 58 | writer.h 59 | DESTINATION "${include_install_dir}") 60 | -------------------------------------------------------------------------------- /src/io/executables/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | add_library(ioconversion INTERFACE) 17 | add_executable(iges2irit iges_to_irit.cc converter_log.cc) 18 | add_executable(iges2vtk iges_to_vtk.cc converter_log.cc) 19 | add_executable(iges2xml iges_to_xml.cc converter_log.cc) 20 | add_executable(irit2iges irit_to_iges.cc converter_log.cc) 21 | add_executable(irit2vtk irit_to_vtk.cc converter_log.cc) 22 | add_executable(irit2xml irit_to_xml.cc converter_log.cc) 23 | add_executable(xml2iges xml_to_iges.cc converter_log.cc) 24 | add_executable(xml2irit xml_to_irit.cc converter_log.cc) 25 | add_executable(xml2vtk xml_to_vtk.cc converter_log.cc) 26 | 27 | set_target_properties(iges2irit iges2vtk iges2xml irit2iges irit2vtk irit2xml xml2iges xml2irit xml2vtk PROPERTIES ENABLE_EXPORTS 1) 28 | 29 | target_link_libraries(iges2irit splinelibio) 30 | target_link_libraries(iges2vtk splinelibio) 31 | target_link_libraries(iges2xml splinelibio) 32 | target_link_libraries(irit2iges splinelibio) 33 | target_link_libraries(irit2vtk splinelibio) 34 | target_link_libraries(irit2xml splinelibio) 35 | target_link_libraries(xml2iges splinelibio) 36 | target_link_libraries(xml2irit splinelibio) 37 | target_link_libraries(xml2vtk splinelibio) 38 | target_link_libraries(ioconversion INTERFACE iges2irit iges2vtk iges2xml irit2iges irit2vtk irit2xml xml2iges xml2irit xml2vtk) 39 | 40 | install( 41 | TARGETS ioconversion iges2irit iges2vtk iges2xml irit2iges irit2vtk irit2xml xml2iges xml2irit xml2vtk 42 | EXPORT "${targets_export_name}" 43 | LIBRARY DESTINATION "${library_install_dir}" 44 | ARCHIVE DESTINATION "${library_install_dir}" 45 | RUNTIME DESTINATION "${executable_install_dir}" 46 | INCLUDES DESTINATION "${include_install_dir}" 47 | ) 48 | -------------------------------------------------------------------------------- /src/io/executables/converter_log.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | #ifndef SRC_IO_EXECUTABLES_CONVERTER_LOG_H_ 15 | #define SRC_IO_EXECUTABLES_CONVERTER_LOG_H_ 16 | 17 | #include 18 | #include 19 | 20 | namespace io { 21 | class ConverterLog { 22 | public: 23 | ConverterLog(); 24 | explicit ConverterLog(const char *log_file); 25 | 26 | const char *GetInput() const; 27 | const char *GetOutput() const; 28 | std::vector GetPositions(std::vector possible_positions); 29 | std::vector> GetScattering(); 30 | 31 | void WriteLog() const; 32 | void PrintHelp() const; 33 | 34 | private: 35 | std::string GetTime() const; 36 | bool OneSpline() const; 37 | 38 | const char *log_file_; 39 | std::string input_; 40 | std::string output_; 41 | std::vector positions_; 42 | std::vector written_; 43 | std::vector not_written_; 44 | std::vector> scattering_; 45 | }; 46 | } // namespace io 47 | 48 | #endif // SRC_IO_EXECUTABLES_CONVERTER_LOG_H_ 49 | -------------------------------------------------------------------------------- /src/io/executables/iges_to_irit.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "converter_log.h" 16 | #include "iges_reader.h" 17 | #include "io_converter.h" 18 | #include "irit_writer.h" 19 | #include "string_operations.h" 20 | #include "vector_utils.h" 21 | 22 | int main(int argc, char *argv[]) { 23 | if (argc != 2) { 24 | throw std::runtime_error("Exactly one name of the log file is required as command line argument."); 25 | } 26 | const char *log_file = argv[1]; // NOLINT 27 | if (util::StringOperations::StartsWith(log_file, "--help") || util::StringOperations::StartsWith(log_file, "-h")) { 28 | io::ConverterLog help; 29 | help.PrintHelp(); 30 | return 0; 31 | } 32 | io::ConverterLog log(log_file); 33 | std::vector splines; 34 | 35 | try { 36 | io::IGESReader iges_reader; 37 | splines = iges_reader.ReadFile(log.GetInput()); 38 | } catch (std::runtime_error &error) { 39 | throw error; 40 | } catch (...) { 41 | throw std::runtime_error(R"(The input file isn't of correct ".iges" format.)"); 42 | } 43 | 44 | io::IRITWriter irit_writer; 45 | std::vector positions = log.GetPositions(io::IOConverter::GetSplinePositionsOfCorrectDimension(splines, 3)); 46 | std::vector splines_with_max_dim = util::VectorUtils::FilterVector(splines, positions); 47 | irit_writer.WriteFile(splines_with_max_dim, log.GetOutput()); 48 | 49 | log.WriteLog(); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /src/io/executables/iges_to_vtk.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "converter_log.h" 16 | #include "iges_reader.h" 17 | #include "io_converter.h" 18 | #include "string_operations.h" 19 | #include "vector_utils.h" 20 | #include "vtk_writer.h" 21 | 22 | int main(int argc, char *argv[]) { 23 | if (argc != 2) { 24 | throw std::runtime_error("Exactly one name of the log file is required as command line argument."); 25 | } 26 | const char *log_file = argv[1]; // NOLINT 27 | if (util::StringOperations::StartsWith(log_file, "--help") || util::StringOperations::StartsWith(log_file, "-h")) { 28 | io::ConverterLog help; 29 | help.PrintHelp(); 30 | return 0; 31 | } 32 | io::ConverterLog log(log_file); 33 | std::vector splines; 34 | 35 | try { 36 | io::IGESReader iges_reader; 37 | splines = iges_reader.ReadFile(log.GetInput()); 38 | } catch (std::runtime_error &error) { 39 | throw error; 40 | } catch (...) { 41 | throw std::runtime_error(R"(The input file isn't of correct ".iges" format.)"); 42 | } 43 | 44 | io::VTKWriter vtk_writer; 45 | std::vector positions = log.GetPositions(io::IOConverter::GetSplinePositionsOfCorrectDimension(splines, 3)); 46 | std::vector> scattering = log.GetScattering(); 47 | std::vector splines_with_max_dim = util::VectorUtils::FilterVector(splines, positions); 48 | vtk_writer.WriteFile(splines_with_max_dim, log.GetOutput(), scattering); 49 | 50 | log.WriteLog(); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /src/io/executables/iges_to_xml.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "converter_log.h" 16 | #include "iges_reader.h" 17 | #include "io_converter.h" 18 | #include "string_operations.h" 19 | #include "vector_utils.h" 20 | #include "xml_writer.h" 21 | 22 | int main(int argc, char *argv[]) { 23 | if (argc != 2) { 24 | throw std::runtime_error("Exactly one name of the log file is required as command line argument."); 25 | } 26 | const char *log_file = argv[1]; // NOLINT 27 | if (util::StringOperations::StartsWith(log_file, "--help") || util::StringOperations::StartsWith(log_file, "-h")) { 28 | io::ConverterLog help; 29 | help.PrintHelp(); 30 | return 0; 31 | } 32 | io::ConverterLog log(log_file); 33 | std::vector splines; 34 | 35 | try { 36 | io::IGESReader iges_reader; 37 | splines = iges_reader.ReadFile(log.GetInput()); 38 | } catch (std::runtime_error &error) { 39 | throw error; 40 | } catch (...) { 41 | throw std::runtime_error(R"(The input file isn't of correct ".iges" format.)"); 42 | } 43 | 44 | io::XMLWriter xml_writer; 45 | std::vector positions = log.GetPositions(io::IOConverter::GetSplinePositionsOfCorrectDimension(splines, 4)); 46 | std::vector splines_with_max_dim = util::VectorUtils::FilterVector(splines, positions); 47 | xml_writer.WriteFile(splines_with_max_dim, log.GetOutput()); 48 | 49 | log.WriteLog(); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /src/io/executables/irit_to_iges.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "converter_log.h" 16 | #include "io_converter.h" 17 | #include "irit_reader.h" 18 | #include "string_operations.h" 19 | #include "iges_writer.h" 20 | 21 | int main(int argc, char *argv[]) { 22 | if (argc != 2) { 23 | throw std::runtime_error("Exactly one name of the log file is required as command line argument."); 24 | } 25 | const char *log_file = argv[1]; // NOLINT 26 | if (util::StringOperations::StartsWith(log_file, "--help") || util::StringOperations::StartsWith(log_file, "-h")) { 27 | io::ConverterLog help; 28 | help.PrintHelp(); 29 | return 0; 30 | } 31 | io::ConverterLog log(log_file); 32 | std::vector splines; 33 | 34 | try { 35 | io::IRITReader irit_reader; 36 | splines = irit_reader.ReadFile(log.GetInput()); 37 | } catch (std::runtime_error &error) { 38 | throw error; 39 | } catch (...) { 40 | throw std::runtime_error(R"(The input file isn't of correct ".itd" format.)"); 41 | } 42 | 43 | io::IGESWriter iges_writer; 44 | std::vector positions = log.GetPositions(io::IOConverter::GetSplinePositionsOfCorrectDimension(splines, 2)); 45 | std::vector splines_with_max_dim = util::VectorUtils::FilterVector(splines, positions); 46 | iges_writer.WriteFile(splines_with_max_dim, log.GetOutput()); 47 | 48 | log.WriteLog(); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /src/io/executables/irit_to_vtk.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "converter_log.h" 16 | #include "io_converter.h" 17 | #include "irit_reader.h" 18 | #include "string_operations.h" 19 | #include "vtk_writer.h" 20 | 21 | int main(int argc, char *argv[]) { 22 | if (argc != 2) { 23 | throw std::runtime_error("Exactly one name of the log file is required as command line argument."); 24 | } 25 | const char *log_file = argv[1]; // NOLINT 26 | if (util::StringOperations::StartsWith(log_file, "--help") || util::StringOperations::StartsWith(log_file, "-h")) { 27 | io::ConverterLog help; 28 | help.PrintHelp(); 29 | return 0; 30 | } 31 | io::ConverterLog log(log_file); 32 | std::vector splines; 33 | 34 | try { 35 | io::IRITReader irit_reader; 36 | splines = irit_reader.ReadFile(log.GetInput()); 37 | } catch (std::runtime_error &error) { 38 | throw error; 39 | } catch (...) { 40 | throw std::runtime_error(R"(The input file isn't of correct ".itd" format.)"); 41 | } 42 | 43 | io::VTKWriter vtk_writer; 44 | std::vector positions = log.GetPositions(io::IOConverter::GetSplinePositionsOfCorrectDimension(splines, 3)); 45 | std::vector> scattering = log.GetScattering(); 46 | std::vector splines_with_max_dim = util::VectorUtils::FilterVector(splines, positions); 47 | vtk_writer.WriteFile(splines_with_max_dim, log.GetOutput(), scattering); 48 | 49 | log.WriteLog(); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /src/io/executables/irit_to_xml.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "converter_log.h" 16 | #include "io_converter.h" 17 | #include "irit_reader.h" 18 | #include "string_operations.h" 19 | #include "xml_writer.h" 20 | 21 | int main(int argc, char *argv[]) { 22 | if (argc != 2) { 23 | throw std::runtime_error("Exactly one name of the log file is required as command line argument."); 24 | } 25 | const char *log_file = argv[1]; // NOLINT 26 | if (util::StringOperations::StartsWith(log_file, "--help") || util::StringOperations::StartsWith(log_file, "-h")) { 27 | io::ConverterLog help; 28 | help.PrintHelp(); 29 | return 0; 30 | } 31 | io::ConverterLog log(log_file); 32 | std::vector splines; 33 | 34 | try { 35 | io::IRITReader irit_reader; 36 | splines = irit_reader.ReadFile(log.GetInput()); 37 | } catch (std::runtime_error &error) { 38 | throw error; 39 | } catch (...) { 40 | throw std::runtime_error(R"(The input file isn't of correct ".itd" format.)"); 41 | } 42 | 43 | io::XMLWriter iges_writer; 44 | std::vector positions = log.GetPositions(io::IOConverter::GetSplinePositionsOfCorrectDimension(splines, 4)); 45 | std::vector splines_with_max_dim = util::VectorUtils::FilterVector(splines, positions); 46 | iges_writer.WriteFile(splines_with_max_dim, log.GetOutput()); 47 | 48 | log.WriteLog(); 49 | } 50 | -------------------------------------------------------------------------------- /src/io/executables/xml_to_iges.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "converter_log.h" 16 | #include "string_operations.h" 17 | #include "iges_writer.h" 18 | #include "io_converter.h" 19 | #include "xml_reader.h" 20 | 21 | int main(int argc, char *argv[]) { 22 | if (argc != 2) { 23 | throw std::runtime_error("Exactly one name of the log file is required as command line argument."); 24 | } 25 | const char *log_file = argv[1]; // NOLINT 26 | if (util::StringOperations::StartsWith(log_file, "--help") || util::StringOperations::StartsWith(log_file, "-h")) { 27 | io::ConverterLog help; 28 | help.PrintHelp(); 29 | return 0; 30 | } 31 | io::ConverterLog log(log_file); 32 | std::vector splines; 33 | 34 | try { 35 | io::XMLReader xml_reader; 36 | splines = xml_reader.ReadFile(log.GetInput()); 37 | } catch (std::runtime_error &error) { 38 | throw error; 39 | } catch (...) { 40 | throw std::runtime_error(R"(The input file isn't of correct ".xml" format.)"); 41 | } 42 | 43 | io::IGESWriter iges_writer; 44 | std::vector positions = log.GetPositions(io::IOConverter::GetSplinePositionsOfCorrectDimension(splines, 2)); 45 | std::vector splines_with_max_dim = util::VectorUtils::FilterVector(splines, positions); 46 | iges_writer.WriteFile(splines_with_max_dim, log.GetOutput()); 47 | 48 | log.WriteLog(); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /src/io/executables/xml_to_irit.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "converter_log.h" 16 | #include "io_converter.h" 17 | #include "irit_writer.h" 18 | #include "string_operations.h" 19 | #include "xml_reader.h" 20 | 21 | int main(int argc, char *argv[]) { 22 | if (argc != 2) { 23 | throw std::runtime_error("Exactly one name of the log file is required as command line argument."); 24 | } 25 | const char *log_file = argv[1]; // NOLINT 26 | if (util::StringOperations::StartsWith(log_file, "--help") || util::StringOperations::StartsWith(log_file, "-h")) { 27 | io::ConverterLog help; 28 | help.PrintHelp(); 29 | return 0; 30 | } 31 | io::ConverterLog log(log_file); 32 | std::vector splines; 33 | 34 | try { 35 | io::XMLReader xml_reader; 36 | splines = xml_reader.ReadFile(log.GetInput()); 37 | } catch (std::runtime_error &error) { 38 | throw error; 39 | } catch (...) { 40 | throw std::runtime_error(R"(The input file isn't of correct ".xml" format.)"); 41 | } 42 | 43 | io::IRITWriter irit_writer; 44 | std::vector positions = log.GetPositions(io::IOConverter::GetSplinePositionsOfCorrectDimension(splines, 3)); 45 | std::vector splines_with_max_dim = util::VectorUtils::FilterVector(splines, positions); 46 | irit_writer.WriteFile(splines_with_max_dim, log.GetOutput()); 47 | 48 | log.WriteLog(); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /src/io/executables/xml_to_vtk.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "converter_log.h" 16 | #include "io_converter.h" 17 | #include "string_operations.h" 18 | #include "xml_reader.h" 19 | #include "vtk_writer.h" 20 | 21 | int main(int argc, char *argv[]) { 22 | if (argc != 2) { 23 | throw std::runtime_error("Exactly one name of the log file is required as command line argument."); 24 | } 25 | const char *log_file = argv[1]; // NOLINT 26 | if (util::StringOperations::StartsWith(log_file, "--help") || util::StringOperations::StartsWith(log_file, "-h")) { 27 | io::ConverterLog help; 28 | help.PrintHelp(); 29 | return 0; 30 | } 31 | io::ConverterLog log(log_file); 32 | std::vector splines; 33 | 34 | try { 35 | io::XMLReader xml_reader; 36 | splines = xml_reader.ReadFile(log.GetInput()); 37 | } catch (std::runtime_error &error) { 38 | throw error; 39 | } catch (...) { 40 | throw std::runtime_error(R"(The input file isn't of correct ".xml" format.)"); 41 | } 42 | 43 | io::VTKWriter vtk_writer; 44 | std::vector positions = log.GetPositions(io::IOConverter::GetSplinePositionsOfCorrectDimension(splines, 3)); 45 | std::vector> scattering = log.GetScattering(); 46 | std::vector splines_with_max_dim = util::VectorUtils::FilterVector(splines, positions); 47 | vtk_writer.WriteFile(splines_with_max_dim, log.GetOutput(), scattering); 48 | 49 | log.WriteLog(); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /src/io/iges_reader.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IO_IGES_READER_H_ 16 | #define SRC_IO_IGES_READER_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "reader.h" 24 | 25 | namespace io { 26 | class IGESReader : public Reader { 27 | public: 28 | IGESReader() = default; 29 | 30 | std::vector ReadFile(const char *filename) override; 31 | 32 | private: 33 | std::any Create1DSpline(const std::vector ¶meterData); 34 | std::any Create2DSpline(const std::vector ¶meterData); 35 | 36 | std::array GetParameterSectionStartEndPointers(std::vector directoryEntrySection, 37 | int entityToBeRead); 38 | 39 | std::vector ParameterSectionToVector(std::vector parameterSection, 40 | std::array ParameterSectionStartEndPointers); 41 | 42 | static inline std::string trim(std::string s); 43 | }; 44 | } // namespace io 45 | 46 | #endif // SRC_IO_IGES_READER_H_ 47 | -------------------------------------------------------------------------------- /src/io/io_converter.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IO_IO_CONVERTER_H_ 16 | #define SRC_IO_IO_CONVERTER_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "any_casts.h" 23 | #include "iges_reader.h" 24 | #include "iges_writer.h" 25 | #include "irit_reader.h" 26 | #include "irit_writer.h" 27 | #include "string_operations.h" 28 | #include "vtk_writer.h" 29 | #include "xml_reader.h" 30 | #include "xml_writer.h" 31 | 32 | namespace io { 33 | class IOConverter { 34 | public: 35 | IOConverter(const char *input_filename, const char *output_filename); 36 | 37 | std::vector ConvertFile(const std::vector &positions = {}, 38 | const std::vector> &scattering = {}); 39 | 40 | static std::vector GetSplinePositionsOfCorrectDimension(const std::vector &splines, int max_dim); 41 | 42 | enum file_format { error, iges, irit, vtk, xml }; 43 | 44 | private: 45 | file_format GetFileFormat(const char *filename) const; 46 | 47 | io::Reader *GetReader() const; 48 | void GetWriter(const std::vector &splines, const std::vector &positions, 49 | const std::vector> &scattering); 50 | void WriteFile(const std::vector &splines, const std::vector &positions, int max_dim, 51 | const std::shared_ptr &writer); 52 | 53 | void GetPositions(const std::vector &positions, const std::vector &possible_positions); 54 | std::vector> GetScattering(const std::vector> &scattering, 55 | const std::vector &positions, 56 | const std::vector &written); 57 | 58 | const char *input_filename_; 59 | const char *output_filename_; 60 | file_format input_format_; 61 | file_format output_format_; 62 | std::vector written_; 63 | }; 64 | } // namespace io 65 | 66 | #endif // SRC_IO_IO_CONVERTER_H_ 67 | -------------------------------------------------------------------------------- /src/io/irit_reader.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IO_IRIT_READER_H_ 16 | #define SRC_IO_IRIT_READER_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "b_spline.h" 23 | #include "reader.h" 24 | 25 | namespace io { 26 | class IRITReader : public Reader { 27 | public: 28 | IRITReader() = default; 29 | 30 | std::vector ReadFile(const char *filename) override; 31 | 32 | private: 33 | std::vector GetSplinePositions(const std::vector &entries) const; 34 | 35 | static int GetDimension(const std::string &type); 36 | 37 | std::any Get1DSpline(int start, const std::vector &entries) const; 38 | std::any Get2DSpline(int start, const std::vector &entries) const; 39 | std::any Get3DSpline(int start, const std::vector &entries) const; 40 | 41 | static int GetNumberOfControlPoints(int start, const std::vector &entries); 42 | 43 | std::vector GetControlPoints(int start, const std::vector &entries, 44 | bool rational, std::vector weights) const; 45 | 46 | std::vector GetWeights(int start, const std::vector &entries, bool rational) const; 47 | 48 | int GetPositionOfFirstControlPoint(int start, const std::vector &entries) const; 49 | }; 50 | } // namespace io 51 | 52 | #endif // SRC_IO_IRIT_READER_H_ 53 | -------------------------------------------------------------------------------- /src/io/irit_reader_utils.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IO_IRIT_READER_UTILS_H_ 16 | #define SRC_IO_IRIT_READER_UTILS_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "b_spline.h" 22 | #include "nurbs.h" 23 | #include "string_operations.h" 24 | 25 | namespace io { 26 | class IRITReaderUtils { 27 | public: 28 | template 29 | static std::array GetDegrees(int start, const std::vector &entries) { 30 | std::array degrees; 31 | for (int i = 0; i < DIM; i++) { 32 | degrees[i] = 33 | Degree(util::StringOperations::StringVectorToNumberVector({entries[start + DIM + 2 + i]})[0] - 1); 34 | } 35 | return degrees; 36 | } 37 | 38 | template 39 | static KnotVectors GetKnotVectors(int start, const std::vector &entries) { 40 | KnotVectors knot_vectors; 41 | for (int i = 0; i < DIM; i++) { 42 | while (!util::StringOperations::StartsWith(entries[start++], "[KV")) {} 43 | std::vector knots; 44 | while (!util::StringOperations::StartsWith(entries[start], "[")) { 45 | knots.emplace_back(util::StringOperations::StringToDouble(util::StringOperations::trim(entries[start++]))); 46 | } 47 | knot_vectors[i] = std::make_shared(knots); 48 | } 49 | return knot_vectors; 50 | } 51 | 52 | template 53 | static bool IsRational(int start_of_spline, const std::vector &entries) { 54 | return util::StringOperations::StartsWith(entries[start_of_spline + 2 * DIM + 2], "P"); 55 | } 56 | }; 57 | } // namespace io 58 | 59 | #endif // SRC_IO_IRIT_READER_UTILS_H_ 60 | -------------------------------------------------------------------------------- /src/io/irit_writer.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IO_IRIT_WRITER_H_ 16 | #define SRC_IO_IRIT_WRITER_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "writer.h" 24 | 25 | namespace io { 26 | class IRITWriter : public Writer { 27 | public: 28 | IRITWriter() = default; 29 | 30 | void WriteFile(const std::vector &splines, const char *filename) const override; 31 | 32 | private: 33 | void AddSpline(std::ofstream &file, const std::any &spline, int spline_number) const; 34 | 35 | void Write1DSpline(std::ofstream &file, const std::any &spline) const; 36 | void Write2DSpline(std::ofstream &file, const std::any &spline) const; 37 | void Write3DSpline(std::ofstream &file, const std::any &spline) const; 38 | 39 | std::string GetPointType(bool rational, int space_dimension) const; 40 | }; 41 | } // namespace io 42 | 43 | #endif // SRC_IO_IRIT_WRITER_H_ 44 | -------------------------------------------------------------------------------- /src/io/reader.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IO_READER_H_ 16 | #define SRC_IO_READER_H_ 17 | 18 | #include 19 | #include 20 | 21 | namespace io { 22 | class Reader { 23 | public: 24 | Reader() = default; 25 | virtual ~Reader() = default; 26 | 27 | virtual std::vector ReadFile(const char *filename) = 0; 28 | }; 29 | } // namespace io 30 | 31 | #endif // SRC_IO_READER_H_ 32 | -------------------------------------------------------------------------------- /src/io/vtk_writer.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IO_VTK_WRITER_H_ 16 | #define SRC_IO_VTK_WRITER_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace io { 25 | class VTKWriter { 26 | public: 27 | VTKWriter() = default; 28 | 29 | void WriteFile(const std::vector &splines, 30 | const std::string &filename, 31 | const std::vector> &scattering) const; 32 | 33 | private: 34 | std::vector GetSplineDimensions(const std::vector &splines) const; 35 | 36 | void ThrowIfScatteringHasWrongSizes(std::vector> scattering, std::vector dimensions) const; 37 | 38 | std::vector GetNumberOfAllPoints(const std::vector &dimensions, 39 | const std::vector> &scattering) const; 40 | std::vector GetNumberOfAllCells(const std::vector &dimensions, 41 | const std::vector> &scattering) const; 42 | int GetNumberOfCellEntries(const std::vector &dimensions, const std::vector &cells) const; 43 | 44 | void AddPoints(std::ofstream &file, const std::any &spline, const std::vector &scattering, int spl_dim) const; 45 | void AddCells(std::ofstream &file, const std::vector &scattering, int offset, int spl_dim) const; 46 | void AddCellTypes(std::ofstream &file, const std::vector &scattering, int spl_dim) const; 47 | 48 | void Write1DCells(std::ofstream &file, int scattering, int offset) const; 49 | void Write2DCells(std::ofstream &file, std::array scattering, int offset) const; 50 | void Write3DCells(std::ofstream &file, std::array scattering, int offset) const; 51 | }; 52 | } // namespace io 53 | 54 | #endif // SRC_IO_VTK_WRITER_H_ 55 | -------------------------------------------------------------------------------- /src/io/vtk_writer_utils.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IO_VTK_WRITER_UTILS_H_ 16 | #define SRC_IO_VTK_WRITER_UTILS_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "any_casts.h" 22 | #include "spline.h" 23 | 24 | namespace io { 25 | template 26 | class VTKWriterUtils { 27 | public: 28 | static std::array GetEdgeKnots(std::shared_ptr> spline_ptr) { 29 | std::array knots{}; 30 | for (int i = 0; i < 2 * DIM; ++i) { 31 | knots[i] = i < DIM ? spline_ptr->GetKnotVector(i)->GetKnot(0).get() 32 | : spline_ptr->GetKnotVector(i - DIM)->GetLastKnot().get(); 33 | } 34 | return knots; 35 | } 36 | 37 | static int NumberOfCells(std::array scattering) { 38 | int product = 1; 39 | for (int i = 0; i < DIM; ++i) { 40 | product *= scattering[i]; 41 | } 42 | return product; 43 | } 44 | 45 | static std::array GetPointHandlerLength(std::array scattering) { 46 | for (int i = 0; i < DIM; ++i) { 47 | ++scattering[i]; 48 | } 49 | return scattering; 50 | } 51 | 52 | static void WritePoints(std::ofstream &file, const std::any &spline, std::array scattering) { 53 | std::shared_ptr> spline_ptr = util::AnyCasts::GetSpline(spline); 54 | std::array knots = GetEdgeKnots(spline_ptr); 55 | util::MultiIndexHandler point_handler(GetPointHandlerLength(scattering)); 56 | for (int i = 0; i < point_handler.Get1DLength(); ++point_handler, ++i) { 57 | std::array coords{}; 58 | for (int j = 0; j < DIM; ++j) { 59 | coords[j] = ParamCoord(knots[j] + point_handler[j] * (knots[j + DIM] - knots[j]) / scattering[j]); 60 | } 61 | for (int k = 0; k < 3; ++k) { 62 | file << (k < spline_ptr->GetPointDim() ? spline_ptr->Evaluate(coords, {k})[0] : 0) << (k < 2 ? " " : "\n"); 63 | } 64 | } 65 | } 66 | 67 | static void WriteCellTypes(std::ofstream &file, std::array scattering, int cell_type) { 68 | for (int i = 0; i < NumberOfCells(scattering); ++i) { 69 | file << cell_type << "\n"; 70 | } 71 | } 72 | }; 73 | } // namespace io 74 | 75 | #endif // SRC_IO_VTK_WRITER_UTILS_H_ 76 | -------------------------------------------------------------------------------- /src/io/writer.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IO_WRITER_H_ 16 | #define SRC_IO_WRITER_H_ 17 | 18 | #include 19 | #include 20 | 21 | namespace io { 22 | class Writer { 23 | public: 24 | Writer() = default; 25 | virtual ~Writer() = default; 26 | 27 | virtual void WriteFile(const std::vector &splines, const char *filename) const = 0; 28 | }; 29 | } // namespace io 30 | 31 | #endif // SRC_IO_WRITER_H_ 32 | -------------------------------------------------------------------------------- /src/io/xml_reader.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IO_XML_READER_H_ 16 | #define SRC_IO_XML_READER_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "pugixml.hpp" 23 | 24 | #include "b_spline.h" 25 | #include "nurbs.h" 26 | #include "reader.h" 27 | 28 | namespace io { 29 | class XMLReader : public Reader { 30 | public: 31 | XMLReader() = default; 32 | 33 | std::vector ReadFile(const char *filename) override; 34 | 35 | private: 36 | void AddSpline(pugi::xml_node *spline, std::vector *splines); 37 | 38 | std::any Get1DSpline(pugi::xml_node *spline, const std::vector &control_points); 39 | std::any Get2DSpline(pugi::xml_node *spline, const std::vector &control_points); 40 | std::any Get3DSpline(pugi::xml_node *spline, const std::vector &control_points); 41 | std::any Get4DSpline(pugi::xml_node *spline, const std::vector &control_points); 42 | 43 | std::vector GetControlPoints(pugi::xml_node *spline); 44 | 45 | std::vector GetWeights(pugi::xml_node *spline); 46 | 47 | int FindCoordinatePosition(const std::string &string); 48 | }; 49 | } // namespace io 50 | 51 | #endif // SRC_IO_XML_READER_H_ 52 | -------------------------------------------------------------------------------- /src/io/xml_reader_utils.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IO_XML_READER_UTILS_H_ 16 | #define SRC_IO_XML_READER_UTILS_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "pugixml.hpp" 22 | 23 | #include "b_spline.h" 24 | #include "nurbs.h" 25 | #include "string_operations.h" 26 | 27 | namespace io { 28 | template 29 | class XMLReaderUtils { 30 | public: 31 | static std::array GetDegrees(pugi::xml_node *spline) { 32 | return StringVectorToDegreeArray(util::StringOperations::split(spline->child("deg").first_child().value(), ' ')); 33 | } 34 | 35 | static KnotVectors GetKnotVectors(pugi::xml_node *spline) { 36 | KnotVectors knot_vector; 37 | for (int i = 0; i < DIM; i++) { 38 | knot_vector[i] = std::make_shared(baf::KnotVector({ParamCoord(0.5)})); 39 | } 40 | for (int i = 0; i < DIM; i++) { 41 | pugi::xml_node child = spline->child("kntVecs").first_child(); 42 | for (int j = 0; j < i; j++) { 43 | child = child.next_sibling(); 44 | } 45 | knot_vector[i] = std::make_shared( 46 | baf::KnotVector(util::StringOperations::StringVectorToNumberVector( 47 | util::StringOperations::split(child.first_child().value(), ' ')))); 48 | } 49 | return knot_vector; 50 | } 51 | 52 | static std::array StringVectorToDegreeArray(const std::vector &string_vector) { 53 | std::array converted; 54 | for (int i = 0; i < DIM; i++) { 55 | auto a = string_vector[i]; 56 | converted[i] = Degree{std::stoi(string_vector[i])}; 57 | } 58 | return converted; 59 | } 60 | }; 61 | } // namespace io 62 | 63 | #endif // SRC_IO_XML_READER_UTILS_H_ 64 | -------------------------------------------------------------------------------- /src/io/xml_writer.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_IO_XML_WRITER_H_ 16 | #define SRC_IO_XML_WRITER_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "pugixml.hpp" 22 | 23 | #include "writer.h" 24 | 25 | namespace io { 26 | class XMLWriter : public Writer { 27 | public: 28 | XMLWriter() = default; 29 | 30 | void WriteFile(const std::vector &splines, const char *filename) const override; 31 | 32 | private: 33 | void AddSpline(pugi::xml_node *spline_list, const std::any &spline) const; 34 | 35 | void Add1DSpline(pugi::xml_node *spline_list, const std::any &spline) const; 36 | void Add2DSpline(pugi::xml_node *spline_list, const std::any &spline) const; 37 | void Add3DSpline(pugi::xml_node *spline_list, const std::any &spline) const; 38 | void Add4DSpline(pugi::xml_node *spline_list, const std::any &spline) const; 39 | 40 | void AddSplineAttributes(pugi::xml_node *spline_node, 41 | int spline_dimension, 42 | int space_dimension, 43 | int control_points) const; 44 | 45 | void AddControlPointVarNames(pugi::xml_node *spline_node, int space_dimension) const; 46 | }; 47 | } // namespace io 48 | 49 | #endif // SRC_IO_XML_WRITER_H_ 50 | -------------------------------------------------------------------------------- /src/spl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | set(SOURCES 17 | square_generator.cc 18 | surface_generator.cc) 19 | 20 | add_library(splinelibspl SHARED ${SOURCES}) 21 | target_include_directories(splinelibspl PUBLIC $) 22 | target_link_libraries(splinelibspl splinelibbaf) 23 | 24 | install( 25 | TARGETS splinelibspl 26 | EXPORT "${targets_export_name}" 27 | LIBRARY DESTINATION "${library_install_dir}" 28 | ARCHIVE DESTINATION "${library_install_dir}" 29 | RUNTIME DESTINATION "${executable_install_dir}" 30 | INCLUDES DESTINATION "${include_install_dir}" 31 | ) 32 | 33 | install(FILES 34 | alias.h 35 | b_spline.h 36 | b_spline_generator.h 37 | nurbs.h 38 | nurbs_generator.h 39 | parameter_space.h 40 | physical_space.h 41 | projection.h 42 | random_b_spline_generator.h 43 | random_nurbs_generator.h 44 | random_spline_utils.h 45 | spline.h 46 | spline_generator.h 47 | square_generator.h 48 | surface_generator.h 49 | weighted_physical_space.h 50 | DESTINATION "${include_install_dir}") 51 | -------------------------------------------------------------------------------- /src/spl/alias.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_SPL_ALIAS_H_ 16 | #define SRC_SPL_ALIAS_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "knot_vector.h" 22 | 23 | template 24 | using KnotVectors = std::array, DIM>; 25 | 26 | #endif // SRC_SPL_ALIAS_H_ 27 | -------------------------------------------------------------------------------- /src/spl/b_spline_generator.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_SPL_B_SPLINE_GENERATOR_H_ 16 | #define SRC_SPL_B_SPLINE_GENERATOR_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "physical_space.h" 22 | #include "spline_generator.h" 23 | 24 | namespace spl { 25 | template 26 | class BSplineGenerator : public SplineGenerator { 27 | public: 28 | BSplineGenerator() = default; 29 | virtual ~BSplineGenerator() = default; 30 | 31 | BSplineGenerator(KnotVectors knot_vector, std::array degree, 32 | const std::vector &control_points) : SplineGenerator(knot_vector, degree) { 33 | std::array number_of_points; 34 | for (int i = 0; i < DIM; ++i) { 35 | number_of_points[i] = knot_vector[i]->GetNumberOfKnots() - degree[i].get() - 1; 36 | } 37 | physical_space_ = std::make_shared>(control_points, number_of_points); 38 | } 39 | 40 | BSplineGenerator(std::shared_ptr> physical_space, 41 | std::shared_ptr> parameter_space) { 42 | this->parameter_space_ = parameter_space; 43 | physical_space_ = physical_space; 44 | } 45 | 46 | std::shared_ptr> GetPhysicalSpace() const { 47 | return physical_space_; 48 | } 49 | 50 | protected: 51 | std::shared_ptr> physical_space_; 52 | }; 53 | } // namespace spl 54 | 55 | #endif // SRC_SPL_B_SPLINE_GENERATOR_H_ 56 | -------------------------------------------------------------------------------- /src/spl/nurbs_generator.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_SPL_NURBS_GENERATOR_H_ 16 | #define SRC_SPL_NURBS_GENERATOR_H_ 17 | 18 | #include 19 | 20 | #include "spline_generator.h" 21 | #include "weighted_physical_space.h" 22 | 23 | namespace spl { 24 | template 25 | class NURBSGenerator : public SplineGenerator { 26 | public: 27 | NURBSGenerator() = default; 28 | virtual ~NURBSGenerator() = default; 29 | 30 | NURBSGenerator(KnotVectors knot_vector, std::array degree, 31 | const std::vector &control_points, std::vector weights) { 32 | std::array number_of_points; 33 | for (int i = 0; i < DIM; ++i) { 34 | number_of_points[i] = knot_vector[i]->GetNumberOfKnots() - degree[i].get() - 1; 35 | } 36 | 37 | this->physical_space_ = std::make_shared>(control_points, weights, number_of_points); 38 | this->parameter_space_ = std::make_shared>(knot_vector, degree); 39 | } 40 | 41 | NURBSGenerator(std::shared_ptr> weighted_physical_space, 42 | std::shared_ptr> parameter_space) { 43 | this->physical_space_ = weighted_physical_space; 44 | this->parameter_space_ = parameter_space; 45 | } 46 | 47 | std::shared_ptr> GetWeightedPhysicalSpace() { 48 | return physical_space_; 49 | } 50 | 51 | protected: 52 | std::shared_ptr> physical_space_; 53 | }; 54 | } // namespace spl 55 | 56 | #endif // SRC_SPL_NURBS_GENERATOR_H_ 57 | -------------------------------------------------------------------------------- /src/spl/random_b_spline_generator.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_SPL_RANDOM_B_SPLINE_GENERATOR_H_ 16 | #define SRC_SPL_RANDOM_B_SPLINE_GENERATOR_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "b_spline_generator.h" 22 | #include "random_spline_utils.h" 23 | 24 | namespace spl { 25 | template 26 | class RandomBSplineGenerator : public BSplineGenerator { 27 | public: 28 | RandomBSplineGenerator() = default; 29 | virtual ~RandomBSplineGenerator() = default; 30 | 31 | RandomBSplineGenerator(std::array coord_limits, int max_degree, int dimension) { 32 | std::array degrees = RandomSplineUtils::GetRandomDegrees(max_degree); 33 | KnotVectors knot_vectors = RandomSplineUtils::GetRandomKnotVectors(coord_limits, degrees); 34 | std::array number_of_points = RandomSplineUtils::GetNumberOfPoints(degrees, knot_vectors); 35 | std::vector 36 | control_points = RandomSplineUtils::GetRandomControlPoints(dimension, number_of_points); 37 | this->physical_space_ = std::make_shared>(control_points, number_of_points); 38 | this->parameter_space_ = std::make_shared>(knot_vectors, degrees); 39 | } 40 | }; 41 | } // namespace spl 42 | 43 | #endif // SRC_SPL_RANDOM_B_SPLINE_GENERATOR_H_ 44 | -------------------------------------------------------------------------------- /src/spl/random_nurbs_generator.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_SPL_RANDOM_NURBS_GENERATOR_H_ 16 | #define SRC_SPL_RANDOM_NURBS_GENERATOR_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "nurbs_generator.h" 22 | #include "random_spline_utils.h" 23 | 24 | namespace spl { 25 | template 26 | class RandomNURBSGenerator : public NURBSGenerator { 27 | public: 28 | RandomNURBSGenerator() = default; 29 | virtual ~RandomNURBSGenerator() = default; 30 | 31 | RandomNURBSGenerator(std::array coord_limits, int max_degree, int dimension) { 32 | std::array degrees = RandomSplineUtils::GetRandomDegrees(max_degree); 33 | KnotVectors knot_vectors = RandomSplineUtils::GetRandomKnotVectors(coord_limits, degrees); 34 | std::array number_of_points = RandomSplineUtils::GetNumberOfPoints(degrees, knot_vectors); 35 | std::vector 36 | control_points = RandomSplineUtils::GetRandomControlPoints(dimension, number_of_points); 37 | std::vector weights = RandomSplineUtils::GetRandomWeights(number_of_points); 38 | this->physical_space_ = std::make_shared>(control_points, weights, number_of_points); 39 | this->parameter_space_ = std::make_shared>(knot_vectors, degrees); 40 | } 41 | }; 42 | } // namespace spl 43 | 44 | #endif // SRC_SPL_RANDOM_NURBS_GENERATOR_H_ 45 | -------------------------------------------------------------------------------- /src/spl/spline_generator.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_SPL_SPLINE_GENERATOR_H_ 16 | #define SRC_SPL_SPLINE_GENERATOR_H_ 17 | 18 | #include "parameter_space.h" 19 | #include "physical_space.h" 20 | #include "weighted_physical_space.h" 21 | 22 | namespace spl { 23 | template 24 | class SplineGenerator { 25 | public: 26 | SplineGenerator() = default; 27 | virtual ~SplineGenerator() = default; 28 | 29 | SplineGenerator(KnotVectors knot_vector, std::array degree) { 30 | parameter_space_ = std::make_shared>(ParameterSpace(knot_vector, degree)); 31 | } 32 | 33 | std::shared_ptr> GetParameterSpace() { 34 | return parameter_space_; 35 | } 36 | 37 | protected: 38 | std::shared_ptr> parameter_space_; 39 | }; 40 | } // namespace spl 41 | 42 | #endif // SRC_SPL_SPLINE_GENERATOR_H_ 43 | -------------------------------------------------------------------------------- /src/spl/square_generator.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | This file is part of SplineLib. 3 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 4 | License as published by the Free Software Foundation version 3 of the License. 5 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 6 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 7 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 8 | . 9 | */ 10 | 11 | #include "square_generator.h" 12 | 13 | spl::SquareGenerator::SquareGenerator() : degree_(Degree{2}), number_of_knots_(6) {} 14 | 15 | spl::SquareGenerator::SquareGenerator(Degree degree, u_int64_t number_of_knots) : degree_(degree), 16 | number_of_knots_(number_of_knots) {} 17 | 18 | 19 | std::unique_ptr> spl::SquareGenerator::CreateSquare() const { 20 | auto parameter_space = std::make_shared>(GenerateParameterSpace()); 21 | auto physical_space = std::make_shared>(GeneratePhysicalSpace()); 22 | spl::BSplineGenerator<2> spline_generator(physical_space, parameter_space); 23 | return std::make_unique>(spline_generator); 24 | } 25 | 26 | spl::ParameterSpace<2> spl::SquareGenerator::GenerateParameterSpace() const { 27 | std::vector knots(number_of_knots_, zero_); 28 | for (auto knot = knots.begin() + degree_.get() + 1; knot != knots.end() - degree_.get() - 1; ++knot) { 29 | *knot = *(knot - 1) + ParamCoord{1.0/(number_of_knots_ - 2.0 * degree_.get() - 1)}; 30 | } 31 | std::fill(knots.end() - degree_.get() - 1, knots.end(), one_); 32 | std::array, 2> knot_vectors = { 33 | std::make_shared(knots), 34 | std::make_shared(knots) 35 | }; 36 | return spl::ParameterSpace<2>(knot_vectors, {degree_, degree_}); 37 | } 38 | 39 | spl::PhysicalSpace<2> spl::SquareGenerator::GeneratePhysicalSpace() const { 40 | u_int64_t num_cps = number_of_knots_ - degree_.get() - 1; 41 | double delta = 2.0/(num_cps - 1.0); 42 | std::vector coordinates(num_cps, - 1.0); 43 | double val = -1.0; 44 | for (auto &coordinate : coordinates) { 45 | coordinate = val; 46 | val += delta; 47 | } 48 | std::vector cps(num_cps * num_cps, baf::ControlPoint({0.0, 0.0})); 49 | size_t cp_it = 0; 50 | for (u_int64_t y_it = 0; y_it < num_cps; ++y_it) { 51 | for (u_int64_t x_it = 0; x_it < num_cps; ++x_it) { 52 | cps[cp_it++] = baf::ControlPoint(std::vector({coordinates[x_it], coordinates[y_it]})); 53 | } 54 | } 55 | return spl::PhysicalSpace<2>(cps, {static_cast(num_cps), static_cast(num_cps)}); 56 | } 57 | -------------------------------------------------------------------------------- /src/spl/square_generator.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | This file is part of SplineLib. 3 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 4 | License as published by the Free Software Foundation version 3 of the License. 5 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 6 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 7 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 8 | . 9 | */ 10 | 11 | #ifndef SRC_SPL_SQUARE_GENERATOR_H_ 12 | #define SRC_SPL_SQUARE_GENERATOR_H_ 13 | 14 | #include 15 | #include 16 | 17 | #include "b_spline.h" 18 | #include "knot_vector.h" 19 | 20 | namespace spl { 21 | class SquareGenerator { 22 | public: 23 | SquareGenerator(); 24 | SquareGenerator(Degree degree, u_int64_t number_of_knots); 25 | 26 | std::unique_ptr> CreateSquare() const; 27 | 28 | private: 29 | spl::ParameterSpace<2> GenerateParameterSpace() const; 30 | 31 | spl::PhysicalSpace<2> GeneratePhysicalSpace() const; 32 | 33 | Degree degree_; 34 | u_int64_t number_of_knots_; 35 | ParamCoord one_{1}; 36 | ParamCoord zero_{0}; 37 | }; 38 | } // namespace spl 39 | 40 | #endif // SRC_SPL_SQUARE_GENERATOR_H_ 41 | -------------------------------------------------------------------------------- /src/spl/surface_generator.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_SPL_SURFACE_GENERATOR_H_ 16 | #define SRC_SPL_SURFACE_GENERATOR_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "nurbs_generator.h" 22 | #include "nurbs.h" 23 | 24 | namespace spl { 25 | class SurfaceGenerator : public NURBSGenerator<2> { 26 | public: 27 | SurfaceGenerator(std::shared_ptr> const &nurbs_T, std::shared_ptr> const &nurbs_C); 28 | 29 | SurfaceGenerator(std::shared_ptr> const &nurbs_T, 30 | std::shared_ptr> const &nurbs_C, 31 | int nbInter, std::vector> scaling); 32 | 33 | std::shared_ptr> JoinParameterSpaces(std::shared_ptr> const &nurbs_T, 34 | std::shared_ptr> const &nurbs_C) const; 35 | 36 | std::shared_ptr> JoinPhysicalSpaces(std::shared_ptr> const &nurbs_T, 37 | std::shared_ptr> const &nurbs_C) const; 38 | 39 | std::array CrossProduct(std::vector a, std::vector b) const; 40 | 41 | std::array CrossProduct(std::array a, std::array b) const; 42 | 43 | double DotProduct(std::array a, std::array b) const; 44 | 45 | double DotProduct(std::array a, std::vector b) const; 46 | 47 | double ComputeNorm(std::vector a); 48 | 49 | double ComputeNorm(std::array a); 50 | 51 | std::array ComputeNormal(std::vector T, std::vector dT, 52 | std::vector ddT, std::array previous, int index); 53 | 54 | std::array, 4> GetTransformation(std::vector t, 55 | std::vector dT, 56 | std::vector ddT, 57 | std::array prev_z, 58 | int index); 59 | }; 60 | } // namespace spl 61 | 62 | #endif // SRC_SPL_SURFACE_GENERATOR_H_ 63 | -------------------------------------------------------------------------------- /src/util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | add_library(splinelibutil INTERFACE) 17 | target_include_directories(splinelibutil INTERFACE 18 | $) 19 | 20 | install( 21 | TARGETS splinelibutil 22 | EXPORT "${targets_export_name}" 23 | LIBRARY DESTINATION "${library_install_dir}" 24 | ARCHIVE DESTINATION "${library_install_dir}" 25 | RUNTIME DESTINATION "${executable_install_dir}" 26 | INCLUDES DESTINATION "${include_install_dir}" 27 | ) 28 | 29 | install(FILES 30 | any_casts.h 31 | element.h 32 | element_generator.h 33 | named_type.h 34 | numeric_operations.h 35 | numeric_settings.h 36 | multi_index_handler.h 37 | random.h 38 | string_operations.h 39 | system_operations.h 40 | vector_utils.h 41 | DESTINATION "${include_install_dir}") 42 | -------------------------------------------------------------------------------- /src/util/any_casts.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_UTIL_ANY_CASTS_H_ 16 | #define SRC_UTIL_ANY_CASTS_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "b_spline.h" 22 | #include "nurbs.h" 23 | 24 | namespace util { 25 | class AnyCasts { 26 | public: 27 | template 28 | static std::shared_ptr> GetSpline(std::any spline) { 29 | try { 30 | return std::any_cast>>(spline); 31 | } catch (std::bad_any_cast &msg) { 32 | try { 33 | return std::any_cast>>(spline); 34 | } catch (std::bad_any_cast &msg) { 35 | throw std::runtime_error("Input has to be a shared pointer to a b-spline or nurbs of declared dimension"); 36 | } 37 | } 38 | } 39 | 40 | static int GetSplineDimension(const std::any &spline) { 41 | try { 42 | GetSpline<1>(spline); 43 | return 1; 44 | } catch (std::runtime_error &e) { 45 | try { 46 | GetSpline<2>(spline); 47 | return 2; 48 | } catch (std::runtime_error &e) { 49 | try { 50 | GetSpline<3>(spline); 51 | return 3; 52 | } catch (std::runtime_error &e) { 53 | try { 54 | GetSpline<4>(spline); 55 | return 4; 56 | } catch (std::runtime_error &e) { 57 | throw std::runtime_error( 58 | "Input has to be a shared pointer to a b-spline or nurbs of dimension 1, 2, 3 or 4."); 59 | } 60 | } 61 | } 62 | } 63 | } 64 | 65 | template 66 | static bool IsRational(std::any spline) { 67 | try { 68 | std::any_cast>>(spline); 69 | return true; 70 | } catch (std::bad_any_cast &msg) { 71 | try { 72 | std::any_cast>>(spline); 73 | return false; 74 | } catch (std::bad_any_cast &msg) { 75 | throw std::runtime_error("Input has to be a shared pointer to a b-spline or nurbs of declared dimension"); 76 | } 77 | } 78 | } 79 | }; 80 | } // namespace util 81 | 82 | #endif // SRC_UTIL_ANY_CASTS_H_ 83 | -------------------------------------------------------------------------------- /src/util/element.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_UTIL_ELEMENT_H_ 16 | #define SRC_UTIL_ELEMENT_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "control_point.h" 22 | #include "knot_vector.h" 23 | 24 | namespace util { 25 | class Element { 26 | public: 27 | explicit Element(const std::array &nodes) : nodes_(nodes) {} 28 | 29 | ParamCoord GetLowerBound() const { 30 | return nodes_[0]; 31 | } 32 | 33 | ParamCoord GetUpperBound() const { 34 | return nodes_[1]; 35 | } 36 | 37 | private: 38 | std::array nodes_; 39 | }; 40 | } // namespace util 41 | 42 | #endif // SRC_UTIL_ELEMENT_H_ 43 | -------------------------------------------------------------------------------- /src/util/element_generator.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_UTIL_ELEMENT_GENERATOR_H_ 16 | #define SRC_UTIL_ELEMENT_GENERATOR_H_ 17 | 18 | #include 19 | 20 | #include "element.h" 21 | #include "multi_index_handler.h" 22 | #include "spline.h" 23 | 24 | namespace util { 25 | template 26 | class ElementGenerator { 27 | public: 28 | explicit ElementGenerator(std::shared_ptr> spl) : spl_(std::move(spl)) { 29 | for (int i = 0; i < DIM; ++i) { 30 | for (uint64_t j = 0; j < spl_->GetKnotVector(i)->GetNumberOfKnots() - spl_->GetDegree(i).get() - 1; ++j) { 31 | if ((spl_->GetKnotVector(i)->GetKnot(j).get() - spl_->GetKnotVector(i)->GetKnot(j + 1).get()) != 0) { 32 | elements_[i].emplace_back(Element({spl_->GetKnotVector(i)->GetKnot(j), 33 | spl_->GetKnotVector(i)->GetKnot(j + 1)})); 34 | } 35 | } 36 | } 37 | } 38 | 39 | std::vector GetElementList(int dir) const { 40 | return elements_[dir]; 41 | } 42 | 43 | private: 44 | std::shared_ptr> spl_; 45 | std::array, DIM> elements_; 46 | }; 47 | } // namespace util 48 | 49 | #endif // SRC_UTIL_ELEMENT_GENERATOR_H_ 50 | -------------------------------------------------------------------------------- /src/util/named_type.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_UTIL_NAMED_TYPE_H_ 16 | #define SRC_UTIL_NAMED_TYPE_H_ 17 | 18 | namespace util { 19 | template 20 | class NamedType { 21 | public: 22 | NamedType() = default; 23 | 24 | explicit NamedType(T const &value) : value_(value) {} 25 | explicit NamedType(T &&value) noexcept : value_(std::move(value)) {} 26 | 27 | constexpr T &get() { return value_; } 28 | constexpr T const &get() const { return value_; } 29 | 30 | constexpr NamedType operator+(const NamedType &rhs) const { 31 | return NamedType{value_ + rhs.get()}; 32 | } 33 | 34 | constexpr NamedType operator-(const NamedType &rhs) const { 35 | return NamedType{value_ - rhs.get()}; 36 | } 37 | 38 | constexpr NamedType operator*(const NamedType &rhs) const { 39 | return NamedType{value_ * rhs.get()}; 40 | } 41 | 42 | constexpr bool operator==(const NamedType &rhs) const { 43 | return value_ == rhs.get(); 44 | } 45 | 46 | constexpr bool operator>(const NamedType &rhs) const { 47 | return value_ > rhs.get(); 48 | } 49 | 50 | constexpr bool operator<(const NamedType &rhs) const { 51 | return value_ < rhs.get(); 52 | } 53 | 54 | constexpr bool operator>=(const NamedType &rhs) const { 55 | return value_ >= rhs.get(); 56 | } 57 | 58 | constexpr bool operator<=(const NamedType &rhs) const { 59 | return value_ <= rhs.get(); 60 | } 61 | 62 | private: 63 | T value_; 64 | }; 65 | } // namespace util 66 | 67 | #endif // SRC_UTIL_NAMED_TYPE_H_ 68 | -------------------------------------------------------------------------------- /src/util/numeric_operations.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_UTIL_NUMERIC_OPERATIONS_H_ 16 | #define SRC_UTIL_NUMERIC_OPERATIONS_H_ 17 | 18 | namespace util { 19 | template 20 | class NumericOperations { 21 | public: 22 | static T increment(T value) { 23 | return ++value; 24 | } 25 | 26 | static T decrement(T value) { 27 | return --value; 28 | } 29 | }; 30 | } // namespace util 31 | 32 | #endif // SRC_UTIL_NUMERIC_OPERATIONS_H_ 33 | -------------------------------------------------------------------------------- /src/util/numeric_settings.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_UTIL_NUMERIC_SETTINGS_H_ 16 | #define SRC_UTIL_NUMERIC_SETTINGS_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "named_type.h" 22 | 23 | namespace util { 24 | template 25 | class NumericSettings { 26 | public: 27 | constexpr static T kEpsilon() { 28 | return kEpsilonFactor_ * std::numeric_limits::epsilon(); 29 | } 30 | 31 | constexpr static bool AreEqual(const T &a, const T &b, T tolerance = kEpsilon()) { 32 | return std::abs(a - b) < tolerance; 33 | } 34 | 35 | NumericSettings(const NumericSettings &numericSettings) = delete; 36 | 37 | void operator=(const NumericSettings &numericSettings) = delete; 38 | 39 | private: 40 | NumericSettings() = default; 41 | 42 | constexpr static double kEpsilonFactor_ = 10.0; 43 | }; 44 | } // namespace util 45 | 46 | #endif // SRC_UTIL_NUMERIC_SETTINGS_H_ 47 | -------------------------------------------------------------------------------- /src/util/random.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_UTIL_RANDOM_H_ 16 | #define SRC_UTIL_RANDOM_H_ 17 | 18 | #include 19 | 20 | namespace util { 21 | class Random { 22 | public: 23 | template 24 | static T GetBinomialRandom(double min, double max, double distance) { 25 | static std::default_random_engine generator; 26 | std::binomial_distribution distribution(static_cast((max - min) / distance), 0.5); 27 | return distribution(generator) * distance + min; 28 | } 29 | 30 | template 31 | static T GetUniformRandom(double min, double max) { 32 | static std::default_random_engine generator; 33 | std::uniform_real_distribution distribution(min, max); 34 | return distribution(generator); 35 | } 36 | }; 37 | } // namespace util 38 | 39 | #endif // SRC_UTIL_RANDOM_H_ 40 | -------------------------------------------------------------------------------- /src/util/system_operations.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_UTIL_SYSTEM_OPERATIONS_H_ 16 | #define SRC_UTIL_SYSTEM_OPERATIONS_H_ 17 | 18 | #include 19 | 20 | namespace util { 21 | class SystemOperations { 22 | public: 23 | static struct tm GetTime() { 24 | struct tm timeinfo{}; 25 | time_t rawtime; 26 | rawtime = time(&rawtime); 27 | localtime_r(&rawtime, &timeinfo); 28 | return timeinfo; 29 | } 30 | }; 31 | } // namespace util 32 | 33 | #endif // SRC_UTIL_SYSTEM_OPERATIONS_H_ 34 | -------------------------------------------------------------------------------- /src/util/vector_utils.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef SRC_UTIL_VECTOR_UTILS_H_ 16 | #define SRC_UTIL_VECTOR_UTILS_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace util { 25 | template 26 | class VectorUtils { 27 | public: 28 | static double ComputeTwoNorm(std::vector vectorA) { 29 | std::transform(vectorA.begin(), vectorA.end(), vectorA.begin(), vectorA.begin(), std::multiplies()); 30 | double sum = 0; 31 | for (T i : vectorA) { 32 | sum += i; 33 | } 34 | return sqrt(sum); 35 | } 36 | 37 | static std::vector ComputeDifference(std::vector vectorA, std::vector vectorB) { 38 | std::transform(vectorA.begin(), vectorA.end(), vectorB.begin(), vectorB.begin(), std::minus()); 39 | return vectorB; 40 | } 41 | 42 | static double ComputeDistance(std::vector vectorA, std::vector vectorB) { 43 | return util::VectorUtils::ComputeTwoNorm(util::VectorUtils::ComputeDifference(vectorA, vectorB)); 44 | } 45 | 46 | static T ComputeScalarProduct(std::vector vectorA, std::vector vectorB) { 47 | std::transform(vectorA.begin(), vectorA.end(), vectorB.begin(), vectorB.begin(), std::multiplies()); 48 | T sum = 0; 49 | for (T i : vectorB) { 50 | sum += i; 51 | } 52 | return sum; 53 | } 54 | 55 | static std::vector ScaleVector(std::vector vectorA, T factor) { 56 | std::transform(vectorA.begin(), vectorA.end(), vectorA.begin(), 57 | std::bind(std::multiplies(), factor, std::placeholders::_1)); 58 | return vectorA; 59 | } 60 | 61 | static std::vector CrossProduct(std::vector const &a, std::vector const &b) { 62 | std::vector r(a.size()); 63 | r[0] = a[1] * b[2] - a[2] * b[1]; 64 | r[1] = a[2] * b[0] - a[0] * b[2]; 65 | r[2] = a[0] * b[1] - a[1] * b[0]; 66 | return r; 67 | } 68 | 69 | static std::vector FilterVector(const std::vector &input, const std::vector &positions) { 70 | std::vector output; 71 | for (const auto &pos : positions) { 72 | if (pos < static_cast(input.size())) { 73 | output.emplace_back(input[pos]); 74 | } else { 75 | throw std::runtime_error("The vector index is too high to be filtered from the input vector."); 76 | } 77 | } 78 | return output; 79 | } 80 | }; 81 | } // namespace util 82 | 83 | #endif // SRC_UTIL_VECTOR_UTILS_H_ 84 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | add_subdirectory(baf) 17 | add_subdirectory(io) 18 | add_subdirectory(spl) 19 | add_subdirectory(util) 20 | 21 | find_package(GMock REQUIRED) 22 | #include_directories(${GTEST_INCLUDE_DIRS}) 23 | 24 | add_executable(SplineLibTests ${TEST_SOURCES}) 25 | target_link_libraries(SplineLibTests splinelibbaf splinelibspl splinelibutil splinelibio ioconversion GMock::Main) 26 | 27 | add_executable(MaxTest ${MAX_SOURCES}) 28 | target_link_libraries(MaxTest splinelibbaf splinelibspl splinelibutil splinelibio GMock::Main) 29 | 30 | set(ACCEPTANCE_TEST_SOURCES 31 | acceptance_tests.cc) 32 | add_executable(AcceptanceTests ${ACCEPTANCE_TEST_SOURCES}) 33 | target_link_libraries(AcceptanceTests splinelibbaf splinelibspl splinelibutil) 34 | 35 | target_compile_definitions(SplineLibTests PRIVATE GTEST_HAS_PTHREAD=0) 36 | target_compile_definitions(MaxTest PRIVATE GTEST_HAS_PTHREAD=0) 37 | 38 | configure_file(io/config_iges.in.h ${CMAKE_CURRENT_BINARY_DIR}/config_iges.h) 39 | configure_file(io/config_irit.in.h ${CMAKE_CURRENT_BINARY_DIR}/config_irit.h) 40 | configure_file(io/config_xml.in.h ${CMAKE_CURRENT_BINARY_DIR}/config_xml.h) 41 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) 42 | -------------------------------------------------------------------------------- /test/acceptance_tests.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "b_spline.h" 21 | 22 | std::unique_ptr> GenerateSpline() { 23 | std::array degree = {Degree{2}}; 24 | std::vector control_points = { 25 | baf::ControlPoint(std::vector({0.0, 0.0})), 26 | baf::ControlPoint(std::vector({0.0, 1.0})), 27 | baf::ControlPoint(std::vector({1.0, 1.0})), 28 | baf::ControlPoint(std::vector({1.5, 1.5})), 29 | baf::ControlPoint(std::vector({2.0, 1.3})), 30 | baf::ControlPoint(std::vector({3.0, 2.0})), 31 | baf::ControlPoint(std::vector({4.0, 1.5})), 32 | baf::ControlPoint(std::vector({4.0, 0.0})) 33 | }; 34 | KnotVectors<1> knot_vector_ptr = { 35 | std::make_shared(baf::KnotVector({ParamCoord{0}, ParamCoord{0}, ParamCoord{0}, ParamCoord{1}, 36 | ParamCoord{2}, ParamCoord{3}, 37 | ParamCoord{4}, ParamCoord{4}, ParamCoord{5}, ParamCoord{5}, 38 | ParamCoord{5}}))}; 39 | return std::make_unique>(knot_vector_ptr, degree, control_points); 40 | } 41 | 42 | int main() { 43 | auto b_spline = GenerateSpline(); 44 | 45 | int repetitions = 20000000; 46 | std::chrono::system_clock::time_point before = std::chrono::system_clock::now(); 47 | for (int i = 0; i < repetitions; i++) { 48 | b_spline->Evaluate({ParamCoord{i * 5.0 / repetitions}}, {0}); 49 | } 50 | std::chrono::system_clock::time_point after = std::chrono::system_clock::now(); 51 | double duration = std::chrono::duration_cast(after - before).count(); 52 | std::cout << "-------------------------------------------------------------------------------" << std::endl 53 | << "test result: Evaluating the spline " << repetitions << " times lasted " << duration << " milliseconds." 54 | << std::endl << "-------------------------------------------------------------------------------" 55 | << std::endl; 56 | } 57 | -------------------------------------------------------------------------------- /test/baf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | set(TEST_SOURCES 17 | ${TEST_SOURCES} 18 | ${CMAKE_CURRENT_SOURCE_DIR}/b_spline_basis_function_test.cc 19 | ${CMAKE_CURRENT_SOURCE_DIR}/basis_function_factory.cc 20 | ${CMAKE_CURRENT_SOURCE_DIR}/control_point_test.cc 21 | ${CMAKE_CURRENT_SOURCE_DIR}/knot_vector_test.cc 22 | ${CMAKE_CURRENT_SOURCE_DIR}/zero_degree_b_spline_basis_function_test.cc 23 | PARENT_SCOPE) 24 | -------------------------------------------------------------------------------- /test/baf/basis_function_factory.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include 16 | 17 | #include "gmock/gmock.h" 18 | 19 | #include "basis_function_factory.h" 20 | 21 | using testing::Test; 22 | 23 | class ABasisFunctionFactory : public Test { 24 | public: 25 | ABasisFunctionFactory() : degree_{Degree{-1}}, 26 | knot_vector_({ParamCoord{0}, ParamCoord{0}, ParamCoord{0}, ParamCoord{1}, ParamCoord{1}, ParamCoord{1}}), 27 | start_of_support_{KnotSpan{4}} {} 28 | 29 | protected: 30 | Degree degree_; 31 | baf::KnotVector knot_vector_; 32 | KnotSpan start_of_support_; 33 | baf::BasisFunctionFactory basis_function_factory; 34 | }; 35 | 36 | TEST_F(ABasisFunctionFactory, throwsError) { //NOLINT 37 | ASSERT_THROW(basis_function_factory.CreateDynamic(knot_vector_, start_of_support_, degree_), std::runtime_error); 38 | } 39 | -------------------------------------------------------------------------------- /test/baf/control_point_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "gmock/gmock.h" 16 | 17 | #include "control_point.h" 18 | 19 | using testing::Test; 20 | using testing::DoubleEq; 21 | using testing::DoubleNear; 22 | 23 | class AControlPoint : public Test { 24 | public: 25 | AControlPoint() : control_point({1.0, 2.0}), control_point_b({2.0, -1.0}), control_point_c({1.0, 0.7, 1.9}), 26 | transMatrix({std::array({0.5, 0.0, 0.866, 0.0}), 27 | std::array({0.0, 1.0, 0.0, 0.0}), 28 | std::array({-0.866, 0.0, 0.5, 0.0}), 29 | std::array({0.0, 0.0, 0.0, 1.0})}), 30 | scaling({1.0, 1.0, 1.0}) {} 31 | 32 | protected: 33 | baf::ControlPoint control_point; 34 | baf::ControlPoint control_point_b; 35 | baf::ControlPoint control_point_c; 36 | std::array, 4> transMatrix; 37 | std::array scaling; 38 | }; 39 | 40 | TEST_F(AControlPoint, ReturnsCorrectDimension) { // NOLINT 41 | ASSERT_THAT(control_point.GetDimension(), 2); 42 | } 43 | 44 | TEST_F(AControlPoint, Returns1For0Dimension) { // NOLINT 45 | ASSERT_THAT(control_point.GetValue(0), DoubleEq(1.0)); 46 | } 47 | 48 | TEST_F(AControlPoint, Returns2For1Dimension) { // NOLINT 49 | ASSERT_THAT(control_point.GetValue(1), DoubleEq(2.0)); 50 | } 51 | 52 | TEST_F(AControlPoint, Returns3ForSum0Dimension) { // NOLINT 53 | ASSERT_THAT((control_point + control_point_b).GetValue(0), DoubleEq(3.0)); 54 | } 55 | 56 | TEST_F(AControlPoint, PerformsTransformationCorrectly) { // NOLINT 57 | baf::ControlPoint control_point_t = control_point_c.Transform(transMatrix, scaling); 58 | ASSERT_THAT(control_point_t.GetValue(0), DoubleEq(2.1454)); 59 | } 60 | 61 | TEST_F(AControlPoint, PerformsScalingTransformation) { // NOLINT 62 | std::array customScaling = {0.5, 1, 0.7}; 63 | baf::ControlPoint control_point_t = control_point_c.Transform(transMatrix, customScaling); 64 | ASSERT_THAT(control_point_t.GetValue(0), DoubleNear(1.40178, 0.00001)); 65 | } 66 | -------------------------------------------------------------------------------- /test/io/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | set(TEST_SOURCES 17 | ${TEST_SOURCES} 18 | ${CMAKE_CURRENT_SOURCE_DIR}/iges_reader_writer_test.cc 19 | ${CMAKE_CURRENT_SOURCE_DIR}/io_converter_executables_test.cc 20 | ${CMAKE_CURRENT_SOURCE_DIR}/io_converter_test.cc 21 | ${CMAKE_CURRENT_SOURCE_DIR}/irit_reader_writer_test.cc 22 | ${CMAKE_CURRENT_SOURCE_DIR}/vtk_writer_test.cc 23 | ${CMAKE_CURRENT_SOURCE_DIR}/xml_reader_test.cc 24 | ${CMAKE_CURRENT_SOURCE_DIR}/xml_writer_test.cc 25 | PARENT_SCOPE) 26 | 27 | set(IGES_READ ${CMAKE_CURRENT_SOURCE_DIR}/test_files/read.iges PARENT_SCOPE) 28 | set(IGES_READ_2 ${CMAKE_CURRENT_SOURCE_DIR}/test_files/read2.iges PARENT_SCOPE) 29 | set(PATH_TO_IRIT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/test_files/test.itd PARENT_SCOPE) 30 | set(PATH_TO_XML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/test_files/spline_tank.xml PARENT_SCOPE) 31 | -------------------------------------------------------------------------------- /test/io/config_iges.in.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef TEST_IO_CONFIG_IGES_IN_H_ // NOLINT 16 | #define TEST_IO_CONFIG_IGES_IN_H_ 17 | 18 | #include 19 | 20 | static const char *iges_read = "@IGES_READ@"; 21 | static const char *iges_read_2 = "@IGES_READ_2@"; 22 | 23 | #endif // TEST_IO_CONFIG_IGES_IN_H_ 24 | -------------------------------------------------------------------------------- /test/io/config_irit.in.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef TEST_IO_CONFIG_IRIT_IN_H_ // NOLINT 16 | #define TEST_IO_CONFIG_IRIT_IN_H_ 17 | 18 | #include 19 | 20 | static const char *path_to_irit_file = "@PATH_TO_IRIT_FILE@"; 21 | 22 | #endif // TEST_IO_CONFIG_IRIT_IN_H_ 23 | -------------------------------------------------------------------------------- /test/io/config_xml.in.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #ifndef TEST_IO_CONFIG_XML_IN_H_ // NOLINT 16 | #define TEST_IO_CONFIG_XML_IN_H_ 17 | 18 | #include 19 | 20 | static const char *path_to_xml_file = "@PATH_TO_XML_FILE@"; 21 | 22 | #endif // TEST_IO_CONFIG_XML_IN_H_ 23 | -------------------------------------------------------------------------------- /test/spl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | set(TEST_SOURCES 17 | ${TEST_SOURCES} 18 | ${CMAKE_CURRENT_SOURCE_DIR}/b_spline_2d_test.cc 19 | ${CMAKE_CURRENT_SOURCE_DIR}/b_spline_test.cc 20 | ${CMAKE_CURRENT_SOURCE_DIR}/degree_elevation_test.cc 21 | ${CMAKE_CURRENT_SOURCE_DIR}/degree_reduction_test.cc 22 | ${CMAKE_CURRENT_SOURCE_DIR}/knot_insertion_and_removal_test.cc 23 | ${CMAKE_CURRENT_SOURCE_DIR}/knot_insertion_test.cc 24 | ${CMAKE_CURRENT_SOURCE_DIR}/knot_removal_test.cc 25 | ${CMAKE_CURRENT_SOURCE_DIR}/nurbs_2d_test.cc 26 | ${CMAKE_CURRENT_SOURCE_DIR}/nurbs_3d_test.cc 27 | ${CMAKE_CURRENT_SOURCE_DIR}/nurbs_test.cc 28 | ${CMAKE_CURRENT_SOURCE_DIR}/parameter_space_test.cc 29 | ${CMAKE_CURRENT_SOURCE_DIR}/physical_space_test.cc 30 | ${CMAKE_CURRENT_SOURCE_DIR}/projection_curve_test.cc 31 | ${CMAKE_CURRENT_SOURCE_DIR}/projection_surface_test.cc 32 | ${CMAKE_CURRENT_SOURCE_DIR}/random_b_spline_generator_test.cc 33 | ${CMAKE_CURRENT_SOURCE_DIR}/random_nurbs_generator_test.cc 34 | ${CMAKE_CURRENT_SOURCE_DIR}/spline_subdivision_test.cc 35 | ${CMAKE_CURRENT_SOURCE_DIR}/square_generator_test.cc 36 | ${CMAKE_CURRENT_SOURCE_DIR}/surface_generator_test.cc 37 | ${CMAKE_CURRENT_SOURCE_DIR}/weighted_physical_space_test.cc 38 | PARENT_SCOPE) 39 | 40 | set(MAX_SOURCES 41 | ${CMAKE_CURRENT_SOURCE_DIR}/surface_generator_test 42 | PARENT_SCOPE) 43 | -------------------------------------------------------------------------------- /test/spl/projection_curve_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "gmock/gmock.h" 16 | 17 | #include "b_spline.h" 18 | #include "projection.h" 19 | 20 | using testing::Test; 21 | using testing::DoubleEq; 22 | using testing::DoubleNear; 23 | 24 | class ABSpline2 : public Test { 25 | public: 26 | ABSpline2() { 27 | std::array knot_vector = 28 | {baf::KnotVector({ParamCoord{0}, ParamCoord{0}, ParamCoord{0}, ParamCoord{0}, ParamCoord{0.2}, ParamCoord{0.4}, 29 | ParamCoord{0.6}, ParamCoord{0.8}, ParamCoord{1}, ParamCoord{1}, ParamCoord{1}, 30 | ParamCoord{1}})}; 31 | std::array degree = {Degree{3}}; 32 | std::vector control_points = { 33 | baf::ControlPoint(std::vector({100, 100})), 34 | baf::ControlPoint(std::vector({140, 196})), 35 | baf::ControlPoint(std::vector({200, 240})), 36 | baf::ControlPoint(std::vector({260, 164})), 37 | baf::ControlPoint(std::vector({340, 164})), 38 | baf::ControlPoint(std::vector({400, 240})), 39 | baf::ControlPoint(std::vector({460, 196})), 40 | baf::ControlPoint(std::vector({500, 100})) 41 | }; 42 | knot_vector_ptr[0] = std::make_shared(knot_vector[0]); 43 | b_spline = std::make_shared>(knot_vector_ptr, degree, control_points); 44 | } 45 | 46 | protected: 47 | std::shared_ptr> b_spline; 48 | KnotVectors<1> knot_vector_ptr; 49 | }; 50 | 51 | TEST_F(ABSpline2, ComputesCorrectProjectionCloseToCenter) { // NOLINT 52 | ASSERT_THAT(spl::Projection<1>::ProjectionOnCurve({332, 200}, b_spline)[0].get(), DoubleNear(0.6223419238, 0.0001)); 53 | } 54 | 55 | TEST_F(ABSpline2, ComputesCorrectProjectionRightOfLastKnot) { // NOLINT 56 | ASSERT_THAT(spl::Projection<1>::ProjectionOnCurve({800, 200}, b_spline)[0].get(), DoubleEq(1)); 57 | } 58 | 59 | TEST_F(ABSpline2, ComputesCorrectProjectionLeftOfFirstKnot) { // NOLINT 60 | ASSERT_THAT(spl::Projection<1>::ProjectionOnCurve({0, 0}, b_spline)[0].get(), DoubleEq(0)); 61 | } 62 | -------------------------------------------------------------------------------- /test/util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | # 3 | # This file is part of SplineLib. 4 | # 5 | # SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation version 3 of the License. 7 | # 8 | # SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 10 | # details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 13 | # . 14 | # 15 | 16 | set(TEST_SOURCES 17 | ${TEST_SOURCES} 18 | ${CMAKE_CURRENT_SOURCE_DIR}/multi_index_handler_test.cc 19 | ${CMAKE_CURRENT_SOURCE_DIR}/string_operations_test.cc 20 | ${CMAKE_CURRENT_SOURCE_DIR}/any_casts_test.cc 21 | ${CMAKE_CURRENT_SOURCE_DIR}/vector_utils_test.cc 22 | PARENT_SCOPE) 23 | -------------------------------------------------------------------------------- /test/util/any_casts_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Chair for Computational Analysis of Technical Systems, RWTH Aachen University 2 | 3 | This file is part of SplineLib. 4 | 5 | SplineLib is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation version 3 of the License. 7 | 8 | SplineLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 9 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 10 | 11 | You should have received a copy of the GNU Lesser General Public License along with SplineLib. If not, see 12 | . 13 | */ 14 | 15 | #include "any_casts.h" 16 | 17 | #include "gmock/gmock.h" 18 | 19 | using testing::Test; 20 | using testing::DoubleEq; 21 | 22 | class AnySplines : public Test { 23 | public: 24 | AnySplines() { 25 | std::array degree = {Degree(1)}; 26 | KnotVectors<1> knot_vector_ptr = 27 | {std::make_shared(baf::KnotVector({ParamCoord(0), ParamCoord(0), ParamCoord(1), 28 | ParamCoord(1)}))}; 29 | std::vector control_points = {baf::ControlPoint{0.0}, baf::ControlPoint{1.2}}; 30 | spl::BSpline<1> b_spline_1d(knot_vector_ptr, degree, control_points); 31 | std::shared_ptr> b_spline_1d_ptr = std::make_shared>(b_spline_1d); 32 | b_spline_1d_any_ = std::make_any>>(b_spline_1d_ptr); 33 | 34 | std::array degrees = {Degree(1), Degree(1)}; 35 | KnotVectors<2> knot_vector_ptrs = {knot_vector_ptr[0], knot_vector_ptr[0]}; 36 | control_points = {baf::ControlPoint{0.0}, baf::ControlPoint{1.0}, baf::ControlPoint{2.0}, baf::ControlPoint{3.0}}; 37 | std::vector weights = {0.9, 0.8, 1.0, 1.2}; 38 | spl::NURBS<2> nurbs_2d(knot_vector_ptrs, degrees, control_points, weights); 39 | std::shared_ptr> nurbs_2d_ptr = std::make_shared>(nurbs_2d); 40 | nurbs_2d_any_ = std::make_any>>(nurbs_2d_ptr); 41 | } 42 | 43 | protected: 44 | std::any b_spline_1d_any_; 45 | std::any nurbs_2d_any_; 46 | }; 47 | 48 | TEST_F(AnySplines, CanBeCheckedForSplineDimension) { // NOLINT 49 | ASSERT_THAT(util::AnyCasts::GetSplineDimension(b_spline_1d_any_), 1); 50 | ASSERT_THAT(util::AnyCasts::GetSplineDimension(nurbs_2d_any_), 2); 51 | ASSERT_THROW(util::AnyCasts::GetSplineDimension(std::make_any(8)), std::runtime_error); 52 | } 53 | 54 | TEST_F(AnySplines, CanBeCastedToSplines) { // NOLINT 55 | ASSERT_THAT(util::AnyCasts::GetSpline<1>(b_spline_1d_any_)->GetControlPoint({1}).GetValue(0), DoubleEq(1.2)); 56 | ASSERT_THAT(util::AnyCasts::GetSpline<2>(nurbs_2d_any_)->GetWeight({1}), DoubleEq(0.8)); 57 | ASSERT_THROW(util::AnyCasts::GetSpline<1>(std::make_any(8)), std::runtime_error); 58 | } 59 | 60 | TEST_F(AnySplines, CanBeCheckedIfRational) { // NOLINT 61 | ASSERT_THAT(util::AnyCasts::IsRational<1>(b_spline_1d_any_), false); 62 | ASSERT_THAT(util::AnyCasts::IsRational<2>(nurbs_2d_any_), true); 63 | ASSERT_THROW(util::AnyCasts::IsRational<1>(std::make_any(8)), std::runtime_error); 64 | } 65 | --------------------------------------------------------------------------------