Skip to content

Commit

Permalink
[SofaLoader] ADD support to load VTK polylines in legacy formated files
Browse files Browse the repository at this point in the history
# Conflicts:
#	SofaKernel/framework/sofa/core/loader/MeshLoader.cpp
#	SofaKernel/framework/sofa/core/loader/MeshLoader.h
  • Loading branch information
lionel untereiner authored and guparan committed Feb 2, 2018
1 parent 5d6c283 commit 3f9d024
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
16 changes: 11 additions & 5 deletions SofaKernel/framework/sofa/core/loader/MeshLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using namespace sofa::defaulttype;

MeshLoader::MeshLoader() : BaseLoader()
, d_positions(initData(&d_positions, "position", "Vertices of the mesh loaded"))
, d_polylines(initData(&d_polylines, "polylines", "Polylines of the mesh loaded"))
, d_edges(initData(&d_edges, "edges", "Edges of the mesh loaded"))
, d_triangles(initData(&d_triangles, "triangles", "Triangles of the mesh loaded"))
, d_quads(initData(&d_quads, "quads", "Quads of the mesh loaded"))
Expand Down Expand Up @@ -82,6 +83,7 @@ MeshLoader::MeshLoader() : BaseLoader()
d_transformation.setDirtyValue();

d_positions.setPersistent(false);
d_polylines.setPersistent(false);
d_edges.setPersistent(false);
d_triangles.setPersistent(false);
d_quads.setPersistent(false);
Expand Down Expand Up @@ -270,17 +272,17 @@ void MeshLoader::updateElements()
Triangle tri1(p[0], p[1], p[2]);
Triangle tri2(p[4], p[3], p[5]);

if (eSetQuad.insert(uniqueOrder(quad1)).second) // the element was inserted
if (eSetQuad.insert(uniqueOrder(quad1)).second) // the element was inserted
{
quads.push_back(quad1);
++nbnewQuad;
}
if (eSetQuad.insert(uniqueOrder(quad2)).second) // the element was inserted
if (eSetQuad.insert(uniqueOrder(quad2)).second) // the element was inserted
{
quads.push_back(quad2);
++nbnewQuad;
}
if (eSetQuad.insert(uniqueOrder(quad3)).second) // the element was inserted
if (eSetQuad.insert(uniqueOrder(quad3)).second) // the element was inserted
{
quads.push_back(quad3);
++nbnewQuad;
Expand Down Expand Up @@ -332,7 +334,7 @@ void MeshLoader::updateElements()
Triangle tri3(p[3], p[4], p[2]);
Triangle tri4(p[0], p[4], p[3]);

if (eSetQuad.insert(uniqueOrder(quad)).second) // the element was inserted
if (eSetQuad.insert(uniqueOrder(quad)).second) // the element was inserted
{
quads.push_back(quad);
++nbnewQuad;
Expand Down Expand Up @@ -381,7 +383,7 @@ void MeshLoader::updateElements()
Triangle e2(t[0], t[1], t[3]);
Triangle e3(t[0], t[3], t[2]);
Triangle e4(t[1], t[2], t[3]); //vtk ordering http://www.vtk.org/wp-content/uploads/2015/04/file-formats.pdf
if (eSet.insert(uniqueOrder(e1)).second) // the element was inserted
if (eSet.insert(uniqueOrder(e1)).second) // the element was inserted
{
triangles.push_back(e1);
++nbnew;
Expand Down Expand Up @@ -685,6 +687,10 @@ void MeshLoader::addPosition(helper::vector<sofa::defaulttype::Vec<3, SReal> >*
addPosition(pPositions, sofa::defaulttype::Vec<3, SReal>(x, y, z));
}

void MeshLoader::addPolyline(helper::vector<Polyline>* pPolylines, Polyline p)
{
pPolylines->push_back(p);
}

void MeshLoader::addEdge(helper::vector<Edge >* pEdges, const Edge& p)
{
Expand Down
6 changes: 6 additions & 0 deletions SofaKernel/framework/sofa/core/loader/MeshLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class SOFA_CORE_API MeshLoader : public BaseLoader
the 3 integers specifying the degree of the element in the x, y and z directions, the 3 integers specifying the position within this hexahedron (i.e. 121 ).. */
typedef sofa::helper::fixed_array<PointID, 8> HighOrderHexahedronPosition;

typedef sofa::helper::vector<PointID> Polyline;


protected:
Expand Down Expand Up @@ -130,6 +131,9 @@ class SOFA_CORE_API MeshLoader : public BaseLoader
// Point coordinates in 3D in double.
Data< helper::vector<sofa::defaulttype::Vec<3, SReal> > > d_positions;

//Tab of 1D elements
Data< helper::vector< Polyline > > d_polylines;

// Tab of 2D elements composition
Data< helper::vector< Edge > > d_edges;
Data< helper::vector< Triangle > > d_triangles;
Expand Down Expand Up @@ -187,6 +191,8 @@ class SOFA_CORE_API MeshLoader : public BaseLoader
void addPosition(helper::vector< sofa::defaulttype::Vec<3, SReal> >* pPositions, const sofa::defaulttype::Vec<3, SReal>& p);
void addPosition(helper::vector<sofa::defaulttype::Vec<3, SReal> >* pPositions, SReal x, SReal y, SReal z);

void addPolyline(helper::vector<Polyline>* pPolylines, Polyline p);

void addEdge(helper::vector<Edge>* pEdges, const Edge& p);
void addEdge(helper::vector<Edge>* pEdges, unsigned int p0, unsigned int p1);

Expand Down
14 changes: 10 additions & 4 deletions SofaKernel/modules/SofaLoader/MeshVTKLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ bool MeshVTKLoader::setInputsMesh()

d_normals.endEdit();


helper::vector<Polyline >& my_polylines = *(d_polylines.beginEdit());
helper::vector<Edge >& my_edges = *(d_edges.beginEdit());
helper::vector<Triangle >& my_triangles = *(d_triangles.beginEdit());
helper::vector<Quad >& my_quads = *(d_quads.beginEdit());
Expand Down Expand Up @@ -368,12 +370,16 @@ bool MeshVTKLoader::setInputsMesh()
addEdge(&my_edges, inFP[i + 0], inFP[i + 1]);
break;
case 4: // POLY_LINE
{
numSubPolyLines.push_back(nv);
for (int v = 0; v < nv - 1; ++v)
std::vector<PointID> points;
for (int v = 0; v < nv; ++v)
{
addEdge(&my_edges, inFP[i + v + 0], inFP[i + v + 1]);
points.push_back(inFP[i + v]);
}
break;
addPolyline(&my_polylines, points);
}
break;
case 5: // TRIANGLE
addTriangle(&my_triangles, inFP[i + 0], inFP[i + 1], inFP[i + 2]);
break;
Expand Down Expand Up @@ -445,7 +451,6 @@ bool MeshVTKLoader::setInputsMesh()
}
}
}

break;
case 24: // QUADRATIC Tetrahedron
addTetrahedron(&my_tetrahedra, inFP[i + 0], inFP[i + 1], inFP[i + 2], inFP[i + 3]);
Expand Down Expand Up @@ -527,6 +532,7 @@ bool MeshVTKLoader::setInputsMesh()
delete reader->inputCellTypes;
}

d_polygons.endEdit();
d_edges.endEdit();
d_triangles.endEdit();
d_quads.endEdit();
Expand Down

0 comments on commit 3f9d024

Please sign in to comment.