Commit d3cfc9a1 authored by Kirill Terekhov's avatar Kirill Terekhov

Sync current updates

parent f531fdce
......@@ -42,11 +42,7 @@ namespace INMOST
adjacent<Node> Cell::getNodes()
{
if( !GetMeshLink()->HideMarker() )
{
adjacent<Node> ret(high_conn.begin(),high_conn.end());
assert(high_conn.size() == ret.size());
return ret;
}
return adjacent<Node>(high_conn.begin(),high_conn.end());
else
{
MIDType hm = GetMeshLink()->HideMarker();
......@@ -56,6 +52,25 @@ namespace INMOST
return aret;
}
}
adjacent<Node> Cell::getNodes(MIDType mask)
{
adjacent<Node> aret;
if( !GetMeshLink()->HideMarker() )
{
for(adj_iterator it = high_conn.begin(); it != high_conn.end(); ++it)
if( (*it)->GetMarker(mask) ) aret.push_back((*it));
}
else
{
MIDType hm = GetMeshLink()->HideMarker();
for(adj_iterator it = high_conn.begin(); it != high_conn.end(); ++it)
if( (*it)->GetMarker(mask) && !(*it)->GetMarker(hm) ) aret.push_back((*it));
}
return aret;
}
adjacent<Edge> Cell::getEdges()
{
adjacent<Edge> aret;
......@@ -152,6 +167,135 @@ namespace INMOST
}
return aret;
}
adjacent<Edge> Cell::getEdges(MIDType mask)
{
adjacent<Edge> aret;
if( !GetMeshLink()->HideMarker() )
{
if( GetElementDimension() == 2 ) // This cell is 2d face
{
aret.reserve(low_conn.size());
Element * last, * first;
Element * q = low_conn[0]; //edge 0
if( q->low_conn[0]->GetMarker(mask) ) aret.push_back(q->low_conn[0]); //node 0
if( q->low_conn[1]->GetMarker(mask) ) aret.push_back(q->low_conn[1]); //node 1
first = q->low_conn[0];
last = q->low_conn[1];
Element * r = low_conn[1]; //edge 1
if( first == r->low_conn[0] || first == r->low_conn[1] )
{
last = first;
if( aret.size() > 1 )
{
Edge * temp = aret.data()[0];
aret.data()[0] = aret.data()[1];
aret.data()[1] = temp;
}
}
adj_iterator it = low_conn.begin()+1, iend = low_conn.end()-1;
while(it != iend) //loop over edges
{
if( last == (*it)->low_conn[0] )
{
last = (*it)->low_conn[1];
if( last->GetMarker(mask) ) aret.push_back(last);
}
else
{
last = (*it)->low_conn[0];
if( last->GetMarker(mask) ) aret.push_back(last);
}
++it;
}
}
else
{
Mesh * m = GetMeshLink();
MIDType mrk = m->CreateMarker();
for(Element::adj_iterator it = low_conn.begin(); it != low_conn.end(); it++) //faces
for(Element::adj_iterator jt = (*it)->low_conn.begin(); jt != (*it)->low_conn.end(); jt++) //edges
if( (*jt)->GetMarker(mask) && !(*jt)->GetMarker(mrk))
{
aret.push_back(*jt);
(*jt)->SetMarker(mrk);
}
for(adjacent<Edge>::iterator it = aret.begin(); it != aret.end(); it++)
it->RemMarker(mrk);
m->ReleaseMarker(mrk);
}
}
else
{
MIDType hm = GetMeshLink()->HideMarker();
if( GetElementDimension() == 2 ) // This cell is 2d face
{
INMOST_DATA_ENUM_TYPE i = static_cast<INMOST_DATA_ENUM_TYPE>(-1),
k = static_cast<INMOST_DATA_ENUM_TYPE>(-1),
k1 = static_cast<INMOST_DATA_ENUM_TYPE>(-1), k2;
Element * last, * first;
aret.reserve(low_conn.size());
i = Mesh::getNext(&low_conn[0],low_conn.size(),i,hm);
Element * q = low_conn[i]; //edge 0
k = Mesh::getNext(&q->low_conn[0],q->low_conn.size(),k,hm);
if( q->low_conn[k]->GetMarker(mask) ) aret.push_back(q->low_conn[k]); //node 0
first = q->low_conn[k];
k = Mesh::getNext(&q->low_conn[0],q->low_conn.size(),k,hm);
if( q->low_conn[k]->GetMarker(mask) ) aret.push_back(q->low_conn[k]); //node 1
last = q->low_conn[k];
i = Mesh::getNext(&low_conn[0],low_conn.size(),i,hm);
Element * r = low_conn[i]; //edge 1
k1 = Mesh::getNext(&q->low_conn[0],q->low_conn.size(),k1,hm);
k2 = Mesh::getNext(&q->low_conn[0],q->low_conn.size(),k1,hm);
if( first == r->low_conn[k1] || first == r->low_conn[k2] )
{
last = first;
if( aret.size() > 1 )
{
Edge * temp = aret.data()[0];
aret.data()[0] = aret.data()[1];
aret.data()[1] = temp;
}
}
adj_iterator it = low_conn.begin()+1, iend = low_conn.end()-1;
while(it != iend) if( !(*it)->GetMarker(hm) ) //loop over edges
{
k1 = static_cast<INMOST_DATA_ENUM_TYPE>(-1);
k1 = Mesh::getNext(&(*it)->low_conn[0],(*it)->low_conn.size(),k1,hm);
k2 = Mesh::getNext(&(*it)->low_conn[0],(*it)->low_conn.size(),k1,hm);
if( last == (*it)->low_conn[k1] )
{
last = (*it)->low_conn[k2];
if( last->GetMarker(mask) ) aret.push_back(last);
}
else
{
last = (*it)->low_conn[k1];
if( last->GetMarker(mask) ) aret.push_back(last);
}
++it;
}
}
else
{
Mesh * m = GetMeshLink();
MIDType mrk = m->CreateMarker();
for(Element::adj_iterator it = low_conn.begin(); it != low_conn.end(); it++) if( !(*it)->GetMarker(hm) ) //faces
for(Element::adj_iterator jt = (*it)->low_conn.begin(); jt != (*it)->low_conn.end(); jt++) if( !(*jt)->GetMarker(hm) )//edges
if( (*jt)->GetMarker(mask) && !(*jt)->GetMarker(mrk))
{
aret.push_back(*jt);
(*jt)->SetMarker(mrk);
}
for(adjacent<Edge>::iterator it = aret.begin(); it != aret.end(); it++)
it->RemMarker(mrk);
m->ReleaseMarker(mrk);
}
}
return aret;
}
adjacent<Face> Cell::getFaces()
{
if( !GetMeshLink()->HideMarker() )
......@@ -165,6 +309,25 @@ namespace INMOST
return aret;
}
}
adjacent<Face> Cell::getFaces(MIDType mask)
{
adjacent<Face> aret;
if( !GetMeshLink()->HideMarker() )
{
for(adj_iterator it = low_conn.begin(); it != low_conn.end(); ++it)
if( (*it)->GetMarker(mask) ) aret.push_back((*it));
}
else
{
MIDType hm = GetMeshLink()->HideMarker();
for(adj_iterator it = low_conn.begin(); it != low_conn.end(); ++it)
if( (*it)->GetMarker(mask) && !(*it)->GetMarker(hm) ) aret.push_back((*it));
}
return aret;
}
......
......@@ -388,13 +388,14 @@ namespace INMOST
etype & operator *() { return *e; }
etype * operator ->() { return e; }
_iterator & operator =(_iterator const & other) { e = other.e; return *this; }
bool operator ==(const _iterator & other) { return e == other.e;}
bool operator !=(const _iterator & other) { return e != other.e;}
bool operator <(const _iterator & other) { return e < other.e;}
bool operator >(const _iterator & other) { return e > other.e;}
bool operator <=(const _iterator & other) { return e <= other.e;}
bool operator >=(const _iterator & other) { return e >= other.e;}
bool operator ==(const _iterator & other) const { return e == other.e;}
bool operator !=(const _iterator & other) const { return e != other.e;}
bool operator <(const _iterator & other) const { return e < other.e;}
bool operator >(const _iterator & other) const { return e > other.e;}
bool operator <=(const _iterator & other) const { return e <= other.e;}
bool operator >=(const _iterator & other) const { return e >= other.e;}
operator void *() {return static_cast<void *> (e);}
operator const void *() {return const_cast<const void *> (e);}
};
typedef _iterator<element> iterator;
typedef _iterator<const element> const_iterator;
......@@ -425,12 +426,12 @@ namespace INMOST
etype & operator *() { return *e; }
etype * operator ->() { return e; }
_reverse_iterator & operator =(_reverse_iterator const & other) { e = other.e; return *this;}
bool operator ==(const _reverse_iterator & other) { return e == other.e;}
bool operator !=(const _reverse_iterator & other) { return e != other.e;}
bool operator <(const _reverse_iterator & other) { return e < other.e;}
bool operator >(const _reverse_iterator & other) { return e > other.e;}
bool operator <=(const _reverse_iterator & other) { return e <= other.e;}
bool operator >=(const _reverse_iterator & other) { return e >= other.e;}
bool operator ==(const _reverse_iterator & other) const { return e == other.e;}
bool operator !=(const _reverse_iterator & other) const { return e != other.e;}
bool operator <(const _reverse_iterator & other) const { return e < other.e;}
bool operator >(const _reverse_iterator & other) const { return e > other.e;}
bool operator <=(const _reverse_iterator & other) const { return e <= other.e;}
bool operator >=(const _reverse_iterator & other) const { return e >= other.e;}
operator void *() {return static_cast<void *> (e);}
};
typedef _reverse_iterator<element> reverse_iterator;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -27,6 +27,48 @@ namespace INMOST
Edge::~Edge()
{
}
Node * Edge::getBeg() const
{
if( !GetMeshLink()->HideMarker() )
{
if( low_conn.empty() )
return NULL;
return low_conn.front()->getAsNode();
}
else
{
if( !low_conn.empty() )
{
INMOST_DATA_ENUM_TYPE i = static_cast<INMOST_DATA_ENUM_TYPE>(-1);
MIDType hm = GetMeshLink()->HideMarker();
i = Mesh::getNext(&low_conn[0],low_conn.size(),i,hm);
if( i != low_conn.size() ) return low_conn[i]->getAsNode();
}
return NULL;
}
}
Node * Edge::getEnd() const
{
if( !GetMeshLink()->HideMarker() )
{
if( low_conn.size() < 2 )
return NULL;
return low_conn.back()->getAsNode();
}
else
{
if( !low_conn.empty() )
{
INMOST_DATA_ENUM_TYPE i = static_cast<INMOST_DATA_ENUM_TYPE>(-1);
MIDType hm = GetMeshLink()->HideMarker();
i = Mesh::getNext(&low_conn[0],low_conn.size(),i,hm);
i = Mesh::getNext(&low_conn[0],low_conn.size(),i,hm);
if( i != low_conn.size() ) return low_conn[i]->getAsNode();
}
return NULL;
}
}
adjacent<Node> Edge::getNodes()
{
......@@ -41,6 +83,23 @@ namespace INMOST
return aret;
}
}
adjacent<Node> Edge::getNodes(MIDType mask)
{
adjacent<Node> aret;
if( !GetMeshLink()->HideMarker() )
{
for(adj_iterator it = low_conn.begin(); it != low_conn.end(); ++it)
if( (*it)->GetMarker(mask) ) aret.push_back((*it));
}
else
{
MIDType hm = GetMeshLink()->HideMarker();
for(adj_iterator it = low_conn.begin(); it != low_conn.end(); ++it)
if( (*it)->GetMarker(mask) && !(*it)->GetMarker(hm) ) aret.push_back((*it));
}
return aret;
}
adjacent<Face> Edge::getFaces()
{
......@@ -55,6 +114,25 @@ namespace INMOST
return aret;
}
}
adjacent<Face> Edge::getFaces(MIDType mask)
{
adjacent<Face> aret;
if( !GetMeshLink()->HideMarker() )
{
for(adj_iterator it = high_conn.begin(); it != high_conn.end(); ++it)
if( (*it)->GetMarker(mask) ) aret.push_back((*it));
}
else
{
MIDType hm = GetMeshLink()->HideMarker();
for(adj_iterator it = high_conn.begin(); it != high_conn.end(); ++it)
if( (*it)->GetMarker(mask) && !(*it)->GetMarker(hm) ) aret.push_back((*it));
}
return aret;
}
adjacent<Cell> Edge::getCells()
{
adjacent<Cell> aret;
......@@ -86,6 +164,39 @@ namespace INMOST
m->ReleaseMarker(mrk);
return aret;
}
adjacent<Cell> Edge::getCells(MIDType mask)
{
adjacent<Cell> aret;
Mesh * m = GetMeshLink();
MIDType mrk = m->CreateMarker();
if( !GetMeshLink()->HideMarker() )
{
for(Element::adj_iterator it = high_conn.begin(); it != high_conn.end(); it++) //faces
for(Element::adj_iterator jt = (*it)->high_conn.begin(); jt != (*it)->high_conn.end(); jt++) //cels
if( (*jt)->GetMarker(mask) && !(*jt)->GetMarker(mrk) )
{
aret.push_back(*jt);
(*jt)->SetMarker(mrk);
}
}
else
{
MIDType hm = GetMeshLink()->HideMarker();
for(Element::adj_iterator it = high_conn.begin(); it != high_conn.end(); it++) if( !(*it)->GetMarker(hm) ) //faces
for(Element::adj_iterator jt = (*it)->high_conn.begin(); jt != (*it)->high_conn.end(); jt++) if( !(*jt)->GetMarker(hm) ) //cels
if( (*jt)->GetMarker(mask) && !(*jt)->GetMarker(mrk) )
{
aret.push_back(*jt);
(*jt)->SetMarker(mrk);
}
}
for(adjacent<Cell>::iterator it = aret.begin(); it != aret.end(); it++)
it->RemMarker(mrk);
m->ReleaseMarker(mrk);
return aret;
}
Storage::real Edge::Length() {Storage::real ret; m_link->GetGeometricData(this,MEASURE,&ret); return ret;}
}
......
This diff is collapsed.
......@@ -29,6 +29,7 @@ int edges = 1;
bool perspective = false;
int text = 4;
int display_orphans = 1;
int badfaces = 1;
ElementSet * problem_set, * orphan_edges, * orphan_faces;
......@@ -322,6 +323,7 @@ void keyboard(unsigned char key, int x, int y)
else if( key == 'e' )
{
edges = !edges;
glutPostRedisplay();
}
else if( key == 27 )
{
......@@ -346,9 +348,9 @@ void keyboard(unsigned char key, int x, int y)
}
else if( key == ' ')
{
drawgrid = (drawgrid+1)%2;
glutPostRedisplay();
mesh->Save("out.vtk");
//drawgrid = (drawgrid+1)%2;
//glutPostRedisplay();
}
else if( key == 'q' )
{
......@@ -435,6 +437,12 @@ void keyboard(unsigned char key, int x, int y)
display_orphans = !display_orphans;
glutPostRedisplay();
}
else if( key == 'l' )
{
badfaces = !badfaces;
glutPostRedisplay();
}
}
......@@ -497,11 +505,13 @@ face2gl DrawFace(Element * f, int mmat, double campos[3])
if( edges )
{
glColor3f(0,0,1);
//glLineWidth(2.0);
if( boundary == 1 ) glColor3f(0,0,1); else glColor3f(0,0,0);
glBegin(GL_LINE_LOOP);
for( adjacent<Node>::iterator kt = nodes.begin(); kt != nodes.end(); kt++)
glVertex3dv(&(kt->Coords()[0]));
glEnd();
//glLineWidth(1.0);
}
return ret;
}
......@@ -591,8 +601,24 @@ void draw()
//glTranslated((l+r)*0.5,(b+t)*0.5,(near+far)*0.5);
int pacef = std::max(1,mesh->MaxLocalIDFACE()/10000);
std::vector<face2gl> polygons;
if( badfaces )
{
for(INMOST_DATA_INTEGER_TYPE it = 0; it < mesh->MaxLocalIDFACE(); it += (interactive ? pacef : 1))
{
Face * f = mesh->FaceByLocalID(it);
if( f != NULL )
{
if( !f->CheckNormalOrientation() )
polygons.push_back(DrawFace(f,1,campos));
}
}
}
char str[2048];
......@@ -1234,7 +1260,7 @@ void draw()
//for(Mesh::iteratorFace it = mesh->BeginFace(); it != mesh->EndFace(); it++)
if( colort.isValid() )
{
for(int i = 0; i < end; i+= interactive ? 10 : 1)
for(int i = 0; i < end; i+= interactive ? pacef : 1)
{
Element * it = mesh->ElementByLocalID(FACE,i);
if( it == NULL ) continue;
......@@ -1248,7 +1274,7 @@ void draw()
}
else
{
for(int i = 0; i < end; i+= interactive ? 10 : 1)
for(int i = 0; i < end; i+= interactive ? pacef : 1)
{
Element * it = mesh->ElementByLocalID(FACE,i);
if( it == NULL ) continue;
......@@ -1257,6 +1283,55 @@ void draw()
}
}
}
if( display_orphans )
{
if( orphan_edges != NULL ) for(ElementSet::iterator iit = orphan_edges->begin(); iit != orphan_edges->end(); ++iit)
{
Element * it = &*iit;//mesh->ElementByLocalID(EDGE,i);
//if( it == NULL ) continue;
//if( it->nbAdjElements(CELL) == 0 )
{
Storage::real cnt[3];
adjacent<Node> nodes = it->getNodes();
{
glBegin(GL_LINES);
glVertex3dv(&nodes[0].Coords()[0]);
glVertex3dv(&nodes[1].Coords()[0]);
glEnd();
}
}
}
if( orphan_faces != NULL ) for(ElementSet::iterator iit = orphan_faces->begin(); iit != orphan_faces->end(); ++iit)
{
Element * it = &*iit;
{
Storage::integer_array mats;
Storage::real cnt[3];
adjacent<Edge> edges = it->getEdges();
for(unsigned k = 0; k < edges.size(); k++)
{
adjacent<Node> nodes = edges[k].getNodes();
{
glBegin(GL_LINES);
glVertex3dv(&nodes[0].Coords()[0]);
glVertex3dv(&nodes[1].Coords()[0]);
glEnd();
}
}
if( matfilter == 0 || std::binary_search(mats.begin(),mats.end(),matfilter-1) )
polygons.push_back(DrawFace(&*it,0,campos));
}
}
}
std::sort(polygons.begin(),polygons.end());
......@@ -1602,6 +1677,8 @@ int main(int argc, char ** argv)
for(Mesh::iteratorNode it = mesh->BeginNode(); it != mesh->EndNode(); ++it)
if(it->nbAdjElements(NODE) == 0 ) delete &*it;
*/
if( argc <= 2 )
{
......@@ -1625,7 +1702,28 @@ int main(int argc, char ** argv)
//mesh = new Mesh(*read);
int badorient = 0;
tiny_map<Element::GeometricType,int,16> neighbours;
tiny_map<Element::GeometricType,int,16> elemtypes;
for(Mesh::iteratorFace it = mesh->BeginFace(); it != mesh->EndFace(); ++it)
if( !it->CheckNormalOrientation() )
{
badorient++;
if( it->BackCell() != NULL ) neighbours[it->BackCell()->GetGeometricType()]++;
if( it->FrontCell() != NULL ) neighbours[it->FrontCell()->GetGeometricType()]++;
elemtypes[it->GetGeometricType()]++;
}
if( badorient )
{
std::cout << "Found " << badorient << " badly oriented faces" << std::endl;
std::cout << "types of bad faces: " << std::endl;
for(tiny_map<Element::GeometricType,int,16>::iterator it = elemtypes.begin(); it != elemtypes.end(); ++it)
std::cout << Element::GeometricTypeName(it->first) << ": " << it->second << std::endl;
std::cout << "neighbours of bad faces: " << std::endl;
for(tiny_map<Element::GeometricType,int,16>::iterator it = neighbours.begin(); it != neighbours.end(); ++it)
std::cout << Element::GeometricTypeName(it->first) << ": " << it->second << std::endl;
}
if( mesh->HaveTag("MATERIAL") ) mat = mesh->GetTag("MATERIAL");
//~
......
......@@ -14,25 +14,142 @@ int drawgrid = 0;
int interactive = 0;
double zoom = 1;
int width = 800, height = 800;
double l = 1e20, r = -1e20, b = 1e20, t = -1e20, zfar = -1e20, znear = 1e20;
double sleft = 1e20, sright = -1e20, sbottom = 1e20, stop = -1e20, sfar = -1e20, snear = 1e20;
double shift[3] = {0,0,0};
bool perspective = false;
std::map<GeometricData,ElementType> table;
void reshape(int w, int h)
void set_matrix3d()
{
double aspect = (double)width/(double)height;
double side = std::max(std::max( sright-sleft, stop-sbottom ), sfar-snear)*0.5;
//double center[3] = { (sleft+sright)*0.5, (sbottom+stop)*0.5, (sfar+snear)*0.5};
const double sc = 2;
double aspect = (double)w/(double)h;
double center[3] = { (l+r)*0.5, (b+t)*0.5, (zfar+znear)*0.5};
double side = std::max(std::max( r-l, t-b ), zfar-znear)*0.5;
width = w;
height = h;
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho(center[0]-sc*side*zoom*aspect,center[0]+sc*zoom*side*aspect,
center[1]-sc*side*zoom,center[1]+sc*zoom*side,
center[2]-sc*side*100,center[2]+sc*side*100);
//~ glOrtho(center[0]-sc*side*zoom*aspect,center[0]+sc*zoom*side*aspect,
//~ center[1]-sc*side*zoom,center[1]+sc*zoom*side,
//~ center[2]-sc*side*100,center[2]+sc*side*100);
if( !perspective )
{
glOrtho(-sc*side*zoom*aspect,sc*side*zoom*aspect,
-sc*side*zoom,sc*side*zoom,
-sc*side*100,sc*side*100);
}
else
gluPerspective(60.0, aspect, 0.00001, 1000.0);
glMatrixMode (GL_MODELVIEW);
}
void set_matrix2d()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1,1,-1,1,-1,1);
glMatrixMode(GL_MODELVIEW);
}
void reshape(int w, int h)
{
width = w;
height = h;
set_matrix3d();
glViewport(0, 0, w, h);
}
int actionstate = 0;
double mymx = 0;
double mymy = 0;
void myclickmotion(int nmx, int nmy) // Mouse
{
double lmx = 2.*(nmx/(double)width - 0.5),lmy = 2.*(0.5 - nmy/(double)height), dmx = lmx-mymx, dmy = lmy - mymy;
if( actionstate == 1 )
{
double shiftmod[3] = {0,0,0};
shiftmod[0] += dmx*zoom*std::max(std::max( sright-sleft, stop-sbottom ), sfar-snear)*0.5;
shiftmod[1] += dmy*zoom*std::max(std::max( sright-sleft, stop-sbottom ), sfar-snear)*0.5;
rotatevector((double*)shiftmod);
shift[0] += shiftmod[0];
shift[1] += shiftmod[1];
shift[2] += shiftmod[2];
glutPostRedisplay();
mymx = lmx;
mymy = lmy;
}
else if( actionstate == 2 )
{
zoom *= expf(-dmy);
reshape(width,height);
double shiftmod[3] = {0,0,0};
shiftmod[2] += dmx*zoom*std::max(std::max( sright-sleft, stop-sbottom ), sfar-snear)*0.5;
rotatevector((double*)shiftmod);
shift[0] += shiftmod[0];
shift[1] += shiftmod[1];
shift[2] += shiftmod[2];
glutPostRedisplay();
mymx = lmx;
mymy = lmy;
}
else if( actionstate == 3 )
clickmotion(nmx,nmy);
}
void mymotion(int nmx, int nmy) // Mouse
{
motion(nmx,nmy);