Refactored a bit the extended marching cube core. Cleaned up a bit the trivial walker to be used by both of them. Updated the sample for marching cube.
This commit is contained in:
parent
3a9a72c098
commit
e94cfb5a43
|
@ -38,7 +38,7 @@ class MyVertex;
|
||||||
struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
|
struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
|
||||||
Use<MyFace> ::AsFaceType>{};
|
Use<MyFace> ::AsFaceType>{};
|
||||||
|
|
||||||
class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f>{};
|
class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags>{};
|
||||||
class MyFace : public Face< MyUsedTypes, face::VertexRef, face::BitFlags> {};
|
class MyFace : public Face< MyUsedTypes, face::VertexRef, face::BitFlags> {};
|
||||||
|
|
||||||
class MyMesh : public vcg::tri::TriMesh< std::vector< MyVertex>, std::vector< MyFace > > {};
|
class MyMesh : public vcg::tri::TriMesh< std::vector< MyVertex>, std::vector< MyFace > > {};
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace vcg
|
||||||
class EMCLookUpTable
|
class EMCLookUpTable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static const int EdgeTable(unsigned char cubetype)
|
static int EdgeTable(unsigned char cubetype)
|
||||||
{
|
{
|
||||||
static const int edgeTable[256]=
|
static const int edgeTable[256]=
|
||||||
{
|
{
|
||||||
|
@ -904,7 +904,7 @@ namespace vcg
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
static const int PolyTable(unsigned int cubetype, int u)
|
static int PolyTable(unsigned int cubetype, int u)
|
||||||
{
|
{
|
||||||
static const int polyTable[8][16] =
|
static const int polyTable[8][16] =
|
||||||
{
|
{
|
||||||
|
|
|
@ -348,13 +348,13 @@ namespace vcg
|
||||||
//--A[i][2] = normals[i][2];
|
//--A[i][2] = normals[i][2];
|
||||||
//--b[i] = (points[i] * normals[i]);
|
//--b[i] = (points[i] * normals[i]);
|
||||||
A(i,0) = normals[i][0];
|
A(i,0) = normals[i][0];
|
||||||
A(i,0) = normals[i][1];
|
A(i,1) = normals[i][1];
|
||||||
A(i,0) = normals[i][2];
|
A(i,2) = normals[i][2];
|
||||||
b(i) = (points[i] * normals[i]);
|
b(i) = (points[i] * normals[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SVD of matrix A
|
// SVD of matrix A
|
||||||
Eigen::JacobiSVD<Eigen::MatrixXd> svd(A);
|
Eigen::JacobiSVD<Eigen::MatrixXd> svd(A, Eigen::ComputeThinU | Eigen::ComputeThinV);
|
||||||
Eigen::MatrixXd sol(3,1);
|
Eigen::MatrixXd sol(3,1);
|
||||||
sol=svd.solve(b);
|
sol=svd.solve(b);
|
||||||
|
|
||||||
|
@ -386,7 +386,7 @@ namespace vcg
|
||||||
|
|
||||||
// transform x to world coords
|
// transform x to world coords
|
||||||
//--CoordType point((ScalarType) x[0], (ScalarType) x[1], (ScalarType) x[2]);
|
//--CoordType point((ScalarType) x[0], (ScalarType) x[1], (ScalarType) x[2]);
|
||||||
CoordType point((ScalarType) sol[0], (ScalarType) sol[1], (ScalarType) sol[2]);
|
CoordType point((ScalarType) sol(0), (ScalarType) sol(1), (ScalarType) sol(2));
|
||||||
point += center;
|
point += center;
|
||||||
|
|
||||||
// Safety check if the feature point found by svd is
|
// Safety check if the feature point found by svd is
|
||||||
|
@ -411,15 +411,13 @@ namespace vcg
|
||||||
*/
|
*/
|
||||||
void FlipEdges()
|
void FlipEdges()
|
||||||
{
|
{
|
||||||
size_t i;
|
|
||||||
std::vector< LightEdge > edges;
|
std::vector< LightEdge > edges;
|
||||||
FaceIterator f_iter = _mesh->face.begin();
|
for (FaceIterator fi = _mesh->face.begin(); fi!=_mesh->face.end(); fi++)
|
||||||
FaceIterator f_end = _mesh->face.end();
|
|
||||||
for (i=0; f_iter!=f_end; f_iter++, i++)
|
|
||||||
{
|
{
|
||||||
if (f_iter->V(1) > f_iter->V(0)) edges.push_back( LightEdge(i,0) );
|
size_t i = tri::Index(*_mesh,*fi);
|
||||||
if (f_iter->V(2) > f_iter->V(1)) edges.push_back( LightEdge(i,1) );
|
if (fi->V(1) > fi->V(0)) edges.push_back( LightEdge(i,0) );
|
||||||
if (f_iter->V(0) > f_iter->V(2)) edges.push_back( LightEdge(i,2) );
|
if (fi->V(2) > fi->V(1)) edges.push_back( LightEdge(i,1) );
|
||||||
|
if (fi->V(0) > fi->V(2)) edges.push_back( LightEdge(i,2) );
|
||||||
}
|
}
|
||||||
vcg::tri::UpdateTopology< TRIMESH_TYPE >::FaceFace( *_mesh );
|
vcg::tri::UpdateTopology< TRIMESH_TYPE >::FaceFace( *_mesh );
|
||||||
|
|
||||||
|
@ -462,7 +460,10 @@ namespace vcg
|
||||||
|
|
||||||
} // end if (vcg::face::CheckFlipEdge< _Face >(*f, z))
|
} // end if (vcg::face::CheckFlipEdge< _Face >(*f, z))
|
||||||
} // end for( ; e_it!=e_end; e_it++)
|
} // end for( ; e_it!=e_end; e_it++)
|
||||||
}; //end of FlipEdges
|
|
||||||
|
} //end of FlipEdges
|
||||||
|
|
||||||
|
|
||||||
}; // end of class ExtendedMarchingCubes
|
}; // end of class ExtendedMarchingCubes
|
||||||
// /*! @} */
|
// /*! @} */
|
||||||
// end of Doxygen documentation
|
// end of Doxygen documentation
|
||||||
|
|
|
@ -38,7 +38,7 @@ public:
|
||||||
|
|
||||||
Point3i sz; /// Dimensioni griglia come numero di celle per lato
|
Point3i sz; /// Dimensioni griglia come numero di celle per lato
|
||||||
|
|
||||||
const Point3i &ISize() {return sz;}; /// Dimensioni griglia come numero di celle per lato
|
const Point3i &ISize() {return sz;} /// Dimensioni griglia come numero di celle per lato
|
||||||
|
|
||||||
void Init(Point3i _sz)
|
void Init(Point3i _sz)
|
||||||
{
|
{
|
||||||
|
@ -60,6 +60,10 @@ public:
|
||||||
return Vol[x+y*sz[0]+z*sz[0]*sz[1]];
|
return Vol[x+y*sz[0]+z*sz[0]*sz[1]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VOX_TYPE &V(const Point3i &pi) {
|
||||||
|
return Vol[ pi[0] + pi[1]*sz[0] + pi[2]*sz[0]*sz[1] ];
|
||||||
|
}
|
||||||
|
|
||||||
const VOX_TYPE &cV(const int &x,const int &y,const int &z) const {
|
const VOX_TYPE &cV(const int &x,const int &y,const int &z) const {
|
||||||
return Vol[x+y*sz[0]+z*sz[0]*sz[1]];
|
return Vol[x+y*sz[0]+z*sz[0]*sz[1]];
|
||||||
}
|
}
|
||||||
|
@ -70,8 +74,8 @@ typedef enum { XAxis=0,YAxis=1,ZAxis=2} VolumeAxis;
|
||||||
template < class VertexPointerType, VolumeAxis AxisVal >
|
template < class VertexPointerType, VolumeAxis AxisVal >
|
||||||
void GetIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointerType &v, const float thr)
|
void GetIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointerType &v, const float thr)
|
||||||
{
|
{
|
||||||
float f1 = Val(p1.X(), p1.Y(), p1.Z())-thr;
|
float f1 = V(p1).V()-thr;
|
||||||
float f2 = Val(p2.X(), p2.Y(), p2.Z())-thr;
|
float f2 = V(p2).V()-thr;
|
||||||
float u = (float) f1/(f1-f2);
|
float u = (float) f1/(f1-f2);
|
||||||
if(AxisVal==XAxis) v->P().X() = (float) p1.X()*(1-u) + u*p2.X();
|
if(AxisVal==XAxis) v->P().X() = (float) p1.X()*(1-u) + u*p2.X();
|
||||||
else v->P().X() = (float) p1.X();
|
else v->P().X() = (float) p1.X();
|
||||||
|
@ -79,6 +83,8 @@ template < class VertexPointerType, VolumeAxis AxisVal >
|
||||||
else v->P().Y() = (float) p1.Y();
|
else v->P().Y() = (float) p1.Y();
|
||||||
if(AxisVal==ZAxis) v->P().Z() = (float) p1.Z()*(1-u) + u*p2.Z();
|
if(AxisVal==ZAxis) v->P().Z() = (float) p1.Z()*(1-u) + u*p2.Z();
|
||||||
else v->P().Z() = (float) p1.Z();
|
else v->P().Z() = (float) p1.Z();
|
||||||
|
|
||||||
|
if(VoxelType::HasNormal()) v->N() = V(p1).N()*(1-u) + V(p2).N()*u;
|
||||||
}
|
}
|
||||||
|
|
||||||
template < class VertexPointerType >
|
template < class VertexPointerType >
|
||||||
|
@ -93,32 +99,31 @@ template < class VertexPointerType >
|
||||||
void GetZIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointerType &v, const float thr)
|
void GetZIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointerType &v, const float thr)
|
||||||
{ GetIntercept<VertexPointerType,ZAxis>(p1,p2,v,thr); }
|
{ GetIntercept<VertexPointerType,ZAxis>(p1,p2,v,thr); }
|
||||||
};
|
};
|
||||||
template <class VolumeType>
|
|
||||||
class RawVolumeImporter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum DataType
|
|
||||||
{
|
|
||||||
// Funzioni superiori
|
|
||||||
UNDEF=0,
|
|
||||||
BYTE=1,
|
|
||||||
SHORT=2,
|
|
||||||
FLOAT=3
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool Open(const char *filename, VolumeType &V, Point3i sz, DataType d)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class SimpleVoxel
|
class SimpleVoxel
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
float _v;
|
float _v;
|
||||||
public:
|
public:
|
||||||
float &V() {return _v;};
|
float &V() {return _v;}
|
||||||
float V() const {return _v;};
|
float V() const {return _v;}
|
||||||
|
static bool HasNormal() {return false;}
|
||||||
|
vcg::Point3f N() const {return Point3f(0,0,0);}
|
||||||
|
vcg::Point3f &N() { static Point3f _p(0,0,0); return _p;}
|
||||||
|
};
|
||||||
|
|
||||||
|
class SimpleVoxelWithNormal
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
float _v;
|
||||||
|
vcg::Point3f _n;
|
||||||
|
public:
|
||||||
|
float &V() {return _v;}
|
||||||
|
float V() const {return _v;}
|
||||||
|
vcg::Point3f &N() {return _n;}
|
||||||
|
vcg::Point3f N() const {return _n;}
|
||||||
|
static bool HasNormal() {return true;}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue