2012-04-02 16:47:04 +02:00
# include <vcg/complex/complex.h>
# include <wrap/io_trimesh/import.h>
# include <wrap/io_trimesh/export_ply.h>
class MyVertex ;
class MyEdge ;
class MyFace ;
struct MyUsedTypes : public vcg : : UsedTypes < vcg : : Use < MyVertex > : : AsVertexType , vcg : : Use < MyEdge > : : AsEdgeType , vcg : : Use < MyFace > : : AsFaceType > { } ;
2017-03-14 07:49:15 +01:00
class MyVertex : public vcg : : Vertex < MyUsedTypes , vcg : : vertex : : VFAdj , vcg : : vertex : : Coord3f , vcg : : vertex : : Normal3f , vcg : : vertex : : Mark , vcg : : vertex : : BitFlags > { } ;
2012-04-02 16:47:04 +02:00
class MyEdge : public vcg : : Edge < MyUsedTypes > { } ;
class MyFace : public vcg : : Face < MyUsedTypes ,
2016-01-25 15:47:06 +01:00
vcg : : face : : VFAdj ,
vcg : : face : : VertexRef ,
vcg : : face : : BitFlags > { } ;
2012-04-02 16:47:04 +02:00
// the main mesh class
class MyMesh : public vcg : : tri : : TriMesh < std : : vector < MyVertex > , std : : vector < MyFace > > { } ;
2012-07-04 15:52:32 +02:00
class OcfVertex ;
class OcfEdge ;
class OcfFace ;
// Declaration of the semantic of the used types
class OcfUsedTypes : public vcg : : UsedTypes < vcg : : Use < OcfVertex > : : AsVertexType ,
2016-01-25 15:47:06 +01:00
vcg : : Use < OcfEdge > : : AsEdgeType ,
vcg : : Use < OcfFace > : : AsFaceType > { } ;
2012-07-04 15:52:32 +02:00
// 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 OcfVertex : public vcg : : Vertex < OcfUsedTypes , vcg : : vertex : : InfoOcf , vcg : : vertex : : Coord3f , vcg : : vertex : : BitFlags , vcg : : vertex : : Normal3fOcf , vcg : : vertex : : VFAdjOcf , vcg : : vertex : : MarkOcf >
{
} ;
// The Main Edge Class
// Currently it does not contains anything.
class OcfEdge : public vcg : : Edge < OcfUsedTypes >
{
} ;
// Each face needs 32 byte, on 32bit arch. and 48 byte on 64bit arch.
class OcfFace : public vcg : : Face < OcfUsedTypes , vcg : : face : : InfoOcf , vcg : : face : : VertexRef , vcg : : face : : BitFlags , vcg : : face : : VFAdjOcf > { } ;
2016-01-25 15:47:06 +01:00
class OcfMesh : public vcg : : tri : : TriMesh < vcg : : vertex : : vector_ocf < OcfVertex > , vcg : : face : : vector_ocf < OcfFace > >
2012-07-04 15:52:32 +02:00
{
2012-04-03 10:03:30 +02:00
} ;
2012-04-02 16:47:04 +02:00
void Usage ( )
{
2016-01-25 15:47:06 +01:00
printf (
" \n Usage: " \
" trimeshcopy fileIn -(n|o) [fileOut] \n " \
" trimeshcopy test vcg::MeshCopy efficiency. \n It imports a fileIn file into a user defined mesh and test how long vcg::MeshCopy needs to copy the imported mesh in a second one.The copy time is expressed in milliseconds. \n If the -n flag is used a non-optional attributes mesh will be tested, defining -o, instead, the target mesh will be an ocf one. \n A fileOut file can be passed to the tool in order to check if the mesh was successfully copied. \n The file will be exported in PLY file format. \n "
) ;
exit ( - 1 ) ;
2012-04-02 16:47:04 +02:00
}
2012-07-04 15:52:32 +02:00
template < class MeshType >
bool UnitTest_Append ( const char * filename1 , const char * filename2 )
{
MeshType mr ;
MeshType ml ;
int startOpen = clock ( ) ;
int err = vcg : : tri : : io : : Importer < MeshType > : : Open ( mr , filename1 ) ;
if ( err )
{
std : : cerr < < " Unable to open mesh " < < filename1 < < " : " < < vcg : : tri : : io : : Importer < MyMesh > : : ErrorMsg ( err ) < < std : : endl ;
exit ( - 1 ) ;
}
int endOpen = clock ( ) ;
2012-10-15 09:52:40 +02:00
std : : cout < < " mesh loaded in " < < float ( endOpen - startOpen ) / CLOCKS_PER_SEC < < " msecs. Verts: " < < mr . VN ( ) < < " Faces: " < < mr . FN ( ) < < " \n " ;
2012-07-04 15:52:32 +02:00
int startCopy = clock ( ) ;
vcg : : tri : : Append < MeshType , MeshType > : : Mesh ( ml , mr , false , true ) ;
int endCopy = clock ( ) ;
std : : cout < < " mesh copied in " < < float ( endCopy - startCopy ) / CLOCKS_PER_SEC < < " msecs. " < < std : : endl ;
2012-10-15 09:52:40 +02:00
assert ( ml . VN ( ) = = mr . VN ( ) ) ;
2012-07-04 15:52:32 +02:00
assert ( ml . en = = mr . en ) ;
2012-10-15 09:52:40 +02:00
assert ( ml . FN ( ) = = mr . FN ( ) ) ;
2012-07-04 15:52:32 +02:00
int startSave = clock ( ) ;
vcg : : tri : : io : : ExporterPLY < MeshType > : : Save ( ml , filename2 ) ;
int endSave = clock ( ) ;
std : : cout < < " mesh saved in " < < float ( endSave - startSave ) / CLOCKS_PER_SEC < < " msecs. " < < std : : endl ;
return true ;
}
2012-11-10 17:57:26 +01:00
int main ( int /*argc*/ , char * * argv )
2012-07-04 15:52:32 +02:00
{
2016-01-25 15:47:06 +01:00
UnitTest_Append < MyMesh > ( argv [ 1 ] , " out.ply " ) ;
UnitTest_Append < OcfMesh > ( argv [ 1 ] , " out.ply " ) ;
return 0 ;
2012-04-02 16:47:04 +02:00
}