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,
|
||||
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 MyMesh : public vcg::tri::TriMesh< std::vector< MyVertex>, std::vector< MyFace > > {};
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace vcg
|
|||
class EMCLookUpTable
|
||||
{
|
||||
public:
|
||||
static const int EdgeTable(unsigned char cubetype)
|
||||
static int EdgeTable(unsigned char cubetype)
|
||||
{
|
||||
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] =
|
||||
{
|
||||
|
|
|
@ -348,13 +348,13 @@ namespace vcg
|
|||
//--A[i][2] = normals[i][2];
|
||||
//--b[i] = (points[i] * normals[i]);
|
||||
A(i,0) = normals[i][0];
|
||||
A(i,0) = normals[i][1];
|
||||
A(i,0) = normals[i][2];
|
||||
A(i,1) = normals[i][1];
|
||||
A(i,2) = normals[i][2];
|
||||
b(i) = (points[i] * normals[i]);
|
||||
}
|
||||
|
||||
// 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);
|
||||
sol=svd.solve(b);
|
||||
|
||||
|
@ -386,7 +386,7 @@ namespace vcg
|
|||
|
||||
// transform x to world coords
|
||||
//--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;
|
||||
|
||||
// Safety check if the feature point found by svd is
|
||||
|
@ -411,15 +411,13 @@ namespace vcg
|
|||
*/
|
||||
void FlipEdges()
|
||||
{
|
||||
size_t i;
|
||||
std::vector< LightEdge > edges;
|
||||
FaceIterator f_iter = _mesh->face.begin();
|
||||
FaceIterator f_end = _mesh->face.end();
|
||||
for (i=0; f_iter!=f_end; f_iter++, i++)
|
||||
for (FaceIterator fi = _mesh->face.begin(); fi!=_mesh->face.end(); fi++)
|
||||
{
|
||||
if (f_iter->V(1) > f_iter->V(0)) edges.push_back( LightEdge(i,0) );
|
||||
if (f_iter->V(2) > f_iter->V(1)) edges.push_back( LightEdge(i,1) );
|
||||
if (f_iter->V(0) > f_iter->V(2)) edges.push_back( LightEdge(i,2) );
|
||||
size_t i = tri::Index(*_mesh,*fi);
|
||||
if (fi->V(1) > fi->V(0)) edges.push_back( LightEdge(i,0) );
|
||||
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 );
|
||||
|
||||
|
@ -439,10 +437,10 @@ namespace vcg
|
|||
f = &_mesh->face[e_it->face];
|
||||
z = (int) e_it->edge;
|
||||
|
||||
// v2------v1 swap the diagonal only if v2 and v3 are feature and v0 and v1 are not.
|
||||
// | / |
|
||||
// | / |
|
||||
// v0------v3
|
||||
// v2------v1 swap the diagonal only if v2 and v3 are feature and v0 and v1 are not.
|
||||
// | / |
|
||||
// | / |
|
||||
// v0------v3
|
||||
if (!(f->IsS()) && vcg::face::CheckFlipEdge< FaceType >(*f, z))
|
||||
{
|
||||
VertexPointer v0, v1, v2, v3;
|
||||
|
@ -462,7 +460,10 @@ namespace vcg
|
|||
|
||||
} // end if (vcg::face::CheckFlipEdge< _Face >(*f, z))
|
||||
} // end for( ; e_it!=e_end; e_it++)
|
||||
}; //end of FlipEdges
|
||||
|
||||
} //end of FlipEdges
|
||||
|
||||
|
||||
}; // end of class ExtendedMarchingCubes
|
||||
// /*! @} */
|
||||
// end of Doxygen documentation
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
|
||||
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)
|
||||
{
|
||||
|
@ -60,18 +60,22 @@ public:
|
|||
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 {
|
||||
return Vol[x+y*sz[0]+z*sz[0]*sz[1]];
|
||||
}
|
||||
|
||||
|
||||
typedef enum { XAxis=0,YAxis=1,ZAxis=2} VolumeAxis;
|
||||
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)
|
||||
{
|
||||
float f1 = Val(p1.X(), p1.Y(), p1.Z())-thr;
|
||||
float f2 = Val(p2.X(), p2.Y(), p2.Z())-thr;
|
||||
{
|
||||
float f1 = V(p1).V()-thr;
|
||||
float f2 = V(p2).V()-thr;
|
||||
float u = (float) f1/(f1-f2);
|
||||
if(AxisVal==XAxis) v->P().X() = (float) p1.X()*(1-u) + u*p2.X();
|
||||
else v->P().X() = (float) p1.X();
|
||||
|
@ -79,7 +83,9 @@ template < class VertexPointerType, VolumeAxis AxisVal >
|
|||
else v->P().Y() = (float) p1.Y();
|
||||
if(AxisVal==ZAxis) v->P().Z() = (float) p1.Z()*(1-u) + u*p2.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 >
|
||||
void GetXIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointerType &v, const float thr)
|
||||
|
@ -93,32 +99,31 @@ template < class VertexPointerType >
|
|||
void GetZIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointerType &v, const float 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
|
||||
{
|
||||
private:
|
||||
float _v;
|
||||
public:
|
||||
float &V() {return _v;};
|
||||
float V() const {return _v;};
|
||||
float &V() {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