Skip to content

Commit

Permalink
Remove all the exit() calls in the poisson filter stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed May 26, 2020
1 parent 1a3215d commit 611188b
Show file tree
Hide file tree
Showing 22 changed files with 57 additions and 1,338 deletions.
3 changes: 2 additions & 1 deletion filters/PoissonFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ PointViewSet PoissonFilter::run(PointViewPtr view)
}

PoissonRecon<double> recon(opts, *source);
recon.execute();
if (!recon.execute())
throwError("Failure executing poisson algorithm.");
recon.evaluate();

PointViewSet s;
Expand Down
13 changes: 4 additions & 9 deletions vendor/kazhdan/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,16 @@ class Allocator
*/
T* newElements( int elements=1 )
{
T* mem;
if( !elements ) return NULL;
if( elements>blockSize ) fprintf( stderr , "[ERROR] Allocator: elements bigger than block-size: %d>%d\n" , elements , blockSize ) , exit( 0 );
if( elements == 0 || elements > blockSize)
return nullptr;
if( remains<elements )
{
if( index==(int)(memory.size()-1))
{
mem = new T[blockSize];
if( !mem ) fprintf( stderr , "[ERROR] Failed to allocate memory\n" ) , exit(0);
memory.push_back( mem );
}
memory.push_back( new T[blockSize] );
index++;
remains = blockSize;
}
mem = &(memory[index][blockSize-remains]);
T *mem = &(memory[index][blockSize-remains]);
remains -= elements;
return mem;
}
Expand Down
10 changes: 0 additions & 10 deletions vendor/kazhdan/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ DAMAGE.
#include <stdlib.h>
#include <vector>

#ifdef _WIN64
#define ASSERT( x ) { if( !( x ) ) __debugbreak(); }
#else // !_WIN64
#ifdef _WIN32
#define ASSERT( x ) { if( !( x ) ) _asm{ int 0x03 } }
#else // !_WIN32
#define ASSERT( x ) { if( !( x ) ) exit(0); }
#endif // _WIN32
#endif // _WIN64

