### Setup Scripts for Windows CI Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/30_Windows.md These batch scripts automate the installation of software requirements for continuous integration on a fresh Windows environment. Use with caution and on disposable virtual machines. ```batch @echo off setlocal enableextensions disabledelayedexpansion REM --- Install Visual Studio Build Tools --- call :install_vs_build_tools REM --- Install CMake --- call :install_cmake REM --- Install Git --- call :install_git REM --- Install Ninja --- call :install_ninja REM --- Install Python --- call :install_python REM --- Install NSIS (for installer) --- call :install_nsis REM --- Install 7-Zip --- call :install_7zip REM --- Install MSYS2 --- call :install_msys2 REM --- Install Chocolatey --- call :install_choco REM --- Install other dependencies via Chocolatey --- call :install_choco_packages endlocal echo All setup scripts completed. exit /b 0 :install_vs_build_tools echo Installing Visual Studio Build Tools... REM Add command to download and install VS Build Tools REM Example: winget install --id Microsoft.VisualStudio.2022.Community --source winget --accept-package-agreements --silent --install-location C:\Program Files\Microsoft Visual Studio\2022\Community echo Skipping VS Build Tools installation (manual step required or use winget). exit /b 0 :install_cmake echo Installing CMake... REM Add command to download and install CMake REM Example: choco install cmake --version=3.25.0 -y echo Skipping CMake installation (manual step required or use choco). exit /b 0 :install_git echo Installing Git... REM Add command to download and install Git REM Example: choco install git -y echo Skipping Git installation (manual step required or use choco). exit /b 0 :install_ninja echo Installing Ninja... REM Add command to download and install Ninja REM Example: choco install ninja -y echo Skipping Ninja installation (manual step required or use choco). exit /b 0 :install_python echo Installing Python... REM Add command to download and install Python REM Example: choco install python --version=3.10.4 -y echo Skipping Python installation (manual step required or use choco). exit /b 0 :install_nsis echo Installing NSIS... REM Add command to download and install NSIS REM Example: choco install nsis -y echo Skipping NSIS installation (manual step required or use choco). exit /b 0 :install_7zip echo Installing 7-Zip... REM Add command to download and install 7-Zip REM Example: choco install 7zip -y echo Skipping 7-Zip installation (manual step required or use choco). exit /b 0 :install_msys2 echo Installing MSYS2... REM Add command to download and install MSYS2 REM Example: Start-Process msiexec.exe -ArgumentList '/i https://repo.msys2.org/distrib/msys2-x86_64-latest.exe /VERYSILENT /NORESTART /SP- /CLOSEAPPTOLERATED /D=C:\msys64' -Wait echo Skipping MSYS2 installation (manual step required). exit /b 0 :install_choco echo Installing Chocolatey... IF NOT DEFINED ALLUSERSPROFILE ( SET ALLUSERSPROFILE=C:\ProgramData ) IF NOT EXIST "%ALLUSERSPROFILE%\chocolatey\bin\choco.exe" ( SET PATH=%PATH%;%ALLUSERSPROFILE% REM PowerShell command to install Chocolatey powershell -Command "Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" choco --version ) ELSE ( echo Chocolatey is already installed. ) exit /b 0 :install_choco_packages echo Installing additional packages via Chocolatey... REM Add commands for other dependencies REM Example: choco install mingw-w64-x86_64-toolchain -y echo Skipping additional package installation via Chocolatey. exit /b 0 ``` -------------------------------- ### SOFA Qt Viewer Video Recording Start Log Source: https://github.com/sofa-framework/doc/blob/master/15_Using_SOFA/11_runSofa_with_Qt.md Example console output when starting video recording using ffmpeg via the SOFA Qt viewer. Specifies output file, codec, FPS, and bitrate. ```shell Start recording to C:/Work/sofa/build/sandbox/screenshots/caduceus__r60_0001.mp4 ( yuv420p, 60 FPS, 5120000 b/s) using ffmpeg.exe ffmpeg version 4.4-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers built with gcc 10.2.0 (Rev6, Built by MSYS2 project) ... frame= 132 fps= 25 q=-1.0 Lsize= 727kB time=00:00:02.15 bitrate=2771.1kbits/s speed=0.412x ``` -------------------------------- ### Install Build Essentials Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Installs the standard compilation toolkit on Debian-based systems. This is a prerequisite for manual builds. ```bash sudo apt install build-essential software-properties-common ``` -------------------------------- ### Install Ninja Build System Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/20_MacOS.md Install Ninja, an alternative build system to Make, using Homebrew. ```bash brew install ninja ``` -------------------------------- ### Install tinyXML2 Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/20_MacOS.md Install the tinyXML2 library, a dependency for SOFA, using Homebrew. ```bash brew install tinyxml2 ``` -------------------------------- ### Install tinyXML2 Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Installs the tinyXML2 library, a core dependency for SOFA. ```bash sudo apt install libtinyxml2-dev ``` -------------------------------- ### Install OpenGL Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Installs the OpenGL library, a core dependency for SOFA. ```bash sudo apt install libopengl0 ``` -------------------------------- ### Install GUI Dependencies Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Installs Xorg and GTK development libraries required for the SOFAGLFW graphical user interface. ```bash sudo apt install xorg-dev libgtk-3-dev ``` -------------------------------- ### Install Ccache Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/20_MacOS.md Install Ccache, a compiler cache that can significantly speed up recompilation times, using Homebrew. ```bash brew install ccache ``` -------------------------------- ### Install Boost Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/20_MacOS.md Install the Boost C++ libraries (version 1.65.1 or higher), a core dependency for SOFA, using Homebrew. ```bash brew install boost ``` -------------------------------- ### Install CMake Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/20_MacOS.md Install CMake version 3.22 or higher using Homebrew. ```bash brew install --cask cmake ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Installs and upgrades pip, then installs NumPy, SciPy, and PyBind11 within a Python virtual environment. ```bash python3.12 -m pip install --upgrade pip \ && python3.12 -m pip install numpy scipy pybind11==2.12.0 ``` -------------------------------- ### InteractionForceField Example Source: https://github.com/sofa-framework/doc/blob/master/40_Programming_with_SOFA/60_API_overview/33_Matrix_assembly_API.md Example demonstrating how to get force derivatives with respect to positions for multiple mechanical states using InteractionForceField. ```APIDOC ## InteractionForceField Example ### Description This code snippet shows how to access and manipulate force derivatives in relation to positions for different mechanical states within the `InteractionForceField`. ### Code Example ```cpp auto df1_dx1 = matrix->getForceDerivativeIn(m1).withRespectToPositionsIn(m1); auto df1_dx2 = matrix->getForceDerivativeIn(m1).withRespectToPositionsIn(m2); auto df2_dx1 = matrix->getForceDerivativeIn(m2).withRespectToPositionsIn(m1); auto df2_dx2 = matrix->getForceDerivativeIn(m2).withRespectToPositionsIn(m2); for (sofa::Index e = 0; e < n; ++e) { const Spring& s = ss[e]; const Mat& m = this->dfdx[e]; const unsigned p1 = Deriv::total_size * s.m1; const unsigned p2 = Deriv::total_size * s.m2; df1_dx1(p1, p1) += -m; df1_dx2(p1, p2) += m; df2_dx1(p2, p1) += m; df2_dx2(p2, p2) += -m; } ``` ``` -------------------------------- ### Install Additional Libraries Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/20_MacOS.md Install additional required libraries for SOFA: libPNG, libJPEG, libTIFF, and Glew using Homebrew. ```bash brew install libpng libjpeg libtiff glew ``` -------------------------------- ### Set CMake Variables for Installer Generation Source: https://github.com/sofa-framework/doc/blob/master/40_Programming_with_SOFA/50_Create_your_binaries.md Configure CMake variables to generate an installer using Qt Installer Framework. Requires Qt IFW to be installed. Set CPACK_IFW_ROOT to the Qt IFW location and enable IFW and ZIP generators. ```cmake CPACK_IFW_ROOT= CPACK_GENERATOR=ZIP;IFW CPACK_BINARY_ZIP=ON CPACK_BINARY_IFW=ON ``` -------------------------------- ### Testing a Solver's Convergence Source: https://github.com/sofa-framework/doc/blob/master/50_Contributing_to_SOFA/20_Writing_tests.md Illustrates testing a solver's convergence to a static solution. This example focuses on checking if the solver has converged to the expected position. ```cpp // Example usage within a test class for a solver // Assume 'this' is an instance of a solver test class // and 'mecSim' is a MechanicalSimulation object. // Simulate the system and obtain results // ... // Check convergence criteria // ASSERT_TRUE(solver.hasConverged()); // ASSERT_NEAR(solver.getConvergedPosition(), expected_position, tolerance); ``` -------------------------------- ### Mapping_test Example Source: https://github.com/sofa-framework/doc/blob/master/50_Contributing_to_SOFA/20_Writing_tests.md Shows how to test a mapping by deriving from Mapping_test.h. It sets up a scene with parent and child nodes and verifies Jacobian methods. ```cpp // Example usage within a test class derived from Mapping_test // Assume 'this' is an instance of a class derived from Mapping_test // and 'mecSim' is a MechanicalSimulation object. // Define expected output positions // ... // The base class methods will automatically test Jacobian-related functions // and compare actual output positions with expected ones. ``` -------------------------------- ### Test Fixture Setup and Teardown Source: https://github.com/sofa-framework/doc/blob/master/50_Contributing_to_SOFA/20_Writing_tests.md Defines the SetUp and TearDown methods for a test fixture, responsible for initializing and unloading the simulation scene. ```cpp /// Create the context for the scene void SetUp() { // Init simulation sofa::simulation::setSimulation(simulation = new sofa::simulation::graph::DAGSimulation()); root = simulation::getSimulation()->createNewGraph("root"); } /// Unload the scene void TearDown() { if (root!=NULL) sofa::simulation::getSimulation()->unload(root); } ``` -------------------------------- ### Install Boost Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Installs the Boost C++ libraries, a core dependency for SOFA. Version 1.65.1 or higher is required. ```bash sudo apt install libboost-all-dev ``` -------------------------------- ### CMakeLists.txt for a Test Executable Source: https://github.com/sofa-framework/doc/blob/master/50_Contributing_to_SOFA/20_Writing_tests.md Example CMakeLists.txt file for creating a test executable. It sets up dependencies on the plugin being tested and SofaTest. ```cmake cmake_minimum_required(VERSION 3.10) project(YourPlugin_test) find_package(Sofa REQUIRED) add_executable(YourPlugin_test test.cpp) target_link_libraries(YourPlugin_test PRIVATE Sofa::Sofa Sofa::SofaTest) ``` -------------------------------- ### Install Eigen Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/20_MacOS.md Install the Eigen library (version 3.2.10 or higher), a dependency for SOFA, using Homebrew. ```bash brew install eigen ``` -------------------------------- ### Install CCache Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Installs CCache, a compiler cache that can significantly speed up recompilation times. This is an optional dependency. ```bash sudo apt install ccache ``` -------------------------------- ### Python Scene Creation Example Source: https://github.com/sofa-framework/doc/blob/master/40_Programming_with_SOFA/40_Create_your_scene_in_Cpp.md A minimal Python snippet demonstrating how to create a scene graph node and add a component using the SofaPython3 plugin. ```python def createScene(node): # create a node in the scene graph (i.e. 'Node' in xml scenes) child_node = node.createChild('child name') # create a component under the graph node child_dofs = child_node.addObject('MechanicalObject', template = 'Vec3', name = 'dofs') ``` -------------------------------- ### Install Python 3.12 and Link Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/20_MacOS.md Install Python 3.12 using Homebrew and force link it. This is required for SOFA dependencies. ```bash brew install python@3.12 brew link --force python@3.10 ``` -------------------------------- ### Install Eigen Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Installs the Eigen library, a dependency for SOFA. Version 3.2.10 or higher is required. ```bash sudo apt install libeigen3-dev ``` -------------------------------- ### Install Ninja Build System Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Installs Ninja, an alternative build system to Make that offers better incremental build performance. This is an optional dependency. ```bash sudo apt install ninja-build ``` -------------------------------- ### Install Additional Image Libraries Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Installs development libraries for PNG, JPEG, TIFF image formats, along with Glew and Zlib. ```bash sudo apt install libpng-dev libjpeg-dev libtiff-dev libglew-dev zlib1g-dev ``` -------------------------------- ### ForceField_test Example Source: https://github.com/sofa-framework/doc/blob/master/50_Contributing_to_SOFA/20_Writing_tests.md Demonstrates testing a force field by deriving from ForceField_test.h. It sets up a scene and uses run_test to check forces and stiffness. ```cpp // Example usage within a test class derived from ForceField_test // Assume 'this' is an instance of a class derived from ForceField_test // and 'mecSim' is a MechanicalSimulation object. // Define positions, velocities, and expected forces // ... // Run the test and automatically check forces and stiffness run_test(positions, velocities, expected_forces); ``` -------------------------------- ### Install Python 3.12 Development Files Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Installs Python 3.12 development headers and venv module, required for SOFA. ```bash sudo apt install python3.12-dev python3.12-venv ``` -------------------------------- ### Using get() Method for Component Search Source: https://github.com/sofa-framework/doc/blob/master/40_Programming_with_SOFA/60_API_overview/10_Components_in_SOFA.md Explains how to use the lower-level `get()` method on a context to find components, with options for search direction and tag filtering. ```APIDOC ## Using get() Method for Component Search ### Description Utilizes the `getContext()->get()` method for component retrieval with various search strategies and tag matching. ### Methods #### Basic `get()` - `this->getContext()->get(mapping)`: Attempts to get a component of the specified type. #### `get()` with Search Direction - `this->getContext()->get(mapping, sofa::core::objectmodel::BaseContext::SearchUp)`: Search upward from the local node. - `this->getContext()->get(mapping, sofa::core::objectmodel::BaseContext::SearchDown)`: Search downward from the local node. - `this->getContext()->get(mapping, sofa::core::objectmodel::BaseContext::Local)`: Search only within the local node. - `this->getContext()->get(mapping, sofa::core::objectmodel::BaseContext::SearchRoot)`: Search starting from the root node and going down. #### `get()` with Template and Search Direction - `static_cast<...>(this->getContext())->get(&list_collisionModels)`: Generic get with default search (up). - `static_cast<...>(this->getContext())->get(&list_collisionModels, BaseContext::SearchUp)`: Explicitly search up. - `static_cast<...>(this->getContext())->get(&list_collisionModels, BaseContext::SearchDown)`: Search down. - `static_cast<...>(this->getContext())->get(&list_collisionModels, BaseContext::Local)`: Search locally. - `static_cast<...>(this->getContext())->get(&list_collisionModels, BaseContext::SearchRoot)`: Search from the root. #### `get()` with Tags - `this->getContext()->get(mapping, this->getTags(), sofa::core::objectmodel::BaseContext::SearchDown)`: Find components matching the current node's tags, searching down. - `this->getContext()->get(mapping, tagsToFind, sofa::core::objectmodel::BaseContext::SearchDown)`: Find components matching a specific `TagSet`, searching down. ### Example Usage (C++) ```cpp // Get a mapping component core::componentmodel::behavior::BaseMapping* mapping; this->getContext()->get(mapping); // Get collision models searching down sofa::helper::vector list_collisionModels; static_cast(this->getContext())->get(&list_collisionModels, sofa::core::objectmodel::BaseContext::SearchDown); // Get components with specific tags sofa::core::objectmodel::TagSet tagsToFind; tagsToFind.insert(sofa::core::objectmodel::Tag("Fluid")); this->getContext()->get(mapping, tagsToFind, sofa::core::objectmodel::BaseContext::SearchDown); ``` ``` -------------------------------- ### Search Available Clang Versions Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Lists all available Clang versions that can be installed on your distribution. ```bash apt-cache search "^clang-[0-9.]+$ " ``` -------------------------------- ### Search Available GCC Versions Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Lists all available GCC versions that can be installed on your distribution. ```bash apt-cache search "^gcc-[0-9.]+$ " ``` -------------------------------- ### Projective Constraint Test Setup Source: https://github.com/sofa-framework/doc/blob/master/50_Contributing_to_SOFA/20_Writing_tests.md Details the setup for testing a projective constraint. It involves creating a scene, defining constraint parameters, and checking particle positions. ```cpp // Example usage within a test class for a projective constraint // Assume 'this' is an instance of a projective constraint test class // and 'mecSim' is a MechanicalSimulation object. // Define constraint parameters (e.g., points to project, normal) // ... // Initialize the scene and project positions // scene.init(); // constraint.projectPosition(); // Check if constrained particles have expected positions and unconstrained ones haven't changed // ASSERT_NEAR(constrained_particle.position, expected_position, tolerance); // ASSERT_EQ(unconstrained_particle.position, initial_position); ``` -------------------------------- ### Transparent API Example Source: https://github.com/sofa-framework/doc/blob/master/40_Programming_with_SOFA/60_API_overview/15_Forward_declaration.md Presents the 'transparent' API of a Node class, showing its inheritance and member function declarations. This requires the full definition of the class. ```cpp #include #include namespace sofa::simulation { class Node : public Context, public BaseNode { public: double getDt(); ///.... }; } ``` -------------------------------- ### TransformEngine Python Configuration Source: https://github.com/sofa-framework/doc/blob/master/20_Simulation_Principles/70_Engine.md Example of configuring a TransformEngine using Python to apply a translation to input positions. ```python node.addObject("TransformEngine", name="translationEngine", template="Vec3d", translation="10 0 0", input_position="@meshLoader.position") node.addObject("MechanicalObject", name="transform", template="Vec3d", position="@translationEngine.output_position") ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/20_MacOS.md Upgrade pip and install necessary Python packages (numpy, scipy, pybind11) for SOFA development within a virtual environment. ```bash python3.12 -m pip install --upgrade pip \ && python3.12 -m pip install numpy scipy pybind11==2.12.0 ``` -------------------------------- ### MatrixLinearSystem Configuration Source: https://github.com/sofa-framework/doc/blob/master/40_Programming_with_SOFA/60_API_overview/33_Matrix_assembly_API.md Example XML configuration for MatrixLinearSystem, the default matrix assembly method. ```APIDOC ## MatrixLinearSystem Configuration ### Description `MatrixLinearSystem` is the default method for matrix assembly in SOFA. It supports contributions from various components like force fields, masses, non-linear mappings, and projective constraints. It also handles matrix mapping. ### XML Configuration Example ```xml ``` ### Attributes - `template`: Specifies the matrix type (e.g., `CompressedRowSparseMatrixd`). - `name`: Unique identifier for the system. - `assembleMass`: Boolean to control mass matrix assembly. - `assembleMappings`: Boolean to control mapping contributions. - `applyProjectiveConstraints`: Boolean to control projective constraint application. ``` -------------------------------- ### SOFA Advanced Timer Output Example Source: https://github.com/sofa-framework/doc/blob/master/15_Using_SOFA/32_Performances/10_Inspect_performances.md This example demonstrates the hierarchical text output generated by SOFA's Advanced Timer, showing computation times for nested code sections. ```text ==== Animate ==== Trace of last iteration : * 0.06 ms > begin Mechanical on Cube grid * 0.10 ms > begin Build linear equation * > begin forces in the right-hand term * 1.27 ms < end forces in the right-hand term * 1.37 ms > begin shift and project independent states * 1.49 ms < end shift and project independent states * > begin local M * 2.11 ms < end local M * 2.38 ms > begin J products * 12.89 ms < end J products * 12.91 ms > begin J products * 28.06 ms < end J products * > begin local K * 28.51 ms < end local K * 28.53 ms > begin JMJt, JKJt, JCJt * 86.86 ms < end JMJt, JKJt, JCJt * > begin implicit equation: scaling and sum of matrices, update right-hand term * 87.75 ms < end implicit equation: scaling and sum of matrices, update right-hand term * < end Build linear equation * > begin Solve linear equation * 90.78 ms < end Solve linear equation * 94.81 ms < end Mechanical on Cube grid * 94.83 ms > begin UpdateMapping * - step UpdateMappingEndEvent * 94.84 ms < end UpdateMapping * > begin UpdateBBox * 94.93 ms < end UpdateBBox * 94.94 ms END Steps Duration Statistics (in ms) : LEVEL START NUM MIN MAX MEAN DEV TOTAL PERCENT ID 0 0 100 86.57 127.50 109.99 7.77 10999.1 100 TOTAL 1 0.06 1 86.32 127.25 109.75 7.75 109.75 99.78 .Mechanical 2 0.09 1 79.42 112.21 99.97 7.02 99.97 90.89 ..Build linear equation 3 0.09 1 0.84 1.36 1.14 0.14 1.14 1.04 ...forces in the right-hand term 3 1.34 1 0.07 0.14 0.10 0.02 0.10 0.09 ...shift and project independent states 3 1.44 1 0.39 0.68 0.55 0.08 0.55 0.50 ...local M 3 2.23 2 7.52 17.67 12.72 2.34 25.44 23.13 ...J products 3 27.70 1 0.28 0.54 0.41 0.06 0.41 0.37 ...local K 3 28.13 1 54.07 79.54 70.61 5.53 70.61 64.20 ...JMJt, JKJt, JCJt 3 98.75 1 0.88 2.29 1.31 0.24 1.32 1.20 ...implicit equation: scaling and sum of matrices, update right-hand term 2 100.06 1 2.71 4.79 3.75 0.51 3.75 3.41 ..Solve linear equation 1 109.84 1 0.01 0.02 0.02 0 0.02 0.01 .UpdateMapping 2 109.84 1 0 0 0 0 0 0 ..UpdateMappingEndEvent 1 109.85 1 0.09 0.28 0.14 0.03 0.14 0.12 .UpdateBBox ==== END ==== ``` -------------------------------- ### SOFA Test Fixture Example Source: https://github.com/sofa-framework/doc/blob/master/50_Contributing_to_SOFA/20_Writing_tests.md A C++ code snippet demonstrating the typical structure of a test fixture in the SOFA framework, including necessary includes and namespace usage. ```cpp /****************************************************************************** * SOFA, Simulation Open-Framework Architecture, development version * * (c) 2006-2017 INRIA, USTL, UJF, CNRS, MGH * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published by * * the Free Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. * * * This program is distributed in the hope that it will be useful, but WITHOUT * * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * * for more details. * * * You should have received a copy of the GNU Lesser General Public License * * along with this program. If not, see . * ******************************************************************************* * Authors: The SOFA Team and external contributors (see Authors.txt) * * * Contact information: contact@sofa-framework.org * *******************************************************************************/ #include #include #include namespace sofa { using namespace component; using namespace defaulttype; template struct EmptyPlugin_test : public Sofa_test { typedef _DataTypes DataTypes; typedef typename DataTypes::CPos CPos; typedef typename DataTypes::VecCoord VecCoord; typedef typename DataTypes::VecDeriv VecDeriv; typedef container::MechanicalObject MechanicalObject; /// Root of the scene graph simulation::Node::SPtr root; /// Simulation simulation::Simulation* simulation; ``` -------------------------------- ### Install Specific Clang Version Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Installs a specific version of Clang, for example, Clang 12. Replace '12' with the desired version. ```bash sudo apt install clang-12 ``` -------------------------------- ### Install Specific GCC Version Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Installs a specific version of GCC, for example, GCC 11. Replace '11' with the desired version. ```bash sudo apt install gcc-11 ``` -------------------------------- ### Add SpotLight Source: https://github.com/sofa-framework/doc/blob/master/30_Components/65_Rendering/40_Lighting.md Set up a spotlight with color, position, direction, cutoff angle, exponent, and attenuation. The color is specified in RGB. ```xml ``` -------------------------------- ### Scene Design: Old vs. New Linear Solver Setup Source: https://github.com/sofa-framework/doc/blob/master/40_Programming_with_SOFA/60_API_overview/33_Matrix_assembly_API.md Illustrates the change in scene design for linear solvers. Previously, only a solver was specified. Now, a separate MatrixLinearSystem component is recommended, with the solver referencing it. ```xml ``` ```xml ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/30_Windows.md Installs or upgrades pip and installs essential Python packages for SOFA development. Ensure your Python virtual environment is activated before running these commands. ```bash path\to\Python312\python.exe -m pip install --upgrade pip ``` ```bash path\to\Python312\python.exe -m pip install numpy scipy pybind11==2.12.0 ``` -------------------------------- ### Configure Multiple Linear Systems in XML Source: https://github.com/sofa-framework/doc/blob/master/40_Programming_with_SOFA/60_API_overview/33_Matrix_assembly_API.md Example XML configuration for setting up multiple MatrixLinearSystem components and a CompositeLinearSystem to manage them. This allows for assembling different matrices (e.g., global, stiffness, mass) simultaneously. ```xml ``` -------------------------------- ### Install CGAL Plugin Dependency Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/20_MacOS.md Installs the CGAL library using Homebrew, which is a dependency for the CGALPlugin. ```bash brew install cgal ``` -------------------------------- ### Launch SOFA with Pixi Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/20_MacOS.md Launch SOFA using the Pixi run command with the 'supported-plugins' environment. ```bash pixi run -e supported-plugins runSofa ``` -------------------------------- ### Install SofaCUDA Dependency Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/20_MacOS.md Installs the NVIDIA CUDA toolkit using Homebrew, required for SofaCUDA plugin. ```bash brew install homebrew/cask-drivers/nvidia-cuda ``` -------------------------------- ### Linear Solver with Preconditioners Configuration Source: https://github.com/sofa-framework/doc/blob/master/40_Programming_with_SOFA/60_API_overview/33_Matrix_assembly_API.md Sets up a ShewchukPCGLinearSolver with a WarpPreconditioner, demonstrating multiple solvers within the same context. ```xml ``` -------------------------------- ### Install CUDA Toolkit Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Installs the NVIDIA CUDA Toolkit, required for the SofaCUDA plugin. The supported version is 12.2. ```bash sudo apt install nvidia-cuda-toolkit ``` -------------------------------- ### Collision Particle and Force Feedback Setup Source: https://github.com/sofa-framework/doc/blob/master/35_Plugins/50_Usual_plugins/55_Sensable.md Sets up a collision particle at the instrument's tip, defines its collision model, maps it to the instrument's state, and configures force feedback based on collisions. ```xml ``` -------------------------------- ### Build SOFA with Pixi Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/20_MacOS.md Trigger the SOFA build using the Pixi run command with the 'supported-plugins' environment. ```bash pixi run -e supported-plugins build ``` -------------------------------- ### Install CGAL Plugin Dependency Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Installs the CGAL library development files, a dependency for the CGALPlugin. This is an optional dependency. ```bash sudo apt install libcgal-dev ``` -------------------------------- ### Install CMake Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md Installs CMake, which is required to configure the SOFA project before compilation. CMake version 3.22 or higher is needed. ```bash sudo apt install cmake cmake-gui ``` -------------------------------- ### Build Constraint System in Simulation Source: https://github.com/sofa-framework/doc/blob/master/20_Simulation_Principles/60_Constraint/20_Lagrange_Constraint.md This C++ code snippet demonstrates the sequential execution of visitors to build and process the constraint system. It includes resetting the constraint matrix, building it based on scene laws, accumulating derivatives, handling projective constraints, clearing Lagrange multipliers, calculating constraint violations, determining resolution methods, and adding compliance in the constraint space. ```cpp simulation::MechanicalResetConstraintVisitor(cParams).execute(context); simulation::MechanicalBuildConstraintMatrix(cParams, cParams->j(), numConstraints).execute(context); simulation::MechanicalAccumulateMatrixDeriv(cParams, cParams->j(), reverseAccumulateOrder.getValue()).execute(context); simulation::MechanicalProjectJacobianMatrixVisitor(&mparams).execute(context); current_cp->clear(numConstraints); MechanicalGetConstraintViolationVisitor(cParams, ¤t_cp->dFree).execute(context); MechanicalGetConstraintResolutionVisitor(cParams, current_cp->constraintsResolutions).execute(context); cc->addComplianceInConstraintSpace(cParams, ¤t_cp->W); ``` -------------------------------- ### Install Plugin Target in CMake Source: https://github.com/sofa-framework/doc/blob/master/40_Programming_with_SOFA/20_Create_your_plugin.md Add this command to your plugin's CMakeLists.txt to install its targets. It specifies the runtime, library, and archive destinations. ```cmake install(TARGETS MyPlugin RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) ``` -------------------------------- ### Initializing Inputs and Outputs in DataEngine Source: https://github.com/sofa-framework/doc/blob/master/40_Programming_with_SOFA/31_Create_your_engine.md Implement the `init()` method in a custom DataEngine to register input and output data fields using `addInput()` and `addOutput()`. ```cpp virtual void init() override { addInput(d_input1) addInput(d_input2) ... addOutput(d_output1) addOutput(d_output2) ... } ``` -------------------------------- ### Launching Visitors Source: https://github.com/sofa-framework/doc/blob/master/40_Programming_with_SOFA/60_API_overview/10_Components_in_SOFA.md Details on how to execute visitors on nodes and components, including configuration and tag-based filtering. ```APIDOC ## Launching Visitors ### Description Procedures for launching visitors, which are key to SOFA's genericity, on nodes and components. ### Methods #### Basic Visitor Execution - `currentNode->execute()`: Launches a visitor (e.g., `VisualUpdateVisitor`) from the current node. - `visitor.execute(this->getContext())`: Executes a configured visitor on the given context. #### Visitor Configuration and Execution - `visitor.setOrder(orderState)`: Configures the visitor with a specific order. - `visitor.setTags(this->getTags())`: Configures the visitor to operate only on components matching the current node's tags. ### Example Usage (C++) ```cpp // Launch a default visitor from the current node simulation::Node *currentNode = static_cast(this->getContext()); currentNode->execute(); // Configure and launch a specific visitor sofa::simulation::MechanicalWriteLMConstraint LMConstraintVisitor; LMConstraintVisitor.setOrder(orderState); LMConstraintVisitor.execute(this->getContext()); // Configure visitor with tags and execute LMConstraintVisitor.setTags(this->getTags()).execute(this->getContext()); ``` ``` -------------------------------- ### Enter Nix Development Shell Source: https://github.com/sofa-framework/doc/blob/master/10_Getting_Started/20_Build/10_Linux.md This command provides a shell environment with all necessary dependencies to build the project using CMake. ```bash nix develop ``` -------------------------------- ### Example of Advanced Timer Statistics Output Source: https://github.com/sofa-framework/doc/blob/master/40_Programming_with_SOFA/60_API_overview/50_Advanced_Timer.md This is an example of the detailed computation time statistics generated by the AdvancedTimer. It shows the trace of the last iteration with nested timings and a summary of duration statistics. ```bash ==== Animate ==== Trace of last iteration :  *    0.06 ms > begin Mechanical on Cube grid  *    0.10 ms   > begin Build linear equation  *                > begin forces in the right-hand term  *    1.27 ms     < end   forces in the right-hand term  *    1.37 ms     > begin shift and project independent states  *    1.49 ms     < end   shift and project independent states  *                > begin local M  *    2.11 ms     < end   local M  *    2.38 ms     > begin J products  *   12.89 ms     < end   J products  *   12.91 ms     > begin J products  *   28.06 ms     < end   J products  *                > begin local K  *   28.51 ms     < end   local K  *   28.53 ms     > begin JMJt, JKJt, JCJt  *   86.86 ms     < end   JMJt, JKJt, JCJt  *                > begin implicit equation: scaling and sum of matrices, update right-hand term  *   87.75 ms     < end   implicit equation: scaling and sum of matrices, update right-hand term   *              < end   Build linear equation  *              > begin Solve linear equation  *   90.78 ms < end   Solve linear equation  *   94.81 ms < end   Mechanical on Cube grid  *   94.83 ms > begin UpdateMapping  *              - step  UpdateMappingEndEvent  *   94.84 ms < end   UpdateMapping  *            > begin UpdateBBox  *   94.93 ms < end   UpdateBBox  *   94.94 ms END Steps Duration Statistics (in ms) : LEVEL   START    NUM      MIN      MAX   MEAN     DEV    TOTAL  PERCENT ID   0       0     100      86.57  127.50  109.99    7.77 10999.1  100    TOTAL   1       0.06    1      86.32  127.25  109.75    7.75  109.75   99.78 .Mechanical   2       0.09    1      79.42  112.21   99.97    7.02   99.97   90.89 ..Build linear equation   3       0.09    1       0.84    1.36    1.14    0.14    1.14    1.04 ...forces in the right-hand term   3       1.34    1       0.07    0.14    0.10    0.02    0.10    0.09 ...shift and project independent states   3       1.44    1       0.39    0.68    0.55    0.08    0.55    0.50 ...local M   3       2.23    2       7.52   17.67   12.72    2.34   25.44   23.13 ...J products   3      27.70    1       0.28    0.54    0.41    0.06    0.41    0.37 ...local K   3      28.13    1      54.07   79.54   70.61    5.53   70.61   64.20 ...JMJt, JKJt, JCJt   3      98.75    1       0.88    2.29    1.31    0.24    1.32    1.20 ...implicit equation: scaling and sum of matrices, update right-hand term    2     100.06    1       2.71    4.79    3.75    0.51    3.75    3.41 ..Solve linear equation   1     109.84    1       0.01    0.02    0.02    0       0.02    0.01 .UpdateMapping   2     109.84    1       0       0       0       0       0       0    ..UpdateMappingEndEvent   1     109.85    1       0.09    0.28    0.14    0.03    0.14    0.12 .UpdateBBox ==== END ==== ``` -------------------------------- ### Get Generic Components using BaseObject::get with Type in SOFA Source: https://github.com/sofa-framework/doc/blob/master/40_Programming_with_SOFA/60_API_overview/10_Components_in_SOFA.md Retrieve a list of components of a specific type using a templated version of the get method. The search direction can be specified. ```cpp sofa::helper::vector< sofa::core::CollisionModel* > list_collisionModels; //container for the component you want to find //Default call: search from current node, then goes up static_cast(this->getContext())->get< sofa::core::CollisionModel >( &list_collisionModels ); //Same behavior as previous call, only it explicits the method called static_cast(this->getContext())->get< sofa::core::CollisionModel >( &list_collisionModels, BaseContext::SearchUp); //Starts from the current node, and goes down static_cast(this->getContext())->get< sofa::core::CollisionModel >( &list_collisionModels, BaseContext::SearchDown); //Search only in the current node static_cast(this->getContext())->get< sofa::core::CollisionModel >( &list_collisionModels, BaseContext::Local); //Search from the root static_cast(this->getContext())->get< sofa::core::CollisionModel >( &list_collisionModels, BaseContext::SearchRoot); ``` -------------------------------- ### Fixing Qt Version Conflicts with Geomagic Script Source: https://github.com/sofa-framework/doc/blob/master/35_Plugins/50_Usual_plugins/70_Geomagic.md If a Qt version conflict arises after installing the Geomagic SDK on Linux, remove or comment out specific lines in the \"geomagic.sh\" script located in \"/etc/profile.d/\". This script can interfere with existing Qt installations. ```bash export LD_LIBRARY_PATH=/opt/geomagic_touch_device_driver/lib export QT_PLUGIN_PATH=/opt/geomagic_touch_device_driver/lib/plugins ```