Commit 060d0851 authored by Kirill Terekhov's avatar Kirill Terekhov

fixes

parent 64fd9a94
Pipeline #167 failed with stages
in 10 minutes and 2 seconds
...@@ -1086,6 +1086,7 @@ namespace INMOST ...@@ -1086,6 +1086,7 @@ namespace INMOST
Mesh & m = *e.GetMeshLink(); Mesh & m = *e.GetMeshLink();
ElementArray<Cell> cells = e.getCells(); ElementArray<Cell> cells = e.getCells();
Element::adj_type & faces = m.HighConn(e.GetHandle()); Element::adj_type & faces = m.HighConn(e.GetHandle());
std::cout << "number of faces " << faces.size() << std::endl;
if( del_protect ) if( del_protect )
{ {
if( e.GetMarker(del_protect) ) if( e.GetMarker(del_protect) )
...@@ -1124,67 +1125,82 @@ namespace INMOST ...@@ -1124,67 +1125,82 @@ namespace INMOST
HandleType nn[2] = {e.getBeg().GetHandle(),e.getEnd().GetHandle()}; HandleType nn[2] = {e.getBeg().GetHandle(),e.getEnd().GetHandle()};
//Collect all cells, faces and edges //Collect all cells, faces and edges
MarkerType unique = m.CreateMarker(); MarkerType unique = m.CreateMarker();
std::cout << "collapse edge " << GetHandleID(e.GetHandle()) << " " << GetHandleID(nn[0]) << "<->" << GetHandleID(nn[1]) << std::endl;
for(unsigned k = 0; k < 2; ++k) for(unsigned k = 0; k < 2; ++k)
{ {
std::cout << "node " << GetHandleID(nn[k]) << std::endl;
Element::adj_type & cells = m.LowConn(nn[k]); Element::adj_type & cells = m.LowConn(nn[k]);
for(unsigned l = 0; l < cells.size(); ++l) if( !m.GetMarker(cells[l],unique) ) for(unsigned l = 0; l < cells.size(); ++l)
{ {
all_cells.push_back(cells[l]); if( !m.GetMarker(cells[l],unique) )
m.SetMarker(cells[l],unique); {
all_cells.push_back(cells[l]);
m.SetMarker(cells[l],unique);
}
//change all connections of cells from old nodes to new node //change all connections of cells from old nodes to new node
Element::adj_type & cell_nodes = m.HighConn(cells[l]); Element::adj_type & cell_nodes = m.HighConn(cells[l]);
for(unsigned j = 0; j < cell_nodes.size(); ++j) for(unsigned j = 0; j < cell_nodes.size(); ++j)
{ {
std::cout << " cell " << GetHandleID(cells[l]) << " node " << GetHandleID(cell_nodes[j]) << std::endl;
if( cell_nodes[j] == nn[k] ) if( cell_nodes[j] == nn[k] )
{
std::cout << "replace node " << GetHandleID(nn[k]) << " in cell " << GetHandleID(cells[l]) << " with " << n.LocalID() << std::endl;
cell_nodes[j] = n.GetHandle(); cell_nodes[j] = n.GetHandle();
}
} }
} }
cells.clear();
Element::adj_type & edges = m.HighConn(nn[k]); Element::adj_type & edges = m.HighConn(nn[k]);
for(unsigned l = 0; l < edges.size(); ++l) if( !m.GetMarker(edges[l],unique) ) for(unsigned l = 0; l < edges.size(); ++l) if( edges[l] != e.GetHandle() )
{ {
all_edges.push_back(edges[l]); if( !m.GetMarker(edges[l],unique) )
m.SetMarker(edges[l],unique); {
all_edges.push_back(edges[l]);
m.SetMarker(edges[l],unique);
}
//Change all connections of edges from old nodes to new node //Change all connections of edges from old nodes to new node
Element::adj_type & nodes = m.LowConn(edges[l]); Element::adj_type & nodes = m.LowConn(edges[l]);
assert( !((nodes[0] == n1 || nodes[0] == n2) && std::cout << "visit edge " << GetHandleID(edges[l]) << std::endl;
(nodes[1] == n1 || nodes[1] == n2)));
if( nodes[0] == nn[k] ) if( nodes[0] == nn[k] )
{ {
std::cout << "(0) replace node " << GetHandleID(nn[k]) << " in edge " << GetHandleID(edges[l]) << std::endl;
nodes[0] = n.GetHandle(); nodes[0] = n.GetHandle();
n_edges.push_back(edges[l]); n_edges.push_back(edges[l]);
} }
if( nodes[1] == nn[k] ) if( nodes[1] == nn[k] )
{ {
std::cout << "(1) replace node " << GetHandleID(nn[k]) << " in edge " << GetHandleID(edges[l]) << std::endl;
nodes[1] = n.GetHandle(); nodes[1] = n.GetHandle();
n_edges.push_back(edges[l]); n_edges.push_back(edges[l]);
} }
Element::adj_type & edge_faces = m.HighConn(edges[l]); Element::adj_type & edge_faces = m.HighConn(edges[l]);
for(unsigned j = 0; j < edge_faces.size(); ++j) if( !m.GetMarker(edge_faces[l],unique) ) for(unsigned j = 0; j < edge_faces.size(); ++j) if( !m.GetMarker(edge_faces[j],unique) )
{ {
all_faces.push_back(edge_faces[j]); all_faces.push_back(edge_faces[j]);
m.SetMarker(edge_faces[j],unique); m.SetMarker(edge_faces[j],unique);
} }
} }
//delete node
cells.clear();
edges.clear(); edges.clear();
//delete node
std::cout << "before number of faces " << faces.size() << std::endl;
m.Delete(nn[k]); m.Delete(nn[k]);
std::cout << "after number of faces " << faces.size() << std::endl;
} }
m.RemMarkerArray(all_cells.data(),all_cells.size(),unique); m.RemMarkerArray(all_cells.data(),all_cells.size(),unique);
m.RemMarkerArray(all_faces.data(),all_faces.size(),unique); m.RemMarkerArray(all_faces.data(),all_faces.size(),unique);
m.RemMarkerArray(all_edges.data(),all_edges.size(),unique); m.RemMarkerArray(all_edges.data(),all_edges.size(),unique);
m.ReleaseMarker(unique); m.ReleaseMarker(unique);
//erase links on edge
m.LowConn(e.GetHandle()).clear();
m.HighConn(e.GetHandle()).clear();
//Check faces to be deleted //Check faces to be deleted
//also should erase edge //also should erase edge
MarkerType del = m.CreateMarker(); MarkerType del = m.CreateMarker();
std::cout << "number of faces " << faces.size() << std::endl;
for(unsigned k = 0; k < faces.size(); ++k) for(unsigned k = 0; k < faces.size(); ++k)
{ {
std::cout << "check face " << GetHandleID(faces[k]) << std::endl;
//two edges will match, should replace them with one //two edges will match, should replace them with one
if( m.GetGeometricType(faces[k]) == Element::Tri ) if( m.GetGeometricType(faces[k]) == Element::Tri )
{ {
std::cout << "collapse triangle " << GetHandleID(faces[k]) << std::endl;
Element::adj_type & edges = m.LowConn(faces[k]); Element::adj_type & edges = m.LowConn(faces[k]);
for(unsigned l = 0; l < 3; ++l) for(unsigned l = 0; l < 3; ++l)
if( edges[l] == e.GetHandle() ) if( edges[l] == e.GetHandle() )
...@@ -1238,11 +1254,13 @@ namespace INMOST ...@@ -1238,11 +1254,13 @@ namespace INMOST
} }
else else
{ {
std::cout << "erase edge in face " << GetHandleID(faces[k]) << std::endl;
//remove link to edge //remove link to edge
Element::adj_type & face_edges = m.LowConn(faces[k]); Element::adj_type & face_edges = m.LowConn(faces[k]);
for(unsigned l = 0; l < face_edges.size(); ++l) for(unsigned l = 0; l < face_edges.size(); ++l)
if( face_edges[l] == e.GetHandle() ) if( face_edges[l] == e.GetHandle() )
{ {
std::cout << "edge erased at " << l << std::endl;
face_edges.erase(face_edges.begin()+l); face_edges.erase(face_edges.begin()+l);
break; break;
} }
...@@ -1254,6 +1272,7 @@ namespace INMOST ...@@ -1254,6 +1272,7 @@ namespace INMOST
{ {
if( m.GetGeometricType(cells.at(k)) == Element::Tet ) if( m.GetGeometricType(cells.at(k)) == Element::Tet )
{ {
std::cout << "collapse tetrahedron " << GetHandleID(cells.at(k)) << std::endl;
//there are 2 faces now that should become just one //there are 2 faces now that should become just one
Element::adj_type & cell_faces = m.LowConn(cells.at(k)); Element::adj_type & cell_faces = m.LowConn(cells.at(k));
assert(cell_faces.size() == 2); assert(cell_faces.size() == 2);
...@@ -1275,44 +1294,68 @@ namespace INMOST ...@@ -1275,44 +1294,68 @@ namespace INMOST
} }
else else
{ {
std::cout << "erase node in cell " << GetHandleID(cells.at(k)) << std::endl;
//there are two subsequent links to the same node //there are two subsequent links to the same node
Element::adj_type & cell_nodes = m.HighConn(cells.at(k)); Element::adj_type & cell_nodes = m.HighConn(cells.at(k));
int cnt = 0;
for(unsigned l = 0; l < cell_nodes.size(); ++l) for(unsigned l = 0; l < cell_nodes.size(); ++l)
if( cell_nodes[l] == n.GetHandle() ) if( cell_nodes[l] == n.GetHandle() ) cnt++;
{ if( cnt == 2 )
cell_nodes.erase(cell_nodes.begin()+l); {
break; for(unsigned l = 0; l < cell_nodes.size(); ++l)
} if( cell_nodes[l] == n.GetHandle() )
{
std::cout << "node erased at " << l << std::endl;
cell_nodes.erase(cell_nodes.begin()+l);
break;
}
}
else std::cout << "node encountered " << cnt << std::endl;
} }
} }
//delete marked elements //delete marked elements
//recompute geometry and types for the rest //recompute geometry and types for the rest
for(int k = 0; k < all_cells.size(); ++k) for(int k = 0; k < all_cells.size(); ++k)
if( m.GetMarker(all_cells[k],del) ) if( m.GetMarker(all_cells[k],del) )
{
std::cout << "delete cell " << GetHandleID(all_cells[k]) << std::endl;
m.Delete(all_cells[k]); m.Delete(all_cells[k]);
}
else else
{ {
std::cout << "recompute data for cell " << GetHandleID(all_cells[k]) << std::endl;
m.RecomputeGeometricData(all_cells[k]); m.RecomputeGeometricData(all_cells[k]);
m.ComputeGeometricType(all_cells[k]); m.ComputeGeometricType(all_cells[k]);
} }
for(int k = 0; k < all_faces.size(); ++k) for(int k = 0; k < all_faces.size(); ++k)
if( m.GetMarker(all_faces[k],del) ) if( m.GetMarker(all_faces[k],del) )
{
std::cout << "delete face " << GetHandleID(all_faces[k]) << std::endl;
m.Delete(all_faces[k]); m.Delete(all_faces[k]);
}
else else
{ {
std::cout << "recompute data for face " << GetHandleID(all_faces[k]) << std::endl;
m.RecomputeGeometricData(all_faces[k]); m.RecomputeGeometricData(all_faces[k]);
m.ComputeGeometricType(all_faces[k]); m.ComputeGeometricType(all_faces[k]);
} }
for(int k = 0; k < all_edges.size(); ++k) for(int k = 0; k < all_edges.size(); ++k)
if( m.GetMarker(all_edges[k],del) ) if( m.GetMarker(all_edges[k],del) )
{
std::cout << "delete edge " << GetHandleID(all_edges[k]) << std::endl;
m.Delete(all_edges[k]); m.Delete(all_edges[k]);
}
else else
{ {
std::cout << "recompute data for edge " << GetHandleID(all_edges[k]) << std::endl;
m.RecomputeGeometricData(all_edges[k]); m.RecomputeGeometricData(all_edges[k]);
m.ComputeGeometricType(all_edges[k]); m.ComputeGeometricType(all_edges[k]);
} }
m.ReleaseMarker(del); m.ReleaseMarker(del);
//erase links on edge
m.LowConn(e.GetHandle()).clear();
m.HighConn(e.GetHandle()).clear();
e.Delete(); e.Delete();
return n; return n;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment