GCC Code Coverage Report


Directory: ./
File: libs/geometry/vtk/mesh.cpp
Date: 2024-03-28 16:25:37
Exec Total Coverage
Lines: 13 13 100.0%
Branches: 8 16 50.0%

Line Branch Exec Source
1 /************************************************************************
2 *
3 * Copyright (C) 2021-2023 IRCAD France
4 * Copyright (C) 2021 IHU Strasbourg
5 *
6 * This file is part of Sight.
7 *
8 * Sight is free software: you can redistribute it and/or modify it under
9 * the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * Sight is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with Sight. If not, see <https://www.gnu.org/licenses/>.
20 *
21 ***********************************************************************/
22
23 #include "mesh.hpp"
24
25 #include <io/vtk/helper/mesh.hpp>
26
27 #include <vtkCenterOfMass.h>
28 #include <vtkPolyData.h>
29 #include <vtkSmartPointer.h>
30
31 namespace sight::geometry::vtk
32 {
33
34 //------------------------------------------------------------------------------
35
36 1 data::point::sptr compute_center_of_mass(const data::mesh::csptr _mesh, const bool _use_scalar_as_weights)
37 {
38 1 vtkSmartPointer<vtkPolyData> poly_data = vtkSmartPointer<vtkPolyData>::New();
39
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 sight::io::vtk::helper::mesh::to_vtk_mesh(_mesh, poly_data);
40
41 // Compute the center of mass
42 1 vtkSmartPointer<vtkCenterOfMass> center_of_mass_filter =
43
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 vtkSmartPointer<vtkCenterOfMass>::New();
44
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 center_of_mass_filter->SetInputData(poly_data);
45
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 center_of_mass_filter->SetUseScalarsAsWeights(_use_scalar_as_weights);
46
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 center_of_mass_filter->Update();
47
48 1 std::array<double, 3> center_of_mass {};
49
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 center_of_mass_filter->GetCenter(center_of_mass.data());
50
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 data::point::sptr center = std::make_shared<data::point>(center_of_mass[0], center_of_mass[1], center_of_mass[2]);
51 1 return center;
52 1 }
53
54 //------------------------------------------------------------------------------
55
56 } // namespace sight::geometry::vtk
57