// Code from http://stackoverflow.com
void* aligned_malloc( size_t size , size_t align )
{
Expand Down
15 changes: 9 additions & 6 deletions vendor/kazhdan/BSplineData.inl
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ template< int Degree1 , BoundaryType BType1 , int Degree2 , BoundaryType BType2
template< unsigned int D1 , unsigned int D2 >
double BSplineIntegrationData< Degree1 , BType1 , Degree2 , BType2 >::Dot( int depth1 , int off1 , int depth2 , int off2 )
{
if( D1>Degree1 ) fprintf( stderr , "[ERROR] BSplineIntegrationData::Dot: taking more derivatives than the degree: %d > %d\n" , D1 , Degree1 ) , exit( 0 );
if( D2>Degree2 ) fprintf( stderr , "[ERROR] BSplineIntegrationData::Dot: taking more derivatives than the degree: %d > %d\n" , D2 , Degree2 ) , exit( 0 );
const int _Degree1 = ( Degree1>=D1 ) ? Degree1 - D1 : 0 , _Degree2 = ( Degree2>=D2 ) ? Degree2 - D2 : 0;
const int _Degree1 = ( Degree1>=D1 ) ? Degree1 - D1 : 0;
const int _Degree2 = ( Degree2>=D2 ) ? Degree2 - D2 : 0;

int sums[ Degree1+1 ][ Degree2+1 ];

int depth = std::max< int >( depth1 , depth2 );
Expand All @@ -246,7 +246,8 @@ double BSplineIntegrationData< Degree1 , BType1 , Degree2 , BType2 >::Dot( int d

BSplineElements< Degree1-D1 > db1;
BSplineElements< Degree2-D2 > db2;
b1.template differentiate< D1 >( db1 ) , b2.template differentiate< D2 >( db2 );
b1.template differentiate< D1 >( db1 );
b2.template differentiate< D2 >( db2 );

int start1=-1 , end1=-1 , start2=-1 , end2=-1;
for( int i=0 ; i<int( b1.size() ) ; i++ )
Expand All @@ -262,8 +263,10 @@ double BSplineIntegrationData< Degree1 , BType1 , Degree2 , BType2 >::Dot( int d
if( b2[i][j] ) end2 = i+1;
}
}
if( start1==end1 || start2==end2 || start1>=end2 || start2>=end1 ) return 0.;
int start = std::max< int >( start1 , start2 ) , end = std::min< int >( end1 , end2 );
if( start1==end1 || start2==end2 || start1>=end2 || start2>=end1 )
return 0.;
int start = std::max< int >( start1 , start2 );
int end = std::min< int >( end1 , end2 );
memset( sums , 0 , sizeof( sums ) );

// Iterate over the support
Expand Down
81 changes: 0 additions & 81 deletions vendor/kazhdan/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,84 +39,3 @@ DAMAGE.
TriangulationEdge::TriangulationEdge(void){pIndex[0]=pIndex[1]=tIndex[0]=tIndex[1]=-1;}
TriangulationTriangle::TriangulationTriangle(void){eIndex[0]=eIndex[1]=eIndex[2]=-1;}

///////////////////////////
// BufferedReadWriteFile //
///////////////////////////
BufferedReadWriteFile::BufferedReadWriteFile( char* fileName , int bufferSize )
{
_bufferIndex = 0;
_bufferSize = bufferSize;
if( fileName ) strcpy( _fileName , fileName ) , tempFile = false , _fp = fopen( _fileName , "w+b" );
else
{
strcpy( _fileName , "PR_XXXXXX" );
#ifdef _WIN32
_mktemp( _fileName );
_fp = fopen( _fileName , "w+b" );
#else // !_WIN32
_fp = fdopen( mkstemp( _fileName ) , "w+b" );
#endif // _WIN32
tempFile = true;
}
if( !_fp ) fprintf( stderr , "[ERROR] Failed to open file: %s\n" , _fileName ) , exit( 0 );
_buffer = (char*) malloc( _bufferSize );
}
BufferedReadWriteFile::~BufferedReadWriteFile( void )
{
free( _buffer );
fclose( _fp );
if( tempFile ) remove( _fileName );
}
void BufferedReadWriteFile::reset( void )
{
if( _bufferIndex ) fwrite( _buffer , 1 , _bufferIndex , _fp );
_bufferIndex = 0;
fseek( _fp , 0 , SEEK_SET );
_bufferIndex = 0;
_bufferSize = fread( _buffer , 1 , _bufferSize , _fp );
}
bool BufferedReadWriteFile::write( const void* data , size_t size )
{
if( !size ) return true;
auto _data = static_cast<const char*>(data);
size_t sz = _bufferSize - _bufferIndex;
while( sz<=size )
{
memcpy( _buffer+_bufferIndex , _data , sz );
fwrite( _buffer , 1 , _bufferSize , _fp );
_data += sz;
size -= sz;
_bufferIndex = 0;
sz = _bufferSize;
}
if( size )
{
memcpy( _buffer+_bufferIndex , _data , size );
_bufferIndex += size;
}
return true;
}
bool BufferedReadWriteFile::read( void* data , size_t size )
{
if( !size ) return true;
char *_data = (char*) data;
size_t sz = _bufferSize - _bufferIndex;
while( sz<=size )
{
if( size && !_bufferSize ) return false;
memcpy( _data , _buffer+_bufferIndex , sz );
_bufferSize = fread( _buffer , 1 , _bufferSize , _fp );
_data += sz;
size -= sz;
_bufferIndex = 0;
if( !size ) return true;
sz = _bufferSize;
}
if( size )
{
if( !_bufferSize ) return false;
memcpy( _data , _buffer+_bufferIndex , size );
_bufferIndex += size;
}
return true;
}
35 changes: 0 additions & 35 deletions vendor/kazhdan/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,42 +373,7 @@ class CoredVectorMeshData : public CoredMeshData< Vertex >
int outOfCorePointCount(void);
int polygonCount( void );
};
class BufferedReadWriteFile
{
bool tempFile;
FILE* _fp;
char *_buffer , _fileName[1024];
size_t _bufferIndex , _bufferSize;
public:
BufferedReadWriteFile( char* fileName=NULL , int bufferSize=(1<<20) );
~BufferedReadWriteFile( void );
bool write( const void* data , size_t size );
bool read ( void* data , size_t size );
void reset( void );
};
template< class Vertex >
class CoredFileMeshData : public CoredMeshData< Vertex >
{
char pointFileName[1024] , polygonFileName[1024];
BufferedReadWriteFile *oocPointFile , *polygonFile;
int oocPoints , polygons;
public:
CoredFileMeshData( void );
~CoredFileMeshData( void );

void resetIterator( void );

int addOutOfCorePoint( const Vertex& p );
int addOutOfCorePoint_s( const Vertex& p );
int addPolygon_s( const std::vector< CoredVertexIndex >& vertices );
int addPolygon_s( const std::vector< int >& vertices );

int nextOutOfCorePoint( Vertex& p );
int nextPolygon( std::vector< CoredVertexIndex >& vertices );

int outOfCorePointCount( void );
int polygonCount( void );
};
#include "Geometry.inl"

#endif // GEOMETRY_INCLUDED
166 changes: 0 additions & 166 deletions vendor/kazhdan/Geometry.inl
Original file line number Diff line number Diff line change
Expand Up @@ -423,169 +423,3 @@ int Triangulation<Real>::flipMinimize(int eIndex){
}
return 1;
}
/////////////////////////
// CoredVectorMeshData //
/////////////////////////
template< class Vertex >
CoredVectorMeshData< Vertex >::CoredVectorMeshData( void ) { oocPointIndex = polygonIndex = 0; }
template< class Vertex >
void CoredVectorMeshData< Vertex >::resetIterator ( void ) { oocPointIndex = polygonIndex = 0; }
template< class Vertex >
int CoredVectorMeshData< Vertex >::addOutOfCorePoint( const Vertex& p )
{
oocPoints.push_back(p);
return int(oocPoints.size())-1;
}
template< class Vertex >
int CoredVectorMeshData< Vertex >::addOutOfCorePoint_s( const Vertex& p )
{
size_t sz;
#pragma omp critical (CoredVectorMeshData_addOutOfCorePoint_s )
{
sz = oocPoints.size();
oocPoints.push_back(p);
}
return (int)sz;
}
template< class Vertex >
int CoredVectorMeshData< Vertex >::addPolygon_s( const std::vector< int >& polygon )
{
size_t sz;
#pragma omp critical (CoredVectorMeshData_addPolygon_s)
{
sz = polygon.size();
polygons.push_back( polygon );
}
return (int)sz;
}
template< class Vertex >
int CoredVectorMeshData< Vertex >::addPolygon_s( const std::vector< CoredVertexIndex >& vertices )
{
std::vector< int > polygon( vertices.size() );
for( int i=0 ; i<(int)vertices.size() ; i++ )
if( vertices[i].inCore ) polygon[i] = vertices[i].idx;
else polygon[i] = -vertices[i].idx-1;
return addPolygon_s( polygon );
}
template< class Vertex >
int CoredVectorMeshData< Vertex >::nextOutOfCorePoint( Vertex& p )
{
if( oocPointIndex<int(oocPoints.size()) )
{
p=oocPoints[oocPointIndex++];
return 1;
}
else{return 0;}
}
template< class Vertex >
int CoredVectorMeshData< Vertex >::nextPolygon( std::vector< CoredVertexIndex >& vertices )
{
if( polygonIndex<int( polygons.size() ) )
{
std::vector< int >& polygon = polygons[ polygonIndex++ ];
vertices.resize( polygon.size() );
for( int i=0 ; i<int(polygon.size()) ; i++ )
if( polygon[i]<0 ) vertices[i].idx = -polygon[i]-1 , vertices[i].inCore = false;
else vertices[i].idx = polygon[i] , vertices[i].inCore = true;
return 1;
}
else return 0;
}
template< class Vertex >
int CoredVectorMeshData< Vertex >::outOfCorePointCount(void){return int(oocPoints.size());}
template< class Vertex >
int CoredVectorMeshData< Vertex >::polygonCount( void ) { return int( polygons.size() ); }

