Commit 929113d8 authored by Kirill Terekhov's avatar Kirill Terekhov

Fix for slice_func

parent fa049b29
......@@ -21,7 +21,8 @@ double func(double x, double y, double z, int n)
return y-(10*x*x*x*x-8*x*x*x-5*x*x+0.2+4*x)+z*z*z;
else if( n == 5 )
{
double Lx = 0.2, Rx = 0.4, Ly = 0.1, Ry = 0.3;
//double Lx = 0.2, Rx = 0.4, Ly = 0.1, Ry = 0.3;
double Lx = 0., Rx = 2, Ly = 0.0, Ry = 4.5;
if (x > Rx){
if (y > Ry) return -sqrt( (x-Rx)*(x-Rx) + (y-Ry)*(y-Ry) );
else return -(x-Rx);
......@@ -107,8 +108,8 @@ int main(int argc, char ** argv)
Mesh m;
m.Load(argv[1]);
m.SetTopologyCheck(NEED_TEST_CLOSURE|PROHIBIT_MULTILINE|PROHIBIT_MULTIPOLYGON|GRID_CONFORMITY|DEGENERATE_EDGE|DEGENERATE_FACE|DEGENERATE_CELL | FACE_EDGES_ORDER);
//m.RemTopologyCheck(THROW_EXCEPTION);
m.SetTopologyCheck(NEED_TEST_CLOSURE|PROHIBIT_MULTILINE|PROHIBIT_MULTIPOLYGON|GRID_CONFORMITY|DEGENERATE_EDGE|DEGENERATE_FACE|DEGENERATE_CELL | FACE_EDGES_ORDER | MARK_ON_ERROR);
m.RemTopologyCheck(THROW_EXCEPTION);
TagInteger material = m.CreateTag("MATERIAL",DATA_INTEGER,CELL|FACE|EDGE|NODE,NONE,1);
Tag sliced = m.CreateTag("SLICED",DATA_BULK,FACE|EDGE|NODE,FACE|EDGE|NODE,1);
......@@ -238,6 +239,7 @@ int main(int argc, char ** argv)
nslice = 0;
MarkerType unique = m.CreateMarker();
for(Mesh::iteratorFace it = m.BeginFace(); it != m.EndFace(); ++it) if( !it->GetMarker(mrk) )
{
ElementArray<Node> nodes = it->getNodes(slice); //those nodes should be ordered so that each pair forms an edge
......@@ -379,11 +381,15 @@ int main(int argc, char ** argv)
{
edge_nodes[0] = n2;
edge_nodes[1] = cutnodes[i1];
Edge e = m.CreateEdge(edge_nodes).first;
material[e] = 2; //on slice
e.Bulk(sliced) = 1;
e.SetMarker(slice);
split_edges.push_back(e);
std::pair<Edge,bool> en = m.CreateEdge(edge_nodes);
//if( en.second )
{
Edge e = en.first;
material[e] = 2; //on slice
e.Bulk(sliced) = 1;
e.SetMarker(slice);
split_edges.push_back(e);
}
}
}
else if( s1 )
......@@ -393,27 +399,47 @@ int main(int argc, char ** argv)
{
edge_nodes[0] = n1;
edge_nodes[1] = cutnodes[i2];
Edge e = m.CreateEdge(edge_nodes).first;
material[e] = 2; //on slice
e.Bulk(sliced) = 1;
e.SetMarker(slice);
split_edges.push_back(e);
std::pair<Edge,bool> en = m.CreateEdge(edge_nodes);
//if( en.second )
{
Edge e = en.first;
material[e] = 2; //on slice
e.Bulk(sliced) = 1;
e.SetMarker(slice);
split_edges.push_back(e);
}
}
}
else if( cutnodes[i1].isValid() && cutnodes[i2].isValid() )
{
edge_nodes[0] = cutnodes[i1];
edge_nodes[1] = cutnodes[i2];
Edge e = m.CreateEdge(edge_nodes).first;
material[e] = 2; //on slice
e.Bulk(sliced) = 1;
e.SetMarker(slice);
split_edges.push_back(e);
std::pair<Edge,bool> en = m.CreateEdge(edge_nodes);
//if( en.second )
{
Edge e = en.first;
material[e] = 2; //on slice
e.Bulk(sliced) = 1;
e.SetMarker(slice);
split_edges.push_back(e);
}
}
}
//split face with multiple edges
if( !split_edges.empty() )
{
int k = 0;
for(int q = 0; q < split_edges.size(); ++q)
{
if( !split_edges[q].GetMarker(unique) )
{
split_edges[q].SetMarker(unique);
split_edges[k++] = split_edges[q];
}
}
split_edges.RemMarker(unique);
split_edges.resize(k);
//std::cout << "Split edges " << split_edges.size() << std::endl;
//for(int q = 0; q < (int)split_edges.size(); ++q)
// std::cout << split_edges[q].getBeg().LocalID() << "<->" << split_edges[q].getEnd().LocalID() << std::endl;
......@@ -438,7 +464,7 @@ int main(int argc, char ** argv)
}
//else std::cout << "Only one adjacent slice node, face " << it->LocalID() << std::endl;
}
m.ReleaseMarker(unique);
nmark = 0;
......
......@@ -1224,6 +1224,9 @@ namespace INMOST
ElementArray<Face> Face::SplitFace(Face face, const ElementArray<Edge> & edges, MarkerType del_protect)
{
//bool did_restart = false;
//bool report = false;
//restart_algorithm:
Mesh * m = face->GetMeshLink();
ElementArray<Edge> loop(m);
ElementArray<Face> ret(m);
......@@ -1231,10 +1234,20 @@ namespace INMOST
if( edges.empty() || face->GetMarker(del_protect) ) return ret;
MarkerType hm = m->HideMarker();
dynarray<HandleType,2> cells;
//if( report ) std::cout << "Marker for hidden elements: " << hm << std::endl;
adj_type & hc = m->HighConn(face->GetHandle());
for(adj_type::size_type it = 0; it < hc.size(); ++it) if( !m->GetMarker(hc[it],hm) )
cells.push_back(hc[it]);
//if( report ) std::cout << "Adjacent cells for face: ";
for(adj_type::size_type it = 0; it < hc.size(); ++it)
{
if( !m->GetMarker(hc[it],hm) )
{
cells.push_back(hc[it]);
//if( report ) std::cout << GetHandleID(hc[it]) << " ";
}
}
//if( report ) std::cout << std::endl;
//assert(cells.size() == 2);
......@@ -1243,15 +1256,24 @@ namespace INMOST
int ninner = 0;
adj_type & lc = m->LowConn(face->GetHandle());
//if( report ) std::cout << "Edges for face: ";
for(adj_type::size_type it = 0; it < lc.size(); ++it) if( !m->GetMarker(lc[it],hm) )
{
m->SetMarker(lc[it],outer);
//if( report ) std::cout << GetHandleID(lc[it]) << " ";
}
//if( report ) std::cout << std::endl;
//if( report ) std::cout << "Split edges: ";
for(ElementArray<Edge>::size_type it = 0; it < edges.size(); ++it)
if( !m->GetMarker(edges[it].GetHandle(),outer) )
{
temp.push_back(edges[it].GetHandle());
//if( report ) std::cout << GetHandleID(edges[it].GetHandle()) << " ";
ninner++;
}
//if( report ) std::cout << std::endl;
for(adj_type::size_type it = 0; it < lc.size(); ++it) if( !m->GetMarker(lc[it],hm) )
{
......@@ -1267,6 +1289,43 @@ namespace INMOST
return ret;
}
/*
if( !did_restart )
{
incident_matrix<Edge> mat(m,temp.begin(),temp.end(),ninner);
do
{
mat.find_shortest_loop(loop);
if (!loop.empty())
{
if( loop.size() > 2 )
{
//ret.push_back(m->CreateFace(loop).first);
//adj_type & hc = m->HighConn(ret.back()->GetHandle());
//hc.replace(hc.begin(),hc.end(),cells.begin(),cells.end());
}
else report = true;
}
else break;
} while(true);
if(report )//!mat.all_visited())
{
mat.print_matrix();
incident_matrix<Edge> mat(m,temp.begin(),temp.end(),ninner,GridCoords(),true);
do
{
mat.find_shortest_loop(loop);
if( loop.empty() ) break;
} while( true );
did_restart = true;
goto restart_algorithm;
}
}
*/
if( !face->Hide() )
{
for(dynarray<HandleType,2>::size_type k = 0; k < cells.size(); k++)
......@@ -1287,20 +1346,22 @@ namespace INMOST
incident_matrix<Edge> mat(m,temp.begin(),temp.end(),ninner);
do
{
mat.find_shortest_loop(loop);
if (!loop.empty())
{
ret.push_back(m->CreateFace(loop).first);
adj_type & hc = m->HighConn(ret.back()->GetHandle());
hc.replace(hc.begin(),hc.end(),cells.begin(),cells.end());
if( loop.size() > 2 )
{
ret.push_back(m->CreateFace(loop).first);
adj_type & hc = m->HighConn(ret.back()->GetHandle());
hc.replace(hc.begin(),hc.end(),cells.begin(),cells.end());
}
}
else break;
} while(true);
for(dynarray<HandleType,2>::size_type it = 0; it < cells.size(); ++it)
......@@ -1379,17 +1440,24 @@ namespace INMOST
incident_matrix<Face> mat(m,temp.begin(),temp.end(),ninner);
//mat.print_matrix();
cell->Delete();
bool report = false;
do
{
mat.find_shortest_loop(loop);
if (!loop.empty()) ret.push_back(m->CreateCell(loop).first);
if (!loop.empty() )
{
if( loop.size() > 3 )
ret.push_back(m->CreateCell(loop).first);
else
report = true;
}
else break;
} while( true );
//debug
/*
if(!mat.all_visited())
if(report )//!mat.all_visited())
{
mat.print_matrix();
incident_matrix<Face> mat(m,temp.begin(),temp.end(),ninner,GridCoords(),true);
......@@ -1399,7 +1467,7 @@ namespace INMOST
if( loop.empty() ) break;
} while( true );
}
*/
return ret;
}
......
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