Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ Checks: >
-fuchsia*,
-llvmlibc*,
-llvm-header-guard,
-llvm-prefer-static-over-anonymous-namespace,
-misc-no-recursion,
-modernize-use-trailing-return-type,
-readability-redundant-access-specifiers,
-readability-convert-member-functions-to-static,
-cppcoreguidelines-avoid-const-or-ref-data-members

CheckOptions:
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1'
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: "1"
- key: readability-identifier-length.MinimumLoopCounterNameLength
value: 1
- key: readability-identifier-length.IgnoredVariableNames
value: '^[defijkptuvw]$'
value: "^[defijkptuvw]$"
# More options here: https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html
- key: readability-identifier-naming.NamespaceCase
value: lower_case
- key: readability-identifier-naming.ClassCase
value: CamelCase
value: CamelCase
- key: readability-identifier-naming.StructCase
value: CamelCase
value: CamelCase
- key: readability-identifier-naming.FunctionCase
value: lower_case
- key: readability-identifier-naming.VariableCase
Expand All @@ -51,14 +52,12 @@ CheckOptions:
- key: readability-identifier-naming.GlobalFunctionCase
value: lower_case
- key: readability-identifier-naming.MemberConstantCase
value: CamelCase
value: CamelCase
- key: readability-identifier-naming.StaticConstantCase
value: lower_case
value: lower_case
- key: readability-function-cognitive-complexity.Threshold
value: 10
- key: readability-function-size.ParameterThreshold
value: 4
- key: misc-include-cleaner.IgnoreHeaders
value: utility;cstddef;geode/.*_export\.h;geode/.*/common\.h;geode/basic/types\.h;geode/basic/assert\.h;


value: utility;cstddef;geode/.*_export\.h;geode/.*/common\.h;geode/basic/types\.h;geode/basic/assert\.h;
37 changes: 37 additions & 0 deletions include/geode/model/helpers/compute_unique_vertices.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2019 - 2026 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

#pragma once
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: avoid 'pragma once' directive; use include guards instead [portability-avoid-pragma-once]

#pragma once
^


#include <geode/model/common.hpp>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header common.hpp is not used directly [misc-include-cleaner]

Suggested change

namespace geode
{
} // namespace geode

