metasurf

diff src/metasurf.c @ 2:9ab057fba0c5

added copyright statements, added comments, yada yada
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 25 Oct 2011 08:59:07 +0300
parents 7aa4627e492b
children 2c575855f707
line diff
     1.1 --- a/src/metasurf.c	Tue Oct 25 07:57:07 2011 +0300
     1.2 +++ b/src/metasurf.c	Tue Oct 25 08:59:07 2011 +0300
     1.3 @@ -1,3 +1,21 @@
     1.4 +/*
     1.5 +metasurf - a library for implicit surface polygonization
     1.6 +Copyright (C) 2011  John Tsiombikas <nuclear@member.fsf.org>
     1.7 +
     1.8 +This program is free software: you can redistribute it and/or modify
     1.9 +it under the terms of the GNU Lesser General Public License as published by
    1.10 +the Free Software Foundation, either version 3 of the License, or
    1.11 +(at your option) any later version.
    1.12 +
    1.13 +This program is distributed in the hope that it will be useful,
    1.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.16 +GNU Lesser General Public License for more details.
    1.17 +
    1.18 +You should have received a copy of the GNU Lesser General Public License
    1.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1.20 +*/
    1.21 +#include <stdio.h>
    1.22  #include <stdlib.h>
    1.23  #include "metasurf.h"
    1.24  #include "mcubes.h"
    1.25 @@ -60,7 +78,7 @@
    1.26  	ms->normal = 0;
    1.27  	ms->min[0] = ms->min[1] = ms->min[2] = -1.0;
    1.28  	ms->max[0] = ms->max[1] = ms->max[2] = 1.0;
    1.29 -	ms->res[0] = ms->res[1] = ms->res[2] = 32;
    1.30 +	ms->res[0] = ms->res[1] = ms->res[2] = 40;
    1.31  	ms->nverts = 0;
    1.32  
    1.33  	return 0;
    1.34 @@ -104,11 +122,16 @@
    1.35  }
    1.36  
    1.37  
    1.38 -void msurf_polygonize(struct metasurface *ms)
    1.39 +int msurf_polygonize(struct metasurface *ms)
    1.40  {
    1.41  	int i, j, k;
    1.42  	vec3 pos, delta;
    1.43  
    1.44 +	if(!ms->eval || !ms->vertex) {
    1.45 +		fprintf(stderr, "you need to set eval and vertex callbacks before calling msurf_polygonize\n");
    1.46 +		return -1;
    1.47 +	}
    1.48 +
    1.49  	for(i=0; i<3; i++) {
    1.50  		delta[i] = (ms->max[i] - ms->min[i]) / (float)ms->res[i];
    1.51  	}
    1.52 @@ -130,6 +153,7 @@
    1.53  		}
    1.54  		pos[0] += delta[0];
    1.55  	}
    1.56 +	return 0;
    1.57  }
    1.58  
    1.59  
    1.60 @@ -248,28 +272,22 @@
    1.61  	unsigned int code = mt_bitcode(val[idx[0]], val[idx[1]], val[idx[2]], val[idx[3]], ms->thres);
    1.62  
    1.63  	switch(code) {
    1.64 -	/*case 1:
    1.65 -	case INV(1):*/
    1.66 -	case 0x0e:
    1.67 -	case 0x01:
    1.68 +	case 1:
    1.69 +	case INV(1):
    1.70  		EDGE(0, 1);
    1.71  		EDGE(0, 2);
    1.72  		EDGE(0, 3);
    1.73  		break;
    1.74  
    1.75 -	/*case 2:
    1.76 -	case INV(2):*/
    1.77 -	case 0x0d:
    1.78 -	case 0x02:
    1.79 +	case 2:
    1.80 +	case INV(2):
    1.81  		EDGE(1, 0);
    1.82  		EDGE(1, 3);
    1.83  		EDGE(1, 2);
    1.84  		break;
    1.85  
    1.86 -	/*case 3:
    1.87 -	case INV(3):*/
    1.88 -	case 0x0c:
    1.89 -	case 0x03:
    1.90 +	case 3:
    1.91 +	case INV(3):
    1.92  		EDGE(0, 3);
    1.93  		EDGE(0, 2);
    1.94  		EDGE(1, 3);
    1.95 @@ -279,19 +297,15 @@
    1.96  		EDGE(0, 2);
    1.97  		break;
    1.98  
    1.99 -	/*case 4:
   1.100 -	case INV(4):*/
   1.101 -	case 0x0b:
   1.102 -	case 0x04:
   1.103 +	case 4:
   1.104 +	case INV(4):
   1.105  		EDGE(2, 0);
   1.106  		EDGE(2, 1);
   1.107  		EDGE(2, 3);
   1.108  		break;
   1.109  
   1.110 -	/*case 5:
   1.111 -	case INV(5):*/
   1.112 -	case 0x0a:
   1.113 -	case 0x05:
   1.114 +	case 5:
   1.115 +	case INV(5):
   1.116  		EDGE(0, 1);
   1.117  		EDGE(2, 3);
   1.118  		EDGE(0, 3);
   1.119 @@ -301,10 +315,8 @@
   1.120  		EDGE(2, 3);
   1.121  		break;
   1.122  
   1.123 -	/*case 6:
   1.124 -	case INV(6):*/
   1.125 -	case 0x09:
   1.126 -	case 0x06:
   1.127 +	case 6:
   1.128 +	case INV(6):
   1.129  		EDGE(0, 1);
   1.130  		EDGE(1, 3);
   1.131  		EDGE(2, 3);
   1.132 @@ -314,10 +326,8 @@
   1.133  		EDGE(2, 3);
   1.134  		break;
   1.135  
   1.136 -	/*case 7:
   1.137 -	case INV(7):*/
   1.138 -	case 0x07:
   1.139 -	case 0x08:
   1.140 +	case 7:
   1.141 +	case INV(7):
   1.142  		EDGE(3, 0);
   1.143  		EDGE(3, 2);
   1.144  		EDGE(3, 1);