Code style cleanup in intern/dualcon.
This commit is contained in:
+25
-25
@@ -24,7 +24,7 @@
|
||||
#define __DUALCON_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef float (*DualConCo)[3];
|
||||
@@ -35,11 +35,11 @@ typedef struct DualConInput {
|
||||
DualConCo co;
|
||||
int co_stride;
|
||||
int totco;
|
||||
|
||||
|
||||
DualConFaces faces;
|
||||
int face_stride;
|
||||
int totface;
|
||||
|
||||
|
||||
float min[3], max[3];
|
||||
} DualConInput;
|
||||
|
||||
@@ -64,32 +64,32 @@ typedef enum {
|
||||
} DualConMode;
|
||||
|
||||
/* Usage:
|
||||
|
||||
The three callback arguments are used for creating the output
|
||||
mesh. The alloc_output callback takes the total number of vertices
|
||||
and faces (quads) that will be in the output. It should allocate
|
||||
and return a structure to hold the output mesh. The add_vert and
|
||||
add_quad callbacks will then be called for each new vertex and
|
||||
quad, and the callback should add the new mesh elements to the
|
||||
structure.
|
||||
*/
|
||||
*
|
||||
* The three callback arguments are used for creating the output
|
||||
* mesh. The alloc_output callback takes the total number of vertices
|
||||
* and faces (quads) that will be in the output. It should allocate
|
||||
* and return a structure to hold the output mesh. The add_vert and
|
||||
* add_quad callbacks will then be called for each new vertex and
|
||||
* quad, and the callback should add the new mesh elements to the
|
||||
* structure.
|
||||
*/
|
||||
void *dualcon(const DualConInput *input_mesh,
|
||||
/* callbacks for output */
|
||||
DualConAllocOutput alloc_output,
|
||||
DualConAddVert add_vert,
|
||||
DualConAddQuad add_quad,
|
||||
/* callbacks for output */
|
||||
DualConAllocOutput alloc_output,
|
||||
DualConAddVert add_vert,
|
||||
DualConAddQuad add_quad,
|
||||
|
||||
/* flags and settings to control the remeshing
|
||||
algorithm */
|
||||
DualConFlags flags,
|
||||
DualConMode mode,
|
||||
float threshold,
|
||||
float hermite_num,
|
||||
float scale,
|
||||
int depth);
|
||||
/* flags and settings to control the remeshing
|
||||
* algorithm */
|
||||
DualConFlags flags,
|
||||
DualConMode mode,
|
||||
float threshold,
|
||||
float hermite_num,
|
||||
float scale,
|
||||
int depth);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __DUALCON_H__ */
|
||||
|
||||
@@ -36,31 +36,26 @@
|
||||
|
||||
|
||||
// 3d point with integer coordinates
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
int x, y, z;
|
||||
} Point3i;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
Point3i begin;
|
||||
Point3i end;
|
||||
} BoundingBox;
|
||||
|
||||
// triangle that points to three vertices
|
||||
typedef struct
|
||||
{
|
||||
float vt[3][3] ;
|
||||
typedef struct {
|
||||
float vt[3][3];
|
||||
} Triangle;
|
||||
|
||||
// 3d point with float coordinates
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
float x, y, z;
|
||||
} Point3f;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
Point3f begin;
|
||||
Point3f end;
|
||||
} BoundingBoxf;
|
||||
|
||||
@@ -43,19 +43,19 @@
|
||||
class VirtualMemoryAllocator
|
||||
{
|
||||
public:
|
||||
virtual void * allocate( ) = 0 ;
|
||||
virtual void deallocate( void * obj ) = 0 ;
|
||||
virtual void destroy( ) = 0 ;
|
||||
virtual void printInfo( ) = 0 ;
|
||||
virtual void *allocate( ) = 0;
|
||||
virtual void deallocate(void *obj) = 0;
|
||||
virtual void destroy( ) = 0;
|
||||
virtual void printInfo( ) = 0;
|
||||
|
||||
virtual int getAllocated( ) = 0 ;
|
||||
virtual int getAll( ) = 0 ;
|
||||
virtual int getBytes( ) = 0 ;
|
||||
virtual int getAllocated( ) = 0;
|
||||
virtual int getAll( ) = 0;
|
||||
virtual int getBytes( ) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Dynamic memory allocator - allows allocation/deallocation
|
||||
*
|
||||
*
|
||||
* Note: there are 4 bytes overhead for each allocated yet unused object.
|
||||
*/
|
||||
template < int N >
|
||||
@@ -63,157 +63,157 @@ class MemoryAllocator : public VirtualMemoryAllocator
|
||||
{
|
||||
private:
|
||||
|
||||
/// Constants
|
||||
int HEAP_UNIT, HEAP_MASK ;
|
||||
/// Constants
|
||||
int HEAP_UNIT, HEAP_MASK;
|
||||
|
||||
/// Data array
|
||||
UCHAR ** data ;
|
||||
/// Data array
|
||||
UCHAR **data;
|
||||
|
||||
/// Allocation stack
|
||||
UCHAR *** stack ;
|
||||
/// Allocation stack
|
||||
UCHAR ***stack;
|
||||
|
||||
/// Number of data blocks
|
||||
int datablocknum ;
|
||||
/// Number of data blocks
|
||||
int datablocknum;
|
||||
|
||||
/// Number of stack blocks
|
||||
int stackblocknum ;
|
||||
/// Number of stack blocks
|
||||
int stackblocknum;
|
||||
|
||||
/// Size of stack
|
||||
int stacksize ;
|
||||
/// Size of stack
|
||||
int stacksize;
|
||||
|
||||
/// Number of available objects on stack
|
||||
int available ;
|
||||
/// Number of available objects on stack
|
||||
int available;
|
||||
|
||||
/**
|
||||
* Allocate a memory block
|
||||
*/
|
||||
void allocateDataBlock ( )
|
||||
/**
|
||||
* Allocate a memory block
|
||||
*/
|
||||
void allocateDataBlock( )
|
||||
{
|
||||
// Allocate a data block
|
||||
datablocknum += 1;
|
||||
data = ( UCHAR ** )realloc(data, sizeof (UCHAR *) * datablocknum);
|
||||
data[datablocknum - 1] = ( UCHAR * )malloc(HEAP_UNIT * N);
|
||||
|
||||
// Update allocation stack
|
||||
for (int i = 0; i < HEAP_UNIT; i++)
|
||||
{
|
||||
// Allocate a data block
|
||||
datablocknum += 1 ;
|
||||
data = ( UCHAR ** )realloc( data, sizeof ( UCHAR * ) * datablocknum ) ;
|
||||
data[ datablocknum - 1 ] = ( UCHAR * )malloc( HEAP_UNIT * N ) ;
|
||||
|
||||
// Update allocation stack
|
||||
for ( int i = 0 ; i < HEAP_UNIT ; i ++ )
|
||||
{
|
||||
stack[ 0 ][ i ] = ( data[ datablocknum - 1 ] + i * N ) ;
|
||||
}
|
||||
available = HEAP_UNIT ;
|
||||
stack[0][i] = (data[datablocknum - 1] + i * N);
|
||||
}
|
||||
available = HEAP_UNIT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a stack block, to store more deallocated objects
|
||||
*/
|
||||
void allocateStackBlock( )
|
||||
{
|
||||
// Allocate a stack block
|
||||
stackblocknum += 1 ;
|
||||
stacksize += HEAP_UNIT ;
|
||||
stack = ( UCHAR *** )realloc( stack, sizeof ( UCHAR ** ) * stackblocknum ) ;
|
||||
stack[ stackblocknum - 1 ] = ( UCHAR ** )malloc( HEAP_UNIT * sizeof ( UCHAR * ) ) ;
|
||||
}
|
||||
/**
|
||||
* Allocate a stack block, to store more deallocated objects
|
||||
*/
|
||||
void allocateStackBlock( )
|
||||
{
|
||||
// Allocate a stack block
|
||||
stackblocknum += 1;
|
||||
stacksize += HEAP_UNIT;
|
||||
stack = ( UCHAR *** )realloc(stack, sizeof (UCHAR * *) * stackblocknum);
|
||||
stack[stackblocknum - 1] = ( UCHAR ** )malloc(HEAP_UNIT * sizeof (UCHAR *) );
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
MemoryAllocator( )
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
MemoryAllocator( )
|
||||
{
|
||||
HEAP_UNIT = 1 << HEAP_BASE;
|
||||
HEAP_MASK = (1 << HEAP_BASE) - 1;
|
||||
|
||||
data = ( UCHAR ** )malloc(sizeof(UCHAR *) );
|
||||
data[0] = ( UCHAR * )malloc(HEAP_UNIT * N);
|
||||
datablocknum = 1;
|
||||
|
||||
stack = ( UCHAR *** )malloc(sizeof (UCHAR * *) );
|
||||
stack[0] = ( UCHAR ** )malloc(HEAP_UNIT * sizeof (UCHAR *) );
|
||||
stackblocknum = 1;
|
||||
stacksize = HEAP_UNIT;
|
||||
available = HEAP_UNIT;
|
||||
|
||||
for (int i = 0; i < HEAP_UNIT; i++)
|
||||
{
|
||||
HEAP_UNIT = 1 << HEAP_BASE ;
|
||||
HEAP_MASK = ( 1 << HEAP_BASE ) - 1 ;
|
||||
stack[0][i] = (data[0] + i * N);
|
||||
}
|
||||
}
|
||||
|
||||
data = ( UCHAR ** )malloc( sizeof( UCHAR * ) ) ;
|
||||
data[ 0 ] = ( UCHAR * )malloc( HEAP_UNIT * N ) ;
|
||||
datablocknum = 1 ;
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
void destroy( )
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < datablocknum; i++)
|
||||
{
|
||||
free(data[i]);
|
||||
}
|
||||
for (i = 0; i < stackblocknum; i++)
|
||||
{
|
||||
free(stack[i]);
|
||||
}
|
||||
free(data);
|
||||
free(stack);
|
||||
}
|
||||
|
||||
stack = ( UCHAR *** )malloc( sizeof ( UCHAR ** ) ) ;
|
||||
stack[ 0 ] = ( UCHAR ** )malloc( HEAP_UNIT * sizeof ( UCHAR * ) ) ;
|
||||
stackblocknum = 1 ;
|
||||
stacksize = HEAP_UNIT ;
|
||||
available = HEAP_UNIT ;
|
||||
|
||||
for ( int i = 0 ; i < HEAP_UNIT ; i ++ )
|
||||
{
|
||||
stack[ 0 ][ i ] = ( data[ 0 ] + i * N ) ;
|
||||
}
|
||||
/**
|
||||
* Allocation method
|
||||
*/
|
||||
void *allocate( )
|
||||
{
|
||||
if (available == 0)
|
||||
{
|
||||
allocateDataBlock( );
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
void destroy( )
|
||||
// printf("Allocating %d\n", header[ allocated ]) ;
|
||||
available--;
|
||||
return (void *)stack[available >> HEAP_BASE][available & HEAP_MASK];
|
||||
}
|
||||
|
||||
/**
|
||||
* De-allocation method
|
||||
*/
|
||||
void deallocate(void *obj)
|
||||
{
|
||||
if (available == stacksize)
|
||||
{
|
||||
int i ;
|
||||
for ( i = 0 ; i < datablocknum ; i ++ )
|
||||
{
|
||||
free( data[ i ] ) ;
|
||||
}
|
||||
for ( i = 0 ; i < stackblocknum ; i ++ )
|
||||
{
|
||||
free( stack[ i ] ) ;
|
||||
}
|
||||
free( data ) ;
|
||||
free( stack ) ;
|
||||
allocateStackBlock( );
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocation method
|
||||
*/
|
||||
void * allocate ( )
|
||||
{
|
||||
if ( available == 0 )
|
||||
{
|
||||
allocateDataBlock ( ) ;
|
||||
}
|
||||
// printf("De-allocating %d\n", ( obj - data ) / N ) ;
|
||||
stack[available >> HEAP_BASE][available & HEAP_MASK] = (UCHAR *)obj;
|
||||
available++;
|
||||
// printf("%d %d\n", allocated, header[ allocated ]) ;
|
||||
}
|
||||
|
||||
// printf("Allocating %d\n", header[ allocated ]) ;
|
||||
available -- ;
|
||||
return (void*)stack[ available >> HEAP_BASE ][ available & HEAP_MASK ] ;
|
||||
}
|
||||
/**
|
||||
* Print information
|
||||
*/
|
||||
void printInfo( )
|
||||
{
|
||||
printf("Bytes: %d Used: %d Allocated: %d Maxfree: %d\n", getBytes(), getAllocated(), getAll(), stacksize);
|
||||
}
|
||||
|
||||
/**
|
||||
* De-allocation method
|
||||
*/
|
||||
void deallocate ( void * obj )
|
||||
{
|
||||
if ( available == stacksize )
|
||||
{
|
||||
allocateStackBlock ( ) ;
|
||||
}
|
||||
/**
|
||||
* Query methods
|
||||
*/
|
||||
int getAllocated( )
|
||||
{
|
||||
return HEAP_UNIT * datablocknum - available;
|
||||
};
|
||||
|
||||
// printf("De-allocating %d\n", ( obj - data ) / N ) ;
|
||||
stack[ available >> HEAP_BASE ][ available & HEAP_MASK ] = (UCHAR*)obj ;
|
||||
available ++ ;
|
||||
// printf("%d %d\n", allocated, header[ allocated ]) ;
|
||||
}
|
||||
int getAll( )
|
||||
{
|
||||
return HEAP_UNIT * datablocknum;
|
||||
};
|
||||
|
||||
/**
|
||||
* Print information
|
||||
*/
|
||||
void printInfo ( )
|
||||
{
|
||||
printf("Bytes: %d Used: %d Allocated: %d Maxfree: %d\n", getBytes(), getAllocated(), getAll(), stacksize ) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query methods
|
||||
*/
|
||||
int getAllocated( )
|
||||
{
|
||||
return HEAP_UNIT * datablocknum - available ;
|
||||
};
|
||||
|
||||
int getAll( )
|
||||
{
|
||||
return HEAP_UNIT * datablocknum ;
|
||||
};
|
||||
|
||||
int getBytes( )
|
||||
{
|
||||
return N ;
|
||||
};
|
||||
int getBytes( )
|
||||
{
|
||||
return N;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -33,31 +33,32 @@
|
||||
class ModelReader
|
||||
{
|
||||
public:
|
||||
/// Constructor
|
||||
ModelReader(){} ;
|
||||
/// Constructor
|
||||
ModelReader(){
|
||||
};
|
||||
|
||||
/// Get next triangle
|
||||
virtual Triangle* getNextTriangle( ) = 0 ;
|
||||
virtual int getNextTriangle( int t[3] ) = 0 ;
|
||||
/// Get next triangle
|
||||
virtual Triangle *getNextTriangle( ) = 0;
|
||||
virtual int getNextTriangle(int t[3]) = 0;
|
||||
|
||||
/// Get bounding box
|
||||
virtual float getBoundingBox ( float origin[3] ) = 0 ;
|
||||
/// Get bounding box
|
||||
virtual float getBoundingBox(float origin[3]) = 0;
|
||||
|
||||
/// Get number of triangles
|
||||
virtual int getNumTriangles ( ) = 0 ;
|
||||
/// Get number of triangles
|
||||
virtual int getNumTriangles( ) = 0;
|
||||
|
||||
/// Get storage size
|
||||
virtual int getMemory ( ) = 0 ;
|
||||
/// Get storage size
|
||||
virtual int getMemory( ) = 0;
|
||||
|
||||
/// Reset file reading location
|
||||
virtual void reset( ) = 0 ;
|
||||
/// Reset file reading location
|
||||
virtual void reset( ) = 0;
|
||||
|
||||
/// For explicit vertex models
|
||||
virtual int getNumVertices( ) = 0 ;
|
||||
/// For explicit vertex models
|
||||
virtual int getNumVertices( ) = 0;
|
||||
|
||||
virtual void getNextVertex( float v[3] ) = 0 ;
|
||||
virtual void getNextVertex(float v[3]) = 0;
|
||||
|
||||
virtual void printInfo ( ) = 0 ;
|
||||
virtual void printInfo( ) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -37,18 +37,15 @@ const int vertmap[8][3] = {
|
||||
const int centmap[3][3][3][2] = {
|
||||
{{{0, 0}, {0, 1}, {1, 1}},
|
||||
{{0, 2}, {0, 3}, {1, 3}},
|
||||
{{2, 2}, {2, 3}, {3, 3}}
|
||||
},
|
||||
|
||||
{{2, 2}, {2, 3}, {3, 3}}},
|
||||
|
||||
{{{0, 4}, {0, 5}, {1, 5}},
|
||||
{{0, 6}, {0, 7}, {1, 7}},
|
||||
{{2, 6}, {2, 7}, {3, 7}}
|
||||
},
|
||||
|
||||
{{2, 6}, {2, 7}, {3, 7}}},
|
||||
|
||||
{{{4, 4}, {4, 5}, {5, 5}},
|
||||
{{4, 6}, {4, 7}, {5, 7}},
|
||||
{{6, 6}, {6, 7}, {7, 7}}
|
||||
}
|
||||
{{6, 6}, {6, 7}, {7, 7}}}
|
||||
};
|
||||
|
||||
const int edgemap[12][2] = {
|
||||
|
||||
+663
-668
File diff suppressed because it is too large
Load Diff
@@ -23,83 +23,81 @@
|
||||
#ifndef QUEUE_H
|
||||
#define QUEUE_H
|
||||
|
||||
struct gridQueueEle
|
||||
{
|
||||
struct gridQueueEle {
|
||||
int x, y, z;
|
||||
UCHAR dir ;
|
||||
gridQueueEle* next ;
|
||||
UCHAR dir;
|
||||
gridQueueEle *next;
|
||||
};
|
||||
|
||||
class GridQueue
|
||||
{
|
||||
gridQueueEle* head ;
|
||||
gridQueueEle* tail ;
|
||||
int numEles ;
|
||||
gridQueueEle *head;
|
||||
gridQueueEle *tail;
|
||||
int numEles;
|
||||
|
||||
public:
|
||||
|
||||
GridQueue( )
|
||||
GridQueue( )
|
||||
{
|
||||
head = NULL;
|
||||
tail = NULL;
|
||||
numEles = 0;
|
||||
}
|
||||
|
||||
gridQueueEle *getHead( )
|
||||
{
|
||||
return head;
|
||||
}
|
||||
|
||||
int getNumElements( )
|
||||
{
|
||||
return numEles;
|
||||
}
|
||||
|
||||
|
||||
void pushQueue(int st[3], int dir)
|
||||
{
|
||||
gridQueueEle *ele = new gridQueueEle;
|
||||
ele->x = st[0];
|
||||
ele->y = st[1];
|
||||
ele->z = st[2];
|
||||
ele->dir = (UCHAR) dir;
|
||||
ele->next = NULL;
|
||||
if (head == NULL)
|
||||
{
|
||||
head = NULL ;
|
||||
tail = NULL ;
|
||||
numEles = 0 ;
|
||||
head = ele;
|
||||
}
|
||||
else {
|
||||
tail->next = ele;
|
||||
}
|
||||
tail = ele;
|
||||
numEles++;
|
||||
}
|
||||
|
||||
int popQueue(int st[3], int& dir)
|
||||
{
|
||||
if (head == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
gridQueueEle* getHead( )
|
||||
st[0] = head->x;
|
||||
st[1] = head->y;
|
||||
st[2] = head->z;
|
||||
dir = (int) (head->dir);
|
||||
|
||||
gridQueueEle *temp = head;
|
||||
head = head->next;
|
||||
delete temp;
|
||||
|
||||
if (head == NULL)
|
||||
{
|
||||
return head ;
|
||||
tail = NULL;
|
||||
}
|
||||
numEles--;
|
||||
|
||||
int getNumElements( )
|
||||
{
|
||||
return numEles ;
|
||||
}
|
||||
|
||||
|
||||
void pushQueue( int st[3], int dir )
|
||||
{
|
||||
gridQueueEle* ele = new gridQueueEle ;
|
||||
ele->x = st[0] ;
|
||||
ele->y = st[1] ;
|
||||
ele->z = st[2] ;
|
||||
ele->dir = (UCHAR) dir ;
|
||||
ele->next = NULL ;
|
||||
if ( head == NULL )
|
||||
{
|
||||
head = ele ;
|
||||
}
|
||||
else
|
||||
{
|
||||
tail->next = ele ;
|
||||
}
|
||||
tail = ele ;
|
||||
numEles ++ ;
|
||||
}
|
||||
|
||||
int popQueue( int st[3], int& dir )
|
||||
{
|
||||
if ( head == NULL )
|
||||
{
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
st[0] = head->x ;
|
||||
st[1] = head->y ;
|
||||
st[2] = head->z ;
|
||||
dir = (int) (head->dir) ;
|
||||
|
||||
gridQueueEle* temp = head ;
|
||||
head = head->next ;
|
||||
delete temp ;
|
||||
|
||||
if ( head == NULL )
|
||||
{
|
||||
tail = NULL ;
|
||||
}
|
||||
numEles -- ;
|
||||
|
||||
return 1 ;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -29,18 +29,18 @@
|
||||
class Cubes
|
||||
{
|
||||
public:
|
||||
/// Get number of triangles
|
||||
int getNumTriangle(int mask)
|
||||
{
|
||||
return marching_cubes_numtri[mask];
|
||||
}
|
||||
/// Get number of triangles
|
||||
int getNumTriangle(int mask)
|
||||
{
|
||||
return marching_cubes_numtri[mask];
|
||||
}
|
||||
|
||||
/// Get a triangle
|
||||
void getTriangle(int mask, int index, int indices[3] )
|
||||
{
|
||||
for(int i = 0; i < 3; i++)
|
||||
indices[i] = marching_cubes_tris[mask][index][i];
|
||||
}
|
||||
/// Get a triangle
|
||||
void getTriangle(int mask, int index, int indices[3])
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
indices[i] = marching_cubes_tris[mask][index][i];
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -40,166 +40,169 @@ void veccopy(float dst[3], const float src[3])
|
||||
}
|
||||
|
||||
#define GET_FACE(_mesh, _n) \
|
||||
(*(DualConFaces)(((char*)(_mesh)->faces) + ((_n) * (_mesh)->face_stride)))
|
||||
(*(DualConFaces)(((char *)(_mesh)->faces) + ((_n) * (_mesh)->face_stride)))
|
||||
|
||||
#define GET_CO(_mesh, _n) \
|
||||
(*(DualConCo)(((char*)(_mesh)->co) + ((_n) * (_mesh)->co_stride)))
|
||||
(*(DualConCo)(((char *)(_mesh)->co) + ((_n) * (_mesh)->co_stride)))
|
||||
|
||||
class DualConInputReader : public ModelReader
|
||||
{
|
||||
private:
|
||||
const DualConInput *input_mesh;
|
||||
int tottri, curface, offset;
|
||||
float min[3], max[3], maxsize;
|
||||
float scale;
|
||||
const DualConInput *input_mesh;
|
||||
int tottri, curface, offset;
|
||||
float min[3], max[3], maxsize;
|
||||
float scale;
|
||||
public:
|
||||
DualConInputReader(const DualConInput *mesh, float _scale)
|
||||
DualConInputReader(const DualConInput *mesh, float _scale)
|
||||
: input_mesh(mesh), scale(_scale)
|
||||
{
|
||||
reset();
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
tottri = 0;
|
||||
curface = 0;
|
||||
offset = 0;
|
||||
maxsize = 0;
|
||||
|
||||
/* initialize tottri */
|
||||
for (int i = 0; i < input_mesh->totface; i++)
|
||||
tottri += GET_FACE(input_mesh, i)[3] ? 2 : 1;
|
||||
|
||||
veccopy(min, input_mesh->min);
|
||||
veccopy(max, input_mesh->max);
|
||||
|
||||
/* initialize maxsize */
|
||||
for (int i = 0; i < 3; i++) {
|
||||
float d = max[i] - min[i];
|
||||
if (d > maxsize)
|
||||
maxsize = d;
|
||||
}
|
||||
|
||||
void reset()
|
||||
/* redo the bounds */
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
tottri = 0;
|
||||
curface = 0;
|
||||
min[i] = (max[i] + min[i]) / 2 - maxsize / 2;
|
||||
max[i] = (max[i] + min[i]) / 2 + maxsize / 2;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
min[i] -= maxsize * (1 / scale - 1) / 2;
|
||||
maxsize *= 1 / scale;
|
||||
}
|
||||
|
||||
Triangle *getNextTriangle()
|
||||
{
|
||||
if (curface == input_mesh->totface)
|
||||
return 0;
|
||||
|
||||
Triangle *t = new Triangle();
|
||||
|
||||
unsigned int *f = GET_FACE(input_mesh, curface);
|
||||
if (offset == 0) {
|
||||
veccopy(t->vt[0], GET_CO(input_mesh, f[0]));
|
||||
veccopy(t->vt[1], GET_CO(input_mesh, f[1]));
|
||||
veccopy(t->vt[2], GET_CO(input_mesh, f[2]));
|
||||
}
|
||||
else {
|
||||
veccopy(t->vt[0], GET_CO(input_mesh, f[2]));
|
||||
veccopy(t->vt[1], GET_CO(input_mesh, f[3]));
|
||||
veccopy(t->vt[2], GET_CO(input_mesh, f[0]));
|
||||
}
|
||||
|
||||
if (offset == 0 && f[3])
|
||||
offset++;
|
||||
else {
|
||||
offset = 0;
|
||||
maxsize = 0;
|
||||
|
||||
/* initialize tottri */
|
||||
for(int i = 0; i < input_mesh->totface; i++)
|
||||
tottri += GET_FACE(input_mesh, i)[3] ? 2 : 1;
|
||||
|
||||
veccopy(min, input_mesh->min);
|
||||
veccopy(max, input_mesh->max);
|
||||
|
||||
/* initialize maxsize */
|
||||
for(int i = 0; i < 3; i++) {
|
||||
float d = max[i] - min[i];
|
||||
if(d > maxsize)
|
||||
maxsize = d;
|
||||
}
|
||||
|
||||
/* redo the bounds */
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
min[i] = (max[i] + min[i]) / 2 - maxsize / 2;
|
||||
max[i] = (max[i] + min[i]) / 2 + maxsize / 2;
|
||||
}
|
||||
|
||||
for(int i = 0; i < 3; i++)
|
||||
min[i] -= maxsize * (1 / scale - 1) / 2;
|
||||
maxsize *= 1 / scale;
|
||||
curface++;
|
||||
}
|
||||
|
||||
Triangle* getNextTriangle()
|
||||
{
|
||||
if(curface == input_mesh->totface)
|
||||
return 0;
|
||||
|
||||
Triangle* t = new Triangle();
|
||||
|
||||
unsigned int *f = GET_FACE(input_mesh, curface);
|
||||
if(offset == 0) {
|
||||
veccopy(t->vt[0], GET_CO(input_mesh, f[0]));
|
||||
veccopy(t->vt[1], GET_CO(input_mesh, f[1]));
|
||||
veccopy(t->vt[2], GET_CO(input_mesh, f[2]));
|
||||
/* remove triangle if it contains invalid coords */
|
||||
for (int i = 0; i < 3; i++) {
|
||||
const float *co = t->vt[i];
|
||||
if (isnan(co[0]) || isnan(co[1]) || isnan(co[2])) {
|
||||
delete t;
|
||||
return getNextTriangle();
|
||||
}
|
||||
else {
|
||||
veccopy(t->vt[0], GET_CO(input_mesh, f[2]));
|
||||
veccopy(t->vt[1], GET_CO(input_mesh, f[3]));
|
||||
veccopy(t->vt[2], GET_CO(input_mesh, f[0]));
|
||||
}
|
||||
|
||||
if(offset == 0 && f[3])
|
||||
offset++;
|
||||
else {
|
||||
offset = 0;
|
||||
curface++;
|
||||
}
|
||||
|
||||
/* remove triangle if it contains invalid coords */
|
||||
for(int i = 0; i < 3; i++) {
|
||||
const float *co = t->vt[i];
|
||||
if(isnan(co[0]) || isnan(co[1]) || isnan(co[2])) {
|
||||
delete t;
|
||||
return getNextTriangle();
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
int getNextTriangle(int t[3])
|
||||
{
|
||||
if(curface == input_mesh->totface)
|
||||
return 0;
|
||||
|
||||
unsigned int *f = GET_FACE(input_mesh, curface);
|
||||
if(offset == 0) {
|
||||
t[0] = f[0];
|
||||
t[1] = f[1];
|
||||
t[2] = f[2];
|
||||
}
|
||||
else {
|
||||
t[0] = f[2];
|
||||
t[1] = f[3];
|
||||
t[2] = f[0];
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
if(offset == 0 && f[3])
|
||||
offset++;
|
||||
else {
|
||||
offset = 0;
|
||||
curface++;
|
||||
}
|
||||
int getNextTriangle(int t[3])
|
||||
{
|
||||
if (curface == input_mesh->totface)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
unsigned int *f = GET_FACE(input_mesh, curface);
|
||||
if (offset == 0) {
|
||||
t[0] = f[0];
|
||||
t[1] = f[1];
|
||||
t[2] = f[2];
|
||||
}
|
||||
else {
|
||||
t[0] = f[2];
|
||||
t[1] = f[3];
|
||||
t[2] = f[0];
|
||||
}
|
||||
|
||||
int getNumTriangles()
|
||||
{
|
||||
return tottri;
|
||||
if (offset == 0 && f[3])
|
||||
offset++;
|
||||
else {
|
||||
offset = 0;
|
||||
curface++;
|
||||
}
|
||||
|
||||
int getNumVertices()
|
||||
{
|
||||
return input_mesh->totco;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
float getBoundingBox(float origin[3])
|
||||
{
|
||||
veccopy(origin, min);
|
||||
return maxsize ;
|
||||
}
|
||||
int getNumTriangles()
|
||||
{
|
||||
return tottri;
|
||||
}
|
||||
|
||||
/* output */
|
||||
void getNextVertex(float v[3])
|
||||
{
|
||||
/* not used */
|
||||
}
|
||||
int getNumVertices()
|
||||
{
|
||||
return input_mesh->totco;
|
||||
}
|
||||
|
||||
/* stubs */
|
||||
void printInfo() {}
|
||||
int getMemory() { return sizeof(DualConInputReader); }
|
||||
float getBoundingBox(float origin[3])
|
||||
{
|
||||
veccopy(origin, min);
|
||||
return maxsize;
|
||||
}
|
||||
|
||||
/* output */
|
||||
void getNextVertex(float v[3])
|
||||
{
|
||||
/* not used */
|
||||
}
|
||||
|
||||
/* stubs */
|
||||
void printInfo() {
|
||||
}
|
||||
int getMemory() {
|
||||
return sizeof(DualConInputReader);
|
||||
}
|
||||
};
|
||||
|
||||
void *dualcon(const DualConInput *input_mesh,
|
||||
/* callbacks for output */
|
||||
DualConAllocOutput alloc_output,
|
||||
DualConAddVert add_vert,
|
||||
DualConAddQuad add_quad,
|
||||
|
||||
DualConFlags flags,
|
||||
DualConMode mode,
|
||||
float threshold,
|
||||
float hermite_num,
|
||||
float scale,
|
||||
int depth)
|
||||
/* callbacks for output */
|
||||
DualConAllocOutput alloc_output,
|
||||
DualConAddVert add_vert,
|
||||
DualConAddQuad add_quad,
|
||||
|
||||
DualConFlags flags,
|
||||
DualConMode mode,
|
||||
float threshold,
|
||||
float hermite_num,
|
||||
float scale,
|
||||
int depth)
|
||||
{
|
||||
DualConInputReader r(input_mesh, scale);
|
||||
Octree o(&r, alloc_output, add_vert, add_quad,
|
||||
flags, mode, depth, threshold, hermite_num);
|
||||
flags, mode, depth, threshold, hermite_num);
|
||||
o.scanConvert();
|
||||
return o.getOutputMesh();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+850
-1169
File diff suppressed because it is too large
Load Diff
+1169
-1179
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user