Commit 4cae379f authored by Kirill Terekhov's avatar Kirill Terekhov

Correct vtk loading for 2d mesh; DrawGrid/OldDrawGrid display 2d meshes without crash

parent a1aa2a28
......@@ -493,9 +493,13 @@ face2gl DrawFace(Element & f, int mmat, double campos[3])
double r = color ? mmat / (double)maxcolor : mmat / (double) maxmat;
ret.set_color(1-r,r,1-r,0.25);
}
double v[3] = {0,0,0};
for( ElementArray<Node>::iterator kt = nodes.begin(); kt != nodes.end(); kt++)
ret.add_vert(&(kt->Coords()[0]));
{
for(int k = 0; k < f->GetMeshLink()->GetDimensions(); ++k)
v[k] = kt->Coords()[k];
ret.add_vert(v);
}
if( edges )
......@@ -504,7 +508,12 @@ face2gl DrawFace(Element & f, int mmat, double campos[3])
if( boundary == 1 ) glColor3f(0,0,1); else glColor3f(0,0,0);
glBegin(GL_LINE_LOOP);
for( ElementArray<Node>::iterator kt = nodes.begin(); kt != nodes.end(); kt++)
glVertex3dv(&(kt->Coords()[0]));
{
if( f->GetMeshLink()->GetDimensions() == 2 )
glVertex2dv(&(kt->Coords()[0]));
else
glVertex3dv(&(kt->Coords()[0]));
}
glEnd();
//glLineWidth(1.0);
}
......@@ -1812,15 +1821,30 @@ int main(int argc, char ** argv)
for(std::map<Element::GeometricType,int>::iterator it = num.begin(); it != num.end(); ++it)
std::cout << Element::GeometricTypeName(it->first) << ": " << it->second << std::endl;
for(Mesh::iteratorNode n = mesh->BeginNode(); n != mesh->EndNode(); n++)
if( mesh->GetDimensions() == 2 )
{
Storage::real_array c = n->Coords();
if( c[0] > sright ) sright = c[0];
if( c[0] < sleft ) sleft = c[0];
if( c[1] > stop ) stop = c[1];
if( c[1] < sbottom ) sbottom = c[1];
if( c[2] > sfar ) sfar = c[2];
if( c[2] < snear ) snear = c[2];
for(Mesh::iteratorNode n = mesh->BeginNode(); n != mesh->EndNode(); n++)
{
Storage::real_array c = n->Coords();
if( c[0] > sright ) sright = c[0];
if( c[0] < sleft ) sleft = c[0];
if( c[1] > stop ) stop = c[1];
if( c[1] < sbottom ) sbottom = c[1];
}
sfar = -1, snear = 1;
}
else
{
for(Mesh::iteratorNode n = mesh->BeginNode(); n != mesh->EndNode(); n++)
{
Storage::real_array c = n->Coords();
if( c[0] > sright ) sright = c[0];
if( c[0] < sleft ) sleft = c[0];
if( c[1] > stop ) stop = c[1];
if( c[1] < sbottom ) sbottom = c[1];
if( c[2] > sfar ) sfar = c[2];
if( c[2] < snear ) snear = c[2];
}
}
printf("%g:%g %g:%g %g:%g\n",sleft,sright,sbottom,stop,snear,sfar);
......@@ -1858,4 +1882,4 @@ int main(int argc, char ** argv)
glutPostRedisplay();
glutMainLoop();
}
\ No newline at end of file
}
......@@ -893,18 +893,24 @@ namespace INMOST
bnd_clipper::~bnd_clipper()
{
mm->DeleteTag(clip_state);
delete tree;
if( tree ) delete tree;
delete[]faces;
}
bnd_clipper::bnd_clipper(Mesh * m, HandleType * _faces, INMOST_DATA_ENUM_TYPE size)
{
mm = m;
clip_state = m->CreateTag("CLIP_FACE_STATE", DATA_INTEGER, FACE, NONE, 1);
clip_state = m->CreateTag("CLIP_FACE_STATE", DATA_INTEGER, (mm->GetDimensions() == 2 ? CELL : NONE) |FACE, NONE, 1);
nfaces = size;
faces = new HandleType[nfaces];
for (INMOST_DATA_ENUM_TYPE k = 0; k < nfaces; k++) faces[k] = _faces[k];
tree = new kdtree(mm, faces, nfaces);
if( mm->GetDimensions() == 2 )
{
for (INMOST_DATA_ENUM_TYPE k = 0; k < nfaces; k++)
mm->IntegerDF(faces[k],clip_state) = CLIP_FACE_INSIDE;
tree = NULL;
}
else tree = new kdtree(mm, faces, nfaces);
}
double bnd_clipper::compute_value(Node n1, Node n2, Storage::real * c1, Storage::real * c2, Storage::real * pnt)
......@@ -922,7 +928,8 @@ namespace INMOST
void bnd_clipper::clip_plane(Storage::real p[3], Storage::real n[3])
{
tree->intersect_plane_face(clip_state, p, n);
if( mm->GetDimensions() != 2 )
tree->intersect_plane_face(clip_state, p, n);
}
void bnd_clipper::gen_clip(std::vector<face2gl> & out, Storage::real p[3], Storage::real n[3], bool elevation)
......@@ -933,17 +940,22 @@ namespace INMOST
int state = mm->IntegerDF(faces[k], clip_state);
if (state == CLIP_FACE_INSIDE)
{
ElementArray<Node> nodes = Face(mm, faces[k])->getNodes();
ElementArray<Node> nodes = Element(mm, faces[k])->getNodes();
face2gl f;
f.set_color(0.6, 0.6, 0.6, 1);
for (INMOST_DATA_ENUM_TYPE q = 0; q < nodes.size(); q++)
{
f.add_vert(&nodes[q].Coords()[0]);
f.add_vert(&nodes[q].Coords()[0], mm->GetDimensions());
if (isColorBarEnabled())
{
//f.add_color(GetColorBar()->pick_color(nodes[q].RealDF(GetVisualizationTag())));
if (GetVisualizationType() == CELL && !isVisualizationSmooth())
f.add_texcoord(GetColorBar()->pick_texture(Face(mm, faces[k]).BackCell().RealDF(GetVisualizationTag())));
{
if( GetHandleElementType(faces[k]) == CELL )
f.add_texcoord(GetColorBar()->pick_texture(Cell(mm, faces[k]).RealDF(GetVisualizationTag())));
else
f.add_texcoord(GetColorBar()->pick_texture(Face(mm, faces[k]).BackCell().RealDF(GetVisualizationTag())));
}
else
f.add_texcoord(GetColorBar()->pick_texture(nodes[q].RealDF(GetVisualizationTag())));
}
......@@ -957,7 +969,7 @@ namespace INMOST
{
face2gl f;
f.set_color(0.6, 0.6, 0.6, 1);
ElementArray<Node> nodes = Face(mm, faces[k])->getNodes();
ElementArray<Node> nodes = Element(mm, faces[k])->getNodes();
dynarray<bool, 64> nodepos(nodes.size());
dynarray<Storage::real, 64> faceverts;
Storage::real_array coords = nodes[0].Coords();
......@@ -1055,13 +1067,13 @@ namespace INMOST
{
GetColorBar()->pick_color(nodes[q].RealDF(GetVisualizationTag())).set_color();
glTexCoord1f(GetColorBar()->pick_texture(nodes[q].RealDF(GetVisualizationTag())));
glVertex3dv(&nodes[q].Coords()[0]);
glVertexNdv(&nodes[q].Coords()[0],mm->GetDimensions());
}
}
else
{
for (INMOST_DATA_ENUM_TYPE q = 0; q < nodes.size(); q++)
glVertex3dv(&nodes[q].Coords()[0]);
glVertexNdv(&nodes[q].Coords()[0],mm->GetDimensions());
}
glEnd();
......@@ -1078,13 +1090,13 @@ namespace INMOST
{
if (mm->IntegerDF(faces[k], clip_state) == CLIP_FACE_INSIDE)
{
ElementArray<Node> nodes = Face(mm, faces[k])->getNodes();
ElementArray<Node> nodes = Element(mm, faces[k])->getNodes();
glBegin(GL_LINE_LOOP);
for (INMOST_DATA_ENUM_TYPE q = 0; q < nodes.size(); q++) glVertex3dv(&nodes[q].Coords()[0]);
for (INMOST_DATA_ENUM_TYPE q = 0; q < nodes.size(); q++) glVertexNdv(&nodes[q].Coords()[0],mm->GetDimensions());
glEnd();
}
}
}
INMOST_DATA_ENUM_TYPE bnd_clipper::size() { return nfaces; }
}
\ No newline at end of file
}
......@@ -13,8 +13,9 @@ namespace INMOST
if (f->nbAdjElements(CELL) == 0) ret.set_color(1, 0, 0, 0.1);
else ret.set_color(0, 1, 0, 0.1);
for (ElementArray<Node>::iterator kt = nodes.begin(); kt != nodes.end(); kt++)
ret.add_vert(&(kt->Coords()[0]));
ret.add_vert(&kt->Coords()[0],kt->GetMeshLink()->GetDimensions());
ret.set_elem(f->GetElementType(), f->LocalID());
ret.compute_center();
return ret;
......@@ -633,4 +634,4 @@ namespace INMOST
for (INMOST_DATA_ENUM_TYPE q = 0; q < set.size(); q++) if (set[q].get_flag()) set[q].drawedges();
glEnd();
}
}
\ No newline at end of file
}
......@@ -39,6 +39,7 @@ namespace INMOST
void set_color(double r, double g, double b, double a) { c[0] = r; c[1] = g; c[2] = b; c[3] = a; }
void add_vert(double x, double y, double z) { unsigned s = (unsigned)verts.size(); verts.resize(s + 3); verts[s] = x; verts[s + 1] = y; verts[s + 2] = z; }
void add_vert(double v[3]) { verts.insert(verts.end(), v, v + 3); }
void add_vert(double * v, int N) { double vv[3] = {0,0,0}; for(int k = 0; k < N; ++k) vv[k] = v[k]; verts.insert(verts.end(), vv, vv + 3); }
void add_color(color_t c) { colors.push_back(c); }
void add_texcoord(double val) { texcoords.push_back(val); }
double * get_vert(int k) { return &verts[k * 3]; }
......@@ -72,4 +73,4 @@ namespace INMOST
void draw_faces_interactive_alpha(std::vector<face2gl> & set, double alpha);
void draw_edges_interactive(std::vector<face2gl> & set);
}
#endif
\ No newline at end of file
#endif
......@@ -22,4 +22,10 @@
void printtext(const char * fmt, ...); //in printtext.cpp
#endif
\ No newline at end of file
static void glVertexNdv(double * v, int N)
{
if( N == 2 ) glVertex2dv(v);
else glVertex3dv(v);
}
#endif
......@@ -560,10 +560,11 @@ void keyboard(unsigned char key, int x, int y)
}
else if( key == 'z' )
{
int ret;
printf("Enter point of plane (x,y,z):\n");
scanf("%lf %lf %lf",p,p+1,p+2);
ret = scanf("%lf %lf %lf",p,p+1,p+2);
printf("Enter normal of plane (x,y,z):\n");
scanf("%lf %lf %lf",n,n+1,n+2);
ret = scanf("%lf %lf %lf",n,n+1,n+2);
Storage::real l = sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]);
if( l )
{
......@@ -574,6 +575,10 @@ void keyboard(unsigned char key, int x, int y)
if( oclipper )
{
oclipper->clip_plane(p,n);
clipboxupdate = true;
}
if( bclipper )
{
bclipper->clip_plane(p,n);
clipboxupdate = true;
}
......@@ -645,7 +650,8 @@ void keyboard(unsigned char key, int x, int y)
if( oclipper ) delete oclipper;
if( bclipper ) delete bclipper;
bclipper = new bnd_clipper(mesh,boundary_faces.data(),(int)boundary_faces.size());
oclipper = new clipper(mesh);
if( mesh->GetDimensions() != 2 )
oclipper = new clipper(mesh);
clipupdate = true;
glutPostRedisplay();
}
......@@ -679,7 +685,8 @@ void keyboard(unsigned char key, int x, int y)
if( oclipper ) delete oclipper;
if( bclipper ) delete bclipper;
bclipper = new bnd_clipper(mesh,boundary_faces.data(),(unsigned)boundary_faces.size());
oclipper = new clipper(mesh);
if( mesh->GetDimensions() != 2 )
oclipper = new clipper(mesh);
clipupdate = true;
glutPostRedisplay();
}
......@@ -756,21 +763,29 @@ void DrawElement(Element e, color_t face, color_t edge, color_t node, bool print
node.set_color();
glColor3f(1,1,0);
glBegin(GL_POINTS);
glVertex3dv(e->getAsNode()->Coords().data());
glVertexNdv(e->getAsNode()->Coords().data(),e.GetMeshLink()->GetDimensions());
glEnd();
}
if( e.GetElementType() == EDGE && e.GetElementDimension() == 0)
{
node.set_color();
glColor3f(1,1,0);
glBegin(GL_POINTS);
glVertexNdv(e->getNodes()[0]->Coords().data(),e.GetMeshLink()->GetDimensions());
glEnd();
}
else if( e.GetElementType() == EDGE )
else if( e.GetElementType() == EDGE && e.GetElementDimension() == 1 )
{
edge.set_color();
glLineWidth(4);
glBegin(GL_LINES);
glVertex3dv(e->getAsEdge()->getBeg()->Coords().data());
glVertex3dv(e->getAsEdge()->getEnd()->Coords().data());
glVertexNdv(e->getAsEdge()->getBeg()->Coords().data(),e.GetMeshLink()->GetDimensions());
glVertexNdv(e->getAsEdge()->getEnd()->Coords().data(),e.GetMeshLink()->GetDimensions());
glEnd();
node.set_color();
glBegin(GL_POINTS);
glVertex3dv(e->getAsEdge()->getBeg()->Coords().data());
glVertex3dv(e->getAsEdge()->getEnd()->Coords().data());
glVertexNdv(e->getAsEdge()->getBeg()->Coords().data(),e.GetMeshLink()->GetDimensions());
glVertexNdv(e->getAsEdge()->getEnd()->Coords().data(),e.GetMeshLink()->GetDimensions());
glEnd();
glLineWidth(1);
......@@ -782,7 +797,30 @@ void DrawElement(Element e, color_t face, color_t edge, color_t node, bool print
printtext("%d", e->getAsEdge().getEnd().LocalID());
}
}
else if( e.GetElementType() == FACE )
else if( e.GetElementType() == FACE && e.GetElementDimension() == 1 )
{
edge.set_color();
glLineWidth(4);
glBegin(GL_LINES);
glVertexNdv(e->getAsFace()->getBeg()->Coords().data(),e.GetMeshLink()->GetDimensions());
glVertexNdv(e->getAsFace()->getEnd()->Coords().data(),e.GetMeshLink()->GetDimensions());
glEnd();
node.set_color();
glBegin(GL_POINTS);
glVertexNdv(e->getAsFace()->getBeg()->Coords().data(),e.GetMeshLink()->GetDimensions());
glVertexNdv(e->getAsFace()->getEnd()->Coords().data(),e.GetMeshLink()->GetDimensions());
glEnd();
glLineWidth(1);
if (print_adj)
{
glRasterPos3dv(e->getAsFace().getBeg().Coords().data());
printtext("%d", e->getAsFace().getBeg().LocalID());
glRasterPos3dv(e->getAsFace().getEnd().Coords().data());
printtext("%d", e->getAsFace().getEnd().LocalID());
}
}
else if( e.GetElementType() == FACE || (e.GetElementType() == CELL && e.GetElementDimension() == 2) )
{
face2gl f = DrawFace(e);
face.set_color();
......@@ -798,7 +836,7 @@ void DrawElement(Element e, color_t face, color_t edge, color_t node, bool print
ElementArray<Edge> edges = e->getEdges();
glBegin(GL_POINTS);
for(ElementArray<Node>::iterator it = nodes.begin(); it != nodes.end(); ++it)
glVertex3dv(it->Coords().data());
glVertexNdv(it->Coords().data(),it->GetMeshLink()->GetDimensions());
glEnd();
glColor3f(0, 0, 0);
//glDisable(GL_DEPTH_TEST);
......@@ -839,7 +877,7 @@ void DrawElement(Element e, color_t face, color_t edge, color_t node, bool print
ElementArray<Node> nodes = e->getNodes();
glBegin(GL_POINTS);
for(ElementArray<Node>::iterator it = nodes.begin(); it != nodes.end(); ++it)
glVertex3dv(it->Coords().data());
glVertexNdv(it->Coords().data(),it->GetMeshLink()->GetDimensions());
glEnd();
if (print_adj)
......@@ -1164,13 +1202,13 @@ void draw_screen()
else
{
if( oclipper )
if( oclipper || bclipper )
{
if( clipupdate )
{
if( current_picker != NULL ) {delete current_picker; current_picker = NULL;}
oclipper->clip_plane(p,n);
if( oclipper ) oclipper->clip_plane(p,n);
clipupdate = false;
clipboxupdate = true;
}
......@@ -1178,7 +1216,7 @@ void draw_screen()
if( !interactive && clipboxupdate )
{
clip_boundary.clear();
oclipper->gen_clip(clip_boundary,n,elevation);
if( oclipper ) oclipper->gen_clip(clip_boundary,n,elevation);
bclipper->clip_plane(p,n);
bclipper->gen_clip(clip_boundary,p,n,elevation);
clipboxupdate = false;
......@@ -1215,13 +1253,13 @@ void draw_screen()
INMOST_DATA_ENUM_TYPE bpace = std::max<INMOST_DATA_ENUM_TYPE>(1,std::min<INMOST_DATA_ENUM_TYPE>(15,bclipper->size()/100));
glColor4f(0.6,0.6,0.6,1);
if (isColorBarEnabled()) GetColorBar()->BindTexture();
oclipper->draw_clip(opace,n,elevation);
if( oclipper ) oclipper->draw_clip(opace,n,elevation);
bclipper->draw_clip(bpace,p,n);
if (isColorBarEnabled()) GetColorBar()->UnbindTexture();
glColor4f(0,0,0,1);
if (drawedges)
{
oclipper->draw_clip_edges(opace, n,elevation);
if( oclipper ) oclipper->draw_clip_edges(opace, n,elevation);
bclipper->draw_clip_edges(bpace);
}
......@@ -1332,8 +1370,8 @@ void draw_screen()
glBegin(GL_LINES);
for(ElementArray<Edge>::iterator it = added_edges.begin(); it != added_edges.end(); ++it)
{
glVertex3dv(it->getBeg()->Coords().data());
glVertex3dv(it->getEnd()->Coords().data());
glVertexNdv(it->getBeg()->Coords().data(),it->GetMeshLink()->GetDimensions());
glVertexNdv(it->getEnd()->Coords().data(),it->GetMeshLink()->GetDimensions());
}
glEnd();
}
......@@ -1644,7 +1682,10 @@ void draw_screen()
for (ElementArray<Element>::iterator jt = elems.begin(); jt != elems.end(); ++jt) if (jt->HaveData(source_tag) && (jt->GetDataSize(source_tag) > comp || comp == ENUMUNDEF))
{
jt->Centroid(cnt);
dist = (cnt[0] - coords[0])*(cnt[0] - coords[0]) + (cnt[1] - coords[1])*(cnt[1] - coords[1]) + (cnt[2] - coords[2])*(cnt[2] - coords[2]);
if( mesh->GetDimensions() == 2 )
dist = (cnt[0] - coords[0])*(cnt[0] - coords[0]) + (cnt[1] - coords[1])*(cnt[1] - coords[1]);
else
dist = (cnt[0] - coords[0])*(cnt[0] - coords[0]) + (cnt[1] - coords[1])*(cnt[1] - coords[1]) + (cnt[2] - coords[2])*(cnt[2] - coords[2]);
wgt = 1.0 / (dist + 1.0e-8);
if (source_tag.GetDataType() == DATA_REAL)
{
......@@ -1944,7 +1985,7 @@ void svg_draw(std::ostream & file)
else
{
if( oclipper )
if( oclipper || bclipper )
{
/*
std::vector<face2gl> temp_boundary;
......@@ -2080,15 +2121,30 @@ int main(int argc, char ** argv)
printf("Calculating bounds.\n");
tt = Timer();
for(Mesh::iteratorNode n = mesh->BeginNode(); n != mesh->EndNode(); n++)
if( mesh->GetDimensions() == 2 )
{
Storage::real_array c = n->Coords();
if( c[0] > sright ) sright = c[0];
if( c[0] < sleft ) sleft = c[0];
if( c[1] > stop ) stop = c[1];
if( c[1] < sbottom ) sbottom = c[1];
if( c[2] > sfar ) sfar = c[2];
if( c[2] < snear ) snear = c[2];
for(Mesh::iteratorNode n = mesh->BeginNode(); n != mesh->EndNode(); n++)
{
Storage::real_array c = n->Coords();
if( c[0] > sright ) sright = c[0];
if( c[0] < sleft ) sleft = c[0];
if( c[1] > stop ) stop = c[1];
if( c[1] < sbottom ) sbottom = c[1];
}
sfar = -1, snear = 1;
}
else
{
for(Mesh::iteratorNode n = mesh->BeginNode(); n != mesh->EndNode(); n++)
{
Storage::real_array c = n->Coords();
if( c[0] > sright ) sright = c[0];
if( c[0] < sleft ) sleft = c[0];
if( c[1] > stop ) stop = c[1];
if( c[1] < sbottom ) sbottom = c[1];
if( c[2] > sfar ) sfar = c[2];
if( c[2] < snear ) snear = c[2];
}
}
printf("Done. Time %lg\n",Timer()-tt);
printf("%g:%g %g:%g %g:%g\n",sleft,sright,sbottom,stop,snear,sfar);
......@@ -2190,7 +2246,8 @@ int main(int argc, char ** argv)
printf("Prepearing interactive mesh clipper.\n");
//tt = Timer();
oclipper = new clipper(mesh);
if( mesh->GetDimensions() != 2 )
oclipper = new clipper(mesh);
bclipper = new bnd_clipper(mesh,boundary_faces.data(),(unsigned)boundary_faces.size());
clipupdate = true;
//printf("Done. Time %g\n",Timer() - tt);
......
......@@ -444,12 +444,12 @@ namespace INMOST
//CHECK THIS!
if( order_singular_values )
{
Var temp;
for(i = 0; i < (int)n; i++)
{
k = i;
for(j = i+1; j < (int)n; ++j)
if( Sigma(k,k) < Sigma(j,j) ) k = j;
Var temp;
if( Sigma(k,k) > Sigma(i,i) )
{
temp = Sigma(k,k);
......
......@@ -159,8 +159,8 @@ namespace INMOST
{
case Element::Tri:
case Element::Quad:
case Element::MultiLine:
case Element::Polygon:
//case Element::MultiLine:
//case Element::Polygon:
case Element::Tet:
case Element::Hex:
case Element::Pyramid:
......@@ -172,6 +172,15 @@ namespace INMOST
for(ElementArray<Node>::iterator jt = nodes.begin(); jt != nodes.end(); jt++)
values.push_back(jt->IntegerDF(set_id));
break;
}
case Element::MultiLine:
case Element::Polygon:
{
ElementArray<Node> nodes = it->getNodes();
values.push_back(static_cast<integer>(nodes.size()));
for(ElementArray<Node>::iterator jt = nodes.begin(); jt != nodes.end(); jt++)
values.push_back(jt->IntegerDF(set_id));
break;
}
/*
case Element::Prism:
......@@ -1329,6 +1338,8 @@ safe_output:
case 2: std::cout << "Grid has undetermined dimension" << std::endl; break;
}
}
if( grid_is_2d && old_nodes.empty() ) SetDimensions(2);
{
if( verbosity > 0 ) printf("Reading %d cells.\n",ncells);
......
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