///////////////////////
// CoredFileMeshData //
///////////////////////
template< class Vertex >
CoredFileMeshData< Vertex >::CoredFileMeshData( void )
{
oocPoints = polygons = 0;

oocPointFile = new BufferedReadWriteFile();
polygonFile = new BufferedReadWriteFile();
}
template< class Vertex >
CoredFileMeshData< Vertex >::~CoredFileMeshData( void )
{
delete oocPointFile;
delete polygonFile;
}
template< class Vertex >
void CoredFileMeshData< Vertex >::resetIterator ( void )
{
oocPointFile->reset();
polygonFile->reset();
}
template< class Vertex >
int CoredFileMeshData< Vertex >::addOutOfCorePoint( const Vertex& p )
{
oocPointFile->write( &p , sizeof( Vertex ) );
oocPoints++;
return oocPoints-1;
}
template< class Vertex >
int CoredFileMeshData< Vertex >::addOutOfCorePoint_s( const Vertex& p )
{
int sz;
#pragma omp critical (CoredFileMeshData_addOutOfCorePoint_s)
{
sz = oocPoints;
oocPointFile->write( &p , sizeof( Vertex ) );
oocPoints++;
}
return sz;
}
template< class Vertex >
int CoredFileMeshData< Vertex >::addPolygon_s( const std::vector< int >& vertices )
{
int sz , vSize = (int)vertices.size();
#pragma omp critical (CoredFileMeshData_addPolygon_s )
{
sz = polygons;
polygonFile->write( &vSize , sizeof(int) );
polygonFile->write( &vertices[0] , sizeof(int) * vSize );
polygons++;
}
return sz;
}
template< class Vertex >
int CoredFileMeshData< Vertex >::addPolygon_s( const std::vector< CoredVertexIndex >& vertices )
{
std::vector< int > polygon( vertices.size() );
for( int i=0 ; i<(int)vertices.size() ; i++ )
if( vertices[i].inCore ) polygon[i] = vertices[i].idx;
else polygon[i] = -vertices[i].idx-1;
return addPolygon_s( polygon );
}
template< class Vertex >
int CoredFileMeshData< Vertex >::nextOutOfCorePoint( Vertex& p )
{
if( oocPointFile->read( &p , sizeof( Vertex ) ) ) return 1;
else return 0;
}
template< class Vertex >
int CoredFileMeshData< Vertex >::nextPolygon( std::vector< CoredVertexIndex >& vertices )
{
int pSize;
if( polygonFile->read( &pSize , sizeof(int) ) )
{
std::vector< int > polygon( pSize );
if( polygonFile->read( &polygon[0] , sizeof(int)*pSize ) )
{
vertices.resize( pSize );
for( int i=0 ; i<int(polygon.size()) ; i++ )
if( polygon[i]<0 ) vertices[i].idx = -polygon[i]-1 , vertices[i].inCore = false;
else vertices[i].idx = polygon[i] , vertices[i].inCore = true;
return 1;
}
return 0;
}
else return 0;
}
template< class Vertex >
int CoredFileMeshData< Vertex >::outOfCorePointCount( void ){ return oocPoints; }
template< class Vertex >
int CoredFileMeshData< Vertex >::polygonCount( void ) { return polygons; }

0 comments on commit 611188b

Please sign in to comment.