Added namespaces, copyright and a bit of cleaning...
This commit is contained in:
parent
f456e8aca3
commit
5fab3cefd1
|
@ -1,16 +1,35 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* VCGLib o o *
|
||||||
|
* Visual and Computer Graphics Library o o *
|
||||||
|
* _ O _ *
|
||||||
|
* Copyright(C) 2004 \/)\/ *
|
||||||
|
* Visual Computing Lab /\/| *
|
||||||
|
* ISTI - Italian National Research Council | *
|
||||||
|
* \ *
|
||||||
|
* All rights reserved. *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||||
|
* for more details. *
|
||||||
|
* *
|
||||||
|
****************************************************************************/
|
||||||
#ifndef MESH_TO_MATRIX
|
#ifndef MESH_TO_MATRIX
|
||||||
#define MESH_TO_MATRIX
|
#define MESH_TO_MATRIX
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <list>
|
|
||||||
#include <utility>
|
|
||||||
#include <Eigen/Dense>
|
|
||||||
#include <vcg/complex/algorithms/update/topology.h>
|
|
||||||
#include <vcg/complex/complex.h>
|
#include <vcg/complex/complex.h>
|
||||||
|
#include <vcg/complex/algorithms/update/topology.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace vcg {
|
namespace vcg {
|
||||||
|
namespace tri {
|
||||||
template < typename TriMeshType >
|
template < typename TriMeshType >
|
||||||
class MeshToMatrix
|
class MeshToMatrix
|
||||||
{
|
{
|
||||||
|
@ -108,11 +127,12 @@ class MeshToMatrix
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// return mesh as vactor of vertices and faces
|
// return mesh as vector of vertices and faces
|
||||||
static void GetTriMeshData(const TriMeshType &mesh,
|
static void GetTriMeshData(const TriMeshType &mesh,
|
||||||
Eigen::MatrixXi &faces,
|
Eigen::MatrixXi &faces,
|
||||||
Eigen::MatrixXd &vert)
|
Eigen::MatrixXd &vert)
|
||||||
{
|
{
|
||||||
|
tri::RequireCompactness(mesh);
|
||||||
// create eigen matrix of vertices
|
// create eigen matrix of vertices
|
||||||
vert=Eigen::MatrixXd(mesh.VN(), 3);
|
vert=Eigen::MatrixXd(mesh.VN(), 3);
|
||||||
|
|
||||||
|
@ -125,13 +145,9 @@ public:
|
||||||
faces=Eigen::MatrixXi(mesh.FN(), 3);
|
faces=Eigen::MatrixXi(mesh.FN(), 3);
|
||||||
|
|
||||||
// copy faces
|
// copy faces
|
||||||
const VertexType *v0 = &mesh.vert[0];
|
|
||||||
for (int i = 0; i < mesh.FN(); i++)
|
for (int i = 0; i < mesh.FN(); i++)
|
||||||
for (int j = 0; j < 3; j++)
|
for (int j = 0; j < 3; j++)
|
||||||
{
|
faces(i,j) = (int)tri::Index(mesh,mesh.face[i].cV(j));
|
||||||
faces(i,j) = (int)(mesh.face[i].cV(j) - v0);
|
|
||||||
assert(faces(i,j) >= 0 && faces(i,j) < mesh.VN());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// return normals of the mesh
|
// return normals of the mesh
|
||||||
|
@ -159,10 +175,7 @@ public:
|
||||||
Eigen::MatrixXi &FFp,
|
Eigen::MatrixXi &FFp,
|
||||||
Eigen::MatrixXi &FFi)
|
Eigen::MatrixXi &FFi)
|
||||||
{
|
{
|
||||||
vcg::tri::UpdateTopology<TriMeshType>::FaceFace(mesh);
|
tri::UpdateTopology<TriMeshType>::FaceFace(mesh);
|
||||||
// FFp = Eigen::PlainObjectBase<int>::Constant(mesh.FN(),3,-1);
|
|
||||||
// FFi = Eigen::PlainObjectBase<int>::Constant(mesh.FN(),3,-1);
|
|
||||||
|
|
||||||
FFp = Eigen::MatrixXi(mesh.FN(),3);
|
FFp = Eigen::MatrixXi(mesh.FN(),3);
|
||||||
FFi = Eigen::MatrixXi(mesh.FN(),3);
|
FFi = Eigen::MatrixXi(mesh.FN(),3);
|
||||||
|
|
||||||
|
@ -174,17 +187,12 @@ public:
|
||||||
{
|
{
|
||||||
FFp(i,j)=-1;
|
FFp(i,j)=-1;
|
||||||
FFi(i,j)=-1;
|
FFi(i,j)=-1;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
int AdjF_Index=vcg::tri::Index(mesh,AdjF);
|
{
|
||||||
int OppF_Index=mesh.face[i].FFi(j);
|
FFp(i,j)=tri::Index(mesh,AdjF);
|
||||||
|
FFi(i,j)=mesh.face[i].FFi(j);
|
||||||
|
}
|
||||||
FFp(i,j)=AdjF_Index;
|
|
||||||
FFi(i,j)=OppF_Index;
|
|
||||||
|
|
||||||
assert(AdjF_Index >= 0 && AdjF_Index < mesh.FN());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,20 +207,8 @@ public:
|
||||||
GetTriMeshData(mesh,faces,vert);
|
GetTriMeshData(mesh,faces,vert);
|
||||||
GetTriEdgeAdjacency(vert,faces,EV,FE,EF);
|
GetTriEdgeAdjacency(vert,faces,EV,FE,EF);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eigen::Vector3d VectorFromCoord(const CoordType &v)
|
|
||||||
{
|
|
||||||
// create eigen vector
|
|
||||||
Eigen::Vector3d c;
|
|
||||||
|
|
||||||
// copy coordinates
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
c(i) = v[i];
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
} // end namespace tri
|
||||||
|
} // end namespace vcg
|
||||||
#endif // MESH_TO_MATRIX_CONVERTER
|
#endif // MESH_TO_MATRIX_CONVERTER
|
||||||
|
|
Loading…
Reference in New Issue