|
47 | 47 | #include <geode/model/representation/builder/detail/copy.hpp> |
48 | 48 | #include <geode/model/representation/core/brep.hpp> |
49 | 49 |
|
| 50 | +namespace |
| 51 | +{ |
| 52 | + void remove_component_meshes_in_mapping( const geode::BRep& brep, |
| 53 | + geode::BRepBuilder& builder, |
| 54 | + const geode::ModelCopyMapping& mapping ) |
| 55 | + { |
| 56 | + for( const auto& in2out : |
| 57 | + mapping.at( geode::Corner3D::component_type_static() ) |
| 58 | + .in2out_map() ) |
| 59 | + { |
| 60 | + builder.update_corner_mesh( |
| 61 | + brep.corner( in2out.first ), geode::PointSet3D::create() ); |
| 62 | + } |
| 63 | + for( const auto& in2out : |
| 64 | + mapping.at( geode::Line3D::component_type_static() ).in2out_map() ) |
| 65 | + { |
| 66 | + builder.update_line_mesh( |
| 67 | + brep.line( in2out.first ), geode::EdgedCurve3D::create() ); |
| 68 | + } |
| 69 | + for( const auto& in2out : |
| 70 | + mapping.at( geode::Surface3D::component_type_static() ) |
| 71 | + .in2out_map() ) |
| 72 | + { |
| 73 | + builder.update_surface_mesh( |
| 74 | + brep.surface( in2out.first ), geode::SurfaceMesh3D::create() ); |
| 75 | + } |
| 76 | + for( const auto& in2out : |
| 77 | + mapping.at( geode::Block3D::component_type_static() ).in2out_map() ) |
| 78 | + { |
| 79 | + builder.update_block_mesh( |
| 80 | + brep.block( in2out.first ), geode::SolidMesh3D::create() ); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + template < typename Mesh > |
| 85 | + absl::FixedArray< geode::index_t > save_mesh_unique_vertices( |
| 86 | + const geode::BRep& model, |
| 87 | + const Mesh& mesh, |
| 88 | + const geode::ComponentID& component_id ) |
| 89 | + { |
| 90 | + const auto nb_vertices = mesh.nb_vertices(); |
| 91 | + absl::FixedArray< geode::index_t > unique_vertices( nb_vertices ); |
| 92 | + for( const auto v : geode::Range{ nb_vertices } ) |
| 93 | + { |
| 94 | + unique_vertices[v] = model.unique_vertex( { component_id, v } ); |
| 95 | + } |
| 96 | + return unique_vertices; |
| 97 | + } |
| 98 | + |
| 99 | + void set_mesh_unique_vertices( geode::BRepBuilder& builder, |
| 100 | + absl::Span< const geode::index_t > unique_vertices, |
| 101 | + const geode::ComponentID& component_id, |
| 102 | + geode::index_t first_new_unique_vertex ) |
| 103 | + { |
| 104 | + for( const auto v : geode::Indices{ unique_vertices } ) |
| 105 | + { |
| 106 | + if( unique_vertices[v] != geode::NO_ID ) |
| 107 | + { |
| 108 | + builder.set_unique_vertex( { component_id, v }, |
| 109 | + first_new_unique_vertex + unique_vertices[v] ); |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | +} // namespace |
| 114 | + |
50 | 115 | namespace geode |
51 | 116 | { |
52 | 117 | BRepBuilder::BRepBuilder( BRep& brep ) |
@@ -85,39 +150,62 @@ namespace geode |
85 | 150 | BRep&& other, const ModelCopyMapping& mapping ) |
86 | 151 | { |
87 | 152 | BRepBuilder other_builder{ other }; |
| 153 | + remove_component_meshes_in_mapping( brep_, *this, mapping ); |
| 154 | + this->delete_isolated_vertices(); |
| 155 | + const auto first_new_unique_vertex_id = |
| 156 | + create_unique_vertices( other.nb_unique_vertices() ); |
88 | 157 | for( const auto& in2out : |
89 | 158 | mapping.at( Corner3D::component_type_static() ).in2out_map() ) |
90 | 159 | { |
| 160 | + const auto corner_unique_vertices = save_mesh_unique_vertices( |
| 161 | + other, other.corner( in2out.second ).mesh(), |
| 162 | + other.corner( in2out.second ).component_id() ); |
91 | 163 | this->update_corner_mesh( brep_.corner( in2out.first ), |
92 | 164 | other_builder.steal_corner_mesh( in2out.second ) ); |
93 | 165 | this->corner_mesh_builder( in2out.first )->set_id( in2out.first ); |
| 166 | + set_mesh_unique_vertices( *this, corner_unique_vertices, |
| 167 | + brep_.corner( in2out.first ).component_id(), |
| 168 | + first_new_unique_vertex_id ); |
94 | 169 | } |
95 | 170 | for( const auto& in2out : |
96 | 171 | mapping.at( Line3D::component_type_static() ).in2out_map() ) |
97 | 172 | { |
| 173 | + const auto line_unique_vertices = save_mesh_unique_vertices( other, |
| 174 | + other.line( in2out.second ).mesh(), |
| 175 | + other.line( in2out.second ).component_id() ); |
98 | 176 | this->update_line_mesh( brep_.line( in2out.first ), |
99 | 177 | other_builder.steal_line_mesh( in2out.second ) ); |
100 | 178 | this->line_mesh_builder( in2out.first )->set_id( in2out.first ); |
| 179 | + set_mesh_unique_vertices( *this, line_unique_vertices, |
| 180 | + brep_.line( in2out.first ).component_id(), |
| 181 | + first_new_unique_vertex_id ); |
101 | 182 | } |
102 | 183 | for( const auto& in2out : |
103 | 184 | mapping.at( Surface3D::component_type_static() ).in2out_map() ) |
104 | 185 | { |
| 186 | + const auto surface_unique_vertices = save_mesh_unique_vertices( |
| 187 | + other, other.surface( in2out.second ).mesh(), |
| 188 | + other.surface( in2out.second ).component_id() ); |
105 | 189 | this->update_surface_mesh( brep_.surface( in2out.first ), |
106 | 190 | other_builder.steal_surface_mesh( in2out.second ) ); |
107 | 191 | this->surface_mesh_builder( in2out.first )->set_id( in2out.first ); |
| 192 | + set_mesh_unique_vertices( *this, surface_unique_vertices, |
| 193 | + brep_.surface( in2out.first ).component_id(), |
| 194 | + first_new_unique_vertex_id ); |
108 | 195 | } |
109 | 196 | for( const auto& in2out : |
110 | 197 | mapping.at( Block3D::component_type_static() ).in2out_map() ) |
111 | 198 | { |
| 199 | + const auto block_unique_vertices = save_mesh_unique_vertices( other, |
| 200 | + other.block( in2out.second ).mesh(), |
| 201 | + other.block( in2out.second ).component_id() ); |
112 | 202 | this->update_block_mesh( brep_.block( in2out.first ), |
113 | 203 | other_builder.steal_block_mesh( in2out.second ) ); |
114 | 204 | this->block_mesh_builder( in2out.first )->set_id( in2out.first ); |
| 205 | + set_mesh_unique_vertices( *this, block_unique_vertices, |
| 206 | + brep_.block( in2out.first ).component_id(), |
| 207 | + first_new_unique_vertex_id ); |
115 | 208 | } |
116 | | - this->delete_isolated_vertices(); |
117 | | - const auto first_new_unique_vertex_id = |
118 | | - create_unique_vertices( other.nb_unique_vertices() ); |
119 | | - detail::copy_vertex_identifier_components( |
120 | | - other, *this, first_new_unique_vertex_id, mapping ); |
121 | 209 | } |
122 | 210 |
|
123 | 211 | ModelCopyMapping BRepBuilder::copy_components( const BRep& brep ) |
|
0 commit comments