Commit 14da724f authored by Kirill Terekhov's avatar Kirill Terekhov

some fixes to handle mesh modification

parent 85b0a530
Pipeline #172 failed with stages
in 10 minutes and 8 seconds
...@@ -333,6 +333,17 @@ namespace INMOST ...@@ -333,6 +333,17 @@ namespace INMOST
} }
//free created tag //free created tag
m->DeleteTag(indicator,FACE|EDGE); m->DeleteTag(indicator,FACE|EDGE);
//restore face orientation
//BUG: bad orientation not fixed automatically
int nfixed = 0;
for(Mesh::iteratorFace it = m->BeginFace(); it != m->EndFace(); ++it)
if( !it->CheckNormalOrientation() )
{
it->FixNormalOrientation();
nfixed++;
}
//std::cout << "Face " << it->LocalID() << " oriented incorrectly " << std::endl;
if( nfixed ) std::cout << "fixed " << nfixed << " faces" << std::endl;
//11. Restore parallel connectivity, global ids //11. Restore parallel connectivity, global ids
//ResolveShared(true); //ResolveShared(true);
//ResolveModification(); //ResolveModification();
...@@ -645,6 +656,17 @@ namespace INMOST ...@@ -645,6 +656,17 @@ namespace INMOST
} }
//free created tag //free created tag
m->DeleteTag(indicator,FACE|EDGE); m->DeleteTag(indicator,FACE|EDGE);
//restore face orientation
//BUG: bad orientation not fixed automatically
int nfixed = 0;
for(Mesh::iteratorFace it = m->BeginFace(); it != m->EndFace(); ++it)
if( !it->CheckNormalOrientation() )
{
it->FixNormalOrientation();
nfixed++;
}
//std::cout << "Face " << it->LocalID() << " oriented incorrectly " << std::endl;
if( nfixed ) std::cout << "fixed " << nfixed << " faces" << std::endl;
//todo: //todo:
//ResolveShared(true); //ResolveShared(true);
//ResolveModification(); //ResolveModification();
......
...@@ -3149,7 +3149,7 @@ namespace INMOST ...@@ -3149,7 +3149,7 @@ namespace INMOST
bool isMeshModified () const {return new_element != 0;} bool isMeshModified () const {return new_element != 0;}
MarkerType HideMarker () const {return hide_element;} MarkerType HideMarker () const {return hide_element;}
MarkerType NewMarker () const {return new_element;} MarkerType NewMarker () const {return new_element;}
void SwapModification (); // swap hidden and new elements, so that old mesh is recovered void SwapModification (bool recompute_geometry); // swap hidden and new elements, so that old mesh is recovered
void BeginModification (); //allow elements to be hidden void BeginModification (); //allow elements to be hidden
/// After this function any link to deleted element will be replaced by InvalidHandle(). /// After this function any link to deleted element will be replaced by InvalidHandle().
/// This will modify DATA_REFERENCE tags and contents of sets, so that all deleted elements are not referenced anymore. /// This will modify DATA_REFERENCE tags and contents of sets, so that all deleted elements are not referenced anymore.
...@@ -3392,7 +3392,9 @@ namespace INMOST ...@@ -3392,7 +3392,9 @@ namespace INMOST
///This structure is a helper structure to aid with search of cells by position.
///Currently the structure is very specific to the step of mesh modification,
///as it performs search over old elements of the mesh.
class SearchKDTree class SearchKDTree
{ {
public: public:
...@@ -3406,7 +3408,7 @@ namespace INMOST ...@@ -3406,7 +3408,7 @@ namespace INMOST
{ {
for(int i = 0; i < 3; i++) for(int i = 0; i < 3; i++)
{ {
if( p[i] < bbox[i*2] || p[i] > bbox[i*2+1] ) if( p[i] < bbox[i*2]-1.0e-4 || p[i] > bbox[i*2+1]+1.0e-4 )
return 0; return 0;
} }
return 1; return 1;
...@@ -3542,22 +3544,55 @@ namespace INMOST ...@@ -3542,22 +3544,55 @@ namespace INMOST
} }
SearchKDTree() : set(NULL), size(0), children(NULL) {} SearchKDTree() : set(NULL), size(0), children(NULL) {}
Cell SubSearchCell(const Storage::real p[3]) Cell SubSearchCell(const Storage::real p[3], bool print)
{ {
Cell ret = InvalidCell(); Cell ret = InvalidCell();
if( size == 1 ) if( size == 1 )
{ {
if( cell_point(Cell(m,set[0].e),p) ) if( print ) std::cout << "test cell " << GetHandleID(set[0].e) << std::endl;
ret = Cell(m,set[0].e); if( m->HideMarker() )
{
m->SwapModification(false);
if( cell_point(Cell(m,set[0].e),p) )
ret = Cell(m,set[0].e);
m->SwapModification(false);
}
else
{
if( cell_point(Cell(m,set[0].e),p) )
ret = Cell(m,set[0].e);
}
} }
else else
{ {
assert(size > 1); assert(size > 1);
if( bbox_point(p,bbox) ) if( bbox_point(p,bbox) )
{ {
ret = children[0].SubSearchCell(p); if( print )
{
std::cout << "point " << p[0] << " " << p[1] << " " << p[2] << " is in bbox ";
std::cout << " x " << bbox[0] << ":" << bbox[1];
std::cout << " y " << bbox[2] << ":" << bbox[3];
std::cout << " z " << bbox[4] << ":" << bbox[5];
std::cout << std::endl;
}
if( print ) std::cout << "try left child" << std::endl;
ret = children[0].SubSearchCell(p,print);
if( print ) std::cout << "ret " << (ret.isValid() ? ret.LocalID() : -1) << std::endl;
if( !ret.isValid() ) if( !ret.isValid() )
ret = children[1].SubSearchCell(p); {
if( print ) std::cout << "try right child" << std::endl;
ret = children[1].SubSearchCell(p,print);
if( print ) std::cout << "ret " << (ret.isValid() ? ret.LocalID() : -1) << std::endl;
}
}
else if( print )
{
std::cout << "point " << p[0] << " " << p[1] << " " << p[2] << " is not in bbox ";
std::cout << " x " << bbox[0] << ":" << bbox[1];
std::cout << " y " << bbox[2] << ":" << bbox[3];
std::cout << " z " << bbox[4] << ":" << bbox[5];
std::cout << std::endl;
} }
} }
return ret; return ret;
...@@ -3636,9 +3671,9 @@ namespace INMOST ...@@ -3636,9 +3671,9 @@ namespace INMOST
} }
} }
Cell SearchCell(const Storage::real * point) Cell SearchCell(const Storage::real * point, bool print = false)
{ {
return SubSearchCell(point); return SubSearchCell(point, print);
} }
}; };
......
...@@ -1938,7 +1938,7 @@ namespace INMOST ...@@ -1938,7 +1938,7 @@ namespace INMOST
new_element = CreateMarker(); new_element = CreateMarker();
} }
void Mesh::SwapModification() void Mesh::SwapModification(bool recompute_geometry)
{ {
MarkerType temp = hide_element; MarkerType temp = hide_element;
hide_element = new_element; hide_element = new_element;
...@@ -1949,15 +1949,18 @@ namespace INMOST ...@@ -1949,15 +1949,18 @@ namespace INMOST
memcpy(hidden_count,hidden_count_zero,sizeof(integer)*6); memcpy(hidden_count,hidden_count_zero,sizeof(integer)*6);
memcpy(hidden_count_zero,tmp,sizeof(integer)*6); memcpy(hidden_count_zero,tmp,sizeof(integer)*6);
for(ElementType etype = EDGE; etype <= CELL; etype = etype << 1) if( recompute_geometry )
{ {
for(integer it = 0; it < LastLocalID(etype); ++it) if( isValidElement(etype,it) ) for(ElementType etype = EDGE; etype <= CELL; etype = etype << 1)
{ {
HandleType h = ComposeHandle(etype,it); for(integer it = 0; it < LastLocalID(etype); ++it) if( isValidElement(etype,it) )
if( GetMarker(h,new_element) )
{ {
ComputeGeometricType(h); HandleType h = ComposeHandle(etype,it);
RecomputeGeometricData(h); if( GetMarker(h,new_element) )
{
ComputeGeometricType(h);
RecomputeGeometricData(h);
}
} }
} }
} }
......
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