Commit e2844e42 authored by chrmaier's avatar chrmaier

Assign properties on face elements for vtk meshes

parent 9088109a
...@@ -56,6 +56,7 @@ namespace INMOST ...@@ -56,6 +56,7 @@ namespace INMOST
{ {
switch(t) switch(t)
{ {
case Element::Line: return 3;
case Element::Tri: return 5; case Element::Tri: return 5;
case Element::Quad: return 9; case Element::Quad: return 9;
case Element::MultiLine: return 4; case Element::MultiLine: return 4;
...@@ -75,6 +76,7 @@ namespace INMOST ...@@ -75,6 +76,7 @@ namespace INMOST
{ {
switch(t) switch(t)
{ {
case Element::Line: return 2;
case Element::Tri: return 3; case Element::Tri: return 3;
case Element::Quad: return 4; case Element::Quad: return 4;
case Element::MultiLine: return ENUMUNDEF; case Element::MultiLine: return ENUMUNDEF;
...@@ -106,12 +108,14 @@ namespace INMOST ...@@ -106,12 +108,14 @@ namespace INMOST
fprintf(f,"ASCII\n"); fprintf(f,"ASCII\n");
fprintf(f,"DATASET UNSTRUCTURED_GRID\n"); fprintf(f,"DATASET UNSTRUCTURED_GRID\n");
//ReorderEmpty(CELL | NODE); //ReorderEmpty(CELL | NODE);
Tag set_id = CreateTag("TEMPORARY_ELEMENT_ID",DATA_INTEGER,CELL | NODE,NONE,1); Tag set_id = CreateTag("TEMPORARY_ELEMENT_ID",DATA_INTEGER,CELL |FACE| NODE,NONE,1);
Storage::integer cur_num = 0; Storage::integer cur_num = 0;
for(Mesh::iteratorNode it = BeginNode(); it != EndNode(); ++it) it->IntegerDF(set_id) = cur_num++; for(Mesh::iteratorNode it = BeginNode(); it != EndNode(); ++it) it->IntegerDF(set_id) = cur_num++;
cur_num = 0; cur_num = 0;
for(Mesh::iteratorCell it = BeginCell(); it != EndCell(); ++it) it->IntegerDF(set_id) = cur_num++; for(Mesh::iteratorCell it = BeginCell(); it != EndCell(); ++it) it->IntegerDF(set_id) = cur_num++;
fprintf(f,"POINTS %u double\n",NumberOfNodes()); cur_num = 0;
for (Mesh::iteratorFace it = BeginFace(); it != EndFace(); ++it) it->IntegerDF(set_id) = cur_num++;
fprintf(f, "POINTS %u double\n", NumberOfNodes());
for(Mesh::iteratorNode it = BeginNode(); it != EndNode(); it++) for(Mesh::iteratorNode it = BeginNode(); it != EndNode(); it++)
{ {
Storage::real_array coords = it->RealArray(CoordsTag()); Storage::real_array coords = it->RealArray(CoordsTag());
...@@ -210,7 +214,34 @@ safe_output: ...@@ -210,7 +214,34 @@ safe_output:
default: printf("This should not happen %s\n",Element::GeometricTypeName(it->GetGeometricType())); default: printf("This should not happen %s\n",Element::GeometricTypeName(it->GetGeometricType()));
} }
} }
fprintf(f,"CELLS %u %ld\n",NumberOfCells(),values.size()); for (Mesh::iteratorFace it = BeginFace(); it != EndFace(); it++)
{
switch (it->GetGeometricType())
{
case Element::Line:
{
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::Tri:
case Element::Quad:
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;
}
default: printf("This should not happen %s\n", Element::GeometricTypeName(it->GetGeometricType()));
}
}
fprintf(f,"CELLS %u %ld\n",NumberOfCells() + NumberOfFaces(),values.size());
for(dynarray<Storage::integer,64>::size_type i = 0; i < values.size(); i++) for(dynarray<Storage::integer,64>::size_type i = 0; i < values.size(); i++)
{ {
fprintf(f,"%d ",values[i]); fprintf(f,"%d ",values[i]);
...@@ -218,7 +249,7 @@ safe_output: ...@@ -218,7 +249,7 @@ safe_output:
} }
fprintf(f,"\n"); fprintf(f,"\n");
} }
fprintf(f,"CELL_TYPES %u\n",NumberOfCells()); fprintf(f,"CELL_TYPES %u\n",NumberOfCells() + NumberOfFaces());
for(Mesh::iteratorCell it = BeginCell(); it != EndCell(); it++) for(Mesh::iteratorCell it = BeginCell(); it != EndCell(); it++)
{ {
INMOST_DATA_ENUM_TYPE nnodes = VtkElementNodes(it->GetGeometricType()); INMOST_DATA_ENUM_TYPE nnodes = VtkElementNodes(it->GetGeometricType());
...@@ -227,6 +258,14 @@ safe_output: ...@@ -227,6 +258,14 @@ safe_output:
else //number of nodes mismatch with expected - some topology checks must be off else //number of nodes mismatch with expected - some topology checks must be off
fprintf(f,"%d\n",VtkElementType(Element::MultiPolygon)); fprintf(f,"%d\n",VtkElementType(Element::MultiPolygon));
} }
for (Mesh::iteratorFace it = BeginFace(); it != EndFace(); it++)
{
INMOST_DATA_ENUM_TYPE nnodes = VtkElementNodes(it->GetGeometricType());
if (nnodes == ENUMUNDEF || nnodes == it->nbAdjElements(NODE)) //nodes match - output correct type
fprintf(f, "%d\n", VtkElementType(it->GetGeometricType()));
else //number of nodes mismatch with expected - some topology checks must be off
fprintf(f, "%d\n", VtkElementType(Element::MultiPolygon));
}
DeleteTag(set_id); DeleteTag(set_id);
{ {
std::vector<std::string> tag_names; std::vector<std::string> tag_names;
...@@ -236,8 +275,8 @@ safe_output: ...@@ -236,8 +275,8 @@ safe_output:
{ {
Tag t = GetTag(tag_names[i]); Tag t = GetTag(tag_names[i]);
//printf("%s %d %d %d\n",tag_names[i].c_str(),t.isDefined(CELL),!t.isSparse(CELL),t.GetDataType() != DATA_BULK); //printf("%s %d %d %d\n",tag_names[i].c_str(),t.isDefined(CELL),!t.isSparse(CELL),t.GetDataType() != DATA_BULK);
if( t.isDefined(CELL) && if ((t.isDefined(CELL) && !t.isSparse(CELL)
!t.isSparse(CELL) && || t.isDefined(FACE) ) &&
t.GetDataType() != DATA_BULK && t.GetDataType() != DATA_BULK &&
t.GetDataType() != DATA_REFERENCE && t.GetDataType() != DATA_REFERENCE &&
t.GetDataType() != DATA_REMOTE_REFERENCE && t.GetDataType() != DATA_REMOTE_REFERENCE &&
...@@ -251,7 +290,7 @@ safe_output: ...@@ -251,7 +290,7 @@ safe_output:
} }
} }
if( !tags.empty() ) fprintf(f,"CELL_DATA %u\n",NumberOfCells()); if( !tags.empty() ) fprintf(f,"CELL_DATA %u\n",NumberOfCells() + NumberOfFaces());
for(unsigned int i = 0; i < tags.size(); i++) for(unsigned int i = 0; i < tags.size(); i++)
{ {
unsigned int comps = tags[i].GetSize(); unsigned int comps = tags[i].GetSize();
...@@ -271,42 +310,101 @@ safe_output: ...@@ -271,42 +310,101 @@ safe_output:
) type_str = "double"; ) type_str = "double";
fprintf(f,"SCALARS %s %s %d\n",tags[i].GetTagName().c_str(),type_str.c_str(),comps); fprintf(f,"SCALARS %s %s %d\n",tags[i].GetTagName().c_str(),type_str.c_str(),comps);
fprintf(f,"LOOKUP_TABLE default\n"); fprintf(f,"LOOKUP_TABLE default\n");
for(Mesh::iteratorCell it = BeginCell(); it != EndCell(); it++) for (Mesh::iteratorCell it = BeginCell(); it != EndCell(); it++)
{ {
switch( tags[i].GetDataType() ) switch (tags[i].GetDataType())
{ {
case DATA_REAL: case DATA_REAL:
{ {
Storage::real_array arr = it->RealArray(tags[i]); if (tags[i].isDefined(CELL))
for(unsigned int m = 0; m < comps; m++) {
{ Storage::real_array arr = it->RealArray(tags[i]);
double val = static_cast<double>(arr[m]); for (unsigned int m = 0; m < comps; m++)
fprintf(f,"%14e ",isbad(val) ? -0.9999E30 : val); {
} double val = static_cast<double>(arr[m]);
fprintf(f,"\n"); fprintf(f, "%14e ", isbad(val) ? -0.9999E30 : val);
} }
}
else for (unsigned int m = 0; m < comps; m++) fprintf(f, "0.0");
fprintf(f, "\n");
}
break; break;
case DATA_INTEGER: case DATA_INTEGER:
{ {
Storage::integer_array arr = it->IntegerArray(tags[i]); if (tags[i].isDefined(CELL))
for(unsigned int m = 0; m < comps; m++) fprintf(f,"%d ",arr[m]); {
fprintf(f,"\n"); Storage::integer_array arr = it->IntegerArray(tags[i]);
} for (unsigned int m = 0; m < comps; m++) fprintf(f, "%d ", arr[m]);
}
else for (unsigned int m = 0; m < comps; m++) fprintf(f, "0");
fprintf(f, "\n");
}
break; break;
#if defined(USE_AUTODIFF) #if defined(USE_AUTODIFF)
case DATA_VARIABLE: case DATA_VARIABLE:
{ {
Storage::var_array arr = it->VariableArray(tags[i]); if (tags[i].isDefined(CELL))
for(unsigned int m = 0; m < comps; m++) {
{ Storage::var_array arr = it->VariableArray(tags[i]);
double val = static_cast<double>(arr[m].GetValue()); for (unsigned int m = 0; m < comps; m++)
fprintf(f,"%14e ",isbad(val) ? -0.9999E30 : val); {
} double val = static_cast<double>(arr[m].GetValue());
fprintf(f,"\n"); fprintf(f, "%14e ", isbad(val) ? -0.9999E30 : val);
} }
break; }
else fprintf(f, "0.0");
fprintf(f, "\n");
}
break;
#endif #endif
default: continue; default: continue;
}
}
for (Mesh::iteratorFace it = BeginFace(); it != EndFace(); it++)
{
switch (tags[i].GetDataType())
{
case DATA_REAL:
{
if (tags[i].isDefined(FACE))
{
Storage::real_array arr = it->RealArray(tags[i]);
for (unsigned int m = 0; m < comps; m++) fprintf(f, "%14e ", arr[m]);
}
else for (unsigned int m = 0; m < comps; m++) fprintf(f, "0.0");
fprintf(f, "\n");
}
break;
case DATA_INTEGER:
{
if (tags[i].isDefined(FACE))
{
Storage::integer_array arr = it->IntegerArray(tags[i]);
for (unsigned int m = 0; m < comps; m++) fprintf(f, "%d ", arr[m]);
}
else for (unsigned int m = 0; m < comps; m++) fprintf(f, "0");
fprintf(f, "\n");
}
break;
#if defined(USE_AUTODIFF)
case DATA_VARIABLE:
{
if (tags[i].isDefined(FACE))
{
Storage::var_array arr = it->VariableArray(tags[i]);
for (unsigned int m = 0; m < comps; m++)
{
double val = static_cast<double>(arr[m].GetValue());
fprintf(f, "%14e ", isbad(val) ? -0.9999E30 : val);
}
}
else fprintf(f, "0.0");
fprintf(f, "\n");
}
break;
#endif
default: continue;
} }
} }
} }
......
...@@ -298,8 +298,12 @@ namespace INMOST ...@@ -298,8 +298,12 @@ namespace INMOST
reader.Report("Sorry, no rule to convert %d edges into a cell",subarr.size()); reader.Report("Sorry, no rule to convert %d edges into a cell",subarr.size());
throw BadFile; throw BadFile;
} }
else if( subtype == FACE ) else if (subtype == FACE)
elems->push_back(CreateCell(subarr.Convert<Face>()).first.GetHandle()); {
Cell c = CreateCell(subarr.Convert<Face>()).first;
if (repair_orientation) c.FixEdgeOrder();
elems->push_back(c.GetHandle());
}
break; break;
} }
} }
......
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