Factorized better the volume creation part
This commit is contained in:
parent
98f1a78882
commit
a03703e2e6
|
@ -46,9 +46,26 @@ public:
|
||||||
typedef typename MeshType::FacePointer FacePointer;
|
typedef typename MeshType::FacePointer FacePointer;
|
||||||
typedef typename vcg::GridStaticPtr<typename MeshType::FaceType, ScalarType> GridType;
|
typedef typename vcg::GridStaticPtr<typename MeshType::FaceType, ScalarType> GridType;
|
||||||
|
|
||||||
typedef SimpleVolume<SimpleVoxel<ScalarType> > MyVolume;
|
typedef SimpleVolume<SimpleVoxel<ScalarType> > VVSVolume;
|
||||||
typedef typename vcg::tri::TrivialWalker<MeshType,MyVolume> MyWalker;
|
typedef typename vcg::tri::TrivialWalker<MeshType,VVSVolume> VVSWalker;
|
||||||
typedef typename vcg::tri::MarchingCubes<MeshType, MyWalker> MyMarchingCubes;
|
typedef typename vcg::tri::MarchingCubes<MeshType, VVSWalker> VVSMarchingCubes;
|
||||||
|
|
||||||
|
class Param
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Param()
|
||||||
|
{
|
||||||
|
elemType=1;
|
||||||
|
isoThr=0.1;
|
||||||
|
surfFlag=false;
|
||||||
|
voxelSide=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int elemType; // the type of element
|
||||||
|
ScalarType isoThr;
|
||||||
|
ScalarType voxelSide;
|
||||||
|
bool surfFlag;
|
||||||
|
};
|
||||||
|
|
||||||
VoronoiVolumeSampling(MeshType &_baseMesh)
|
VoronoiVolumeSampling(MeshType &_baseMesh)
|
||||||
:surfTree(0),seedTree(0),baseMesh(_baseMesh),cb(0),restrictedRelaxationFlag(false)
|
:surfTree(0),seedTree(0),baseMesh(_baseMesh),cb(0),restrictedRelaxationFlag(false)
|
||||||
|
@ -367,6 +384,31 @@ void QuadricRelaxVoronoiSamples(int relaxStep)
|
||||||
// qDebug("performed %i relax step on %i",i,relaxStep);
|
// qDebug("performed %i relax step on %i",i,relaxStep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ScalarType ImplicitFunction(const CoordType &p, Param &pp)
|
||||||
|
{
|
||||||
|
CoordType closest;
|
||||||
|
ScalarType surfDist = this->DistanceFromSurface(p,closest);
|
||||||
|
|
||||||
|
ScalarType elemDist;
|
||||||
|
switch(pp.elemType)
|
||||||
|
{
|
||||||
|
case 0: elemDist = DistanceFromVoronoiSeed(p) - pp.isoThr; break;
|
||||||
|
case 1: elemDist = DistanceFromVoronoiSurfaceEdge(p,closest) - pp.isoThr; break;
|
||||||
|
case 2: elemDist = DistanceFromVoronoiFace(p) - pp.isoThr; break;
|
||||||
|
case 3: elemDist = DistanceFromVoronoiCorner(p) - pp.isoThr; break;
|
||||||
|
case 4: elemDist = DistanceFromVoronoiInternalEdge(p) - pp.isoThr; break;
|
||||||
|
default: assert(0);
|
||||||
|
}
|
||||||
|
ScalarType val;
|
||||||
|
if(pp.surfFlag)
|
||||||
|
val = std::max(-elemDist,surfDist);
|
||||||
|
else
|
||||||
|
val = std::max(elemDist,surfDist);
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Function: BuildScaffoldingMesh
|
* Function: BuildScaffoldingMesh
|
||||||
* ----------------------------
|
* ----------------------------
|
||||||
|
@ -379,53 +421,34 @@ void QuadricRelaxVoronoiSamples(int relaxStep)
|
||||||
* PruningPoisson: mesh of inside and surface points, it's the voronoi3d diagram
|
* PruningPoisson: mesh of inside and surface points, it's the voronoi3d diagram
|
||||||
* n_voxel: number of voxels for the greater side
|
* n_voxel: number of voxels for the greater side
|
||||||
*/
|
*/
|
||||||
void BuildScaffoldingMesh(MeshType &scaffoldingMesh, float voxelSide, const ScalarType isoThr,int elemEnum, bool surfFlag)
|
void BuildScaffoldingMesh(MeshType &scaffoldingMesh, Param &pp)
|
||||||
{
|
{
|
||||||
MyVolume volume;
|
VVSVolume volume;
|
||||||
int sizeX = (baseMesh.bbox.DimX() / voxelSide)+1;
|
int sizeX = (baseMesh.bbox.DimX() / pp.voxelSide)+1;
|
||||||
int sizeY = (baseMesh.bbox.DimY() / voxelSide)+1;
|
int sizeY = (baseMesh.bbox.DimY() / pp.voxelSide)+1;
|
||||||
int sizeZ = (baseMesh.bbox.DimZ() / voxelSide)+1;
|
int sizeZ = (baseMesh.bbox.DimZ() / pp.voxelSide)+1;
|
||||||
|
|
||||||
printf("Scaffolding of the mesh %i %i %i\n",sizeX,sizeY,sizeZ);
|
|
||||||
|
|
||||||
|
int t0=clock();
|
||||||
BoxType bb = BoxType::Construct(baseMesh.bbox);
|
BoxType bb = BoxType::Construct(baseMesh.bbox);
|
||||||
bb.Offset(voxelSide+isoThr*2.0f);
|
bb.Offset(pp.voxelSide+pp.isoThr*2.0f);
|
||||||
volume.Init(Point3i(sizeX,sizeY,sizeZ),bb);
|
volume.Init(Point3i(sizeX,sizeY,sizeZ),bb);
|
||||||
int cnt=0;
|
int cnt=0;
|
||||||
for(ScalarType i=0;i<sizeX;i++)
|
for(ScalarType i=0;i<sizeX;i++)
|
||||||
for(ScalarType j=0;j<sizeY;j++)
|
for(ScalarType j=0;j<sizeY;j++)
|
||||||
for(ScalarType k=0;k<sizeZ;k++)
|
for(ScalarType k=0;k<sizeZ;k++)
|
||||||
{
|
{
|
||||||
ScalarType val;
|
CoordType p;
|
||||||
// check if the point is inside the mesh
|
|
||||||
CoordType p,closest;
|
|
||||||
volume.IPiToPf(Point3i(i,j,k),p);
|
volume.IPiToPf(Point3i(i,j,k),p);
|
||||||
ScalarType surfDist = this->DistanceFromSurface(p,closest);
|
volume.Val(i,j,k) = ImplicitFunction(p,pp);
|
||||||
|
|
||||||
ScalarType elemDist;
|
|
||||||
switch(elemEnum)
|
|
||||||
{
|
|
||||||
case 0: elemDist = DistanceFromVoronoiSeed(p) - isoThr; break;
|
|
||||||
case 1: elemDist = DistanceFromVoronoiSurfaceEdge(p,closest) - isoThr; break;
|
|
||||||
case 2: elemDist = DistanceFromVoronoiFace(p) - isoThr; break;
|
|
||||||
case 3: elemDist = DistanceFromVoronoiCorner(p) - isoThr; break;
|
|
||||||
case 4: elemDist = DistanceFromVoronoiInternalEdge(p) - isoThr; break;
|
|
||||||
default: assert(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(surfFlag)
|
|
||||||
val = std::max(-elemDist,surfDist);
|
|
||||||
else
|
|
||||||
val = std::max(elemDist,surfDist);
|
|
||||||
volume.Val(i,j,k) = val;
|
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
|
int t1=clock();
|
||||||
// MARCHING CUBES
|
VVSWalker walker;
|
||||||
// qDebug("voxel out %i on %i",cnt,sizeX*sizeY*sizeZ);
|
VVSMarchingCubes mc(scaffoldingMesh, walker);
|
||||||
MyWalker walker;
|
walker.template BuildMesh <VVSMarchingCubes>(scaffoldingMesh, volume, mc,0);
|
||||||
MyMarchingCubes mc(scaffoldingMesh, walker);
|
int t2=clock();
|
||||||
walker.template BuildMesh <MyMarchingCubes>(scaffoldingMesh, volume, mc,0);
|
printf("Fill Volume (%3i %3i %3i) %5.2f\n", sizeX,sizeY,sizeZ,float(t1-t0)/CLOCKS_PER_SEC);
|
||||||
|
printf("Marching %i tris %5.2f\n", scaffoldingMesh.fn,float(t2-t1)/CLOCKS_PER_SEC);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Compute an evaulation of the thickness as distance from the medial axis.
|
* @brief Compute an evaulation of the thickness as distance from the medial axis.
|
||||||
|
|
Loading…
Reference in New Issue