namespace geode
{
template < typename Model >
void compute_model_unique_vertices(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void compute_model_unique_vertices(
void compute_model_unique_vertices_using_colocalisation(

Maybe add some info on how they will be computed?

const Model& model, typename Model::Builder& builder );
} // namespace geode
2 changes: 2 additions & 0 deletions src/geode/model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ add_geode_library(
"helpers/component_mesh_polyhedra.cpp"
"helpers/component_mesh_vertices.cpp"
"helpers/component_mensurations.cpp"
"helpers/compute_unique_vertices.cpp"
"helpers/convert_brep_section.cpp"
"helpers/convert_model_meshes.cpp"
"helpers/convert_to_mesh.cpp"
Expand Down Expand Up @@ -108,6 +109,7 @@ add_geode_library(
"helpers/component_mesh_polyhedra.hpp"
"helpers/component_mesh_vertices.hpp"
"helpers/component_mensurations.hpp"
"helpers/compute_unique_vertices.hpp"
"helpers/convert_brep_section.hpp"
"helpers/convert_model_meshes.hpp"
"helpers/convert_to_mesh.hpp"
Expand Down
280 changes: 280 additions & 0 deletions src/geode/model/helpers/compute_unique_vertices.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
/*
* Copyright (c) 2019 - 2026 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

#include <geode/model/helpers/compute_unique_vertices.hpp>

#include <geode/geometry/nn_search.hpp>

#include <geode/mesh/core/edged_curve.hpp>
#include <geode/mesh/core/point_set.hpp>
#include <geode/mesh/core/solid_mesh.hpp>
#include <geode/mesh/core/surface_mesh.hpp>

#include <geode/model/mixin/core/block.hpp>
#include <geode/model/mixin/core/corner.hpp>
#include <geode/model/mixin/core/line.hpp>
#include <geode/model/mixin/core/surface.hpp>
#include <geode/model/representation/builder/brep_builder.hpp>
#include <geode/model/representation/builder/section_builder.hpp>
#include <geode/model/representation/core/brep.hpp>
#include <geode/model/representation/core/section.hpp>

namespace
{
template < typename Model >
std::vector< geode::Point< Model::dim > > get_all_points_base(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::vector" is directly included [misc-include-cleaner]

src/geode/model/helpers/compute_unique_vertices.cpp:40:

+ #include <vector>

const Model& model )
{
std::vector< geode::Point< Model::dim > > points;
for( const auto& corner : model.corners() )
{
for( const auto v : geode::Range{ corner.mesh().nb_vertices() } )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "geode::Range" is directly included [misc-include-cleaner]

src/geode/model/helpers/compute_unique_vertices.cpp:23:

- #include <geode/model/helpers/compute_unique_vertices.hpp>
+ #include "geode/basic/range.hpp"
+ #include <geode/model/helpers/compute_unique_vertices.hpp>

{
points.emplace_back( corner.mesh().point( v ) );
}
}
for( const auto& line : model.lines() )
{
for( const auto v : geode::Range{ line.mesh().nb_vertices() } )
{
points.emplace_back( line.mesh().point( v ) );
}
}
for( const auto& surface : model.surfaces() )
{
for( const auto v : geode::Range{ surface.mesh().nb_vertices() } )
{
points.emplace_back( surface.mesh().point( v ) );
}
}
return points;
}

std::vector< geode::Point2D > get_all_points( const geode::Section& model )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::vector" is directly included [misc-include-cleaner]

    std::vector< geode::Point2D > get_all_points( const geode::Section& model )
         ^

{
return get_all_points_base< geode::Section >( model );
}

std::vector< geode::Point3D > get_all_points( const geode::BRep& model )
{
auto points = get_all_points_base< geode::BRep >( model );
for( const auto& block : model.blocks() )
{
for( const auto v : geode::Range{ block.mesh().nb_vertices() } )
{
points.emplace_back( block.mesh().point( v ) );
}
}
return points;
}

template < typename Model >
const geode::Point< Model::dim >& get_point_base(
const Model& model, const geode::ComponentMeshVertex& cmv )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "geode::ComponentMeshVertex" is directly included [misc-include-cleaner]

src/geode/model/helpers/compute_unique_vertices.cpp:23:

- #include <geode/model/helpers/compute_unique_vertices.hpp>
+ #include "geode/model/mixin/core/vertex_identifier.hpp"
+ #include <geode/model/helpers/compute_unique_vertices.hpp>

{
if( cmv.component_id.type()
== geode::Surface< Model::dim >::component_type_static() )
{
const auto& surface = model.surface( cmv.component_id.id() );
return surface.mesh().point( cmv.vertex );
}
if( cmv.component_id.type()
== geode::Line< Model::dim >::component_type_static() )
{
const auto& line = model.line( cmv.component_id.id() );
return line.mesh().point( cmv.vertex );
}
if( cmv.component_id.type()
== geode::Corner< Model::dim >::component_type_static() )
{
const auto& corner = model.corner( cmv.component_id.id() );
return corner.mesh().point( cmv.vertex );
}
throw geode::OpenGeodeException{
"[compute_unique_vertices::get_point] Unknown component type: ",
cmv.component_id.string()
};
const auto& corner = model.corner( cmv.component_id.id() );
return corner.mesh().point( cmv.vertex );
}

const geode::Point2D& get_point(
const geode::Section& model, const geode::ComponentMeshVertex& cmv )
{
return get_point_base< geode::Section >( model, cmv );
}

const geode::Point3D& get_point(
const geode::BRep& model, const geode::ComponentMeshVertex& cmv )
{
if( cmv.component_id.type()
== geode::Block< 3 >::component_type_static() )
{
const auto& block = model.block( cmv.component_id.id() );
return block.mesh().point( cmv.vertex );
}
return get_point_base< geode::BRep >( model, cmv );
}

template < typename Model >
void set_unique_vertices_base( const Model& model,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'set_unique_vertices_base' has cognitive complexity of 18 (threshold 10) [readability-function-cognitive-complexity]

    void set_unique_vertices_base( const Model& model,
         ^
Additional context

src/geode/model/helpers/compute_unique_vertices.cpp:144: +1, including nesting penalty of 0, nesting level increased to 1

        for( const auto& corner : model.corners() )
        ^

src/geode/model/helpers/compute_unique_vertices.cpp:146: +2, including nesting penalty of 1, nesting level increased to 2

            for( const auto v : geode::Range{ corner.mesh().nb_vertices() } )
            ^

src/geode/model/helpers/compute_unique_vertices.cpp:149: +3, including nesting penalty of 2, nesting level increased to 3

                if( model.unique_vertex( { corner.component_id(), v } )
                ^

src/geode/model/helpers/compute_unique_vertices.cpp:161: +1, including nesting penalty of 0, nesting level increased to 1

        for( const auto& line : model.lines() )
        ^

src/geode/model/helpers/compute_unique_vertices.cpp:163: +2, including nesting penalty of 1, nesting level increased to 2

            for( const auto v : geode::Range{ line.mesh().nb_vertices() } )
            ^

src/geode/model/helpers/compute_unique_vertices.cpp:166: +3, including nesting penalty of 2, nesting level increased to 3

                if( model.unique_vertex( cmv ) != geode::NO_ID )
                ^

src/geode/model/helpers/compute_unique_vertices.cpp:177: +1, including nesting penalty of 0, nesting level increased to 1

        for( const auto& surface : model.surfaces() )
        ^

src/geode/model/helpers/compute_unique_vertices.cpp:179: +2, including nesting penalty of 1, nesting level increased to 2

            for( const auto v : geode::Range{ surface.mesh().nb_vertices() } )
            ^

src/geode/model/helpers/compute_unique_vertices.cpp:182: +3, including nesting penalty of 2, nesting level increased to 3

                if( model.unique_vertex( cmv ) != geode::NO_ID )
                ^

typename Model::Builder& builder,
absl::Span< const geode::index_t > initial_uv_correspondance,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "absl::Span" is directly included [misc-include-cleaner]

src/geode/model/helpers/compute_unique_vertices.cpp:23:

- #include <geode/model/helpers/compute_unique_vertices.hpp>
+ #include <absl/types/span.h>
+ #include <geode/model/helpers/compute_unique_vertices.hpp>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "geode::index_t" is directly included [misc-include-cleaner]

src/geode/model/helpers/compute_unique_vertices.cpp:23:

- #include <geode/model/helpers/compute_unique_vertices.hpp>
+ #include "geode/basic/types.hpp"
+ #include <geode/model/helpers/compute_unique_vertices.hpp>

const geode::NNSearch< Model::dim >& unique_nns )
{
for( const auto& corner : model.corners() )
{
for( const auto v : geode::Range{ corner.mesh().nb_vertices() } )
{
geode::ComponentMeshVertex cmv{ corner.component_id(), v };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'cmv' of type 'geode::ComponentMeshVertex' can be declared 'const' [misc-const-correctness]

Suggested change
geode::ComponentMeshVertex cmv{ corner.component_id(), v };
geode::ComponentMeshVertex const cmv{ corner.component_id(), v };

if( model.unique_vertex( { corner.component_id(), v } )
!= geode::NO_ID )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "geode::NO_ID" is directly included [misc-include-cleaner]

                    != geode::NO_ID )
                              ^

{
continue;
}
const auto& point = corner.mesh().point( v );
const auto unique_vertex_id =
unique_nns.closest_neighbor( point );
builder.set_unique_vertex(
cmv, initial_uv_correspondance[unique_vertex_id] );
}
}
for( const auto& line : model.lines() )
{
for( const auto v : geode::Range{ line.mesh().nb_vertices() } )
{
geode::ComponentMeshVertex cmv{ line.component_id(), v };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'cmv' of type 'geode::ComponentMeshVertex' can be declared 'const' [misc-const-correctness]

Suggested change
geode::ComponentMeshVertex cmv{ line.component_id(), v };
geode::ComponentMeshVertex const cmv{ line.component_id(), v };

if( model.unique_vertex( cmv ) != geode::NO_ID )
{
continue;
}
const auto& point = line.mesh().point( v );
const auto unique_vertex_id =
unique_nns.closest_neighbor( point );
builder.set_unique_vertex(
cmv, initial_uv_correspondance[unique_vertex_id] );
}
}
for( const auto& surface : model.surfaces() )
{
for( const auto v : geode::Range{ surface.mesh().nb_vertices() } )
{
geode::ComponentMeshVertex cmv{ surface.component_id(), v };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'cmv' of type 'geode::ComponentMeshVertex' can be declared 'const' [misc-const-correctness]

Suggested change
geode::ComponentMeshVertex cmv{ surface.component_id(), v };
geode::ComponentMeshVertex const cmv{ surface.component_id(), v };

if( model.unique_vertex( cmv ) != geode::NO_ID )
{
continue;
}
const auto& point = surface.mesh().point( v );
const auto unique_vertex_id =
unique_nns.closest_neighbor( point );
builder.set_unique_vertex(
cmv, initial_uv_correspondance[unique_vertex_id] );
}
}
}

void set_unique_vertices( const geode::Section& model,
geode::SectionBuilder& builder,
absl::Span< const geode::index_t > initial_uv_correspondance,
const geode::NNSearch2D& unique_nns )
{
set_unique_vertices_base(
model, builder, initial_uv_correspondance, unique_nns );
}

void set_unique_vertices( const geode::BRep& model,
geode::BRepBuilder& builder,
absl::Span< const geode::index_t > initial_uv_correspondance,
const geode::NNSearch3D& unique_nns )
{
set_unique_vertices_base(
model, builder, initial_uv_correspondance, unique_nns );
for( const auto& block : model.blocks() )
{
for( const auto v : geode::Range{ block.mesh().nb_vertices() } )
{
geode::ComponentMeshVertex cmv{ block.component_id(), v };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'cmv' of type 'geode::ComponentMeshVertex' can be declared 'const' [misc-const-correctness]

Suggested change
geode::ComponentMeshVertex cmv{ block.component_id(), v };
geode::ComponentMeshVertex const cmv{ block.component_id(), v };

if( model.unique_vertex( cmv ) != geode::NO_ID )
{
continue;
}
const auto& point = block.mesh().point( v );
const auto unique_vertex_id =
unique_nns.closest_neighbor( point );
builder.set_unique_vertex(
cmv, initial_uv_correspondance[unique_vertex_id] );
}
}
}

template < typename Model >
std::vector< geode::index_t > compute_initial_uv_correspondance(
const Model& model, const geode::NNSearch< Model::dim >& unique_nns )
{
std::vector< geode::index_t > initial_uv_correspondance(
unique_nns.nb_points(), geode::NO_ID );
for( const auto uv : geode::Range{ model.nb_unique_vertices() } )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable name 'uv' is too short, expected at least 3 characters [readability-identifier-length]

        for( const auto uv : geode::Range{ model.nb_unique_vertices() } )
                        ^

{
const auto& cmv = model.component_mesh_vertices( uv ).front();
const auto& point = get_point( model, cmv );
initial_uv_correspondance[unique_nns.closest_neighbor( point )] =
uv;
}
geode::index_t new_uv = model.nb_unique_vertices();
for( auto& uv : initial_uv_correspondance )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable name 'uv' is too short, expected at least 3 characters [readability-identifier-length]

        for( auto& uv : initial_uv_correspondance )
                   ^

{
if( uv == geode::NO_ID )
{
uv = new_uv++;
}
}
return initial_uv_correspondance;
}

} // namespace

namespace geode
{
template < typename Model >
void compute_model_unique_vertices(
const Model& model, typename Model::Builder& builder )
{
auto all_vertices = get_all_points( model );
NNSearch< Model::dim > nns{ all_vertices };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'nns' of type 'NNSearchBRep::dim' can be declared 'const' [misc-const-correctness]

Suggested change
NNSearch< Model::dim > nns{ all_vertices };
NNSearch< Model::dim > const nns{ all_vertices };

const auto colocated_info =
nns.colocated_index_mapping( GLOBAL_EPSILON );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "geode::GLOBAL_EPSILON" is directly included [misc-include-cleaner]

            nns.colocated_index_mapping( GLOBAL_EPSILON );
                                         ^

const auto nb_initial_unique_vertices = model.nb_unique_vertices();
NNSearch< Model::dim > unique_nns{ colocated_info.unique_points };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'unique_nns' of type 'NNSearchBRep::dim' can be declared 'const' [misc-const-correctness]

Suggested change
NNSearch< Model::dim > unique_nns{ colocated_info.unique_points };
NNSearch< Model::dim > const unique_nns{ colocated_info.unique_points };

const auto initial_uv_correspondance =
compute_initial_uv_correspondance( model, unique_nns );
builder.create_unique_vertices(
colocated_info.nb_unique_points() - nb_initial_unique_vertices );
set_unique_vertices(
model, builder, initial_uv_correspondance, unique_nns );
}

template void opengeode_model_api compute_model_unique_vertices(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "opengeode_model_api" is directly included [misc-include-cleaner]

src/geode/model/helpers/compute_unique_vertices.cpp:23:

- #include <geode/model/helpers/compute_unique_vertices.hpp>
+ #include "geode/model/opengeode_model_export.hpp"
+ #include <geode/model/helpers/compute_unique_vertices.hpp>

const BRep&, BRepBuilder& );
template void opengeode_model_api compute_model_unique_vertices(
const Section&, SectionBuilder& );
} // namespace geode
2 changes: 2 additions & 0 deletions src/geode/model/helpers/detail/surface_mesh_validity_fix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#include <geode/geometry/point.hpp>

#include <geode/mesh/builder/surface_mesh_builder.hpp>
#include <geode/mesh/core/surface_mesh.hpp>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header surface_mesh_builder.hpp is not used directly [misc-include-cleaner]

Suggested change
#include <geode/mesh/core/surface_mesh.hpp>
#include <geode/mesh/core/surface_mesh.hpp>

#include <geode/mesh/helpers/detail/surface_mesh_validity_fix.hpp>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header surface_mesh.hpp is not used directly [misc-include-cleaner]

Suggested change
#include <geode/mesh/helpers/detail/surface_mesh_validity_fix.hpp>
#include <geode/mesh/helpers/detail/surface_mesh_validity_fix.hpp>


#include <geode/model/mixin/core/surface.hpp>
Expand Down
Binary file not shown.
Loading