Commit c4bbb73d authored by Jan Möbius's avatar Jan Möbius
Browse files

Removed PLY support

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free-Staging@16316 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 7ff3e6d0
/*
Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer. Redistributions in binary form must reproduce
the above copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the distribution.
Neither the name of the Johns Hopkins University nor the names of its contributors
may be used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#ifdef _WIN32
#include <Windows.h>
#include <Psapi.h>
#endif // _WIN32
#include "Time.h"
#include "MarchingCubes.h"
#include "Octree.h"
#include "SparseMatrix.h"
#include "CmdLineParser.h"
#include "PPolynomial.h"
#include "ply.h"
#include "MemoryUsage.h"
#include "omp.h"
#include <stdarg.h>
#include "MultiGridOctreeData.h"
cmdLineString
In( "in" ) ,
Out( "out" ) ,
VoxelGrid( "voxel" ) ,
XForm( "xForm" );
cmdLineReadable
#ifdef _WIN32
Performance( "performance" ) ,
#endif // _WIN32
Verbose( "verbose" ) ,
NoComments( "noComments" ) ,
PolygonMesh( "polygonMesh" ) ,
Confidence( "confidence" ) ,
NonManifold( "nonManifold" ) ,
ASCII( "ascii" ) ,
ShowResidual( "showResidual" );
cmdLineInt
Depth( "depth" , 8 ) ,
SolverDivide( "solverDivide" , 8 ) ,
IsoDivide( "isoDivide" , 8 ) ,
KernelDepth( "kernelDepth" ) ,
AdaptiveExponent( "adaptiveExp" , 1 ) ,
MinIters( "minIters" , 24 ) ,
FixedIters( "iters" , -1 ) ,
VoxelDepth( "voxelDepth" , -1 ) ,
#if 1
#ifdef _WIN32
#pragma message( "[WARNING] Setting default min-depth to 5" )
#endif // _WIN32
MinDepth( "minDepth" , 5 ) ,
#else
MinDepth( "minDepth" , 0 ) ,
#endif
MaxSolveDepth( "maxSolveDepth" ) ,
BoundaryType( "boundary" , 1 ) ,
Threads( "threads" , omp_get_num_procs() );
cmdLineFloat
SamplesPerNode( "samplesPerNode" , 1.f ) ,
Scale( "scale" , 1.1f ) ,
SolverAccuracy( "accuracy" , float(1e-3) ) ,
PointWeight( "pointWeight" , 4.f );
cmdLineReadable* params[] =
{
&In , &Depth , &Out , &XForm ,
&SolverDivide , &IsoDivide , &Scale , &Verbose , &SolverAccuracy , &NoComments ,
&KernelDepth , &SamplesPerNode , &Confidence , &NonManifold , &PolygonMesh , &ASCII , &ShowResidual , &MinIters , &FixedIters , &VoxelDepth ,
&PointWeight , &VoxelGrid , &Threads , &MinDepth , &MaxSolveDepth ,
&AdaptiveExponent , &BoundaryType ,
#ifdef _WIN32
&Performance ,
#endif // _WIN32
};
void ShowUsage(char* ex)
{
printf( "Usage: %s\n" , ex );
printf( "\t --%s <input points>\n" , In.name );
printf( "\t[--%s <ouput triangle mesh>]\n" , Out.name );
printf( "\t[--%s <ouput voxel grid>]\n" , VoxelGrid.name );
printf( "\t[--%s <maximum reconstruction depth>=%d]\n" , Depth.name , Depth.value );
printf( "\t\t Running at depth d corresponds to solving on a 2^d x 2^d x 2^d\n" );
printf( "\t\t voxel grid.\n" );
printf( "\t[--%s <depth at which to extract the voxel grid>=<%s>]\n" , VoxelDepth.name , Depth.name );
printf( "\t[--%s <scale factor>=%f]\n" , Scale.name , Scale.value );
printf( "\t\t Specifies the factor of the bounding cube that the input\n" );
printf( "\t\t samples should fit into.\n" );
printf( "\t[--%s <subdivision depth>=%d]\n" , SolverDivide.name , SolverDivide.value );
printf( "\t\t The depth at which a block Gauss-Seidel solver is used\n");
printf( "\t\t to solve the Laplacian.\n");
printf( "\t[--%s <minimum number of samples per node>=%f]\n" , SamplesPerNode.name, SamplesPerNode.value );
printf( "\t\t This parameter specifies the minimum number of points that\n" );
printf( "\t\t should fall within an octree node.\n" );
printf( "\t[--%s <num threads>=%d]\n" , Threads.name , Threads.value );
printf( "\t\t This parameter specifies the number of threads across which\n" );
printf( "\t\t the solver should be parallelizeds.\n" );
printf( "\t[--%s]\n" , Confidence.name );
printf( "\t\t If this flag is enabled, the size of a sample's normals is\n" );
printf( "\t\t used as a confidence value, affecting the sample's\n" );
printf( "\t\t constribution to the reconstruction process.\n" );
printf( "\t[--%s]\n" , NonManifold.name );
printf( "\t\t If this flag is enabled, the isosurface extraction does not add\n" );
printf( "\t\t a planar polygon's barycenter in order to ensure that the output\n" );
printf( "\t\t mesh is manifold.\n" );
printf( "\t[--%s]\n" , PolygonMesh.name);
printf( "\t\t If this flag is enabled, the isosurface extraction returns polygons\n" );
printf( "\t\t rather than triangles.\n" );
printf( "\t[--%s <interpolation weight>=%f]\n" , PointWeight.name , PointWeight.value );
printf( "\t\t This value specifies the weight that point interpolation constraints are\n" );
printf( "\t\t given when defining the (screened) Poisson system.\n" );
printf( "\t[--%s <minimum depth>=%d]\n" , MinDepth.name , MinDepth.value );
printf( "\t\t This flag specifies the minimum depth at which the octree is to be adaptive.\n" );
printf( "\t[--%s <solver accuracy>=%g]\n" , SolverAccuracy.name , SolverAccuracy.value );
printf( "\t[--%s <minimum number of solver iterations>=%d]\n" , MinIters.name , MinIters.value );
printf( "\t[--%s <adaptive weighting exponent>=%d]\n", AdaptiveExponent.name , AdaptiveExponent.value );
printf( "\t\t This flag specifies the exponent scale for the adaptive weighting.\n" );
#ifdef _WIN32
printf( "\t[--%s]\n" , Performance.name );
printf( "\t\t If this flag is enabled, the running time and peak memory usage\n" );
printf( "\t\t is output after the reconstruction.\n" );
#endif // _WIN32
printf( "\t[--%s]\n" , ASCII.name );
printf( "\t\t If this flag is enabled, the output file is written out in ASCII format.\n" );
printf( "\t[--%s]\n" , NoComments.name );
printf( "\t\t If this flag is enabled, the output file will not include comments.\n" );
printf( "\t[--%s]\n" , Verbose.name );
printf( "\t\t If this flag is enabled, the progress of the reconstructor will be output to STDOUT.\n" );
}
template< int Degree >
int Execute( int argc , char* argv[] )
{
int i;
int paramNum = sizeof(params)/sizeof(cmdLineReadable*);
int commentNum=0;
char **comments;
comments = new char*[paramNum+7];
for( i=0 ; i<paramNum+7 ; i++ ) comments[i] = new char[1024];
cmdLineParse( argc-1 , &argv[1] , paramNum , params , 1 );
if( Verbose.set ) echoStdout=1;
XForm4x4< Real > xForm , iXForm;
if( XForm.set )
{
FILE* fp = fopen( XForm.value , "r" );
if( !fp )
{
fprintf( stderr , "[WARNING] Could not read x-form from: %s\n" , XForm.value );
xForm = XForm4x4< Real >::Identity();
}
else
{
for( int i=0 ; i<4 ; i++ ) for( int j=0 ; j<4 ; j++ ) fscanf( fp , " %f " , &xForm( i , j ) );
fclose( fp );
}
}
else xForm = XForm4x4< Real >::Identity();
iXForm = xForm.inverse();
DumpOutput2( comments[commentNum++] , "Running Screened Poisson Reconstruction (Version 4.51)\n" , Degree );
char str[1024];
for( int i=0 ; i<paramNum ; i++ )
if( params[i]->set )
{
params[i]->writeValue( str );
if( strlen( str ) ) DumpOutput2( comments[commentNum++] , "\t--%s %s\n" , params[i]->name , str );
else DumpOutput2( comments[commentNum++] , "\t--%s\n" , params[i]->name );
}
double t;
double tt=Time();
Real isoValue = 0;
Octree<Degree> tree;
tree.threads = Threads.value;
if( !In.set )
{
ShowUsage(argv[0]);
return 0;
}
if( !MaxSolveDepth.set ) MaxSolveDepth.value = Depth.value;
if( SolverDivide.value<MinDepth.value )
{
fprintf( stderr , "[WARNING] %s must be at least as large as %s: %d>=%d\n" , SolverDivide.name , MinDepth.name , SolverDivide.value , MinDepth.value );
SolverDivide.value = MinDepth.value;
}
if( IsoDivide.value<MinDepth.value )
{
fprintf( stderr , "[WARNING] %s must be at least as large as %s: %d>=%d\n" , IsoDivide.name , MinDepth.name , IsoDivide.value , IsoDivide.value );
IsoDivide.value = MinDepth.value;
}
TreeOctNode::SetAllocator( MEMORY_ALLOCATOR_BLOCK_SIZE );
t=Time();
int kernelDepth = KernelDepth.set ? KernelDepth.value : Depth.value-2;
tree.setBSplineData( Depth.value , BoundaryType.value );
if( kernelDepth>Depth.value )
{
fprintf( stderr,"[ERROR] %s can't be greater than %s: %d <= %d\n" , KernelDepth.name , Depth.name , KernelDepth.value , Depth.value );
return EXIT_FAILURE;
}
double maxMemoryUsage;
t=Time() , tree.maxMemoryUsage=0;
int pointCount = tree.setTree( In.value , Depth.value , MinDepth.value , kernelDepth , Real(SamplesPerNode.value) , Scale.value , Confidence.set , PointWeight.value , AdaptiveExponent.value , xForm );
tree.ClipTree();
tree.finalize( IsoDivide.value );
DumpOutput2( comments[commentNum++] , "# Tree set in: %9.1f (s), %9.1f (MB)\n" , Time()-t , tree.maxMemoryUsage );
DumpOutput( "Input Points: %d\n" , pointCount );
DumpOutput( "Leaves/Nodes: %d/%d\n" , tree.tree.leaves() , tree.tree.nodes() );
DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage() )/(1<<20) );
maxMemoryUsage = tree.maxMemoryUsage;
t=Time() , tree.maxMemoryUsage=0;
tree.SetLaplacianConstraints();
DumpOutput2( comments[commentNum++] , "# Constraints set in: %9.1f (s), %9.1f (MB)\n" , Time()-t , tree.maxMemoryUsage );
DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage())/(1<<20) );
maxMemoryUsage = std::max< double >( maxMemoryUsage , tree.maxMemoryUsage );
t=Time() , tree.maxMemoryUsage=0;
tree.LaplacianMatrixIteration( SolverDivide.value, ShowResidual.set , MinIters.value , SolverAccuracy.value , MaxSolveDepth.value , FixedIters.value );
DumpOutput2( comments[commentNum++] , "# Linear system solved in: %9.1f (s), %9.1f (MB)\n" , Time()-t , tree.maxMemoryUsage );
DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage() )/(1<<20) );
maxMemoryUsage = std::max< double >( maxMemoryUsage , tree.maxMemoryUsage );
CoredFileMeshData mesh;
if( Verbose.set ) tree.maxMemoryUsage=0;
t=Time();
isoValue = tree.GetIsoValue();
DumpOutput( "Got average in: %f\n" , Time()-t );
DumpOutput( "Iso-Value: %e\n" , isoValue );
if( VoxelGrid.set )
{
double t = Time();
FILE* fp = fopen( VoxelGrid.value , "wb" );
if( !fp ) fprintf( stderr , "Failed to open voxel file for writing: %s\n" , VoxelGrid.value );
else
{
int res;
Pointer( Real ) values = tree.GetSolutionGrid( res , isoValue , VoxelDepth.value );
fwrite( &res , sizeof(int) , 1 , fp );
if( sizeof(Real)==sizeof(float) ) fwrite( values , sizeof(float) , res*res*res , fp );
else
{
float *fValues = new float[res*res*res];
for( int i=0 ; i<res*res*res ; i++ ) fValues[i] = float( values[i] );
fwrite( fValues , sizeof(float) , res*res*res , fp );
delete[] fValues;
}
fclose( fp );
DeletePointer( values );
}
DumpOutput( "Got voxel grid in: %f\n" , Time()-t );
}
if( Out.set )
{
t = Time() , tree.maxMemoryUsage = 0;
tree.GetMCIsoTriangles( isoValue , IsoDivide.value , &mesh , 0 , 1 , !NonManifold.set , PolygonMesh.set );
if( PolygonMesh.set ) DumpOutput2( comments[commentNum++] , "# Got polygons in: %9.1f (s), %9.1f (MB)\n" , Time()-t , tree.maxMemoryUsage );
else DumpOutput2( comments[commentNum++] , "# Got triangles in: %9.1f (s), %9.1f (MB)\n" , Time()-t , tree.maxMemoryUsage );
maxMemoryUsage = std::max< double >( maxMemoryUsage , tree.maxMemoryUsage );
DumpOutput2( comments[commentNum++],"# Total Solve: %9.1f (s), %9.1f (MB)\n" , Time()-tt , maxMemoryUsage );
if( NoComments.set )
{
if( ASCII.set ) PlyWritePolygons( Out.value , &mesh , PLY_ASCII , NULL , 0 , iXForm );
else PlyWritePolygons( Out.value , &mesh , PLY_BINARY_NATIVE , NULL , 0 , iXForm );
}
else
{
if( ASCII.set ) PlyWritePolygons( Out.value , &mesh , PLY_ASCII , comments , commentNum , iXForm );
else PlyWritePolygons( Out.value , &mesh , PLY_BINARY_NATIVE , comments , commentNum , iXForm );
}
}
return 1;
}
#ifdef _WIN32
inline double to_seconds( const FILETIME& ft )
{
const double low_to_sec=100e-9; // 100 nanoseconds
const double high_to_sec=low_to_sec*4294967296.0;
return ft.dwLowDateTime*low_to_sec+ft.dwHighDateTime*high_to_sec;
}
#endif // _WIN32
int main( int argc , char* argv[] )
{
double t = Time();
Execute< 2 >( argc , argv );
#ifdef _WIN32
if( Performance.set )
{
HANDLE cur_thread=GetCurrentThread();
FILETIME tcreat, texit, tkernel, tuser;
if( GetThreadTimes( cur_thread , &tcreat , &texit , &tkernel , &tuser ) )
printf( "Time (Wall/User/Kernel): %.2f / %.2f / %.2f\n" , Time()-t , to_seconds( tuser ) , to_seconds( tkernel ) );
else printf( "Time: %.2f\n" , Time()-t );
HANDLE h = GetCurrentProcess();
PROCESS_MEMORY_COUNTERS pmc;
if( GetProcessMemoryInfo( h , &pmc , sizeof(pmc) ) ) printf( "Peak Memory (MB): %d\n" , pmc.PeakWorkingSetSize>>20 );
}
#endif // _WIN32
return EXIT_SUCCESS;
}
......@@ -918,7 +918,6 @@ int Octree<Degree>::setTree( char* fileName , int maxDepth , int minDepth ,
PointStream< Real >* pointStream;
char* ext = GetFileExtension( fileName );
if ( !strcasecmp( ext , "bnpts" ) ) pointStream = new BinaryPointStream< Real >( fileName );
else if( !strcasecmp( ext , "ply" ) ) pointStream = new PLYPointStream< Real >( fileName );
else pointStream = new ASCIIPointStream< Real >( fileName );
delete[] ext;
......
......@@ -63,21 +63,5 @@ public:
bool nextPoint( Point3D< Real >& p , Point3D< Real >& n );
};
template< class Real >
class PLYPointStream : public PointStream< Real >
{
char* _fileName;
PlyFile* _ply;
int _nr_elems;
char **_elist;
int _pCount , _pIdx;
void _free( void );
public:
PLYPointStream( const char* fileName );
~PLYPointStream( void );
void reset( void );
bool nextPoint( Point3D< Real >& p , Point3D< Real >& n );
};
#include "PointStream.inl"
#endif // POINT_STREAM_INCLUDED
......@@ -25,7 +25,6 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
*/
#include "ply.h"
template< class Real >
ASCIIPointStream< Real >::ASCIIPointStream( const char* fileName )
......@@ -91,150 +90,3 @@ bool BinaryPointStream< Real >::nextPoint( Point3D< Real >& p , Point3D< Real >&
else return nextPoint( p , n );
}
}
template< class Real >
class PlyOrientedVertex
{
public:
const static int ReadComponents=6;
const static int WriteComponents=6;
static PlyProperty ReadProperties[];
static PlyProperty WriteProperties[];
Point3D< Real > point , normal;
operator Point3D<Real>& () {return point;}
operator const Point3D<Real>& () const {return point;}
template< class Real2 > operator Point3D< Real2 > ( ) const { return Point3D< Real2 >( point ); }
PlyOrientedVertex(void) {point.coords[0]=point.coords[1]=point.coords[2]=normal.coords[0]=normal.coords[1]=normal.coords[2]=0;}
PlyOrientedVertex(const Point3D<Real>& p) {point=p;}
};
template<>
PlyProperty PlyOrientedVertex< float >::ReadProperties[]=
{
{"x", PLY_FLOAT, PLY_FLOAT, int(offsetof(PlyOrientedVertex,point.coords[0])), 0, 0, 0, 0},
{"y", PLY_FLOAT, PLY_FLOAT, int(offsetof(PlyOrientedVertex,point.coords[1])), 0, 0, 0, 0},
{"z", PLY_FLOAT, PLY_FLOAT, int(offsetof(PlyOrientedVertex,point.coords[2])), 0, 0, 0, 0},
{"nx", PLY_FLOAT, PLY_FLOAT, int(offsetof(PlyOrientedVertex,normal.coords[0])), 0, 0, 0, 0},
{"ny", PLY_FLOAT, PLY_FLOAT, int(offsetof(PlyOrientedVertex,normal.coords[1])), 0, 0, 0, 0},
{"nz", PLY_FLOAT, PLY_FLOAT, int(offsetof(PlyOrientedVertex,normal.coords[2])), 0, 0, 0, 0}
};
template<>
PlyProperty PlyOrientedVertex< float >::WriteProperties[]=
{
{"x", PLY_FLOAT, PLY_FLOAT, int(offsetof(PlyOrientedVertex,point.coords[0])), 0, 0, 0, 0},
{"y", PLY_FLOAT, PLY_FLOAT, int(offsetof(PlyOrientedVertex,point.coords[1])), 0, 0, 0, 0},
{"z", PLY_FLOAT, PLY_FLOAT, int(offsetof(PlyOrientedVertex,point.coords[2])), 0, 0, 0, 0},
{"nx", PLY_FLOAT, PLY_FLOAT, int(offsetof(PlyOrientedVertex,normal.coords[0])), 0, 0, 0, 0},
{"ny", PLY_FLOAT, PLY_FLOAT, int(offsetof(PlyOrientedVertex,normal.coords[1])), 0, 0, 0, 0},
{"nz", PLY_FLOAT, PLY_FLOAT, int(offsetof(PlyOrientedVertex,normal.coords[2])), 0, 0, 0, 0}
};
template<>
PlyProperty PlyOrientedVertex< double >::ReadProperties[]=
{
{"x", PLY_DOUBLE, PLY_DOUBLE, int(offsetof(PlyOrientedVertex,point.coords[0])), 0, 0, 0, 0},
{"y", PLY_DOUBLE, PLY_DOUBLE, int(offsetof(PlyOrientedVertex,point.coords[1])), 0, 0, 0, 0},
{"z", PLY_DOUBLE, PLY_DOUBLE, int(offsetof(PlyOrientedVertex,point.coords[2])), 0, 0, 0, 0},
{"nx", PLY_DOUBLE, PLY_DOUBLE, int(offsetof(PlyOrientedVertex,normal.coords[0])), 0, 0, 0, 0},
{"ny", PLY_DOUBLE, PLY_DOUBLE, int(offsetof(PlyOrientedVertex,normal.coords[1])), 0, 0, 0, 0},
{"nz", PLY_DOUBLE, PLY_DOUBLE, int(offsetof(PlyOrientedVertex,normal.coords[2])), 0, 0, 0, 0}
};
template<>
PlyProperty PlyOrientedVertex< double >::WriteProperties[]=
{
{"x", PLY_DOUBLE, PLY_DOUBLE, int(offsetof(PlyOrientedVertex,point.coords[0])), 0, 0, 0, 0},
{"y", PLY_DOUBLE, PLY_DOUBLE, int(offsetof(PlyOrientedVertex,point.coords[1])), 0, 0, 0, 0},
{"z", PLY_DOUBLE, PLY_DOUBLE, int(offsetof(PlyOrientedVertex,point.coords[2])), 0, 0, 0, 0},
{"nx", PLY_DOUBLE, PLY_DOUBLE, int(offsetof(PlyOrientedVertex,normal.coords[0])), 0, 0, 0, 0},
{"ny", PLY_DOUBLE, PLY_DOUBLE, int(offsetof(PlyOrientedVertex,normal.coords[1])), 0, 0, 0, 0},
{"nz", PLY_DOUBLE, PLY_DOUBLE, int(offsetof(PlyOrientedVertex,normal.coords[2])), 0, 0, 0, 0}
};
template< class Real >
PLYPointStream< Real >::PLYPointStream( const char* fileName )
{
_fileName = new char[ strlen( fileName )+1 ];
strcpy( _fileName , fileName );
_ply = NULL;
reset();
}
template< class Real >
void PLYPointStream< Real >::reset( void )
{
int fileType;
float version;
PlyProperty** plist;
if( _ply ) _free();
_ply = ply_open_for_reading( _fileName, &_nr_elems, &_elist, &fileType, &version );
if( !_ply )
{
fprintf( stderr, "[ERROR] Failed to open ply file for reading: %s\n" , _fileName );
exit( 0 );
}
bool foundVertices = false;
for( int i=0 ; i<_nr_elems ; i++ )
{
int num_elems;
int nr_props;
char* elem_name = _elist[i];
plist = ply_get_element_description( _ply , elem_name , &num_elems , &nr_props );
if( !plist )
{
fprintf( stderr , "[ERROR] Failed to get element description: %s\n" , elem_name );
exit( 0 );
}
if( equal_strings( "vertex" , elem_name ) )
{
foundVertices = true;
_pCount = num_elems , _pIdx = 0;
for( int i=0 ; i<PlyOrientedVertex< Real >::ReadComponents ; i++ )
if( !ply_get_property( _ply , elem_name , &(PlyOrientedVertex< Real >::ReadProperties[i]) ) )
{
fprintf( stderr , "[ERROR] Failed to find property in ply file: %s\n" , PlyOrientedVertex< Real >::ReadProperties[i].name );
exit( 0 );
}
}
for( int j=0 ; j<nr_props ; j++ )
{
free( plist[j]->name );
free( plist[j] );
}
free( plist );
if( foundVertices ) break;
}
if( !foundVertices )
{
fprintf( stderr , "[ERROR] Could not find vertices in ply file\n" );
exit( 0 );
}
}
template< class Real >
void PLYPointStream< Real >::_free( void )
{
if( _ply ) ply_close( _ply ) , _ply = NULL;
if( _elist )
{
for( int i=0 ; i<_nr_elems ; i++ ) free( _elist[i] );
free( _elist );
}
}
template< class Real >
PLYPointStream< Real >::~PLYPointStream( void )
{
_free();
if( _fileName ) delete[] _fileName , _fileName = NULL;
}
template< class Real >
bool PLYPointStream< Real >::nextPoint( Point3D< Real >& p , Point3D< Real >& n )
{
if( _pIdx<_pCount )
{
PlyOrientedVertex< Real > op;
ply_get_element( _ply, (void *)&op );
p = op.point;
n = op.normal;
_pIdx++;
return true;
}
else return false;
}
/*
Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer. Redistributions in binary form must reproduce
the above copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the distribution.
Neither the name of the Johns Hopkins University nor the names of its contributors
may be used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
*/
#include "ply.h"
//
// PLY data structures
//
char *elem_names[] = { "vertex", "face" };
typedef struct PlyVertex
{
float x, y, z;
} PlyVertex;
typedef struct PlyVertex2
{
float x1 , x2 , y1 , y2 , z1 , z2 , s;
} PlyVertex2;
typedef struct PlyOrientedVertex
{
float x, y, z , nx, ny, nz;
} PlyOrientedVertex;
typedef struct PlyFace
{
unsigned char nr_vertices;
int *vertices;
int segment;
} PlyFace;
static PlyProperty vert_props[] = {