Menu

#2 ball_pivoting sample

v1.0_(example)
open
nobody
None
1
2014-11-02
2014-03-19
Anonymous
No

I did compiled vcglib\apps\sample\trimesh_ball_pivoting\ball_pivoting.cpp with some change.
But, result differ from result created by meshlab.


include<vcg complex="" complex.h="">

include <vcg complex="" algorithms="" update="" bounding.h="">

include <vcg complex="" algorithms="" update="" topology.h="">

include <vcg complex="" algorithms="" update="" normal.h="">

include <vcg complex="" algorithms="" update="" flag.h="">

include <vcg complex="" algorithms="" create="" ball_pivoting.h="">

// input output
//#include <wrap io_trimesh="" import_ply.h="">
//#include <wrap io_trimesh="" export_ply.h="">

include <wrap io_trimesh="" import_obj.h="">

include <wrap io_trimesh="" export_obj.h="">

include <time.h>

include <string>

using namespace vcg;
using namespace std;

class MyFace;
class MyVertex;

struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
Use<MyFace> ::AsFaceType>{};

class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Color4b, vertex::Normal3f, vertex::BitFlags, vertex::Mark>{};
class MyFace : public Face < MyUsedTypes, face::VertexRef, face::Normal3f, face::BitFlags > {};
class MyMesh : public vcg::tri::TriMesh< vector<MyVertex>, vector<MyFace> > {};

//// Forward declarations needed for creating the used types
//class CVertexO;
//class CEdgeO;
//class CFaceO;
//
//// Declaration of the semantic of the used types
//class CUsedTypesO : public vcg::UsedTypes < vcg::Use<CVertexO>::AsVertexType,
// vcg::Use<CEdgeO>::AsEdgeType,
// vcg::Use<CFaceO>::AsFaceType >{};
//
//
//// The Main Vertex Class
//// Most of the attributes are optional and must be enabled before use.
//// Each vertex needs 40 byte, on 32bit arch. and 44 byte on 64bit arch.
//
//class CVertexO : public vcg::Vertex< CUsedTypesO,
// vcg::vertex::InfoOcf, / 4b /
// vcg::vertex::Coord3f, / 12b /
// vcg::vertex::BitFlags, / 4b /
// vcg::vertex::Normal3f, / 12b /
// vcg::vertex::Qualityf, / 4b /
// vcg::vertex::Color4b, / 4b /
// vcg::vertex::VFAdjOcf, / 0b /
// vcg::vertex::MarkOcf, / 0b /
// vcg::vertex::TexCoordfOcf, / 0b /
// vcg::vertex::CurvaturefOcf, / 0b /
// vcg::vertex::CurvatureDirfOcf, / 0b /
// vcg::vertex::RadiusfOcf / 0b /
//>{
//};
//
//
//// The Main Edge Class
//// Currently it does not contains anything.
//class CEdgeO : public vcg::Edge<CUsedTypesO, vcg::edge::BitFlags,="" *="" 4b="" *="" vcg::edge::EVAdj,="" vcg::edge::EEAdj=""/>{
//};
//
//// Each face needs 32 byte, on 32bit arch. and 48 byte on 64bit arch.
//class CFaceO : public vcg::Face< CUsedTypesO,
// vcg::face::InfoOcf, / 4b /
// vcg::face::VertexRef, /12b /
// vcg::face::BitFlags, / 4b /
// vcg::face::Normal3f, /12b /
// vcg::face::QualityfOcf, / 0b /
// vcg::face::MarkOcf, / 0b /
// vcg::face::Color4bOcf, / 0b /
// vcg::face::FFAdjOcf, / 0b /
// vcg::face::VFAdjOcf, / 0b /
// vcg::face::WedgeTexCoordfOcf / 0b /
//> {};
//
//class MyMesh : public vcg::tri::TriMesh< vcg::vertex::vector_ocf<CVertexO>, vcg::face::vector_ocf<CFaceO> >
//{
//public:
// int sfn; //The number of selected faces.
// int svn; //The number of selected vertices.
// vcg::Matrix44f Tr; // Usually it is the identity. It is applied in rendering and filters can or cannot use it. (most of the filter will ignore this)
//
// const vcg::Box3f &trBB()
// {
// static vcg::Box3f bb;
// bb.SetNull();
// bb.Add(Tr, bbox);
// return bb;
// }
//};

bool callback(int percent, const char *str) {
cout << "str: " << str << " " << percent << "%\n";
return true;
}

int MeshReconstruction(const char ModelFileName, const char MeshModelFileName)
{
printf(
"\n trimesh_ball_pivoting ("DATE")\n"
" Visual Computing Group I.S.T.I. C.N.R.\n"
"Usage: trimesh_ball_pivoting filein.obj fileout.obj [opt]\n"
"options: \n"
"-r <val> radius of the rolling ball\n"
"-c <val> clustering radius (as fraction of radius) default: 0.05\n");

float radius = 0.0f;
float clustering = 20.0f/100.0f;
float creaseThr = math::ToRad(90.0f);
//int i = 3;

            //case 'r' :    radius = atof(argv[++i]); printf("Using %f sphere radius\n",radius);  break;
            //case 'c' :    clustering = atof(argv[++i]); printf("Using %f clustering radius\n",clustering); break;

            //default : {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}

if(radius == 0) 
  printf("Autodetecting ball radius...\n");

MyMesh m;
vcg::tri::io::ImporterOBJ<MyMesh>::Info oi;
vcg::tri::io::ImporterOBJ<MyMesh>::LoadMask(ModelFileName, oi);
if (vcg::tri::io::ImporterOBJ<MyMesh>::Open(m, ModelFileName, oi) != 0)
    {
    printf("Error reading file  %s\n", ModelFileName);
        exit(0);
    }

vcg::tri::UpdateBounding<MyMesh>::Box(m);
vcg::tri::UpdateNormal<MyMesh>::PerFace(m);
printf("Input mesh vn:%i fn:%i\n",m.VN(),m.FN());

int t0=clock();
// Initialization
tri::BallPivoting<MyMesh> pivot(m, radius, clustering, creaseThr);
printf("Ball radius: %f\nClustering points withing %f radii\n", pivot.radius, clustering);

int t1=clock();
// the main processing
pivot.BuildMesh(callback);

int t2=clock();

printf("Output mesh vn:%i fn:%i\n",m.VN(),m.FN());
printf("Created in :%i msec (%i+%i)\n",t2-t0,t1-t0,t2-t1);

vcg::tri::io::ExporterOBJ<MyMesh>::Save(m, MeshModelFileName, vcg::tri::io::Mask::IOM_VERTCOLOR);
//vcg::tri::io::PlyInfo pi;
//vcg::tri::io::ExporterPLY<MyMesh>::Save(m,argv[2],pi.mask);
return 0;
}


By the way, vcg library is good to read. Thanks.

Discussion

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.